diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java index 6dfb078..9bcacd4 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java @@ -1,149 +1,111 @@ package application.simulator; -import java.io.BufferedReader; -import java.io.FileReader; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.swing.JFrame; - +import algorithms.TypeInference; +import application.editor.Editor; 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.mxGraphComponent; import com.mxgraph.util.mxEvent; import com.mxgraph.util.mxEventObject; -import com.mxgraph.util.mxPoint; import com.mxgraph.util.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; - -import algorithms.TypeInference; -import application.editor.DataTransferModelingCellEditor; -import application.editor.Editor; -import application.layouts.DAGLayout; -import generators.JavaCodeGenerator; -import models.Edge; -import models.EdgeAttribute; -import models.algebra.Expression; -import models.algebra.InvalidMessage; -import models.algebra.ParameterizedIdentifierIsFutureWork; -import models.algebra.UnificationFailed; -import models.algebra.ValueUndefined; -import models.dataConstraintModel.Channel; -import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.ResourcePath; -import models.dataConstraintModel.Selector; -import models.dataFlowModel.ChannelNode; -import models.dataFlowModel.DataFlowEdge; -import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; -import models.dataFlowModel.ResourceNode; -import parser.Parser; -import parser.ParserDTRAM; -import parser.exceptions.ExpectedColon; -import parser.exceptions.ExpectedRightBracket; -import parser.exceptions.WrongJsonExpression; -import parser.Parser.TokenStream; import simulator.Event; -import simulator.Resource; -import simulator.ResourceIdentifier; import simulator.Simulator; import simulator.SystemState; import simulator.interfaces.INativeReceiver; +import javax.swing.*; +import java.util.ArrayList; +import java.util.List; + public class SimulatorWindow extends JFrame implements INativeReceiver { - private static final long serialVersionUID = -2425820512017088254L; - public static final String title = "Simulation Tool"; + private static final long serialVersionUID = -2425820512017088254L; + public static final String title = "Simulation Tool"; - final int PORT_DIAMETER = 8; - final int PORT_RADIUS = PORT_DIAMETER / 2; - - private Editor editor = null; - private mxGraph graph = null; - private mxGraphComponent graphComponent = null; - - private Simulator simulator = null; + final int PORT_DIAMETER = 8; + final int PORT_RADIUS = PORT_DIAMETER / 2; - private boolean bReflectingArchitectureModel = false; - private double x = 20; - private double y = 20; - private SimulatorMenuBar menuBar; - - public SimulatorWindow(Editor editor) { - setTitle(title); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - this.graph = new mxGraph() { - public boolean isPort(Object cell) { - mxGeometry geo = getCellGeometry(cell); - - return (geo != null) ? geo.isRelative() : false; - } - - public boolean isCellFoldable(Object cell, boolean collapse) { - return false; - } - }; - - this.graphComponent = new mxGraphComponent(graph); - this.editor = editor; - - 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}); - } - } - } - }); - getContentPane().add(graphComponent); - new mxRubberband(graphComponent); - graph.setAllowDanglingEdges(false); - graph.setCellsDisconnectable(true); - - setTitle(title); - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - setSize(870,640); - setVisible(true); - - DataTransferModel model = this.editor.getModel(); - TypeInference.infer(model); - simulator = new Simulator(model); - SimulationLayout layout = new SimulationLayout(simulator.getCurState()); - layout.constructSimulateGraph(graph, simulator); - graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor)); - simulator.addSystemReceiver(this); - - menuBar = new SimulatorMenuBar(this); - setJMenuBar(menuBar); - } - + private Editor editor = null; + private mxGraph graph = null; + private mxGraphComponent graphComponent = null; - @Override - public void onReceiveFromModel(Event event, SystemState nextSystemState) { - SimulationLayout layout = new SimulationLayout(nextSystemState); - layout.constructSimulateGraph(graph, simulator); - } + private Simulator simulator = null; + + private boolean bReflectingArchitectureModel = false; + private double x = 20; + private double y = 20; + private SimulatorMenuBar menuBar; + + public SimulatorWindow(Editor editor) { + setTitle(title); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + this.graph = new mxGraph() { + public boolean isPort(Object cell) { + mxGeometry geo = getCellGeometry(cell); + + return (geo != null) ? geo.isRelative() : false; + } + + public boolean isCellFoldable(Object cell, boolean collapse) { + return false; + } + }; + + this.graphComponent = new mxGraphComponent(graph); + this.editor = editor; + + 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}); + } + } + } + }); + getContentPane().add(graphComponent); + new mxRubberband(graphComponent); + graph.setAllowDanglingEdges(false); + graph.setCellsDisconnectable(true); + + setTitle(title); + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setSize(870, 640); + setVisible(true); + + DataTransferModel model = this.editor.getModel(); + TypeInference.infer(model); + simulator = new Simulator(model); + SimulationLayout layout = new SimulationLayout(simulator.getCurState()); + layout.constructSimulateGraph(graph, simulator); + graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor)); + simulator.addSystemReceiver(this); + + menuBar = new SimulatorMenuBar(this); + setJMenuBar(menuBar); + } + + + @Override + public void onReceiveFromModel(Event event, SystemState nextSystemState) { + SimulationLayout layout = new SimulationLayout(nextSystemState); + layout.constructSimulateGraph(graph, simulator); + } // public mxGraph constructSimulateGraph(Set simulateRes, DataTransferModel model, DataFlowGraph dataFlowGraph) { // bReflectingArchitectureModel = true; @@ -193,21 +155,21 @@ // resNode.getState().getValue().toString(), 0.5, 0.5, 0.25, 0.25, "opacity=0;verticalAlign=down;", true); // insert a state label as a vertex // } // } - - public mxGraphComponent getGraphComponent() { - return graphComponent; - } - public Editor getEditor() { - return editor; - } + public mxGraphComponent getGraphComponent() { + return graphComponent; + } - public void setEditor(Editor editor) { - this.editor = editor; - } + public Editor getEditor() { + return editor; + } - public Simulator getSimulator() { - return simulator; - } + public void setEditor(Editor editor) { + this.editor = editor; + } + + public Simulator getSimulator() { + return simulator; + } }