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 ComponentYReceiver implements INativeReceiver {
	protected Component component;
	
	public ComponentYReceiver(Component component) {
		this.component = component;
	}

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

}
