Implement copy action

This commit is contained in:
2025-02-19 11:27:45 +01:00
parent b4eac668c8
commit aea90f5a93
8 changed files with 58 additions and 14 deletions

View File

@@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.stream.Collectors;
public class SCollection extends AbstractShape implements Streamable<Shape> {
private final static Logger logger = LoggerFactory.getLogger(SCollection.class);
@@ -43,6 +44,14 @@ public class SCollection extends AbstractShape implements Streamable<Shape> {
}
}
@Override
public Shape clone() {
var clonedChildren = children.stream().map(Shape::clone).toArray(Shape[]::new);
var collection = new SCollection(clonedChildren);
collection.addAttributes(new SelectionAttributes());
return collection;
}
@Override
public void setLoc(Point newLoc) {
final Point loc = getBounds().getLocation();
@@ -59,6 +68,10 @@ public class SCollection extends AbstractShape implements Streamable<Shape> {
return children.spliterator();
}
public void add(Shape s) {
children.add(s);
}
public void remove(Shape s) {
if (!children.remove(s)) {
logger.error("Unable to delete shape: {}", s);