Base java event POC

This commit is contained in:
2019-03-19 21:17:08 +01:00
parent 95cb82d419
commit 51885d8c53
16 changed files with 587 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
package ovh.gasser.newshapes.shapes;
import ovh.gasser.newshapes.App;
import ovh.gasser.newshapes.attributes.SelectionAttributes;
import ovh.gasser.newshapes.ShapeVisitor;
import ovh.gasser.newshapes.util.Streamable;
import java.awt.*;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
public class SCollection extends AbstractShape implements Streamable<Shape> {
private final List<Shape> children;
private SCollection(Shape... shapes) {
this.children = List.of(shapes);
}
@Override
public void accept(ShapeVisitor visitor) {
visitor.visitCollection(this);
}
@Override
public Rectangle getBounds() {
try {
Rectangle bounds = children.get(0).getBounds();
for (Shape s : children) bounds = bounds.union(s.getBounds());
return bounds;
} catch (IndexOutOfBoundsException e){
// If the SCollection is empty, set the bounds to fill the window
return new Rectangle(App.WIN_SIZE);
}
}
@Override
public void setLoc(Point newLoc) {
final Point loc = getBounds().getLocation();
children.forEach(s -> s.translate(newLoc.x - loc.x, newLoc.y - loc.y));
}
@Override
public Iterator<Shape> iterator() {
return children.iterator();
}
@Override
public Spliterator<Shape> spliterator() {
return children.spliterator();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("SCollection{");
children.forEach(obj -> sb.append(obj).append(", "));
return sb.append("}").toString();
}
public static SCollection of(Shape ...shapes) {
SCollection collection = new SCollection(shapes);
collection.addAttributes(new SelectionAttributes());
return collection;
}
}