]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16827 ac1ea38d-2e2b...
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Jul 2010 12:48:39 +0000 (12:48 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Jul 2010 12:48:39 +0000 (12:48 +0000)
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java

index b26509f92330a1f0bac54eb69d0c2649f0f6dfc6..0c205c38ceeb845a70f6a93cb81ce3cb2afae576 100644 (file)
@@ -5,13 +5,13 @@ import java.awt.Color;
 import java.awt.Font;\r
 import java.awt.Shape;\r
 import java.awt.geom.Path2D;\r
+import java.awt.geom.Rectangle2D;\r
 import java.util.Collection;\r
 \r
 import org.simantics.db.Builtins;\r
 import org.simantics.db.ReadGraph;\r
 import org.simantics.db.Resource;\r
 import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.diagram.elements.TextElementHandler;\r
 import org.simantics.diagram.elements.TextElementNoBounds;\r
 import org.simantics.diagram.elements.TextNode;\r
 import org.simantics.g2d.canvas.ICanvasContext;\r
@@ -20,6 +20,7 @@ import org.simantics.g2d.element.ElementClass;
 import org.simantics.g2d.element.ElementUtils;\r
 import org.simantics.g2d.element.IElement;\r
 import org.simantics.g2d.element.SceneGraphNodeKey;\r
+import org.simantics.g2d.element.handler.InternalSize;\r
 import org.simantics.g2d.element.handler.impl.BoundsOutline;\r
 import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
 import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
@@ -71,10 +72,8 @@ public class InputFactory extends SysdynElementFactory {
                 new StaticObjectAdapter(elementType),\r
                 new StaticSymbolImpl(INPUT_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
-                TextElementHandler.INSTANCE,\r
                 Input.INSTANCE,\r
-                new InputSceneGraph(0, 5, Alignment.CENTER),\r
-//                InputSceneGraph.INSTANCE,\r
+                new InputSceneGraph(0, 0, Alignment.CENTER),\r
                 BoundsOutline.INSTANCE,\r
                 new WholeElementTerminals(terminals)\r
         ).setId(InputFactory.class.getSimpleName());\r
@@ -112,7 +111,7 @@ public class InputFactory extends SysdynElementFactory {
     }\r
     \r
     \r
-    public static class InputSceneGraph extends TextElementNoBounds {\r
+    public static class InputSceneGraph extends TextElementNoBounds implements InternalSize {\r
 \r
         private static final long   serialVersionUID = -3713275157729126409L;\r
         public static final Key     SG_NODE          = new SceneGraphNodeKey(TextNode.class, "INPUT_SG_NODE");\r
@@ -121,15 +120,15 @@ public class InputFactory extends SysdynElementFactory {
         private final Alignment horizontalAlignment;\r
         \r
         public InputSceneGraph(double originX, double originY, Alignment horizontalAlignment) {\r
-            super(originX, originY, horizontalAlignment);\r
+            super(originX, originY, horizontalAlignment, 0, true);\r
             this.originX = originX;\r
             this.horizontalAlignment = horizontalAlignment;\r
         }\r
         \r
         @Override\r
         public void init(final IElement e, G2DParentNode parent) {\r
+            super.init(e, parent);\r
             TextNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, "input", TextNode.class);\r
-            //Font font = new Font("Tahoma", 0, 12);\r
             Font font = ElementUtils.getTextFont(e);\r
             font = font.deriveFont((float) 10.0);\r
             font = font.deriveFont(Font.ITALIC);\r
@@ -144,6 +143,19 @@ public class InputFactory extends SysdynElementFactory {
             node.setHorizontalAlignment((byte) horizontalAlignment.ordinal());\r
             node.setBorderWidth((float) 0);\r
             node.setEditable(false);\r
+            node.setShowSelection(false);\r
+        }\r
+\r
+        @Override\r
+        public Rectangle2D getBounds(IElement e, Rectangle2D size) {\r
+            TextNode node = (TextNode) e.getHint(SG_NODE);\r
+            if (size == null)\r
+                size = new Rectangle2D.Double();\r
+            if (node != null)\r
+                size.setRect(node.getBoundsInLocal());\r
+            else\r
+                size.setFrame(0, 0, 0, 0);\r
+            return size;\r
         }\r
     }\r
 }\r