diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index e2dc634..3c8dbc0 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -1,6 +1,7 @@ package application.editor; import application.editor.stages.DataFlowModelingStage; +import application.editor.stages.DependencyModelingStage; import application.editor.stages.PushPullSelectionStage; import application.layouts.DAGLayout; import code.ast.CompilationUnit; @@ -52,6 +53,7 @@ public static DataFlowModelingStage STAGE_DATA_FLOW_MODELING = null; public static PushPullSelectionStage STAGE_PUSH_PULL_SELECTION = null; + public static DependencyModelingStage STAGE_DEPENDENCY_MODELING = null; public Editor(mxGraphComponent graphComponent) { this.graphComponent = graphComponent; @@ -59,6 +61,7 @@ STAGE_DATA_FLOW_MODELING = new DataFlowModelingStage(graphComponent); STAGE_PUSH_PULL_SELECTION = new PushPullSelectionStage(graphComponent); + STAGE_DEPENDENCY_MODELING = new DependencyModelingStage(graphComponent); graphComponent.setCellEditor(STAGE_DATA_FLOW_MODELING.createCellEditor(graphComponent)); @@ -488,7 +491,7 @@ } public void addFormulaChannel(String channelName, Symbol op) { - // Force to change to data-flow modeling stage + // Forceget to change to data-flow modeling stage boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) { return; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java new file mode 100644 index 0000000..e8b5e13 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyCellEditor.java @@ -0,0 +1,27 @@ +package application.editor.stages; + +import application.editor.FlowCellEditor; +import com.mxgraph.model.mxCell; +import com.mxgraph.swing.mxGraphComponent; +import models.dataFlowModel.DataTransferChannel; + +import javax.swing.*; +import java.awt.*; +import java.util.EventObject; + +public class DependencyCellEditor extends FlowCellEditor { + + public DependencyCellEditor(DependencyModelingStage stage, mxGraphComponent graphComponent) { + super(stage, graphComponent); + } + + @Override + public void startEditing(Object cellObj, EventObject eventObj) { + + } + + @Override + public void stopEditing(boolean cancel) { + + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java new file mode 100644 index 0000000..684f27f --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DependencyModelingStage.java @@ -0,0 +1,80 @@ +package application.editor.stages; + +import algorithms.Validation; +import application.editor.Editor; +import application.editor.FlowCellEditor; +import application.editor.Stage; +import com.mxgraph.model.mxCell; +import com.mxgraph.model.mxGeometry; +import com.mxgraph.model.mxGraphModel; +import com.mxgraph.model.mxGraphModel.mxTerminalChange; +import com.mxgraph.swing.mxGraphComponent; +import com.mxgraph.util.mxEventSource.mxIEventListener; +import com.mxgraph.util.mxPoint; +import models.algebra.Expression; +import models.dataConstraintModel.Channel; +import models.dataConstraintModel.ChannelMember; +import models.dataConstraintModel.ResourcePath; +import models.dataConstraintModel.Selector; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferModel; +import models.dataFlowModel.ResourceNode; +import models.visualModel.FormulaChannel; +import parser.Parser; +import parser.exceptions.*; + +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class DependencyModelingStage extends Stage { + public final int PORT_DIAMETER = 8; + public final int PORT_RADIUS = PORT_DIAMETER / 2; + + public DependencyModelingStage(mxGraphComponent graphComponent) { + super(graphComponent); + } + + @Override + public void init(Stage prevStage) { + } + + @Override + public FlowCellEditor createCellEditor(mxGraphComponent graphComponent) { + return new DependencyCellEditor(this, graphComponent); + } + + @Override + public mxIEventListener createChangeEventListener(Editor editor) { + return (sender, event) -> { + List terminals = new ArrayList<>(); + mxCell cell = null; + for (Object change : ((List) event.getProperties().get("changes"))) { + if (change instanceof mxTerminalChange) { + mxTerminalChange terminalChange = (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}); + graph.clearSelection(); + } + } + }; + } + + @Override + public MouseListener createMouseEventListener(Editor editor) { + return null; + } + + @Override + public boolean canChangeFrom(Stage prevStage) { + return true; + } + +} diff --git a/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java index cddad6c..f8e1275 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/views/NavigationWindow.java @@ -6,6 +6,7 @@ import application.editor.Stage; import application.editor.stages.DataFlowModelingStage; import application.editor.stages.PushPullSelectionStage; +import application.editor.stages.DependencyModelingStage; import javax.swing.*; import java.awt.*; @@ -19,6 +20,7 @@ private final JToggleButton dataFlowModelingButton; private final JToggleButton pushPullSelectionButton; + private final JToggleButton dependencyModelingButton; private boolean forbidReentry = false; @@ -27,21 +29,28 @@ this.editor = editor; dataFlowModelingButton = new JToggleButton("Data Flow Modeling"); pushPullSelectionButton = new JToggleButton("Push Pull Selection"); + dependencyModelingButton = new JToggleButton("Dependency Modeling"); + dataFlowModelingButton.addActionListener(new DataFlowModelingButtonListener()); pushPullSelectionButton.addActionListener(new PushPullSelectionButtonListener()); - pushPullSelectionButton.setEnabled(false); + dependencyModelingButton.addActionListener(new DependencyModelingButtonListener()); + dataFlowModelingButton.setSelected(true); + pushPullSelectionButton.setEnabled(true); + dependencyModelingButton.setEnabled(false); setTitle(TITLE); setDefaultCloseOperation(HIDE_ON_CLOSE); Container panel = getContentPane(); - panel.setLayout(new GridLayout(2, 1)); + panel.setLayout(new GridLayout(3, 1)); ButtonGroup group = new ButtonGroup(); group.add(dataFlowModelingButton); group.add(pushPullSelectionButton); + group.add(dependencyModelingButton); panel.add(dataFlowModelingButton); panel.add(pushPullSelectionButton); + panel.add(dependencyModelingButton); pack(); @@ -61,7 +70,9 @@ pushPullSelectionButton.setEnabled(editor.canChange(Editor.STAGE_PUSH_PULL_SELECTION)); } else if (newStage instanceof PushPullSelectionStage) { pushPullSelectionButton.setSelected(true); - dataFlowModelingButton.setEnabled(editor.canChange(Editor.STAGE_DATA_FLOW_MODELING)); + dependencyModelingButton.setEnabled(editor.canChange(Editor.STAGE_DEPENDENCY_MODELING)); + } else if (newStage instanceof DependencyModelingStage) { + dependencyModelingButton.setSelected(true); } } @@ -81,7 +92,16 @@ forbidReentry = true; editor.changeStage(Editor.STAGE_PUSH_PULL_SELECTION); forbidReentry = false; - dataFlowModelingButton.setEnabled(editor.canChange(Editor.STAGE_DATA_FLOW_MODELING)); + dependencyModelingButton.setEnabled(editor.canChange(Editor.STAGE_DEPENDENCY_MODELING)); + } + } + + private class DependencyModelingButtonListener implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + forbidReentry = true; + editor.changeStage(Editor.STAGE_DEPENDENCY_MODELING); + forbidReentry = false; } } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dependencyModel/DependencyFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dependencyModel/DependencyFlowGraph.java new file mode 100644 index 0000000..5a96381 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dependencyModel/DependencyFlowGraph.java @@ -0,0 +1,12 @@ +package models.dependencyModel; + +import models.dataFlowModel.DataFlowGraph; +import models.dataFlowModel.DataTransferModel; + +public class DependencyFlowGraph { + private DataFlowGraph dataFlowGraph; + + public DependencyFlowGraph(DataFlowGraph dataFlowGraph, DataTransferModel model) { + this.dataFlowGraph = dataFlowGraph; + } +} \ No newline at end of file