X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2FDistrictPanZoomRotateHandler.java;h=ac0d22e3df34bb79b8ec17f07d44f25fb86d13ae;hb=440c2b11fd49be2feb9edd39b931306b824b8aba;hp=fecc17548e98c5f995eef4d912112c354007a5f0;hpb=cb2ebef6cbe572f646082952f57bb69135f308bd;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java index fecc1754..ac0d22e3 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/DistrictPanZoomRotateHandler.java @@ -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 getMapElements(Collection elements) { + List 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);