From: Tuukka Lehtonen Date: Fri, 29 Nov 2019 19:17:55 +0000 (+0200) Subject: Fixed vertex hover after previous commit X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=7e17143c72db32ba32f67f735d2394156589557d;p=simantics%2Fdistrict.git Fixed vertex hover after previous commit Amendment to 86d471d96d6bc11bf7629113e57c6d9a9916e608 gitlab #44 Change-Id: Id8412c69303721b619262fe7977f2805ae22dfbb (cherry picked from commit 6218654d0a683aed2fec569dea2ecb89e395c7be) --- diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java index 1639d571..76151a83 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java @@ -179,6 +179,10 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti updateBounds(); } + public DistrictNetworkVertex getVertex() { + return vertex; + } + @Override public boolean hover(boolean hover, boolean isConnectionTool) { // Only react to hover when the connection tool is active diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java index 9fbb8a29..d1a81088 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/participants/DynamicVisualisationContributionsParticipant.java @@ -173,7 +173,7 @@ public class DynamicVisualisationContributionsParticipant extends AbstractCanvas StyleResult results = DistrictNetworkHoverInfoStyle.doCalculateStyleResult(graph, runtimeDiagram, mapElement); if (results != null) { - Point2D location = DistrictNetworkHoverInfoStyle.calculatePoint(hoveredNode, zoomLevel); + Point2D location = DistrictNetworkHoverInfoStyle.calculatePoint(hoveredNode, zoomLevel, null); thread.asyncExec(() -> { if (isRemoved()) return; diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java index ced9b9b5..ffc303a9 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/styles/DistrictNetworkHoverInfoStyle.java @@ -1,7 +1,6 @@ package org.simantics.district.network.ui.styles; import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; import java.util.Collections; import java.util.List; @@ -124,14 +123,17 @@ public class DistrictNetworkHoverInfoStyle { return point; } - public static Point2D calculatePoint(INode node, int zoomLevel) { + public static Point2D calculatePoint(INode node, int zoomLevel, Point2D result) { if (node instanceof DistrictNetworkVertexNode) { DistrictNetworkVertexNode vertex = (DistrictNetworkVertexNode) node; - Rectangle2D b = vertex.getBounds(); - return new Point2D.Double(b.getCenterX(), b.getCenterY()); + return DistrictNetworkNodeUtils.calculatePoint2D(vertex.getVertex().getPoint(), result); } else if (node instanceof DistrictNetworkEdgeNode) { DistrictNetworkEdgeNode edge = (DistrictNetworkEdgeNode) node; - return (Point2D) edge.getCenterPoint(zoomLevel).clone(); + Point2D cp = edge.getCenterPoint(zoomLevel); + if (result == null) + result = new Point2D.Double(); + result.setLocation(cp); + return result; } return null; }