diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java index ca28124..8715432 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/editor/Editor.java @@ -226,9 +226,6 @@ } } } - - graph.setAllowDanglingEdges(false); - graph.setCellsDisconnectable(false); } finally { graph.getModel().endUpdate(); } @@ -261,4 +258,24 @@ graph.getModel().endUpdate(); } } + + public boolean connectEdge(mxCell src, mxCell dst) { + ChannelGenerator srcCh = model.getChannelGenerator((String) src.getValue()); + if (srcCh == null) { + srcCh = model.getIOChannelGenerator((String) src.getValue()); + if (srcCh == null) { + IdentifierTemplate srcRes = model.getIdentifierTemplate((String) src.getValue()); + ChannelGenerator dstCh = model.getChannelGenerator((String) dst.getValue()); + if (srcRes == null || dstCh == null) return false; + ChannelMember srcCm = new ChannelMember(srcRes); + ((DataflowChannelGenerator ) dstCh).addChannelMemberAsInput(srcCm); + return true; + } + } + IdentifierTemplate dstRes = model.getIdentifierTemplate((String) dst.getValue()); + if (dstRes == null) return false; + ChannelMember dstCm = new ChannelMember(dstRes); + ((DataflowChannelGenerator) srcCh).addChannelMemberAsOutput(dstCm); + return true; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java index 8c93eba..fe75489 100644 --- a/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java +++ b/AlgebraicDataflowArchitectureModel/src/graphicalrefactor/views/GraphicalRefactor.java @@ -1,11 +1,19 @@ package graphicalrefactor.views; +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 graphicalrefactor.editor.Editor; @@ -39,8 +47,26 @@ return new ComboBoxCellEditor(this); } }; + graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { + public void invoke(Object sender, mxEventObject evt) { + List terminals = new ArrayList<>(); + for (Object change: ((List) evt.getProperties().get("changes"))) { + if (change instanceof mxGraphModel.mxTerminalChange) { + mxGraphModel.mxTerminalChange terminalChange = (mxGraphModel.mxTerminalChange) change; + mxCell cell = (mxCell) terminalChange.getCell(); + mxCell terminal = (mxCell) terminalChange.getTerminal(); + terminals.add(terminal); + } + } + if (terminals.size() == 2) { + editor.connectEdge(terminals.get(0), terminals.get(1)); + } + } + }); getContentPane().add(graphComponent); new mxRubberband(graphComponent); + graph.setAllowDanglingEdges(false); + graph.setCellsDisconnectable(true); editor = new Editor(graph); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 4643b4c..d81269c 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -273,6 +273,10 @@ return ioChannelGenerators.values(); } + public ChannelGenerator getIOChannelGenerator(String channelName) { + return ioChannelGenerators.get(channelName); + } + public void setIOChannelGenerators(HashMap ioChannelGenerators) { this.ioChannelGenerators = ioChannelGenerators; for (ChannelGenerator g: ioChannelGenerators.values()) {