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); } } }