Add change color action

This commit is contained in:
2025-02-19 11:39:50 +01:00
parent aea90f5a93
commit 1b0284cb4d
2 changed files with 31 additions and 9 deletions

View File

@@ -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");