sync edit menu checkbox state with the selected shape

This commit is contained in:
2026-03-19 16:06:01 +01:00
parent ce6d0b0815
commit dd59c7d51a
8 changed files with 113 additions and 16 deletions

View File

@@ -4,14 +4,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ovh.gasser.newshapes.App;
import ovh.gasser.newshapes.ShapeVisitor;
import ovh.gasser.newshapes.attributes.Attributes;
import ovh.gasser.newshapes.attributes.ColorAttributes;
import ovh.gasser.newshapes.attributes.SelectionAttributes;
import ovh.gasser.newshapes.util.Streamable;
import javax.swing.text.html.Option;
import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.*;
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);
@@ -38,7 +39,7 @@ public class SCollection extends AbstractShape implements Streamable<Shape> {
for (Shape s : children) bounds = bounds.union(s.getBounds());
return bounds;
} catch (IndexOutOfBoundsException e){
logger.error("getBounds(): {}");
logger.error("getBounds(): {e}", e);
throw new RuntimeException(e);
}
}
@@ -76,6 +77,27 @@ public class SCollection extends AbstractShape implements Streamable<Shape> {
}
}
@Override
public Attributes getAttributes(String key) {
if (key.equals(ColorAttributes.ID)) {
// If the shape is a collection, it does not support color attributes directly
// For now, use the attributes from the first child shape
Optional<Shape> first = children.stream().findFirst();
return first.map(shape -> shape.getAttributes(key)).orElse(null);
}
return super.getAttributes(key);
}
@Override
public void addAttributes(Attributes attrs) {
// Propagate color attributes to children
if (attrs.getID().equals(ColorAttributes.ID)) {
children.forEach(shape -> shape.addAttributes(attrs));
}
super.addAttributes(attrs);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("SCollection{");