Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / simulator / interfaces / swing / ComponentWidthReceiver.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 ComponentWidthReceiver implements INativeReceiver {
	protected Component component;
	
	public ComponentWidthReceiver(Component component) {
		this.component = component;
	}

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

}