diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java index 8ee36b5..bcbd998 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java @@ -21,6 +21,7 @@ private TreeLayoutAction treeLayoutAction = null; private CircleLayoutAction circleLayoutAction = null; private ShowNavigationAction showNavigationAction; + private ShowFlowLayerWindowAction showFlowLayerWindowAction; //private SimulateAction simulateAction = null; @@ -67,6 +68,7 @@ menu = add(new JMenu("Window")); menu.add(showNavigationAction = new ShowNavigationAction(applicationWindow)); + menu.add(showFlowLayerWindowAction = new ShowFlowLayerWindowAction(applicationWindow)); } public Editor getEditor() { diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index 794a44d..c692fa3 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -1,6 +1,7 @@ package application; import application.editor.Editor; +import application.views.FlowLayerWindow; import application.views.NavigationWindow; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; @@ -26,6 +27,7 @@ private ApplicationMenuBar menuBar = null; private NavigationWindow navigationWindow; + private FlowLayerWindow showFlowLayerWindow = null; public ApplicationWindow() { setTitle(title); @@ -58,7 +60,12 @@ navigationWindow = new NavigationWindow(this, editor); navigationWindow.setVisible(true); + + showFlowLayerWindow = new FlowLayerWindow(this); + showFlowLayerWindow.setVisible(false); + editor.addStageChangeListener(navigationWindow); + editor.addStageChangeListener(showFlowLayerWindow); } public mxGraph getGraph() { @@ -80,4 +87,8 @@ public void showNavigationWindow() { navigationWindow.setVisible(true); } -} + + public void showSwitchLayerWindow(){ + showFlowLayerWindow.setVisible(true); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/ShowFlowLayerWindowAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/ShowFlowLayerWindowAction.java new file mode 100644 index 0000000..a73a535 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/ShowFlowLayerWindowAction.java @@ -0,0 +1,17 @@ +package application.actions; + +import application.ApplicationWindow; + +import java.awt.event.ActionEvent; + +public class ShowFlowLayerWindowAction extends AbstractSystemAction { + + public ShowFlowLayerWindowAction(ApplicationWindow frame) { + super(/*propName*/"Show FlowLayer", frame); + } + + @Override + public void actionPerformed(ActionEvent e) { + frame.showSwitchLayerWindow(); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index 33114bd..8eb198e 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java @@ -1,5 +1,6 @@ package application.editor; +import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.util.mxEventSource.mxIEventListener; @@ -18,6 +19,11 @@ protected mxGraphComponent graphComponent; protected mxGraph graph; + public static final int NODE_LAYER = 0; + public static final int DATA_FLOW_LAYER = 0; + public static final int PUSH_FLOW_LAYER = 1; + public static final int PULL_FLOW_LAYER = 2; + public Stage(mxGraphComponent graphComponent) { this.graphComponent = graphComponent; this.graph = graphComponent.getGraph(); @@ -36,4 +42,54 @@ public DataTransferModel getModel() { return model; } -} + + /** + * Constructs the hierarchical layer structure under the root cell. + */ + public void constructLayer(mxGraph graph){ + mxCell root = (mxCell) graph.getDefaultParent(); + + mxCell nodeAndDataFlowLayer = new mxCell(); // 0 + mxCell pushFlowLayer = new mxCell(); // 1 + mxCell pullFlowLayer = new mxCell(); // 2 + + graph.getModel().beginUpdate(); + try { + graph.addCell(nodeAndDataFlowLayer, root); + graph.addCell(pushFlowLayer, root); + graph.addCell(pullFlowLayer, root); + } finally { + graph.getModel().endUpdate(); + } + } + + /** + * Enable or disable only the specified layer (layerNo) + */ + public void setEnabledForLayer(final int layerNo, final boolean isEnable){ + mxCell rootCell = (mxCell) graph.getDefaultParent(); + if(rootCell == null) return; + if(rootCell.getChildCount() <= 0) return; + + graph.getModel().setVisible(rootCell.getChildAt(layerNo), isEnable); + graph.refresh(); + } + + /** + * After hiding all layers, show only the specified ones (argsOfLayers) + */ + public void showOnlyLayer(final int... argsOfLayers){ + mxCell rootCell = (mxCell) graph.getDefaultParent(); + if(rootCell == null) return; + if(rootCell.getChildCount() <= 0) return; + + + for(int i = 0; i < rootCell.getChildCount(); i++){ + graph.getModel().setVisible(rootCell.getChildAt(i), false); + } + + for(int layerNo : argsOfLayers){ + graph.getModel().setVisible(rootCell.getChildAt(layerNo), true); + } + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/FlowLayerWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/FlowLayerWindow.java new file mode 100644 index 0000000..ae2749a --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/views/FlowLayerWindow.java @@ -0,0 +1,82 @@ +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); + } +}