Base java event POC
This commit is contained in:
51
src/main/java/ovh/gasser/newshapes/shapes/AbstractShape.java
Normal file
51
src/main/java/ovh/gasser/newshapes/shapes/AbstractShape.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package ovh.gasser.newshapes.shapes;
|
||||
|
||||
import ovh.gasser.newshapes.attributes.Attributes;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public abstract class AbstractShape implements Shape {
|
||||
|
||||
private Map<String, Attributes> attributes = new TreeMap<>();
|
||||
private Rectangle bounds;
|
||||
|
||||
AbstractShape() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
AbstractShape(Rectangle bounds) {
|
||||
this.bounds = bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Attributes getAttributes(String key) {
|
||||
return attributes.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttributes(Attributes attrs) {
|
||||
attributes.put(attrs.getID(), attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLoc(Point newLoc) {
|
||||
getBounds().setLocation(newLoc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(int dx, int dy) {
|
||||
getBounds().translate(dx, dy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getBounds() {
|
||||
return this.bounds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("x=%d, y=%d, width=%d, height=%d", bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user