]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkHoverInfoNode.java
Usability fixes for district network node hover info showing
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkHoverInfoNode.java
index 316370bd2911042683593fb0a1950825517c5859..0ccd12f4152938f5f39a14c931c76e106fb79fbd 100644 (file)
@@ -13,12 +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.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;
@@ -31,6 +29,8 @@ 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;
@@ -51,12 +51,12 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit
      */
     private Rectangle2D bgRect = new Rectangle2D.Double();
 
-    private static AtomicReference<G2DParentNode> activeNode = new AtomicReference<>();
+    private static AtomicReference<INode> 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
@@ -198,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;
     }
 
@@ -221,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) {
 
@@ -230,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);