X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.network.ui%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Fnetwork%2Fui%2Fnodes%2FDistrictNetworkHoverInfoNode.java;h=0ccd12f4152938f5f39a14c931c76e106fb79fbd;hb=HEAD;hp=24b7f5898c0dd0a06970ce1b28147c1b623120d2;hpb=900f0e33431c1e3ea7d94d73cbf4d21f533dac26;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java index 24b7f589..0ccd12f4 100644 --- a/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java +++ b/org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java @@ -13,13 +13,10 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicReference; import java.util.function.ToIntFunction; -import org.simantics.district.network.ui.styles.DistrictNetworkHoverInfoStyle; -import org.simantics.maps.MapScalingTransform; import org.simantics.scenegraph.INode; import org.simantics.scenegraph.NodeException; import org.simantics.scenegraph.ParentNode; import org.simantics.scenegraph.g2d.G2DNode; -import org.simantics.scenegraph.g2d.G2DParentNode; import org.simantics.scenegraph.g2d.nodes.spatial.RTreeNode; import org.simantics.scenegraph.profile.common.ProfileVariables; import org.simantics.scenegraph.utils.DPIUtil; @@ -32,16 +29,15 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit private static final long serialVersionUID = 1L; + private static final String HOVER_INFO_DEFERRED = "hoverInfo"; + public static final String NODE_KEY = "DISTRICT_NETWORK_HOVER_INFO"; private static final int PAD = 15; private List labels; - private Font font = new Font( - Font.SANS_SERIF, - Font.PLAIN, - (int)(DPIUtil.upscale(9) * MapScalingTransform.getScaleY() + 0.5)); + private Font font = new Font(Font.SANS_SERIF, Font.PLAIN, DPIUtil.upscale(14)); @SuppressWarnings("unused") private Point2D origin; @@ -55,12 +51,12 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit */ private Rectangle2D bgRect = new Rectangle2D.Double(); - private static AtomicReference activeNode = new AtomicReference<>(); + private static AtomicReference activeNode = new AtomicReference<>(); @Override public void render(Graphics2D g) { ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(this, RTreeNode.class); - DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED) : null; + DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(HOVER_INFO_DEFERRED) : null; if (deferred != null) deferred.deferNode(g.getTransform(), this); else @@ -71,7 +67,7 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit public void renderDeferred(Graphics2D g) { if (!hover || activeNode.get() == null) return; - if (labels.isEmpty() || mousePosition == null) + if (labels == null || labels.isEmpty() || mousePosition == null) return; AffineTransform ot = g.getTransform(); Font of = g.getFont(); @@ -90,9 +86,8 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit g.translate(mousePosition.getX(), mousePosition.getY()); //g.translate(origin.getX(), origin.getY()); - double scale = DPIUtil.upscale( 1.25 / GeometryUtils.getScale(g.getTransform()) ); + double scale = 1.0 / GeometryUtils.getScale(g.getTransform()); g.scale(scale, scale); - g.setFont(font); FontMetrics fm = g.getFontMetrics(); @@ -203,15 +198,8 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit @Override public boolean hover(boolean hover, boolean isConnectionTool) { -// hover = hover && activeNode.updateAndGet(current -> current == null ? this : current) == this; boolean changed = hover != this.hover; this.hover = hover; - -// if (changed) { -// if (!hover) activeNode.updateAndGet(current -> current == this ? null : current); -// repaint(); -// } - return changed; } @@ -226,7 +214,7 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit activeNode.set(null); } - public void hover2(G2DParentNode hoveredNode) { + public void setHoveredNode(INode hoveredNode) { ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(parent, RTreeNode.class); if (root != null) { @@ -235,10 +223,10 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit throw new NullPointerException("Scenegraph child node was not found: " + ""); } - INode existing = NodeUtil.getChildById(child, DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED); + INode existing = NodeUtil.getChildById(child, HOVER_INFO_DEFERRED); if (existing == null) { if (child instanceof ParentNode) { - existing = ((ParentNode) child).addNode(DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED, DeferredRenderingNode.class); + existing = ((ParentNode) child).addNode(HOVER_INFO_DEFERRED, DeferredRenderingNode.class); ((DeferredRenderingNode)existing).setZIndex(Integer.MAX_VALUE); } else { throw new NodeException("Cannot claim child node for non-parent-node " + child);