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,59 @@
package ovh.gasser.newshapes.ui;
import ovh.gasser.newshapes.ShapeVisitor;
import ovh.gasser.newshapes.shapes.Shape;
import ovh.gasser.newshapes.attributes.ColorAttributes;
import ovh.gasser.newshapes.attributes.SelectionAttributes;
import ovh.gasser.newshapes.shapes.SCollection;
import ovh.gasser.newshapes.shapes.SRectangle;
import java.awt.*;
public class ShapeDraftman implements ShapeVisitor {
private static final ColorAttributes DEFAULT_COLOR_ATTRIBUTES =
new ColorAttributes(false, true, Color.BLACK, Color.BLACK);
private Graphics2D g2d;
public ShapeDraftman(Graphics graph) {
this.g2d = (Graphics2D) graph;
}
@Override
public void visitRectangle(SRectangle rect) {
Rectangle r = rect.getBounds();
ColorAttributes colAttrs = (ColorAttributes) rect.getAttributes(ColorAttributes.ID);
if (colAttrs == null){
colAttrs = DEFAULT_COLOR_ATTRIBUTES;
}
if (colAttrs.filled) {
this.g2d.setColor(colAttrs.filledColor);
this.g2d.fillRect(r.x, r.y, r.width, r.height);
}
if (colAttrs.stroked) {
this.g2d.setColor(colAttrs.strokedColor);
this.g2d.drawRect(r.x, r.y, r.width, r.height);
}
drawHandlerIfSelected(rect);
}
@Override
public void visitCollection(SCollection collection) {
for (Shape s: collection) {
s.accept(this);
}
drawHandlerIfSelected(collection);
}
private void drawHandlerIfSelected(Shape s) {
SelectionAttributes selAttrs = (SelectionAttributes) s.getAttributes(SelectionAttributes.ID);
if ((selAttrs != null) && (selAttrs.selected)){
Rectangle bounds = s.getBounds();
this.g2d.setColor(Color.RED);
this.g2d.drawRect(bounds.x - 5, bounds.y - 5, 5, 5);
this.g2d.drawRect(bounds.x + bounds.width, bounds.y + bounds.height, 5, 5);
}
}
}