]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
fixed the but with the connection updates when valve was moved
authorniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 08:48:06 +0000 (08:48 +0000)
committerniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 08:48:06 +0000 (08:48 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13757 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.h2d/src/org/simantics/h2d/element/Element.java
org.simantics.h2d/src/org/simantics/h2d/event/handler/MoveSelected.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/CloudElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/DependencyElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/FlowElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/RectangularElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/ValveElementOld.java

index e51faa650183f85e336d2b6ee286601181e0fbe8..05b2ecb225be50743aa63279aeb1a75cec5b59cb 100644 (file)
@@ -12,7 +12,7 @@ public abstract class Element implements IElement {
                return null;\r
        }\r
        \r
-       protected void update() {\r
+       protected void fireElementUpdated() {\r
                if(listener != null)\r
                        listener.elementUpdated(this);\r
        }\r
@@ -32,6 +32,5 @@ public abstract class Element implements IElement {
                if(listener != null)\r
                        listener.elementRemoved(this);\r
        }\r
-       \r
 \r
 }\r
index d55befc68139eadefd3661634af1e1b9d19badd5..be23005d77cd607be730cc378631efdc532bd106 100644 (file)
@@ -49,8 +49,11 @@ public class MoveSelected extends DragEventHandler {
        @Override\r
        protected void end(IDiagramEditor editor, DragEvent event) {\r
                for(IElement element : selection)\r
-                       if(element instanceof Movable)\r
+                       if(element instanceof Movable) {\r
+                           System.out.println("move");\r
                                ((Movable)element).move(deltaX, deltaY);\r
+                               System.out.println("move ok");\r
+                       }\r
                selection = null;\r
                editor.requestRepaint();\r
        }\r
index 97c974d1ed7a6e3507687ab171b013c9cc5e7e95..279feecf0d56cbf69dcb5d4c5462a7a30efb36d3 100644 (file)
@@ -42,7 +42,6 @@ public class CloudElement extends RectangularElement implements Connectable {
                cloudNode.remove();\r
        }\r
        \r
-       @Override\r
        protected void update() {\r
                //bounds.setFrame(posX-CLOUD_SIZE_X, posY-CLOUD_SIZE_Y, 2.0*CLOUD_SIZE_X, 2.0*CLOUD_SIZE_Y);\r
                Path2D path = new Path2D.Double();      \r
@@ -62,7 +61,7 @@ public class CloudElement extends RectangularElement implements Connectable {
                }\r
                cloudNode.setShape(path);\r
                bounds = path.getBounds2D();\r
-           super.update();\r
+           fireElementUpdated();\r
        }\r
 \r
        public boolean isRotated() {\r
index ca449e7a6d71dc3192024864a3380e374c79abf2..41efa59fa7c87f9583472e4c3c0d3dd01917beb4 100644 (file)
@@ -96,6 +96,7 @@ public class DependencyElement extends Element implements IElementListener {
     }\r
        \r
        protected void updateSceneGraph() {\r
+           System.out.println("update");\r
                double x0 = tail.getOrigo().getX();\r
         double y0 = tail.getOrigo().getY();\r
         double x1 = head.getOrigo().getX();\r
@@ -114,9 +115,11 @@ public class DependencyElement extends Element implements IElementListener {
         r = Math.sqrt(dx0*dx0 + dy0*dy0);\r
         Rectangle2D bounds = new Rectangle2D.Double();\r
         tail.getBounds(bounds);\r
+        System.out.println("tail: " + bounds);\r
         angle0 = Arcs.nextIntersectingAngle(cx, cy, r, \r
             Math.atan2(-dy0, dx0), bounds, angle < 0.0);\r
         head.getBounds(bounds);\r
+        System.out.println("head: " + bounds);\r
         angle1 = Arcs.nextIntersectingAngle(cx, cy, r, \r
             Math.atan2(-dy1, dx1), bounds, angle > 0.0);\r
         double extent = angle1-angle0;\r
@@ -148,7 +151,7 @@ public class DependencyElement extends Element implements IElementListener {
        public void update() {\r
                if(arcNode != null)\r
                        updateSceneGraph();\r
-               super.update();\r
+               fireElementUpdated();\r
        }\r
                \r
        @Override\r
index 4e93b7fbf47fdddef74cc2b61757814d599045fc..4501e6fbcae462d360dd5a3ca840980d02376590 100644 (file)
@@ -205,7 +205,7 @@ public class FlowElement extends Element implements IElementListener {
     public void update() {\r
         if(lineNode1 != null)\r
             updateSceneGraph();\r
-        super.update();\r
+        fireElementUpdated();\r
     }\r
 \r
     @Override\r
index c2d4a2ad8903f0fa16d89015c82c8a1ec0bc42df..af7c0ba4b830497babca441d1efb7c053e2e0fdf 100644 (file)
@@ -34,6 +34,8 @@ public abstract class RectangularElement extends Element implements Movable {
                return bounds.intersects(x-tolerance, y-tolerance, 2.0*tolerance, 2.0*tolerance);\r
        }       \r
        \r
+       protected abstract void update();\r
+       \r
        @Override\r
        public void move(double deltaX, double deltaY) {\r
                posX += deltaX;\r
index 915b5656ebdef5d7b014b3250bf6c7d05b0db75e..860091f8f2ae0e15f48bb8587af72dca703205a6 100644 (file)
@@ -73,29 +73,31 @@ public class TextElement extends RectangularElement implements Movable, Connecta
                update();\r
        }\r
        \r
-       @Override\r
-       protected void update() {\r
-               Rectangle2D textBounds = FONT.getStringBounds(label, FRC);\r
-               textBounds.setFrame(\r
-                               textBounds.getX()*FONT_SCALE,\r
-                               textBounds.getY()*FONT_SCALE,\r
-                               textBounds.getWidth()*FONT_SCALE,\r
-                               textBounds.getHeight()*FONT_SCALE\r
-                               );\r
-               \r
-               textX = posX+getTextDeltaX()-textBounds.getCenterX();\r
-               textY = posY+getTextDeltaY()-textBounds.getCenterY();\r
-               bounds.setFrame(\r
-                               posX+getTextDeltaX()-textBounds.getWidth()*0.5-XPADDING,\r
-                               posY+getTextDeltaY()-textBounds.getHeight()*0.5-YPADDING,\r
-                               textBounds.getWidth()+XPADDING*2,\r
-                               textBounds.getHeight()+YPADDING*2\r
-                               );              \r
+       protected void updateText() {\r
+           Rectangle2D textBounds = FONT.getStringBounds(label, FRC);\r
+        textBounds.setFrame(\r
+                textBounds.getX()*FONT_SCALE,\r
+                textBounds.getY()*FONT_SCALE,\r
+                textBounds.getWidth()*FONT_SCALE,\r
+                textBounds.getHeight()*FONT_SCALE\r
+                );\r
+        \r
+        textX = posX+getTextDeltaX()-textBounds.getCenterX();\r
+        textY = posY+getTextDeltaY()-textBounds.getCenterY();\r
+        bounds.setFrame(\r
+                posX+getTextDeltaX()-textBounds.getWidth()*0.5-XPADDING,\r
+                posY+getTextDeltaY()-textBounds.getHeight()*0.5-YPADDING,\r
+                textBounds.getWidth()+XPADDING*2,\r
+                textBounds.getHeight()+YPADDING*2\r
+                );      \r
+    \r
+        if(textNode != null)\r
+            textNode.init(label, FONT, Color.BLACK, textX, textY, FONT_SCALE);\r
+       }\r
        \r
-               if(textNode != null)\r
-                       textNode.init(label, FONT, Color.BLACK, textX, textY, FONT_SCALE);\r
-               \r
-               super.update();\r
+       protected void update() {\r
+               updateText();           \r
+               fireElementUpdated();\r
        }\r
 \r
        class TextEditingAction implements IAction, ITextListener {\r
index ad3a4cd2fc3a43389853242aa6646c824aa48560..6cf57f6f1c14e5da585a05dfdbe37b9fb4ff9ea0 100644 (file)
@@ -61,8 +61,9 @@ public class ValveElement extends TextElement implements Rotatable {
                path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE);\r
                path.closePath();\r
                valveNode.setShape(path);\r
-           super.update();\r
+               updateText();\r
            bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
+           fireElementUpdated();\r
        }\r
 \r
        @Override\r
index e70e1b1b02c556966606555779601fb50a82c5f5..7b33b5ca2e605c98bb2c3e5cdfc7572bf4b4afdd 100644 (file)
@@ -40,7 +40,6 @@ public class ValveElementOld extends RectangularElement implements Connectable,
                valveNode.remove();\r
        }\r
        \r
-       @Override\r
        protected void update() {\r
                bounds.setFrame(posX-VALVE_SIZE, posY-VALVE_SIZE, 2.0*VALVE_SIZE, 2.0*VALVE_SIZE);\r
                Path2D path = new Path2D.Double();\r
@@ -56,7 +55,7 @@ public class ValveElementOld extends RectangularElement implements Connectable,
                path.lineTo(posX+VALVE_SIZE, posY+VALVE_SIZE);\r
                path.closePath();\r
                valveNode.setShape(path);\r
-           super.update();\r
+           fireElementUpdated();\r
        }\r
 \r
        @Override\r