]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Input nodes with reference text
authorlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Jul 2010 11:23:51 +0000 (11:23 +0000)
committerlempinen <lempinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 26 Jul 2010 11:23:51 +0000 (11:23 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16826 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java [new file with mode: 0644]
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java
org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java

diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java
new file mode 100644 (file)
index 0000000..60f9a4c
--- /dev/null
@@ -0,0 +1,25 @@
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import org.simantics.g2d.element.IElement;\r
+import org.simantics.g2d.element.handler.ElementHandler;\r
+\r
+public class Input implements ElementHandler {\r
+\r
+    private static final long serialVersionUID = -1526125969376635502L;\r
+    \r
+    public static final Input INSTANCE = new Input();\r
+    \r
+    public String getInputReference(IElement e) {\r
+        return e.getHint(SysdynElementHints.KEY_INPUT_REFERENCE);\r
+    }\r
+\r
+    \r
+    public void setInputReference(IElement e, String inputReference) {\r
+        if (inputReference != null)\r
+            e.setHint(SysdynElementHints.KEY_INPUT_REFERENCE, inputReference);\r
+        else\r
+            e.removeHint(SysdynElementHints.KEY_INPUT_REFERENCE);\r
+    }\r
+    \r
+\r
+}\r
index e266bf224ccc665757d13b4bf2beef711acc9897..b26509f92330a1f0bac54eb69d0c2649f0f6dfc6 100644 (file)
@@ -1,13 +1,25 @@
 package org.simantics.sysdyn.ui.elements2;\r
 \r
 import java.awt.BasicStroke;\r
+import java.awt.Color;\r
+import java.awt.Font;\r
 import java.awt.Shape;\r
 import java.awt.geom.Path2D;\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
+import org.simantics.g2d.diagram.IDiagram;\r
 import org.simantics.g2d.element.ElementClass;\r
+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.impl.BoundsOutline;\r
 import org.simantics.g2d.element.handler.impl.DefaultTransform;\r
 import org.simantics.g2d.element.handler.impl.ObjectTerminal;\r
@@ -21,11 +33,16 @@ import org.simantics.g2d.element.handler.impl.TextFontImpl;
 import org.simantics.g2d.element.handler.impl.TextImpl;\r
 import org.simantics.g2d.image.Image;\r
 import org.simantics.g2d.image.impl.ShapeImage;\r
+import org.simantics.g2d.utils.Alignment;\r
+import org.simantics.modeling.ModelingResources;\r
+import org.simantics.scenegraph.g2d.G2DParentNode;\r
+import org.simantics.sysdyn.SysdynResource;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
 \r
 public class InputFactory extends SysdynElementFactory {\r
 \r
-    private static final BasicStroke    STROKE           = new BasicStroke(1f);\r
-    private static final Image       INPUT_IMAGE = new ShapeImage(getInputShape(), null, STROKE, true);\r
+    private static final BasicStroke    STROKE          = new BasicStroke(1f);\r
+    private static final Image          INPUT_IMAGE     = new ShapeImage(getInputShape(), null, STROKE, true);\r
 \r
     static Shape getInputShape() {\r
         Path2D path = new Path2D.Double();\r
@@ -41,6 +58,7 @@ public class InputFactory extends SysdynElementFactory {
         path.closePath();\r
         return path;\r
     }\r
+    \r
     @Override\r
     protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
         return ElementClass.compile(\r
@@ -54,10 +72,78 @@ public class InputFactory extends SysdynElementFactory {
                 new StaticSymbolImpl(INPUT_IMAGE),\r
                 StaticSymbolImageInitializer.INSTANCE,\r
                 TextElementHandler.INSTANCE,\r
+                Input.INSTANCE,\r
+                new InputSceneGraph(0, 5, Alignment.CENTER),\r
+//                InputSceneGraph.INSTANCE,\r
                 BoundsOutline.INSTANCE,\r
                 new WholeElementTerminals(terminals)\r
-        ).setId(AuxiliaryFactory.class.getSimpleName());\r
+        ).setId(InputFactory.class.getSimpleName());\r
     }\r
 \r
+    @Override\r
+    public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException {\r
+        super.load(graph, canvas, diagram, element, e);\r
+        Builtins b = graph.getBuiltins();\r
+        ModelingResources mr = ModelingResources.getInstance(graph);\r
+        SysdynResource sr = SysdynResource.getInstance(graph);\r
+\r
+        Resource component = null;\r
+        Resource dependency = null;\r
+        Resource refersTo = null;\r
+        Resource module = null;\r
+        component = graph.getPossibleObject(element, mr.ElementToComponent);\r
+        if(component != null) \r
+            dependency = graph.getPossibleObject(component, sr.IsHeadOf);\r
+        if(dependency != null) {\r
+            refersTo = graph.getPossibleObject(dependency, sr.RefersTo);\r
+            module = graph.getPossibleObject(dependency, sr.HasTail);\r
+        }\r
+        String inputReference = null;\r
+        if (module != null && refersTo != null) {\r
+            inputReference = (String) graph.getPossibleRelatedValue(module, b.HasName);\r
+            inputReference += ".";\r
+            inputReference += (String) graph.getPossibleRelatedValue(refersTo, b.HasName);\r
+        }\r
+        if (inputReference == null) {\r
+            inputReference = "\"\"";\r
+        }\r
+\r
+       SysdynElementUtils.setInputReference(e, inputReference);\r
+    }\r
+    \r
+    \r
+    public static class InputSceneGraph extends TextElementNoBounds {\r
+\r
+        private static final long   serialVersionUID = -3713275157729126409L;\r
+        public static final Key     SG_NODE          = new SceneGraphNodeKey(TextNode.class, "INPUT_SG_NODE");\r
 \r
+        private final double originX;\r
+        private final Alignment horizontalAlignment;\r
+        \r
+        public InputSceneGraph(double originX, double originY, Alignment horizontalAlignment) {\r
+            super(originX, originY, horizontalAlignment);\r
+            this.originX = originX;\r
+            this.horizontalAlignment = horizontalAlignment;\r
+        }\r
+        \r
+        @Override\r
+        public void init(final IElement e, G2DParentNode 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
+            Color color = new Color(150, 150, 150);\r
+            Color fillColor = ElementUtils.getFillColor(e);\r
+            Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK);\r
+            String text = SysdynElementUtils.getInputReference(e);\r
+            double scale = 0.235;\r
+            node.init(text, font, color, originX, font.getSize2D() * scale, scale);\r
+            node.setBackgroundColor(fillColor);\r
+            node.setBorderColor(borderColor);\r
+            node.setHorizontalAlignment((byte) horizontalAlignment.ordinal());\r
+            node.setBorderWidth((float) 0);\r
+            node.setEditable(false);\r
+        }\r
+    }\r
 }\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java
