Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / simulator / interfaces / html / HtmlElementMouseSender.java
Sakoda2269 on 19 Nov 1 KB 不要なものを削除
package simulator.interfaces.html;

import models.algebra.Constant;
import models.algebra.Expression;
import models.algebra.Term;
import models.dataConstraintModel.DataConstraintModel;
import models.dataConstraintModel.JsonTerm;
import models.dataConstraintModel.ResourcePath;
import models.dataFlowModel.DataTransferChannel;
import simulator.Resource;
import simulator.Simulator;
import simulator.interfaces.NativeSender;

public class HtmlElementMouseSender extends NativeSender implements IRestEventListener{

	public HtmlElementMouseSender(Simulator simulator, DataTransferChannel channel, ResourcePath resourcePath,
			Resource resource) {
		super(simulator, channel, resourcePath, resource);
	}

	@Override
	public void onEvent(String method, JsonTerm message) {
		if(method.equals("onMousePressed")) {
			Constant one = new Constant("1", DataConstraintModel.typeInt);
			Expression eventMessage = channel.getOutputChannelMembers().iterator().next().getStateTransition().getMessageExpression();
			Term termMessage = (Term)eventMessage.clone();
			termMessage.setChild(0, one);
			sendToModel(termMessage);
			
		} else if(method.equals("onMouseReleased")) {
			Constant zero = new Constant("0", DataConstraintModel.typeInt);
			Expression eventMessage = channel.getOutputChannelMembers().iterator().next().getStateTransition().getMessageExpression();
			Term termMessage = (Term) eventMessage.clone();
			termMessage.setChild(0, zero);
			sendToModel(termMessage);
		}
	}

}