From d28d8d995314b063b1466ee9ee2cbf503c960ae3 Mon Sep 17 00:00:00 2001 From: Jelle Van De Sijpe Date: Sun, 15 Mar 2020 17:35:50 +0100 Subject: [PATCH] added comments --- .../java/GUI/Components/GUIBlockHandler.java | 73 ++++++++++++++++++- .../java/GUI/Components/GUIConnector.java | 6 +- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/src/main/java/GUI/Components/GUIBlockHandler.java b/src/main/java/GUI/Components/GUIBlockHandler.java index 8a960ea9..b76926f6 100644 --- a/src/main/java/GUI/Components/GUIBlockHandler.java +++ b/src/main/java/GUI/Components/GUIBlockHandler.java @@ -1,13 +1,10 @@ package GUI.Components; -import Controllers.ConnectionController; -import Controllers.ProgramController; import GUI.Blocks.GUIBlock; import GUI.CollisionShapes.CollisionRectangle; import GUI.Panel.GamePanel; import GUI.Panel.PalettePanel; import GUI.Panel.ProgramAreaPanel; -import System.Logic.ProgramArea.Program; import Utility.Position; import java.awt.event.MouseEvent; @@ -15,6 +12,11 @@ import java.util.List; import java.util.Optional; +/** + * A class used to handle GUI blocks. + * + * @author Alpha-team + */ public class GUIBlockHandler { private final PalettePanel palette; @@ -29,6 +31,14 @@ public GUIBlockHandler(PalettePanel palette, ProgramAreaPanel programArea) { this.programArea = programArea; } + /** + * Handle the current mouse event with the given id, x and y coordinate. + * @param id the given mouse event id + * @param x the given mouse x-coordinate + * @param y the given mouse y-coordinate + * + * @effect The right mouse event is handled accordingly. + */ public void handleMouseEvent(int id, int x, int y) { if (id == MouseEvent.MOUSE_PRESSED) { @@ -42,6 +52,11 @@ else if (id == MouseEvent.MOUSE_DRAGGED) { } } + /** + * todo + * @param x + * @param y + */ private void handleMousePressed(int x, int y) { boolean paletteBlockContainsMouse = AnyContains(palette.getBlocks(), x, y); @@ -66,6 +81,9 @@ private void handleMousePressed(int x, int y) { } } + /** + * todo + */ private void handleMouseReleased() { if (draggedBlock != null) { @@ -91,12 +109,23 @@ else if (isInPanelAny(palette.getPanelRectangle(), draggedBlocks)) { } } + /** + * Handle the event where the mouse is dragged with the given x and y coordinates of the mouse. + * + * @param x the given x-coordinate of the mouse + * @param y the given y-coordinate of the mouse + * + * @effect The position of the dragged block is updated accordingly. + */ private void handleMouseDragged(int x, int y) { if (draggedBlock != null) { draggedBlock.setPosition(x + dragDelta.getX(), y + dragDelta.getY()); } } + /** + * todo + */ private void handleBlockFromPaletteToProgramArea() { GUIBlock newBlock = palette.getNewBlock(draggedBlock.getId(), draggedBlock.getX(), draggedBlock.getY()); @@ -114,12 +143,15 @@ private void handleBlockFromPaletteToProgramArea() { } } + /** + * todo + */ private void handleBlockFromProgramAreaToProgramArea() { + boolean connectionFound = false; programArea.disconnectInProgramArea(draggedBlock); draggedBlock.disconnectMainConnector(); - for (GUIBlock block : draggedBlocks) { Optional connectedBlock = programArea.getBlocks().stream().filter(b -> b.intersectsWithConnector(block)).findAny(); @@ -134,6 +166,13 @@ private void handleBlockFromProgramAreaToProgramArea() { } } + /** + * Handle the event where the dragged gui bock goes from a certain position to the palette + * + * @effect Disconnect the dragged block from its previous set of blocks. + * @effect Reset the position of the original palette block if the dragged block came from the palette. + * @effect Delete the block from the program area if the dragged block came from the program area. + */ private void handleBlockToPalette() { programArea.disconnectInProgramArea(draggedBlock); @@ -147,14 +186,40 @@ else if (blockSourcePanel == programArea) { } } + /** + * Return whether any block in the given list of gui blocks contains the point defined + * by the given x and y coordinate. + * + * @param blocks the given list of gui blocks + * @param x the given x-coordinate + * @param y the given y-coordinate + * + * @return whether any block in the given list of gui blocks contains the point. + */ private boolean AnyContains(List blocks, int x, int y) { return blocks.stream().anyMatch(b -> b.contains(x, y)); } + /** + * Checks if a given gui block is in a given collision rectangle panel. + * + * @param panel the given panel + * @param blocks the given gui block + * + * @return if the given gui block is in the given panel. + */ private boolean isInPanel(CollisionRectangle panel, List blocks) { return blocks.stream().allMatch(b -> b.isInside(panel)); } + /** + * Checks if a given list of guiblocks is in a given collision rectangle panel. + * + * @param panel the given panel + * @param blocks the given list of gui blocks + * + * @return if the given list of gui blocks is in the given panel. + */ private boolean isInPanelAny(CollisionRectangle panel, List blocks) { return blocks.stream().anyMatch(b -> b.isInside(panel)); } diff --git a/src/main/java/GUI/Components/GUIConnector.java b/src/main/java/GUI/Components/GUIConnector.java index b488977c..b2348d9f 100644 --- a/src/main/java/GUI/Components/GUIConnector.java +++ b/src/main/java/GUI/Components/GUIConnector.java @@ -4,7 +4,11 @@ import GUI.Blocks.GUIBlock; import java.awt.*; - +/** + * A class used as a GUI connector to connect GUI Blocks visually. + * + * @author Alpha-team + */ public class GUIConnector { /**