new file mode 100644 (file)
index 0000000..44d5fef
--- /dev/null
@@ -0,0 +1,9 @@
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+public class SysdynElementHints {\r
+\r
+    public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE");\r
+}\r
diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java
new file mode 100644 (file)
index 0000000..ba1bc73
--- /dev/null
@@ -0,0 +1,20 @@
+package org.simantics.sysdyn.ui.elements2;\r
+\r
+import org.simantics.g2d.element.ElementUtils;\r
+import org.simantics.g2d.element.IElement;\r
+\r
+public class SysdynElementUtils extends ElementUtils {\r
+\r
+    \r
+    public static void setInputReference(IElement e, String inputReference)\r
+    {\r
+        Input i = e.getElementClass().getSingleItem(Input.class);\r
+        i.setInputReference(e, inputReference);\r
+    }\r
+\r
+    public static String getInputReference(IElement e)\r
+    {\r
+        Input i = e.getElementClass().getSingleItem(Input.class);\r
+        return i.getInputReference(e);\r
+    }\r
+}\r
index e178b0b592e0e5f2ae91215bb9b30bada2ebb7b3..3db2b187bb3a2e17267677d9b76484149c6e5b10 100644 (file)
@@ -55,6 +55,7 @@ public class NewModuleNodeHandler extends AbstractHandler {
                 \r
                 Resource configuration = GraphUtils.create2(g, \r
                         sr.Configuration,\r
+                        mu.b.HasName, "ModuuliConffi",\r
                         mu.mr.CompositeToDiagram, diagram);\r
                 \r
                 g.claim(moduleType, mu.sr.IsDefinedBy , configuration);\r
index 209235e352480a6ef038efdee3af3dc18f2f700a..da9f555a3d0b65712e83f0fa977bbef05765c16b 100644 (file)
@@ -22,7 +22,6 @@ public class SysdynResource {
     \r
     public final Resource Admin1;\r
     public final Resource Admin2;\r
-    public final Resource Asiakasmoduuli;\r
     public final Resource Auxiliary;\r
     public final Resource AuxiliarySymbol;\r
     public final Resource BasicExperiment;\r
@@ -79,7 +78,6 @@ public class SysdynResource {
     public final Resource IsOutput;\r
     public final Resource IsTailOf;\r
     public final Resource IsTailOfTerminal;\r
-    public final Resource Kapasiteettimoduuli;\r
     public final Resource LookupExpression;\r
     public final Resource Module;\r
     public final Resource ModuleSymbol;\r
@@ -107,7 +105,6 @@ public class SysdynResource {
     public static class URIs {\r
         public static final String Admin1 = "http://www.simantics.org/Sysdyn-1.0/Admin1";\r
         public static final String Admin2 = "http://www.simantics.org/Sysdyn-1.0/Admin2";\r
-        public static final String Asiakasmoduuli = "http://www.simantics.org/Sysdyn-1.0/Asiakasmoduuli";\r
         public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary";\r
         public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol";\r
         public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment";\r
@@ -164,7 +161,6 @@ public class SysdynResource {
         public static final String IsOutput = "http://www.simantics.org/Sysdyn-1.0/IsOutput";\r
         public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.0/IsTailOf";\r
         public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsTailOfTerminal";\r
-        public static final String Kapasiteettimoduuli = "http://www.simantics.org/Sysdyn-1.0/Kapasiteettimoduuli";\r
         public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.0/LookupExpression";\r
         public static final String Module = "http://www.simantics.org/Sysdyn-1.0/Module";\r
         public static final String ModuleSymbol = "http://www.simantics.org/Sysdyn-1.0/ModuleSymbol";\r
@@ -202,7 +198,6 @@ public class SysdynResource {
     public SysdynResource(ReadGraph graph) {\r
         Admin1 = getResourceOrNull(graph, URIs.Admin1);\r
         Admin2 = getResourceOrNull(graph, URIs.Admin2);\r
-        Asiakasmoduuli = getResourceOrNull(graph, URIs.Asiakasmoduuli);\r
         Auxiliary = getResourceOrNull(graph, URIs.Auxiliary);\r
         AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol);\r
         BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment);\r
@@ -259,7 +254,6 @@ public class SysdynResource {
         IsOutput = getResourceOrNull(graph, URIs.IsOutput);\r
         IsTailOf = getResourceOrNull(graph, URIs.IsTailOf);\r
         IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal);\r
-        Kapasiteettimoduuli = getResourceOrNull(graph, URIs.Kapasiteettimoduuli);\r
         LookupExpression = getResourceOrNull(graph, URIs.LookupExpression);\r
         Module = getResourceOrNull(graph, URIs.Module);\r
         ModuleSymbol = getResourceOrNull(graph, URIs.ModuleSymbol);\r