Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jxlle committed Mar 15, 2020
1 parent c3367de commit d28d8d9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
73 changes: 69 additions & 4 deletions src/main/java/GUI/Components/GUIBlockHandler.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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;
import java.util.ArrayList;
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;
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -66,6 +81,9 @@ private void handleMousePressed(int x, int y) {
}
}

/**
* todo
*/
private void handleMouseReleased() {

if (draggedBlock != null) {
Expand All @@ -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());
Expand All @@ -114,12 +143,15 @@ private void handleBlockFromPaletteToProgramArea() {
}
}

/**
* todo
*/
private void handleBlockFromProgramAreaToProgramArea() {

boolean connectionFound = false;
programArea.disconnectInProgramArea(draggedBlock);
draggedBlock.disconnectMainConnector();


for (GUIBlock block : draggedBlocks) {
Optional<GUIBlock> connectedBlock = programArea.getBlocks().stream().filter(b -> b.intersectsWithConnector(block)).findAny();

Expand All @@ -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);
Expand All @@ -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<GUIBlock> 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<GUIBlock> 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<GUIBlock> blocks) {
return blocks.stream().anyMatch(b -> b.isInside(panel));
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/GUI/Components/GUIConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down

0 comments on commit d28d8d9

Please sign in to comment.