diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java index 039c4bd..c837ba4 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationMenuBar.java @@ -25,9 +25,12 @@ import application.editor.Editor; public class ApplicationMenuBar extends JMenuBar { - private static final long serialVersionUID = 4811536194182272888L; + private static final long serialVersionUID = 4811536194182272888L; + + private Editor editor = null; private ApplicationWindow applicationWindow = null; + private NewResourceAction newResourceAction = null; private NewChannelAction newChannelAction = null; private NewIOChannelAction newIOChannelAction = null; @@ -38,9 +41,10 @@ private DAGLayoutAction dagLayoutAction = null; private TreeLayoutAction treeLayoutAction = null; private CircleLayoutAction circleLayoutAction = null; - + public ApplicationMenuBar(ApplicationWindow applicationWindow) { this.applicationWindow = applicationWindow; + this.editor = editor; JMenu newMenu = new JMenu("New"); newMenu.add(new NewModelAction(applicationWindow)); diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index bd82ef3..e6d16e2 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -19,7 +19,7 @@ import application.editor.Editor; import application.editor.stages.DataFlowCellEditor; import application.views.NavigationWindow; -import application.views.SwitchDisplayFlowWindow; +import application.views.controlFlowDelegation.FlowLayerWindow; public class ApplicationWindow extends JFrame { private static final long serialVersionUID = -8690140317781055614L; @@ -31,7 +31,7 @@ private ApplicationMenuBar menuBar = null; private NavigationWindow navigationWindow = null; - private SwitchDisplayFlowWindow switchDisplayFlowWindow = null; + private FlowLayerWindow switchDisplayFlowWindow = null; public ApplicationWindow() { setTitle(title); @@ -55,21 +55,21 @@ graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { public void invoke(Object sender, mxEventObject evt) { - List terminals = new ArrayList<>(); - mxCell cell = null; - for (Object change: ((List) evt.getProperties().get("changes"))) { - if (change instanceof mxGraphModel.mxTerminalChange) { - mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; - cell = (mxCell) terminalChange.getCell(); - mxCell terminal = (mxCell) terminalChange.getTerminal(); - terminals.add(terminal); - } - } - if (terminals.size() == 2) { - if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { - graph.removeCells(new mxCell[] {cell}); - } - } +// List terminals = new ArrayList<>(); +// mxCell cell = null; +// for (Object change: ((List) evt.getProperties().get("changes"))) { +// if (change instanceof mxGraphModel.mxTerminalChange) { +// mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; +// cell = (mxCell) terminalChange.getCell(); +// mxCell terminal = (mxCell) terminalChange.getTerminal(); +// terminals.add(terminal); +// } +// } +// if (terminals.size() == 2) { +// if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { +// graph.removeCells(new mxCell[] {cell}); +// } +// } } }); getContentPane().add(graphComponent); @@ -84,7 +84,7 @@ navigationWindow = new NavigationWindow(this, editor); navigationWindow.setVisible(true); - switchDisplayFlowWindow = new SwitchDisplayFlowWindow(this, editor); + switchDisplayFlowWindow = new FlowLayerWindow(this); switchDisplayFlowWindow.setVisible(false); editor.addStageChangeListener(navigationWindow); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 12eafb3..9320731 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -57,7 +57,7 @@ protected Stage curStage = null; protected List stageQueue = null; private List stageChangeListeners = null; - + protected String curFileName = null; protected String curFilePath = null; protected ArrayList codes = null; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java index 76cbb8c..a154445 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Stage.java @@ -37,14 +37,27 @@ abstract public boolean canChangeFrom(Stage prevStage); abstract public void init(Stage prevStage); abstract public mxICellEditor createCellEditor(mxGraphComponent graphComponent); + /************************************************************* - * [ *protected ] + * [ *public ] + /************************************************************* + * + */ + 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(); + } + /************************************************************* * Showing layers are specified number of layers. * @param you want to show numbers of layers. */ - protected void showOnlyLayer(mxGraph graph, final int... argsOfLayers) { + public void showOnlyLayer(final int... argsOfLayers) { mxCell rootCell = (mxCell) graph.getDefaultParent(); if(rootCell== null) return; if(rootCell.getChildCount() <= 0) return; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java index ddac887..b0a468d 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationCellEditor.java @@ -23,6 +23,7 @@ */ public class ControlFlowDelegationCellEditor extends FlowCellEditor { private ControlFlowDelegationStageStatus curState = null; + private mxCell targetEdgeCell = null; /************************************************************* * [ *constructor ] @@ -54,14 +55,20 @@ @Override public void startEditing(Object cellObj, EventObject eventObj) { if( editingCell != null) stopEditing(true); - + + System.out.println("state:" + curState.name()); + switch(curState) { 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; @@ -70,15 +77,19 @@ mxCellState state = graphComponent.getGraph().getView().getState(cellObj); if(state == null || state.getLabel() == null || state.getLabel().equals("")) return; - changeCallOrderOfCallEdge(cellObj); - + changeCallOrderOfCallEdge(cellObj); } break; case SHOWING_DELEGATABLE_NODES: if( graphComponent.getGraph().getModel().isVertex(cellObj) ) { - System.out.println("move delegating state."); - // invocating delegation method + // invocating delegation method + if(!(cellObj instanceof mxCell)) throw new ClassCastException(); + + ((ControlFlowDelegationStage)stage) + .showDelegatedGraph(graphComponent.getGraph(), targetEdgeCell, (mxCell)cellObj); + + curState = ControlFlowDelegationStageStatus.SELECTING_AN_EDGE; } else { System.out.println("cancel showing state."); @@ -117,7 +128,7 @@ /************************************************************* * */ - private void changeCallOrderOfCallEdge(Object cellObj) { + private void changeCallOrderOfCallEdge(final Object cellObj) { String input = ""; int inputOrder = 0; @@ -136,7 +147,7 @@ final int endOfOrderOfSrc = callEdgeAttr.getSourceObjectNode().getOutdegree(); if(inputOrder <= 0 || endOfOrderOfSrc < inputOrder) { - JOptionPane.showMessageDialog(graphComponent, "Input order must be between 0 and " + endOfOrderOfSrc + "."); + JOptionPane.showMessageDialog(graphComponent, "Input order must be between 1 and " + endOfOrderOfSrc + "."); return; } @@ -181,6 +192,7 @@ /************************************************************* * [ *inner class ] /************************************************************* + * [ action ] * Inserting an intermediation object type of . */ private class InsertObjectNodeAction extends MouseAdapter { @@ -190,8 +202,13 @@ // 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; @@ -217,5 +234,6 @@ ((ControlFlowDelegationStage)stage) .insertObjectNodeCellInControlFlowLayer(graphComponent.getGraph(), edgeCell, objName); } + } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index 6171996..64360b3 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -5,20 +5,25 @@ import java.util.Map; import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxPoint; import com.mxgraph.view.mxGraph; import application.editor.FlowCellEditor; import application.editor.Stage; import models.Edge; +import models.Node; import models.controlFlowModel.CallEdge; import models.controlFlowModel.CallEdgeAttribute; import models.controlFlowModel.CallGraph; import models.controlFlowModel.ControlFlowDelegator; import models.controlFlowModel.ControlFlowGraph; +import models.controlFlowModel.EntryPointObjectNode; import models.controlFlowModel.ObjectNode; import models.controlFlowModel.ObjectNodeAttribute; import models.controlFlowModel.StatefulObjectNode; +import models.dataConstraintModel.ChannelGenerator; import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResourceNode; @@ -47,8 +52,6 @@ * [ *public ] /************************************************************* * - * @param prevStage - * @return */ @Override public boolean canChangeFrom(Stage prevStage) { @@ -58,7 +61,6 @@ /************************************************************* * - * @param prevStage */ @Override public void init(Stage prevStage) { @@ -118,6 +120,41 @@ } finally { graph.getModel().endUpdate(); + graph.refresh(); + } + } + + /************************************************************* + * Showing the delegated graph. + */ + 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 controlLayerCell = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); + try { + mxCell dstNodeCell = targetEdgeAttr.getDestinationCell(); + + // Removing the target edge from graph model. + if(graph.getModel().getValue(targetEdgeCell) != null) { + graph.getModel().remove(targetEdgeCell); + } + + // Insert an edge + CallEdgeAttribute newAttr = new CallEdgeAttribute(targetEdgeAttr.getCallEdge(), dstObjNodeCell, dstNodeCell); + graph.insertEdge(controlLayerCell, "", newAttr, dstObjNodeCell, dstNodeCell, "movable=false;"); + + resetGraph(); + } + finally { + graph.getModel().endUpdate(); } } @@ -137,25 +174,26 @@ if(node instanceof mxCell) cell = (mxCell)node; else continue; - ObjectNodeAttribute objNodeAttr = null; - if(cell.getValue() instanceof ObjectNodeAttribute) - objNodeAttr = (ObjectNodeAttribute) cell.getValue(); - else throw new NullPointerException(""); + ObjectNodeAttribute objNodeAttr = (ObjectNodeAttribute)(cell.getValue()); + + if(objNodeAttr == null) throw new NullPointerException(""); graph.getModel().setStyle(cell, objNodeAttr.getDefaultStyle()); } } finally { graph.getModel().endUpdate(); + graph.refresh(); } } /************************************************************* * Inserting an intermediation object type of . + * todo: support to PUSH/PULL-layer */ public void insertObjectNodeCellInControlFlowLayer(mxGraph graph, mxCell targetEdge, final String insertObjName) { mxCell root = (mxCell)graph.getDefaultParent(); - mxCell contorlLayerCell = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); + mxCell controlLayerCell = (mxCell)root.getChildAt(CONTROL_FLOW_LAYER); CallEdgeAttribute callEdgeAttr = (CallEdgeAttribute)targetEdge.getValue(); if(callEdgeAttr == null) throw new NullPointerException(); @@ -166,7 +204,19 @@ // Inserting the node type of to the graph. ObjectNode insertObjNode = new ObjectNode(insertObjName); ObjectNodeAttribute objNodeAttr = new ObjectNodeAttribute(insertObjNode); - mxCell insertObjNodeCell = (mxCell)graph.insertVertex(contorlLayerCell, null, objNodeAttr, 20, 20, 40, 40, objNodeAttr.getDefaultStyle()); + + + mxPoint srcPoint = new mxPoint(callEdgeAttr.getSourceCell().getGeometry().getX(), callEdgeAttr.getSourceCell().getGeometry().getY()); + mxPoint dstPoint = new mxPoint(callEdgeAttr.getDestinationCell().getGeometry().getX(), callEdgeAttr.getDestinationCell().getGeometry().getY()); + mxPoint insertPoint = new mxPoint( + (srcPoint.getX() + dstPoint.getX())/2, + (srcPoint.getY() + dstPoint.getY())/2); + + mxCell insertObjNodeCell = + (mxCell)graph.insertVertex(controlLayerCell, null, objNodeAttr, + /* coordinate*/ insertPoint.getX(), insertPoint.getY(), + /* scale */ 40, 40, + objNodeAttr.getDefaultStyle()); insertObjNodeCell.setValue(objNodeAttr); @@ -189,8 +239,8 @@ insertObjNode.addInEdge(srcToInsertEdge); insertObjNode.addOutEdge(insertToDstEdge); - for(int i =0; i < contorlLayerCell.getChildCount(); i++) { - mxCell nodeCell = (mxCell)contorlLayerCell.getChildAt(i); + for(int i =0; i < controlLayerCell.getChildCount(); i++) { + mxCell nodeCell = (mxCell)controlLayerCell.getChildAt(i); if( !nodeCell.isVertex()) continue; // Checking "nodeCell" has an instance of @@ -204,10 +254,10 @@ // If the target call edge hasn't removed yet. // then it removes from mxGraphModel. - if(graph.getModel().getValue(targetEdge) == null) return; - graph.getModel().remove(targetEdge); + if(graph.getModel().getValue(targetEdge) != null) + graph.getModel().remove(targetEdge); - graph.insertEdge(contorlLayerCell, null, newInEdgeAttr, srcNodeCell, insertObjNodeCell, "movable=false;"); + graph.insertEdge(controlLayerCell, null, newInEdgeAttr, srcNodeCell, insertObjNodeCell, "movable=false;"); continue; } @@ -217,10 +267,10 @@ CallEdgeAttribute newOutEdgeAttr = new CallEdgeAttribute(insertToDstEdge, insertObjNodeCell, dstNodeCell); // If the target - if(graph.getModel().getValue(targetEdge) == null) return; - graph.getModel().remove(targetEdge); + if(graph.getModel().getValue(targetEdge) != null) + graph.getModel().remove(targetEdge); - graph.insertEdge(contorlLayerCell, null, newOutEdgeAttr, insertObjNodeCell, dstNodeCell, "movable=false;"); + graph.insertEdge(controlLayerCell, null, newOutEdgeAttr, insertObjNodeCell, dstNodeCell, "movable=false;"); continue; } @@ -231,13 +281,14 @@ } } + /************************************************************* * [ *private ] /************************************************************* * */ private mxGraph constructGraph(mxGraph graph, ControlFlowGraph controlFlowGraph) { - showOnlyLayer(graph, CONTROL_FLOW_LAYER); + showOnlyLayer(CONTROL_FLOW_LAYER); graph.getModel().beginUpdate(); try { @@ -246,10 +297,13 @@ Map pushResNodeCells = createCellsOfResourceMap(graph, PUSH_FLOW_LAYER, controlFlowGraph); Map pullResNodeCells = createCellsOfResourceMap(graph, PULL_FLOW_LAYER, controlFlowGraph); + // Creating Entry-Point Object + // Map channelsIn = createCellsOfInputChannel(graph, CONTROL_FLOW_LAYER, controlFlowGraph, controlFlowNodeCells); + // Inserting edges of each transfer graph = insertControlFlowEdges(graph, PUSH_FLOW_LAYER, controlFlowGraph.getPushCallGraph(), pushResNodeCells); graph = insertControlFlowEdges(graph, PULL_FLOW_LAYER, controlFlowGraph.getPullCallGraph(), pullResNodeCells); - + // 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); @@ -349,7 +403,55 @@ return resNodeCells; } + /************************************************************* + * Createing an input channel object + */ + private Map createCellsOfInputChannel(mxGraph graph, final int layerNumber, final ControlFlowGraph controlGraph, final Map resNodeCell){ + mxCell root = (mxCell)graph.getDefaultParent(); +// mxCell nodeLayerCell = (mxCell)root.getChildAt(NODE_LAYER); + 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); + outPortGeometry.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); + outPortGeometry.setRelative(true); + + // insert an I/O channel as a vertex + for (ChannelGenerator ioChannelGen: model.getIOChannelGenerators()) { + Object channel = graph.insertVertex(layerCell, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); + mxCell port_out = new mxCell(null, outPortGeometry, "shape=ellipse;perimter=ellipsePerimeter"); + port_out.setVertex(true); + graph.addCell(port_out, channel); // insert the output port of a channel + + EntryPointObjectNode entryPointObjNode = new EntryPointObjectNode(ioChannelGen.getChannelName()); + CallGraph callGraph = null; + if(layerNumber == PUSH_FLOW_LAYER) { + callGraph = controlFlowGraph.getPushCallGraph(); + for (Node node : callGraph.getNodes()) { + StatefulObjectNode statefulObjNode = (StatefulObjectNode)node; + if( !ioChannelGen.getIdentifierTemplates().contains(statefulObjNode.getResource().getIdentifierTemplate())) + continue; +// controlFlowGraph.getPushCallGraph().addNode(entryPointObjNode); +// controlFlowGraph.getPushCallGraph().addEdge(entryPointObjNode, statefulObjectNode, PushPullValue.PUSH); + + + graph.insertEdge(layerCell, null, null, port_out, resNodeCell.get(statefulObjNode), "movable=false;strokeColor=#FF0000"); + } + + } + ioChannelCells.put(entryPointObjNode, port_out); + } + } + finally { + graph.getModel().endUpdate(); + } + + return ioChannelCells; + } + /************************************************************* * When changed from previous stage, it will be called in initializing. */ @@ -377,7 +479,7 @@ } return graph; } - + /************************************************************* * */ @@ -396,5 +498,6 @@ break; } - } + } + } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index 0fd74f4..d9628a8 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -67,7 +67,7 @@ */ @Override public void init(Stage prevStage) { - showOnlyLayer(graph, NODE_LAYER, DATA_FLOW_LAYER); + showOnlyLayer(DATA_FLOW_LAYER); } /************************************************************* @@ -94,7 +94,7 @@ root.insert(new mxCell()); // PUSH_FLOW_LAYER root.insert(new mxCell()); // PULL_FLOW_LAYER - showOnlyLayer(graph, NODE_LAYER, DATA_FLOW_LAYER); + showOnlyLayer(NODE_LAYER, DATA_FLOW_LAYER); } finally { graph.getModel().endUpdate(); @@ -210,9 +210,11 @@ port_out.setVertex(true); graph.addCell(port_out, channel); // insert the output port of a channel channelsOut.put((DataTransferChannelGenerator) ioChannelGen, port_out); + for (IdentifierTemplate outRes: ((DataTransferChannelGenerator) ioChannelGen).getOutputIdentifierTemplates()) { graph.insertEdge(dataFlowLayer, null, null, port_out, resources.get(outRes), "movable=false;strokeColor=#FF0000"); } + } } } finally { diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index d3b3318..6224fd9 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -40,10 +40,11 @@ if (prevStage instanceof DataFlowModelingStage) { model = ((DataFlowModelingStage) prevStage).getModel(); dataFlowGraph = analyzeDataTransferModel(graph, model); + showOnlyLayer(DATA_FLOW_LAYER); } if(prevStage instanceof ControlFlowDelegationStage) { - showOnlyLayer(graph, NODE_LAYER, DATA_FLOW_LAYER); + showOnlyLayer(DATA_FLOW_LAYER); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/SwitchDisplayFlowWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/SwitchDisplayFlowWindow.java deleted file mode 100644 index 5bfd503..0000000 --- a/AlgebraicDataflowArchitectureModel/src/application/views/SwitchDisplayFlowWindow.java +++ /dev/null @@ -1,59 +0,0 @@ -package application.views; - -import java.awt.Container; -import java.awt.GridLayout; - -import javax.swing.ButtonGroup; -import javax.swing.JDialog; -import javax.swing.JToggleButton; - -import application.ApplicationWindow; -import application.editor.Editor; - -/************************************************************* - * the window has a button group for swichting layers in the control-flow-modeling. - */ -public class SwitchDisplayFlowWindow extends JDialog { - private String title = "ShowLayer"; - private Editor editor = null; - private JToggleButton enableControlFlowLayerButton = null; - private JToggleButton enablePushFlowLayerButton = null; - private JToggleButton enablePullFlowLayerButton = null; - - /************************************************************* - * [ *constructor ] - /************************************************************* - * - */ - public SwitchDisplayFlowWindow(final ApplicationWindow owner, final Editor editor) { - super(owner); - this.editor = editor; - - setTitle(title); - setDefaultCloseOperation(HIDE_ON_CLOSE); - - // initialize buttons - enableControlFlowLayerButton = new JToggleButton("PUSH/PULL-Flow"); - enablePushFlowLayerButton = new JToggleButton("PUSH-Flow"); - enablePullFlowLayerButton = new JToggleButton("PULL-Flow"); - - enableControlFlowLayerButton.setEnabled(true); - enableControlFlowLayerButton.setEnabled(false); - enableControlFlowLayerButton.setEnabled(false); - - ButtonGroup buttonGroup = new ButtonGroup(); - buttonGroup.add(enableControlFlowLayerButton); - buttonGroup.add(enablePushFlowLayerButton); - buttonGroup.add(enablePullFlowLayerButton); - - // initialize panel - Container panel = getContentPane(); - panel.setLayout(new GridLayout(/*low*/3, /*col*/1)); - panel.add(enableControlFlowLayerButton); - panel.add(enablePushFlowLayerButton); - panel.add(enablePullFlowLayerButton); - pack(); - setResizable(false); - } - -} diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/FlowLayerValue.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/FlowLayerValue.java new file mode 100644 index 0000000..0c9317c --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/FlowLayerValue.java @@ -0,0 +1,10 @@ +package application.views.controlFlowDelegation; + +/************************************************************* + * + */ +public enum FlowLayerValue { + DATA_FLOW, + PUSH_FLOW, + PULL_FLOW +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/FlowLayerWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/FlowLayerWindow.java new file mode 100644 index 0000000..f78fa03 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/views/controlFlowDelegation/FlowLayerWindow.java @@ -0,0 +1,80 @@ +package application.views.controlFlowDelegation; + +import java.awt.Container; +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; +import application.editor.IStageChangeListener; +import application.editor.Stage; +import application.editor.stages.ControlFlowDelegationStage; + +/************************************************************* + * the window has a button group for swichting layers in the control-flow-modeling. + */ +public class FlowLayerWindow extends JDialog implements ActionListener, IStageChangeListener { + private String title = "ShowFlowLayer"; + private Map checkBoxes = null; + private ControlFlowDelegationStage stage = null; + + /************************************************************* + * [ *constructor ] + /************************************************************* + * + */ + public FlowLayerWindow(final ApplicationWindow owner) { + super(owner); + + setTitle(title); + setDefaultCloseOperation(HIDE_ON_CLOSE); + + // initialize buttons + checkBoxes = new HashMap<>(); + checkBoxes.put(FlowLayerValue.DATA_FLOW, new JCheckBox("Data-Flow")); + checkBoxes.put(FlowLayerValue.PUSH_FLOW, new JCheckBox("Push-Flow")); + checkBoxes.put(FlowLayerValue.PULL_FLOW, new JCheckBox("Pull-Flow")); + + ButtonGroup buttonGroup = new ButtonGroup(); + for(JCheckBox checkBox : checkBoxes.values()) { + buttonGroup.add(checkBox); + checkBox.setEnabled(true); + } + + // initialize panel + Container panel = getContentPane(); + panel.setLayout(new GridLayout(/*low*/3, /*col*/1)); + for(JCheckBox checkBox : checkBoxes.values()) { + panel.add(checkBox); + } + pack(); + setResizable(false); + } + + /************************************************************* + * [ *public ] + /************************************************************* + * + */ + @Override + public void actionPerformed(ActionEvent e) { + stage.setEnabledForLayer(Stage.DATA_FLOW_LAYER, checkBoxes.get(FlowLayerValue.DATA_FLOW).isSelected()); + stage.setEnabledForLayer(Stage.PUSH_FLOW_LAYER, checkBoxes.get(FlowLayerValue.PUSH_FLOW).isSelected()); + stage.setEnabledForLayer(Stage.PULL_FLOW_LAYER, checkBoxes.get(FlowLayerValue.PULL_FLOW).isSelected()); + } + + @Override + public void stageChanged(Stage newStage) { + if(!(newStage instanceof ControlFlowDelegationStage))return; + + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java index 66a8807..21b9322 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/CallEdgeAttribute.java @@ -57,6 +57,10 @@ return dstCell; } + public void setDestinationCell(final mxCell dstCell) { + this.dstCell = dstCell; + } + /************************************************************* * */ diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java index 3c972b2..2d0b5de 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowDelegator.java @@ -3,13 +3,7 @@ import java.util.ArrayList; import java.util.List; -import javax.swing.event.ListDataEvent; - import models.Edge; -import models.Node; -import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.PushPullAttribute; -import models.dataFlowModel.PushPullValue; /************************************************************* * it has Delegation of Control-Flow algorithm. @@ -54,15 +48,35 @@ // 3. if the transfer method is PUSH-style, // then serach delegatable area. - collectParentNodesInPushTransfer(nodes, parentNode); + collectParentNodesInPushTransfer(nodes, delegatingNode, parentNode); // switch objects by transfer type return nodes; } /************************************************************* + * + */ + public void delegateCallEdge(CallEdge delegatingEdge, final ObjectNode dstObjNode) { + ObjectNode srcObjNode = (ObjectNode)delegatingEdge.getDestination(); + if(srcObjNode == null) throw new ClassCastException(); + + delegatingEdge.getSource().removeOutEdge(delegatingEdge); + srcObjNode.removeInEdge(delegatingEdge); + + // Reconnecting the edge to the new source object. + delegatingEdge.setDestination(srcObjNode); + delegatingEdge.setSource(dstObjNode); + + srcObjNode.addInEdge(delegatingEdge); + dstObjNode.addOutEdge(delegatingEdge); + } + + /************************************************************* * [* private ] /************************************************************* + * [ search ] + /************************************************************* * Collecting nodes in the "nodes" parameter for each transfer method has nodes in the common area. * @param nodes * @param curObjNode @@ -87,42 +101,51 @@ * @param result in "nodes" parameter. * @param curObjNode */ - private void collectParentNodesInPushTransfer(List nodes, ObjectNode curObjNode) { + private void collectParentNodesInPushTransfer(List nodes, ObjectNode curObjNode, final ObjectNode parentDelegatingNode) { if( isRootNode(curObjNode) ) return; if( isInEdgesConversingToNode(curObjNode) ) return; - - if( !(curObjNode.getInEdge(0).getSource() instanceof ObjectNode)) - throw new ClassCastException(); - + ObjectNode parentObjNode = (ObjectNode)curObjNode.getInEdge(0).getSource(); - nodes.add(parentObjNode); + if(parentObjNode == null) return; + + if( !parentDelegatingNode.equals(parentObjNode) ) + nodes.add(parentObjNode); int inEdgeCallOrder = parentObjNode.getOutEdgeCallOrder(curObjNode.getInEdge(0)); for(Edge edge : parentObjNode.getOutEdges()) { if( !(edge instanceof CallEdge)) continue; - int callOrder = curObjNode.getOutEdgeCallOrder((CallEdge)edge); - if(inEdgeCallOrder < callOrder) collectChildNodesInPushTransfer(nodes, parentObjNode); + int callOrder = parentObjNode.getOutEdgeCallOrder((CallEdge)edge); + if(inEdgeCallOrder < callOrder) collectChildNodesInPushTransfer(nodes, (CallEdge)edge); } - collectParentNodesInPushTransfer(nodes, parentObjNode); + collectParentNodesInPushTransfer(nodes, parentObjNode, parentDelegatingNode); } /************************************************************* * * @param node */ - private void collectChildNodesInPushTransfer(List nodes, ObjectNode curObjNode) { - if( !hasChildrenNode(curObjNode)) return; + private void collectChildNodesInPushTransfer(List nodes, CallEdge callEdge) { + ObjectNode dstObjNode = (ObjectNode)callEdge.getDestination(); + if(dstObjNode == null) return; - for(Edge e : curObjNode.getOutEdges()) { - ObjectNode foundNode = (ObjectNode)e.getDestination(); - nodes.add(foundNode); + nodes.add(dstObjNode); + + if(!hasChildrenNode(dstObjNode)) return; + + for(Edge e : dstObjNode.getOutEdges()) { + CallEdge edge = (CallEdge)e; + if(edge == null) continue; - collectChildNodesInPushTransfer(nodes, curObjNode); + ObjectNode foundNode = (ObjectNode)e.getDestination(); + if(foundNode == null) continue; + if(nodes.contains(foundNode))continue; + + collectChildNodesInPushTransfer(nodes, edge); } } - + /************************************************************* * * @param node