diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java index 517f525..f61fdc9 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewModelAction.java @@ -3,7 +3,6 @@ import java.awt.event.ActionEvent; import application.ApplicationWindow; -import application.editor.Editor; public class NewModelAction extends AbstractSystemAction { /** @@ -18,7 +17,7 @@ @Override public void actionPerformed(ActionEvent e) { frame.getEditor().clear(); - frame.setTitle(frame.title); + frame.setTitle(frame.TITLE); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java index 90f3ca1..2c51211 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java @@ -32,7 +32,7 @@ if (option == JFileChooser.APPROVE_OPTION) { lastDir = fc.getSelectedFile().getParent(); editor.open(fc.getSelectedFile()); - frame.setTitle(ApplicationWindow.title + " - " + fc.getSelectedFile().getAbsolutePath()); + frame.setTitle(ApplicationWindow.TITLE + " - " + fc.getSelectedFile().getAbsolutePath()); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java index 1a38b08..b5306e7 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java @@ -3,7 +3,6 @@ import java.awt.event.ActionEvent; import java.io.File; -import javax.swing.AbstractAction; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; @@ -71,7 +70,7 @@ // overwriting file editor.save(); - frame.setTitle(ApplicationWindow.title + " - " + fc.getSelectedFile().getAbsolutePath()); + frame.setTitle(ApplicationWindow.TITLE + " - " + fc.getSelectedFile().getAbsolutePath()); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/SimulateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/SimulateAction.java index 26a1779..74611be 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/SimulateAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/SimulateAction.java @@ -1,38 +1,21 @@ package application.actions; -import java.awt.event.ActionEvent; -import java.io.File; - -import javax.swing.JFileChooser; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.filechooser.FileFilter; -import javax.swing.filechooser.FileNameExtensionFilter; - import application.ApplicationWindow; -import application.editor.Editor; import application.simulator.SimulatorWindow; -import models.dataFlowModel.DataTransferChannel; + +import java.awt.event.ActionEvent; public class SimulateAction extends AbstractSystemAction { - - private SimulatorWindow simulatorWindow = null; - /** - * - */ - private static final long serialVersionUID = -995609232489316795L; + private static final long serialVersionUID = -995609232489316795L; - public SimulateAction(ApplicationWindow frame) { - super("Simulate", frame); - //this.simulatorWindow = new SimulatorWindow(frame.getEditor()); - } - + public SimulateAction(ApplicationWindow frame) { + super("Simulate", frame); + } - @Override - public void actionPerformed(ActionEvent e) { - this.simulatorWindow = new SimulatorWindow(frame.getEditor()); - } + @Override + public void actionPerformed(ActionEvent e) { + new SimulatorWindow(frame); + } } - diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java index 46bc39a..7cad2c5 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/InputEventCellEditor.java @@ -1,208 +1,172 @@ package application.simulator; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Rectangle; -import java.util.EventObject; -import java.util.HashMap; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.swing.BorderFactory; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JTextArea; -import javax.swing.JTextField; - +import application.editor.Editor; import com.mxgraph.model.mxCell; -import com.mxgraph.model.mxGraphModel; import com.mxgraph.model.mxIGraphModel; import com.mxgraph.swing.mxGraphComponent; import com.mxgraph.swing.view.mxICellEditor; import com.mxgraph.util.mxConstants; import com.mxgraph.util.mxUtils; import com.mxgraph.view.mxCellState; -import com.mxgraph.view.mxGraph; -import com.mxgraph.view.mxGraphView; - -import application.editor.Editor; -import application.layouts.DAGLayout; -import models.algebra.Expression; -import models.algebra.InvalidMessage; -import models.algebra.ParameterizedIdentifierIsFutureWork; -import models.algebra.Term; -import models.algebra.UnificationFailed; -import models.algebra.ValueUndefined; -import models.algebra.Variable; +import models.algebra.*; import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.ResourceHierarchy; import models.dataConstraintModel.ResourcePath; -import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; -import models.visualModel.FormulaChannel; import parser.Parser; import parser.Parser.TokenStream; import parser.exceptions.ExpectedColon; import parser.exceptions.ExpectedDoubleQuotation; import parser.exceptions.ExpectedRightBracket; import parser.exceptions.WrongJsonExpression; -import simulator.ChannelState; +import simulator.Event; import simulator.Resource; import simulator.ResourceIdentifier; import simulator.Simulator; -import simulator.Event; -import simulator.SystemState; -public class InputEventCellEditor implements mxICellEditor { - public int DEFAULT_MIN_WIDTH = 70; - public int DEFAULT_MIN_HEIGHT = 30; - public double DEFAULT_MINIMUM_EDITOR_SCALE = 1; - private double x = 20; - private double y = 20; +import javax.swing.*; +import java.awt.*; +import java.util.ArrayList; +import java.util.EventObject; +import java.util.List; - protected double minimumEditorScale = DEFAULT_MINIMUM_EDITOR_SCALE; - protected int minimumWidth = DEFAULT_MIN_WIDTH; - protected int minimumHeight = DEFAULT_MIN_HEIGHT; +public class InputEventCellEditor implements mxICellEditor { + public int DEFAULT_MIN_WIDTH = 70; + public int DEFAULT_MIN_HEIGHT = 30; + public double DEFAULT_MINIMUM_EDITOR_SCALE = 1; - private Object editingCell; - private EventObject trigger; - private JComboBox comboBox; - private mxGraphComponent graphComponent; - private Simulator simulator; - private JComboBox pulldownMenu; - private Editor editor; - private boolean bReflectingArchitectureModel = false; - - public InputEventCellEditor(mxGraphComponent graphComponent, Simulator simulator, Editor editor) { - this.graphComponent = graphComponent; - this.simulator = simulator; - this.editor = editor; - } + protected double minimumEditorScale = DEFAULT_MINIMUM_EDITOR_SCALE; + protected int minimumWidth = DEFAULT_MIN_WIDTH; + protected int minimumHeight = DEFAULT_MIN_HEIGHT; - @Override - public Object getEditingCell() { - return editingCell; - } + private final mxGraphComponent graphComponent; + private final SimulatorWindow simulatorWindow; + private final Simulator simulator; + private final Editor editor; - @Override - public void startEditing(Object cell, EventObject evt) { - if (editingCell != null) { - stopEditing(true); - } - if (!graphComponent.getGraph().getModel().isEdge(cell)) { - - Resource res = simulator.getCurState().getResource((String) ((mxCell) cell).getValue()); - ResourceIdentifier resId = res.getResourceIdentifier();//resource - ArrayList eventChs = new ArrayList<>();//iOchannelList - ArrayList messages = new ArrayList<>();//ADLmessage - ArrayList eventMessages = new ArrayList<>();//messageList - ResourcePath eventResPath = null; + private Object editingCell; + private EventObject trigger; + private JComboBox comboBox; - for(Channel ch : simulator.getModel().getInputChannels()) {//all channel - if(((DataTransferChannel)ch).getInputResources().size()== 0) {//ioch Or normalch - for(ChannelMember out: ((DataTransferChannel)ch).getOutputChannelMembers()) { - ResourcePath resPath = out.getResource(); - if(resId.isInstanceOf(resPath)) {//account.uid == acounts.123 - eventResPath = resPath; - eventChs.add(((DataTransferChannel)ch)); - String message = null; - Expression mesExp = out.getStateTransition().getMessageExpression();//sync(a,b) - eventMessages.add(mesExp); - if(mesExp instanceof Term) { - message = ((Term) mesExp).getSymbol().toString();//sync - }else if(mesExp instanceof Variable) { - message = ((Variable) mesExp).getName();//x,y,z.. - } - messages.add(message);//pulldown - - } - } - } - } - - if(messages.isEmpty()) { - return; - } - String[] eventList = messages.toArray(new String[messages.size()]); - JComboBox event = new JComboBox(eventList); - - JPanel eventChoice = new JPanel(); - eventChoice.add(event);//FirstEventChoice - - int ret = JOptionPane.showConfirmDialog(null, eventChoice, "Event Choice", JOptionPane.OK_CANCEL_OPTION); - if (ret == JOptionPane.OK_OPTION) { - - JPanel inputEvent = new JPanel(); - int i , eventNum; - i = eventNum = 0; - - for(String eventString : eventList) { - if(eventString.equals(event.getSelectedItem().toString())) { - eventNum = i; - } - i++; - } - - JTextArea textArea = new JTextArea(eventMessages.get(eventNum).toString(), 10, 30);//EventInput - inputEvent.add(textArea); - - int approve = JOptionPane.showConfirmDialog(null, inputEvent, "Event Code", JOptionPane.OK_CANCEL_OPTION); - if (approve == JOptionPane.OK_OPTION) { - try { - - TokenStream stream = new Parser.TokenStream(); - Parser parser = new Parser(stream); - stream.addLine(textArea.getText()); - Expression eventMessage = parser.parseTerm(stream,simulator.getModel()); - - Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId)); - simulator.transition(newEvent); + public InputEventCellEditor(mxGraphComponent graphComponent, SimulatorWindow simulatorWindow) { + this.graphComponent = graphComponent; + this.simulatorWindow = simulatorWindow; -// SimulationLayout layout = new SimulationLayout(simulator.getCurState()); -// layout.constructSimulateGraph(graph, simulator); + simulator = simulatorWindow.getSimulator(); + editor = simulatorWindow.getEditor(); + } - graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor)); - - } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork - | InvalidMessage | UnificationFailed | ValueUndefined | ExpectedRightBracket | WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) { - e.printStackTrace(); - } - } - } - //resource - return; - } + @Override + public Object getEditingCell() { + return editingCell; + } - mxCellState state = graphComponent.getGraph().getView().getState(cell); - if (state != null && state.getLabel() != null && !state.getLabel().equals("")) { - editingCell = cell; - trigger = evt; + @Override + public void startEditing(Object cell, EventObject evt) { + if (editingCell != null) { + stopEditing(true); + } + if (!graphComponent.getGraph().getModel().isEdge(cell)) { + Resource res = simulator.getCurState().getResource((String) ((mxCell) cell).getValue()); + ResourceIdentifier resId = res.getResourceIdentifier(); // Resource + ArrayList eventChs = new ArrayList<>(); // IOChannel List + ArrayList messages = new ArrayList<>(); // ADL message + ArrayList eventMessages = new ArrayList<>(); // Message list + ResourcePath eventResPath = null; - double scale = Math.max(minimumEditorScale, graphComponent.getGraph().getView().getScale()); - Object value = graphComponent.getGraph().getModel().getValue(cell); - if (value != null && value instanceof PushPullAttribute) { - PushPullAttribute attr = (PushPullAttribute) value; - comboBox = new JComboBox<>(attr.getOptionStrings()); - comboBox.setBorder(BorderFactory.createEmptyBorder()); - comboBox.setOpaque(false); - comboBox.setBounds(getEditorBounds(state, scale)); - comboBox.setVisible(true); - graphComponent.getGraphControl().add(comboBox, 0); - comboBox.updateUI(); - } - } - } + for (Channel ch : simulator.getModel().getInputChannels()) { // All channel + if (((DataTransferChannel) ch).getInputResources().isEmpty()) { // Input channel or Normal channel + for (ChannelMember out : ((DataTransferChannel) ch).getOutputChannelMembers()) { + ResourcePath resPath = out.getResource(); + if (resId.isInstanceOf(resPath)) { // account.uid == accounts.123 + eventResPath = resPath; + eventChs.add(((DataTransferChannel) ch)); + String message = null; + Expression mesExp = out.getStateTransition().getMessageExpression(); // sync(a,b) + eventMessages.add(mesExp); + if (mesExp instanceof Term) { + message = ((Term) mesExp).getSymbol().toString(); // sync + } else if (mesExp instanceof Variable) { + message = ((Variable) mesExp).getName(); // x,y,z.. + } + messages.add(message); // Pull-down + } + } + } + } + + if (messages.isEmpty()) { + return; + } + String[] eventList = messages.toArray(new String[messages.size()]); + JComboBox event = new JComboBox<>(eventList); + + JPanel eventChoice = new JPanel(); + eventChoice.add(event); // FirstEventChoice + + int ret = JOptionPane.showConfirmDialog(simulatorWindow, eventChoice, "Event Choice", JOptionPane.OK_CANCEL_OPTION); + if (ret == JOptionPane.OK_OPTION) { + JPanel inputEvent = new JPanel(); + int i, eventNum; + i = eventNum = 0; + + for (String eventString : eventList) { + if (eventString.equals(event.getSelectedItem().toString())) { + eventNum = i; + } + i++; + } + + JTextArea textArea = new JTextArea(eventMessages.get(eventNum).toString(), 10, 30); // EventInput + inputEvent.add(textArea); + + int approve = JOptionPane.showConfirmDialog(simulatorWindow, inputEvent, "Event Code", JOptionPane.OK_CANCEL_OPTION); + if (approve == JOptionPane.OK_OPTION) { + try { + TokenStream stream = new Parser.TokenStream(); + Parser parser = new Parser(stream); + stream.addLine(textArea.getText()); + Expression eventMessage = parser.parseTerm(stream, simulator.getModel()); + + Event newEvent = new Event(eventChs.get(eventNum), eventMessage, eventResPath, simulator.getCurState().getResource(resId)); + simulator.transition(newEvent); + + // SimulationLayout layout = new SimulationLayout(simulator.getCurState()); + // layout.constructSimulateGraph(graph, simulator); + + graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulatorWindow)); + } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | + InvalidMessage | UnificationFailed | ValueUndefined | ExpectedRightBracket | + WrongJsonExpression | ExpectedColon | ExpectedDoubleQuotation e) { + e.printStackTrace(); + } + } + } + return; + } + + mxCellState state = graphComponent.getGraph().getView().getState(cell); + if (state != null && state.getLabel() != null && !state.getLabel().isEmpty()) { + editingCell = cell; + trigger = evt; + + double scale = Math.max(minimumEditorScale, graphComponent.getGraph().getView().getScale()); + Object value = graphComponent.getGraph().getModel().getValue(cell); + if (value instanceof PushPullAttribute) { + PushPullAttribute attr = (PushPullAttribute) value; + comboBox = new JComboBox<>(attr.getOptionStrings()); + comboBox.setBorder(BorderFactory.createEmptyBorder()); + comboBox.setOpaque(false); + comboBox.setBounds(getEditorBounds(state, scale)); + comboBox.setVisible(true); + graphComponent.getGraphControl().add(comboBox, 0); + comboBox.updateUI(); + } + } + } // private mxGraph constructNextSimulateGraph(Set simulateRes, DataTransferModel model,DataFlowGraph dataFlowGraph, mxGraph nextGraph) { // bReflectingArchitectureModel = true; @@ -255,88 +219,79 @@ // } // } - @Override - public void stopEditing(boolean cancel) { - if (editingCell != null) { - comboBox.transferFocusUpCycle(); - Object cell = editingCell; - editingCell = null; - if (!cancel) { - EventObject trig = trigger; - trigger = null; - Object value = graphComponent.getGraph().getModel().getValue(cell); - if (value != null && value instanceof PushPullAttribute) { - PushPullAttribute attr = (PushPullAttribute) value; - List options = attr.getOptions(); - PushPullValue selected = null; - for (PushPullValue option: options) { - if (option.toString().equals(getCurrentValue())) { - selected = option; - break; - } - } - if (selected != null) { - options.remove(selected); - options.add(0, selected); - } - graphComponent.labelChanged(cell, attr, trig); - } - } else { - mxCellState state = graphComponent.getGraph().getView().getState(cell); - graphComponent.redraw(state); - } + @Override + public void stopEditing(boolean cancel) { + if (editingCell != null) { + comboBox.transferFocusUpCycle(); + Object cell = editingCell; + editingCell = null; + if (!cancel) { + EventObject trig = trigger; + trigger = null; + Object value = graphComponent.getGraph().getModel().getValue(cell); + if (value instanceof PushPullAttribute) { + PushPullAttribute attr = (PushPullAttribute) value; + List options = attr.getOptions(); + PushPullValue selected = null; + for (PushPullValue option : options) { + if (option.toString().equals(getCurrentValue())) { + selected = option; + break; + } + } + if (selected != null) { + options.remove(selected); + options.add(0, selected); + } + graphComponent.labelChanged(cell, attr, trig); + } + } else { + mxCellState state = graphComponent.getGraph().getView().getState(cell); + graphComponent.redraw(state); + } + if (comboBox.getParent() != null) { + comboBox.setVisible(false); + comboBox.getParent().remove(comboBox); + } + graphComponent.requestFocusInWindow(); + } + } - if (comboBox.getParent() != null) { - comboBox.setVisible(false); - comboBox.getParent().remove(comboBox); - } + public String getCurrentValue() { + return (String) comboBox.getSelectedItem(); + } - graphComponent.requestFocusInWindow(); - } - } + /** + * Returns the bounds to be used for the editor. + */ + public Rectangle getEditorBounds(mxCellState state, double scale) { + mxIGraphModel model = state.getView().getGraph().getModel(); + Rectangle bounds; - public String getCurrentValue() { - return (String) comboBox.getSelectedItem(); - } + bounds = state.getLabelBounds().getRectangle(); + bounds.height += 10; - /** - * Returns the bounds to be used for the editor. - */ - public Rectangle getEditorBounds(mxCellState state, double scale) { - mxIGraphModel model = state.getView().getGraph().getModel(); - Rectangle bounds = null; + // Applies the horizontal and vertical label positions + if (model.isVertex(state.getCell())) { + String horizontal = mxUtils.getString(state.getStyle(), mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER); - bounds = state.getLabelBounds().getRectangle(); - bounds.height += 10; + if (horizontal.equals(mxConstants.ALIGN_LEFT)) { + bounds.x -= (int) state.getWidth(); + } else if (horizontal.equals(mxConstants.ALIGN_RIGHT)) { + bounds.x += (int) state.getWidth(); + } - // Applies the horizontal and vertical label positions - if (model.isVertex(state.getCell())) { - String horizontal = mxUtils.getString(state.getStyle(), mxConstants.STYLE_LABEL_POSITION, mxConstants.ALIGN_CENTER); + String vertical = mxUtils.getString(state.getStyle(), mxConstants.STYLE_VERTICAL_LABEL_POSITION, mxConstants.ALIGN_MIDDLE); - if (horizontal.equals(mxConstants.ALIGN_LEFT)) { - bounds.x -= state.getWidth(); - } else if (horizontal.equals(mxConstants.ALIGN_RIGHT)) { - bounds.x += state.getWidth(); - } + if (vertical.equals(mxConstants.ALIGN_TOP)) { + bounds.y -= (int) state.getHeight(); + } else if (vertical.equals(mxConstants.ALIGN_BOTTOM)) { + bounds.y += (int) state.getHeight(); + } + } - String vertical = mxUtils.getString(state.getStyle(), - mxConstants.STYLE_VERTICAL_LABEL_POSITION, - mxConstants.ALIGN_MIDDLE); + bounds.setSize((int) Math.max(bounds.getWidth(), Math.round(minimumWidth * scale)), (int) Math.max(bounds.getHeight(), Math.round(minimumHeight * scale))); - if (vertical.equals(mxConstants.ALIGN_TOP)) { - bounds.y -= state.getHeight(); - } else if (vertical.equals(mxConstants.ALIGN_BOTTOM)) { - bounds.y += state.getHeight(); - } - } - - bounds.setSize( - (int) Math.max(bounds.getWidth(), - Math.round(minimumWidth * scale)), - (int) Math.max(bounds.getHeight(), - Math.round(minimumHeight * scale))); - - return bounds; - } - + return bounds; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorMenuBar.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorMenuBar.java index 8d1e609..e2a7406 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorMenuBar.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorMenuBar.java @@ -20,6 +20,6 @@ menu.add(new ZoomOutAction(simulatorWindow.getGraphComponent())); menu = add(new JMenu("Show")); - menu.add(new ShowUISimulatorAction(simulatorWindow.getSimulator())); + menu.add(new ShowUISimulatorAction(simulatorWindow)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java index 9bcacd4..df03082 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/SimulatorWindow.java @@ -1,6 +1,7 @@ package application.simulator; import algorithms.TypeInference; +import application.ApplicationWindow; import application.editor.Editor; import com.mxgraph.model.mxCell; import com.mxgraph.model.mxGeometry; @@ -18,37 +19,28 @@ import simulator.interfaces.INativeReceiver; import javax.swing.*; +import java.awt.*; 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"; - final int PORT_DIAMETER = 8; - final int PORT_RADIUS = PORT_DIAMETER / 2; + private Editor editor; - private Editor editor = null; - private mxGraph graph = null; - private mxGraphComponent graphComponent = null; + private final mxGraph graph; + private final mxGraphComponent graphComponent; - private Simulator simulator = null; + private final Simulator simulator; - 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); - + public SimulatorWindow(ApplicationWindow applicationWindow) { this.graph = new mxGraph() { public boolean isPort(Object cell) { mxGeometry geo = getCellGeometry(cell); - - return (geo != null) ? geo.isRelative() : false; + return geo != null && geo.isRelative(); } public boolean isCellFoldable(Object cell, boolean collapse) { @@ -57,7 +49,7 @@ }; this.graphComponent = new mxGraphComponent(graph); - this.editor = editor; + this.editor = applicationWindow.getEditor(); graph.getModel().addListener(mxEvent.CHANGE, new mxIEventListener() { public void invoke(Object sender, mxEventObject evt) { @@ -83,9 +75,17 @@ graph.setAllowDanglingEdges(false); graph.setCellsDisconnectable(true); + // Configure window setTitle(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(870, 640); + + setLocationRelativeTo(applicationWindow); + + int centerX = applicationWindow.getX() + applicationWindow.getWidth() / 2 - getWidth() / 2; + int centerY = applicationWindow.getY() + applicationWindow.getHeight() / 2 - getHeight() / 2; + setLocation(new Point(centerX, centerY)); + setVisible(true); DataTransferModel model = this.editor.getModel(); @@ -93,14 +93,13 @@ simulator = new Simulator(model); SimulationLayout layout = new SimulationLayout(simulator.getCurState()); layout.constructSimulateGraph(graph, simulator); - graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, simulator, this.editor)); + graphComponent.setCellEditor(new InputEventCellEditor(graphComponent, this)); simulator.addSystemReceiver(this); - menuBar = new SimulatorMenuBar(this); + SimulatorMenuBar menuBar = new SimulatorMenuBar(this); setJMenuBar(menuBar); } - @Override public void onReceiveFromModel(Event event, SystemState nextSystemState) { SimulationLayout layout = new SimulationLayout(nextSystemState); @@ -171,5 +170,4 @@ public Simulator getSimulator() { return simulator; } - } diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/UISimulatorWindow.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/UISimulatorWindow.java index 1c246b9..7e52653 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/UISimulatorWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/UISimulatorWindow.java @@ -1,29 +1,39 @@ package application.simulator; -import javax.swing.JFrame; -import javax.swing.JPanel; - import simulator.Simulator; import simulator.interfaces.swing.SwingPresenter; import simulator.interfaces.timers.TimerService; +import javax.swing.*; +import java.awt.*; + public class UISimulatorWindow extends JFrame { - private static final long serialVersionUID = 1770206525826167136L; - private SwingPresenter presenter; - private Simulator simulator; - private JPanel mainPanel; - private TimerService timerService; - - public UISimulatorWindow(Simulator simulator) { - setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - this.simulator = simulator; - mainPanel = new JPanel(); - presenter = new SwingPresenter(mainPanel, simulator); - this.add(mainPanel); - timerService = new TimerService(simulator); - - setSize(870,640); - setVisible(true); - } + private static final long serialVersionUID = 1770206525826167136L; + + private JPanel mainPanel; + private SwingPresenter presenter; + private Simulator simulator; + private TimerService timerService; + + public UISimulatorWindow(SimulatorWindow simulatorWindow) { + this.simulator = simulatorWindow.getSimulator(); + + mainPanel = new JPanel(); + presenter = new SwingPresenter(mainPanel, simulatorWindow.getSimulator()); + add(mainPanel); + timerService = new TimerService(simulatorWindow.getSimulator()); + + // Configure window + setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + setSize(870, 640); + + setLocationRelativeTo(simulatorWindow); + + int centerX = simulatorWindow.getX() + simulatorWindow.getWidth() / 2 - getWidth() / 2; + int centerY = simulatorWindow.getY() + simulatorWindow.getHeight() / 2 - getHeight() / 2; + setLocation(new Point(centerX, centerY)); + + setVisible(true); + } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/simulator/actions/ShowUISimulatorAction.java b/AlgebraicDataflowArchitectureModel/src/application/simulator/actions/ShowUISimulatorAction.java index 758d2d9..54ac3ec 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/simulator/actions/ShowUISimulatorAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/simulator/actions/ShowUISimulatorAction.java @@ -1,23 +1,22 @@ package application.simulator.actions; +import application.simulator.SimulatorWindow; +import application.simulator.UISimulatorWindow; + +import javax.swing.*; import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; - -import application.simulator.UISimulatorWindow; -import simulator.Simulator; - public class ShowUISimulatorAction extends AbstractAction { - private Simulator simulator; - public ShowUISimulatorAction(Simulator simulator) { - super("Show UI Simulator"); - this.simulator = simulator; - } + private final SimulatorWindow simulatorWindow; - @Override - public void actionPerformed(ActionEvent e) { - new UISimulatorWindow(simulator); - } + public ShowUISimulatorAction(SimulatorWindow simulatorWindow) { + super("Show UI Simulator"); + this.simulatorWindow = simulatorWindow; + } + @Override + public void actionPerformed(ActionEvent e) { + new UISimulatorWindow(simulatorWindow); + } }