node.remove();
}
- public Rectangle2D imageBounds(IElement e) {
- Image i = getImage(e);
- return i.getBounds();
+ protected Rectangle2D imageBounds(IElement e, Rectangle2D size) {
+ Image i = getImage(e);
+ Rectangle2D r = i.getBounds();
+ if (r != null)
+ size.setFrame(r);
+ return r;
}
@Override
public Rectangle2D getBounds(IElement e, Rectangle2D size) {
+ if (size == null)
+ size = new Rectangle2D.Double();
+
+ ElementClass ec = e.getElementClass();
+ if (ec.containsClass(ConnectionHandler.class)) {
+ imageBounds(e, size);
+ } else {
+ IG2DNode node = e.getHint(getNodeKey());
+ Rectangle2D r = node != null ? node.getBoundsInLocal() : null;
+ if (r != null) {
+ size.setFrame(r);
+ } else {
+ imageBounds(e, size);
+ }
+ }
- if (size == null)
- size = new Rectangle2D.Double();
-
- ElementClass ec = e.getElementClass();
- if(ec.containsClass(ConnectionHandler.class)) {
- size.setFrame(imageBounds(e));
- } else {
- IG2DNode node = e.getHint(getNodeKey());
- if(node != null) {
- size.setFrame(node.getBoundsInLocal());
- } else {
- size.setFrame(imageBounds(e));
- }
- }
-
- return size;
-
+ return size;
}
@Override
@Override
public Shape getElementShape(IElement e) {
-
IG2DNode node = e.getHint(getNodeKey());
- if (node == null)
- throw new IllegalStateException();
- return node.getBoundsInLocal();
-
+ if (node != null) {
+ Rectangle2D bounds = node.getBoundsInLocal();
+ if (bounds != null)
+ return bounds;
+ }
+ // Fallback to old logic.
+ Image i = getImage(e);
+ return i.getOutline();
}
}
\ No newline at end of file