Base java event POC
This commit is contained in:
59
src/main/java/ovh/gasser/newshapes/ui/ShapeDraftman.java
Normal file
59
src/main/java/ovh/gasser/newshapes/ui/ShapeDraftman.java
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user