]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixed diagram NPE regressions caused by commit 5d2af6df 12/412/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 13 Apr 2017 16:13:06 +0000 (19:13 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 13 Apr 2017 16:13:06 +0000 (19:13 +0300)
The code was not taking into account that IG2DNode.getBoundsInLocal can
return null.

refs #7109

Change-Id: I9f41b9f2119ba8d273daf97b1b1e90a03d91fd22

bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/DefinedElementHandler.java

index b5cc293aca500079edda9823ec80b1c247686445..17f22cfcfae23d131531913ed526d9b1e5b84061 100644 (file)
@@ -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