]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java
Elimination of compiler warnings.
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / DistrictPanZoomRotateHandler.java
index fecc17548e98c5f995eef4d912112c354007a5f0..ac0d22e3df34bb79b8ec17f07d44f25fb86d13ae 100644 (file)
@@ -2,13 +2,15 @@ package org.simantics.district.network.ui;
 
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Rectangle2D;
+import java.util.Collection;
+import java.util.List;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.simantics.g2d.canvas.ICanvasContext;
 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
 import org.simantics.g2d.canvas.impl.DependencyReflection.Reference;
 import org.simantics.g2d.diagram.DiagramHints;
-import org.simantics.g2d.diagram.DiagramUtils;
 import org.simantics.g2d.diagram.IDiagram;
 import org.simantics.g2d.diagram.participant.Selection;
 import org.simantics.g2d.element.ElementUtils;
@@ -89,7 +91,7 @@ public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler {
         if (d == null)
             return false;
 
-        Rectangle2D diagramRect = DiagramUtils.getContentRect(d);
+        Rectangle2D diagramRect = ElementUtils.getSurroundingElementBoundsOnDiagram(getMapElements(d.getElements()));
         if (diagramRect == null)
             return false;
         if (diagramRect.isEmpty())
@@ -103,9 +105,15 @@ public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler {
         return true;
     }
 
+    protected static List<IElement> getMapElements(Collection<IElement> elements) {
+        List<IElement> justMapElements = elements.stream()
+                .filter(e -> "DistrictNetworkEdgeElement".equals(e.getElementClass().getId())
+                          || "DistrictNetworkVertexElement".equals(e.getElementClass().getId()))
+                .collect(Collectors.toList());
+        return justMapElements;
+    }
+
     private boolean zoomToPage() {
-        int currentZoomLevel = MapScalingTransform.zoomLevel(util.getTransform());
-        
         util.setTransform(new AffineTransform(2,0,0,2,270,270));
         return true;
     }
@@ -124,7 +132,7 @@ public class DistrictPanZoomRotateHandler extends PanZoomRotateHandler {
             // no can do, 
             return zoomToPage();
         }
-        Rectangle2D diagramRect = ElementUtils.getSurroundingElementBoundsOnDiagram(selections);
+        Rectangle2D diagramRect = ElementUtils.getSurroundingElementBoundsOnDiagram(getMapElements(selections));
         
         // Make sure that even empty bounds can be zoomed into.
         org.simantics.scenegraph.utils.GeometryUtils.expandRectangle(diagramRect, 1);