Add change color action

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

12
pom.xml
View File

@ -9,6 +9,18 @@
<maven.compiler.source>1.10</maven.compiler.source> <maven.compiler.source>1.10</maven.compiler.source>
<maven.compiler.target>1.10</maven.compiler.target> <maven.compiler.target>1.10</maven.compiler.target>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
<groupId>ovh.gasser</groupId> <groupId>ovh.gasser</groupId>
<artifactId>shapes</artifactId> <artifactId>shapes</artifactId>

View File

@ -3,9 +3,11 @@ package ovh.gasser.newshapes.ui;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ovh.gasser.newshapes.Selection; import ovh.gasser.newshapes.Selection;
import ovh.gasser.newshapes.attributes.ColorAttributes;
import ovh.gasser.newshapes.shapes.SCollection; import ovh.gasser.newshapes.shapes.SCollection;
import ovh.gasser.newshapes.shapes.Shape; import ovh.gasser.newshapes.shapes.Shape;
import java.awt.*;
import java.awt.event.KeyAdapter; import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -69,18 +71,26 @@ public class Controller {
private void handleKeyPressed(KeyEvent evt) { private void handleKeyPressed(KeyEvent evt) {
switch (evt.getKeyCode()) { switch (evt.getKeyCode()) {
case KeyEvent.VK_DELETE: case KeyEvent.VK_DELETE -> deleteSelected();
deleteSelected(); case KeyEvent.VK_C -> copySelection();
break; case KeyEvent.VK_A -> changeSelectionColor();
case KeyEvent.VK_C: default -> logger.warn("Pressed unhandled key: {}", evt.getKeyChar());
copySelection();
break;
default:
logger.warn("Pressed unhandled key: {}", evt.getKeyChar());
break;
} }
} }
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() { private void copySelection() {
if (selection == null) { if (selection == null) {
logger.debug("No selection to copy"); logger.debug("No selection to copy");