]> gerrit.simantics Code Review - simantics/district.git/blobdiff - org.simantics.district.network.ui/src/org/simantics/district/network/ui/nodes/NetworkDrawingNode.java
Support copying of attributes from DN.MappedComponent
[simantics/district.git] / org.simantics.district.network.ui / src / org / simantics / district / network / ui / nodes / NetworkDrawingNode.java
index 524bf7221e42133f76b0644130760af8fd43842a..b94639e2311080c9881044f0228a4c06e14bbc6d 100644 (file)
@@ -55,8 +55,6 @@ public class NetworkDrawingNode extends G2DNode {
 
     private Resource diagramResource;
 
-    private boolean committed;
-
     private NetworkDrawingParticipant participant;
 
     private IDiagram diagram;
@@ -67,6 +65,7 @@ public class NetworkDrawingNode extends G2DNode {
             4.0f, new float[]{4.0f}, 0.0f);
 
     private static final Color BLUE_ALPHA = new Color(0, 0, 255, 100);
+    private static final Color RED_ALPHA = new Color(255, 0, 0, 100);
 
     private boolean scaleStroke = true;
     
@@ -123,8 +122,13 @@ public class NetworkDrawingNode extends G2DNode {
             }
             
             g2d.setColor(BLUE_ALPHA);
-
             g2d.draw(path);
+            
+            g2d.setColor(RED_ALPHA);
+            BasicStroke stroke = GeometryUtils.scaleStroke(DASHED_STROKE, (float) (1.0 / GeometryUtils.getScale(g2d.getTransform())));
+            g2d.setStroke(stroke);
+            Point2D currentPoint = path.getCurrentPoint();
+            g2d.draw(new Rectangle2D.Double(currentPoint.getX() - 0.0001 / 2, currentPoint.getY() - 0.0001 / 2, 0.0001, 0.0001));
         }
         
         g2d.setStroke(oldStroke);
@@ -232,10 +236,6 @@ public class NetworkDrawingNode extends G2DNode {
         // check ToolMode
         IToolMode mode = getToolMode();
         if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {
-            if (committed) {
-                committed = false;
-                return false;
-            }
             if (e.button == MouseEvent.RIGHT_BUTTON && !nodes.isEmpty()) {
                 nodes.remove(nodes.size() - 1);
             } else if (e.button == MouseEvent.LEFT_BUTTON) {
@@ -254,7 +254,6 @@ public class NetworkDrawingNode extends G2DNode {
                     }
                     currentRouteNode = null;
                     nodes.clear();
-                    committed = true;
                 } else if (currentRouteNode != null) {
                     currentRouteNode.routeNodes.add(new Point2D.Double(localPos.getX(), localPos.getY()));
                 }
@@ -276,22 +275,21 @@ public class NetworkDrawingNode extends G2DNode {
     @Override
     protected boolean mouseMoved(MouseMovedEvent e) {
         IToolMode mode = getToolMode();
-        if (mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK)) {
-            boolean repaint = false;
-            Point2D p = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());
-            if (participant.pickHoveredElement(p)) {
-                repaint = true;
-            }
-            if (!nodes.isEmpty()) {
-                currentMousePos = p;
-                
-                repaint();
-                return true;
-            }
-            currentMousePos = null;
-            if (repaint == true)
-                repaint();
+        boolean repaint = false;
+        Point2D p = NodeUtil.worldToLocal(this, e.controlPosition, new Point2D.Double());
+        boolean isConnectionTool = mode == Hints.CONNECTTOOL || e.hasAnyModifier(MouseEvent.ALT_MASK | MouseEvent.ALT_GRAPH_MASK);
+        if (participant.pickHoveredElement(p, isConnectionTool)) {
+            repaint = true;
+        }
+        if (!nodes.isEmpty()) {
+            currentMousePos = p;
+            
+            repaint();
+            return true;
         }
+        currentMousePos = null;
+        if (repaint == true)
+            repaint();
         return super.mouseMoved(e);
     }