diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/InEdgeAttribute.java b/AlgebraicDataflowArchitectureModel/src/application/editor/InEdgeAttribute.java index 5481474..5956f6c 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/InEdgeAttribute.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/InEdgeAttribute.java @@ -5,7 +5,7 @@ import models.dataFlowModel.ResourceNode; public class InEdgeAttribute extends PushPullAttribute { - ResourceNode srcRes; + private ResourceNode srcRes; public InEdgeAttribute(PushPullAttribute attr, ResourceNode srcRes) { super(); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index 591927d..7eadbbf 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.view.mxGraph; @@ -11,13 +12,24 @@ protected mxGraph graph = null; 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 static final int CONTROL_FLOW_LAYER = 1; + public static final int PUSH_FLOW_LAYER = 2; + public static final int PULL_FLOW_LAYER = 3; + /************************************************************* + * [ *constructor] + /************************************************************* + * + * @param graph + */ public Stage(mxGraph graph) { this.graph = graph; } + /************************************************************* + * + * @return model + */ public DataTransferModel getModel() { return model; } @@ -25,4 +37,24 @@ abstract public boolean canChangeFrom(Stage prevStage); abstract public void init(Stage prevStage); abstract public mxICellEditor createCellEditor(mxGraphComponent graphComponent); + + /************************************************************* + * [ *protected ] + /************************************************************* + * Showing layers are specified number of layers. + * @param you want to show numbers of layers. + */ + protected void showOnlyLayer(mxGraph graph, 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); + } + } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index 609aeaf..455299b 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -3,7 +3,6 @@ import java.util.EventObject; import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.swing.view.mxICellEditor; import application.editor.FlowCellEditor; @@ -41,5 +40,4 @@ public void stopEditing(boolean cancel) { } - } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index a2d2f87..2171a54 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -1,21 +1,24 @@ package application.editor.stages; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; +import java.util.HashMap; +import java.util.Map; import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.swing.mxGraphComponent.mxGraphControl; import com.mxgraph.view.mxGraph; import application.editor.FlowCellEditor; +import application.editor.InEdgeAttribute; +import application.editor.OutEdgeAttribute; import application.editor.Stage; +import models.Edge; +import models.controlFlowModel.CallEdge; +import models.controlFlowModel.CallEdgeAttribute; +import models.controlFlowModel.CallGraph; import models.controlFlowModel.ControlFlowGraph; import models.controlFlowModel.StatefulObjectNode; import models.dataConstraintModel.IdentifierTemplate; import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ResourceNode; public class ControlFlowDelegationStage extends Stage { @@ -24,9 +27,9 @@ private ControlFlowGraph controlFlowGraph = null; - /**-------------------------------------------------------------------------------- + /************************************************************* * [ *constructor ] - /*-------------------------------------------------------------------------------- + /************************************************************* * * @param graph */ @@ -34,10 +37,11 @@ super(graph); } - /**-------------------------------------------------------------------------------- + /************************************************************* * [ *public ] - /**-------------------------------------------------------------------------------- + /************************************************************* * + * @param prevStage * @return */ @Override @@ -46,8 +50,9 @@ return false; } - /**-------------------------------------------------------------------------------- + /************************************************************* * + * @param prevStage */ @Override public void init(Stage prevStage) { @@ -55,96 +60,137 @@ model = ((PushPullSelectionStage) prevStage).getModel(); DataFlowGraph dataFlowGraph = ((PushPullSelectionStage) prevStage).getDataFlowGraph(); - controlFlowGraph = new ControlFlowGraph(dataFlowGraph); + controlFlowGraph = new ControlFlowGraph(dataFlowGraph); + + graph = clearControlFlowGraphCells(graph); + graph = constructGraph(graph, controlFlowGraph); -// graph = constructGraph(graph, model); // First, a mouse-event is "Showing delegatable Objects". - // curMouseAdapter = new SelectingACallEdgeAction(); - - // removeExistingDelegationMouseListener(graphComponent.getGraphControl(), curMouseAdapter); - // graphComponent.getGraphControl().addMouseListener(curMouseAdapter); } } - /**-------------------------------------------------------------------------------- + /************************************************************* * + * @return */ @Override public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { return new ControlFlowDelegationCellEditor(this, graphComponent); } - - /**-------------------------------------------------------------------------------- - /* [ *private ] - /**-------------------------------------------------------------------------------- - * remove an existing mouse event handler which is used in Control-Flow-Delegation Stage. - * @param graphControl - * @param mouseHandler + + /************************************************************* + * [ *private ] + /************************************************************* + * [ views ] + /************************************************************* + * + * @param graph + * @param dataFlowGraph */ - private void removeExistingDelegationMouseListener(mxGraphControl graphControl, MouseAdapter mouseHandler) { - if(graphControl.getMouseListeners().length <= 0) return; - - for(MouseListener listener : graphControl.getMouseListeners()) { - if(listener.getClass().equals(mouseHandler.getClass())) - graphControl.removeMouseListener(listener); - } - } + private mxGraph constructGraph(mxGraph graph, ControlFlowGraph controlFlowGraph) { + mxCell root = (mxCell) graph.getDefaultParent(); - /**-------------------------------------------------------------------------------- - * Construct a mxGraph from DataFlowModel + showOnlyLayer(graph, CONTROL_FLOW_LAYER); + + // Creating Control-Flow and separeted Push/Pull which types of + Map controlFlowNodeCells = createCellsOfResourceMap(graph, CONTROL_FLOW_LAYER, controlFlowGraph); + Map pushResNodeCells = createCellsOfResourceMap(graph, PUSH_FLOW_LAYER, controlFlowGraph); + Map pullResNodeCells = createCellsOfResourceMap(graph, PULL_FLOW_LAYER, controlFlowGraph); + + graph.getModel().beginUpdate(); + try { + // Inserting edges of both Push and Pull transfer + graph = insertControlFlowEdges(graph, CONTROL_FLOW_LAYER, controlFlowGraph.getPushCallGraph(),controlFlowNodeCells); + graph = insertControlFlowEdges(graph, CONTROL_FLOW_LAYER, controlFlowGraph.getPullCallGraph(),controlFlowNodeCells); + + // Inserting edges of each transfer + graph = insertControlFlowEdges(graph, PUSH_FLOW_LAYER, controlFlowGraph.getPushCallGraph(), pushResNodeCells); + graph = insertControlFlowEdges(graph, PULL_FLOW_LAYER, controlFlowGraph.getPullCallGraph(), pullResNodeCells); + } finally { + graph.getModel().endUpdate(); + } + return graph; + } + + /************************************************************* + * When changed from previous stage, it will be called in initializing. + * @return + */ + private mxGraph clearControlFlowGraphCells(mxGraph graph) { + mxCell root = (mxCell)graph.getDefaultParent(); + + graph.getModel().beginUpdate(); + try { + // removing child from end of a root cell + root.remove(root.getChildAt(PULL_FLOW_LAYER)); + root.remove(root.getChildAt(PUSH_FLOW_LAYER)); + root.remove(root.getChildAt(CONTROL_FLOW_LAYER)); + + root.insert(new mxCell()); + root.insert(new mxCell()); + root.insert(new mxCell()); + + } finally { + graph.getModel().endUpdate(); + } + + graph.refresh(); + + return graph; + } + + /************************************************************* + * Creating a map of to and Creating 's vertices * @param model * @param dataFlowGraph * @return constructed mxGraph */ - public mxGraph constructGraph(mxGraph graph, DataTransferModel model) { + private Map createCellsOfResourceMap(mxGraph graph, final int layerNumber, final ControlFlowGraph controlFlowGraph) { + Map resNodeCells = new HashMap<>(); + + mxCell root = (mxCell)graph.getDefaultParent(); + mxCell layerCell = (mxCell)root.getChildAt(layerNumber); + + // create resource vertices + for (ResourceNode resNode : controlFlowGraph.getDataFlowGraph().getResouceNodes()) { + IdentifierTemplate id = resNode.getIdentifierTemplate(); + Object resNodeObj = graph.insertVertex(layerCell, null, + id.getResourceName(), 20, 20, 80, 30, + "shape=ellipse;perimeter=ellipsePerimeter"); // insert a resource as a vertex + resNodeCells.put(resNode, resNodeObj); + } + + return resNodeCells; + } + + /************************************************************* + * + * @param graph + * @param layerNumber + * @param callGraph + * @param resNodeCells + * @return + */ + private mxGraph insertControlFlowEdges(mxGraph graph, final int layerNumber, final CallGraph callGraph ,final Map resNodeCells) { + 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) continue; + if(callEdge.getDestination() == null) continue; + + ResourceNode srcResNode = ((StatefulObjectNode)callEdge.getSource()).getResource(); + ResourceNode dstResNode = ((StatefulObjectNode)callEdge.getDestination()).getResource(); + + Object srcNodeCell =resNodeCells.get(srcResNode); + Object dstNodeCell = resNodeCells.get(dstResNode); + + graph.insertEdge(layerCell, null, null/*callEdgeAttribute*/,srcNodeCell, dstNodeCell, "movable=false"); + } return graph; } - - /**-------------------------------------------------------------------------------- - * [ *handler ] - /**-------------------------------------------------------------------------------- - * 委譲する基点となる呼び出し辺(データフロー)の選択 - */ - public class SelectingACallEdgeAction extends MouseAdapter { - private StatefulObjectNode statefulObjNode = null; - private mxGraphComponent graphComponent = null; - - /**-------------------------------------------------------------------------------- - * [ *constructor ] - /**-------------------------------------------------------------------------------- - * - */ - public SelectingACallEdgeAction(mxGraphComponent graphComponent) { - this.graphComponent = graphComponent; - } - - /**-------------------------------------------------------------------------------- - * - /**-------------------------------------------------------------------------------- - * - */ - @Override - public void mouseClicked(MouseEvent e) { - mxCell cell = graphComponent.getCellAt(e.getX(), e.getY()) instanceof mxCell - ? (mxCell) graphComponent.getCellAt(e.getX(), e.getY()) - : null; - if(cell == null) return; - - String resourceName = graph.getModel().getValue(cell) instanceof String - ? graph.getModel().getValue(cell).toString() - : null; - if(resourceName == null) return; - - IdentifierTemplate identifireTemplate = model.getIdentifierTemplate(resourceName); - if(identifireTemplate == null) return; - - ResourceNode resNode = controlFlowGraph.getDataFlowGraph().getResouceNode(identifireTemplate); - - // - // statefulObjNode = controlFlowGraph. - - System.out.println("show: " + identifireTemplate.getResourceName()); - } - } - } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index f94754f..76176e5 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -49,6 +49,7 @@ @Override public void init(Stage prevStage) { + showOnlyLayer(graph, NODE_LAYER, DATA_FLOW_LAYER); } @Override @@ -65,8 +66,10 @@ graph.getModel().beginUpdate(); try { root.insert(new mxCell()); // NODE_LAYER, DATA_FLOW_LAYER + root.insert(new mxCell()); // CONTROL_FLOW_LAYER root.insert(new mxCell()); // PUSH_FLOW_LAYER root.insert(new mxCell()); // PULL_FLOW_LAYER + showOnlyLayer(graph, NODE_LAYER, DATA_FLOW_LAYER); } finally { graph.getModel().endUpdate(); } @@ -105,6 +108,7 @@ mxCell root = (mxCell) graph.getDefaultParent(); mxCell nodeLayer = (mxCell) root.getChildAt(NODE_LAYER); mxCell dataFlowLayer = (mxCell) root.getChildAt(DATA_FLOW_LAYER); + graph.getModel().beginUpdate(); try { mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER, PORT_DIAMETER); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index 7c8c8c2..d3b3318 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -2,15 +2,14 @@ import com.mxgraph.model.mxCell; import com.mxgraph.swing.mxGraphComponent; -import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.view.mxGraph; import algorithms.DataTransferModelAnalyzer; -import application.editor.Stage; import application.editor.Editor.SrcDstAttribute; +import application.editor.FlowCellEditor; import application.editor.InEdgeAttribute; import application.editor.OutEdgeAttribute; -import application.editor.FlowCellEditor; +import application.editor.Stage; import models.Edge; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; @@ -42,6 +41,10 @@ model = ((DataFlowModelingStage) prevStage).getModel(); dataFlowGraph = analyzeDataTransferModel(graph, model); } + + if(prevStage instanceof ControlFlowDelegationStage) { + showOnlyLayer(graph, NODE_LAYER, DATA_FLOW_LAYER); + } } @Override @@ -63,6 +66,7 @@ private void updateEdgeAttiributes(mxGraph graph, DataFlowGraph dataFlowGraph) { mxCell root = (mxCell) graph.getDefaultParent(); mxCell layer = (mxCell) root.getChildAt(DATA_FLOW_LAYER); + graph.getModel().beginUpdate(); try { // update attributes of input and output edges diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java new file mode 100644 index 0000000..9164d5c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java @@ -0,0 +1,39 @@ +package models.controlFlowModel; + +import models.EdgeAttribute; +import models.dataFlowModel.PushPullValue; + +public class CallEdgeAttribute extends EdgeAttribute { + private PushPullValue selectedOption; + private ObjectNode srcObjNode; + private ObjectNode dstObjNode; + + /************************************************************* + * [ *constructor ] + /************************************************************* + * + */ + public CallEdgeAttribute(PushPullValue selectedOption, ObjectNode srcObjNode, ObjectNode dstObjNode) { + this.selectedOption = selectedOption; + this.srcObjNode = srcObjNode; + this.dstObjNode = dstObjNode; + } + + /************************************************************* + * [ *public ] + /************************************************************* + * [ getter ] + /*************************************************************/ + public PushPullValue getSelectedOption() { + return selectedOption; + } + + public ObjectNode getSourceObjectNode() { + return srcObjNode; + } + + public ObjectNode getDestinationObjectNode() { + return dstObjNode; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java index c2ae6db..23012bf 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java @@ -1,16 +1,11 @@ package models.controlFlowModel; -import java.util.Map; -import java.util.Set; - -import models.DirectedGraph; import models.Edge; -import models.Node; -import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.ResourceNode; import models.dataFlowModel.DataFlowEdge; +import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; +import models.dataFlowModel.ResourceNode; public class ControlFlowGraph { private DataFlowGraph dataFlowGraph; diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java index 861a51c..dde47b2 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java @@ -1,5 +1,6 @@ package models.dataFlowModel; +import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -38,6 +39,10 @@ addEdge(new DataFlowEdge(srcNode, dstNode, dfChannelGen)); } + public Collection getResouceNodes(){ + return nodeMap.values(); + } + public ResourceNode getResouceNode(IdentifierTemplate identifierTemplate) { if(nodeMap.get(identifierTemplate) == null) throw new NullPointerException(identifierTemplate.getResourceName() + "was not found."); return nodeMap.get(identifierTemplate);