diff --git a/src/main/java/projects/sample6/CustomGlobal.java b/src/main/java/projects/sample6/CustomGlobal.java index 2bf3db7a28c277d791fd4a03b1ef0645013d83c2..29f2a75a8fe1cf4983817a575c8a135788a2bf02 100644 --- a/src/main/java/projects/sample6/CustomGlobal.java +++ b/src/main/java/projects/sample6/CustomGlobal.java @@ -104,7 +104,7 @@ public class CustomGlobal extends AbstractCustomGlobal { * nodes in the framework that were added prior to this method call. * <p> * The method places all leaves on a line at the bottom of the screen and builds - * a balanced tree on top (bottom up), such that each tree-node is is parent of + * a balanced tree on top (bottom up), such that each tree-node is is parentGUI of * fanOut children. * * @param fanOut The max. fan-out of tree-nodes. E.g. 2 results in a binary tree @@ -157,11 +157,11 @@ public class CustomGlobal extends AbstractCustomGlobal { TreeNode currentNode = null; // loop over all nodes in the list, and group fanOut nodes, attach them - // to a new parent (tn), which will be placed in the center of the + // to a new parentGUI (tn), which will be placed in the center of the // associated nodes. for (TreeNode toProces : toProcess) { currentNode = toProces; - if (tn == null) { // start new parent + if (tn == null) { // start new parentGUI tn = new TreeNode(); tn.finishInitializationWithDefaultModels(true); this.treeNodes.add(tn); @@ -179,7 +179,7 @@ public class CustomGlobal extends AbstractCustomGlobal { } // Cleanup-code. If at the right-side of the tree, the we don't have enough // children - // for the parent, we need to finish the parent's placement outside the loop. + // for the parentGUI, we need to finish the parentGUI's placement outside the loop. if (tn != null) { tn.setPosition((leftMostXOffset + currentNode.getPosition().getXCoord()) / 2, posY, 0); } diff --git a/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java b/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java index 9db6bbdc15bad3cb1f6d26e358cc4a0a77674a92..ed499c7789f320f4ffbcbb65cfba5e884723ee2e 100644 --- a/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java +++ b/src/main/java/projects/sample6/nodes/nodeImplementations/TreeNode.java @@ -16,7 +16,7 @@ import java.awt.*; */ public class TreeNode extends Node { - public TreeNode parent = null; // the parent in the tree, null if this node is the root + public TreeNode parent = null; // the parentGUI in the tree, null if this node is the root @Override public void checkRequirements() throws WrongConfigurationException { @@ -33,7 +33,7 @@ public class TreeNode extends Node { this.setColor(Color.RED); // forward the message to all children for (Edge e : this.getOutgoingConnections()) { - if (!e.getEndNode().equals(this.parent)) { // don't send it to the parent + if (!e.getEndNode().equals(this.parent)) { // don't send it to the parentGUI this.send(m, e.getEndNode()); } } diff --git a/src/main/java/sinalgo/Run.java b/src/main/java/sinalgo/Run.java index 7c7bfd92546f8c52424113bbf8c03f753e21e089..9ddb5c4b731c09879dcaed6208bb5938a5c5d260 100644 --- a/src/main/java/sinalgo/Run.java +++ b/src/main/java/sinalgo/Run.java @@ -126,7 +126,7 @@ public class Run { // Setting it to server mode s = s.replaceFirst("server=n", "server=y"); // Do NOT block until the debugger has attached - s = s.replaceFirst("suspend=y", "suspend=n"); + s = s.replaceFirst("suspend=y", "suspend=y"); } return s; }) diff --git a/src/main/java/sinalgo/configuration/AppConfig.java b/src/main/java/sinalgo/configuration/AppConfig.java index b63559fb436c858c6f1875a9a5edae8241c20d41..a5ee084969618c9ab692d44266a7a9cdf51e256a 100644 --- a/src/main/java/sinalgo/configuration/AppConfig.java +++ b/src/main/java/sinalgo/configuration/AppConfig.java @@ -36,6 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.configuration; +import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import org.jdom2.Document; @@ -56,6 +57,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Objects; +import java.util.function.Supplier; /** * A config file that stores application wide settings for the user, such as the @@ -103,16 +105,23 @@ public class AppConfig { private String previousRunCmdLineArgs = ""; // cmd line args of the previous call to 'Run' - private static AppConfig singletonInstance = null; // the singleton instance + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static AppConfig singletonInstance = null; + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static Supplier<AppConfig> appConfigProvider = () -> { + AppConfig.setSingletonInstance(new AppConfig()); + AppConfig.setAppConfigProvider(AppConfig::getSingletonInstance); + return AppConfig.getAppConfig(); + }; /** * @return The singleton instance of AppConfig. */ public static AppConfig getAppConfig() { - if (singletonInstance == null) { - singletonInstance = new AppConfig(); - } - return singletonInstance; + return AppConfig.getAppConfigProvider().get(); } /** diff --git a/src/main/java/sinalgo/gui/GUI.java b/src/main/java/sinalgo/gui/GUI.java index b9509240383042fded2909c9115e3d2f0a61cd19..6109af40fbef0591b07e6b6e4c32bf050499c3c8 100644 --- a/src/main/java/sinalgo/gui/GUI.java +++ b/src/main/java/sinalgo/gui/GUI.java @@ -36,7 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui; +import lombok.AccessLevel; import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.exception.ExportException; @@ -68,9 +70,11 @@ import java.util.HashMap; import java.util.Vector; /** - * The parent frame for the whole gui. It contains two children: the graph panel + * The parentGUI frame for the whole gui. It contains two children: the graph panel * and the control panel. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class GUI extends JFrame implements ActionListener { private static final long serialVersionUID = -2301103668898732398L; @@ -99,13 +103,22 @@ public class GUI extends JFrame implements ActionListener { private GlobalInvoker globalInvoker = new GlobalInvoker(); + /** + * @return The graph panel where the graph is drawn onto + */ + @Getter private GraphPanel graphPanel; + + /** + * The control panel of this GUI. + * + * @return The controlpanel of this GUI. + */ + @Getter private ControlPanel controlPanel; private HashMap<MenuElement, Method> methodsAndNames = new HashMap<>(); - private AppConfig appConfig = AppConfig.getAppConfig(); - /** * The constructor for the GUI class. * @@ -116,51 +129,35 @@ public class GUI extends JFrame implements ActionListener { GuiHelper.setWindowIcon(this); // load the buttons for the menu - these settings should be done only once - this.settingsMenuItem.addActionListener(this); - this.settingsMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_S); - this.aboutMenuItem.addActionListener(this); - this.aboutMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_A); - this.aboutMenuItem.setIcon(GuiHelper.getIcon("sinalgo_21.png")); - this.helpMenuItem.addActionListener(this); - this.helpMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_H); - this.helpMenuItem.setIcon(GuiHelper.getIcon("helpSmall.gif")); - this.helpMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); - - this.viewFullScreenMenuItem.addActionListener(this); - this.viewFullScreenMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_F); - this.viewFullScreenMenuItem.setIcon(GuiHelper.getIcon("zoomFullView.gif")); - this.viewFullScreenMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0)); - - this.viewZoomInMenuItem.addActionListener(this); - this.viewZoomInMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_I); - this.viewZoomInMenuItem.setIcon(GuiHelper.getIcon("zoominimage.png")); - - this.viewZoomOutMenuItem.addActionListener(this); - this.viewZoomOutMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_O); - this.viewZoomOutMenuItem.setIcon(GuiHelper.getIcon("zoomoutimage.png")); - - this.viewZoomFitMenuItem.addActionListener(this); - this.viewZoomFitMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_T); - this.viewZoomFitMenuItem.setIcon(GuiHelper.getIcon("zoomtofit.gif")); - this.viewZoomFitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0)); - - this.runtime = r; - } - - /** - * @return The graph panel where the graph is drawn onto - */ - public GraphPanel getGraphPanel() { - return this.graphPanel; - } - - /** - * Returns the control panel of this GUI. - * - * @return The controlpanel of this GUI. - */ - public ControlPanel getControlPanel() { - return this.controlPanel; + this.getSettingsMenuItem().addActionListener(this); + this.getSettingsMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_S); + this.getAboutMenuItem().addActionListener(this); + this.getAboutMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_A); + this.getAboutMenuItem().setIcon(GuiHelper.getIcon("sinalgo_21.png")); + this.getHelpMenuItem().addActionListener(this); + this.getHelpMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_H); + this.getHelpMenuItem().setIcon(GuiHelper.getIcon("helpSmall.gif")); + this.getHelpMenuItem().setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); + + this.getViewFullScreenMenuItem().addActionListener(this); + this.getViewFullScreenMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_F); + this.getViewFullScreenMenuItem().setIcon(GuiHelper.getIcon("zoomFullView.gif")); + this.getViewFullScreenMenuItem().setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0)); + + this.getViewZoomInMenuItem().addActionListener(this); + this.getViewZoomInMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_I); + this.getViewZoomInMenuItem().setIcon(GuiHelper.getIcon("zoominimage.png")); + + this.getViewZoomOutMenuItem().addActionListener(this); + this.getViewZoomOutMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_O); + this.getViewZoomOutMenuItem().setIcon(GuiHelper.getIcon("zoomoutimage.png")); + + this.getViewZoomFitMenuItem().addActionListener(this); + this.getViewZoomFitMenuItem().setMnemonic(java.awt.event.KeyEvent.VK_T); + this.getViewZoomFitMenuItem().setIcon(GuiHelper.getIcon("zoomtofit.gif")); + this.getViewZoomFitMenuItem().setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0)); + + this.setRuntime(r); } private GenerateNodesDialog genNodesDialog = new GenerateNodesDialog(this); @@ -169,17 +166,15 @@ public class GUI extends JFrame implements ActionListener { * The instance of the runtime to make changes comming from the gui. */ @Getter + @Setter(AccessLevel.PRIVATE) private SinalgoRuntime runtime; // The zoom level used to draw the graph. - private double zoomFactor = 1; - /** * @return The zoom factor currently used to draw the graph. */ - public double getZoomFactor() { - return this.zoomFactor; - } + @Getter + private double zoomFactor = 1; /** * Sets the zoom factor at which the graph will be drawn and repaints the graph. @@ -254,12 +249,12 @@ public class GUI extends JFrame implements ActionListener { } else { // restore the normal window size // setExtendedState(JFrame.NORMAL); - // GUI.this.setSize(appConfig.guiWindowWidth, appConfig.guiWindowHeight); - // GUI.this.setLocation(appConfig.guiWindowPosX, appConfig.guiWindowPosY); + // GUI.this.setSize(AppConfig.getAppConfig().guiWindowWidth, AppConfig.getAppConfig().guiWindowHeight); + // GUI.this.setLocation(AppConfig.getAppConfig().guiWindowPosX, AppConfig.getAppConfig().guiWindowPosY); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null); } // update the menu title - this.viewFullScreenMenuItem.setText(full ? "Exit Full Screen" : "Full Screen"); + this.getViewFullScreenMenuItem().setText(full ? "Exit Full Screen" : "Full Screen"); } @@ -282,18 +277,18 @@ public class GUI extends JFrame implements ActionListener { // react upon resize-events this.addComponentListener(new ComponentListener() { - int oldX = GUI.this.appConfig.getGuiWindowPosX(), oldY = GUI.this.appConfig.getGuiWindowPosY(); + int oldX = AppConfig.getAppConfig().getGuiWindowPosX(), oldY = AppConfig.getAppConfig().getGuiWindowPosY(); @Override public void componentResized(ComponentEvent e) { if (GUI.this.getExtendedState() == Frame.MAXIMIZED_BOTH) { - GUI.this.appConfig.setGuiIsMaximized(true); - GUI.this.appConfig.setGuiWindowPosX(this.oldX); - GUI.this.appConfig.setGuiWindowPosY(this.oldY); + AppConfig.getAppConfig().setGuiIsMaximized(true); + AppConfig.getAppConfig().setGuiWindowPosX(this.oldX); + AppConfig.getAppConfig().setGuiWindowPosY(this.oldY); } else { - GUI.this.appConfig.setGuiIsMaximized(false); - GUI.this.appConfig.setGuiWindowWidth(GUI.this.getWidth()); - GUI.this.appConfig.setGuiWindowHeight(GUI.this.getHeight()); + AppConfig.getAppConfig().setGuiIsMaximized(false); + AppConfig.getAppConfig().setGuiWindowWidth(GUI.this.getWidth()); + AppConfig.getAppConfig().setGuiWindowHeight(GUI.this.getHeight()); } } @@ -301,10 +296,10 @@ public class GUI extends JFrame implements ActionListener { public void componentMoved(ComponentEvent e) { // upon maximizing, first the component is moved, then resized. We only catch // the resize event - this.oldX = GUI.this.appConfig.getGuiWindowPosX(); - this.oldY = GUI.this.appConfig.getGuiWindowPosY(); - GUI.this.appConfig.setGuiWindowPosX(GUI.this.getX()); - GUI.this.appConfig.setGuiWindowPosY(GUI.this.getY()); + this.oldX = AppConfig.getAppConfig().getGuiWindowPosX(); + this.oldY = AppConfig.getAppConfig().getGuiWindowPosY(); + AppConfig.getAppConfig().setGuiWindowPosX(GUI.this.getX()); + AppConfig.getAppConfig().setGuiWindowPosY(GUI.this.getY()); } @Override @@ -328,9 +323,9 @@ public class GUI extends JFrame implements ActionListener { // Note: the event should not be marked consumed. A consumed Enter may // have been used elsewhere, e.g. to select a menu. if (Global.isRunning()) { - this.controlPanel.stopSimulation(); + this.getControlPanel().stopSimulation(); } else { - this.controlPanel.startSimulation(); + this.getControlPanel().startSimulation(); } return true; // no further event handling for this key event } @@ -338,71 +333,71 @@ public class GUI extends JFrame implements ActionListener { }); this.setResizable(true); - if (this.appConfig.isGuiIsMaximized()) { + if (AppConfig.getAppConfig().isGuiIsMaximized()) { this.setExtendedState(Frame.MAXIMIZED_BOTH); } - this.setSize(new Dimension(this.appConfig.getGuiWindowWidth(), this.appConfig.getGuiWindowHeight())); - this.setLocation(this.appConfig.getGuiWindowPosX(), this.appConfig.getGuiWindowPosY()); + this.setSize(new Dimension(AppConfig.getAppConfig().getGuiWindowWidth(), AppConfig.getAppConfig().getGuiWindowHeight())); + this.setLocation(AppConfig.getAppConfig().getGuiWindowPosX(), AppConfig.getAppConfig().getGuiWindowPosY()); JMenuBar menuBar = new JMenuBar(); this.menuFont = menuBar.getFont().deriveFont(Font.PLAIN); - this.graphMenu = new JMenu("Simulation"); - this.graphMenu.setMnemonic(java.awt.event.KeyEvent.VK_S); - - this.exportMenuItem = new JMenuItem("Export..."); - this.exportMenuItem.addActionListener(this); - this.exportMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_E); - this.exportMenuItem.setIcon(GuiHelper.getIcon("export.gif")); - - this.clearMenuItem = new JMenuItem("Clear Graph"); - this.clearMenuItem.addActionListener(this); - this.clearMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_C); - this.clearMenuItem.setIcon(GuiHelper.getIcon("cleargraph.gif")); - this.clearMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0)); - - this.reevaluateMenuItem = new JMenuItem("Reevaluate Connections"); - this.reevaluateMenuItem.addActionListener(this); - this.reevaluateMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_R); - this.reevaluateMenuItem.setIcon(GuiHelper.getIcon("connectnodes.gif")); - this.reevaluateMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0)); - - this.generateMenuItem = new JMenuItem("Generate Nodes"); - this.generateMenuItem.addActionListener(this); - this.generateMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_G); - this.generateMenuItem.setIcon(GuiHelper.getIcon("addnodes.gif")); - this.generateMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); - - this.infoMenuItem = new JMenuItem("Network Info"); - this.infoMenuItem.addActionListener(this); - this.infoMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_I); - - this.exitMenuItem = new JMenuItem("Exit"); - this.exitMenuItem.addActionListener(this); - this.exitMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_X); - - this.preferencesMenuItem = new JMenuItem("Preferences"); - this.preferencesMenuItem.addActionListener(this); - this.preferencesMenuItem.setMnemonic(java.awt.event.KeyEvent.VK_P); - - this.graphMenu.add(this.generateMenuItem); - this.graphMenu.add(this.reevaluateMenuItem); - this.graphMenu.add(this.clearMenuItem); - - this.graphMenu.addSeparator(); - this.graphMenu.add(this.infoMenuItem); - this.graphMenu.add(this.exportMenuItem); - this.graphMenu.add(this.preferencesMenuItem); - this.graphMenu.addSeparator(); - this.graphMenu.add(this.exitMenuItem); - - menuBar.add(this.graphMenu); - - this.globalMenu = new JMenu("Global"); - this.globalMenu.setMnemonic(java.awt.event.KeyEvent.VK_G); + this.setGraphMenu(new JMenu("Simulation")); + this.getGraphMenu().setMnemonic(KeyEvent.VK_S); + + this.setExportMenuItem(new JMenuItem("Export...")); + this.getExportMenuItem().addActionListener(this); + this.getExportMenuItem().setMnemonic(KeyEvent.VK_E); + this.getExportMenuItem().setIcon(GuiHelper.getIcon("export.gif")); + + this.setClearMenuItem(new JMenuItem("Clear Graph")); + this.getClearMenuItem().addActionListener(this); + this.getClearMenuItem().setMnemonic(KeyEvent.VK_C); + this.getClearMenuItem().setIcon(GuiHelper.getIcon("cleargraph.gif")); + this.getClearMenuItem().setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0)); + + this.setReevaluateMenuItem(new JMenuItem("Reevaluate Connections")); + this.getReevaluateMenuItem().addActionListener(this); + this.getReevaluateMenuItem().setMnemonic(KeyEvent.VK_R); + this.getReevaluateMenuItem().setIcon(GuiHelper.getIcon("connectnodes.gif")); + this.getReevaluateMenuItem().setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0)); + + this.setGenerateMenuItem(new JMenuItem("Generate Nodes")); + this.getGenerateMenuItem().addActionListener(this); + this.getGenerateMenuItem().setMnemonic(KeyEvent.VK_G); + this.getGenerateMenuItem().setIcon(GuiHelper.getIcon("addnodes.gif")); + this.getGenerateMenuItem().setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); + + this.setInfoMenuItem(new JMenuItem("Network Info")); + this.getInfoMenuItem().addActionListener(this); + this.getInfoMenuItem().setMnemonic(KeyEvent.VK_I); + + this.setExitMenuItem(new JMenuItem("Exit")); + this.getExitMenuItem().addActionListener(this); + this.getExitMenuItem().setMnemonic(KeyEvent.VK_X); + + this.setPreferencesMenuItem(new JMenuItem("Preferences")); + this.getPreferencesMenuItem().addActionListener(this); + this.getPreferencesMenuItem().setMnemonic(KeyEvent.VK_P); + + this.getGraphMenu().add(this.getGenerateMenuItem()); + this.getGraphMenu().add(this.getReevaluateMenuItem()); + this.getGraphMenu().add(this.getClearMenuItem()); + + this.getGraphMenu().addSeparator(); + this.getGraphMenu().add(this.getInfoMenuItem()); + this.getGraphMenu().add(this.getExportMenuItem()); + this.getGraphMenu().add(this.getPreferencesMenuItem()); + this.getGraphMenu().addSeparator(); + this.getGraphMenu().add(this.getExitMenuItem()); + + menuBar.add(this.getGraphMenu()); + + this.setGlobalMenu(new JMenu("Global")); + this.getGlobalMenu().setMnemonic(KeyEvent.VK_G); // Compose this menu every time when it is shown. This allows us to // give some more control to the user about the CustomMethods. - this.globalMenu.addMenuListener(new MenuListener() { + this.getGlobalMenu().addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent e) { @@ -475,12 +470,12 @@ public class GUI extends JFrame implements ActionListener { continue; // the method was dropped by the project } JMenuItem item = new JMenuItem(text); - item.addActionListener(GUI.this.globalInvoker); - GUI.this.methodsAndNames.put(item, method); + item.addActionListener(GUI.this.getGlobalInvoker()); + GUI.this.getMethodsAndNames().put(item, method); String subMenuText = info.subMenu(); if (subMenuText.equals("")) { - GUI.this.globalMenu.add(item); + GUI.this.getGlobalMenu().add(item); } else { JMenu menu = null; for (JMenu m : subMenus) { @@ -492,7 +487,7 @@ public class GUI extends JFrame implements ActionListener { if (menu == null) { menu = new JMenu(subMenuText); subMenus.add(menu); - GUI.this.globalMenu.add(menu); + GUI.this.getGlobalMenu().add(menu); } menu.add(item); } @@ -504,85 +499,84 @@ public class GUI extends JFrame implements ActionListener { @Override public void menuSelected(MenuEvent event) { - GUI.this.globalMenu.removeAll(); + GUI.this.getGlobalMenu().removeAll(); // add the project specific methods Method[] methods = Global.getCustomGlobal().getClass().getMethods(); if (this.testMethods(methods, true)) { - GUI.this.globalMenu.addSeparator(); + GUI.this.getGlobalMenu().addSeparator(); } // add the framework-side defined methods in sinalgo.runtime.Global try { methods = Thread.currentThread().getContextClassLoader().loadClass("sinalgo.runtime.Global").getMethods(); if (this.testMethods(methods, false)) { - GUI.this.globalMenu.addSeparator(); + GUI.this.getGlobalMenu().addSeparator(); } } catch (ClassNotFoundException e) { throw new SinalgoFatalException("Could not find class sinalgo.runtime.Global to get the global gui methods from."); } // And finally the Settings and About dialog - GUI.this.globalMenu.add(GUI.this.settingsMenuItem); + GUI.this.getGlobalMenu().add(GUI.this.getSettingsMenuItem()); // and set the font of the menu entries - GUI.this.setMenuFont(GUI.this.globalMenu); + GUI.this.setMenuFont(GUI.this.getGlobalMenu()); } }); - menuBar.add(this.globalMenu); + menuBar.add(this.getGlobalMenu()); // --------------------------------------------- // View Menu // --------------------------------------------- - this.viewMenu = new JMenu("View"); - this.viewMenu.setMnemonic(java.awt.event.KeyEvent.VK_V); - this.viewMenu.add(this.viewZoomOutMenuItem); - this.viewMenu.add(this.viewZoomInMenuItem); - this.viewMenu.add(this.viewZoomFitMenuItem); - this.viewMenu.add(this.viewFullScreenMenuItem); + this.setViewMenu(new JMenu("View")); + this.getViewMenu().setMnemonic(KeyEvent.VK_V); + this.getViewMenu().add(this.getViewZoomOutMenuItem()); + this.getViewMenu().add(this.getViewZoomInMenuItem()); + this.getViewMenu().add(this.getViewZoomFitMenuItem()); + this.getViewMenu().add(this.getViewFullScreenMenuItem()); - menuBar.add(this.viewMenu); + menuBar.add(this.getViewMenu()); // --------------------------------------------- // Help Menu // --------------------------------------------- - this.helpMenu = new JMenu("Help"); - this.helpMenu.setMnemonic(java.awt.event.KeyEvent.VK_H); - this.helpMenu.add(this.helpMenuItem); - this.helpMenu.addSeparator(); - this.helpMenu.add(this.aboutMenuItem); - menuBar.add(this.helpMenu); + this.setHelpMenu(new JMenu("Help")); + this.getHelpMenu().setMnemonic(KeyEvent.VK_H); + this.getHelpMenu().add(this.getHelpMenuItem()); + this.getHelpMenu().addSeparator(); + this.getHelpMenu().add(this.getAboutMenuItem()); + menuBar.add(this.getHelpMenu()); this.setMenuFont(menuBar); this.setJMenuBar(menuBar); // The content pane - this.contentPane = new JPanel(); + this.setGuiPanel(new JPanel()); + this.getGuiPanel().setLayout(new BoxLayout(this.getGuiPanel(), BoxLayout.X_AXIS)); - this.graphPanel = new GraphPanel(this); + this.setGraphPanel(new GraphPanel(this)); // activate the Tooltip for the graphPanel. The "Default Tooltip" is actually // never shown // because the text to show is overwritten in the GraphPanel-Classes // getToolTipText(MouseEvent e) - this.graphPanel.createToolTip(); - this.graphPanel.setToolTipText("Default Tooltip"); // to initialize, must set an arbitrary text - this.graphPanel.requestDefaultViewOnNextDraw(); + this.getGraphPanel().createToolTip(); + this.getGraphPanel().setToolTipText("Default Tooltip"); // to initialize, must set an arbitrary text + this.getGraphPanel().requestDefaultViewOnNextDraw(); if (Configuration.isExtendedControl()) { - this.contentPane.setLayout(new BoxLayout(this.contentPane, BoxLayout.X_AXIS)); - this.controlPanel = new MaximizedControlPanel(this); - this.contentPane.add(this.graphPanel); - this.contentPane.add(this.controlPanel); + this.setControlPanel(new MaximizedControlPanel(this)); + this.getGuiPanel().add(this.getGraphPanel()); + this.getGuiPanel().add(this.getControlPanel()); } else { - this.contentPane.setLayout(new BoxLayout(this.contentPane, BoxLayout.Y_AXIS)); - this.controlPanel = new MinimizedControlPanel(this); - this.contentPane.add(this.controlPanel); - this.contentPane.add(this.graphPanel); + this.setControlPanel(new MinimizedControlPanel(this)); + this.getGuiPanel().add(this.getControlPanel()); + this.getGuiPanel().add(this.getGraphPanel()); } - this.add(this.contentPane); + this.add(this.getGuiPanel()); this.setVisible(true); // trigger a first paint (needed!) @@ -590,7 +584,7 @@ public class GUI extends JFrame implements ActionListener { } private void setMenuFont(MenuElement m) { - m.getComponent().setFont(this.menuFont); + m.getComponent().setFont(this.getMenuFont()); if (m.getSubElements().length > 0) { for (MenuElement e : m.getSubElements()) { this.setMenuFont(e); @@ -598,7 +592,7 @@ public class GUI extends JFrame implements ActionListener { } } - private JPanel contentPane = null; + private JPanel guiPanel = null; /** * Switches between the two modes for the control panel depending on the boolean @@ -610,20 +604,20 @@ public class GUI extends JFrame implements ActionListener { // STRANGE! we need to add the new contol panel before removing the old one // otherwise, the mouse scrolling wont be detected anymore. if (toExtended) { // from minimized to maximized - this.contentPane.setLayout(new BoxLayout(this.contentPane, BoxLayout.X_AXIS)); - ControlPanel oldCP = this.controlPanel; - this.controlPanel = new MaximizedControlPanel(this); - this.contentPane.add(this.controlPanel, 2); // content pane must be after graph panel - this.contentPane.remove(oldCP); + this.getGuiPanel().setLayout(new BoxLayout(this.getGuiPanel(), BoxLayout.X_AXIS)); + ControlPanel oldCP = this.getControlPanel(); + this.setControlPanel(new MaximizedControlPanel(this)); + this.getGuiPanel().add(this.getControlPanel(), 2); // content pane must be after graph panel + this.getGuiPanel().remove(oldCP); } else { // from maximized to minimized - this.contentPane.setLayout(new BoxLayout(this.contentPane, BoxLayout.Y_AXIS)); - ControlPanel oldCP = this.controlPanel; - this.controlPanel = new MinimizedControlPanel(this); - this.contentPane.add(this.controlPanel, 0); // content pane is first in list - this.contentPane.remove(oldCP); + this.getGuiPanel().setLayout(new BoxLayout(this.getGuiPanel(), BoxLayout.Y_AXIS)); + ControlPanel oldCP = this.getControlPanel(); + this.setControlPanel(new MinimizedControlPanel(this)); + this.getGuiPanel().add(this.getControlPanel(), 0); // content pane is first in list + this.getGuiPanel().remove(oldCP); } - this.contentPane.revalidate(); - this.graphPanel.requireFullDrawOnNextPaint(); + this.getGuiPanel().revalidate(); + this.getGraphPanel().requireFullDrawOnNextPaint(); this.repaint(); } @@ -632,7 +626,7 @@ public class GUI extends JFrame implements ActionListener { * method is called when the user removes all nodes. */ public void allNodesAreRemoved() { - this.graphPanel.allNodesAreRemoved(); + this.getGraphPanel().allNodesAreRemoved(); } /** @@ -640,14 +634,16 @@ public class GUI extends JFrame implements ActionListener { * at least once. THe graph panel starts drawing itself only after this flag has * been set to true. */ - public boolean firstTimePainted = false; + @Getter + @Setter + private boolean firstTimePainted = false; @Override public void paint(Graphics g) { super.paint(g); - this.firstTimePainted = true; - this.controlPanel.repaint(); - this.graphPanel.repaint(); + this.setFirstTimePainted(true); + this.getControlPanel().repaint(); + this.getGraphPanel().repaint(); } /** @@ -684,8 +680,8 @@ public class GUI extends JFrame implements ActionListener { * In almost all cases, calling redrawGUI() is preferred. */ public void redrawGUINow() { - this.controlPanel.repaint(); - this.graphPanel.paintNow(); + this.getControlPanel().repaint(); + this.getGraphPanel().paintNow(); } /** @@ -709,9 +705,9 @@ public class GUI extends JFrame implements ActionListener { * @see GUI#redrawGUINow() for how the graph panel is drawn. */ public void redrawGUI() { - this.graphPanel.requireFullDrawOnNextPaint(); - this.controlPanel.repaint(); - this.graphPanel.repaint(); + this.getGraphPanel().requireFullDrawOnNextPaint(); + this.getControlPanel().repaint(); + this.getGraphPanel().repaint(); } /** @@ -719,7 +715,7 @@ public class GUI extends JFrame implements ActionListener { * (inclusive the small preview picture) without painting the whole graph. */ public void redrawControl() { - this.controlPanel.repaint(); + this.getControlPanel().repaint(); } /** @@ -741,11 +737,11 @@ public class GUI extends JFrame implements ActionListener { * is set false (and vice versa) */ public void setStartButtonEnabled(boolean b) { - this.controlPanel.setStartButtonEnabled(b); - this.graphMenu.setEnabled(b); - this.globalMenu.setEnabled(b); - this.helpMenu.setEnabled(b); - this.viewMenu.setEnabled(b); + this.getControlPanel().setStartButtonEnabled(b); + this.getGraphMenu().setEnabled(b); + this.getGlobalMenu().setEnabled(b); + this.getHelpMenu().setEnabled(b); + this.getViewMenu().setEnabled(b); // We could disallow resizing the window here, but this flickers // setResizable(b); } @@ -767,7 +763,7 @@ public class GUI extends JFrame implements ActionListener { * @param i The number to be displayed in the control panel. */ public void setRoundsPerformed(long i) { - this.controlPanel.setRoundsPerformed(i); + this.getControlPanel().setRoundsPerformed(i); } /** @@ -776,7 +772,7 @@ public class GUI extends JFrame implements ActionListener { * @param e The event that was last processed, null if there was no event. */ public void setCurrentlyProcessedEvent(Event e) { - this.controlPanel.setCurrentEvent(e); + this.getControlPanel().setCurrentEvent(e); } /** @@ -785,7 +781,7 @@ public class GUI extends JFrame implements ActionListener { * @param s A string representation of the position */ public void setMousePosition(String s) { - this.controlPanel.setMousePosition(s); + this.getControlPanel().setMousePosition(s); } /** @@ -800,7 +796,7 @@ public class GUI extends JFrame implements ActionListener { * Opens a dialog that allows to add new nodes */ public void addNodes() { - this.genNodesDialog.compose(null); + this.getGenNodesDialog().compose(null); } /** @@ -810,7 +806,7 @@ public class GUI extends JFrame implements ActionListener { * @param pos The positino where the node will be placed. */ public void addSingleNode(Position pos) { - this.genNodesDialog.compose(pos); + this.getGenNodesDialog().compose(pos); } /** @@ -819,51 +815,51 @@ public class GUI extends JFrame implements ActionListener { * @param pos The position */ public void addSingleDefaultNode(Position pos) { - this.genNodesDialog.generateDefaultNode(pos); + this.getGenNodesDialog().generateDefaultNode(pos); } @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals(this.generateMenuItem.getActionCommand())) { + if (e.getActionCommand().equals(this.getGenerateMenuItem().getActionCommand())) { this.addNodes(); - } else if (e.getActionCommand().equals(this.clearMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getClearMenuItem().getActionCommand())) { if (0 == JOptionPane.showConfirmDialog(this, "Do you really want to remove all nodes?", "Remove all nodes?", JOptionPane.YES_NO_OPTION)) { this.clearAllNodes(); } - } else if (e.getActionCommand().equals(this.preferencesMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getPreferencesMenuItem().getActionCommand())) { new GraphPreferencesDialog(this); - } else if (e.getActionCommand().equals(this.reevaluateMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getReevaluateMenuItem().getActionCommand())) { if (0 == JOptionPane.showConfirmDialog(this, "Do you really want to reevaluate the connections of all nodes?", "Reevaluate Connections?", JOptionPane.YES_NO_OPTION)) { SinalgoRuntime.reevaluateConnections(); this.redrawGUI(); } - } else if (e.getActionCommand().equals(this.exportMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getExportMenuItem().getActionCommand())) { try { - new Exporter(this).export(new Rectangle(0, 0, this.graphPanel.getWidth(), this.graphPanel.getHeight()), + new Exporter(this).export(new Rectangle(0, 0, this.getGraphPanel().getWidth(), this.getGraphPanel().getHeight()), this.getTransformator()); } catch (ExportException e1) { Main.minorError(e1.getMessage()); } - } else if (e.getActionCommand().equals(this.infoMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getInfoMenuItem().getActionCommand())) { new GraphInfoDialog(this); - } else if (e.getActionCommand().equals(this.settingsMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getSettingsMenuItem().getActionCommand())) { new GlobalSettingsDialog(this); - } else if (e.getActionCommand().equals(this.aboutMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getAboutMenuItem().getActionCommand())) { new AboutDialog(this); - } else if (e.getActionCommand().equals(this.helpMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getHelpMenuItem().getActionCommand())) { HelpDialog.showHelp(this); // start in a new thread - } else if (e.getActionCommand().equals(this.exitMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getExitMenuItem().getActionCommand())) { Main.exitApplication(); - } else if (e.getActionCommand().equals(this.viewFullScreenMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getViewFullScreenMenuItem().getActionCommand())) { this.toggleFullScreen(); - } else if (e.getActionCommand().equals(this.viewZoomInMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getViewZoomInMenuItem().getActionCommand())) { this.zoomIn(); - } else if (e.getActionCommand().equals(this.viewZoomOutMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getViewZoomOutMenuItem().getActionCommand())) { this.zoomOut(); - } else if (e.getActionCommand().equals(this.viewZoomFitMenuItem.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getViewZoomFitMenuItem().getActionCommand())) { this.getTransformator().zoomToFit(this.getGraphPanel().getWidth(), this.getGraphPanel().getHeight()); this.setZoomFactor(this.getTransformator().getZoomFactor()); } @@ -874,7 +870,7 @@ public class GUI extends JFrame implements ActionListener { @Override public void actionPerformed(ActionEvent event) { - Method method = GUI.this.methodsAndNames.get(event.getSource()); + Method method = GUI.this.getMethodsAndNames().get(event.getSource()); if (method == null) { throw new SinalgoFatalException("Cannot find method associated with menu item " + event.getActionCommand()); } diff --git a/src/main/java/sinalgo/gui/GraphPanel.java b/src/main/java/sinalgo/gui/GraphPanel.java index 42f990b4ef37cdcaf7069e64da4202f1b338c582..928a9cf4ac802186c81346575b1902a58d5d221c 100644 --- a/src/main/java/sinalgo/gui/GraphPanel.java +++ b/src/main/java/sinalgo/gui/GraphPanel.java @@ -64,13 +64,7 @@ import sinalgo.tools.logging.Logging; import javax.swing.*; import javax.swing.event.MouseInputListener; import java.awt.*; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; +import java.awt.event.*; import java.util.ConcurrentModificationException; import java.util.Enumeration; import java.util.Stack; @@ -98,8 +92,7 @@ public class GraphPanel extends JPanel { private EdgePopupMenu edgePopupMenu; private SpacePopupMenu spacePopupMenu; - @Getter - private final GUI parent; + private final GUI parentGUI; private Node nodeToDrag; private Position nodeToDragInitialPosition = new Position(); // initial position of the node that is being dragged, @@ -156,11 +149,11 @@ public class GraphPanel extends JPanel { /** * Constructor for the GraphPanel class. * - * @param p The parent Frame (GUI) where the Graph Panel is added. + * @param p The parentGUI Frame (GUI) where the Graph Panel is added. */ public GraphPanel(GUI p) { - this.parent = p; - this.pt = this.parent.getTransformator(); + this.parentGUI = p; + this.pt = this.parentGUI.getTransformator(); MyMouseListener ml = new MyMouseListener(); this.addMouseListener(ml); @@ -169,13 +162,13 @@ public class GraphPanel extends JPanel { this.addKeyListener(new MyKeyListener()); this.setFocusable(true); - this.nodePopupMenu = new NodePopupMenu(this.parent); + this.nodePopupMenu = new NodePopupMenu(this.parentGUI); this.add(this.nodePopupMenu); - this.edgePopupMenu = new EdgePopupMenu(this.parent); + this.edgePopupMenu = new EdgePopupMenu(this.parentGUI); this.add(this.edgePopupMenu); - this.spacePopupMenu = new SpacePopupMenu(this.parent); + this.spacePopupMenu = new SpacePopupMenu(this.parentGUI); this.add(this.spacePopupMenu); this.imageSizeX = this.getWidth(); @@ -218,7 +211,7 @@ public class GraphPanel extends JPanel { */ public void defaultView() { this.pt.defaultView(this.imageSizeX, this.imageSizeY); - this.parent.setZoomFactor(this.pt.getZoomFactor()); // initiates redrawing the graph + this.parentGUI.setZoomFactor(this.pt.getZoomFactor()); // initiates redrawing the graph } /** @@ -226,7 +219,7 @@ public class GraphPanel extends JPanel { */ private void defaultViewWithoutRedraw() { this.pt.defaultView(this.imageSizeX, this.imageSizeY); - this.parent.setZoomFactorNoRepaint(this.pt.getZoomFactor()); + this.parentGUI.setZoomFactorNoRepaint(this.pt.getZoomFactor()); } /** @@ -588,9 +581,9 @@ public class GraphPanel extends JPanel { */ private void setDefaultCursor() { if (this.isUserSelectsNodeMode()) { - this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + this.getParentGUI().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { - this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + this.getParentGUI().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } @@ -829,8 +822,8 @@ public class GraphPanel extends JPanel { if (GraphPanel.this.getPt().supportReverseTranslation()) { GraphPanel.this.getPt().translateToLogicPosition(event.getX(), event.getY()); try { - GraphPanel.this.getParent().addSingleDefaultNode(new Position(GraphPanel.this.getPt().getLogicX(), GraphPanel.this.pt.getLogicY(), GraphPanel.this.pt.getLogicZ())); - GraphPanel.this.getParent().redrawGUI(); + GraphPanel.this.getParentGUI().addSingleDefaultNode(new Position(GraphPanel.this.getPt().getLogicX(), GraphPanel.this.pt.getLogicY(), GraphPanel.this.pt.getLogicZ())); + GraphPanel.this.getParentGUI().redrawGUI(); } catch (WrongConfigurationException e1) { Main.minorError(e1); } @@ -903,7 +896,7 @@ public class GraphPanel extends JPanel { GraphPanel.this.requestFocusInWindow(); // request focus s.t. key events are obtained (escape) if (GraphPanel.this.getPt().supportReverseTranslation()) { // only start dragging if it's supported GraphPanel.this.setNodeToDrag(node); - GraphPanel.this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + GraphPanel.this.getParentGUI().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { GraphPanel.this.setNodeToDrag(node); GraphPanel.this.setNodeToDragDrawCoordCube(node); @@ -933,7 +926,7 @@ public class GraphPanel extends JPanel { } else { // scroll the pane GraphPanel.this.setShiftStartPoint(e.getPoint()); - GraphPanel.this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + GraphPanel.this.getParentGUI().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } } } @@ -968,7 +961,7 @@ public class GraphPanel extends JPanel { GraphPanel.this.getNodeToAddEdge().getOutgoingConnections() .add(GraphPanel.this.getNodeToAddEdge(), targetNode, false); } catch (WrongConfigurationException wCE) { - JOptionPane.showMessageDialog(GraphPanel.this.getParent(), wCE.getMessage(), + JOptionPane.showMessageDialog(GraphPanel.this.getParentGUI(), wCE.getMessage(), "Configuration Error", JOptionPane.ERROR_MESSAGE); } } @@ -976,7 +969,7 @@ public class GraphPanel extends JPanel { GraphPanel.this.setTargetNodeToAddEdge(null); GraphPanel.this.setNodeToAddEdge(null); if (targetNode != null) { - GraphPanel.this.getParent().redrawGUI(); // we added an edge, need to repaint the graph + GraphPanel.this.getParentGUI().redrawGUI(); // we added an edge, need to repaint the graph } else { GraphPanel.this.repaint(); } @@ -997,16 +990,16 @@ public class GraphPanel extends JPanel { GraphPanel.this.getZoomRect().height = -GraphPanel.this.getZoomRect().height; } GraphPanel.this.getPt().zoomToRect(GraphPanel.this.getZoomRect()); - GraphPanel.this.getParent().setZoomFactor(GraphPanel.this.getPt().getZoomFactor()); + GraphPanel.this.getParentGUI().setZoomFactor(GraphPanel.this.getPt().getZoomFactor()); } GraphPanel.this.setZoomRect(null); - GraphPanel.this.getParent().redrawGUI(); + GraphPanel.this.getParentGUI().redrawGUI(); } } else if (e.getButton() == MouseEvent.BUTTON3) { // the right button GraphPanel.this.setNodeToDragDrawCoordCube(null); GraphPanel.this.setDefaultCursor(); GraphPanel.this.setNodeToDrag(null); - GraphPanel.this.getParent().redrawGUI(); + GraphPanel.this.getParentGUI().redrawGUI(); } Global.getLog().logln(LogL.GUI_ULTRA_DETAIL, "Mouse Released finished"); } @@ -1057,7 +1050,7 @@ public class GraphPanel extends JPanel { && (GraphPanel.this.getPt().getLogicX() > 0) && (GraphPanel.this.getPt().getLogicY() < Configuration.getDimY()) && (GraphPanel.this.getPt().getLogicY() > 0)) { - GraphPanel.this.getParent().setMousePosition(GraphPanel.this.getPt().getLogicPositionString()); + GraphPanel.this.getParentGUI().setMousePosition(GraphPanel.this.getPt().getLogicPositionString()); } } @@ -1070,7 +1063,7 @@ public class GraphPanel extends JPanel { GraphPanel.this.getNodeToDrag() .setPosition(GraphPanel.this.getPt().getLogicX(), GraphPanel.this.getPt().getLogicY(), GraphPanel.this.getPt().getLogicZ()); this.moveViewOnMousesDrag(e.getPoint()); - GraphPanel.this.getParent().redrawGUI(); // we need to repaint the graph panel + GraphPanel.this.getParentGUI().redrawGUI(); // we need to repaint the graph panel } else { // 3D: move along the axis to which the angle of the mouse-motion is smallest GraphPanel.this.getPt().translateToGUIPosition(GraphPanel.this.getNodeToDrag().getPosition()); @@ -1089,24 +1082,24 @@ public class GraphPanel extends JPanel { // mouse-movement in direction of x-axis GraphPanel.this.pt.translateToGUIPosition(1, 0, 0); - double cX = GraphPanel.this.pt.getGuiXDouble() - originX; - double cY = GraphPanel.this.pt.getGuiYDouble() - originY; + double cX = GraphPanel.this.getPt().getGuiXDouble() - originX; + double cY = GraphPanel.this.getPt().getGuiYDouble() - originY; double xLength = Math.sqrt(cX * cX + cY * cY); double aX = (mouseDx * cX + mouseDy * cY) / (mouseLength * xLength); // cos(angle) of mouse-movement // with x-axis // mouse-movement in direction of y-axis - GraphPanel.this.pt.translateToGUIPosition(0, 1, 0); - cX = GraphPanel.this.pt.getGuiXDouble() - originX; - cY = GraphPanel.this.pt.getGuiYDouble() - originY; + GraphPanel.this.getPt().translateToGUIPosition(0, 1, 0); + cX = GraphPanel.this.getPt().getGuiXDouble() - originX; + cY = GraphPanel.this.getPt().getGuiYDouble() - originY; double yLength = Math.sqrt(cX * cX + cY * cY); double aY = (mouseDx * cX + mouseDy * cY) / (mouseLength * yLength); // cos(angle) of mouse-movement // with y-axis // mouse-movement in direction of z-axis - GraphPanel.this.pt.translateToGUIPosition(0, 0, 1); - cX = GraphPanel.this.pt.getGuiXDouble() - originX; - cY = GraphPanel.this.pt.getGuiYDouble() - originY; + GraphPanel.this.getPt().translateToGUIPosition(0, 0, 1); + cX = GraphPanel.this.getPt().getGuiXDouble() - originX; + cY = GraphPanel.this.getPt().getGuiYDouble() - originY; double zLength = Math.sqrt(cX * cX + cY * cY); double aZ = (mouseDx * cX + mouseDy * cY) / (mouseLength * zLength); // cos(angle) of mouse-movement // with z-axis @@ -1122,47 +1115,43 @@ public class GraphPanel extends JPanel { aZ = 0; } - Position p = GraphPanel.this.nodeToDrag.getPosition(); + Position p = GraphPanel.this.getNodeToDrag().getPosition(); if (Math.abs(aX) > Math.abs(aY) && Math.abs(aX) > Math.abs(aZ)) { - GraphPanel.this.nodeToDrag.setPosition(p.getXCoord() + Math.signum(aX) * mouseLength / xLength, p.getYCoord(), p.getZCoord()); + GraphPanel.this.getNodeToDrag().setPosition(p.getXCoord() + Math.signum(aX) * mouseLength / xLength, p.getYCoord(), p.getZCoord()); } else if (Math.abs(aY) > Math.abs(aZ)) { - GraphPanel.this.nodeToDrag.setPosition(p.getXCoord(), p.getYCoord() + Math.signum(aY) * mouseLength / yLength, p.getZCoord()); + GraphPanel.this.getNodeToDrag().setPosition(p.getXCoord(), p.getYCoord() + Math.signum(aY) * mouseLength / yLength, p.getZCoord()); } else { - GraphPanel.this.nodeToDrag.setPosition(p.getXCoord(), p.getYCoord(), p.getZCoord() + Math.signum(aZ) * mouseLength / zLength); + GraphPanel.this.getNodeToDrag().setPosition(p.getXCoord(), p.getYCoord(), p.getZCoord() + Math.signum(aZ) * mouseLength / zLength); } this.moveViewOnMousesDrag(e.getPoint()); - GraphPanel.this.parent.redrawGUI(); // we need to repaint the graph panel + GraphPanel.this.getParentGUI().redrawGUI(); // we need to repaint the graph panel } - } else if (GraphPanel.this.nodeToAddEdge != null) { + } else if (GraphPanel.this.getNodeToAddEdge() != null) { this.moveViewOnMousesDrag(e.getPoint()); - GraphPanel.this.targetNodeToAddEdge = GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY()); + GraphPanel.this.setTargetNodeToAddEdge(GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY())); // the drawing of the line is done while redrawing GraphPanel.this.repaint(); - } else if (GraphPanel.this.zoomRect != null) { - GraphPanel.this.zoomRect.width = e.getX() - GraphPanel.this.zoomRect.x; - GraphPanel.this.zoomRect.height = e.getY() - GraphPanel.this.zoomRect.y; + } else if (GraphPanel.this.getZoomRect() != null) { + GraphPanel.this.getZoomRect().width = e.getX() - GraphPanel.this.getZoomRect().x; + GraphPanel.this.getZoomRect().height = e.getY() - GraphPanel.this.getZoomRect().y; // currently, it's only allowed to select the region from top left to bottom // right :-( // if(zoomRect.width < 0){ zoomRect.width = 0; } // if(zoomRect.height < 0){ zoomRect.height = 0; } GraphPanel.this.repaint(); - } else if (GraphPanel.this.shiftStartPoint != null) { - GraphPanel.this.pt.moveView(e.getX() - GraphPanel.this.shiftStartPoint.x, e.getY() - GraphPanel.this.shiftStartPoint.y); - GraphPanel.this.shiftStartPoint = e.getPoint(); - GraphPanel.this.parent.redrawGUI(); // we need to redraw the graph - the view has changed - } else if (GraphPanel.this.rotateStartPoint != null) { - if (GraphPanel.this.pt instanceof Transformation3D) { - Transformation3D t3d = (Transformation3D) GraphPanel.this.pt; - t3d.rotate(e.getX() - GraphPanel.this.rotateStartPoint.x, e.getY() - GraphPanel.this.rotateStartPoint.y, !e.isControlDown(), false); // read - // keyboard - // - - // ctrl - // allows - // to - // freely - // rotate - GraphPanel.this.rotateStartPoint = e.getPoint(); - GraphPanel.this.parent.redrawGUI(); // need to redraw the graph - the view has changed + } else if (GraphPanel.this.getShiftStartPoint() != null) { + GraphPanel.this.getPt().moveView(e.getX() - GraphPanel.this.getShiftStartPoint().x, + e.getY() - GraphPanel.this.getShiftStartPoint().y); + GraphPanel.this.setShiftStartPoint(e.getPoint()); + GraphPanel.this.getParentGUI().redrawGUI(); // we need to redraw the graph - the view has changed + } else if (GraphPanel.this.getRotateStartPoint() != null) { + if (GraphPanel.this.getPt() instanceof Transformation3D) { + Transformation3D t3d = (Transformation3D) GraphPanel.this.getPt(); + t3d.rotate(e.getX() - GraphPanel.this.getRotateStartPoint().x, + e.getY() - GraphPanel.this.getRotateStartPoint().y, !e.isControlDown(), false); // read + // keyboard - ctrl allows to freely rotate + GraphPanel.this.setRotateStartPoint(e.getPoint()); + GraphPanel.this.getParentGUI().redrawGUI(); // need to redraw the graph - the view has changed } } Global.getLog().logln(LogL.GUI_ULTRA_DETAIL, "Mouse Dragged finished"); @@ -1170,21 +1159,23 @@ public class GraphPanel extends JPanel { @Override public void mouseMoved(MouseEvent e) { - GraphPanel.this.currentCursorPosition.setLocation(e.getX(), e.getY()); - if (GraphPanel.this.pt.supportReverseTranslation()) { - GraphPanel.this.pt.translateToLogicPosition(e.getX(), e.getY()); - if ((GraphPanel.this.pt.getLogicX() < Configuration.getDimX()) && (GraphPanel.this.pt.getLogicX() > 0) && (GraphPanel.this.pt.getLogicY() < Configuration.getDimY()) - && (GraphPanel.this.pt.getLogicY() > 0)) { - GraphPanel.this.parent.setMousePosition(GraphPanel.this.pt.getLogicPositionString()); + GraphPanel.this.getCurrentCursorPosition().setLocation(e.getX(), e.getY()); + if (GraphPanel.this.getPt().supportReverseTranslation()) { + GraphPanel.this.getPt().translateToLogicPosition(e.getX(), e.getY()); + if ((GraphPanel.this.getPt().getLogicX() < Configuration.getDimX()) + && (GraphPanel.this.getPt().getLogicX() > 0) + && (GraphPanel.this.getPt().getLogicY() < Configuration.getDimY()) + && (GraphPanel.this.getPt().getLogicY() > 0)) { + GraphPanel.this.getParentGUI().setMousePosition(GraphPanel.this.getPt().getLogicPositionString()); } } - if (GraphPanel.this.userSelectsNodeMode) { - GraphPanel.this.userSelectsNodeCurrentFocus = GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY()); + if (GraphPanel.this.isUserSelectsNodeMode()) { + GraphPanel.this.setUserSelectsNodeCurrentFocus(GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY())); GraphPanel.this.repaint(); // async call that does not repaint the network graph, but only the stuff on top // of the graph } else { - GraphPanel.this.userSelectsNodeCurrentFocus = null; + GraphPanel.this.setUserSelectsNodeCurrentFocus(null); } if (GraphPanel.this.getToolTipDrawCoordCube() != null) { GraphPanel.this.setToolTipDrawCoordCube(null); @@ -1208,9 +1199,9 @@ public class GraphPanel extends JPanel { } int clicks = e.getWheelRotation(); if (clicks < 0) { - GraphPanel.this.parent.zoom(Configuration.getWheelZoomStep()); // zoom In + GraphPanel.this.getParentGUI().zoom(Configuration.getWheelZoomStep()); // zoom In } else { - GraphPanel.this.parent.zoom(1.0 / Configuration.getWheelZoomStep()); // zoom out + GraphPanel.this.getParentGUI().zoom(1.0 / Configuration.getWheelZoomStep()); // zoom out } } } // END OF CLASS MyMouseListener @@ -1220,20 +1211,20 @@ public class GraphPanel extends JPanel { @Override public void keyPressed(KeyEvent e) { // react to pressing escape - if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ESCAPE) { - if (GraphPanel.this.nodeToDrag != null) { // stop dragging a node, and undo - GraphPanel.this.nodeToDrag.getPosition().assign(GraphPanel.this.nodeToDragInitialPosition); - GraphPanel.this.nodeToDragDrawCoordCube = null; - GraphPanel.this.nodeToDrag = null; - GraphPanel.this.parent.redrawGUI(); // node position has changed, full repaint + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + if (GraphPanel.this.getNodeToDrag() != null) { // stop dragging a node, and undo + GraphPanel.this.getNodeToDrag().getPosition().assign(GraphPanel.this.getNodeToDragInitialPosition()); + GraphPanel.this.setNodeToDragDrawCoordCube(null); + GraphPanel.this.setNodeToDrag(null); + GraphPanel.this.getParentGUI().redrawGUI(); // node position has changed, full repaint } - if (GraphPanel.this.nodeToAddEdge != null) { - GraphPanel.this.nodeToAddEdge = null; - GraphPanel.this.targetNodeToAddEdge = null; + if (GraphPanel.this.getNodeToAddEdge() != null) { + GraphPanel.this.setNodeToAddEdge(null); + GraphPanel.this.setTargetNodeToAddEdge(null); GraphPanel.this.repaint(); // no need to redraw whole gui, just repaint layer } - if (GraphPanel.this.zoomRect != null) { - GraphPanel.this.zoomRect = null; + if (GraphPanel.this.getZoomRect() != null) { + GraphPanel.this.setZoomRect(null); GraphPanel.this.repaint(); } } @@ -1261,7 +1252,7 @@ public class GraphPanel extends JPanel { // running) // We could disallow to resize the window during simulation, but then, the // window flickers - GraphPanel.this.parent.redrawGUI(); + GraphPanel.this.getParentGUI().redrawGUI(); } @Override diff --git a/src/main/java/sinalgo/gui/ProjectSelector.java b/src/main/java/sinalgo/gui/ProjectSelector.java index 746f685ea7fce7271f1372ff9e4a974cac1fb2a9..5f3afb37be89c0a15104286e5c0ed191cf57299b 100644 --- a/src/main/java/sinalgo/gui/ProjectSelector.java +++ b/src/main/java/sinalgo/gui/ProjectSelector.java @@ -36,6 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui; +import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.Setter; @@ -68,26 +69,10 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import javax.swing.text.JTextComponent; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.ComponentEvent; -import java.awt.event.ComponentListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; +import java.awt.event.*; import java.beans.IntrospectionException; import java.beans.PropertyDescriptor; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.io.StringReader; +import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -100,6 +85,8 @@ import java.util.Vector; /** * This class provides a dialog to let the user select a project. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class ProjectSelector extends JFrame implements ActionListener, ListSelectionListener { private static final long serialVersionUID = -6312902319966899446L; @@ -118,13 +105,12 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec private JPanel customConfigurationPanel = new JPanel(); private JButton saveConfig = new JButton("Save Config"); private JButton saveConfig2 = new JButton("Save Config"); - private JButton expand, collapse; + private JButton expand; + private JButton collapse; private JTextArea customParameters = new JTextArea(); private JTabbedPane right = new JTabbedPane(); - private AppConfig appConfig = AppConfig.getAppConfig(); - private boolean showOptionalFields = false; private Vector<ConfigEntry> projectEntries; @@ -147,7 +133,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec super("Select a Project"); GuiHelper.setWindowIcon(this); // show all the tooltips for 15000 mili-seconds - this.defaultTooltipDismissDelay = ToolTipManager.sharedInstance().getDismissDelay(); + this.setDefaultTooltipDismissDelay(ToolTipManager.sharedInstance().getDismissDelay()); int myTooltipDismissDelay = 15000; ToolTipManager.sharedInstance().setDismissDelay(myTooltipDismissDelay); this.main = main; @@ -162,29 +148,29 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec this.addComponentListener(new ComponentListener() { - int oldX = ProjectSelector.this.appConfig.getProjectSelectorWindowPosX(), oldY = ProjectSelector.this.appConfig.getProjectSelectorWindowPosY(); + int oldX = AppConfig.getAppConfig().getProjectSelectorWindowPosX(), oldY = AppConfig.getAppConfig().getProjectSelectorWindowPosY(); @Override public void componentResized(ComponentEvent e) { if (ProjectSelector.this.getExtendedState() == Frame.MAXIMIZED_BOTH) { - ProjectSelector.this.appConfig.setProjectSelectorIsMaximized(true); - ProjectSelector.this.appConfig.setProjectSelectorWindowPosX(this.oldX); - ProjectSelector.this.appConfig.setProjectSelectorWindowPosY(this.oldY); + AppConfig.getAppConfig().setProjectSelectorIsMaximized(true); + AppConfig.getAppConfig().setProjectSelectorWindowPosX(this.oldX); + AppConfig.getAppConfig().setProjectSelectorWindowPosY(this.oldY); } else { - ProjectSelector.this.appConfig.setProjectSelectorIsMaximized(false); - ProjectSelector.this.appConfig.setProjectSelectorWindowWidth(ProjectSelector.this.getWidth()); - ProjectSelector.this.appConfig.setProjectSelectorWindowHeight(ProjectSelector.this.getHeight()); + AppConfig.getAppConfig().setProjectSelectorIsMaximized(false); + AppConfig.getAppConfig().setProjectSelectorWindowWidth(ProjectSelector.this.getWidth()); + AppConfig.getAppConfig().setProjectSelectorWindowHeight(ProjectSelector.this.getHeight()); } - ProjectSelector.this.customParameters.setSize(100, ProjectSelector.this.customParameters.getHeight()); + ProjectSelector.this.getCustomParameters().setSize(100, ProjectSelector.this.getCustomParameters().getHeight()); // needed to ensure that the text field shrinks as well } @Override public void componentMoved(ComponentEvent e) { - this.oldX = ProjectSelector.this.appConfig.getProjectSelectorWindowPosX(); - this.oldY = ProjectSelector.this.appConfig.getProjectSelectorWindowPosY(); - ProjectSelector.this.appConfig.setProjectSelectorWindowPosX(ProjectSelector.this.getX()); - ProjectSelector.this.appConfig.setProjectSelectorWindowPosY(ProjectSelector.this.getY()); + this.oldX = AppConfig.getAppConfig().getProjectSelectorWindowPosX(); + this.oldY = AppConfig.getAppConfig().getProjectSelectorWindowPosY(); + AppConfig.getAppConfig().setProjectSelectorWindowPosX(ProjectSelector.this.getX()); + AppConfig.getAppConfig().setProjectSelectorWindowPosY(ProjectSelector.this.getY()); } @Override @@ -205,8 +191,8 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec @Override public void windowClosing(WindowEvent e) { - ProjectSelector.this.appConfig.setProjectSelectorSelectedTab(1 + ProjectSelector.this.right.getSelectedIndex()); - ProjectSelector.this.appConfig.writeConfig(); + AppConfig.getAppConfig().setProjectSelectorSelectedTab(1 + ProjectSelector.this.getRight().getSelectedIndex()); + AppConfig.getAppConfig().writeConfig(); } @Override @@ -232,40 +218,40 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec this.setLayout(new BorderLayout()); this.setResizable(true); - if (this.appConfig.isProjectSelectorIsMaximized()) { + if (AppConfig.getAppConfig().isProjectSelectorIsMaximized()) { this.setExtendedState(Frame.MAXIMIZED_BOTH); } - this.setSize(new Dimension(this.appConfig.getProjectSelectorWindowWidth(), this.appConfig.getProjectSelectorWindowHeight())); - this.setLocation(this.appConfig.getProjectSelectorWindowPosX(), this.appConfig.getProjectSelectorWindowPosY()); + this.setSize(new Dimension(AppConfig.getAppConfig().getProjectSelectorWindowWidth(), AppConfig.getAppConfig().getProjectSelectorWindowHeight())); + this.setLocation(AppConfig.getAppConfig().getProjectSelectorWindowPosX(), AppConfig.getAppConfig().getProjectSelectorWindowPosY()); JPanel left = new JPanel(); left.setLayout(new BorderLayout()); // List of all projects - this.selection.setListData(projects); - this.selection.setSelectedValue(this.appConfig.getLastChosenProject(), true); - if (!this.selection.isSelectionEmpty()) { - this.selectedProjectName = (String) this.selection.getSelectedValue(); + this.getSelection().setListData(projects); + this.getSelection().setSelectedValue(AppConfig.getAppConfig().getLastChosenProject(), true); + if (!this.getSelection().isSelectionEmpty()) { + this.setSelectedProjectName((String) this.getSelection().getSelectedValue()); } else { - this.selectedProjectName = ""; + this.setSelectedProjectName(""); } - this.selection.addListSelectionListener(this); - this.selection.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 0)); - this.selection.setBackground(this.listPanel.getBackground()); - JScrollPane listScroller = new JScrollPane(this.selection); - this.listPanel.setLayout(new BorderLayout()); + this.getSelection().addListSelectionListener(this); + this.getSelection().setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 0)); + this.getSelection().setBackground(this.getListPanel().getBackground()); + JScrollPane listScroller = new JScrollPane(this.getSelection()); + this.getListPanel().setLayout(new BorderLayout()); listScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); - this.listPanel.add(listScroller, BorderLayout.CENTER); - this.listPanel.setBorder(BorderFactory.createTitledBorder("Available Projects")); - left.add(this.listPanel, BorderLayout.CENTER); + this.getListPanel().add(listScroller, BorderLayout.CENTER); + this.getListPanel().setBorder(BorderFactory.createTitledBorder("Available Projects")); + left.add(this.getListPanel(), BorderLayout.CENTER); // OK / Cancel buttons - this.buttonPanel.add(this.ok); - this.buttonPanel.add(this.cancel); - this.ok.addActionListener(this); - this.cancel.addActionListener(this); + this.getButtonPanel().add(this.getOk()); + this.getButtonPanel().add(this.getCancel()); + this.getOk().addActionListener(this); + this.getCancel().addActionListener(this); int projectListWidth = 160; - this.buttonPanel.setPreferredSize(new Dimension(projectListWidth, 40)); - left.add(this.buttonPanel, BorderLayout.SOUTH); + this.getButtonPanel().setPreferredSize(new Dimension(projectListWidth, 40)); + left.add(this.getButtonPanel(), BorderLayout.SOUTH); this.add(left, BorderLayout.WEST); @@ -275,72 +261,72 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec // The tab containing the description of the selected project JPanel description = new JPanel(); description.setLayout(new BorderLayout()); - JScrollPane scrollableDescriptionPane = new JScrollPane(this.descriptionText); + JScrollPane scrollableDescriptionPane = new JScrollPane(this.getDescriptionText()); description.add(scrollableDescriptionPane); - this.descriptionText.setEditable(false); - this.descriptionText.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + this.getDescriptionText().setEditable(false); + this.getDescriptionText().setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - int i = this.selection.getSelectedIndex(); + int i = this.getSelection().getSelectedIndex(); if (i == -1) { // there was no defaultProject - this.descriptionText.setText("Please select a project."); + this.getDescriptionText().setText("Please select a project."); } else { - this.generateGUIDescription(this.selectedProjectName); + this.generateGUIDescription(this.getSelectedProjectName()); } - this.right.addTab("Description", description); + this.getRight().addTab("Description", description); // The tab containing the config-file entries - this.configuration.setLayout(new BoxLayout(this.configuration, BoxLayout.Y_AXIS)); + this.getConfiguration().setLayout(new BoxLayout(this.getConfiguration(), BoxLayout.Y_AXIS)); - JScrollPane scrollableConfigurationPane = new JScrollPane(this.frameworkConfigurationPanel); + JScrollPane scrollableConfigurationPane = new JScrollPane(this.getFrameworkConfigurationPanel()); // increment the scroll speed (for some reason the speed for the // scrollableConfigurationPane is very low) scrollableConfigurationPane.getVerticalScrollBar().setUnitIncrement(15); - this.frameworkConfigurationPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + this.getFrameworkConfigurationPanel().setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); - this.configuration.add(scrollableConfigurationPane); + this.getConfiguration().add(scrollableConfigurationPane); JPanel bp = new JPanel(); - bp.add(this.saveConfig); - this.saveConfig.addActionListener(this); - this.saveConfig.setMnemonic(java.awt.event.KeyEvent.VK_S); - this.configuration.add(bp); + bp.add(this.getSaveConfig()); + this.getSaveConfig().addActionListener(this); + this.getSaveConfig().setMnemonic(java.awt.event.KeyEvent.VK_S); + this.getConfiguration().add(bp); - this.expand = this.createFrameworkIconButton("expand", "expand.gif", "Show advanced settings"); - this.collapse = this.createFrameworkIconButton("collapse", "collapse.gif", "Hide advanced settings"); + this.setExpand(this.createFrameworkIconButton("expand", "expand.gif", "Show advanced settings")); + this.setCollapse(this.createFrameworkIconButton("collapse", "collapse.gif", "Hide advanced settings")); - this.customConfigurationPanel.setLayout(new BorderLayout()); + this.getCustomConfigurationPanel().setLayout(new BorderLayout()); JPanel mainCustomConfigurationPanel = new JPanel(); mainCustomConfigurationPanel.setLayout(new BoxLayout(mainCustomConfigurationPanel, BoxLayout.Y_AXIS)); - mainCustomConfigurationPanel.add(this.customConfigurationPanel); + mainCustomConfigurationPanel.add(this.getCustomConfigurationPanel()); // and the save button JPanel bp2 = new JPanel(); - bp2.add(this.saveConfig2); - this.saveConfig2.addActionListener(this); - this.saveConfig2.setMnemonic(java.awt.event.KeyEvent.VK_S); + bp2.add(this.getSaveConfig2()); + this.getSaveConfig2().addActionListener(this); + this.getSaveConfig2().setMnemonic(java.awt.event.KeyEvent.VK_S); mainCustomConfigurationPanel.add(bp2); - this.right.addTab("Framework Config", this.configuration); - this.right.addTab("Project Config", mainCustomConfigurationPanel); - this.right.setMnemonicAt(0, java.awt.event.KeyEvent.VK_D); - this.right.setMnemonicAt(1, java.awt.event.KeyEvent.VK_F); - this.right.setMnemonicAt(2, java.awt.event.KeyEvent.VK_P); - this.right.setSelectedIndex(this.appConfig.getProjectSelectorSelectedTab() - 1); + this.getRight().addTab("Framework Config", this.getConfiguration()); + this.getRight().addTab("Project Config", mainCustomConfigurationPanel); + this.getRight().setMnemonicAt(0, java.awt.event.KeyEvent.VK_D); + this.getRight().setMnemonicAt(1, java.awt.event.KeyEvent.VK_F); + this.getRight().setMnemonicAt(2, java.awt.event.KeyEvent.VK_P); + this.getRight().setSelectedIndex(AppConfig.getAppConfig().getProjectSelectorSelectedTab() - 1); if (i == -1) { JTextField msg = new JTextField("Please select a project."); msg.setEditable(false); - this.frameworkConfigurationPanel.add(msg); + this.getFrameworkConfigurationPanel().add(msg); } else { - this.generateGUIGonfiguration(this.selectedProjectName); + this.generateGUIGonfiguration(this.getSelectedProjectName()); } - this.add(this.right, BorderLayout.CENTER); + this.add(this.getRight(), BorderLayout.CENTER); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - this.getRootPane().setDefaultButton(this.ok); + this.getRootPane().setDefaultButton(this.getOk()); this.setVisible(true); @@ -391,7 +377,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec InputStream proj = cldr.getResourceAsStream(IOUtils.getAsPath(Configuration.getProjectResourceDirPrefix(), projectName, Configuration.getDescriptionFileName())); try { if (proj == null) { - this.descriptionText.setText("There is no description-file in the currently selected project."); + this.getDescriptionText().setText("There is no description-file in the currently selected project."); } else { LineNumberReader r = new LineNumberReader(new InputStreamReader(proj)); StringBuilder description = new StringBuilder(); @@ -399,14 +385,14 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec while ((tmp = r.readLine()) != null) { description.append(tmp).append("\n"); } - this.descriptionText.setText(description.toString()); - this.descriptionText.setCaretPosition(0); + this.getDescriptionText().setText(description.toString()); + this.getDescriptionText().setCaretPosition(0); } } catch (FileNotFoundException e) { - this.descriptionText.setText("There is no description-file in the currently selected project."); + this.getDescriptionText().setText("There is no description-file in the currently selected project."); } catch (IOException e) { Main.minorError(e); - this.descriptionText.setText("There is no description-file in the currently selected project."); + this.getDescriptionText().setText("There is no description-file in the currently selected project."); } } @@ -491,7 +477,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec } } - this.projectEntries = new Vector<>(); + this.setProjectEntries(new Vector<>()); Class<?> configClass = Configuration.class; // We assume here that the fields are returned in the order they are listed in @@ -518,7 +504,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec if (dan != null || oan != null) { if (san != null) { // get the title sectionName = san.value(); - this.projectEntries.add(new ConfigEntry(sectionName, "", Configuration.SectionInConfigFile.class, "", + this.getProjectEntries().add(new ConfigEntry(sectionName, "", Configuration.SectionInConfigFile.class, "", false, field)); } String description = dan != null ? dan.value() : oan.value(); // the description text @@ -533,11 +519,11 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec if (value == null) { Object fieldValue = useGetter ? getter.invoke(null) : field.get(null); // there was no entry in the config-file. Take the default value. - this.projectEntries.add( + this.getProjectEntries().add( new ConfigEntry(field.getName(), Configuration.getConfigurationText(fieldValue), field.getType(), description, oan != null, field)); } else { // there is an entry in the XML file - this.projectEntries.add(new ConfigEntry(field.getName(), value, field.getType(), description, + this.getProjectEntries().add(new ConfigEntry(field.getName(), value, field.getType(), description, oan != null, field)); // elem.comment } } else if (field.getName().equals("edgeType")) { @@ -552,10 +538,10 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec } if (value == null) { // there was no entry in the config-file. Take the default value. - this.projectEntries.add(new ConfigEntry(field.getName(), Configuration.getEdgeType(), + this.getProjectEntries().add(new ConfigEntry(field.getName(), Configuration.getEdgeType(), field.getType(), comment, oan != null, field)); } else { - this.projectEntries.add(new ConfigEntry(field.getName(), value, + this.getProjectEntries().add(new ConfigEntry(field.getName(), value, field.getType(), comment, oan != null, field)); } } @@ -567,9 +553,9 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec // for each entry, create the corresponding GUI components - this.asynchronousSimulationCB = null; - this.mobilityCB = null; - for (ConfigEntry e : this.projectEntries) { + this.setAsynchronousSimulationCB(null); + this.setMobilityCB(null); + for (ConfigEntry e : this.getProjectEntries()) { String ttt = e.getComment().equals("") ? null : e.getComment(); // the tool tip text, don't show at all, if no text to // display @@ -591,22 +577,22 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec } else { booleanChoice.setSelectedItem("true"); } - booleanChoice.addActionListener(this.userInputListener); // ! add this listener AFTER setting the value! + booleanChoice.addActionListener(this.getUserInputListener()); // ! add this listener AFTER setting the value! booleanChoice.setToolTipText(ttt); e.setValueComponent(booleanChoice); // special case: mobility can only be changed if simulation is in sync mode. if (e.getKey().equals("asynchronousMode")) { - this.asynchronousSimulationCB = booleanChoice; - if (this.mobilityCB != null && (e.getValue()).equals("true")) { - this.mobilityCB.setSelectedItem("false"); - this.mobilityCB.setEnabled(false); + this.setAsynchronousSimulationCB(booleanChoice); + if (this.getMobilityCB() != null && (e.getValue()).equals("true")) { + this.getMobilityCB().setSelectedItem("false"); + this.getMobilityCB().setEnabled(false); } } if (e.getKey().equals("mobility")) { - this.mobilityCB = booleanChoice; - if (this.asynchronousSimulationCB != null && "true".equals(this.asynchronousSimulationCB.getSelectedItem())) { - this.mobilityCB.setSelectedItem("false"); - this.mobilityCB.setEnabled(false); + this.setMobilityCB(booleanChoice); + if (this.getAsynchronousSimulationCB() != null && "true".equals(this.getAsynchronousSimulationCB().getSelectedItem())) { + this.getMobilityCB().setSelectedItem("false"); + this.getMobilityCB().setEnabled(false); } } } else if (e.getEntryClass() == Configuration.SectionInConfigFile.class) { @@ -621,7 +607,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec choice.setEditable(true); // let the user the freedom to enter other stuff (which is likely to be // wrong...) choice.setSelectedItem(e.getValue()); - choice.addActionListener(this.userInputListener); // ! add this listener AFTER setting the value! + choice.addActionListener(this.getUserInputListener()); // ! add this listener AFTER setting the value! choice.setToolTipText(ttt); e.setValueComponent(choice); } else { @@ -631,12 +617,12 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec textArea.setBorder((new JTextField()).getBorder()); // copy the border textArea.setLineWrap(true); // textArea.setPreferredSize(new Dimension(50, 30)); - textArea.addKeyListener(this.userInputListener); + textArea.addKeyListener(this.getUserInputListener()); e.setValueComponent(textArea); } else { MultiLineToolTipJTextField textField = new MultiLineToolTipJTextField(e.getValue()); textField.setToolTipText(ttt); - textField.addKeyListener(this.userInputListener); + textField.addKeyListener(this.getUserInputListener()); e.setValueComponent(textField); } } @@ -645,7 +631,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec // and finally add all the entries this.insertProjectEntries(); - this.customConfigurationPanel.removeAll(); + this.getCustomConfigurationPanel().removeAll(); // And add the custom entries @@ -660,24 +646,24 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec // customParameters.addMouseWheelListener(new // MouseWheelForwarder(scrollableConfigurationPane.getMouseWheelListeners())); - this.customParameters.setTabSize(3); - this.customParameters.setLineWrap(true); - this.customParameters.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); + this.getCustomParameters().setTabSize(3); + this.getCustomParameters().setLineWrap(true); + this.getCustomParameters().setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); if (configExists) { - this.customParameters.setText(this.getCustomText(IOUtils.getProjectConfigurationAsReader(projectName))); + this.getCustomParameters().setText(this.getCustomText(IOUtils.getProjectConfigurationAsReader(projectName))); } else { - this.customParameters.setText(""); + this.getCustomParameters().setText(""); } - this.customParameters.addKeyListener(this.userInputListener); // ! add this listener AFTER setting the text ! + this.getCustomParameters().addKeyListener(this.getUserInputListener()); // ! add this listener AFTER setting the text ! - JScrollPane customScroll = new JScrollPane(this.customParameters, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, + JScrollPane customScroll = new JScrollPane(this.getCustomParameters(), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); customScroll.setWheelScrollingEnabled(true); - this.customConfigurationPanel.add(customScroll); + this.getCustomConfigurationPanel().add(customScroll); - this.userInputListener.reset(); + this.getUserInputListener().reset(); super.repaint(); } @@ -689,14 +675,14 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec * keep what he has already entered. */ private void insertProjectEntries() { - this.frameworkConfigurationPanel.removeAll(); - this.frameworkConfigurationPanel.setLayout(new BorderLayout()); + this.getFrameworkConfigurationPanel().removeAll(); + this.getFrameworkConfigurationPanel().setLayout(new BorderLayout()); JPanel entryTable = new JPanel(); - this.frameworkConfigurationPanel.add(entryTable, BorderLayout.CENTER); - if (this.showOptionalFields) { - this.frameworkConfigurationPanel.add(this.collapse, BorderLayout.SOUTH); // add the 'expand' button + this.getFrameworkConfigurationPanel().add(entryTable, BorderLayout.CENTER); + if (this.isShowOptionalFields()) { + this.getFrameworkConfigurationPanel().add(this.getCollapse(), BorderLayout.SOUTH); // add the 'expand' button } else { - this.frameworkConfigurationPanel.add(this.expand, BorderLayout.SOUTH); // add the 'expand' button + this.getFrameworkConfigurationPanel().add(this.getExpand(), BorderLayout.SOUTH); // add the 'expand' button } entryTable.removeAll(); @@ -704,12 +690,12 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec int numEntryTableLines = 0; // count number of rows added to entryTable - for (ConfigEntry e : this.projectEntries) { + for (ConfigEntry e : this.getProjectEntries()) { if (e.getValueComponent() == null) { // it's a title title = e; continue; } - if (e.isOptional() && !this.showOptionalFields) { + if (e.isOptional() && !this.isShowOptionalFields()) { continue; } if (title != null) { // first print the title @@ -739,7 +725,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec private Document validateCustomFields() { Document doc; try { - String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Document><Custom>" + this.customParameters.getText() + String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Document><Custom>" + this.getCustomParameters().getText() + "</Custom></Document>"; doc = new SAXBuilder().build(new StringReader(xml)); } catch (JDOMException e) { @@ -769,7 +755,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec root.addContent(custom); custom.addContent(new Element("_xml_custom_")); // this tag will be replaced by the config text in a second step - for (ConfigEntry e : this.projectEntries) { + for (ConfigEntry e : this.getProjectEntries()) { if (e.getValueComponent() != null) { // there is a value field in the GUI if (!Objects.equals("", e.getComment())) { // the comment is not "", add it framework.addContent(new Comment(e.getComment().replace("\n", " "))); // without the newline chars @@ -804,7 +790,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec String outputPath = IOUtils.getAsPath( (isTemporary ? Configuration.getAppTmpFolder() : Configuration.getAppConfigDir()), - Configuration.getUserProjectsPackage(), this.selectedProjectName); + Configuration.getUserProjectsPackage(), this.getSelectedProjectName()); IOUtils.createDir(outputPath); File outputFile = new File(IOUtils.getAsPath(outputPath, Configuration.getConfigfileFileName() + (isTemporary ? ".run" : ""))); @@ -814,7 +800,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec f.setIndent("\t"); outputter.setFormat(f); String tempOutputFolder = IOUtils.getAsPath(Configuration.getAppTmpFolder(), - Configuration.getUserProjectsPackage(), this.selectedProjectName); + Configuration.getUserProjectsPackage(), this.getSelectedProjectName()); IOUtils.createDir(tempOutputFolder); File tempOutputFile = new File(IOUtils.getAsPath(tempOutputFolder, Configuration.getConfigfileFileName() + ".temp")); @@ -835,7 +821,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec if (line.contains("<_xml_NL_")) { output.newLine(); } else if (line.contains("<_xml_custom_")) { - output.write(this.customParameters.getText()); + output.write(this.getCustomParameters().getText()); } else { output.write(line); output.newLine(); @@ -847,7 +833,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec Main.minorError("Could not write the configuration file!\n\n" + e1.getMessage()); } - this.userInputListener.reset(); // finally reset the 'modified' flag + this.getUserInputListener().reset(); // finally reset the 'modified' flag } /*-**********************************************************************************/ @@ -859,7 +845,7 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec * project selector configuration. */ private void setFrameworkConfig() { - for (ConfigEntry e : this.projectEntries) { + for (ConfigEntry e : this.getProjectEntries()) { if (e.getValueComponent() == null) { continue; // this entry does not have a value - its probably a section header } @@ -875,8 +861,8 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec @Override public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(this.saveConfig) || e.getSource().equals(this.saveConfig2)) { // -------------------------------------------------------------------- - if (this.selection.getSelectedValue() == null) { + if (e.getSource().equals(this.getSaveConfig()) || e.getSource().equals(this.getSaveConfig2())) { // -------------------------------------------------------------------- + if (this.getSelection().getSelectedValue() == null) { JOptionPane.showMessageDialog(this, "Please select a project from the selection.", "No project selected.", JOptionPane.ERROR_MESSAGE); } else { @@ -886,12 +872,12 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec throw new SinalgoWrappedException(ex); } } - } else if (e.getSource().equals(this.ok)) { // -------------------------------------------------------------------- - if (this.selection.getSelectedValue() == null) { + } else if (e.getSource().equals(this.getOk())) { // -------------------------------------------------------------------- + if (this.getSelection().getSelectedValue() == null) { JOptionPane.showMessageDialog(this, "Please select a project from the selection.", "No project selected.", JOptionPane.ERROR_MESSAGE); } else { - if (this.userInputListener.isModified()) { + if (this.getUserInputListener().isModified()) { // the user has modified the config, but not stored it int decision = JOptionPane.showConfirmDialog(this, "The modifications to this configuration have not yet been saved.\n\nDo you want to store this configuration, such that it is also available for subsequent runs?", @@ -913,10 +899,10 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec return; } - if (!this.selectedProjectName.equals("defaultProject")) { - Global.setProjectName(this.selectedProjectName); + if (!this.getSelectedProjectName().equals("defaultProject")) { + Global.setProjectName(this.getSelectedProjectName()); Global.setUseProject(true); - this.appConfig.setLastChosenProject(Global.getProjectName()); + AppConfig.getAppConfig().setLastChosenProject(Global.getProjectName()); } Element customEle = customDoc.getRootElement().getChild("Custom"); @@ -930,23 +916,23 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec this.setVisible(false); // reset the tooltip dismiss delay to the default value - ToolTipManager.sharedInstance().setDismissDelay(this.defaultTooltipDismissDelay); + ToolTipManager.sharedInstance().setDismissDelay(this.getDefaultTooltipDismissDelay()); - this.appConfig.setProjectSelectorSelectedTab(1 + this.right.getSelectedIndex()); - this.appConfig.writeConfig(); // write the config, s.t. when the main application crashes, at least the + AppConfig.getAppConfig().setProjectSelectorSelectedTab(1 + this.getRight().getSelectedIndex()); + AppConfig.getAppConfig().writeConfig(); // write the config, s.t. when the main application crashes, at least the // project selector config is preserved this.storeConfig(true); // store the config to a file s.t. the simulation process can read it // wake up the waiting object. - synchronized (this.main) { - this.main.notify(); + synchronized (this.getMain()) { + this.getMain().notify(); } } - } else if (e.getSource().equals(this.cancel)) { // -------------------------------------------------------------------- - if (this.userInputListener.isModified()) { + } else if (e.getSource().equals(this.getCancel())) { // -------------------------------------------------------------------- + if (this.getUserInputListener().isModified()) { // the user has modified the config, but not stored it int decision = JOptionPane.showConfirmDialog(this, - "The configuration for project '" + this.selectedProjectName + "The configuration for project '" + this.getSelectedProjectName() + "' has unsaved changes. Do you wish to save them?", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION); if (decision == JOptionPane.YES_OPTION) { // store @@ -960,15 +946,15 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec return; } } - this.appConfig.setProjectSelectorSelectedTab(1 + this.right.getSelectedIndex()); - this.appConfig.writeConfig(); + AppConfig.getAppConfig().setProjectSelectorSelectedTab(1 + this.getRight().getSelectedIndex()); + AppConfig.getAppConfig().writeConfig(); System.exit(1); - } else if (e.getSource().equals(this.collapse)) { // -------------------------------------------------------------------- - this.showOptionalFields = false; + } else if (e.getSource().equals(this.getCollapse())) { // -------------------------------------------------------------------- + this.setShowOptionalFields(false); this.insertProjectEntries(); this.repaint(); - } else if (e.getSource().equals(this.expand)) { // -------------------------------------------------------------------- - this.showOptionalFields = true; + } else if (e.getSource().equals(this.getExpand())) { // -------------------------------------------------------------------- + this.setShowOptionalFields(true); this.insertProjectEntries(); this.repaint(); } @@ -977,10 +963,10 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { - if (this.userInputListener.isModified()) { + if (this.getUserInputListener().isModified()) { // the user has modified the config, but not stored it int decision = JOptionPane.showConfirmDialog(this, - "The configuration for project '" + this.selectedProjectName + "The configuration for project '" + this.getSelectedProjectName() + "' has unsaved changes. Do you wish to save them?", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION); if (decision == JOptionPane.YES_OPTION) { // store @@ -991,15 +977,15 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec } } if (decision == JOptionPane.CANCEL_OPTION) { - this.selection.removeListSelectionListener(this); - this.selection.setSelectedValue(this.selectedProjectName, true); - this.selection.addListSelectionListener(this); + this.getSelection().removeListSelectionListener(this); + this.getSelection().setSelectedValue(this.getSelectedProjectName(), true); + this.getSelection().addListSelectionListener(this); return; } } - this.selectedProjectName = (String) this.selection.getSelectedValue(); - this.generateGUIGonfiguration(this.selectedProjectName); - this.generateGUIDescription(this.selectedProjectName); + this.setSelectedProjectName((String) this.getSelection().getSelectedValue()); + this.generateGUIGonfiguration(this.getSelectedProjectName()); + this.generateGUIDescription(this.getSelectedProjectName()); } } @@ -1009,21 +995,18 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec */ private class UserInputListener implements KeyListener, ActionListener { + @Getter private boolean isModified = false; - public boolean isModified() { - return this.isModified; - } - public void reset() { - ProjectSelector.this.saveConfig.setEnabled(false); - ProjectSelector.this.saveConfig2.setEnabled(false); + ProjectSelector.this.getSaveConfig().setEnabled(false); + ProjectSelector.this.getSaveConfig2().setEnabled(false); this.isModified = false; } public void setModified() { - ProjectSelector.this.saveConfig.setEnabled(true); - ProjectSelector.this.saveConfig2.setEnabled(true); + ProjectSelector.this.getSaveConfig().setEnabled(true); + ProjectSelector.this.getSaveConfig2().setEnabled(true); this.isModified = true; } @@ -1047,13 +1030,13 @@ public class ProjectSelector extends JFrame implements ActionListener, ListSelec } private void test(ActionEvent e) { - if (e.getSource() == ProjectSelector.this.asynchronousSimulationCB) { - if (ProjectSelector.this.mobilityCB != null) { - if ("true".equals(ProjectSelector.this.asynchronousSimulationCB.getSelectedItem())) { - ProjectSelector.this.mobilityCB.setSelectedItem("false"); - ProjectSelector.this.mobilityCB.setEnabled(false); + if (e.getSource() == ProjectSelector.this.getAsynchronousSimulationCB()) { + if (ProjectSelector.this.getMobilityCB() != null) { + if ("true".equals(ProjectSelector.this.getAsynchronousSimulationCB().getSelectedItem())) { + ProjectSelector.this.getMobilityCB().setSelectedItem("false"); + ProjectSelector.this.getMobilityCB().setEnabled(false); } else { - ProjectSelector.this.mobilityCB.setEnabled(true); + ProjectSelector.this.getMobilityCB().setEnabled(true); } } } diff --git a/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java b/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java index b8d4fe05b4f4e0c9c4314d717e21e0173bfe72d7..1e58440c76ec2a96113a4b27b4525bfd3f500d2f 100644 --- a/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/ControlPanel.java @@ -122,8 +122,7 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou @Setter private Color bgColor = new Color(this.getBackground().getRed(), this.getBackground().getGreen(), this.getBackground().getBlue()); - @Getter // public getter for overriding that of JPanel's - private GUI parent = null; + private GUI parentGUI = null; private JTextField roundsPerformed = new JTextField(0); private JTextField timePerformed = new JTextField(0); @@ -250,11 +249,11 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou * happens when called on a 2D graph. */ public void defaultViewXY() { - PositionTransformation pt = this.getParent().getTransformator(); + PositionTransformation pt = this.getParentGUI().getTransformator(); if (pt instanceof Transformation3D) { - ((Transformation3D) pt).defaultViewXY(this.getParent().getGraphPanel().getWidth(), - this.getParent().getGraphPanel().getHeight()); - this.getParent().setZoomFactor(pt.getZoomFactor()); + ((Transformation3D) pt).defaultViewXY(this.getParentGUI().getGraphPanel().getWidth(), + this.getParentGUI().getGraphPanel().getHeight()); + this.getParentGUI().setZoomFactor(pt.getZoomFactor()); } } @@ -263,11 +262,11 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou * happens when called on a 2D graph. */ public void defaultViewXZ() { - PositionTransformation pt = this.getParent().getTransformator(); + PositionTransformation pt = this.getParentGUI().getTransformator(); if (pt instanceof Transformation3D) { - ((Transformation3D) pt).defaultViewXZ(this.getParent().getGraphPanel().getWidth(), - this.getParent().getGraphPanel().getHeight()); - this.getParent().setZoomFactor(pt.getZoomFactor()); + ((Transformation3D) pt).defaultViewXZ(this.getParentGUI().getGraphPanel().getWidth(), + this.getParentGUI().getGraphPanel().getHeight()); + this.getParentGUI().setZoomFactor(pt.getZoomFactor()); } } @@ -276,11 +275,11 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou * happens when called on a 2D graph. */ public void defaultViewYZ() { - PositionTransformation pt = this.getParent().getTransformator(); + PositionTransformation pt = this.getParentGUI().getTransformator(); if (pt instanceof Transformation3D) { - ((Transformation3D) pt).defaultViewYZ(this.getParent().getGraphPanel().getWidth(), - this.getParent().getGraphPanel().getHeight()); - this.getParent().setZoomFactor(pt.getZoomFactor()); + ((Transformation3D) pt).defaultViewYZ(this.getParentGUI().getGraphPanel().getWidth(), + this.getParentGUI().getGraphPanel().getHeight()); + this.getParentGUI().setZoomFactor(pt.getZoomFactor()); } } @@ -404,8 +403,8 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou + "' is not a positive integer.\nThe number of rounds has to be a positive integer."); return; } - this.getParent().setStartButtonEnabled(false); - this.getParent().getRuntime().run(rounds, true); + this.getParentGUI().setStartButtonEnabled(false); + this.getParentGUI().getRuntime().run(rounds, true); } catch (java.lang.NumberFormatException nFE) { Main.minorError("Invalid input: '" + getRoundsToPerform().getText() + "' is not a valid integer."); } @@ -415,7 +414,7 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou * Stops a running simulation. */ public void stopSimulation() { - this.getParent().getRuntime().abort(); + this.getParentGUI().getRuntime().abort(); } @Override @@ -433,33 +432,33 @@ public abstract class ControlPanel extends JPanel implements ActionListener, Mou Point guiP = this.getLocationOnScreen(); rp.show(this, p.x - guiP.x - 29, p.y - guiP.y + 29); } else if (e.getActionCommand().equals("zoomIn")) { - this.getParent().zoomIn(); + this.getParentGUI().zoomIn(); } else if (e.getActionCommand().equals("zoomOut")) { - this.getParent().zoomOut(); + this.getParentGUI().zoomOut(); } else if (e.getActionCommand().equals("zoomToFit")) { - this.getParent().getTransformator().zoomToFit(this.getParent().getGraphPanel().getWidth(), this.getParent().getGraphPanel().getHeight()); - this.getParent().setZoomFactor(this.getParent().getTransformator().getZoomFactor()); + this.getParentGUI().getTransformator().zoomToFit(this.getParentGUI().getGraphPanel().getWidth(), this.getParentGUI().getGraphPanel().getHeight()); + this.getParentGUI().setZoomFactor(this.getParentGUI().getTransformator().getZoomFactor()); } else if (e.getActionCommand().equals("zoomToFit3D")) { - this.getParent().getTransformator().defaultView(this.getParent().getGraphPanel().getWidth(), - this.getParent().getGraphPanel().getHeight()); - this.getParent().setZoomFactor(this.getParent().getTransformator().getZoomFactor()); + this.getParentGUI().getTransformator().defaultView(this.getParentGUI().getGraphPanel().getWidth(), + this.getParentGUI().getGraphPanel().getHeight()); + this.getParentGUI().setZoomFactor(this.getParentGUI().getTransformator().getZoomFactor()); } else if (e.getActionCommand().equals("extendPanel")) { - this.getParent().changePanel(true); + this.getParentGUI().changePanel(true); } else if (e.getActionCommand().equals("minimizedPanel")) { - this.getParent().changePanel(false); + this.getParentGUI().changePanel(false); } else if (e.getActionCommand().equals("clearGraph")) { - this.getParent().clearAllNodes(); + this.getParentGUI().clearAllNodes(); } else if (e.getActionCommand().equals("addNodes")) { - this.getParent().addNodes(); + this.getParentGUI().addNodes(); } else if (e.getActionCommand().equals("connectNodes")) { SinalgoRuntime.reevaluateConnections(); // could ask... - this.getParent().redrawGUI(); + this.getParentGUI().redrawGUI(); } else { // test whether its a custom button for (Tuple<JButton, Method> t : this.getCustomButtons()) { if (t.getFirst() == e.getSource()) { try { - synchronized (this.getParent().getTransformator()) { + synchronized (this.getParentGUI().getTransformator()) { // synchronize it on the transformator to grant not to be concurrent with // any drawing or modifying action t.getSecond().invoke(Global.getCustomGlobal()); diff --git a/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java b/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java index 0b7e6f332e7d1d5b73f3ec329a4a9b4373fe25ab..7e0c39b4bcbec97cebf5755700bedb33e6a3d2db 100644 --- a/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/MaximizedControlPanel.java @@ -93,7 +93,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis @Override public Dimension getPreferredScrollableViewportSize() { - return new Dimension(MaximizedControlPanel.this.getControlPanelWidth(), MaximizedControlPanel.this.getParent().getHeight() - 60); // hand-crafted :( + return new Dimension(MaximizedControlPanel.this.getControlPanelWidth(), MaximizedControlPanel.this.getParentGUI().getHeight() - 60); // hand-crafted :( } @Override @@ -472,7 +472,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis // .... add zoom view if (AppConfig.getAppConfig().isGuiControlPanelShowFullViewPanel()) { - if (this.getParent().getTransformator().supportReverseTranslation()) { + if (this.getParentGUI().getTransformator().supportReverseTranslation()) { // only show the coordinate if it can be mapped from GUI to logic coordinates JPanel mousePos = new JPanel(); JLabel mousePosLabel = new JLabel("Mouse Position:"); @@ -486,7 +486,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis viewPanel.add(mousePos); } - this.setZoomPanel(new ZoomPanel(this.getParent(), this.getParent().getTransformator())); + this.setZoomPanel(new ZoomPanel(this.getParentGUI(), this.getParentGUI().getTransformator())); this.getZoomPanel().setPreferredSize( new Dimension(this.getControlPanelWidth(), this.getZoomPanel().getPreferredHeight(this.getControlPanelWidth()))); viewPanel.add(this.getZoomPanel()); @@ -509,7 +509,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis buttonPanel.add(button); this.addToDisabledButtonList(button); - if (this.getParent().getTransformator() instanceof Transformation3D) { + if (this.getParentGUI().getTransformator() instanceof Transformation3D) { button = this.createFrameworkIconButton("zoomToFit3D", "zoomtofit3d.gif", "Default View"); buttonPanel.add(button); this.addToDisabledButtonList(button); @@ -578,7 +578,7 @@ public class MaximizedControlPanel extends ControlPanel implements EventQueueLis * @param p The Gui instance to create the MaximizedControlPanel for. */ public MaximizedControlPanel(GUI p) { - this.setParent(p); + this.setParentGUI(p); this.setBorder(BorderFactory.createRaisedBevelBorder()); this.setLayout(new BorderLayout()); diff --git a/src/main/java/sinalgo/gui/controlPanel/MinimizedControlPanel.java b/src/main/java/sinalgo/gui/controlPanel/MinimizedControlPanel.java index f3cb298d92e3d1d433ac3e54f08e12414fe7fd78..cbd186dc31b2d0d4900f983dadea52c7183d0d10 100644 --- a/src/main/java/sinalgo/gui/controlPanel/MinimizedControlPanel.java +++ b/src/main/java/sinalgo/gui/controlPanel/MinimizedControlPanel.java @@ -68,7 +68,7 @@ public class MinimizedControlPanel extends ControlPanel { * @param p The Gui instance to create the MinimizedControlPanel for. */ public MinimizedControlPanel(GUI p) { - this.setParent(p); + this.setParentGUI(p); int controlPanelHeight = 25; this.setMaximumSize(new Dimension(20000, controlPanelHeight)); this.setMinimumSize(new Dimension(20000, controlPanelHeight)); @@ -105,7 +105,7 @@ public class MinimizedControlPanel extends ControlPanel { this.getButtonPanel().add(button); this.addToDisabledButtonList(button); - if (this.getParent().getTransformator() instanceof Transformation3D) { + if (this.getParentGUI().getTransformator() instanceof Transformation3D) { button = this.createFrameworkIconButton("zoomToFit3D", "zoomtofit3d.gif", "Default View"); this.getButtonPanel().add(button); this.addToDisabledButtonList(button); diff --git a/src/main/java/sinalgo/gui/dialogs/AboutDialog.java b/src/main/java/sinalgo/gui/dialogs/AboutDialog.java index 511b54bb67c94e31e5c4b953bf60502824750e66..1b298ec22aa8566b1e350bc972dbc906c952ac6c 100644 --- a/src/main/java/sinalgo/gui/dialogs/AboutDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/AboutDialog.java @@ -57,7 +57,7 @@ public class AboutDialog extends JDialog implements ActionListener { /** * The constructor for the GlobalSettingsDialog class. * - * @param parent The parent Frame to attach the dialog to. + * @param parent The parentGUI Frame to attach the dialog to. */ public AboutDialog(JFrame parent) { super(parent, "About Sinalgo", true); diff --git a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java index 1657ede284c3fa9f6f3a89b7a4559ffc4bb0e104..875d75da1f322d3cef1cec8d702f293bae9418a5 100644 --- a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java @@ -47,12 +47,7 @@ import sinalgo.gui.GUI; import sinalgo.gui.GuiHelper; import sinalgo.gui.helper.NonRegularGridLayout; import sinalgo.gui.helper.UnborderedJTextField; -import sinalgo.models.ConnectivityModel; -import sinalgo.models.DistributionModel; -import sinalgo.models.InterferenceModel; -import sinalgo.models.MobilityModel; -import sinalgo.models.Model; -import sinalgo.models.ReliabilityModel; +import sinalgo.models.*; import sinalgo.nodes.Node; import sinalgo.nodes.Position; import sinalgo.runtime.Global; @@ -67,12 +62,7 @@ import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.util.Vector; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_CONNECTIVITY; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_DISTRIBUTION; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_INTERFERENCE; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_MOBILITY; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.MODELS_RELIABILITY; -import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.NODES_IMPLEMENTATIONS; +import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType.*; /** * The Dialog to generate a number of new Nodes. @@ -130,15 +120,14 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog private PercentualProgressDialog pf = null; private boolean canceled = false; - @Getter - private GUI parent; + private GUI parentGUI; private Position singleNodePosition; // null if the dialgo was created for several nodes /** * The constructor for the GenerateNodesDialog class. * - * @param p The parent Frame to add the Dialog to. + * @param p The parentGUI Frame to add the Dialog to. */ public GenerateNodesDialog(GUI p) { super(p, "Create new Nodes", true); @@ -164,7 +153,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog }); this.setLocationRelativeTo(p); - this.setParent(p); + this.setParentGUI(p); } /** @@ -301,7 +290,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog // this.setResizable(false); this.getRootPane().setDefaultButton(this.getOk()); this.pack(); - this.setLocationRelativeTo(this.getParent()); + this.setLocationRelativeTo(this.getParentGUI()); getNumber().grabFocus(); this.setVisible(true); } diff --git a/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java b/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java index 4f439dec5a1d3a88113f62c56651359235ab32d7..1978338ef275ca40cc21185ad2ff733fab5ff943 100644 --- a/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java @@ -69,7 +69,7 @@ public class GlobalSettingsDialog extends JDialog implements ActionListener { /** * The constructor for the GlobalSettingsDialog class. * - * @param parent The parent Frame to attach the dialog to. + * @param parent The parentGUI Frame to attach the dialog to. */ public GlobalSettingsDialog(JFrame parent) { super(parent, "Global Settings", true); diff --git a/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java b/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java index 9fda38b7045117e15b9f5c0392b4abd4d8ce18f1..3e7d1b0985de254111e9605ed8d8840fd337bc65 100644 --- a/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GraphInfoDialog.java @@ -62,7 +62,7 @@ public class GraphInfoDialog extends JDialog implements ActionListener { /** * The constructor for the GraphInfoDialog class. * - * @param parent The parent frame to attach the Dialog to. + * @param parent The parentGUI frame to attach the Dialog to. */ public GraphInfoDialog(JFrame parent) { super(parent, "Info about the current network", true); diff --git a/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java b/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java index 4fd333c25f82042206e3bcd508f15de3720918ba..1ae2f54934cdf103c9cf9394c6279a2e470ae1db 100644 --- a/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java @@ -78,18 +78,17 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { private JButton ok = new JButton("Ok"); - @Getter - private GUI parent; + private GUI parentGUI; /** * Generates a dialog that shows information about the current graph. * - * @param parent The Gui instance that created the dialog. + * @param parentGUI The Gui instance that created the dialog. */ - public GraphPreferencesDialog(GUI parent) { - super(parent, "Preferences", true); + public GraphPreferencesDialog(GUI parentGUI) { + super(parentGUI, "Preferences", true); GuiHelper.setWindowIcon(this); - this.setParent(parent); + this.setParentGUI(parentGUI); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); @@ -184,7 +183,7 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { this.getRootPane().setDefaultButton(this.getOk()); this.pack(); - this.setLocationRelativeTo(parent); + this.setLocationRelativeTo(parentGUI); this.setVisible(true); } @@ -232,23 +231,23 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { if (this.getDrawRulerCB().isSelected() != Configuration.isDrawRulers()) { Configuration.setDrawRulers(this.getDrawRulerCB().isSelected()); - this.getParent().getGraphPanel().forceDrawInNextPaint(); + this.getParentGUI().getGraphPanel().forceDrawInNextPaint(); } if (this.getDrawArrowsCB().isSelected() != Configuration.isDrawArrows()) { Configuration.setDrawArrows(this.getDrawArrowsCB().isSelected()); - this.getParent().getGraphPanel().forceDrawInNextPaint(); + this.getParentGUI().getGraphPanel().forceDrawInNextPaint(); } if (this.getDrawEdgesCB().isSelected() != Configuration.isDrawEdges()) { Configuration.setDrawEdges(this.getDrawEdgesCB().isSelected()); - this.getParent().getGraphPanel().forceDrawInNextPaint(); + this.getParentGUI().getGraphPanel().forceDrawInNextPaint(); } if (this.getDrawNodesCB().isSelected() != Configuration.isDrawNodes()) { Configuration.setDrawNodes(this.getDrawNodesCB().isSelected()); - this.getParent().getGraphPanel().forceDrawInNextPaint(); + this.getParentGUI().getGraphPanel().forceDrawInNextPaint(); } if (this.getUsePerspectiveCB().isSelected() != Configuration.isUsePerspectiveView()) { Configuration.setUsePerspectiveView(!Configuration.isUsePerspectiveView()); - this.getParent().getGraphPanel().forceDrawInNextPaint(); + this.getParentGUI().getGraphPanel().forceDrawInNextPaint(); } } catch (WrongConfigurationException ex) { diff --git a/src/main/java/sinalgo/gui/dialogs/HelpDialog.java b/src/main/java/sinalgo/gui/dialogs/HelpDialog.java index b3348eb39bc2eceb2abbf8812950f0f7ffbb70c7..4b149afaaa9d6b69f98c5f02f755b8ebdf06e9cf 100644 --- a/src/main/java/sinalgo/gui/dialogs/HelpDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/HelpDialog.java @@ -49,11 +49,7 @@ import javax.swing.event.HyperlinkListener; import javax.swing.text.html.HTMLDocument; import javax.swing.text.html.HTMLFrameHyperlinkEvent; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; +import java.awt.event.*; import java.io.IOException; import java.net.URL; @@ -168,8 +164,7 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener private static final long serialVersionUID = -950395591867596455L; - @Getter - private JFrame parent; + private JFrame parentFrame; private JButton closeButton = new JButton("Close"); private JButton resetButton = new JButton("Reset"); @@ -178,7 +173,7 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener MenuDialog(JFrame owner, Point pos) { super(owner); - this.setParent(owner); + this.setParentFrame(owner); this.setLayout(new BorderLayout()); this.setEPane(new JEditorPane()); @@ -230,12 +225,12 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener public void actionPerformed(ActionEvent e) { if (e.getSource().equals(this.getCloseButton())) { this.setVisible(false); - this.getParent().setEnabled(true); + this.getParentFrame().setEnabled(true); HelpDialog.this.setMenuDlg(null); } if (e.getSource().equals(this.getResetButton())) { this.setVisible(false); - this.getParent().setEnabled(true); + this.getParentFrame().setEnabled(true); HelpDialog.this.setMenuDlg(null); try { HelpDialog.this.setCurrentURL(HelpDialog.this.getDefaultURL()); @@ -249,20 +244,19 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener } private void saveWindowState() { - AppConfig ac = AppConfig.getAppConfig(); - ac.setHelpWindowHeight(this.getHeight()); - ac.setHelpWindowWidth(this.getWidth()); - ac.setHelpWindowPosX(this.getLocation().x); - ac.setHelpWindowPosY(this.getLocation().y); - ac.setHelpWindowIsMaximized((this.getExtendedState() == Frame.MAXIMIZED_BOTH)); - ac.writeConfig(); + AppConfig.getAppConfig().setHelpWindowHeight(this.getHeight()); + AppConfig.getAppConfig().setHelpWindowWidth(this.getWidth()); + AppConfig.getAppConfig().setHelpWindowPosX(this.getLocation().x); + AppConfig.getAppConfig().setHelpWindowPosY(this.getLocation().y); + AppConfig.getAppConfig().setHelpWindowIsMaximized((this.getExtendedState() == Frame.MAXIMIZED_BOTH)); + AppConfig.getAppConfig().writeConfig(); } private void restoreWindowState() { - AppConfig ac = AppConfig.getAppConfig(); - this.setPreferredSize(new Dimension(ac.getHelpWindowWidth(), ac.getHelpWindowHeight())); - this.setLocation(new Point(ac.getHelpWindowPosX(), ac.getHelpWindowPosY())); - if (ac.isHelpWindowIsMaximized()) { + + this.setPreferredSize(new Dimension(AppConfig.getAppConfig().getHelpWindowWidth(), AppConfig.getAppConfig().getHelpWindowHeight())); + this.setLocation(new Point(AppConfig.getAppConfig().getHelpWindowPosX(), AppConfig.getAppConfig().getHelpWindowPosY())); + if (AppConfig.getAppConfig().isHelpWindowIsMaximized()) { this.setExtendedState(Frame.MAXIMIZED_BOTH); } } diff --git a/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java b/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java index a11be0749058083ac68aad55589f96e53a6a5884..36bb2dba84f16279656379cd71938f0504cea622 100644 --- a/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java @@ -52,12 +52,7 @@ import sinalgo.runtime.SinalgoRuntime; import javax.swing.*; import java.awt.*; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; +import java.awt.event.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.util.Enumeration; @@ -71,8 +66,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC private static final long serialVersionUID = 5403782066445725367L; - @Getter - private GUI parent; + private GUI parentGUI; private Node node; private JFormattedTextField nodeNumber = new JFormattedTextField(); @@ -95,13 +89,13 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC /** * The constructor for the NodeInfoDialog class. * - * @param p The parent gui where this dialog is attached to. + * @param p The parentGUI gui where this dialog is attached to. * @param n The node the information is about. */ public NodeInfoDialog(GUI p, Node n) { super(p, "Edit Node " + n.getID(), true); GuiHelper.setWindowIcon(this); - this.setParent(p); + this.setParentGUI(p); this.setNode(n); this.getNode().highlight(true); @@ -227,7 +221,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC @Override public void windowClosing(WindowEvent event) { NodeInfoDialog.this.getNode().highlight(false); - NodeInfoDialog.this.getParent().redrawGUI(); + NodeInfoDialog.this.getParentGUI().redrawGUI(); } }; this.addWindowListener(listener); @@ -241,13 +235,13 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC if (!e.isConsumed() && e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE) { this.getNode().highlight(false); NodeInfoDialog.this.setVisible(false); - this.getParent().redrawGUINow(); // needs blocking redrawing + this.getParentGUI().redrawGUINow(); // needs blocking redrawing } return false; }); // Redraw the graph to have the selected node painted in the right color. - this.getParent().redrawGUI(); + this.getParentGUI().redrawGUI(); this.pack(); this.setLocationRelativeTo(p); this.setVisible(true); @@ -279,7 +273,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC this.getReliabilityText().setText(Global.toShortName(this.getNode().getReliabilityModel().getClass().getName())); this.getInfoText().setText(this.getNode().toString()); - this.getParent().redrawGUI(); + this.getParentGUI().redrawGUI(); } @Override @@ -288,7 +282,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC case "Cancel": this.getNode().highlight(false); this.setVisible(false); - this.getParent().redrawGUINow(); // needs blocking redrawing + this.getParentGUI().redrawGUINow(); // needs blocking redrawing break; case "OK": try { @@ -299,7 +293,7 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC } this.getNode().highlight(false); this.setVisible(false); - this.getParent().redrawGUINow(); // needs blocking redrawing + this.getParentGUI().redrawGUINow(); // needs blocking redrawing break; case "Next Node": { Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); diff --git a/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java b/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java index 58728c6dba368b46466e4b040736646252fbb4e9..8fec84c6b27d1616093036730e9c4a5162400eb2 100644 --- a/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java @@ -87,11 +87,11 @@ public class PercentualProgressDialog extends JDialog { // } /** - * Constructs a progress bar that is attached to a parent and is modal (blocks - * the parent until the progressbar is closed). + * Constructs a progress bar that is attached to a parentGUI and is modal (blocks + * the parentGUI until the progressbar is closed). * * @param pbu The ProgressBarUser using this progress bar. - * @param parent The parent JDialog to attach the ProgressBar to. + * @param parent The parentGUI JDialog to attach the ProgressBar to. * @param title The title of the Dialog. */ public PercentualProgressDialog(ProgressBarUser pbu, JDialog parent, String title) { @@ -100,17 +100,17 @@ public class PercentualProgressDialog extends JDialog { } // /** - // * Constructs a progress bar that is attached to a parent and is modal (blocks - // * the parent until the progressbar is closed). + // * Constructs a progress bar that is attached to a parentGUI and is modal (blocks + // * the parentGUI until the progressbar is closed). // * // * @param pbu The ProgressBarUser using this progress bar. - // * @param parent The parent JDialog to attach the ProgressBar to. + // * @param parentGUI The parentGUI JDialog to attach the ProgressBar to. // * @param title The title of the Dialog. // * @param cancelEnabled whether the cancelButton is enabled or not // */ - // public PercentualProgressDialog(ProgressBarUser pbu, JDialog parent, String + // public PercentualProgressDialog(ProgressBarUser pbu, JDialog parentGUI, String // title, boolean cancelEnabled){ - // super(parent, title, true); + // super(parentGUI, title, true); // blocking = true; // cancel.setEnabled(cancelEnabled); // create(pbu); @@ -152,8 +152,7 @@ public class PercentualProgressDialog extends JDialog { * This method initializes the ProgressBar and starts the update Thread. */ public void init() { - UpdateThread updateThread = new UpdateThread(); - updateThread.start(); + new UpdateThread().start(); this.setVisible(true); // blocking if this dialog was started with the modal bit set to true. } diff --git a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJList.java b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJList.java index 27476a32ceb3aa0c1321aef8f6558de5c7235b63..932f6043b0a02824c33b3da2e0da76cb4ef6aa63 100644 --- a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJList.java +++ b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJList.java @@ -36,11 +36,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.multiLineTooltip; +import lombok.NoArgsConstructor; + import javax.swing.*; /** * A JList having a Tooltip which can have more than one line. */ +@NoArgsConstructor public class MultiLineToolTipJList extends JList { private static final long serialVersionUID = -1778917939929406346L; diff --git a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJTextArea.java b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJTextArea.java index 0b5c2bca7b9fc691935f6f02c8c96ace8ccd7b1c..582196769ef84b9770cc2963ff878e45588414c6 100644 --- a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJTextArea.java +++ b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTipJTextArea.java @@ -1,5 +1,7 @@ package sinalgo.gui.multiLineTooltip; +import lombok.NoArgsConstructor; + import javax.swing.*; import javax.swing.text.Document; import java.awt.*; @@ -8,6 +10,7 @@ import java.awt.*; * A JTextArea that implements a multi line tool tip. Furthermore, it returns as * its preferred with always the value 0. */ +@NoArgsConstructor public class MultiLineToolTipJTextArea extends JTextArea { private static final long serialVersionUID = -8502823518346846466L; @@ -19,9 +22,6 @@ public class MultiLineToolTipJTextArea extends JTextArea { return d; } - public MultiLineToolTipJTextArea() { - } - public MultiLineToolTipJTextArea(String text) { super(text); } diff --git a/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java b/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java index 0b6e02b467bc426dfe39dbbdcb77d8fddf47a415..8621aa16cc14e8ac81dfae2462e5654920497afd 100644 --- a/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java @@ -55,7 +55,7 @@ public abstract class AbstractPopupMenu extends JPopupMenu { private static final long serialVersionUID = 6108642977345194041L; @Getter - private GUI parent = null; + private GUI parentGUI = null; private JMenuItem zoomIn = new JMenuItem("Zoom In"); private JMenuItem zoomOut = new JMenuItem("Zoom Out"); @@ -71,9 +71,9 @@ public abstract class AbstractPopupMenu extends JPopupMenu { @Override public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals(AbstractPopupMenu.this.getZoomIn().getActionCommand())) { - AbstractPopupMenu.this.getParent().zoomIn(); + AbstractPopupMenu.this.getParentGUI().zoomIn(); } else if (event.getActionCommand().equals(AbstractPopupMenu.this.getZoomOut().getActionCommand())) { - AbstractPopupMenu.this.getParent().zoomOut(); + AbstractPopupMenu.this.getParentGUI().zoomOut(); } } } diff --git a/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java b/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java index 7af9c607facc2bacb4c4aa71db9df7c9d46bddd7..4e8acf5b393933b179acee855bd58765981e117d 100644 --- a/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java @@ -64,10 +64,10 @@ public class EdgePopupMenu extends AbstractPopupMenu implements ActionListener { /** * The constructor for the EdgePopupMenu class. * - * @param p The parent GUI used to trigger the zooming. + * @param p The parentGUI GUI used to trigger the zooming. */ public EdgePopupMenu(GUI p) { - this.setParent(p); + this.setParentGUI(p); this.getInfo().addActionListener(this); this.getDelete().addActionListener(this); } @@ -93,10 +93,10 @@ public class EdgePopupMenu extends AbstractPopupMenu implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(this.getInfo().getActionCommand())) { - new EdgeInfoDialog(this.getParent(), this.getEdge()); + new EdgeInfoDialog(this.getParentGUI(), this.getEdge()); } else if (e.getActionCommand().equals(this.getDelete().getActionCommand())) { SinalgoRuntime.removeEdge(this.getEdge()); - this.getParent().redrawGUINow(); + this.getParentGUI().redrawGUINow(); } } } diff --git a/src/main/java/sinalgo/gui/popups/NodePopupMenu.java b/src/main/java/sinalgo/gui/popups/NodePopupMenu.java index bc4c51758cc4f01c2326d08d6e6bf8f05087bbcc..37116e2467973c88946f9aebd533de9e94bc8f05 100644 --- a/src/main/java/sinalgo/gui/popups/NodePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/NodePopupMenu.java @@ -75,10 +75,10 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { /** * The constructor for the NodePopupMenu class. * - * @param p The parent gui, where the popupMenu appears in. + * @param p The parentGUI gui, where the popupMenu appears in. */ public NodePopupMenu(GUI p) { - this.setParent(p); + this.setParentGUI(p); this.getInfo().addActionListener(this); this.getDelete().addActionListener(this); this.getShowCoordinateCube().addActionListener(this); @@ -100,7 +100,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { this.add(this.getInfo()); if (Configuration.getDimensions() == 3) { - if (this.getParent().getGraphPanel().containsNodeToDrawCoordinateCube(n)) { + if (this.getParentGUI().getGraphPanel().containsNodeToDrawCoordinateCube(n)) { this.add(this.getHideCoordinateCube()); } else { this.add(this.getShowCoordinateCube()); @@ -145,16 +145,16 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { @Override public void actionPerformed(ActionEvent event) { if (event.getActionCommand().equals(this.getInfo().getActionCommand())) { - new NodeInfoDialog(this.getParent(), this.getNode()); + new NodeInfoDialog(this.getParentGUI(), this.getNode()); } else if (event.getActionCommand().equals(this.getDelete().getActionCommand())) { SinalgoRuntime.removeNode(this.getNode()); - this.getParent().redrawGUI(); + this.getParentGUI().redrawGUI(); } else if (event.getActionCommand().equals(this.getShowCoordinateCube().getActionCommand())) { - this.getParent().getGraphPanel().setNodeToDrawCoordinateCube(this.getNode()); - this.getParent().repaint(); // need not repaint the graph, only the toppings + this.getParentGUI().getGraphPanel().setNodeToDrawCoordinateCube(this.getNode()); + this.getParentGUI().repaint(); // need not repaint the graph, only the toppings } else if (event.getActionCommand().equals(this.getHideCoordinateCube().getActionCommand())) { - this.getParent().getGraphPanel().removeNodeToDrawCoordinateCube(this.getNode()); - this.getParent().repaint(); // need not repaint the graph, only the toppings + this.getParentGUI().getGraphPanel().removeNodeToDrawCoordinateCube(this.getNode()); + this.getParentGUI().repaint(); // need not repaint the graph, only the toppings } else { // try to execute a custom-command Method clickedMethod = this.getMethodsAndDescriptions().get(event.getActionCommand()); @@ -162,7 +162,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { throw new SinalgoFatalException("Cannot find method associated with menu item " + event.getActionCommand()); } try { - synchronized (this.getParent().getTransformator()) { + synchronized (this.getParentGUI().getTransformator()) { // synchronize it on the transformator to grant not to be concurrent with // any drawing or modifying action clickedMethod.invoke(this.getNode()); @@ -182,7 +182,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { + e.getMessage()); } - this.getParent().redrawGUI(); + this.getParentGUI().redrawGUI(); } } } diff --git a/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java b/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java index 9ce120228c08d50296cb736cc193c4d7a82cf6bc..9be4a30663c647d127672ed8f9a3fa3ce9a40c3b 100644 --- a/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java @@ -68,7 +68,7 @@ public class SpacePopupMenu extends AbstractPopupMenu implements ActionListener * @param p The Frame to add the AddNodeDialog to if the user clicked AddNode. */ public SpacePopupMenu(GUI p) { - this.setParent(p); + this.setParentGUI(p); this.getAdd().addActionListener(this); } @@ -82,7 +82,7 @@ public class SpacePopupMenu extends AbstractPopupMenu implements ActionListener this.removeAll(); - if (this.getParent().getTransformator().supportReverseTranslation()) { + if (this.getParentGUI().getTransformator().supportReverseTranslation()) { this.add(this.getAdd()); this.addSeparator(); } @@ -94,10 +94,10 @@ public class SpacePopupMenu extends AbstractPopupMenu implements ActionListener @Override public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals(this.getAdd().getActionCommand())) { - PositionTransformation pt = this.getParent().getTransformator(); + PositionTransformation pt = this.getParentGUI().getTransformator(); if (pt.supportReverseTranslation()) { pt.translateToLogicPosition(this.getPos().x, this.getPos().y); - this.getParent().addSingleNode(new Position(pt.getLogicX(), pt.getLogicY(), pt.getLogicZ())); + this.getParentGUI().addSingleNode(new Position(pt.getLogicX(), pt.getLogicY(), pt.getLogicZ())); } } } diff --git a/src/main/java/sinalgo/io/eps/Exporter.java b/src/main/java/sinalgo/io/eps/Exporter.java index 340e92bd76cb2d125b4cdbfd3f944d53a7c97b05..4f1bc006475803144e774c8a5866f7b73c0726fc 100644 --- a/src/main/java/sinalgo/io/eps/Exporter.java +++ b/src/main/java/sinalgo/io/eps/Exporter.java @@ -49,11 +49,7 @@ import sinalgo.runtime.SinalgoRuntime; import javax.swing.*; import javax.swing.filechooser.FileFilter; import java.awt.*; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStreamReader; +import java.io.*; import java.util.Enumeration; import java.util.Random; @@ -66,10 +62,10 @@ public class Exporter { private JFrame parent = null; /** - * Creates a new Exporter instance with a given JFrame as parent. The parent + * Creates a new Exporter instance with a given JFrame as parentGUI. The parentGUI * frame is used to attach the save-dialog to. * - * @param p The parent frame to attach the save-dialog to. + * @param p The parentGUI frame to attach the save-dialog to. */ public Exporter(JFrame p) { this.parent = p; @@ -77,7 +73,7 @@ public class Exporter { /** * The default constructor for the Exporter class. It generates an instance of - * the exporter class that isn't attached to a parent frame. This is absolutely + * the exporter class that isn't attached to a parentGUI frame. This is absolutely * the same as calling the constructor Exporter(null). */ public Exporter() { diff --git a/src/main/java/sinalgo/models/DistributionModel.java b/src/main/java/sinalgo/models/DistributionModel.java index a9e74ac2cec87c55e6f7874d5a1a9d13918d3b76..209edb7e550142ef8ca31f7fd5b4e05b5ddec594 100644 --- a/src/main/java/sinalgo/models/DistributionModel.java +++ b/src/main/java/sinalgo/models/DistributionModel.java @@ -36,6 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.models; +import lombok.Getter; +import lombok.Setter; import sinalgo.nodes.Position; /** @@ -52,8 +54,15 @@ import sinalgo.nodes.Position; public abstract class DistributionModel extends Model { /** - * The number of nodes, that have to be generated by this model. + * Sets The number of nodes this distribution model will have to generate. + * <p> + * This information must be given before the first call to + * <code>getOnePosition()</code>. + * + * @param num The number of nodes */ + @Getter + @Setter protected int numberOfNodes = -1; /** @@ -65,18 +74,6 @@ public abstract class DistributionModel extends Model { // empty body - overwrite in the subclass, if needed. } - /** - * Sets the number of nodes this distribution model will have to generate. - * <p> - * This information must be given before the first call to - * <code>getOnePosition()</code>. - * - * @param num The number of nodes - */ - public void setNumberOfNodes(int num) { - this.numberOfNodes = num; - } - /** * Returns the next position where a node is placed. * <p> diff --git a/src/main/java/sinalgo/models/InterferenceModel.java b/src/main/java/sinalgo/models/InterferenceModel.java index 069bb3e79a1978c4d94b081cda402adee88c4d42..e3308fbfa6c13f6542e6cc1fdceca9f6f4f1fc2c 100644 --- a/src/main/java/sinalgo/models/InterferenceModel.java +++ b/src/main/java/sinalgo/models/InterferenceModel.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.models; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.nodes.messages.Packet; import sinalgo.runtime.Main; @@ -49,6 +52,8 @@ import sinalgo.runtime.Main; */ public abstract class InterferenceModel extends Model { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static boolean firstTime = true; /** @@ -76,10 +81,10 @@ public abstract class InterferenceModel extends Model { * The default constructor tests that interference is enabled. */ protected InterferenceModel() { - if (firstTime && !Configuration.isInterference()) { + if (isFirstTime() && !Configuration.isInterference()) { Main.warning( "Some nodes are using an interference model even though interference is explicitly turned off in the XML Configuration file."); - firstTime = false; // important to only have one message. + setFirstTime(false); // important to only have one message. } } @@ -91,10 +96,10 @@ public abstract class InterferenceModel extends Model { * performed if false. */ protected InterferenceModel(boolean check) { - if (check && firstTime && !Configuration.isInterference()) { + if (check && isFirstTime() && !Configuration.isInterference()) { Main.warning( "Some nodes are using an interference model even though interference is explicitly turned off in the XML Configuration file."); - firstTime = false; + setFirstTime(false); } } } diff --git a/src/main/java/sinalgo/runtime/GUIRuntime.java b/src/main/java/sinalgo/runtime/GUIRuntime.java index ff2dea58a901eaf2cc2a48036fd483ff967e2da6..82e676efd0339a992b225c1b0a286e071ab6c2be 100644 --- a/src/main/java/sinalgo/runtime/GUIRuntime.java +++ b/src/main/java/sinalgo/runtime/GUIRuntime.java @@ -36,6 +36,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.runtime; +import lombok.Getter; +import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoWrappedException; import sinalgo.gui.GUI; @@ -48,16 +50,13 @@ import sinalgo.gui.dialogs.ProgressBarUser; */ public class GUIRuntime extends SinalgoRuntime implements ProgressBarUser { - private GUI gui = new GUI(this); - /** - * This method returns the gui instance. + * The gui instance. * * @return The one and only instance of the gui. */ - public GUI getGUI() { - return this.gui; - } + @Getter + private final GUI GUI = new GUI(this); private PercentualProgressDialog pf = new PercentualProgressDialog(this, "Initialising the Nodes"); @@ -89,10 +88,10 @@ public class GUIRuntime extends SinalgoRuntime implements ProgressBarUser { } // init the gui - this.gui.init(); + this.getGUI().init(); if (this.getNumberOfRounds() != 0) { - this.gui.setStartButtonEnabled(false); + this.getGUI().setStartButtonEnabled(false); } // wait until the the GUI has been painted at least once @@ -117,7 +116,7 @@ public class GUIRuntime extends SinalgoRuntime implements ProgressBarUser { if (rounds <= 0) { return;// nothing to do } - if (considerInfiniteRunFlag && !appConfig.isGuiRunOperationIsLimited()) { + if (considerInfiniteRunFlag && !AppConfig.getAppConfig().isGuiRunOperationIsLimited()) { rounds = Long.MAX_VALUE; } if (Configuration.isAsynchronousMode()) { diff --git a/src/main/java/sinalgo/runtime/SinalgoRuntime.java b/src/main/java/sinalgo/runtime/SinalgoRuntime.java index 4b897a5b9d96eeeccd1bd64e3fe9f21abdc51dcd..0e9836edad16bfe25aa3786ae8b687f1e13e4988 100644 --- a/src/main/java/sinalgo/runtime/SinalgoRuntime.java +++ b/src/main/java/sinalgo/runtime/SinalgoRuntime.java @@ -39,7 +39,6 @@ package sinalgo.runtime; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.exception.NotInGUIModeException; import sinalgo.exception.SinalgoFatalException; @@ -99,7 +98,6 @@ public abstract class SinalgoRuntime { */ public static Map map = null; - static AppConfig appConfig = AppConfig.getAppConfig(); // some information on the rounds