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

	@Override
	public void onReceiveFromModel(Event event, SystemState nextSystemState) {
		Expression message = event.getMessage();
		if (message instanceof Term) {
			Expression height = ((Term) message).getChild(0);
			if (height instanceof Constant) {
				int curWidth = component.getSize().width;
				component.setSize(curWidth, Integer.parseInt(height.toString()));
			}
		}
	}

}
