handle multiple selection with shift

This commit is contained in:
2025-02-19 13:44:23 +01:00
parent 5f0bcda8ba
commit 02dd84c1f4
6 changed files with 70 additions and 38 deletions

View File

@@ -2,23 +2,30 @@ package ovh.gasser.newshapes;
import ovh.gasser.newshapes.attributes.SelectionAttributes;
import ovh.gasser.newshapes.shapes.Shape;
import ovh.gasser.newshapes.util.Streamable;
public class Selection {
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
private final SelectionAttributes attributes;
public final Shape shape;
public class Selection implements Streamable<Shape> {
private final List<Shape> selectedShapes = new ArrayList<>();
public Selection(final Shape shape, boolean selected) {
this(shape);
attributes.selected = selected;
@Override
public Iterator<Shape> iterator() {
return selectedShapes.iterator();
}
private Selection(final Shape shape) {
attributes = (SelectionAttributes) shape.getAttributes(SelectionAttributes.ID);
this.shape = shape;
public void clear() {
for (Shape shape : selectedShapes) {
shape.addAttributes(new SelectionAttributes(false));
}
selectedShapes.clear();
}
public void unselect() {
attributes.selected = false;
public void add(Shape s) {
selectedShapes.add(s);
s.addAttributes(new SelectionAttributes(true));
}
}