Add delete shape operation

This commit is contained in:
2025-02-19 10:50:27 +01:00
parent 98b05e435e
commit b4eac668c8
5 changed files with 48 additions and 8 deletions

View File

@@ -8,8 +8,8 @@ import java.util.TreeMap;
public abstract class AbstractShape implements Shape {
private Map<String, Attributes> attributes = new TreeMap<>();
private Rectangle bounds;
private final Map<String, Attributes> attributes = new TreeMap<>();
private final Rectangle bounds;
AbstractShape() {
this(null);

View File

@@ -8,16 +8,17 @@ import ovh.gasser.newshapes.attributes.SelectionAttributes;
import ovh.gasser.newshapes.util.Streamable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
public class SCollection extends AbstractShape implements Streamable<Shape> {
private final static Logger logger = LoggerFactory.getLogger(SCollection.class);
private final List<Shape> children;
private List<Shape> children;
private SCollection(Shape... shapes) {
this.children = List.of(shapes);
this.children = new ArrayList<>(List.of(shapes));
}
@Override
@@ -58,6 +59,12 @@ public class SCollection extends AbstractShape implements Streamable<Shape> {
return children.spliterator();
}
public void remove(Shape s) {
if (!children.remove(s)) {
logger.error("Unable to delete shape: {}", s);
}
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("SCollection{");