]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/DistrictNetworkEdgeNode.java
Add default mappings for right/left click & prevent edge drawing
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / DistrictNetworkEdgeNode.java
index 21f3d741e77d81755376faa7047b3762266d0a92..61aec5ce55cc8285ad64b8b8fafc67984bc3c463 100644 (file)
@@ -77,11 +77,11 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
         BasicStroke oldStroke = (BasicStroke) g2d.getStroke();
 
         BasicStroke bs = null;
+        double scale = 1.0;
         if (scaleStroke) {
-            double scale = GeometryUtils.getScale(g2d.getTransform());
-            scale = Math.max(10000, Math.min(scale, 50000));
-            double str = stroke != null ? Math.abs(stroke) : 1.0;
-            bs = GeometryUtils.scaleStroke(STROKE, (float) (str / scale));
+            AffineTransform tr = g2d.getTransform();
+            scale = DistrictNetworkNodeUtils.getScale(tr);
+            bs = GeometryUtils.scaleStroke(STROKE, getStrokeWidth(scale));
         } else {
             bs = STROKE;
         }
@@ -90,7 +90,7 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
 
         if (isSelected()) {
             g2d.setColor(SELECTION_COLOR);
-            g2d.setStroke(GeometryUtils.scaleStroke(bs, 4f));
+            g2d.setStroke(GeometryUtils.scaleAndOffsetStrokeWidth(bs, 1.f, (float)(2 * STROKE.getLineWidth() / scale)));
             g2d.draw(path);
         }
 
@@ -101,12 +101,13 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
         // Draw arrow
         if (arrowLength != null) {
             g2d.setColor(Color.BLACK);
-            g2d.setStroke(new BasicStroke(bs.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
+            float lw = STROKE.getLineWidth() / (float)scale;
+            g2d.setStroke(new BasicStroke(lw, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
             
             double l = arrowLength;
-            double w = 2 * (double) bs.getLineWidth() * Math.signum(l);
+            double w = 2 * (double) lw * Math.signum(l);
             if (Math.abs(w) > Math.abs(l)) w = l;
-            double offset = 2 * (double) bs.getLineWidth();
+            double offset = 2 * (double) lw;
             
             double centerX = (startX + endX) / 2, centerY = (startY + endY) / 2;
             double deltaX = endX - startX, deltaY = endY - startY;
@@ -136,8 +137,6 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
         // Render SVG symbol
         double viewScaleRecip = 10;
         if (scaleStroke) {
-            double scale = GeometryUtils.getScale(g2d.getTransform());
-            scale = Math.max(10000, Math.min(scale, 50000));
             viewScaleRecip /= scale;
         }
         
@@ -157,6 +156,28 @@ public class DistrictNetworkEdgeNode extends G2DParentNode implements ISelection
             g2d.setTransform(ot);
     }
 
+    public float getStrokeWidth(AffineTransform tr, boolean selection) {
+        double scale = DistrictNetworkNodeUtils.getScale(tr);
+        float width = STROKE.getLineWidth() * getStrokeWidth(scale);
+        if (selection) width = width + (float) (2 * STROKE.getLineWidth() / scale);
+        return width;
+    }
+    
+    private float getStrokeWidth(double scale) {
+        if (scaleStroke) {
+            double str = stroke != null ? Math.abs(stroke) : 1.0;
+            float strokeWidth = (float) (str / scale);
+            return strokeWidth;
+        }
+        else {
+            return 1.f;
+        }
+    }
+
+    public Path2D getPath() {
+        return path;
+    }
+    
     private Point2D getCenterPoint() {
         if (centerPoint == null)
             centerPoint = new Point2D.Double();