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;
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 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
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();
@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;
}
activeNode.set(null);
}
- public void hover2(G2DParentNode hoveredNode) {
+ public void setHoveredNode(INode hoveredNode) {
ParentNode<?> root = (ParentNode<?>) NodeUtil.getNearestParentOfType(parent, RTreeNode.class);
if (root != null) {
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);