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
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
path.closePath();\r
return path;\r
}\r
+ \r
@Override\r
protected ElementClass compileElementClass(Resource elementType, Collection<ObjectTerminal> terminals) {\r
return ElementClass.compile(\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
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
\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
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
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
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
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
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