Newer
Older
AlgebraicDataflowArchitectureModel / AlgebraicDataflowArchitectureModel / src / application / views / FlowLayerWindow.java
Shohei Yamagiwa 17 days ago 2 KB Fix comment
package application.views;

import application.ApplicationWindow;
import application.editor.Editor;
import application.editor.IStageChangeListener;
import application.editor.Stage;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class FlowLayerWindow extends JDialog implements IStageChangeListener {
	private String title = "Flow Layer";
	private JCheckBox dataFlowCheckBox = null;
	private JCheckBox pushFlowCheckBox = null;
	private JCheckBox pullFlowCheckBox = null;
	
	private Stage stage = null;
	
	public FlowLayerWindow(final ApplicationWindow owner) {
		super(owner);
		
		setTitle(title);
		setDefaultCloseOperation(HIDE_ON_CLOSE);
		
		stage = Editor.STAGE_CONTROL_FLOW_DELEGATION;
		
		// Add check boxes.
		dataFlowCheckBox = new JCheckBox("Data-Flow", false);
		pushFlowCheckBox = new JCheckBox("Push-Flow", true);
		pullFlowCheckBox = new JCheckBox("Pull-Flow", true);
		
		// Add handlers to the checkboxes.
		dataFlowCheckBox.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				stage.setLayerEnabled(Stage.DATA_FLOW_LAYER, dataFlowCheckBox.isSelected());
			}
		});
		
		pushFlowCheckBox.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				stage.setLayerEnabled(Stage.PUSH_FLOW_LAYER, pushFlowCheckBox.isSelected());
			}
		});
		
		pullFlowCheckBox.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				stage.setLayerEnabled(Stage.PULL_FLOW_LAYER, pullFlowCheckBox.isSelected());
			}
		});
		
		dataFlowCheckBox.setEnabled(false);
		pushFlowCheckBox.setEnabled(false);
		pullFlowCheckBox.setEnabled(false);
		
		// Initialize the layer panel layout.
		Container panel = getContentPane();
		panel.setLayout(new GridLayout(/*low*/4, /*col*/1));
		panel.add(dataFlowCheckBox);
		panel.add(pushFlowCheckBox);
		panel.add(pullFlowCheckBox);
		Point location = new Point(owner.getX() + (owner.getWidth() / 2) - (this.getWidth() / 2), owner.getY() + (owner.getHeight() / 2) - (this.getHeight() / 2));
		setLocation(location);
		
		pack();
		setResizable(false);
	}
	
	/**
	 * Toggle the activation of layer check boxes whenever the current stage changes.
	 */
	@Override
	public void stageChanged(Stage newStage) {
		dataFlowCheckBox.setEnabled(false);
		pushFlowCheckBox.setEnabled(false);
		pullFlowCheckBox.setEnabled(false);
		
		newStage.setLayerEnabled(Stage.PUSH_FLOW_LAYER, false);
		newStage.setLayerEnabled(Stage.PULL_FLOW_LAYER, false);
	}
}