Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / simulator / interfaces / swing / ComponentXReceiver.java
package simulator.interfaces.swing;

import java.awt.Component;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.text.JTextComponent;

import models.algebra.Constant;
import models.algebra.Expression;
import models.algebra.Term;
import simulator.Event;
import simulator.SystemState;
import simulator.interfaces.INativeReceiver;

public class ComponentXReceiver implements INativeReceiver {
	protected Component component;
	
	public ComponentXReceiver(Component component) {
		this.component = component;
	}

	@Override
	public void onReceiveFromModel(Event event, SystemState nextSystemState) {
		Expression message = event.getMessage();
		if (message instanceof Term) {
			Expression x = ((Term) message).getChild(0);
			if (x instanceof Constant) {
				int curY = component.getLocation().y;
				component.setLocation(Integer.parseInt(x.toString()), curY);
			}
		}
	}

}