From 13798386471e68e750568edd823a9c3f1bda7378 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 13 Apr 2017 19:13:06 +0300 Subject: [PATCH] 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 (cherry picked from commit 477ce5a22d86916107b2c319f4d6cf84d639305a) --- .../adapter/DefinedElementHandler.java | 55 ++++++++++--------- 1 file changed, 30 insertions(+), 25 deletions(-) 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 -- 2.47.1