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;
private Point2D mousePosition;
- private static AtomicReference<DistrictNetworkHoverInfoNode> activeNode = new AtomicReference<>();
+ private static AtomicReference<G2DParentNode> 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;
@Override
public void renderDeferred(Graphics2D g) {
+ if (!hover || activeNode.get() == null)
+ return;
AffineTransform ot = g.getTransform();
Font of = g.getFont();
doRender(g);
}
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();
@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;
}
@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();
+ }
+
}