diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index 17a33ab..0e7b5d5 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -1,23 +1,13 @@ package application; -import java.util.ArrayList; -import java.util.List; - import javax.swing.JFrame; -import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; -import com.mxgraph.model.mxGraphModel; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.handler.mxRubberband; -import com.mxgraph.swing.view.mxICellEditor; -import com.mxgraph.util.mxEvent; -import com.mxgraph.util.mxEventObject; -import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; import application.editor.Editor; -import application.editor.stages.DataFlowCellEditor; import application.views.NavigationWindow; import application.views.controlFlowDelegation.ShowFlowLayerWindow; diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractPopupAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractPopupAction.java new file mode 100644 index 0000000..4fea18c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/AbstractPopupAction.java @@ -0,0 +1,21 @@ +package application.actions; + +import javax.swing.AbstractAction; + +import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; + +public abstract class AbstractPopupAction extends AbstractAction { + protected mxGraphComponent graphComponent = null; + protected mxCell targetCell = null; + + public AbstractPopupAction(final String name, final mxCell targetCell, final mxGraphComponent graphComponent) { + super(name); + this.graphComponent = graphComponent; + this.targetCell = targetCell; + } + + public void updateTargetCell(final mxCell targetCell) { + this.targetCell = targetCell; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/ChangeCallOrderAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/ChangeCallOrderAction.java new file mode 100644 index 0000000..b415a3d --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/ChangeCallOrderAction.java @@ -0,0 +1,76 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.JOptionPane; + +import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; + +import models.controlFlowModel.CallEdgeAttribute; + +/************************************************************* + * + */ +public class ChangeCallOrderAction extends AbstractPopupAction { + + /************************************************************* + * [ *constructor ] + /************************************************************* + */ + public ChangeCallOrderAction(final mxGraphComponent graphComponent ,final mxCell cell) { + super("Change Call Order", cell, graphComponent); + } + + /************************************************************* + * [ *public ] + /************************************************************* + * + */ + @Override + public void actionPerformed(ActionEvent e) { + if(targetCell == null) return; + changeCallOrderOfCallEdge(targetCell); + } + + /************************************************************* + * [ *private ] + /************************************************************* + */ + private void changeCallOrderOfCallEdge(Object cellObj) { + String input = ""; + int inputOrder = 0; + + CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); + if(callEdgeAttr == null) return; + + input = JOptionPane.showInputDialog("Call order"); + if( input == null) return; + + if( !isNumeric(input) ) { + JOptionPane.showMessageDialog(graphComponent, "Input value must type of number."); + return; + } + + inputOrder = Integer.parseInt(input); + + final int endOfOrderOfSrc = callEdgeAttr.getSourceObjectNode().getOutdegree(); + if(inputOrder <= 0 || endOfOrderOfSrc < inputOrder) { + JOptionPane.showMessageDialog(graphComponent, "Input order must be between 1 and " + endOfOrderOfSrc + "."); + return; + } + + int curOrder = callEdgeAttr.getSourceObjectNode().getOutEdgeCallOrder(callEdgeAttr.getCallEdge()); + callEdgeAttr.getSourceObjectNode().sortOutEdgesByCallOrder(curOrder, inputOrder); + + graphComponent.refresh(); + } + + /************************************************************* + * + */ + private boolean isNumeric(final String str) { + if(str == null) return false; + return str.matches("[0-9.]+"); + } +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/InsertStatelessObjectAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/InsertStatelessObjectAction.java new file mode 100644 index 0000000..c9d423b --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/InsertStatelessObjectAction.java @@ -0,0 +1,89 @@ +package application.actions; + +import java.awt.event.ActionEvent; + +import javax.swing.JOptionPane; + +import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; + +import application.editor.stages.ControlFlowDelegationStage; +import application.editor.stages.ControlFlowDelegationStageStatus; +import models.controlFlowModel.ObjectNodeAttribute; + +/************************************************************* + * + */ +public class InsertStatelessObjectAction extends AbstractPopupAction{ + + /************************************************************* + * [ *constructor ] + /************************************************************* + */ + private ControlFlowDelegationStage stage = null; + + /************************************************************* + * [ *constructor ] + /************************************************************* + */ + public InsertStatelessObjectAction(final ControlFlowDelegationStage stage, final mxGraphComponent graphComponent ,final mxCell cell) { + super("Insert Mediator", cell, graphComponent); + this.stage = stage; + } + + @Override + public void actionPerformed(ActionEvent e) { + insertObjectNode(targetCell); + stage.setState( ControlFlowDelegationStageStatus.SELECTING_AN_EDGE); + } + + /*************************************************************/ + private void insertObjectNode(final Object cellObj) { + if(cellObj == null) return; + + mxCell edgeCell = null; + if(cellObj instanceof mxCell) edgeCell = (mxCell)cellObj; + else return; + + // Inputing name to the dialog. + String objName = JOptionPane.showInputDialog("Object Name:"); + if(objName == null) return; + + if( objName.isEmpty()) { + JOptionPane.showMessageDialog(graphComponent, "You must input a name. \nIt mustn't be empty."); + return; + } + + if( isDuplicatedName(objName) ) { + JOptionPane.showMessageDialog(graphComponent, "The named object has already existed."); + return; + } + + stage.insertObjectNodeCellInControlFlowLayer(graphComponent.getGraph(), edgeCell, objName); + } + + /************************************************************* + * + */ + private boolean isDuplicatedName(final String name) { + mxCell root = (mxCell)graphComponent.getGraph().getDefaultParent(); + + for(int i = 0; i < root.getChildCount(); i++) { + mxCell layerCell = (mxCell)root.getChildAt(i); + for(int j = 0; j < layerCell.getChildCount(); j++) { + mxCell cell = (mxCell)layerCell.getChildAt(j); + + ObjectNodeAttribute attr = null; + if(cell.getValue() instanceof ObjectNodeAttribute) + attr = (ObjectNodeAttribute)cell.getValue(); + else continue; + + if( !(attr.getObjectNode().getName().equals(name))) continue; + return true; + } + } + return false; + } + + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 9aa7f96..1f2eda4 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -1,5 +1,6 @@ package application.editor; +import java.awt.event.MouseListener; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; @@ -57,6 +58,7 @@ public mxGraph graph = null; private mxGraphComponent graphComponent = null; private mxIEventListener curChangeEventListener = null; + private MouseListener curMouseEventListener = null; protected Stage curStage = null; protected List stageQueue = null; @@ -74,9 +76,9 @@ this.graphComponent = graphComponent; this.graph = graphComponent.getGraph(); - STAGE_DATA_FLOW_MODELING = new DataFlowModelingStage(graph); - STAGE_PUSH_PULL_SELECTION = new PushPullSelectionStage(graph); - STAGE_CONTROL_FLOW_DELEGATION = new ControlFlowDelegationStage(graph); + STAGE_DATA_FLOW_MODELING = new DataFlowModelingStage(graphComponent); + STAGE_PUSH_PULL_SELECTION = new PushPullSelectionStage(graphComponent); + STAGE_CONTROL_FLOW_DELEGATION = new ControlFlowDelegationStage(graphComponent); graphComponent.setCellEditor(STAGE_DATA_FLOW_MODELING.createCellEditor(graphComponent)); @@ -120,6 +122,9 @@ if (!nextStage.canChangeFrom(curStage)) return false; nextStage.init(curStage); graphComponent.setCellEditor(nextStage.createCellEditor(graphComponent)); + + // add listeners + // "curChangeEventListener" will be called when updating the mxGraph. if (curChangeEventListener != null) { graph.getModel().removeListener(curChangeEventListener); } @@ -127,6 +132,15 @@ if (curChangeEventListener != null) { graph.getModel().addListener(mxEvent.CHANGE, curChangeEventListener); } + + // A handler of a mouse event. + if(curMouseEventListener != null) { + graphComponent.getGraphControl().removeMouseListener(curMouseEventListener); + } + curMouseEventListener = nextStage.createMouseEventListener(this); + if(curMouseEventListener != null) { + graphComponent.getGraphControl().addMouseListener(curMouseEventListener); + } curStage = nextStage; notifyStageChangeListeners(); return true; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/FlowCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/FlowCellEditor.java index 24f98e3..c44b42d 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/FlowCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/FlowCellEditor.java @@ -36,7 +36,7 @@ /************************************************************* * */ - abstract public void startEditing(Object arg0, EventObject arg1); + abstract public void startEditing(Object cellObj, EventObject eventObj); /************************************************************* * diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index c3873bc..ba5baba 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java @@ -1,5 +1,7 @@ package application.editor; +import java.awt.event.MouseListener; + import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.view.mxICellEditor; @@ -10,6 +12,7 @@ abstract public class Stage { protected DataTransferModel model = null; + protected mxGraphComponent graphComponent = null; protected mxGraph graph = null; public static final int NODE_LAYER = 0; public static final int DATA_FLOW_LAYER = 0; @@ -20,10 +23,11 @@ * [ *constructor] /************************************************************* * - * @param graph + * @param graphComponent */ - public Stage(mxGraph graph) { - this.graph = graph; + public Stage(mxGraphComponent graphComponent) { + this.graphComponent = graphComponent; + this.graph = graphComponent.getGraph(); } /************************************************************* @@ -38,6 +42,7 @@ abstract public void init(Stage prevStage); abstract public mxICellEditor createCellEditor(mxGraphComponent graphComponent); abstract public mxIEventListener createChangeEventListener(Editor editor); + abstract public MouseListener createMouseEventListener(Editor editor); /************************************************************* * [ *public ] diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index eff02d8..077d713 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -1,33 +1,23 @@ package application.editor.stages; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.EventObject; import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.swing.mxGraphComponent.mxGraphControl; -import com.mxgraph.view.mxCellState; import application.editor.FlowCellEditor; -import application.editor.Stage; import models.controlFlowModel.CallEdgeAttribute; -import models.controlFlowModel.ControlFlowDelegator; import models.controlFlowModel.ObjectNode; import models.controlFlowModel.ObjectNodeAttribute; -import models.dataFlowModel.PushPullValue; /************************************************************* * */ public class ControlFlowDelegationCellEditor extends FlowCellEditor { - private ControlFlowDelegationStageStatus curState = null; private mxCell targetEdgeCell = null; - + /************************************************************* * [ *constructor ] /************************************************************* @@ -36,18 +26,6 @@ */ public ControlFlowDelegationCellEditor(ControlFlowDelegationStage stage, mxGraphComponent graphComponent) { super(stage, graphComponent); - curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; - - // If required handlers have already resistered, - // then remove them before each add. - mxGraphControl graphControl = graphComponent.getGraphControl(); - for(MouseListener listener : graphControl.getMouseListeners()) { - if(listener instanceof InsertObjectNodeAction) - graphControl.removeMouseListener(listener); - } - - // Adding handlers - graphControl.addMouseListener(new InsertObjectNodeAction()); } /************************************************************* @@ -58,30 +36,18 @@ @Override public void startEditing(Object cellObj, EventObject eventObj) { if( editingCell != null) stopEditing(true); + ControlFlowDelegationStage cfdStage = (ControlFlowDelegationStage)stage; - System.out.println("state:" + curState.name()); - ControlFlowDelegationStage curStage = (ControlFlowDelegationStage)stage; - - switch(curState) { + switch(cfdStage.getCurState()) { case SELECTING_AN_EDGE: - // Branching based on the edge click event. // | double clicked > Showing delegatable nodes. - // | right clicked > Inserting a stateless node. - // (added listener -> InsertObjectNodeAction) if( graphComponent.getGraph().getModel().isEdge(cellObj)) { // cache a target edge of cell; targetEdgeCell = (mxCell)cellObj; showDelegatableNodesBySelectedEdge(cellObj); - curState = ControlFlowDelegationStageStatus.SHOWING_DELEGATABLE_NODES; - - // If the label of the edge is clicked, - // then inputing a call order you want. - mxCellState state = graphComponent.getGraph().getView().getState(cellObj); - if(state == null || state.getLabel() == null || state.getLabel().equals("")) return; - - changeCallOrderOfCallEdge(cellObj); + cfdStage.setState(ControlFlowDelegationStageStatus.SHOWING_DELEGATABLE_NODES); } break; @@ -98,18 +64,16 @@ ObjectNode dstObjNode = ((ObjectNodeAttribute)dstCell.getValue()).getObjectNode(); if(dstObjNode == null) throw new ClassCastException(); - if(!curStage.isExecutableDelegation(callEdgeAttr, dstObjNode)){ + if(!cfdStage.isExecutableDelegation(callEdgeAttr, dstObjNode)){ JOptionPane.showMessageDialog(graphComponent, "It's impossible for the chose object to delegate."); return; } - curStage.showDelegatedGraph(graphComponent.getGraph(), targetEdgeCell, (mxCell)cellObj); - - curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; + cfdStage.showDelegatedGraph(graphComponent.getGraph(), targetEdgeCell, (mxCell)cellObj); + cfdStage.setState(ControlFlowDelegationStageStatus.SELECTING_AN_EDGE); } else { - System.out.println("cancel showing state."); - curStage.resetAllStyleOfCells(); - curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; + cfdStage.resetAllStyleOfCells(); + cfdStage.setState(ControlFlowDelegationStageStatus.SELECTING_AN_EDGE); } break; } @@ -119,134 +83,20 @@ * */ @Override - public void stopEditing(boolean cancel) { - - } + public void stopEditing(boolean cancel) { } /************************************************************* * [ *private ] /************************************************************* - * [ view ] + * view /************************************************************* * - * Todo: support to PUSH/PULL each layer */ private void showDelegatableNodesBySelectedEdge(Object cellObj) { CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); if(callEdgeAttr == null) return; - ((ControlFlowDelegationStage)stage) - .showDelegatableNodes(graphComponent.getGraph(), callEdgeAttr); - } - - /************************************************************* - * - */ - private void changeCallOrderOfCallEdge(final Object cellObj) { - String input = ""; - int inputOrder = 0; - - CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)graphComponent.getGraph().getModel().getValue(cellObj); - if(callEdgeAttr == null) return; - - input = JOptionPane.showInputDialog("Call order"); - if( input == null) return; - if( !isNumeric(input) ) { - JOptionPane.showMessageDialog(graphComponent, "Input value must type of number."); - return; - } - - inputOrder = Integer.parseInt(input); - - final int endOfOrderOfSrc = callEdgeAttr.getSourceObjectNode().getOutdegree(); - - if(inputOrder <= 0 || endOfOrderOfSrc < inputOrder) { - JOptionPane.showMessageDialog(graphComponent, "Input order must be between 1 and " + endOfOrderOfSrc + "."); - return; - } - - int curOrder = callEdgeAttr.getSourceObjectNode().getOutEdgeCallOrder(callEdgeAttr.getCallEdge()); - callEdgeAttr.getSourceObjectNode().sortOutEdgesByCallOrder(curOrder, inputOrder); - graphComponent.refresh(); - } - - - /************************************************************* - * - */ - private boolean isNumeric(final String str) { - if(str == null) return false; - return str.matches("[0-9.]+"); - } - - /************************************************************* - * - */ - private boolean isDuplicatedName(final String name) { - mxCell root = (mxCell)graphComponent.getGraph().getDefaultParent(); - - for(int i = 0; i < root.getChildCount(); i++) { - mxCell layerCell = (mxCell)root.getChildAt(i); - for(int j = 0; j < layerCell.getChildCount(); j++) { - mxCell cell = (mxCell)layerCell.getChildAt(i); - - ObjectNodeAttribute attr = null; - if(cell.getValue() instanceof ObjectNodeAttribute) - attr = (ObjectNodeAttribute)cell.getValue(); - else continue; - - if( !(attr.getObjectNode().getName().equals(name))) continue; - return true; - } - } - return false; - } - - /************************************************************* - * [ *inner class ] - /************************************************************* - * [ action ] - * Inserting an intermediation object type of . - */ - private class InsertObjectNodeAction extends MouseAdapter { - @Override - public void mouseReleased(MouseEvent e) { - // if the right mouse button was clicked, - // then pop up the dialog name to insert a mediator-object. - if( !curState.equals(ControlFlowDelegationStageStatus.SELECTING_AN_EDGE)) return; - if( !SwingUtilities.isRightMouseButton(e) )return; - - Object cellObj = graphComponent.getCellAt(e.getX(), e.getY()); - insertObjectNode(cellObj); - } - - /*************************************************************/ - private void insertObjectNode(final Object cellObj) { - if(cellObj == null) return; - - mxCell edgeCell = null; - if(cellObj instanceof mxCell) edgeCell = (mxCell)cellObj; - else return; - - curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; - - // Inputing name to the dialog. - String objName = JOptionPane.showInputDialog("Object Name:"); - if(objName == null) return; - - if( objName.isEmpty()) { - JOptionPane.showMessageDialog(graphComponent, "You must input a name. \nIt mustn't be empty."); - return; - } - - if( isDuplicatedName(objName) ) { - JOptionPane.showMessageDialog(graphComponent, "The named object has already existed."); - return; - } - - ((ControlFlowDelegationStage)stage) - .insertObjectNodeCellInControlFlowLayer(graphComponent.getGraph(), edgeCell, objName); - } - + ControlFlowDelegationStage cfdStage = (ControlFlowDelegationStage)stage; + cfdStage.showDelegatableNodes(graphComponent.getGraph(), callEdgeAttr); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index 24f29d1..5a60a80 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -1,12 +1,17 @@ package application.editor.stages; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.swing.SwingUtilities; + import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.swing.util.mxMouseAdapter; import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraph; @@ -14,6 +19,8 @@ import application.editor.Editor; import application.editor.FlowCellEditor; import application.editor.Stage; +import application.views.PopupMenuBase; +import application.views.controlFlowDelegation.ControlFlowDelegationStagePopupMenu; import models.Edge; import models.Node; import models.controlFlowModel.CallEdge; @@ -37,21 +44,44 @@ public final int PORT_DIAMETER = 8; public final int PORT_RADIUS = PORT_DIAMETER / 2; + private ControlFlowDelegationStageStatus curState = null; + private ControlFlowGraph controlFlowGraph = null; - + private PopupMenuBase popupMenu = null; + /************************************************************* * [ *constructor ] /************************************************************* * - * @param graph */ - public ControlFlowDelegationStage(mxGraph graph) { - super(graph); + public ControlFlowDelegationStage(mxGraphComponent graphComoponent) { + super(graphComoponent); + this.curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; + this.popupMenu = new ControlFlowDelegationStagePopupMenu(this, graphComoponent); } /************************************************************* * [ *public ] /************************************************************* + * getters / setters + /************************************************************* + */ + public ControlFlowGraph getControlFlowGraph() { + return controlFlowGraph; + } + + /************************************************************* + * + */ + public ControlFlowDelegationStageStatus getCurState() { + return curState; + } + + public void setState(ControlFlowDelegationStageStatus nextState) { + curState = nextState; + } + + /************************************************************* * */ @Override @@ -68,15 +98,16 @@ if (prevStage instanceof PushPullSelectionStage) { model = ((PushPullSelectionStage) prevStage).getModel(); - DataFlowGraph dataFlowGraph = ((PushPullSelectionStage) prevStage).getDataFlowGraph(); + DataFlowGraph dataFlowGraph = ((PushPullSelectionStage) prevStage).getDataFlowGraph(); - controlFlowGraph = new ControlFlowGraph(dataFlowGraph, model); - - graph = clearControlFlowGraphCells(graph); + controlFlowGraph = new ControlFlowGraph(dataFlowGraph, model); + + clearControlFlowGraphCells(graph); graph = constructGraph(graph, controlFlowGraph); } } + /************************************************************* * */ @@ -85,15 +116,42 @@ return new ControlFlowDelegationCellEditor(this, graphComponent); } + /************************************************************* + * + */ @Override - public mxIEventListener createChangeEventListener(Editor editor) { + public mxIEventListener createChangeEventListener(Editor editor) { return null; } - - public ControlFlowGraph getControlFlowGraph() { - return controlFlowGraph; + + /************************************************************* + * + */ + @Override + public MouseListener createMouseEventListener(Editor editor) { + MouseListener listener = new mxMouseAdapter() { + @Override + public void mouseReleased(MouseEvent e) { + if(SwingUtilities.isLeftMouseButton(e)) { + if(graphComponent.getCellAt(e.getX(), e.getY()) != null) return; + if(curState.equals(ControlFlowDelegationStageStatus.SELECTING_AN_EDGE)) return; + + System.out.println("cancel showing state."); + resetAllStyleOfCells(); + curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; + return; + } + else if(SwingUtilities.isRightMouseButton(e)) { + popupMenu.show(e.getX(), e.getY()); + } + } + }; + return listener; } - + + + /************************************************************* + * manipulating the control-graph /************************************************************* * */ @@ -108,14 +166,14 @@ for(Object node : graph.getChildVertices(layerCell)) { if( !(node instanceof mxCell) ) continue; mxCell cell = (mxCell)node; - + ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)cell.getValue(); if(objNodeAttr == null) return; - + ObjectNode objNode = objNodeAttr.getObjectNode(); ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); List delegatableNodes = delegator.searchDelegatableNodes(callEdgeAttr.getCallEdge()); - + if(delegatableNodes.contains(objNode)) { graph.getModel().setStyle(cell, objNodeAttr.getEnableStyle()); } @@ -133,32 +191,31 @@ graph.refresh(); } } - + /************************************************************* - * Showing the delegated graph. + * Showing the graph that was executed CFD. */ public void showDelegatedGraph(mxGraph graph, mxCell targetEdgeCell, final mxCell dstObjNodeCell) { ObjectNode dstObjNode = ((ObjectNodeAttribute)dstObjNodeCell.getValue()).getObjectNode(); if(dstObjNode == null) throw new ClassCastException(); - CallEdgeAttribute targetEdgeAttr = (CallEdgeAttribute)targetEdgeCell.getValue(); if(targetEdgeAttr == null) throw new ClassCastException(); ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); delegator.delegateCallEdge(targetEdgeAttr.getCallEdge(), dstObjNode); - + mxCell root = (mxCell)graph.getDefaultParent(); mxCell layerCell = null; switch(targetEdgeAttr.getSelectedOption()) { - case PUSH: - layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); - break; - - case PULL: - case PUSHorPULL: - layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); + case PUSH: + layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); + break; + + case PULL: + case PUSHorPULL: + layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); } - + try { mxCell dstNodeCell = targetEdgeAttr.getDestinationCell(); @@ -166,7 +223,7 @@ if(graph.getModel().getValue(targetEdgeCell) != null) { graph.getModel().remove(targetEdgeCell); } - + // Insert an edge CallEdgeAttribute newAttr = new CallEdgeAttribute(targetEdgeAttr.getCallEdge(), targetEdgeAttr.getOriginalSourceObjectNode(),dstObjNodeCell, dstNodeCell); graph.insertEdge(layerCell, "", newAttr, dstObjNodeCell, dstNodeCell, "movable=false;"); @@ -177,17 +234,17 @@ graph.getModel().endUpdate(); } } - + /************************************************************* * */ public void resetAllStyleOfCells() { mxCell root = (mxCell)graph.getDefaultParent(); - + graph.getModel().beginUpdate(); try { for(int layerNo = Stage.PUSH_FLOW_LAYER; layerNo <= Stage.PULL_FLOW_LAYER; layerNo++) { - + mxCell layerCell = (mxCell)root.getChildAt(layerNo); for(Object node : graph.getChildVertices(layerCell)) { mxCell cell = null; @@ -196,7 +253,7 @@ ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)(cell.getValue()); if(objNodeAttr == null) throw new NullPointerException(""); - + graph.getModel().setStyle(cell, objNodeAttr.getDefaultStyle()); } } @@ -206,7 +263,7 @@ graph.refresh(); } } - + /************************************************************* * Inserting an intermediation object type of . */ @@ -217,17 +274,17 @@ mxCell root = (mxCell)graph.getDefaultParent(); mxCell layerCell = null; switch(callEdgeAttr.getSelectedOption()) { - case PUSH: - layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); - break; - - case PULL: - case PUSHorPULL: - layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); + case PUSH: + layerCell = (mxCell)root.getChildAt(Stage.PUSH_FLOW_LAYER); + break; + + case PULL: + case PUSHorPULL: + layerCell = (mxCell)root.getChildAt(Stage.PULL_FLOW_LAYER); } - + graph.getModel().beginUpdate(); - + try { // Inserting the node type of to the graph. ObjectNode insertObjNode = new ObjectNode(insertObjName); @@ -238,37 +295,37 @@ mxPoint insertPoint = new mxPoint( (srcPoint.getX() + dstPoint.getX())/2, (srcPoint.getY() + dstPoint.getY())/2); - + mxCell insertObjNodeCell = (mxCell)graph.insertVertex(layerCell, null, objNodeAttr, /* coordinate*/ insertPoint.getX(), insertPoint.getY(), /* scale */ 40, 40, objNodeAttr.getDefaultStyle()); insertObjNodeCell.setValue(objNodeAttr); - + addObjectNodeToCallGraphl(insertObjNode, callEdgeAttr.getSelectedOption()); - + // Reconnecting each edges of the node. ObjectNode srcObjNode = callEdgeAttr.getSourceObjectNode(); ObjectNode dstObjNode = callEdgeAttr.getDestinationObjectNode(); if(srcObjNode == null || dstObjNode == null) throw new NullPointerException(); if(!(srcObjNode instanceof ObjectNode && dstObjNode instanceof ObjectNode)) throw new ClassCastException(); - + // Connecting I/O Edges to the insert object. CallEdge srcToInsertEdge = callEdgeAttr.getCallEdge(); CallEdge insertToDstEdge = new CallEdge(insertObjNode, dstObjNode, callEdgeAttr.getSelectedOption()); if(srcToInsertEdge == null || insertToDstEdge == null) throw new NullPointerException(); - + // Remove the destination edge of the object node. // After add the "srcToInsertEdge" to the destination object node. dstObjNode.removeInEdge(srcToInsertEdge); dstObjNode.addInEdge(insertToDstEdge); srcToInsertEdge.setDestination(insertObjNode); // changing the out of edge of the sourceObjectNode - + insertObjNode.addInEdge(srcToInsertEdge); insertObjNode.addOutEdge(insertToDstEdge); - + // Update the cell of the graph. for(int i =0; i < layerCell.getChildCount(); i++) { mxCell nodeCell = (mxCell)layerCell.getChildAt(i); @@ -277,12 +334,12 @@ // Checking "nodeCell" has an instance of ObjectNodeAttribute cellObjNodeAttr = (ObjectNodeAttribute)nodeCell.getValue(); if(cellObjNodeAttr == null) throw new ClassCastException("dosen't have the value of "); - + // Is "nodeCell" the same as the source cell of the call edge? if(nodeCell.equals(callEdgeAttr.getSourceCell())){ mxCell srcNodeCell = callEdgeAttr.getSourceCell(); CallEdgeAttribute newInEdgeAttr = new CallEdgeAttribute(srcToInsertEdge, srcNodeCell, insertObjNodeCell); - + // If the target call edge hasn't removed yet. // then it removes from mxGraphModel. if(graph.getModel().getValue(targetEdge) != null) @@ -301,7 +358,7 @@ else if(nodeCell.equals(callEdgeAttr.getDestinationCell())) { mxCell dstNodeCell = callEdgeAttr.getDestinationCell(); CallEdgeAttribute newOutEdgeAttr = new CallEdgeAttribute(insertToDstEdge, insertObjNodeCell, dstNodeCell); - + // If the target if(graph.getModel().getValue(targetEdge) != null) graph.getModel().remove(targetEdge); @@ -317,17 +374,18 @@ } } + /************************************************************* * */ public boolean isExecutableDelegation(final CallEdgeAttribute targetEdgeAttr, final ObjectNode dstObjNode) { ControlFlowDelegator delegator = new ControlFlowDelegator(controlFlowGraph); List delegatableNodes = delegator.searchDelegatableNodes(targetEdgeAttr.getCallEdge()); - + return delegatableNodes.contains(dstObjNode); } - - + + /************************************************************* * [ *private ] /************************************************************* @@ -335,7 +393,7 @@ */ private mxGraph constructGraph(mxGraph graph, ControlFlowGraph controlFlowGraph) { showOnlyLayer(PUSH_FLOW_LAYER, PULL_FLOW_LAYER); - + graph.getModel().beginUpdate(); try { // Creating Control-Flow and separeted Push/Pull which types of @@ -344,21 +402,22 @@ // Creating Entry-Point Object Map pushFlowEntryNodeCells = createCellsOfInputChannel(graph, PUSH_FLOW_LAYER, controlFlowGraph, pushResNodeCells); - + // Inserting edges of each transfer graph = insertControlFlowEdges(graph, PUSH_FLOW_LAYER, controlFlowGraph.getPushCallGraph(), pushResNodeCells, pushFlowEntryNodeCells); graph = insertControlFlowEdges(graph, PULL_FLOW_LAYER, controlFlowGraph.getPullCallGraph(), pullResNodeCells, null); - + } finally { graph.getModel().endUpdate(); } return graph; } + /************************************************************* * When changed from previous stage, it will be called in initializing. */ - private mxGraph clearControlFlowGraphCells(mxGraph graph) { + private void clearControlFlowGraphCells(mxGraph graph) { mxCell root = (mxCell)graph.getDefaultParent(); graph.getModel().beginUpdate(); @@ -366,66 +425,64 @@ // removing child from end of a root cell root.remove(root.getChildAt(PULL_FLOW_LAYER)); root.remove(root.getChildAt(PUSH_FLOW_LAYER)); - + root.insert(new mxCell()); root.insert(new mxCell()); } finally { graph.getModel().endUpdate(); + graph.refresh(); } - - graph.refresh(); - - return graph; } + /************************************************************* * Creating a map of to and Creating 's vertices * @return constructed the view of the graph */ private Map createCellsOfResourceMap(mxGraph graph, final int layerNumber, final ControlFlowGraph controlFlowGraph) { Map resNodeCells = new HashMap<>(); - + mxCell root = (mxCell)graph.getDefaultParent(); mxCell nodeLayerCell = (mxCell)root.getChildAt(NODE_LAYER); mxCell layerCell = (mxCell)root.getChildAt(layerNumber); - + // create resource vertices for (ResourceNode resNode : controlFlowGraph.getDataFlowGraph().getResouceNodes()) { - + ObjectNode objNode = null; switch(layerNumber) { - case PUSH_FLOW_LAYER: - if(controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode) != null) - objNode = controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode); - break; + case PUSH_FLOW_LAYER: + if(controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode) != null) + objNode = controlFlowGraph.getPushCallGraph().getStatefulObjectNode(resNode); + break; - case PULL_FLOW_LAYER: - if(controlFlowGraph.getPullCallGraph().getStatefulObjectNode(resNode) != null) - objNode = controlFlowGraph.getPullCallGraph().getStatefulObjectNode(resNode); - break; + case PULL_FLOW_LAYER: + if(controlFlowGraph.getPullCallGraph().getStatefulObjectNode(resNode) != null) + objNode = controlFlowGraph.getPullCallGraph().getStatefulObjectNode(resNode); + break; } - + if(objNode == null) continue; - + for(int i =0; i < nodeLayerCell.getChildCount(); i++) { mxCell nodeCell = (mxCell)nodeLayerCell.getChildAt(i); if( nodeCell.getValue() instanceof ResourceNodeAttribute ) { nodeCell = (mxCell)nodeLayerCell.getChildAt(i); } else continue; - + // Checking if the "node" has a cell of the data-flow-layer is the same as "resNode". ResourceNodeAttribute resNodeAttr = (ResourceNodeAttribute)nodeCell.getValue(); if( !resNodeAttr.getResourceNode().equals(resNode) )continue; - + // Getting information from the cell in the data-flow-layer, // After that, insert a resource as a vertex ObjectNodeAttribute objNodeAttr = new ObjectNodeAttribute(objNode); mxCell resNodeObjCell = (mxCell)graph.insertVertex(layerCell, null, objNodeAttr, - /* scale */nodeCell.getGeometry().getX(), nodeCell.getGeometry().getY(), - /*coordinate*/nodeCell.getGeometry().getWidth(), nodeCell.getGeometry().getHeight(), - objNodeAttr.getDefaultStyle()); - + /* scale */nodeCell.getGeometry().getX(), nodeCell.getGeometry().getY(), + /*coordinate*/nodeCell.getGeometry().getWidth(), nodeCell.getGeometry().getHeight(), + objNodeAttr.getDefaultStyle()); + resNodeCells.put(resNode, resNodeObjCell); } } @@ -433,6 +490,7 @@ return resNodeCells; } + /************************************************************* * Createing an input channel object */ @@ -441,9 +499,9 @@ mxCell root = (mxCell)graph.getDefaultParent(); mxCell layerCell = (mxCell)root.getChildAt(layerNumber); - + Map ioChannelCells = new HashMap<>(); - + graph.getModel().beginUpdate(); try { mxGeometry outPortGeometry = new mxGeometry(1.0, 0.5, PORT_DIAMETER, PORT_DIAMETER); @@ -451,16 +509,16 @@ outPortGeometry.setRelative(true); CallGraph callGraph = controlFlowGraph.getPushCallGraph(); - + // insert an I/O channel as a vertex for (Node node : callGraph.getNodes()) { EntryPointObjectNode entryPointObjNode = null; if(node instanceof EntryPointObjectNode) entryPointObjNode = (EntryPointObjectNode)node; else continue; - + ObjectNodeAttribute entryObjAttr = new ObjectNodeAttribute(entryPointObjNode); - + // Taking over geometry information from the channel node with the same name. mxCell dataFlowLayerCell = (mxCell)root.getChildAt(Stage.DATA_FLOW_LAYER); for(int i = 0; i < dataFlowLayerCell.getChildCount(); i++) { @@ -472,13 +530,13 @@ else continue; if(!entryPointObjNodeName.equals(channelCellName))continue; - + mxCell entryPointCelll = (mxCell)graph.insertVertex(layerCell, null, entryObjAttr, /* scale */ channelCell.getGeometry().getX(), channelCell.getGeometry().getY(), /* geometry*/channelCell.getGeometry().getWidth(), channelCell.getGeometry().getHeight()); mxCell port_out = new mxCell(null, outPortGeometry, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); - + graph.addCell(port_out, entryPointCelll); // insert the output port of a channel ioChannelCells.put(entryPointObjNode, entryPointCelll); } @@ -487,31 +545,32 @@ finally { graph.getModel().endUpdate(); } - + return ioChannelCells; } + /************************************************************* * When changed from previous stage, it will be called in initializing. */ private mxGraph insertControlFlowEdges(mxGraph graph, final int layerNumber, final CallGraph callGraph ,final Map resNodeCells, final Map entryNodeCells) { mxCell root = (mxCell)graph.getDefaultParent(); mxCell layerCell = (mxCell)root.getChildAt(layerNumber); - + for (Edge callGraphEdge : callGraph.getEdges()) { if ( !(callGraphEdge instanceof CallEdge))continue; CallEdge callEdge = (CallEdge) callGraphEdge; // Is checking node connecting a resource? if(callEdge.getSource() == null || callEdge.getDestination() == null) continue; - + Node srcResNode = null; ResourceNode dstResNode = ((StatefulObjectNode)callEdge.getDestination()).getResource(); - + mxCell srcNodeCell =null; mxCell srcOutPortCell = null; mxCell dstNodeCell = resNodeCells.get(dstResNode); - + if(callEdge.getSource() instanceof StatefulObjectNode) { srcResNode = ((StatefulObjectNode)callEdge.getSource()).getResource(); srcNodeCell =resNodeCells.get(srcResNode); @@ -522,11 +581,11 @@ srcOutPortCell = (mxCell)srcNodeCell.getChildAt(0); } else continue; - + if(srcNodeCell == null || dstNodeCell == null) continue; CallEdgeAttribute callEdgeAttr = new CallEdgeAttribute(callEdge, (ObjectNode)callEdge.getSource(), srcNodeCell, dstNodeCell); - + // If "srcResNode" types of "EntryPointObjectNode" (= channel) // then parameter references to geometry of "outPort". if(srcResNode instanceof ResourceNode) { @@ -535,29 +594,31 @@ else if(srcResNode instanceof EntryPointObjectNode) { graph.insertEdge(layerCell, null, callEdgeAttr, srcOutPortCell, dstNodeCell, "movable=false;"); } - + } return graph; } + /************************************************************* * */ private void addObjectNodeToCallGraphl(final ObjectNode insertObjNode, final PushPullValue selectedOption) { switch(selectedOption) { - case PUSH: - if(controlFlowGraph.getPushCallGraph().getNodes().contains(insertObjNode))return; - controlFlowGraph.getPushCallGraph().addNode(insertObjNode); + case PUSH: + if(controlFlowGraph.getPushCallGraph().getNodes().contains(insertObjNode))return; + controlFlowGraph.getPushCallGraph().addNode(insertObjNode); - break; - - case PULL: - case PUSHorPULL: - if(controlFlowGraph.getPullCallGraph().getNodes().contains(insertObjNode))return; - controlFlowGraph.getPullCallGraph().addNode(insertObjNode); - - break; + break; + + case PULL: + case PUSHorPULL: + if(controlFlowGraph.getPullCallGraph().getNodes().contains(insertObjNode))return; + controlFlowGraph.getPullCallGraph().addNode(insertObjNode); + + break; } } + } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStageStatus.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStageStatus.java index 9cf8f99..f2b7e7a 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStageStatus.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStageStatus.java @@ -2,7 +2,6 @@ /************************************************************* * - * @author k-fujii */ public enum ControlFlowDelegationStageStatus { SELECTING_AN_EDGE, diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index 8d5e86d..0906962 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -1,5 +1,6 @@ package application.editor.stages; +import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -53,8 +54,8 @@ /************************************************************* * */ - public DataFlowModelingStage(mxGraph graph) { - super(graph); + public DataFlowModelingStage(mxGraphComponent graphComponent) { + super(graphComponent); } /************************************************************* @@ -106,6 +107,11 @@ }; } + @Override + public MouseListener createMouseEventListener(Editor editor) { + return null; + } + /************************************************************* * */ diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index dedf31d..0e14d32 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -1,5 +1,6 @@ package application.editor.stages; +import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.List; @@ -28,8 +29,8 @@ public class PushPullSelectionStage extends Stage { protected DataFlowGraph dataFlowGraph = null; - public PushPullSelectionStage(mxGraph graph) { - super(graph); + public PushPullSelectionStage(mxGraphComponent graphComponent) { + super(graphComponent); } @Override @@ -82,6 +83,12 @@ }; } + @Override + public MouseListener createMouseEventListener(Editor editor) { + return null; + } + + public DataFlowGraph getDataFlowGraph() { return dataFlowGraph; } diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/PopupMenuBase.java b/AlgebraicDataflowArchitectureModel/src/application/views/PopupMenuBase.java new file mode 100644 index 0000000..625774c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/views/PopupMenuBase.java @@ -0,0 +1,47 @@ +package application.views; + +import java.awt.Component; + +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; + +import application.actions.AbstractPopupAction; + +/************************************************************* + * + */ +public abstract class PopupMenuBase { + protected JPopupMenu popupMenu = null; + protected mxGraphComponent graphComponent = null; + + /************************************************************* + * [ *constructor ] + /************************************************************* + */ + public PopupMenuBase(final mxGraphComponent graphComponent) { + this.graphComponent = graphComponent; + this.popupMenu = new JPopupMenu(); + } + + /************************************************************* + * [ *public ] + /************************************************************* + * + */ + public void show(int x, int y) { + popupMenu.show(graphComponent, x, y); + } + + /************************************************************* + * [ *protected ] + /************************************************************* + * + */ + protected void addMenuItem(JMenuItem menuItem) { + popupMenu.add(menuItem); + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java new file mode 100644 index 0000000..1bd8d7c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ControlFlowDelegationStagePopupMenu.java @@ -0,0 +1,91 @@ +package application.views.controlFlowDelegation; + +import java.awt.Component; + +import javax.swing.JMenuItem; + +import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; + +import application.actions.AbstractPopupAction; +import application.actions.ChangeCallOrderAction; +import application.actions.InsertStatelessObjectAction; +import application.editor.stages.ControlFlowDelegationStage; +import application.views.PopupMenuBase; + +/************************************************************* + * + */ +public class ControlFlowDelegationStagePopupMenu extends PopupMenuBase { + private ControlFlowDelegationStage stage = null; + private mxCell selectedCell = null; + + /************************************************************* + * [ *constructor ] + /************************************************************* + */ + public ControlFlowDelegationStagePopupMenu(final ControlFlowDelegationStage stage, mxGraphComponent graphComponent) { + super(graphComponent); + this.stage = stage; + + addMenuItem(new JMenuItem(new InsertStatelessObjectAction(stage, graphComponent, selectedCell))); + addMenuItem(new JMenuItem(new ChangeCallOrderAction(graphComponent, selectedCell))); + } + + /************************************************************* + * [ *public ] + /************************************************************* + * + */ + @Override + public void show(int x, int y) { + + boolean isEnable = (graphComponent.getCellAt(x, y) != null) + ? true + : false; + + setEnableMenuItems(isEnable); + super.show(x, y); + + + if( graphComponent.getCellAt(x, y) instanceof mxCell ) { + selectedCell =(mxCell) graphComponent.getCellAt(x, y); + } + else { + selectedCell = null; + } + + notifyCellCached(selectedCell); + } + + /************************************************************* + * [ *private ] + /************************************************************* + */ + private void notifyCellCached(final mxCell cell) { + if(cell == null) return; + + for(Component component : popupMenu.getComponents()) { + JMenuItem menuItem = null; + if(component instanceof JMenuItem) menuItem = (JMenuItem)component; + else return; + + AbstractPopupAction action = null; + if(menuItem.getAction() instanceof AbstractPopupAction) { + action = (AbstractPopupAction)menuItem.getAction(); + } + else return; + + action.updateTargetCell(cell); + } + } + + /************************************************************* + * + */ + private void setEnableMenuItems(final boolean isEnable) { + for(Component component : popupMenu.getComponents()) { + component.setEnabled(isEnable); + } + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java index f409b46..230504c 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/ShowFlowLayerWindow.java @@ -4,14 +4,9 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.swing.ButtonGroup; import javax.swing.JCheckBox; import javax.swing.JDialog; -import javax.swing.JRadioButton; import application.ApplicationWindow; import application.editor.Editor;