]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Use affine transform to move valve name below valve symbol, because node initial...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 8 Sep 2011 07:57:07 +0000 (07:57 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Thu, 8 Sep 2011 07:57:07 +0000 (07:57 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@22149 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/HoverTextElementNoBounds.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/ValveFactory.java

index 1495974b9de261108381f7a543369c0b3fa747f3..61a7a398541fc211f6f5f08055f9f6921e3d7e1b 100644 (file)
@@ -166,10 +166,11 @@ public class HoverTextElementNoBounds extends TextElementNoBounds {
                Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK);\r
                String text = ElementUtils.getText(e);\r
                AffineTransform at = ElementUtils.getTransform(e);\r
+        Alignment hAlign = ElementUtils.getHintOrDefault(e, ElementHints.KEY_HORIZONTAL_ALIGN, horizontalAlignment);\r
                node.init(text, font, color, originX, originY, 0.235);\r
                node.setBackgroundColor(fillColor);\r
                node.setBorderColor(borderColor);\r
-               node.setHorizontalAlignment((byte) horizontalAlignment.ordinal());\r
+        node.setHorizontalAlignment((byte) hAlign.ordinal());\r
                node.setPadding(paddingX, paddingY);\r
                node.setBorderWidth((float) borderWidth);\r
                node.setEditable(editable);\r
index 6293a91e133f3551f37846f39152c909336197d9..4824b40ee47ff6efd3ece959cbbb166a1b447ef4 100644 (file)
@@ -19,6 +19,7 @@ import java.awt.geom.Rectangle2D;
 import java.util.Collection;\r
 \r
 import org.simantics.db.Resource;\r
+import org.simantics.diagram.elements.TextNode;\r
 import org.simantics.g2d.element.ElementClass;\r
 import org.simantics.g2d.element.ElementHints;\r
 import org.simantics.g2d.element.ElementUtils;\r
@@ -112,7 +113,8 @@ public class ValveFactory extends SysdynElementFactory {
         private IHintListener hoverHintListener;\r
 \r
         public ValveSceneGraph() {\r
-            super(0, VALVE_SIZE + 3.0, Alignment.CENTER);\r
+//            super(0, VALVE_SIZE + 3.0, Alignment.CENTER); // Move with affine transformation in init()\r
+            super(0, 0, Alignment.CENTER);\r
         }\r
         @Override\r
         public void init(IElement e, G2DParentNode parent) {\r
@@ -128,9 +130,18 @@ public class ValveFactory extends SysdynElementFactory {
             Boolean hover = e.getHint(ElementHints.KEY_HOVER); \r
             node.setHover(hover != null ? hover : false);\r
 \r
-            if(at != null)\r
+            if(at != null) {\r
                 node.setTransform(at);\r
             \r
+                // Use affinetransform to move the name of the valve below the valve symbol\r
+                TextNode name = (TextNode) e.getHint(SG_NODE);\r
+                if(name != null) {\r
+                    AffineTransform at2 = (AffineTransform) at.clone();\r
+                    at2.translate(0, VALVE_SIZE + 3.0);\r
+                    name.setTransform(at2);\r
+                }\r
+            }\r
+\r
             hoverHintListener = new IHintListener() {\r
                 \r
                 @Override\r