]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkVertexNode.java
Hover label profile for district elements.
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkVertexNode.java
index 929ad9353ebd72d87b37b41d02e2373e639fc8d2..0533e3117bf38b32a4f94191139fe55d8876e148 100644 (file)
@@ -9,30 +9,32 @@ import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 
 import org.simantics.district.network.ui.adapters.DistrictNetworkVertex;
+import org.simantics.maps.MapScalingTransform;
 import org.simantics.scenegraph.INode;
 import org.simantics.scenegraph.ISelectionPainterNode;
 import org.simantics.scenegraph.g2d.G2DNode;
 import org.simantics.scenegraph.g2d.G2DParentNode;
+import org.simantics.scenegraph.g2d.IG2DNode;
 import org.simantics.scenegraph.g2d.nodes.SVGNode;
 import org.simantics.scenegraph.utils.GeometryUtils;
 import org.simantics.scenegraph.utils.NodeUtil;
 
-public class DistrictNetworkVertexNode extends G2DParentNode implements ISelectionPainterNode {
+public class DistrictNetworkVertexNode extends G2DParentNode implements ISelectionPainterNode, HoverSensitiveNode {
 
     //private static final Logger LOGGER = LoggerFactory.getLogger(DistrictNetworkVertexNode.class);
 
     private static final long serialVersionUID = -2641639101400236719L;
 
-    private static final double left = -0.00005;
+    private static final double left = -15;
     private static final double top = left;
-    public static final double width = 0.0001;
+    public static final double width = 30;
     private static final double height = width;
 
     private static final BasicStroke STROKE           = new BasicStroke((float)width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
     private static final Color       SELECTION_COLOR  = new Color(255, 0, 255, 96);
 
     private static final Rectangle2D NORMAL = new Rectangle2D.Double(left, top, width, height);
-    private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 3, top * 3, width * 3, height * 3);
+    private static final Rectangle2D HOVERED = new Rectangle2D.Double(left * 2, top * 2, width * 2, height * 2);
 
     private DistrictNetworkVertex vertex;
 
@@ -47,7 +49,7 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
     private transient Rectangle2D rect;
     private transient AffineTransform symbolTransform;
 
-    private double nodeSize = 3;
+    private double nodeSize = 1.0;
 
     @Override
     public void init() {
@@ -90,7 +92,7 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
         if (NodeUtil.isSelected(this, 1)) {
             changeColor = true;
             g2d.setColor(SELECTION_COLOR);
-            BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float) (viewScaleRecip * nodeSize));
+            BasicStroke ss = GeometryUtils.scaleStroke(STROKE, (float)viewScaleRecip);
             g2d.setStroke(ss);
             g2d.draw(toDraw);
         }
@@ -127,6 +129,7 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
 
     @Override
     public Rectangle2D getBoundsInLocal() {
+        updateBounds();
         return bounds;
     }
 
@@ -151,12 +154,17 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
 
     private Rectangle2D calculateBounds(Rectangle2D rect) {
         Point2D calcPoint = DistrictNetworkNodeUtils.calculatePoint2D(vertex.getPoint(), point);
-        AffineTransform at = getTransform();
+        AffineTransform at = NodeUtil.getLocalToGlobalTransform(this);
+        at.concatenate(MapScalingTransform.INSTANCE);
         double x = calcPoint.getX();
         double y = calcPoint.getY();
-        double widthh = width / at.getScaleX();
-        double heighth = height / at.getScaleY();
-        return new Rectangle2D.Double(x - widthh, y - heighth, widthh * 2, heighth * 2).getBounds2D();
+        double scaleRecip = DistrictNetworkNodeUtils.calculateScaleRecip(at);
+        double widthh = width * scaleRecip * nodeSize;
+        double heighth = height * scaleRecip * nodeSize;
+        if (rect == null)
+            rect = new Rectangle2D.Double();
+        rect.setRect(x - widthh/2, y - heighth/2, widthh, heighth);
+        return rect;
     }
 
     public void setVertex(DistrictNetworkVertex vertex) {
@@ -164,14 +172,18 @@ public class DistrictNetworkVertexNode extends G2DParentNode implements ISelecti
         updateBounds();
     }
 
-    public boolean hover(boolean hover) {
-//        if (hover && LOGGER.isDebugEnabled())
-//            LOGGER.debug("Hovering " + this);
-        boolean changed = false;
-        if (this.hover != hover) {
-            this.hover = hover;
-            changed = true;
+    @Override
+    public boolean hover(boolean hover, boolean isConnectionTool) {
+        // Only react to hover when the connection tool is active
+        boolean doHover = hover && isConnectionTool;
+        boolean changed = this.hover != doHover;
+        this.hover = doHover;
+        
+        for (IG2DNode child : getNodes()) {
+            if (child instanceof HoverSensitiveNode)
+                changed = ((HoverSensitiveNode)child).hover(hover, isConnectionTool) || changed;
         }
+        
         return changed;
     }