From: lempinen Date: Mon, 26 Jul 2010 11:23:51 +0000 (+0000) Subject: Input nodes with reference text X-Git-Tag: simantics-1.2.0~162 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=ff8a40fd04b110f14fb8f92caa6f7c4043ff9dab;p=simantics%2Fsysdyn.git Input nodes with reference text git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@16826 ac1ea38d-2e2b-0410-8846-a27921b304fc --- 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 index 00000000..60f9a4c5 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/Input.java @@ -0,0 +1,25 @@ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.handler.ElementHandler; + +public class Input implements ElementHandler { + + private static final long serialVersionUID = -1526125969376635502L; + + public static final Input INSTANCE = new Input(); + + public String getInputReference(IElement e) { + return e.getHint(SysdynElementHints.KEY_INPUT_REFERENCE); + } + + + public void setInputReference(IElement e, String inputReference) { + if (inputReference != null) + e.setHint(SysdynElementHints.KEY_INPUT_REFERENCE, inputReference); + else + e.removeHint(SysdynElementHints.KEY_INPUT_REFERENCE); + } + + +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java index e266bf22..b26509f9 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/InputFactory.java @@ -1,13 +1,25 @@ package org.simantics.sysdyn.ui.elements2; import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Font; import java.awt.Shape; import java.awt.geom.Path2D; import java.util.Collection; +import org.simantics.db.Builtins; +import org.simantics.db.ReadGraph; import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.elements.TextElementHandler; +import org.simantics.diagram.elements.TextElementNoBounds; +import org.simantics.diagram.elements.TextNode; +import org.simantics.g2d.canvas.ICanvasContext; +import org.simantics.g2d.diagram.IDiagram; import org.simantics.g2d.element.ElementClass; +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; +import org.simantics.g2d.element.SceneGraphNodeKey; import org.simantics.g2d.element.handler.impl.BoundsOutline; import org.simantics.g2d.element.handler.impl.DefaultTransform; import org.simantics.g2d.element.handler.impl.ObjectTerminal; @@ -21,11 +33,16 @@ import org.simantics.g2d.element.handler.impl.TextFontImpl; import org.simantics.g2d.element.handler.impl.TextImpl; import org.simantics.g2d.image.Image; import org.simantics.g2d.image.impl.ShapeImage; +import org.simantics.g2d.utils.Alignment; +import org.simantics.modeling.ModelingResources; +import org.simantics.scenegraph.g2d.G2DParentNode; +import org.simantics.sysdyn.SysdynResource; +import org.simantics.utils.datastructures.hints.IHintContext.Key; public class InputFactory extends SysdynElementFactory { - private static final BasicStroke STROKE = new BasicStroke(1f); - private static final Image INPUT_IMAGE = new ShapeImage(getInputShape(), null, STROKE, true); + private static final BasicStroke STROKE = new BasicStroke(1f); + private static final Image INPUT_IMAGE = new ShapeImage(getInputShape(), null, STROKE, true); static Shape getInputShape() { Path2D path = new Path2D.Double(); @@ -41,6 +58,7 @@ public class InputFactory extends SysdynElementFactory { path.closePath(); return path; } + @Override protected ElementClass compileElementClass(Resource elementType, Collection terminals) { return ElementClass.compile( @@ -54,10 +72,78 @@ public class InputFactory extends SysdynElementFactory { new StaticSymbolImpl(INPUT_IMAGE), StaticSymbolImageInitializer.INSTANCE, TextElementHandler.INSTANCE, + Input.INSTANCE, + new InputSceneGraph(0, 5, Alignment.CENTER), +// InputSceneGraph.INSTANCE, BoundsOutline.INSTANCE, new WholeElementTerminals(terminals) - ).setId(AuxiliaryFactory.class.getSimpleName()); + ).setId(InputFactory.class.getSimpleName()); } + @Override + public void load(ReadGraph graph, final ICanvasContext canvas, final IDiagram diagram, final Resource element, final IElement e) throws DatabaseException { + super.load(graph, canvas, diagram, element, e); + Builtins b = graph.getBuiltins(); + ModelingResources mr = ModelingResources.getInstance(graph); + SysdynResource sr = SysdynResource.getInstance(graph); + + Resource component = null; + Resource dependency = null; + Resource refersTo = null; + Resource module = null; + component = graph.getPossibleObject(element, mr.ElementToComponent); + if(component != null) + dependency = graph.getPossibleObject(component, sr.IsHeadOf); + if(dependency != null) { + refersTo = graph.getPossibleObject(dependency, sr.RefersTo); + module = graph.getPossibleObject(dependency, sr.HasTail); + } + String inputReference = null; + if (module != null && refersTo != null) { + inputReference = (String) graph.getPossibleRelatedValue(module, b.HasName); + inputReference += "."; + inputReference += (String) graph.getPossibleRelatedValue(refersTo, b.HasName); + } + if (inputReference == null) { + inputReference = "\"\""; + } + + SysdynElementUtils.setInputReference(e, inputReference); + } + + + public static class InputSceneGraph extends TextElementNoBounds { + + private static final long serialVersionUID = -3713275157729126409L; + public static final Key SG_NODE = new SceneGraphNodeKey(TextNode.class, "INPUT_SG_NODE"); + private final double originX; + private final Alignment horizontalAlignment; + + public InputSceneGraph(double originX, double originY, Alignment horizontalAlignment) { + super(originX, originY, horizontalAlignment); + this.originX = originX; + this.horizontalAlignment = horizontalAlignment; + } + + @Override + public void init(final IElement e, G2DParentNode parent) { + TextNode node = ElementUtils.getOrCreateNode(e, parent, SG_NODE, "input", TextNode.class); + //Font font = new Font("Tahoma", 0, 12); + Font font = ElementUtils.getTextFont(e); + font = font.deriveFont((float) 10.0); + font = font.deriveFont(Font.ITALIC); + Color color = new Color(150, 150, 150); + Color fillColor = ElementUtils.getFillColor(e); + Color borderColor = ElementUtils.getBorderColor(e, Color.BLACK); + String text = SysdynElementUtils.getInputReference(e); + double scale = 0.235; + node.init(text, font, color, originX, font.getSize2D() * scale, scale); + node.setBackgroundColor(fillColor); + node.setBorderColor(borderColor); + node.setHorizontalAlignment((byte) horizontalAlignment.ordinal()); + node.setBorderWidth((float) 0); + node.setEditable(false); + } + } } 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 index 00000000..44d5fef4 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementHints.java @@ -0,0 +1,9 @@ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintContext.KeyOf; + +public class SysdynElementHints { + + public static final Key KEY_INPUT_REFERENCE = new KeyOf(String.class, "INPUT_REFERENCE"); +} 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 index 00000000..ba1bc733 --- /dev/null +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements2/SysdynElementUtils.java @@ -0,0 +1,20 @@ +package org.simantics.sysdyn.ui.elements2; + +import org.simantics.g2d.element.ElementUtils; +import org.simantics.g2d.element.IElement; + +public class SysdynElementUtils extends ElementUtils { + + + public static void setInputReference(IElement e, String inputReference) + { + Input i = e.getElementClass().getSingleItem(Input.class); + i.setInputReference(e, inputReference); + } + + public static String getInputReference(IElement e) + { + Input i = e.getElementClass().getSingleItem(Input.class); + return i.getInputReference(e); + } +} diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java index e178b0b5..3db2b187 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/NewModuleNodeHandler.java @@ -55,6 +55,7 @@ public class NewModuleNodeHandler extends AbstractHandler { Resource configuration = GraphUtils.create2(g, sr.Configuration, + mu.b.HasName, "ModuuliConffi", mu.mr.CompositeToDiagram, diagram); g.claim(moduleType, mu.sr.IsDefinedBy , configuration); diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java index 209235e3..da9f555a 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/SysdynResource.java @@ -22,7 +22,6 @@ public class SysdynResource { public final Resource Admin1; public final Resource Admin2; - public final Resource Asiakasmoduuli; public final Resource Auxiliary; public final Resource AuxiliarySymbol; public final Resource BasicExperiment; @@ -79,7 +78,6 @@ public class SysdynResource { public final Resource IsOutput; public final Resource IsTailOf; public final Resource IsTailOfTerminal; - public final Resource Kapasiteettimoduuli; public final Resource LookupExpression; public final Resource Module; public final Resource ModuleSymbol; @@ -107,7 +105,6 @@ public class SysdynResource { public static class URIs { public static final String Admin1 = "http://www.simantics.org/Sysdyn-1.0/Admin1"; public static final String Admin2 = "http://www.simantics.org/Sysdyn-1.0/Admin2"; - public static final String Asiakasmoduuli = "http://www.simantics.org/Sysdyn-1.0/Asiakasmoduuli"; public static final String Auxiliary = "http://www.simantics.org/Sysdyn-1.0/Auxiliary"; public static final String AuxiliarySymbol = "http://www.simantics.org/Sysdyn-1.0/AuxiliarySymbol"; public static final String BasicExperiment = "http://www.simantics.org/Sysdyn-1.0/BasicExperiment"; @@ -164,7 +161,6 @@ public class SysdynResource { public static final String IsOutput = "http://www.simantics.org/Sysdyn-1.0/IsOutput"; public static final String IsTailOf = "http://www.simantics.org/Sysdyn-1.0/IsTailOf"; public static final String IsTailOfTerminal = "http://www.simantics.org/Sysdyn-1.0/IsTailOfTerminal"; - public static final String Kapasiteettimoduuli = "http://www.simantics.org/Sysdyn-1.0/Kapasiteettimoduuli"; public static final String LookupExpression = "http://www.simantics.org/Sysdyn-1.0/LookupExpression"; public static final String Module = "http://www.simantics.org/Sysdyn-1.0/Module"; public static final String ModuleSymbol = "http://www.simantics.org/Sysdyn-1.0/ModuleSymbol"; @@ -202,7 +198,6 @@ public class SysdynResource { public SysdynResource(ReadGraph graph) { Admin1 = getResourceOrNull(graph, URIs.Admin1); Admin2 = getResourceOrNull(graph, URIs.Admin2); - Asiakasmoduuli = getResourceOrNull(graph, URIs.Asiakasmoduuli); Auxiliary = getResourceOrNull(graph, URIs.Auxiliary); AuxiliarySymbol = getResourceOrNull(graph, URIs.AuxiliarySymbol); BasicExperiment = getResourceOrNull(graph, URIs.BasicExperiment); @@ -259,7 +254,6 @@ public class SysdynResource { IsOutput = getResourceOrNull(graph, URIs.IsOutput); IsTailOf = getResourceOrNull(graph, URIs.IsTailOf); IsTailOfTerminal = getResourceOrNull(graph, URIs.IsTailOfTerminal); - Kapasiteettimoduuli = getResourceOrNull(graph, URIs.Kapasiteettimoduuli); LookupExpression = getResourceOrNull(graph, URIs.LookupExpression); Module = getResourceOrNull(graph, URIs.Module); ModuleSymbol = getResourceOrNull(graph, URIs.ModuleSymbol);