diff --git a/pom.xml b/pom.xml index 7e08e84..17a30b9 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,18 @@ 1.10 1.10 + + + + org.apache.maven.plugins + maven-compiler-plugin + + 16 + 16 + + + + ovh.gasser shapes diff --git a/src/main/java/ovh/gasser/newshapes/ui/Controller.java b/src/main/java/ovh/gasser/newshapes/ui/Controller.java index 6c49c51..a7cc8f1 100644 --- a/src/main/java/ovh/gasser/newshapes/ui/Controller.java +++ b/src/main/java/ovh/gasser/newshapes/ui/Controller.java @@ -3,9 +3,11 @@ package ovh.gasser.newshapes.ui; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ovh.gasser.newshapes.Selection; +import ovh.gasser.newshapes.attributes.ColorAttributes; import ovh.gasser.newshapes.shapes.SCollection; import ovh.gasser.newshapes.shapes.Shape; +import java.awt.*; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@ -69,18 +71,26 @@ public class Controller { private void handleKeyPressed(KeyEvent evt) { switch (evt.getKeyCode()) { - case KeyEvent.VK_DELETE: - deleteSelected(); - break; - case KeyEvent.VK_C: - copySelection(); - break; - default: - logger.warn("Pressed unhandled key: {}", evt.getKeyChar()); - break; + case KeyEvent.VK_DELETE -> deleteSelected(); + case KeyEvent.VK_C -> copySelection(); + case KeyEvent.VK_A -> changeSelectionColor(); + default -> logger.warn("Pressed unhandled key: {}", evt.getKeyChar()); } } + private void changeSelectionColor(){ + if (selection == null) { + logger.debug("No selection to change color of"); + return; + } + if (selection.shape instanceof SCollection collection) { + collection.forEach(shape -> shape.addAttributes(new ColorAttributes(false, true, Color.BLACK, new Color((int) (Math.random() * 0x1000000))))); + } else { + selection.shape.addAttributes(new ColorAttributes(false, true, Color.BLACK, new Color((int) (Math.random() * 0x1000000)))); + } + view.repaint(); + } + private void copySelection() { if (selection == null) { logger.debug("No selection to copy");