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=07ad2eedb4df1decd66f4ac0e965a76a67d6039c;hb=refs%2Fchanges%2F72%2F3472%2F1;hp=7a75ad5f2e4382390f798ebc0ea38ea7c7614da5;hpb=4b71501bae63934eefa07dc5acf6fd9eb3dbd583;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 7a75ad5f..07ad2eed 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,9 +13,13 @@ import java.util.concurrent.atomic.AtomicReference; 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; import org.simantics.scenegraph.utils.NodeUtil; import org.simantics.scl.runtime.Lists; @@ -42,12 +46,10 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit private Point2D mousePosition; - private static AtomicReference activeNode = new AtomicReference<>(); + private static AtomicReference activeNode = new AtomicReference<>(); @Override public void render(Graphics2D g) { - if (!hover || activeNode.get() != this) - return; ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(this, RTreeNode.class); DeferredRenderingNode deferred = root != null ? (DeferredRenderingNode) root.getNode(DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED) : null; @@ -59,6 +61,8 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit @Override public void renderDeferred(Graphics2D g) { + if (!hover || activeNode.get() == null) + return; AffineTransform ot = g.getTransform(); Font of = g.getFont(); doRender(g); @@ -67,7 +71,10 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit } private void doRender(Graphics2D g) { - g.transform(MapScalingTransform.INVERSE); + AffineTransform tt = getTransform(); + g.transform(tt); + if (mousePosition == null) + return; g.translate(mousePosition.getX(), mousePosition.getY()); //g.translate(origin.getX(), origin.getY()); double scale = 1.5 / g.getTransform().getScaleX(); @@ -119,15 +126,15 @@ 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; +// 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(); - } - +// +// if (changed) { +// if (!hover) activeNode.updateAndGet(current -> current == this ? null : current); +// repaint(); +// } +// return changed; } @@ -139,6 +146,31 @@ public class DistrictNetworkHoverInfoNode extends G2DNode implements HoverSensit @Override public void delete() { super.delete(); - activeNode.getAndUpdate(current -> current == this ? null : current); + activeNode.set(null); } + + public void hover2(G2DParentNode hoveredNode) { + ParentNode root = (ParentNode) NodeUtil.getNearestParentOfType(parent, RTreeNode.class); + if (root != null) { + + INode child = ProfileVariables.browseChild(root, ""); + if(child == null) { + throw new NullPointerException("Scenegraph child node was not found: " + ""); + } + + INode existing = NodeUtil.getChildById(child, DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED); + if (existing == null) { + if (child instanceof ParentNode) { + existing = ((ParentNode) child).addNode(DistrictNetworkHoverInfoStyle.HOVER_INFO_DEFERRED, DeferredRenderingNode.class); + ((DeferredRenderingNode)existing).setZIndex(Integer.MAX_VALUE); + } else { + throw new NodeException("Cannot claim child node for non-parent-node " + child); + } + } + } + + activeNode.set(hoveredNode); + repaint(); + } + }