diff --git a/src/main/java/sinalgo/gui/GraphPanel.java b/src/main/java/sinalgo/gui/GraphPanel.java index 4f3b3ee41617e76d04c9ee1a4afff9d3b4ff26d9..42f990b4ef37cdcaf7069e64da4202f1b338c582 100644 --- a/src/main/java/sinalgo/gui/GraphPanel.java +++ b/src/main/java/sinalgo/gui/GraphPanel.java @@ -36,6 +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.Configuration; import sinalgo.exception.SinalgoFatalException; import sinalgo.exception.WrongConfigurationException; @@ -61,7 +64,13 @@ import sinalgo.tools.logging.Logging; import javax.swing.*; import javax.swing.event.MouseInputListener; import java.awt.*; -import java.awt.event.*; +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.util.ConcurrentModificationException; import java.util.Enumeration; import java.util.Stack; @@ -70,12 +79,17 @@ import java.util.Vector; /** * A panel where the Graph is painted into. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class GraphPanel extends JPanel { private static final long serialVersionUID = -7446360484673626267L; private Image offscreen = null; // needs to be set to true whenever offscreen has been assigned a new object + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private boolean newOffscreen = true; private boolean forcedDraw = false; @@ -83,6 +97,8 @@ public class GraphPanel extends JPanel { private NodePopupMenu nodePopupMenu; private EdgePopupMenu edgePopupMenu; private SpacePopupMenu spacePopupMenu; + + @Getter private final GUI parent; private Node nodeToDrag; @@ -114,13 +130,17 @@ public class GraphPanel extends JPanel { /** * A boolean indicating whether the graph was already painted once or not. */ - public static boolean firstTimePainted = false; + @Getter + @Setter + private static boolean firstTimePainted = false; private final PositionTransformation pt; private long myLastPtVersionNumber = -1; // Support to let the user select a node - private int cancelAreaWidth, cancelAreaHeight, cancelAreaOffsetX; // dimension of the cancel area printed directly + private int cancelAreaWidth; + private int cancelAreaHeight; + private int cancelAreaOffsetX; // dimension of the cancel area printed directly // onto the graphics private Node userSelectsNodeCurrentFocus = null; // the node over which the mouse currently hovers, if the user is // to select a node @@ -189,7 +209,7 @@ public class GraphPanel extends JPanel { */ public void requireFullDrawOnNextPaint() { this.log.logln(LogL.GUI_SEQ, "GraphPanel.requireFullDrawOnNextPaint()s"); - this.forcedDraw = true; + this.setForcedDraw(true); } /** @@ -213,17 +233,17 @@ public class GraphPanel extends JPanel { * Creates a new _offscreen image object according to the current dimensions of * this panel. */ - private void getNewOffscreen() { - this.log.logln(LogL.GUI_SEQ, "GraphPanel.getNewOffscreen: Allocating a new offscreen image."); - this.imageSizeX = this.getWidth(); - this.imageSizeY = this.getHeight(); - this.offscreen = null; - if (this.imageSizeX > 0 && this.imageSizeY > 0) { + private void createNewOffscreen() { + this.getLog().logln(LogL.GUI_SEQ, "GraphPanel.createNewOffscreen: Allocating a new offscreen image."); + this.setImageSizeX(this.getWidth()); + this.setImageSizeY(this.getHeight()); + this.setOffscreen(null); + if (this.getImageSizeX() > 0 && this.getImageSizeY() > 0) { // update the transformation object - this.pt.setWidth(this.imageSizeX); - this.pt.setHeight(this.imageSizeY); - this.offscreen = this.createImage(this.imageSizeX, this.imageSizeY); - this.newOffscreen = true; + this.getPt().setWidth(this.getImageSizeX()); + this.getPt().setHeight(this.getImageSizeY()); + this.setOffscreen(this.createImage(this.getImageSizeX(), this.getImageSizeY())); + this.setNewOffscreen(true); } } @@ -231,37 +251,38 @@ public class GraphPanel extends JPanel { public void paint(Graphics g) { if (Global.isRunning()) { // if possible, draw the previous image, but without updating it! - if (this.offscreen != null) { - g.drawImage(this.offscreen, 0, 0, this); + if (this.getOffscreen() != null) { + g.drawImage(this.getOffscreen(), 0, 0, this); // drawOnTop(this.getGraphics()); - this.log.logln(LogL.GUI_SEQ, "GraphPanel.paint(): Simulation is running -> draw offscreen."); + this.getLog().logln(LogL.GUI_SEQ, "GraphPanel.paint(): Simulation is running -> draw offscreen."); } return; } - if (this.imageSizeX != this.getWidth() || this.imageSizeY != this.getHeight()) { - this.log.logln(LogL.GUI_SEQ, "GraphPanel.paint(): We missed a resize event."); - this.getNewOffscreen(); + if (this.getImageSizeX() != this.getWidth() || this.getImageSizeY() != this.getHeight()) { + this.getLog().logln(LogL.GUI_SEQ, "GraphPanel.paint(): We missed a resize event."); + this.createNewOffscreen(); } - GraphPanel.firstTimePainted = true; - if (this.offscreen == null) { - this.getNewOffscreen(); + GraphPanel.setFirstTimePainted(true); + if (this.getOffscreen() == null) { + this.createNewOffscreen(); } - if (this.offscreen != null) { + if (this.getOffscreen() != null) { // we may not need to redraw the graph, but can reuse the old offscreen image - if (this.myLastPtVersionNumber != this.pt.getVersionNumber() || this.newOffscreen || this.forcedDraw) { - this.log.logln(LogL.GUI_SEQ, + if (this.getMyLastPtVersionNumber() != this.getPt().getVersionNumber() + || this.isNewOffscreen() || this.isForcedDraw()) { + this.getLog().logln(LogL.GUI_SEQ, "GraphPanel.paint(): drawing graph to offscreen" - + (this.myLastPtVersionNumber != this.pt.getNumberOfDimensions() ? " ptVersionNumber changed" - : " new Offscreen")); - this.draw(this.offscreen.getGraphics()); - this.myLastPtVersionNumber = this.pt.getVersionNumber(); - this.forcedDraw = false; - this.newOffscreen = false; + + (this.getMyLastPtVersionNumber() != this.getPt().getNumberOfDimensions() ? + " ptVersionNumber changed" : " new Offscreen")); + this.draw(this.getOffscreen().getGraphics()); + this.setMyLastPtVersionNumber(this.getPt().getVersionNumber()); + this.setForcedDraw(false); + this.setNewOffscreen(false); } else { this.log.logln(LogL.GUI_SEQ, "GraphPanel.paint(): no changes -> draw old offscreen"); } - g.drawImage(this.offscreen, 0, 0, this); + g.drawImage(this.getOffscreen(), 0, 0, this); this.drawOnTop(g); } else { // the offscreen object is not available - draw on the provided graphics @@ -276,12 +297,12 @@ public class GraphPanel extends JPanel { * the graph, this method is used internaly. */ public void paintNow() { - this.log.log(LogL.GUI_SEQ, "GraphPanel.paintNow()"); - if (this.offscreen != null) { - this.draw(this.offscreen.getGraphics()); - this.myLastPtVersionNumber = this.pt.getVersionNumber(); - this.newOffscreen = false; - this.getGraphics().drawImage(this.offscreen, 0, 0, this); + this.getLog().log(LogL.GUI_SEQ, "GraphPanel.paintNow()"); + if (this.getOffscreen() != null) { + this.draw(this.getOffscreen().getGraphics()); + this.setMyLastPtVersionNumber(this.getPt().getVersionNumber()); + this.setNewOffscreen(false); + this.getGraphics().drawImage(this.getOffscreen(), 0, 0, this); this.drawOnTop(this.getGraphics()); } else { this.repaint(); // defer paint to default call @@ -294,18 +315,18 @@ public class GraphPanel extends JPanel { * @param g The graphics to paint to */ private void draw(Graphics g) { - synchronized (this.pt) { - this.log.logln(LogL.GUI_SEQ, "GraphPanel.draw(): draw imgSize=(" + this.imageSizeX + "," + this.imageSizeY + ")"); - if (this.defaultViewOnNextDraw) { + synchronized (this.getPt()) { + this.getLog().logln(LogL.GUI_SEQ, "GraphPanel.draw(): draw imgSize=(" + this.getImageSizeX() + "," + this.getImageSizeY() + ")"); + if (this.isDefaultViewOnNextDraw()) { this.defaultViewWithoutRedraw(); - this.defaultViewOnNextDraw = false; + this.setDefaultViewOnNextDraw(false); } - g.clearRect(0, 0, this.imageSizeX, this.imageSizeY); + g.clearRect(0, 0, this.getImageSizeX(), this.getImageSizeY()); this.pt.drawBackground(g); if (Configuration.isUseMap()) { - SinalgoRuntime.map.paintMap(g, this.pt); + SinalgoRuntime.map.paintMap(g, this.getPt()); } g.setColor(Color.BLACK); @@ -320,7 +341,7 @@ public class GraphPanel extends JPanel { Node node = nodeEnumer.nextElement(); // first draw all outgoing edges of this node for (Edge e : node.getOutgoingConnections()) { - e.draw(g, this.pt); + e.draw(g, this.getPt()); } } } @@ -330,7 +351,7 @@ public class GraphPanel extends JPanel { nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(true); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); - node.draw(g, this.pt, false); + node.draw(g, this.getPt(), false); } } } catch (ConcurrentModificationException eME) { @@ -347,7 +368,7 @@ public class GraphPanel extends JPanel { } if (Configuration.isShowMessageAnimations()) { - Animations.drawEnvelopes(g, this.pt); + Animations.drawEnvelopes(g, this.getPt()); } // perform the custom drawing. Note that the custom paint is only called when @@ -355,7 +376,7 @@ public class GraphPanel extends JPanel { // entire graph was painted. This ensures that there should be no conflict due // to any // concurrent data accesses - Global.getCustomGlobal().customPaint(g, this.pt); + Global.getCustomGlobal().customPaint(g, this.getPt()); } } @@ -369,27 +390,28 @@ public class GraphPanel extends JPanel { */ public void drawOnTop(Graphics g) { // draw the line to add a new edge - if (this.nodeToAddEdge != null) { - this.pt.translateToGUIPosition(this.nodeToAddEdge.getPosition()); - if (this.pt.getGuiX() != this.currentCursorPosition.x || this.pt.getGuiY() != this.currentCursorPosition.y) { - Arrow.drawArrow(this.pt.getGuiX(), this.pt.getGuiY(), this.currentCursorPosition.x, this.currentCursorPosition.y, g, this.pt, Color.RED); + if (this.getNodeToAddEdge() != null) { + this.getPt().translateToGUIPosition(this.getNodeToAddEdge().getPosition()); + if (this.getPt().getGuiX() != this.getCurrentCursorPosition().x || this.getPt().getGuiY() != this.getCurrentCursorPosition().y) { + Arrow.drawArrow(this.getPt().getGuiX(), this.getPt().getGuiY(), + this.getCurrentCursorPosition().x, this.getCurrentCursorPosition().y, g, this.getPt(), Color.RED); } } // draw the rectangle for zooming if (this.zoomRect != null) { - if ((Math.abs(this.zoomRect.height) > this.zoomRectMinSize) && (Math.abs(this.zoomRect.width) > this.zoomRectMinSize)) { + if ((Math.abs(this.getZoomRect().height) > this.getZoomRectMinSize()) && (Math.abs(this.getZoomRect().width) > this.getZoomRectMinSize())) { Color temp = g.getColor(); g.setColor(Color.RED); - int topx = this.zoomRect.x; - int topy = this.zoomRect.y; - if (this.zoomRect.width < 0) { - topx += this.zoomRect.width; + int topx = this.getZoomRect().x; + int topy = this.getZoomRect().y; + if (this.getZoomRect().width < 0) { + topx += this.getZoomRect().width; } - if (this.zoomRect.height < 0) { - topy += this.zoomRect.height; + if (this.getZoomRect().height < 0) { + topy += this.getZoomRect().height; } - g.drawRect(topx, topy, Math.abs(this.zoomRect.width), Math.abs(this.zoomRect.height)); + g.drawRect(topx, topy, Math.abs(this.getZoomRect().width), Math.abs(this.getZoomRect().height)); // VERY strange: If we also draw some non-vertical/non-horizontal lines when // drawing // the rectangle (which consists of only vertical and horizontal lines), the @@ -398,40 +420,40 @@ public class GraphPanel extends JPanel { // the // line outside the clipping area seems not to help.) // OK - seems not to be a problem on all PCs... - g.drawLine(this.zoomRect.x, this.zoomRect.y, this.zoomRect.x + 1, this.zoomRect.y + 1); + g.drawLine(this.getZoomRect().x, this.getZoomRect().y, this.getZoomRect().x + 1, this.getZoomRect().y + 1); g.setColor(temp); } } // Draw the highlighted node - for (Node highLighted : this.nodesToHighlight) { - highLighted.draw(g, this.pt, true); + for (Node highLighted : this.getNodesToHighlight()) { + highLighted.draw(g, this.getPt(), true); } - if (this.toolTipDrawCoordCube != null) { - this.drawNodeCubeCoords(g, this.toolTipDrawCoordCube); + if (this.getToolTipDrawCoordCube() != null) { + this.drawNodeCubeCoords(g, this.getToolTipDrawCoordCube()); } - if (this.nodeToDragDrawCoordCube != null) { - this.drawNodeCubeCoords(g, this.nodeToDragDrawCoordCube); + if (this.getNodeToDragDrawCoordCube() != null) { + this.drawNodeCubeCoords(g, this.getNodeToDragDrawCoordCube()); } - for (Node cubeNode : this.nodesToDrawCoordCube) { + for (Node cubeNode : this.getNodesToDrawCoordCube()) { this.drawNodeCubeCoords(g, cubeNode); } - if (this.nodeToAddEdge != null) { - this.nodeToAddEdge.draw(g, this.pt, true); + if (this.getNodeToAddEdge() != null) { + this.getNodeToAddEdge().draw(g, this.getPt(), true); } - if (this.targetNodeToAddEdge != null) { - this.targetNodeToAddEdge.draw(g, this.pt, true); + if (this.getTargetNodeToAddEdge() != null) { + this.getTargetNodeToAddEdge().draw(g, this.getPt(), true); } - if (this.nodeToDrag != null) { - this.nodeToDrag.draw(g, this.pt, true); + if (this.getNodeToDrag() != null) { + this.getNodeToDrag().draw(g, this.getPt(), true); } - if (this.userSelectsNodeMode) { - if (this.userSelectsNodeCurrentFocus != null) { - this.userSelectsNodeCurrentFocus.draw(g, this.pt, true); + if (this.isUserSelectsNodeMode()) { + if (this.getUserSelectsNodeCurrentFocus() != null) { + this.getUserSelectsNodeCurrentFocus().draw(g, this.getPt(), true); } - if (!this.userSelectsNodeHandler.isEmpty()) { - Tuple<NodeSelectionHandler, String> h = this.userSelectsNodeHandler.peek(); + if (!this.getUserSelectsNodeHandler().isEmpty()) { + Tuple<NodeSelectionHandler, String> h = this.getUserSelectsNodeHandler().peek(); String text = h.getSecond(); String textCancel = "Cancel"; Font font = new Font(null, Font.PLAIN, 12); @@ -449,9 +471,9 @@ public class GraphPanel extends JPanel { g.setColor(Color.BLACK); g.drawString(textCancel, len1 + 25, height + 2); // set the - this.cancelAreaWidth = len2 + 25; - this.cancelAreaHeight = height + 9; - this.cancelAreaOffsetX = len1 + 10; + this.setCancelAreaWidth(len2 + 25); + this.setCancelAreaHeight(height + 9); + this.setCancelAreaOffsetX(len1 + 10); } } } @@ -478,7 +500,7 @@ public class GraphPanel extends JPanel { * method is closed. */ public void forceDrawInNextPaint() { - this.forcedDraw = true; + this.setForcedDraw(true); } /** @@ -518,9 +540,9 @@ public class GraphPanel extends JPanel { Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(false); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); - if (node.isInside(event.getX(), event.getY(), this.pt)) { + if (node.isInside(event.getX(), event.getY(), this.getPt())) { if (Configuration.getDimensions() == 3) { - this.toolTipDrawCoordCube = node; + this.setToolTipDrawCoordCube(node); this.repaint(); } return "Node " + node.getID() + ":\n" + node.toString(); @@ -554,8 +576,8 @@ public class GraphPanel extends JPanel { throw new SinalgoFatalException( "Invalid call to 'GUI.getNodeSelectedByUser()'. This method is not supported in batch mode."); } - this.userSelectsNodeHandler.push(new Tuple<>(handler, text)); - this.userSelectsNodeMode = true; + this.getUserSelectsNodeHandler().push(new Tuple<>(handler, text)); + this.setUserSelectsNodeMode(true); this.setDefaultCursor(); this.repaint(); // async call that does not repaint the network graph, but only the stuff on top // of the graph @@ -565,10 +587,10 @@ public class GraphPanel extends JPanel { * Set the default mouse cursor, depending on the current state of the GUI. */ private void setDefaultCursor() { - if (this.userSelectsNodeMode) { - this.parent.getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + if (this.isUserSelectsNodeMode()) { + this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } else { - this.parent.getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } @@ -579,7 +601,7 @@ public class GraphPanel extends JPanel { * @param n The node to add */ public void setNodeToDrawCoordinateCube(Node n) { - this.nodesToDrawCoordCube.add(n); + this.getNodesToDrawCoordCube().add(n); } /** @@ -589,7 +611,7 @@ public class GraphPanel extends JPanel { * @return True if the coordinate cube is drawn for the given node */ public boolean containsNodeToDrawCoordinateCube(Node n) { - return this.nodesToDrawCoordCube.contains(n); + return this.getNodesToDrawCoordCube().contains(n); } /** @@ -598,7 +620,7 @@ public class GraphPanel extends JPanel { * @param n The node to remove. */ public void removeNodeToDrawCoordinateCube(Node n) { - this.nodesToDrawCoordCube.remove(n); + this.getNodesToDrawCoordCube().remove(n); } /** @@ -611,9 +633,9 @@ public class GraphPanel extends JPanel { */ public void setNodeHighlighted(Node n, boolean highlighted) { if (highlighted) { - this.nodesToHighlight.add(n); + this.getNodesToHighlight().add(n); } else // if this is highlighted node, dis-highlight it. - this.nodesToHighlight.remove(n); + this.getNodesToHighlight().remove(n); } /** @@ -629,7 +651,7 @@ public class GraphPanel extends JPanel { Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(false); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); - if (node.isInside(x, y, this.pt)) { + if (node.isInside(x, y, this.getPt())) { return node; } } @@ -651,14 +673,14 @@ public class GraphPanel extends JPanel { */ public Edge getFirstEdgeAtPosition(int x, int y, Node n) { for (Edge e : n.getOutgoingConnections()) { - if (e.isInside(x, y, this.pt)) { + if (e.isInside(x, y, this.getPt())) { Edge opposEdge = e.getOppositeEdge(); if (opposEdge != null) { // find out which one we want to delete. this.pt.translateToGUIPosition(e.getEndNode().getPosition()); - Position oneEnd = new Position(this.pt.getGuiXDouble(), this.pt.getGuiYDouble(), 0.0); + Position oneEnd = new Position(this.getPt().getGuiXDouble(), this.getPt().getGuiYDouble(), 0.0); this.pt.translateToGUIPosition(opposEdge.getEndNode().getPosition()); - Position otherEnd = new Position(this.pt.getGuiXDouble(), this.pt.getGuiYDouble(), 0.0); + Position otherEnd = new Position(this.getPt().getGuiXDouble(), this.getPt().getGuiYDouble(), 0.0); Position eventPos = new Position(x, y, 0.0); if (eventPos.distanceTo(oneEnd) > eventPos.distanceTo(otherEnd)) { @@ -687,12 +709,12 @@ public class GraphPanel extends JPanel { */ public void drawCubeCoordLine(Graphics g, double fromX, double fromY, double fromZ, double toX, double toY, double toZ) { - this.pt.translateToGUIPosition(fromX, fromY, fromZ); - int guiX = this.pt.getGuiX(); - int guiY = this.pt.getGuiY(); - this.pt.translateToGUIPosition(toX, toY, toZ); + this.getPt().translateToGUIPosition(fromX, fromY, fromZ); + int guiX = this.getPt().getGuiX(); + int guiY = this.getPt().getGuiY(); + this.getPt().translateToGUIPosition(toX, toY, toZ); g.setColor(Color.LIGHT_GRAY); - g.drawLine(guiX, guiY, this.pt.getGuiX(), this.pt.getGuiY()); + g.drawLine(guiX, guiY, this.getPt().getGuiX(), this.getPt().getGuiY()); } /** @@ -780,17 +802,19 @@ public class GraphPanel extends JPanel { Global.getLog().logln(LogL.GUI_DETAIL, "Mouse Clicked"); - if (GraphPanel.this.userSelectsNodeMode && event.getClickCount() == 1 && event.getButton() == MouseEvent.BUTTON1) { - if (event.getX() >= GraphPanel.this.cancelAreaOffsetX && event.getX() <= GraphPanel.this.cancelAreaOffsetX + GraphPanel.this.cancelAreaWidth - && event.getY() <= GraphPanel.this.cancelAreaHeight) { - if (!GraphPanel.this.userSelectsNodeHandler.isEmpty()) { - Tuple<NodeSelectionHandler, String> h = GraphPanel.this.userSelectsNodeHandler.pop(); - GraphPanel.this.userSelectsNodeMode = !GraphPanel.this.userSelectsNodeHandler.isEmpty(); + if (GraphPanel.this.isUserSelectsNodeMode() && event.getClickCount() == 1 + && event.getButton() == MouseEvent.BUTTON1) { + if (event.getX() >= GraphPanel.this.getCancelAreaOffsetX() + && event.getX() <= GraphPanel.this.getCancelAreaOffsetX() + GraphPanel.this.getCancelAreaWidth() + && event.getY() <= GraphPanel.this.getCancelAreaHeight()) { + if (!GraphPanel.this.getUserSelectsNodeHandler().isEmpty()) { + Tuple<NodeSelectionHandler, String> h = GraphPanel.this.getUserSelectsNodeHandler().pop(); + GraphPanel.this.setUserSelectsNodeMode(!GraphPanel.this.getUserSelectsNodeHandler().isEmpty()); GraphPanel.this.repaint(); // async call that does not repaint the network graph, but only the stuff on top // of the graph h.getFirst().handleNodeSelectedEvent(null); // abort } else { - GraphPanel.this.userSelectsNodeMode = false; + GraphPanel.this.setUserSelectsNodeMode(false); GraphPanel.this.repaint(); // async call that does not repaint the network graph, but only the stuff on top // of the graph } @@ -802,11 +826,11 @@ public class GraphPanel extends JPanel { // Left mouse has been clicked - create a default node at this position // else cannot create a new node clicki-bunti if the gui coord cannot be // translated to logic coordinates. - if (GraphPanel.this.pt.supportReverseTranslation()) { - GraphPanel.this.pt.translateToLogicPosition(event.getX(), event.getY()); + if (GraphPanel.this.getPt().supportReverseTranslation()) { + GraphPanel.this.getPt().translateToLogicPosition(event.getX(), event.getY()); try { - GraphPanel.this.parent.addSingleDefaultNode(new Position(GraphPanel.this.pt.getLogicX(), GraphPanel.this.pt.getLogicY(), GraphPanel.this.pt.getLogicZ())); - GraphPanel.this.parent.redrawGUI(); + GraphPanel.this.getParent().addSingleDefaultNode(new Position(GraphPanel.this.getPt().getLogicX(), GraphPanel.this.pt.getLogicY(), GraphPanel.this.pt.getLogicZ())); + GraphPanel.this.getParent().redrawGUI(); } catch (WrongConfigurationException e1) { Main.minorError(e1); } @@ -821,7 +845,7 @@ public class GraphPanel extends JPanel { Enumeration<Node> nodeEnumer = SinalgoRuntime.nodes.getSortedNodeEnumeration(false); while (nodeEnumer.hasMoreElements()) { Node node = nodeEnumer.nextElement(); - if (node.isInside(event.getX(), event.getY(), GraphPanel.this.pt)) { + if (node.isInside(event.getX(), event.getY(), GraphPanel.this.getPt())) { // rightClick on a Node clickedNode = node; break; // take the first node that matches @@ -832,29 +856,29 @@ public class GraphPanel extends JPanel { } if (clickedNode != null) { Global.getLog().logln(LogL.GUI_DETAIL, "User clicked on node " + clickedNode.getID()); - GraphPanel.this.nodePopupMenu.compose(clickedNode); - GraphPanel.this.nodePopupMenu.show(event.getComponent(), event.getX(), event.getY()); + GraphPanel.this.getNodePopupMenu().compose(clickedNode); + GraphPanel.this.getNodePopupMenu().show(event.getComponent(), event.getX(), event.getY()); } else if (clickedEdge != null) { Global.getLog().logln(LogL.GUI_DETAIL, "right click on a edge"); - GraphPanel.this.edgePopupMenu.compose(clickedEdge); - GraphPanel.this.edgePopupMenu.show(event.getComponent(), event.getX(), event.getY()); + GraphPanel.this.getEdgePopupMenu().compose(clickedEdge); + GraphPanel.this.getEdgePopupMenu().show(event.getComponent(), event.getX(), event.getY()); } else { Global.getLog().logln(LogL.GUI_DETAIL, "User clicked in the free space"); - GraphPanel.this.spacePopupMenu.compose(event.getPoint()); - GraphPanel.this.spacePopupMenu.show(event.getComponent(), event.getX(), event.getY()); + GraphPanel.this.getSpacePopupMenu().compose(event.getPoint()); + GraphPanel.this.getSpacePopupMenu().show(event.getComponent(), event.getX(), event.getY()); } - } else if (event.getButton() == MouseEvent.BUTTON1 && GraphPanel.this.userSelectsNodeMode) { + } else if (event.getButton() == MouseEvent.BUTTON1 && GraphPanel.this.isUserSelectsNodeMode()) { Node selected = GraphPanel.this.getFirstNodeAtPosition(event.getX(), event.getY()); if (selected != null) { - if (!GraphPanel.this.userSelectsNodeHandler.isEmpty()) { - Tuple<NodeSelectionHandler, String> h = GraphPanel.this.userSelectsNodeHandler.pop(); - GraphPanel.this.userSelectsNodeMode = !GraphPanel.this.userSelectsNodeHandler.isEmpty(); + if (!GraphPanel.this.getUserSelectsNodeHandler().isEmpty()) { + Tuple<NodeSelectionHandler, String> h = GraphPanel.this.getUserSelectsNodeHandler().pop(); + GraphPanel.this.setUserSelectsNodeMode(!GraphPanel.this.getUserSelectsNodeHandler().isEmpty()); GraphPanel.this.setDefaultCursor(); GraphPanel.this.repaint(); // async call that does not repaint the network graph, but only the stuff on top // of the graph h.getFirst().handleNodeSelectedEvent(selected); } else { - GraphPanel.this.userSelectsNodeMode = false; + GraphPanel.this.setUserSelectsNodeMode(false); } } } @@ -872,44 +896,44 @@ public class GraphPanel extends JPanel { if (e.getButton() == MouseEvent.BUTTON3) { // The right mouse button is pressed : move a node - if (GraphPanel.this.nodeToDrag == null) { + if (GraphPanel.this.getNodeToDrag() == null) { Node node = GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY()); if (null != node) { - GraphPanel.this.nodeToDragInitialPosition.assign(node.getPosition()); + GraphPanel.this.getNodeToDragInitialPosition().assign(node.getPosition()); GraphPanel.this.requestFocusInWindow(); // request focus s.t. key events are obtained (escape) - if (GraphPanel.this.pt.supportReverseTranslation()) { // only start dragging if it's supported - GraphPanel.this.nodeToDrag = node; - GraphPanel.this.parent.getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); + 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)); } else { - GraphPanel.this.nodeToDrag = node; - GraphPanel.this.nodeToDragDrawCoordCube = node; - GraphPanel.this.minMouseMovementUntilNodeMovement = 10; + GraphPanel.this.setNodeToDrag(node); + GraphPanel.this.setNodeToDragDrawCoordCube(node); + GraphPanel.this.setMinMouseMovementUntilNodeMovement(10); GraphPanel.this.repaint(); // did not change the graph! } } else { // rotate if 3D - if (GraphPanel.this.pt instanceof Transformation3D) { - GraphPanel.this.rotateStartPoint = e.getPoint(); + if (GraphPanel.this.getPt() instanceof Transformation3D) { + GraphPanel.this.setRotateStartPoint(e.getPoint()); } } } } else if (e.getButton() == MouseEvent.BUTTON1) { // the left-button if (e.isControlDown()) { // left button + control = zoom into a region - GraphPanel.this.zoomRect = new Rectangle(e.getX(), e.getY(), 0, 0); + GraphPanel.this.setZoomRect(new Rectangle(e.getX(), e.getY(), 0, 0)); } else { // The left mouse button is pressed - connect two nodes if the mouse // event started over a node - if (GraphPanel.this.nodeToAddEdge == null) { + if (GraphPanel.this.getNodeToAddEdge() == null) { Node node = GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY()); if (null != node) { - GraphPanel.this.nodeToAddEdge = node; + GraphPanel.this.setNodeToAddEdge(node); GraphPanel.this.requestFocusInWindow(); // request focus to obtain key events (escape) } else { // scroll the pane - GraphPanel.this.shiftStartPoint = e.getPoint(); - GraphPanel.this.parent.getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); + GraphPanel.this.setShiftStartPoint(e.getPoint()); + GraphPanel.this.getParent().getComponent(0).setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); } } } @@ -927,31 +951,32 @@ public class GraphPanel extends JPanel { Global.getLog().logln(LogL.GUI_DETAIL, "Mouse Released"); - GraphPanel.this.shiftStartPoint = null; - GraphPanel.this.rotateStartPoint = null; + GraphPanel.this.setShiftStartPoint(null); + GraphPanel.this.setRotateStartPoint(null); if (e.getButton() == MouseEvent.BUTTON1) { // the left button - if (GraphPanel.this.nodeToAddEdge != null) { + if (GraphPanel.this.getNodeToAddEdge() != null) { Node targetNode = GraphPanel.this.getFirstNodeAtPosition(e.getX(), e.getY()); // check if there is a targetNode otherwise the endpoint isn't a node (do // nothing then) if (targetNode != null) { // check if the target node is different to the startnode (do not add an edge // from a node to itself - if (targetNode.getID() != GraphPanel.this.nodeToAddEdge.getID()) { + if (targetNode.getID() != GraphPanel.this.getNodeToAddEdge().getID()) { try { // the user added a edge from nodeToAddEdge to targetNode - GraphPanel.this.nodeToAddEdge.getOutgoingConnections().add(GraphPanel.this.nodeToAddEdge, targetNode, false); + GraphPanel.this.getNodeToAddEdge().getOutgoingConnections() + .add(GraphPanel.this.getNodeToAddEdge(), targetNode, false); } catch (WrongConfigurationException wCE) { - JOptionPane.showMessageDialog(GraphPanel.this.parent, wCE.getMessage(), "Configuration Error", - JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(GraphPanel.this.getParent(), wCE.getMessage(), + "Configuration Error", JOptionPane.ERROR_MESSAGE); } } } - GraphPanel.this.targetNodeToAddEdge = null; - GraphPanel.this.nodeToAddEdge = null; + GraphPanel.this.setTargetNodeToAddEdge(null); + GraphPanel.this.setNodeToAddEdge(null); if (targetNode != null) { - GraphPanel.this.parent.redrawGUI(); // we added an edge, need to repaint the graph + GraphPanel.this.getParent().redrawGUI(); // we added an edge, need to repaint the graph } else { GraphPanel.this.repaint(); } @@ -960,27 +985,28 @@ public class GraphPanel extends JPanel { GraphPanel.this.setDefaultCursor(); } // Handle the button-release for the case that we were zooming into a rectangle - if (GraphPanel.this.zoomRect != null) { - if ((Math.abs(GraphPanel.this.zoomRect.height) > GraphPanel.this.zoomRectMinSize) && (Math.abs(GraphPanel.this.zoomRect.width) > GraphPanel.this.zoomRectMinSize)) { - if (GraphPanel.this.zoomRect.width < 0) { - GraphPanel.this.zoomRect.x += GraphPanel.this.zoomRect.width; - GraphPanel.this.zoomRect.width = -GraphPanel.this.zoomRect.width; + if (GraphPanel.this.getZoomRect() != null) { + if ((Math.abs(GraphPanel.this.getZoomRect().height) > GraphPanel.this.getZoomRectMinSize()) + && (Math.abs(GraphPanel.this.getZoomRect().width) > GraphPanel.this.getZoomRectMinSize())) { + if (GraphPanel.this.getZoomRect().width < 0) { + GraphPanel.this.getZoomRect().x += GraphPanel.this.getZoomRect().width; + GraphPanel.this.getZoomRect().width = -GraphPanel.this.getZoomRect().width; } - if (GraphPanel.this.zoomRect.height < 0) { - GraphPanel.this.zoomRect.y += GraphPanel.this.zoomRect.height; - GraphPanel.this.zoomRect.height = -GraphPanel.this.zoomRect.height; + if (GraphPanel.this.getZoomRect().height < 0) { + GraphPanel.this.getZoomRect().y += GraphPanel.this.getZoomRect().height; + GraphPanel.this.getZoomRect().height = -GraphPanel.this.getZoomRect().height; } - GraphPanel.this.pt.zoomToRect(GraphPanel.this.zoomRect); - GraphPanel.this.parent.setZoomFactor(GraphPanel.this.pt.getZoomFactor()); + GraphPanel.this.getPt().zoomToRect(GraphPanel.this.getZoomRect()); + GraphPanel.this.getParent().setZoomFactor(GraphPanel.this.getPt().getZoomFactor()); } - GraphPanel.this.zoomRect = null; - GraphPanel.this.parent.redrawGUI(); + GraphPanel.this.setZoomRect(null); + GraphPanel.this.getParent().redrawGUI(); } } else if (e.getButton() == MouseEvent.BUTTON3) { // the right button - GraphPanel.this.nodeToDragDrawCoordCube = null; + GraphPanel.this.setNodeToDragDrawCoordCube(null); GraphPanel.this.setDefaultCursor(); - GraphPanel.this.nodeToDrag = null; - GraphPanel.this.parent.redrawGUI(); + GraphPanel.this.setNodeToDrag(null); + GraphPanel.this.getParent().redrawGUI(); } Global.getLog().logln(LogL.GUI_ULTRA_DETAIL, "Mouse Released finished"); } @@ -1000,7 +1026,7 @@ public class GraphPanel extends JPanel { dx = move; requireMove = true; } - if (p.x > GraphPanel.this.imageSizeX - border) { + if (p.x > GraphPanel.this.getImageSizeX() - border) { dx = -move; requireMove = true; } @@ -1008,12 +1034,12 @@ public class GraphPanel extends JPanel { dy = 10; requireMove = true; } - if (p.y > GraphPanel.this.imageSizeY - border) { + if (p.y > GraphPanel.this.getImageSizeY() - border) { dy = -move; requireMove = true; } if (requireMove) { - GraphPanel.this.pt.moveView(dx, dy); + GraphPanel.this.getPt().moveView(dx, dy); } } @@ -1024,39 +1050,42 @@ public class GraphPanel extends JPanel { return; } - 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.getParent().setMousePosition(GraphPanel.this.getPt().getLogicPositionString()); } } Global.getLog().logln(LogL.GUI_DETAIL, "Mouse Dragged"); - if (GraphPanel.this.nodeToDrag != null) { - if (GraphPanel.this.pt.supportReverseTranslation()) { + if (GraphPanel.this.getNodeToDrag() != null) { + if (GraphPanel.this.getPt().supportReverseTranslation()) { // cannot support node movement by the mouse if the gui coordinate cannot be // translated to the logic counterpart - GraphPanel.this.pt.translateToLogicPosition(e.getX(), e.getY()); - GraphPanel.this.nodeToDrag.setPosition(GraphPanel.this.pt.getLogicX(), GraphPanel.this.pt.getLogicY(), GraphPanel.this.pt.getLogicZ()); + GraphPanel.this.getPt().translateToLogicPosition(e.getX(), e.getY()); + GraphPanel.this.getNodeToDrag() + .setPosition(GraphPanel.this.getPt().getLogicX(), GraphPanel.this.getPt().getLogicY(), GraphPanel.this.getPt().getLogicZ()); this.moveViewOnMousesDrag(e.getPoint()); - GraphPanel.this.parent.redrawGUI(); // we need to repaint the graph panel + GraphPanel.this.getParent().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.pt.translateToGUIPosition(GraphPanel.this.nodeToDrag.getPosition()); + GraphPanel.this.getPt().translateToGUIPosition(GraphPanel.this.getNodeToDrag().getPosition()); // mouse diff vector - int mouseDx = e.getX() - GraphPanel.this.pt.getGuiX(); - int mouseDy = e.getY() - GraphPanel.this.pt.getGuiY(); + int mouseDx = e.getX() - GraphPanel.this.getPt().getGuiX(); + int mouseDy = e.getY() - GraphPanel.this.getPt().getGuiY(); double mouseLength = Math.sqrt(mouseDx * mouseDx + mouseDy * mouseDy); - if (mouseLength <= GraphPanel.this.minMouseMovementUntilNodeMovement) { + if (mouseLength <= GraphPanel.this.getMinMouseMovementUntilNodeMovement()) { return; } - GraphPanel.this.minMouseMovementUntilNodeMovement = 1; // after starting to move, we use a better resolution + GraphPanel.this.setMinMouseMovementUntilNodeMovement(1); // after starting to move, we use a better resolution - GraphPanel.this.pt.translateToGUIPosition(0, 0, 0); - double originX = GraphPanel.this.pt.getGuiXDouble(), originY = GraphPanel.this.pt.getGuiYDouble(); + GraphPanel.this.getPt().translateToGUIPosition(0, 0, 0); + double originX = GraphPanel.this.getPt().getGuiXDouble(), originY = GraphPanel.this.getPt().getGuiYDouble(); // mouse-movement in direction of x-axis GraphPanel.this.pt.translateToGUIPosition(1, 0, 0); @@ -1157,8 +1186,8 @@ public class GraphPanel extends JPanel { } else { GraphPanel.this.userSelectsNodeCurrentFocus = null; } - if (GraphPanel.this.toolTipDrawCoordCube != null) { - GraphPanel.this.toolTipDrawCoordCube = null; + if (GraphPanel.this.getToolTipDrawCoordCube() != null) { + GraphPanel.this.setToolTipDrawCoordCube(null); GraphPanel.this.repaint(); } } @@ -1226,7 +1255,7 @@ public class GraphPanel extends JPanel { @Override public void componentResized(ComponentEvent e) { - GraphPanel.this.getNewOffscreen(); + GraphPanel.this.createNewOffscreen(); // don't force a redraw, s.t. if the resize happens during a simulation, the // graph is not repainted. (but this may leave an empty graph if a simulation is // running) diff --git a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java index 51812734bbbc1d10a978d3b338cbde3d18903505..1657ede284c3fa9f6f3a89b7a4559ffc4bb0e104 100644 --- a/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GenerateNodesDialog.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.dialogs; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.configuration.Configuration.ImplementationChoiceInConfigFile.ImplementationType; @@ -74,15 +77,19 @@ import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFi /** * The Dialog to generate a number of new Nodes. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class GenerateNodesDialog extends JDialog implements ActionListener, ProgressBarUser { private static final long serialVersionUID = -8080111497886244380L; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static JTextField number = new JTextField(6); // static: keep the value for subsequent calls static { - number.setText(Integer.toString(AppConfig.getAppConfig().getGenerateNodesDlgNumNodes())); + getNumber().setText(Integer.toString(AppConfig.getAppConfig().getGenerateNodesDlgNumNodes())); } private int numberOfNodes; // 'number' field translated to an int, set after a call to readSelection() @@ -123,6 +130,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog private PercentualProgressDialog pf = null; private boolean canceled = false; + @Getter private GUI parent; private Position singleNodePosition; // null if the dialgo was created for several nodes @@ -135,16 +143,16 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog public GenerateNodesDialog(GUI p) { super(p, "Create new Nodes", true); GuiHelper.setWindowIcon(this); - this.cancel.addActionListener(this); - this.ok.addActionListener(this); + this.getCancel().addActionListener(this); + this.getOk().addActionListener(this); - Font f = this.distributionModelComboBox.getFont().deriveFont(Font.PLAIN); - this.distributionModelComboBox.setFont(f); - this.nodeTypeComboBox.setFont(f); - this.connectivityModelComboBox.setFont(f); - this.interferenceModelComboBox.setFont(f); - this.mobilityModelComboBox.setFont(f); - this.reliabilityModelComboBox.setFont(f); + Font f = this.getDistributionModelComboBox().getFont().deriveFont(Font.PLAIN); + this.getDistributionModelComboBox().setFont(f); + this.getNodeTypeComboBox().setFont(f); + this.getConnectivityModelComboBox().setFont(f); + this.getInterferenceModelComboBox().setFont(f); + this.getMobilityModelComboBox().setFont(f); + this.getReliabilityModelComboBox().setFont(f); // Detect ESCAPE button KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); @@ -156,7 +164,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog }); this.setLocationRelativeTo(p); - this.parent = p; + this.setParent(p); } /** @@ -167,7 +175,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog * dialog for several nodes, set this parameter to null. */ public void compose(Position singleNodePos) { - this.singleNodePosition = singleNodePos; + this.setSingleNodePosition(singleNodePos); JPanel cp = new JPanel(); cp.setLayout(new BoxLayout(cp, BoxLayout.Y_AXIS)); @@ -187,7 +195,7 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog // ---------------------------- UnborderedJTextField numSelLabel = new UnborderedJTextField("Number of Nodes:", Font.BOLD); distSel.add(numSelLabel); - distSel.add(number); + distSel.add(getNumber()); JTextField dummy = new JTextField(); dummy.setVisible(false); distSel.add(dummy); @@ -196,10 +204,10 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog // ---------------------------- UnborderedJTextField distSelLabel = new UnborderedJTextField("Distribution Model:", Font.BOLD); distSel.add(distSelLabel); - this.fillChoice(this.distributionModelComboBox, MODELS_DISTRIBUTION, this.distributionSel); - distSel.add(this.distributionModelComboBox); - this.distributionParam.setText(this.distributionParamDefString); - distSel.add(this.distributionParam); + this.fillChoice(this.getDistributionModelComboBox(), MODELS_DISTRIBUTION, this.getDistributionSel()); + distSel.add(this.getDistributionModelComboBox()); + this.getDistributionParam().setText(this.getDistributionParamDefString()); + distSel.add(this.getDistributionParam()); dist.add(distSel); JPanel propertyPanel = new JPanel(); @@ -215,86 +223,86 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog // ---------------------------- UnborderedJTextField propSelLabel = new UnborderedJTextField("Node Implementation:", Font.BOLD); props.add(propSelLabel); - this.fillChoice(this.nodeTypeComboBox, NODES_IMPLEMENTATIONS, this.nodeTypeSel); - props.add(this.nodeTypeComboBox); - this.nodeTypeParam.setEditable(false); - this.nodeTypeParam.setVisible(false); - props.add(this.nodeTypeParam); + this.fillChoice(this.getNodeTypeComboBox(), NODES_IMPLEMENTATIONS, this.getNodeTypeSel()); + props.add(this.getNodeTypeComboBox()); + this.getNodeTypeParam().setEditable(false); + this.getNodeTypeParam().setVisible(false); + props.add(this.getNodeTypeParam()); // the available connectivities // ---------------------------- UnborderedJTextField connSelLabel = new UnborderedJTextField("Connectivity Model:", Font.BOLD); props.add(connSelLabel); - this.fillChoice(this.connectivityModelComboBox, MODELS_CONNECTIVITY, this.connectivitySel); - props.add(this.connectivityModelComboBox); - this.connectivityParam.setText(this.connectivityDefString); - props.add(this.connectivityParam); + this.fillChoice(this.getConnectivityModelComboBox(), MODELS_CONNECTIVITY, this.getConnectivitySel()); + props.add(this.getConnectivityModelComboBox()); + this.getConnectivityParam().setText(this.getConnectivityDefString()); + props.add(this.getConnectivityParam()); // the available interferences // ---------------------------- UnborderedJTextField interSelLabel = new UnborderedJTextField("Interference Model:", Font.BOLD); props.add(interSelLabel); - this.fillChoice(this.interferenceModelComboBox, MODELS_INTERFERENCE, this.interferenceSel); - props.add(this.interferenceModelComboBox); - this.interferenceParam.setText(this.interferenceDefString); - props.add(this.interferenceParam); + this.fillChoice(this.getInterferenceModelComboBox(), MODELS_INTERFERENCE, this.getInterferenceSel()); + props.add(this.getInterferenceModelComboBox()); + this.getInterferenceParam().setText(this.getInterferenceDefString()); + props.add(this.getInterferenceParam()); // the available mobility // ---------------------------- UnborderedJTextField mobSelLabel = new UnborderedJTextField("Mobility Model:", Font.BOLD); props.add(mobSelLabel); - this.fillChoice(this.mobilityModelComboBox, MODELS_MOBILITY, this.mobilitySel); - props.add(this.mobilityModelComboBox); - this.mobilityParam.setText(this.mobilityDefString); - props.add(this.mobilityParam); + this.fillChoice(this.getMobilityModelComboBox(), MODELS_MOBILITY, this.getMobilitySel()); + props.add(this.getMobilityModelComboBox()); + this.getMobilityParam().setText(this.getMobilityDefString()); + props.add(this.getMobilityParam()); // the available reliability models // ---------------------------- UnborderedJTextField reliSelLabel = new UnborderedJTextField("Reliability Model:", Font.BOLD); props.add(reliSelLabel); - this.fillChoice(this.reliabilityModelComboBox, MODELS_RELIABILITY, this.reliabilitySel); - props.add(this.reliabilityModelComboBox); - this.reliabilityParam.setText(this.reliabilityDefString); - props.add(this.reliabilityParam); + this.fillChoice(this.getReliabilityModelComboBox(), MODELS_RELIABILITY, this.getReliabilitySel()); + props.add(this.getReliabilityModelComboBox()); + this.getReliabilityParam().setText(this.getReliabilityDefString()); + props.add(this.getReliabilityParam()); // add a button to change whether all implementations are contained in the drop // down fields JPanel allModelsPanel = new JPanel(); allModelsPanel.setLayout(new BorderLayout()); - this.allModelsCheckBox = new JCheckBox("Show all implementations"); - this.allModelsCheckBox.setSelected(Configuration.isShowModelsOfAllProjects()); - this.allModelsCheckBox.addChangeListener(e -> { - if (Configuration.isShowModelsOfAllProjects() != this.allModelsCheckBox.isSelected()) { - Configuration.setShowModelsOfAllProjects(this.allModelsCheckBox.isSelected()); + this.setAllModelsCheckBox(new JCheckBox("Show all implementations")); + this.getAllModelsCheckBox().setSelected(Configuration.isShowModelsOfAllProjects()); + this.getAllModelsCheckBox().addChangeListener(e -> { + if (Configuration.isShowModelsOfAllProjects() != this.getAllModelsCheckBox().isSelected()) { + Configuration.setShowModelsOfAllProjects(this.getAllModelsCheckBox().isSelected()); // reload the contents of the drop down fields - this.fillChoice(this.distributionModelComboBox, MODELS_DISTRIBUTION, this.distributionSel); - this.fillChoice(this.nodeTypeComboBox, NODES_IMPLEMENTATIONS, this.nodeTypeSel); - this.fillChoice(this.connectivityModelComboBox, MODELS_CONNECTIVITY, this.connectivitySel); - this.fillChoice(this.interferenceModelComboBox, MODELS_INTERFERENCE, this.interferenceSel); - this.fillChoice(this.mobilityModelComboBox, MODELS_MOBILITY, this.mobilitySel); - this.fillChoice(this.reliabilityModelComboBox, MODELS_RELIABILITY, this.reliabilitySel); + this.fillChoice(this.getDistributionModelComboBox(), MODELS_DISTRIBUTION, this.getDistributionSel()); + this.fillChoice(this.getNodeTypeComboBox(), NODES_IMPLEMENTATIONS, this.getNodeTypeSel()); + this.fillChoice(this.getConnectivityModelComboBox(), MODELS_CONNECTIVITY, this.getConnectivitySel()); + this.fillChoice(this.getInterferenceModelComboBox(), MODELS_INTERFERENCE, this.getInterferenceSel()); + this.fillChoice(this.getMobilityModelComboBox(), MODELS_MOBILITY, this.getMobilitySel()); + this.fillChoice(this.getReliabilityModelComboBox(), MODELS_RELIABILITY, this.getReliabilitySel()); GenerateNodesDialog.this.pack(); } }); - allModelsPanel.add(this.allModelsCheckBox); + allModelsPanel.add(this.getAllModelsCheckBox()); cp.add(allModelsPanel); // the buttons OK / CANCEL JPanel buttons = new JPanel(); - this.ok.setMnemonic(KeyEvent.VK_O); - buttons.add(this.ok); - this.cancel.setMnemonic(KeyEvent.VK_C); - buttons.add(this.cancel); + this.getOk().setMnemonic(KeyEvent.VK_O); + buttons.add(this.getOk()); + this.getCancel().setMnemonic(KeyEvent.VK_C); + buttons.add(this.getCancel()); cp.add(buttons); this.setContentPane(cp); // this.setResizable(false); - this.getRootPane().setDefaultButton(this.ok); + this.getRootPane().setDefaultButton(this.getOk()); this.pack(); - this.setLocationRelativeTo(this.parent); - number.grabFocus(); + this.setLocationRelativeTo(this.getParent()); + getNumber().grabFocus(); this.setVisible(true); } @@ -312,77 +320,77 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog @Override public void actionPerformed(ActionEvent event) { - if (event.getActionCommand().equals(this.ok.getActionCommand())) { - if (this.singleNodePosition == null) { + if (event.getActionCommand().equals(this.getOk().getActionCommand())) { + if (this.getSingleNodePosition() == null) { try { - int num = Integer.parseInt(number.getText()); + int num = Integer.parseInt(getNumber().getText()); if (num <= 0) { throw new NumberFormatException(); } AppConfig.getAppConfig().setGenerateNodesDlgNumNodes(num); - this.pf = new PercentualProgressDialog(this, this, "Creating new Nodes..."); - this.canceled = false; - this.pf.init(); + this.setPf(new PercentualProgressDialog(this, this, "Creating new Nodes...")); + this.setCanceled(false); + this.getPf().init(); } catch (NumberFormatException nfE) { Main.minorError( "Please specify a correct number of nodes to generate. This number has to be an integer greater than zero."); } } else { // only for a single node this.readSelection(); - Node n = this.generateNode(this.singleNodePosition); + Node n = this.generateNode(this.getSingleNodePosition()); n.finishInitializationWithDefaultModels(true); // redraw Tools.getGraphPanel().forceDrawInNextPaint(); Tools.getGraphPanel().repaint(); this.setVisible(false); } - } else if (event.getActionCommand().equals(this.cancel.getActionCommand())) { + } else if (event.getActionCommand().equals(this.getCancel().getActionCommand())) { this.setVisible(false); } } @Override public void cancelClicked() { - this.canceled = true; + this.setCanceled(true); } /** * Reads and stores the selction the user made */ private void readSelection() { - this.numberOfNodes = Integer.parseInt(number.getText()); - this.distributionSel = this.distributionModelComboBox.getSelectedItem().toString(); - this.nodeTypeSel = this.nodeTypeComboBox.getSelectedItem().toString(); - this.interferenceSel = this.interferenceModelComboBox.getSelectedItem().toString(); - this.mobilitySel = this.mobilityModelComboBox.getSelectedItem().toString(); - this.reliabilitySel = this.reliabilityModelComboBox.getSelectedItem().toString(); - this.connectivitySel = this.connectivityModelComboBox.getSelectedItem().toString(); - - this.distributionParamDefString = this.distributionParam.getText(); - this.interferenceDefString = this.interferenceParam.getText(); - this.mobilityDefString = this.mobilityParam.getText(); - this.reliabilityDefString = this.reliabilityParam.getText(); - this.connectivityDefString = this.connectivityParam.getText(); + this.setNumberOfNodes(Integer.parseInt(getNumber().getText())); + this.setDistributionSel(this.getDistributionModelComboBox().getSelectedItem().toString()); + this.setNodeTypeSel(this.getNodeTypeComboBox().getSelectedItem().toString()); + this.setInterferenceSel(this.getInterferenceModelComboBox().getSelectedItem().toString()); + this.setMobilitySel(this.getMobilityModelComboBox().getSelectedItem().toString()); + this.setReliabilitySel(this.getReliabilityModelComboBox().getSelectedItem().toString()); + this.setConnectivitySel(this.getConnectivityModelComboBox().getSelectedItem().toString()); + + this.setDistributionParamDefString(this.getDistributionParam().getText()); + this.setInterferenceDefString(this.getInterferenceParam().getText()); + this.setMobilityDefString(this.getMobilityParam().getText()); + this.setReliabilityDefString(this.getReliabilityParam().getText()); + this.setConnectivityDefString(this.getConnectivityParam().getText()); } private Node generateNode(Position pos) { - Node node = Node.createNodeByClassname(this.nodeTypeSel); + Node node = Node.createNodeByClassname(this.getNodeTypeSel()); node.setPosition(pos); - InterferenceModel im = Model.getInterferenceModelInstance(this.interferenceSel); - im.setParamString(this.interferenceDefString); + InterferenceModel im = Model.getInterferenceModelInstance(this.getInterferenceSel()); + im.setParamString(this.getInterferenceDefString()); node.setInterferenceModel(im); - MobilityModel mm = Model.getMobilityModelInstance(this.mobilitySel); - mm.setParamString(this.mobilityDefString); + MobilityModel mm = Model.getMobilityModelInstance(this.getMobilitySel()); + mm.setParamString(this.getMobilityDefString()); node.setMobilityModel(mm); - ReliabilityModel rm = Model.getReliabilityModelInstance(this.reliabilitySel); - rm.setParamString(this.reliabilityDefString); + ReliabilityModel rm = Model.getReliabilityModelInstance(this.getReliabilitySel()); + rm.setParamString(this.getReliabilityDefString()); node.setReliabilityModel(rm); - ConnectivityModel cm = Model.getConnectivityModelInstance(this.connectivitySel); - cm.setParamString(this.connectivityDefString); + ConnectivityModel cm = Model.getConnectivityModelInstance(this.getConnectivitySel()); + cm.setParamString(this.getConnectivityDefString()); node.setConnectivityModel(cm); return node; } @@ -403,25 +411,25 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog public void performMethod() { this.readSelection(); try { - DistributionModel distribution = Model.getDistributionModelInstance(this.distributionSel); - distribution.setParamString(this.distributionParamDefString); - distribution.setNumberOfNodes(this.numberOfNodes); + DistributionModel distribution = Model.getDistributionModelInstance(this.getDistributionSel()); + distribution.setParamString(this.getDistributionParamDefString()); + distribution.setNumberOfNodes(this.getNumberOfNodes()); distribution.initialize(); Vector<Node> addedNodes = new Vector<>(); - for (int i = 0; i < this.numberOfNodes; i++) { - this.pf.setPercentage(100.0d * ((double) i / (double) this.numberOfNodes)); + for (int i = 0; i < this.getNumberOfNodes(); i++) { + this.getPf().setPercentage(100.0d * ((double) i / (double) this.getNumberOfNodes())); Node node = this.generateNode(distribution.getNextPosition()); - if (this.canceled) { + if (this.isCanceled()) { for (Node n : addedNodes) { SinalgoRuntime.nodes.removeNode(n); i--; - this.pf.setPercentage(100.0d * ((double) i / (double) this.numberOfNodes)); + this.getPf().setPercentage(100.0d * ((double) i / (double) this.getNumberOfNodes())); } - this.pf.finish(); + this.getPf().finish(); addedNodes.clear(); return; } @@ -432,10 +440,9 @@ public class GenerateNodesDialog extends JDialog implements ActionListener, Prog } catch (WrongConfigurationException e) { Main.minorError("There was an error while generating the nodes.\n" + e.getMessage()); } - this.pf.finish(); + this.getPf().finish(); Tools.getGraphPanel().forceDrawInNextPaint(); Tools.getGraphPanel().repaint(); this.setVisible(false); } - } diff --git a/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java b/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java index 6b0fd20407f6ec7c9577776823e8717d49a100a2..4f439dec5a1d3a88113f62c56651359235ab32d7 100644 --- a/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GlobalSettingsDialog.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.dialogs; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.configuration.Configuration; import sinalgo.gui.GuiHelper; @@ -52,6 +55,8 @@ import java.io.PrintStream; /** * Dialog that shows the global settings of the current simulation. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class GlobalSettingsDialog extends JDialog implements ActionListener { private static final long serialVersionUID = -9208723898830546097L; @@ -88,18 +93,18 @@ public class GlobalSettingsDialog extends JDialog implements ActionListener { JPanel settingsPanel = new JPanel(); settingsPanel.setLayout(new BorderLayout()); - this.testForUpdatesAtStartup.setSelected(AppConfig.getAppConfig().isCheckForSinalgoUpdate()); - this.testForUpdatesAtStartup.addActionListener(this); - settingsPanel.add(BorderLayout.LINE_START, this.testForUpdatesAtStartup); + this.getTestForUpdatesAtStartup().setSelected(AppConfig.getAppConfig().isCheckForSinalgoUpdate()); + this.getTestForUpdatesAtStartup().addActionListener(this); + settingsPanel.add(BorderLayout.LINE_START, this.getTestForUpdatesAtStartup()); - this.versionTest.addActionListener(this); - settingsPanel.add(BorderLayout.EAST, this.versionTest); + this.getVersionTest().addActionListener(this); + settingsPanel.add(BorderLayout.EAST, this.getVersionTest()); buttonPanel.add(settingsPanel); - this.close.addActionListener(this); + this.getClose().addActionListener(this); JPanel closePanel = new JPanel(); - closePanel.add(this.close); + closePanel.add(this.getClose()); buttonPanel.add(BorderLayout.SOUTH, closePanel); this.add(BorderLayout.SOUTH, buttonPanel); @@ -113,7 +118,7 @@ public class GlobalSettingsDialog extends JDialog implements ActionListener { return false; }); - this.getRootPane().setDefaultButton(this.close); + this.getRootPane().setDefaultButton(this.getClose()); this.pack(); this.setLocationRelativeTo(parent); @@ -122,13 +127,14 @@ public class GlobalSettingsDialog extends JDialog implements ActionListener { @Override public void actionPerformed(ActionEvent event) { - if (event.getSource().equals(this.close)) { + if (event.getSource().equals(this.getClose())) { this.setVisible(false); - } else if (event.getSource().equals(this.versionTest)) { + } else if (event.getSource().equals(this.getVersionTest())) { VersionTester.testVersion(false, true); - } else if (event.getSource().equals(this.testForUpdatesAtStartup)) { - AppConfig.getAppConfig().setCheckForSinalgoUpdate(this.testForUpdatesAtStartup.isSelected()); + } else if (event.getSource().equals(this.getTestForUpdatesAtStartup())) { + AppConfig.getAppConfig().setCheckForSinalgoUpdate(this.getTestForUpdatesAtStartup().isSelected()); AppConfig.getAppConfig().writeConfig(); } } + } diff --git a/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java b/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java index 67f9a74d144c7dd7c3d24ac2fe08c82b6cfa590d..4fd333c25f82042206e3bcd508f15de3720918ba 100644 --- a/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/GraphPreferencesDialog.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.dialogs; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoWrappedException; import sinalgo.exception.WrongConfigurationException; @@ -57,6 +60,8 @@ import static sinalgo.configuration.Configuration.ImplementationChoiceInConfigFi /** * The Class for the dialog for the Graph preferences. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class GraphPreferencesDialog extends JDialog implements ActionListener { private static final long serialVersionUID = 7895237565849731280L; @@ -73,6 +78,7 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { private JButton ok = new JButton("Ok"); + @Getter private GUI parent; /** @@ -83,7 +89,7 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { public GraphPreferencesDialog(GUI parent) { super(parent, "Preferences", true); GuiHelper.setWindowIcon(this); - this.parent = parent; + this.setParent(parent); JPanel cp = new JPanel(); cp.setLayout(new BorderLayout()); @@ -93,22 +99,22 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { visualDetails.setBorder(BorderFactory.createTitledBorder("Visual Details:")); visualDetails.setLayout(new BoxLayout(visualDetails, BoxLayout.Y_AXIS)); - this.drawArrowsCB.setSelected(Configuration.isDrawArrows()); - visualDetails.add(this.drawArrowsCB); + this.getDrawArrowsCB().setSelected(Configuration.isDrawArrows()); + visualDetails.add(this.getDrawArrowsCB()); // Feature not yet implemented // drawRulerCB.setSelected(Configuration.drawRulers); // visualDetails.add(drawRulerCB); - this.drawNodesCB.setSelected(Configuration.isDrawNodes()); - visualDetails.add(this.drawNodesCB); + this.getDrawNodesCB().setSelected(Configuration.isDrawNodes()); + visualDetails.add(this.getDrawNodesCB()); - this.drawEdgesCB.setSelected(Configuration.isDrawEdges()); - visualDetails.add(this.drawEdgesCB); + this.getDrawEdgesCB().setSelected(Configuration.isDrawEdges()); + visualDetails.add(this.getDrawEdgesCB()); - this.usePerspectiveCB.setSelected(Configuration.isUsePerspectiveView()); + this.getUsePerspectiveCB().setSelected(Configuration.isUsePerspectiveView()); if (Configuration.getDimensions() == 3) { // only show in 3D - visualDetails.add(this.usePerspectiveCB); + visualDetails.add(this.getUsePerspectiveCB()); } cp.add(visualDetails, BorderLayout.NORTH); @@ -119,29 +125,29 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { // Edges implemenations - Font f = this.typeOfEdges.getFont().deriveFont(Font.PLAIN); - this.typeOfEdges.setFont(f); + Font f = this.getTypeOfEdges().getFont().deriveFont(Font.PLAIN); + this.getTypeOfEdges().setFont(f); this.fillTypesOfEdges(); simulationDetails.add(new JLabel("Type of Edges: ")); - simulationDetails.add(this.typeOfEdges); + simulationDetails.add(this.getTypeOfEdges()); // Transmission model - this.selectedTransmissionModel.setFont(f); + this.getSelectedTransmissionModel().setFont(f); this.fillTransmissionModel(); simulationDetails.add(new JLabel("Transmission Model: ")); - simulationDetails.add(this.selectedTransmissionModel); + simulationDetails.add(this.getSelectedTransmissionModel()); simulationDetails.add(new JLabel("")); - this.allModelsCheckBox = new JCheckBox("Show all implementations"); - this.allModelsCheckBox.setSelected(Configuration.isShowModelsOfAllProjects()); - this.allModelsCheckBox.addChangeListener(e -> { - if (Configuration.isShowModelsOfAllProjects() != this.allModelsCheckBox.isSelected()) { - Configuration.setShowModelsOfAllProjects(this.allModelsCheckBox.isSelected()); + this.setAllModelsCheckBox(new JCheckBox("Show all implementations")); + this.getAllModelsCheckBox().setSelected(Configuration.isShowModelsOfAllProjects()); + this.getAllModelsCheckBox().addChangeListener(e -> { + if (Configuration.isShowModelsOfAllProjects() != this.getAllModelsCheckBox().isSelected()) { + Configuration.setShowModelsOfAllProjects(this.getAllModelsCheckBox().isSelected()); this.fillTypesOfEdges(); this.fillTransmissionModel(); } }); - simulationDetails.add(this.allModelsCheckBox); + simulationDetails.add(this.getAllModelsCheckBox()); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.setBorder(BorderFactory.createEmptyBorder()); @@ -156,8 +162,8 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { JPanel buttons = new JPanel(); - this.ok.addActionListener(this); - buttons.add(this.ok); + this.getOk().addActionListener(this); + buttons.add(this.getOk()); JButton cancel = new JButton("Cancel"); cancel.addActionListener(this); @@ -176,7 +182,7 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { return false; }); - this.getRootPane().setDefaultButton(this.ok); + this.getRootPane().setDefaultButton(this.getOk()); this.pack(); this.setLocationRelativeTo(parent); this.setVisible(true); @@ -188,12 +194,12 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { if (!names.contains(Configuration.getEdgeTypeShortName())) { names.add(Configuration.getEdgeTypeShortName()); } - this.typeOfEdges.removeAllItems(); + this.getTypeOfEdges().removeAllItems(); for (String s : names) { - this.typeOfEdges.addItem(s); + this.getTypeOfEdges().addItem(s); } - this.typeOfEdges.setSelectedItem(Configuration.getEdgeTypeShortName()); + this.getTypeOfEdges().setSelectedItem(Configuration.getEdgeTypeShortName()); } private void fillTransmissionModel() { @@ -203,46 +209,46 @@ public class GraphPreferencesDialog extends JDialog implements ActionListener { if (!names.contains(Configuration.getDefaultMessageTransmissionModel())) { names.add(Configuration.getDefaultMessageTransmissionModel()); } - this.selectedTransmissionModel.removeAllItems(); + this.getSelectedTransmissionModel().removeAllItems(); for (String s : names) { - this.selectedTransmissionModel.addItem(s); + this.getSelectedTransmissionModel().addItem(s); } - this.selectedTransmissionModel.setSelectedItem(Configuration.getDefaultMessageTransmissionModel()); + this.getSelectedTransmissionModel().setSelectedItem(Configuration.getDefaultMessageTransmissionModel()); } @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals(this.ok.getActionCommand())) { + if (e.getActionCommand().equals(this.getOk().getActionCommand())) { try { - String selectedType = (String) this.typeOfEdges.getSelectedItem(); + String selectedType = (String) this.getTypeOfEdges().getSelectedItem(); Configuration.setEdgeType(selectedType); - String selectedTransModel = (String) this.selectedTransmissionModel.getSelectedItem(); + String selectedTransModel = (String) this.getSelectedTransmissionModel().getSelectedItem(); if (!Configuration.getDefaultMessageTransmissionModel().equals(selectedTransModel)) { Configuration.setDefaultMessageTransmissionModel(selectedTransModel); Global.setMessageTransmissionModel(Model.getMessageTransmissionModelInstance( Configuration.getDefaultMessageTransmissionModel())); } - if (this.drawRulerCB.isSelected() != Configuration.isDrawRulers()) { - Configuration.setDrawRulers(this.drawRulerCB.isSelected()); - this.parent.getGraphPanel().forceDrawInNextPaint(); + if (this.getDrawRulerCB().isSelected() != Configuration.isDrawRulers()) { + Configuration.setDrawRulers(this.getDrawRulerCB().isSelected()); + this.getParent().getGraphPanel().forceDrawInNextPaint(); } - if (this.drawArrowsCB.isSelected() != Configuration.isDrawArrows()) { - Configuration.setDrawArrows(this.drawArrowsCB.isSelected()); - this.parent.getGraphPanel().forceDrawInNextPaint(); + if (this.getDrawArrowsCB().isSelected() != Configuration.isDrawArrows()) { + Configuration.setDrawArrows(this.getDrawArrowsCB().isSelected()); + this.getParent().getGraphPanel().forceDrawInNextPaint(); } - if (this.drawEdgesCB.isSelected() != Configuration.isDrawEdges()) { - Configuration.setDrawEdges(this.drawEdgesCB.isSelected()); - this.parent.getGraphPanel().forceDrawInNextPaint(); + if (this.getDrawEdgesCB().isSelected() != Configuration.isDrawEdges()) { + Configuration.setDrawEdges(this.getDrawEdgesCB().isSelected()); + this.getParent().getGraphPanel().forceDrawInNextPaint(); } - if (this.drawNodesCB.isSelected() != Configuration.isDrawNodes()) { - Configuration.setDrawNodes(this.drawNodesCB.isSelected()); - this.parent.getGraphPanel().forceDrawInNextPaint(); + if (this.getDrawNodesCB().isSelected() != Configuration.isDrawNodes()) { + Configuration.setDrawNodes(this.getDrawNodesCB().isSelected()); + this.getParent().getGraphPanel().forceDrawInNextPaint(); } - if (this.usePerspectiveCB.isSelected() != Configuration.isUsePerspectiveView()) { + if (this.getUsePerspectiveCB().isSelected() != Configuration.isUsePerspectiveView()) { Configuration.setUsePerspectiveView(!Configuration.isUsePerspectiveView()); - this.parent.getGraphPanel().forceDrawInNextPaint(); + this.getParent().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 7f46d0ff683c4044265a26850494616b3ca3c0fe..b3348eb39bc2eceb2abbf8812950f0f7ffbb70c7 100644 --- a/src/main/java/sinalgo/gui/dialogs/HelpDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/HelpDialog.java @@ -37,6 +37,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package sinalgo.gui.dialogs; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.AppConfig; import sinalgo.gui.GuiHelper; @@ -54,6 +57,8 @@ import java.awt.event.WindowListener; import java.io.IOException; import java.net.URL; +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class HelpDialog extends JFrame implements ActionListener, WindowListener { private static final long serialVersionUID = 5648555963120786571L; @@ -77,23 +82,23 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener this.add(topPanel, BorderLayout.NORTH); topPanel.setLayout(new BorderLayout()); topPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - topPanel.add(this.menuButton, BorderLayout.WEST); - this.menuButton.addActionListener(this); + topPanel.add(this.getMenuButton(), BorderLayout.WEST); + this.getMenuButton().addActionListener(this); - this.html = new JEditorPane(); + this.setHtml(new JEditorPane()); JScrollPane scroller = new JScrollPane(); JViewport vp = scroller.getViewport(); - vp.add(this.html); + vp.add(this.getHtml()); this.add(scroller, BorderLayout.CENTER); try { - this.defaultURL = new URL("https://github.com/andrebrait/sinalgo/raw/master/MANUAL.pdf"); - this.currentURL = this.defaultURL; - this.html.setPage(this.currentURL); - this.html.setEditable(false); - this.html.addHyperlinkListener(this.getLinkListener()); + this.setDefaultURL(new URL("https://github.com/andrebrait/sinalgo/raw/master/MANUAL.pdf")); + this.setCurrentURL(this.getDefaultURL()); + this.getHtml().setPage(this.getCurrentURL()); + this.getHtml().setEditable(false); + this.getHtml().addHyperlinkListener(this.getLinkListener()); } catch (IOException e1) { - this.html.setText("Cannot display the page.\n" + e1.getMessage()); + this.getHtml().setText("Cannot display the page.\n" + e1.getMessage()); } // Detect ESCAPE button @@ -113,28 +118,29 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener return e -> { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (e instanceof HTMLFrameHyperlinkEvent) { - ((HTMLDocument) this.html.getDocument()).processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) e); + ((HTMLDocument) this.getHtml().getDocument()) + .processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) e); } else { try { - this.currentURL = e.getURL(); - String s = this.currentURL.toString(); + this.setCurrentURL(e.getURL()); + String s = this.getCurrentURL().toString(); int offset = s.indexOf(".html"); if (offset > 0) { // .html is in the string s = s.substring(0, offset + 5); s += "?help"; - if (this.currentURL.getRef() != null) { - s += "#" + this.currentURL.getRef(); + if (this.getCurrentURL().getRef() != null) { + s += "#" + this.getCurrentURL().getRef(); } - this.currentURL = new URL(s); + this.setCurrentURL(new URL(s)); HelpDialog.this.setEnabled(true); - if (this.menuDlg != null) { - this.menuDlg.setVisible(false); - this.menuDlg = null; + if (this.getMenuDlg() != null) { + this.getMenuDlg().setVisible(false); + this.setMenuDlg(null); } } - this.html.setPage(this.currentURL); + this.getHtml().setPage(this.getCurrentURL()); } catch (IOException e1) { - this.html.setText("Cannot display the page.\n" + e1.getMessage()); + this.getHtml().setText("Cannot display the page.\n" + e1.getMessage()); } } } @@ -144,73 +150,76 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener private MenuDialog menuDlg = null; // The menu dialog if its currently shown, otherwise null private void showMenu() { - Point p = this.menuButton.getLocationOnScreen(); - this.menuDlg = new MenuDialog(this, p); + Point p = this.getMenuButton().getLocationOnScreen(); + this.setMenuDlg(new MenuDialog(this, p)); this.setEnabled(false); } @Override public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(this.menuButton)) { + if (e.getSource().equals(this.getMenuButton())) { this.showMenu(); } } + @Getter(AccessLevel.PACKAGE) + @Setter(AccessLevel.PACKAGE) class MenuDialog extends JWindow implements ActionListener { private static final long serialVersionUID = -950395591867596455L; - JFrame parent; + @Getter + private JFrame parent; - JButton closeButton = new JButton("Close"); - JButton resetButton = new JButton("Reset"); - JEditorPane ePane; - String defaultMenuURL = "https://github.com/andrebrait/sinalgo/"; + private JButton closeButton = new JButton("Close"); + private JButton resetButton = new JButton("Reset"); + private JEditorPane ePane; + private String defaultMenuURL = "https://github.com/andrebrait/sinalgo/"; MenuDialog(JFrame owner, Point pos) { super(owner); - this.parent = owner; + this.setParent(owner); this.setLayout(new BorderLayout()); - this.ePane = new JEditorPane(); + this.setEPane(new JEditorPane()); // ePane.getEditorKit(). - this.ePane.setPreferredSize(new Dimension(250, 400)); - this.ePane.setEditable(false); + this.getEPane().setPreferredSize(new Dimension(250, 400)); + this.getEPane().setEditable(false); JScrollPane scroller = new JScrollPane(); JViewport vp = scroller.getViewport(); - vp.add(this.ePane); + vp.add(this.getEPane()); this.add(scroller, BorderLayout.CENTER); try { // create the URL for the menu (ensure that the url still points to a Sinalgo // page - String s = (HelpDialog.this.currentURL == null ? this.defaultMenuURL : HelpDialog.this.currentURL.toString()); + String s = (HelpDialog.this.getCurrentURL() == null ? this.getDefaultMenuURL() : HelpDialog.this.getCurrentURL().toString()); URL myURL; int offset = s.indexOf(".html"); if (offset > 0) { // .html is in the string if (!s.contains("github.com/andrebrait/sinalgo/")) { // went to a different site - myURL = new URL(this.defaultMenuURL); + myURL = new URL(this.getDefaultMenuURL()); } else { // add the ?menu option s = s.substring(0, offset + 5); s += "?menu"; myURL = new URL(s); } } else { - myURL = new URL(this.defaultMenuURL); + myURL = new URL(this.getDefaultMenuURL()); } - this.ePane.setPage(myURL); // load the page - this.ePane.addHyperlinkListener(HelpDialog.this.getLinkListener()); + this.getEPane().setPage(myURL); // load the page + this.getEPane().addHyperlinkListener(HelpDialog.this.getLinkListener()); } catch (IOException e1) { - this.ePane.setText("Cannot display the page.\n" + e1.getMessage()); + this.getEPane().setText("Cannot display the page.\n" + e1.getMessage()); } JPanel menuPanel = new JPanel(); menuPanel.setLayout(new BoxLayout(menuPanel, BoxLayout.X_AXIS)); this.add(menuPanel, BorderLayout.NORTH); - this.closeButton.addActionListener(this); - menuPanel.add(this.closeButton); - this.resetButton.addActionListener(this); - menuPanel.add(this.resetButton); + this.getCloseButton().addActionListener(this); + menuPanel.add(this.getCloseButton()); + this.getResetButton().addActionListener(this); + menuPanel.add(this.getResetButton()); this.setLocation(pos); this.pack(); @@ -219,20 +228,20 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener @Override public void actionPerformed(ActionEvent e) { - if (e.getSource().equals(this.closeButton)) { + if (e.getSource().equals(this.getCloseButton())) { this.setVisible(false); - this.parent.setEnabled(true); - HelpDialog.this.menuDlg = null; + this.getParent().setEnabled(true); + HelpDialog.this.setMenuDlg(null); } - if (e.getSource().equals(this.resetButton)) { + if (e.getSource().equals(this.getResetButton())) { this.setVisible(false); - this.parent.setEnabled(true); - HelpDialog.this.menuDlg = null; + this.getParent().setEnabled(true); + HelpDialog.this.setMenuDlg(null); try { - HelpDialog.this.currentURL = HelpDialog.this.defaultURL; - HelpDialog.this.html.setPage(HelpDialog.this.currentURL); + HelpDialog.this.setCurrentURL(HelpDialog.this.getDefaultURL()); + HelpDialog.this.getHtml().setPage(HelpDialog.this.getCurrentURL()); } catch (IOException e1) { - HelpDialog.this.html.setText("Cannot display the page.\n" + e1.getMessage()); + HelpDialog.this.getHtml().setText("Cannot display the page.\n" + e1.getMessage()); } } } @@ -294,17 +303,19 @@ public class HelpDialog extends JFrame implements ActionListener, WindowListener r.start(); } + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) static class Runner extends Thread { private JFrame p; Runner(JFrame parent) { - this.p = parent; + this.setP(parent); } @Override public void run() { - new HelpDialog(this.p); + new HelpDialog(this.getP()); } } diff --git a/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java b/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java index a5def97e39a4c3db9a33c8495fc00a41991b9319..a11be0749058083ac68aad55589f96e53a6a5884 100644 --- a/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/NodeInfoDialog.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.dialogs; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoWrappedException; import sinalgo.gui.GUI; @@ -62,10 +65,13 @@ import java.util.Enumeration; /** * The class for the dialog displaying information about a node. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class NodeInfoDialog extends JDialog implements ActionListener, PropertyChangeListener { private static final long serialVersionUID = 5403782066445725367L; + @Getter private GUI parent; private Node node; @@ -95,10 +101,10 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC public NodeInfoDialog(GUI p, Node n) { super(p, "Edit Node " + n.getID(), true); GuiHelper.setWindowIcon(this); - this.parent = p; - this.node = n; + this.setParent(p); + this.setNode(n); - this.node.highlight(true); + this.getNode().highlight(true); this.setLayout(new BorderLayout()); @@ -116,39 +122,39 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC Node nd = nodesEnumer.nextElement(); if (nd.getID() == n.getID()) { if (!nodesEnumer.hasMoreElements()) { - this.nextNode.setEnabled(false); + this.getNextNode().setEnabled(false); } - this.prevNode.setEnabled(hasPrev); + this.getPrevNode().setEnabled(hasPrev); break; } hasPrev = true; } - this.prevNode.addActionListener(this); - this.nodeNumber.setColumns(6); - this.nodeNumber.setValue(this.node.getID()); - this.nodeNumber.addPropertyChangeListener("value", this); - this.nextNode.addActionListener(this); - nodeSel.add(this.prevNode); - nodeSel.add(this.nodeNumber); - nodeSel.add(this.nextNode); + this.getPrevNode().addActionListener(this); + this.getNodeNumber().setColumns(6); + this.getNodeNumber().setValue(this.getNode().getID()); + this.getNodeNumber().addPropertyChangeListener("value", this); + this.getNextNode().addActionListener(this); + nodeSel.add(this.getPrevNode()); + nodeSel.add(this.getNodeNumber()); + nodeSel.add(this.getNextNode()); this.add(nodeSel); - Position pos = this.node.getPosition(); + Position pos = this.getNode().getPosition(); - this.positionX.setText(String.valueOf(pos.getXCoord())); - this.positionY.setText(String.valueOf(pos.getYCoord())); - this.positionZ.setText(String.valueOf(pos.getZCoord())); + this.getPositionX().setText(String.valueOf(pos.getXCoord())); + this.getPositionY().setText(String.valueOf(pos.getYCoord())); + this.getPositionZ().setText(String.valueOf(pos.getZCoord())); JPanel position = new JPanel(); position.setBorder(BorderFactory.createTitledBorder("Position")); position.setLayout(new BoxLayout(position, BoxLayout.Y_AXIS)); position.setPreferredSize(new Dimension(80, 80)); - position.add(this.positionX); - position.add(this.positionY); + position.add(this.getPositionX()); + position.add(this.getPositionY()); if (Configuration.getDimensions() == 3) { - position.add(this.positionZ); + position.add(this.getPositionZ()); } nodeSelAndPosition.add(BorderLayout.NORTH, nodeSel); @@ -168,41 +174,41 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC info.add(infoPanel); UnborderedJTextField typeLabel = new UnborderedJTextField("Node Implementation:", Font.BOLD); - this.implementationText.setText(Global.toShortName(this.node.getClass().getName())); - this.implementationText.setEditable(false); + this.getImplementationText().setText(Global.toShortName(this.getNode().getClass().getName())); + this.getImplementationText().setEditable(false); infoPanel.add(typeLabel); - infoPanel.add(this.implementationText); + infoPanel.add(this.getImplementationText()); UnborderedJTextField connectivityLabel = new UnborderedJTextField("Node Connectivity:", Font.BOLD); - this.connectivityText.setText(Global.toShortName(this.node.getConnectivityModel().getClass().getName())); - this.connectivityText.setEditable(false); + this.getConnectivityText().setText(Global.toShortName(this.getNode().getConnectivityModel().getClass().getName())); + this.getConnectivityText().setEditable(false); infoPanel.add(connectivityLabel); - infoPanel.add(this.connectivityText); + infoPanel.add(this.getConnectivityText()); UnborderedJTextField interferenceLabel = new UnborderedJTextField("Node Interference:", Font.BOLD); - this.interferenceText.setText(Global.toShortName(this.node.getInterferenceModel().getClass().getName())); - this.interferenceText.setEditable(false); + this.getInterferenceText().setText(Global.toShortName(this.getNode().getInterferenceModel().getClass().getName())); + this.getInterferenceText().setEditable(false); infoPanel.add(interferenceLabel); - infoPanel.add(this.interferenceText); + infoPanel.add(this.getInterferenceText()); UnborderedJTextField mobilityLabel = new UnborderedJTextField("Node Mobility:", Font.BOLD); - this.mobilityText.setText(Global.toShortName(this.node.getMobilityModel().getClass().getName())); - this.mobilityText.setEditable(false); + this.getMobilityText().setText(Global.toShortName(this.getNode().getMobilityModel().getClass().getName())); + this.getMobilityText().setEditable(false); infoPanel.add(mobilityLabel); - infoPanel.add(this.mobilityText); + infoPanel.add(this.getMobilityText()); UnborderedJTextField reliabilityLabel = new UnborderedJTextField("Node Reliability:", Font.BOLD); - this.reliabilityText.setText(Global.toShortName(this.node.getReliabilityModel().getClass().getName())); - this.reliabilityText.setEditable(false); + this.getReliabilityText().setText(Global.toShortName(this.getNode().getReliabilityModel().getClass().getName())); + this.getReliabilityText().setEditable(false); infoPanel.add(reliabilityLabel); - infoPanel.add(this.reliabilityText); + infoPanel.add(this.getReliabilityText()); - this.infoText.setText(this.node.toString()); + this.getInfoText().setText(this.getNode().toString()); JLabel infoTextLabel = new JLabel("Info Text:"); - this.infoText.setEditable(false); - this.infoText.setBackground(infoTextLabel.getBackground()); + this.getInfoText().setEditable(false); + this.getInfoText().setBackground(infoTextLabel.getBackground()); infoPanel.add(infoTextLabel); - infoPanel.add(this.infoText); + infoPanel.add(this.getInfoText()); JPanel buttons = new JPanel(); @@ -220,8 +226,8 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC @Override public void windowClosing(WindowEvent event) { - NodeInfoDialog.this.node.highlight(false); - NodeInfoDialog.this.parent.redrawGUI(); + NodeInfoDialog.this.getNode().highlight(false); + NodeInfoDialog.this.getParent().redrawGUI(); } }; this.addWindowListener(listener); @@ -233,15 +239,15 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); focusManager.addKeyEventPostProcessor(e -> { if (!e.isConsumed() && e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE) { - this.node.highlight(false); + this.getNode().highlight(false); NodeInfoDialog.this.setVisible(false); - this.parent.redrawGUINow(); // needs blocking redrawing + this.getParent().redrawGUINow(); // needs blocking redrawing } return false; }); // Redraw the graph to have the selected node painted in the right color. - this.parent.redrawGUI(); + this.getParent().redrawGUI(); this.pack(); this.setLocationRelativeTo(p); this.setVisible(true); @@ -250,57 +256,57 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC private void revalidate(Node n, boolean hasPrev, boolean hasNext) { this.setTitle("Edit Node " + n.getID()); - this.node.highlight(false); + this.getNode().highlight(false); - this.node = n; + this.setNode(n); - this.node.highlight(true); + this.getNode().highlight(true); - this.prevNode.setEnabled(hasPrev); - this.nextNode.setEnabled(hasNext); + this.getPrevNode().setEnabled(hasPrev); + this.getNextNode().setEnabled(hasNext); - Position pos = this.node.getPosition(); + Position pos = this.getNode().getPosition(); - this.positionX.setText(String.valueOf(pos.getXCoord())); - this.positionY.setText(String.valueOf(pos.getYCoord())); - this.positionZ.setText(String.valueOf(pos.getZCoord())); + this.getPositionX().setText(String.valueOf(pos.getXCoord())); + this.getPositionY().setText(String.valueOf(pos.getYCoord())); + this.getPositionZ().setText(String.valueOf(pos.getZCoord())); - this.implementationText.setText(Global.toShortName(this.node.getClass().getName())); + this.getImplementationText().setText(Global.toShortName(this.getNode().getClass().getName())); - this.connectivityText.setText(Global.toShortName(this.node.getConnectivityModel().getClass().getName())); - this.interferenceText.setText(Global.toShortName(this.node.getInterferenceModel().getClass().getName())); - this.mobilityText.setText(Global.toShortName(this.node.getMobilityModel().getClass().getName())); - this.reliabilityText.setText(Global.toShortName(this.node.getReliabilityModel().getClass().getName())); + this.getConnectivityText().setText(Global.toShortName(this.getNode().getConnectivityModel().getClass().getName())); + this.getInterferenceText().setText(Global.toShortName(this.getNode().getInterferenceModel().getClass().getName())); + this.getMobilityText().setText(Global.toShortName(this.getNode().getMobilityModel().getClass().getName())); + this.getReliabilityText().setText(Global.toShortName(this.getNode().getReliabilityModel().getClass().getName())); - this.infoText.setText(this.node.toString()); - this.parent.redrawGUI(); + this.getInfoText().setText(this.getNode().toString()); + this.getParent().redrawGUI(); } @Override public void actionPerformed(ActionEvent event) { switch (event.getActionCommand()) { case "Cancel": - this.node.highlight(false); + this.getNode().highlight(false); this.setVisible(false); - this.parent.redrawGUINow(); // needs blocking redrawing + this.getParent().redrawGUINow(); // needs blocking redrawing break; case "OK": try { - this.node.setPosition(new Position(Double.parseDouble(this.positionX.getText()), - Double.parseDouble(this.positionY.getText()), Double.parseDouble(this.positionZ.getText()))); + this.getNode().setPosition(new Position(Double.parseDouble(this.getPositionX().getText()), + Double.parseDouble(this.getPositionY().getText()), Double.parseDouble(this.getPositionZ().getText()))); } catch (NumberFormatException nFE) { throw new SinalgoWrappedException(nFE); } - this.node.highlight(false); + this.getNode().highlight(false); this.setVisible(false); - this.parent.redrawGUINow(); // needs blocking redrawing + this.getParent().redrawGUINow(); // needs blocking redrawing break; case "Next Node": { Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); while (nodesEnumer.hasMoreElements()) { Node nd = nodesEnumer.nextElement(); - if (nd.getID() == this.node.getID() + 1) { - this.nodeNumber.setValue(nd.getID()); + if (nd.getID() == this.getNode().getID() + 1) { + this.getNodeNumber().setValue(nd.getID()); // this triggers a property change event. break; } @@ -311,8 +317,8 @@ public class NodeInfoDialog extends JDialog implements ActionListener, PropertyC Enumeration<Node> nodesEnumer = SinalgoRuntime.nodes.getNodeEnumeration(); while (nodesEnumer.hasMoreElements()) { Node nd = nodesEnumer.nextElement(); - if (nd.getID() == this.node.getID() - 1) { - this.nodeNumber.setValue(nd.getID()); + if (nd.getID() == this.getNode().getID() - 1) { + this.getNodeNumber().setValue(nd.getID()); // this triggers a property change event. break; } diff --git a/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java b/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java index 1c74ee88ff1f9a926ba8dd1cfe91ecd955b69591..58728c6dba368b46466e4b040736646252fbb4e9 100644 --- a/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java +++ b/src/main/java/sinalgo/gui/dialogs/PercentualProgressDialog.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.dialogs; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.gui.GuiHelper; import javax.swing.*; @@ -44,6 +47,8 @@ import java.awt.*; /** * This is a JDialog that shows the percentual progress of a action. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class PercentualProgressDialog extends JDialog { private static final long serialVersionUID = 1320076393340365149L; @@ -118,17 +123,17 @@ public class PercentualProgressDialog extends JDialog { */ public void create(ProgressBarUser pbu) { GuiHelper.setWindowIcon(this); - this.pBU = pbu; + this.setPBU(pbu); - this.jPB.setStringPainted(true); - this.jp.add(this.jPB); + this.getJPB().setStringPainted(true); + this.getJp().add(this.getJPB()); - this.buttonPanel.add(this.cancel); + this.getButtonPanel().add(this.getCancel()); this.setLayout(new BorderLayout()); - this.add(BorderLayout.NORTH, this.jp); - this.add(BorderLayout.SOUTH, this.buttonPanel); + this.add(BorderLayout.NORTH, this.getJp()); + this.add(BorderLayout.SOUTH, this.getButtonPanel()); this.setResizable(false); this.setLocationRelativeTo(null); @@ -136,10 +141,10 @@ public class PercentualProgressDialog extends JDialog { this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - this.cancel.addActionListener(e -> { - this.pBU.cancelClicked(); + this.getCancel().addActionListener(e -> { + this.getPBU().cancelClicked(); this.setTitle("Undoing..."); - this.cancel.setEnabled(false); + this.getCancel().setEnabled(false); }); } @@ -165,14 +170,14 @@ public class PercentualProgressDialog extends JDialog { * @param percent The percentage of the progress. */ public void setPercentage(double percent) { - this.jPB.setValue((int) (percent)); + this.getJPB().setValue((int) (percent)); } private class UpdateThread extends Thread { @Override public void run() { - PercentualProgressDialog.this.pBU.performMethod(); + PercentualProgressDialog.this.getPBU().performMethod(); } } } diff --git a/src/main/java/sinalgo/gui/helper/Arrow.java b/src/main/java/sinalgo/gui/helper/Arrow.java index 4ff2e09129c9e0c865b892d1ba0bc8d98181a9b5..243317c3efd26c2ceae4472c9f8991fd7072d2eb 100644 --- a/src/main/java/sinalgo/gui/helper/Arrow.java +++ b/src/main/java/sinalgo/gui/helper/Arrow.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.helper; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.gui.transformation.PositionTransformation; @@ -48,7 +51,12 @@ import java.io.PrintStream; */ public class Arrow { + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static int unzoomedArrowLength = Configuration.getArrowLength(); + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static int unzoomedArrowWidth = Configuration.getArrowWidth(); /** @@ -98,8 +106,8 @@ public class Arrow { g.setColor(col); // the size of the arrow - double arrowLength = unzoomedArrowLength * pt.getZoomFactor(); - double arrowWidth = unzoomedArrowWidth * pt.getZoomFactor(); + double arrowLength = getUnzoomedArrowLength() * pt.getZoomFactor(); + double arrowWidth = getUnzoomedArrowWidth() * pt.getZoomFactor(); double lineLength = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); // shorten the arrow if the two nodes are very close @@ -119,21 +127,26 @@ public class Arrow { // one end-point of the triangle is (x2,y2), the second end-point (ex1, ey1) and // the third (ex2, ey2) - arrowX[0] = x2; - arrowY[0] = y2; - arrowX[1] = (int) (ix + arrowWidth * uy); - arrowY[1] = (int) (iy - arrowWidth * ux); - arrowX[2] = (int) (ix - arrowWidth * uy); - arrowY[2] = (int) (iy + arrowWidth * ux); + getArrowX()[0] = x2; + getArrowY()[0] = y2; + getArrowX()[1] = (int) (ix + arrowWidth * uy); + getArrowY()[1] = (int) (iy - arrowWidth * ux); + getArrowX()[2] = (int) (ix - arrowWidth * uy); + getArrowY()[2] = (int) (iy + arrowWidth * ux); - g.fillPolygon(arrowX, arrowY, 3); + g.fillPolygon(getArrowX(), getArrowY(), 3); g.setColor(tmpCol); } } - private static int arrowX[] = new int[3]; - private static int arrowY[] = new int[3]; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static int[] arrowX = new int[3]; + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static int[] arrowY = new int[3]; /** * This method writes an arrow (Edge) as metapost into the given printstream. It diff --git a/src/main/java/sinalgo/gui/helper/MultiLineFlowLayout.java b/src/main/java/sinalgo/gui/helper/MultiLineFlowLayout.java index 398bd290c9b4c5fe92c2632768b1f1b4cce5543e..2aadfa8ea5286c487ce18e859c556b21c51ff1ad 100644 --- a/src/main/java/sinalgo/gui/helper/MultiLineFlowLayout.java +++ b/src/main/java/sinalgo/gui/helper/MultiLineFlowLayout.java @@ -36,12 +36,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.helper; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + import java.awt.*; /** * Similar to FlowLayout, but allows to set max width and then starts a new * line. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class MultiLineFlowLayout implements LayoutManager { private int maxWidth; @@ -54,9 +60,9 @@ public class MultiLineFlowLayout implements LayoutManager { * @param vGap the vertical gap between two elements */ public MultiLineFlowLayout(int maxWidth, int hGap, int vGap) { - this.maxWidth = maxWidth; - this.hGap = hGap; - this.vGap = vGap; + this.setMaxWidth(maxWidth); + this.setHGap(hGap); + this.setVGap(vGap); } private int exactLineHeight = -1; @@ -67,7 +73,7 @@ public class MultiLineFlowLayout implements LayoutManager { * @param height The exact height of the line. */ public void setExactLineHight(int height) { - this.exactLineHeight = height; // set to <= 0 to disable + this.setExactLineHeight(height); // set to <= 0 to disable } @Override @@ -75,7 +81,7 @@ public class MultiLineFlowLayout implements LayoutManager { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); - int totalWidth = this.maxWidth - insets.left - insets.right; + int totalWidth = this.getMaxWidth() - insets.left - insets.right; int height = 0; int width = 0; int maxHeightOfThisLine = 0; @@ -85,19 +91,19 @@ public class MultiLineFlowLayout implements LayoutManager { Component c = parent.getComponent(i); Dimension d = c.getPreferredSize(); if (width + d.width < totalWidth || width == 0) { // also accept any first component on this line - width += d.width + this.hGap; + width += d.width + this.getHGap(); maxHeightOfThisLine = Math.max(maxHeightOfThisLine, d.height); } else { // this component must go onto the next line - if (this.exactLineHeight > 0) { - maxHeightOfThisLine = this.exactLineHeight; + if (this.getExactLineHeight() > 0) { + maxHeightOfThisLine = this.getExactLineHeight(); } - height += maxHeightOfThisLine + this.vGap; + height += maxHeightOfThisLine + this.getVGap(); maxHeightOfThisLine = d.height; - width = d.width + this.hGap; + width = d.width + this.getHGap(); } } height += maxHeightOfThisLine; - return new Dimension(this.maxWidth, insets.top + insets.bottom + height); + return new Dimension(this.getMaxWidth(), insets.top + insets.bottom + height); } } @@ -111,7 +117,7 @@ public class MultiLineFlowLayout implements LayoutManager { synchronized (parent.getTreeLock()) { Insets insets = parent.getInsets(); - int totalWidth = this.maxWidth - insets.left - insets.right; + int totalWidth = this.getMaxWidth() - insets.left - insets.right; int height = 0; int width = 0; int maxHeightOfThisLine = 0; @@ -123,16 +129,16 @@ public class MultiLineFlowLayout implements LayoutManager { c.setSize(d); // we need to set the size of the components if (width + d.width < totalWidth || width == 0) { // also accept any first component on this line c.setLocation(insets.left + width, insets.top + height); - width += d.width + this.hGap; + width += d.width + this.getHGap(); maxHeightOfThisLine = Math.max(maxHeightOfThisLine, d.height); } else { // this component must go onto the next line - if (this.exactLineHeight > 0) { - maxHeightOfThisLine = this.exactLineHeight; + if (this.getExactLineHeight() > 0) { + maxHeightOfThisLine = this.getExactLineHeight(); } - height += maxHeightOfThisLine + this.vGap; + height += maxHeightOfThisLine + this.getVGap(); c.setLocation(insets.left, insets.top + height); // width is 0 maxHeightOfThisLine = d.height; - width = d.width + this.hGap; + width = d.width + this.getHGap(); } } } @@ -147,5 +153,4 @@ public class MultiLineFlowLayout implements LayoutManager { public void removeLayoutComponent(Component comp) { // not used by this class } - } diff --git a/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java b/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java index 99e5ca0ab591608d19c2703294fbddf9433c2632..bfc344d2c7b289c9f2a7399e3eebe5b59002bb57 100644 --- a/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java +++ b/src/main/java/sinalgo/gui/helper/NonRegularGridLayout.java @@ -36,6 +36,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.helper; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + import java.awt.*; /** @@ -77,17 +81,15 @@ public class NonRegularGridLayout extends GridLayout { super(rows, cols, hgap, vgap); } - private boolean alignToLeft = false; - /** - * Sets whether all components of the grid should be left-aligned and the + * Determines whether all components of the grid should be left-aligned and the * remaining space given to the right-most cells. * - * @param alignLeft Whether to align left or not + * @param alignToLeft Whether to align left or not */ - public void setAlignToLeft(boolean alignLeft) { - this.alignToLeft = alignLeft; - } + @Getter(AccessLevel.PRIVATE) + @Setter + private boolean alignToLeft = false; @Override public Dimension preferredLayoutSize(Container parent) { @@ -179,7 +181,7 @@ public class NonRegularGridLayout extends GridLayout { // scaling factors Dimension pd = this.preferredLayoutSize(parent); - if (this.alignToLeft) { + if (this.isAlignToLeft()) { int[] w = new int[ncols]; // maximal width int[] h = new int[nrows]; // maximal height this.calculateSize(parent, ncomponents, ncols, w, h); diff --git a/src/main/java/sinalgo/gui/helper/UnborderedJTextField.java b/src/main/java/sinalgo/gui/helper/UnborderedJTextField.java index 56a288d9af62e54cfe8af1239195caa4d1ae13c0..30f3ab14d2bcdea52bb7547ac5cd781851cff2fb 100644 --- a/src/main/java/sinalgo/gui/helper/UnborderedJTextField.java +++ b/src/main/java/sinalgo/gui/helper/UnborderedJTextField.java @@ -50,8 +50,8 @@ public class UnborderedJTextField extends MultiLineToolTipJTextField { private static final long serialVersionUID = 3756769692591270883L; - private static Font boldHelvetica12 = new Font("Helvetica", Font.BOLD, 12); - private static Font plainHelvetica12 = new Font("Helvetica", Font.PLAIN, 12); + private static final Font BOLD_HELVETICA_12 = new Font("Helvetica", Font.BOLD, 12); + private static final Font PLAIN_HELVETICA_12 = new Font("Helvetica", Font.PLAIN, 12); /** * Creates a Text field having no border that is not editable and that has a @@ -66,10 +66,10 @@ public class UnborderedJTextField extends MultiLineToolTipJTextField { this.setBorder(BorderFactory.createEmptyBorder()); switch (type) { case Font.BOLD: - this.setFont(boldHelvetica12); + this.setFont(BOLD_HELVETICA_12); break; case Font.PLAIN: - this.setFont(plainHelvetica12); + this.setFont(PLAIN_HELVETICA_12); break; default: throw new NotYetImplementedException("There this Font-Style is not supported."); diff --git a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java index dc9353d6a53f3f27fc95fe8824ccf7e5574a78ec..d8510d29fbbdb2d51f8487aae0052a7429334a2c 100644 --- a/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java +++ b/src/main/java/sinalgo/gui/multiLineTooltip/MultiLineToolTip.java @@ -36,6 +36,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.multiLineTooltip; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; + import javax.swing.*; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicToolTipUI; @@ -49,9 +53,6 @@ public class MultiLineToolTip extends JToolTip { private static final long serialVersionUID = 1860432832820206556L; - String tipText; - JComponent component; - /** * The constructor for the MyToolTip class. */ @@ -71,53 +72,57 @@ public class MultiLineToolTip extends JToolTip { */ public void setColumns(int columns) { this.columns = columns; - this.fixedwidth = 0; + this.setFixedWidth(0); } /** - * This method returns the number of columns the tooltip has. + * This method sets the fixed width for the tooltip. * - * @return The number of columns the Tooltip has. + * @param width The fixed width of the tooltip. */ - public int getColumns() { - return this.columns; + public void setFixedWidth(int width) { + this.fixedWidth = width; + this.setColumns(0); } /** - * This method sets the fixed width for the tooltip. + * The number of columns the tooltip has. * - * @param width The fixed width of the tooltip. + * @return The number of columns the tooltip has. */ - public void setFixedWidth(int width) { - this.fixedwidth = width; - this.columns = 0; - } + @Getter + private int columns = 0; /** - * This method returns the fixes with of the tooltip. + * The fixed with of the tooltip. * * @return The fixed width of the tooltip. */ - public int getFixedWidth() { - return this.fixedwidth; - } - - protected int columns = 0; - protected int fixedwidth = 0; + @Getter + private int fixedWidth = 0; } // used such that the tooltip can display several lines of text (e.g. newlines) +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) class MultiLineToolTipUI extends BasicToolTipUI { - static MultiLineToolTipUI sharedInstance = new MultiLineToolTipUI(); - Font smallFont; - static JToolTip tip; - protected CellRendererPane rendererPane; + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static MultiLineToolTipUI sharedInstance = new MultiLineToolTipUI(); + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) + private static JToolTip tip; + + private CellRendererPane rendererPane; + + @Getter(AccessLevel.PRIVATE) + @Setter(AccessLevel.PRIVATE) private static JTextArea textArea; public static ComponentUI createUI(JComponent c) { - return sharedInstance; + return getSharedInstance(); } /** @@ -130,24 +135,24 @@ class MultiLineToolTipUI extends BasicToolTipUI { @Override public void installUI(JComponent c) { super.installUI(c); - tip = (JToolTip) c; - this.rendererPane = new CellRendererPane(); - c.add(this.rendererPane); + setTip((JToolTip) c); + this.setRendererPane(new CellRendererPane()); + c.add(this.getRendererPane()); } @Override public void uninstallUI(JComponent c) { super.uninstallUI(c); - c.remove(this.rendererPane); - this.rendererPane = null; + c.remove(this.getRendererPane()); + this.setRendererPane(null); } @Override public void paint(Graphics g, JComponent c) { Dimension size = c.getSize(); - textArea.setBackground(c.getBackground()); - this.rendererPane.paintComponent(g, textArea, c, 1, 1, size.width - 1, size.height - 1, true); + getTextArea().setBackground(c.getBackground()); + this.getRendererPane().paintComponent(g, getTextArea(), c, 1, 1, size.width - 1, size.height - 1, true); } @Override @@ -156,29 +161,29 @@ class MultiLineToolTipUI extends BasicToolTipUI { if (tipText == null) { return new Dimension(0, 0); } - textArea = new JTextArea(tipText); - this.rendererPane.removeAll(); - this.rendererPane.add(textArea); - textArea.setWrapStyleWord(true); + setTextArea(new JTextArea(tipText)); + this.getRendererPane().removeAll(); + this.getRendererPane().add(getTextArea()); + getTextArea().setWrapStyleWord(true); int width = ((MultiLineToolTip) c).getFixedWidth(); int columns = ((MultiLineToolTip) c).getColumns(); if (columns > 0) { - textArea.setColumns(columns); - textArea.setSize(0, 0); - textArea.setLineWrap(true); - textArea.setSize(textArea.getPreferredSize()); + getTextArea().setColumns(columns); + getTextArea().setSize(0, 0); + getTextArea().setLineWrap(true); + getTextArea().setSize(getTextArea().getPreferredSize()); } else if (width > 0) { - textArea.setLineWrap(true); - Dimension d = textArea.getPreferredSize(); + getTextArea().setLineWrap(true); + Dimension d = getTextArea().getPreferredSize(); d.width = width; d.height++; - textArea.setSize(d); + getTextArea().setSize(d); } else { - textArea.setLineWrap(false); + getTextArea().setLineWrap(false); } - Dimension dim = textArea.getPreferredSize(); + Dimension dim = getTextArea().getPreferredSize(); dim.height += 1; dim.width += 1; @@ -194,4 +199,5 @@ class MultiLineToolTipUI extends BasicToolTipUI { public Dimension getMaximumSize(JComponent c) { return this.getPreferredSize(c); } + } diff --git a/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java b/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java index 585744780ae6c77b4ac02701ff2029a20a64149b..0b6e02b467bc426dfe39dbbdcb77d8fddf47a415 100644 --- a/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/AbstractPopupMenu.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.popups; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.gui.GUI; import javax.swing.*; @@ -45,18 +48,21 @@ import java.awt.event.ActionListener; /** * Common items for popup menus */ +@Getter(AccessLevel.PROTECTED) +@Setter(AccessLevel.PROTECTED) public abstract class AbstractPopupMenu extends JPopupMenu { private static final long serialVersionUID = 6108642977345194041L; - protected GUI parent = null; + @Getter + private GUI parent = null; - protected JMenuItem zoomIn = new JMenuItem("Zoom In"); - protected JMenuItem zoomOut = new JMenuItem("Zoom Out"); + private JMenuItem zoomIn = new JMenuItem("Zoom In"); + private JMenuItem zoomOut = new JMenuItem("Zoom Out"); protected AbstractPopupMenu() { - this.zoomIn.addActionListener(new ZoomListener()); - this.zoomOut.addActionListener(new ZoomListener()); + this.getZoomIn().addActionListener(new ZoomListener()); + this.getZoomOut().addActionListener(new ZoomListener()); } // Listening to the zoom in and zoom out action events @@ -64,10 +70,10 @@ public abstract class AbstractPopupMenu extends JPopupMenu { @Override public void actionPerformed(ActionEvent event) { - if (event.getActionCommand().equals(AbstractPopupMenu.this.zoomIn.getActionCommand())) { - AbstractPopupMenu.this.parent.zoomIn(); - } else if (event.getActionCommand().equals(AbstractPopupMenu.this.zoomOut.getActionCommand())) { - AbstractPopupMenu.this.parent.zoomOut(); + if (event.getActionCommand().equals(AbstractPopupMenu.this.getZoomIn().getActionCommand())) { + AbstractPopupMenu.this.getParent().zoomIn(); + } else if (event.getActionCommand().equals(AbstractPopupMenu.this.getZoomOut().getActionCommand())) { + AbstractPopupMenu.this.getParent().zoomOut(); } } } diff --git a/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java b/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java index 23e4074047f58f55e0a93741a9a3a2e93be9721f..7af9c607facc2bacb4c4aa71db9df7c9d46bddd7 100644 --- a/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/EdgePopupMenu.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.popups; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.gui.GUI; import sinalgo.gui.dialogs.EdgeInfoDialog; import sinalgo.nodes.edges.Edge; @@ -48,6 +51,8 @@ import java.awt.event.ActionListener; /** * The PopupMenu which pops up upon a right-click on an Edge */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class EdgePopupMenu extends AbstractPopupMenu implements ActionListener { private static final long serialVersionUID = 1879611828353447896L; @@ -62,9 +67,9 @@ public class EdgePopupMenu extends AbstractPopupMenu implements ActionListener { * @param p The parent GUI used to trigger the zooming. */ public EdgePopupMenu(GUI p) { - this.parent = p; - this.info.addActionListener(this); - this.delete.addActionListener(this); + this.setParent(p); + this.getInfo().addActionListener(this); + this.getDelete().addActionListener(this); } /** @@ -73,25 +78,25 @@ public class EdgePopupMenu extends AbstractPopupMenu implements ActionListener { * @param e The edge the information is about. */ public void compose(Edge e) { - this.edge = e; + this.setEdge(e); this.removeAll(); - this.add(this.info); - this.add(this.delete); + this.add(this.getInfo()); + this.add(this.getDelete()); this.addSeparator(); - this.add(this.zoomIn); - this.add(this.zoomOut); + this.add(this.getZoomIn()); + this.add(this.getZoomOut()); } @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals(this.info.getActionCommand())) { - new EdgeInfoDialog(this.parent, this.edge); - } else if (e.getActionCommand().equals(this.delete.getActionCommand())) { - SinalgoRuntime.removeEdge(this.edge); - this.parent.redrawGUINow(); + if (e.getActionCommand().equals(this.getInfo().getActionCommand())) { + new EdgeInfoDialog(this.getParent(), this.getEdge()); + } else if (e.getActionCommand().equals(this.getDelete().getActionCommand())) { + SinalgoRuntime.removeEdge(this.getEdge()); + this.getParent().redrawGUINow(); } } } diff --git a/src/main/java/sinalgo/gui/popups/EventPopupMenu.java b/src/main/java/sinalgo/gui/popups/EventPopupMenu.java index b9d6ad2f7bdb3d828b173b044b6a6169b39d027c..3bd967cd2643d593b41f5ea0af8bc35a99860f46 100644 --- a/src/main/java/sinalgo/gui/popups/EventPopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/EventPopupMenu.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.popups; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.runtime.SinalgoRuntime; import sinalgo.runtime.events.Event; @@ -48,6 +51,8 @@ import java.awt.event.ComponentListener; /** * @author rflury */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class EventPopupMenu extends JPopupMenu implements ActionListener { private static final long serialVersionUID = 315706472796346139L; @@ -60,24 +65,24 @@ public class EventPopupMenu extends JPopupMenu implements ActionListener { private JMenuItem deleteAll = new JMenuItem("Delete All Events"); public EventPopupMenu(Event e, JList l, ListCellRenderer lcr) { - this.event = e; - this.list = l; - this.renderer = lcr; - this.info.addActionListener(this); - this.delete.addActionListener(this); - this.deleteAll.addActionListener(this); - - this.add(this.info); + this.setEvent(e); + this.setList(l); + this.setRenderer(lcr); + this.getInfo().addActionListener(this); + this.getDelete().addActionListener(this); + this.getDeleteAll().addActionListener(this); + + this.add(this.getInfo()); this.addSeparator(); - this.add(this.delete); - this.add(this.deleteAll); + this.add(this.getDelete()); + this.add(this.getDeleteAll()); this.addComponentListener(new ComponentListener() { @Override public void componentHidden(ComponentEvent e) { - EventPopupMenu.this.list.setCellRenderer(EventPopupMenu.this.renderer); - EventPopupMenu.this.list.repaint(); + EventPopupMenu.this.getList().setCellRenderer(EventPopupMenu.this.getRenderer()); + EventPopupMenu.this.getList().repaint(); } @Override @@ -97,17 +102,16 @@ public class EventPopupMenu extends JPopupMenu implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals(this.info.getActionCommand())) { + if (e.getActionCommand().equals(this.getInfo().getActionCommand())) { JOptionPane.showMessageDialog(null, - this.event.getEventListText(false) + "\n" + this.event.getEventListToolTipText(false), + this.getEvent().getEventListText(false) + "\n" + this.getEvent().getEventListToolTipText(false), "Information about an Event", JOptionPane.INFORMATION_MESSAGE); - } else if (e.getActionCommand().equals(this.delete.getActionCommand())) { - SinalgoRuntime.removeEvent(this.event); - } else if (e.getActionCommand().equals(this.deleteAll.getActionCommand())) { + } else if (e.getActionCommand().equals(this.getDelete().getActionCommand())) { + SinalgoRuntime.removeEvent(this.getEvent()); + } else if (e.getActionCommand().equals(this.getDeleteAll().getActionCommand())) { SinalgoRuntime.removeAllAsynchronousEvents(); } - this.list.setCellRenderer(this.renderer); - this.list.repaint(); + this.getList().setCellRenderer(this.getRenderer()); + this.getList().repaint(); } - } diff --git a/src/main/java/sinalgo/gui/popups/NodePopupMenu.java b/src/main/java/sinalgo/gui/popups/NodePopupMenu.java index 193c46f9066382b3e64ef555bc61e46684ee85e1..bc4c51758cc4f01c2326d08d6e6bf8f05087bbcc 100644 --- a/src/main/java/sinalgo/gui/popups/NodePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/NodePopupMenu.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.popups; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.configuration.Configuration; import sinalgo.exception.SinalgoFatalException; import sinalgo.gui.GUI; @@ -55,6 +58,8 @@ import java.util.HashMap; * The class for the popupmenus displayed on the graph panel when the user * presses the right mouse button over a node. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { private static final long serialVersionUID = 3539517948195533969L; @@ -73,11 +78,11 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { * @param p The parent gui, where the popupMenu appears in. */ public NodePopupMenu(GUI p) { - this.parent = p; - this.info.addActionListener(this); - this.delete.addActionListener(this); - this.showCoordinateCube.addActionListener(this); - this.hideCoordinateCube.addActionListener(this); + this.setParent(p); + this.getInfo().addActionListener(this); + this.getDelete().addActionListener(this); + this.getShowCoordinateCube().addActionListener(this); + this.getHideCoordinateCube().addActionListener(this); } /** @@ -87,22 +92,22 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { */ public void compose(Node n) { - this.node = n; + this.setNode(n); - this.methodsAndDescriptions.clear(); + this.getMethodsAndDescriptions().clear(); this.removeAll(); - this.add(this.info); + this.add(this.getInfo()); if (Configuration.getDimensions() == 3) { - if (this.parent.getGraphPanel().containsNodeToDrawCoordinateCube(n)) { - this.add(this.hideCoordinateCube); + if (this.getParent().getGraphPanel().containsNodeToDrawCoordinateCube(n)) { + this.add(this.getHideCoordinateCube()); } else { - this.add(this.showCoordinateCube); + this.add(this.getShowCoordinateCube()); } } - this.add(this.delete); + this.add(this.getDelete()); this.addSeparator(); @@ -111,7 +116,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { boolean customMethods = false; - Method[] methods = this.node.getClass().getMethods(); + Method[] methods = this.getNode().getClass().getMethods(); for (Method method : methods) { Node.NodePopupMethod info = method.getAnnotation(Node.NodePopupMethod.class); if (info != null) { @@ -123,7 +128,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { item.addActionListener(this); // BUGFIX for 0.75.0 -> 0.75.1 : this line was missing this.add(item); customMethods = true; - this.methodsAndDescriptions.put(text, method); // BUGFIX: 1st parameter was info.menuText() + this.getMethodsAndDescriptions().put(text, method); // BUGFIX: 1st parameter was info.menuText() } } @@ -133,34 +138,34 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { this.addSeparator(); - this.add(this.zoomIn); - this.add(this.zoomOut); + this.add(this.getZoomIn()); + this.add(this.getZoomOut()); } @Override public void actionPerformed(ActionEvent event) { - if (event.getActionCommand().equals(this.info.getActionCommand())) { - new NodeInfoDialog(this.parent, this.node); - } else if (event.getActionCommand().equals(this.delete.getActionCommand())) { - SinalgoRuntime.removeNode(this.node); - this.parent.redrawGUI(); - } else if (event.getActionCommand().equals(this.showCoordinateCube.getActionCommand())) { - this.parent.getGraphPanel().setNodeToDrawCoordinateCube(this.node); - this.parent.repaint(); // need not repaint the graph, only the toppings - } else if (event.getActionCommand().equals(this.hideCoordinateCube.getActionCommand())) { - this.parent.getGraphPanel().removeNodeToDrawCoordinateCube(this.node); - this.parent.repaint(); // need not repaint the graph, only the toppings + if (event.getActionCommand().equals(this.getInfo().getActionCommand())) { + new NodeInfoDialog(this.getParent(), this.getNode()); + } else if (event.getActionCommand().equals(this.getDelete().getActionCommand())) { + SinalgoRuntime.removeNode(this.getNode()); + this.getParent().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 + } 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 } else { // try to execute a custom-command - Method clickedMethod = this.methodsAndDescriptions.get(event.getActionCommand()); + Method clickedMethod = this.getMethodsAndDescriptions().get(event.getActionCommand()); if (clickedMethod == null) { throw new SinalgoFatalException("Cannot find method associated with menu item " + event.getActionCommand()); } try { - synchronized (this.parent.getTransformator()) { + synchronized (this.getParent().getTransformator()) { // synchronize it on the transformator to grant not to be concurrent with // any drawing or modifying action - clickedMethod.invoke(this.node); + clickedMethod.invoke(this.getNode()); } } catch (InvocationTargetException e) { String text = ""; @@ -177,7 +182,7 @@ public class NodePopupMenu extends AbstractPopupMenu implements ActionListener { + e.getMessage()); } - this.parent.redrawGUI(); + this.getParent().redrawGUI(); } } } diff --git a/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java b/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java index de70e164cb41f0617fd2211aaab78a2540734649..9ce120228c08d50296cb736cc193c4d7a82cf6bc 100644 --- a/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java +++ b/src/main/java/sinalgo/gui/popups/SpacePopupMenu.java @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ package sinalgo.gui.popups; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.Setter; import sinalgo.gui.GUI; import sinalgo.gui.transformation.PositionTransformation; import sinalgo.nodes.Position; @@ -50,12 +53,13 @@ import java.awt.event.ActionListener; * presses the right mouse button over a place, where there is no node and no * edge. */ +@Getter(AccessLevel.PRIVATE) +@Setter(AccessLevel.PRIVATE) public class SpacePopupMenu extends AbstractPopupMenu implements ActionListener { private static final long serialVersionUID = 8356598949303688723L; private Point pos = null; - private JMenuItem add = new JMenuItem("Add Node"); /** @@ -64,8 +68,8 @@ 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.parent = p; - this.add.addActionListener(this); + this.setParent(p); + this.getAdd().addActionListener(this); } /** @@ -74,26 +78,26 @@ public class SpacePopupMenu extends AbstractPopupMenu implements ActionListener * @param p The position the user clicked to. */ public void compose(Point p) { - this.pos = p; + this.setPos(p); this.removeAll(); - if (this.parent.getTransformator().supportReverseTranslation()) { - this.add(this.add); + if (this.getParent().getTransformator().supportReverseTranslation()) { + this.add(this.getAdd()); this.addSeparator(); } - this.add(this.zoomIn); - this.add(this.zoomOut); + this.add(this.getZoomIn()); + this.add(this.getZoomOut()); } @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals(this.add.getActionCommand())) { - PositionTransformation pt = this.parent.getTransformator(); + if (e.getActionCommand().equals(this.getAdd().getActionCommand())) { + PositionTransformation pt = this.getParent().getTransformator(); if (pt.supportReverseTranslation()) { - pt.translateToLogicPosition(this.pos.x, this.pos.y); - this.parent.addSingleNode(new Position(pt.getLogicX(), pt.getLogicY(), pt.getLogicZ())); + pt.translateToLogicPosition(this.getPos().x, this.getPos().y); + this.getParent().addSingleNode(new Position(pt.getLogicX(), pt.getLogicY(), pt.getLogicZ())); } } } diff --git a/src/main/java/sinalgo/runtime/GUIRuntime.java b/src/main/java/sinalgo/runtime/GUIRuntime.java index 35ea8cea5013c58cda5ba812ac516f855da6ebc6..ff2dea58a901eaf2cc2a48036fd483ff967e2da6 100644 --- a/src/main/java/sinalgo/runtime/GUIRuntime.java +++ b/src/main/java/sinalgo/runtime/GUIRuntime.java @@ -98,7 +98,7 @@ public class GUIRuntime extends SinalgoRuntime implements ProgressBarUser { // wait until the the GUI has been painted at least once // this ensures that the the entire GUI has been drawn nicely // before any simulation starts - while (!GraphPanel.firstTimePainted) { + while (!GraphPanel.isFirstTimePainted()) { try { synchronized (this) { this.wait(100);