diff --git a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java index 57fea37..346e75d 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java +++ b/AlgebraicDataflowArchitectureModel/src/application/ApplicationWindow.java @@ -8,8 +8,6 @@ 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.mxEventSource.mxIEventListener; import com.mxgraph.view.mxGraph; import javax.swing.*; @@ -17,24 +15,23 @@ import java.util.List; public class ApplicationWindow extends JFrame { + private static final long serialVersionUID = -8690140317781055614L; - public static final String title = "Visual Modeling Tool"; - private Editor editor = null; - private mxGraph graph = null; - private mxGraphComponent graphComponent = null; + public static final String TITLE = "Visual Modeling Tool"; - private ApplicationMenuBar menuBar = null; - private NavigationWindow navigationWindow; + private Editor editor; + private final mxGraph graph; + private final mxGraphComponent graphComponent; + + private final ApplicationMenuBar menuBar; + private final NavigationWindow navigationWindow; public ApplicationWindow() { - setTitle(title); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - this.graph = new mxGraph() { + 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) { @@ -42,26 +39,23 @@ } }; - this.graphComponent = new mxGraphComponent(graph); + graphComponent = new mxGraphComponent(graph); + editor = new Editor(graphComponent); - this.editor = new Editor(graphComponent); - - 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); - } + graph.getModel().addListener(mxEvent.CHANGE, (sender, event) -> { + List terminals = new ArrayList<>(); + mxCell cell = null; + for (Object change : ((List) event.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}); - } + } + if (terminals.size() == 2) { + if (!editor.connectEdge(cell, terminals.get(0), terminals.get(1))) { + graph.removeCells(new mxCell[]{cell}); } } }); @@ -71,11 +65,13 @@ graph.setCellsDisconnectable(true); menuBar = new ApplicationMenuBar(this); + setTitle(TITLE); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setJMenuBar(menuBar); setSize(870, 640); setLocationRelativeTo(null); // Center on screen - navigationWindow = new NavigationWindow(this, editor); + navigationWindow = new NavigationWindow(this); navigationWindow.setVisible(true); editor.addStageChangeListener(navigationWindow); }