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_PUSH_PULL_SELECTION;
//ボタンの追加
dataFlowCheckBox = new JCheckBox("Data-Flow", false);
pushFlowCheckBox = new JCheckBox("Push-Flow", true);
pullFlowCheckBox = new JCheckBox("Pull-Flow", true);
// 各Viewにイベントハンドラを追加
dataFlowCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stage.setEnabledForLayer(Stage.DATA_FLOW_LAYER, dataFlowCheckBox.isSelected());
}});
pushFlowCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, pushFlowCheckBox.isSelected());
}});
pullFlowCheckBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, pullFlowCheckBox.isSelected());
}});
dataFlowCheckBox.setEnabled(false);
pushFlowCheckBox.setEnabled(false);
pullFlowCheckBox.setEnabled(false);
// レイヤーのパネルレイアウトの初期化.
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);
}
/**
* When the stage changes, toggle the active state of layer visibility buttons
*/
@Override
public void stageChanged(Stage newStage) {
dataFlowCheckBox.setEnabled(false);
pushFlowCheckBox.setEnabled(false);
pullFlowCheckBox.setEnabled(false);
newStage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, false);
newStage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, false);
}
}