From: Tuukka Lehtonen Date: Thu, 13 Apr 2017 16:13:06 +0000 (+0300) Subject: Fixed diagram NPE regressions caused by commit 5d2af6df X-Git-Tag: v1.29.0~110 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F12%2F412%2F1;p=simantics%2Fplatform.git Fixed diagram NPE regressions caused by commit 5d2af6df The code was not taking into account that IG2DNode.getBoundsInLocal can return null. refs #7109 Change-Id: I9f41b9f2119ba8d273daf97b1b1e90a03d91fd22 --- diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementHandler.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementHandler.java index b5cc293ac..17f22cfcf 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementHandler.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementHandler.java @@ -60,31 +60,33 @@ public class DefinedElementHandler implements SceneGraph, InternalSize, Resize, 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 @@ -112,12 +114,15 @@ public class DefinedElementHandler implements SceneGraph, InternalSize, Resize, @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