From 6218654d0a683aed2fec569dea2ecb89e395c7be Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Fri, 29 Nov 2019 21:17:55 +0200 Subject: [PATCH] Fixed vertex hover after previous commit Amendment to 86d471d96d6bc11bf7629113e57c6d9a9916e608 gitlab #44 Change-Id: Id8412c69303721b619262fe7977f2805ae22dfbb --- .../network/ui/nodes/DistrictNetworkVertexNode.java | 4 ++++ ...DynamicVisualisationContributionsParticipant.java | 2 +- .../ui/styles/DistrictNetworkHoverInfoStyle.java | 12 +++++++----- 3 files changed, 12 insertions(+), 6 deletions(-) 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 bdb0b731..31332ec6 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; } -- 2.47.1