]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/element/ElementHints.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / ElementHints.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/element/ElementHints.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/element/ElementHints.java
new file mode 100644 (file)
index 0000000..c9fb2c4
--- /dev/null
@@ -0,0 +1,197 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.g2d.element;\r
+\r
+import java.awt.AlphaComposite;\r
+import java.awt.Color;\r
+import java.awt.Composite;\r
+import java.awt.Font;\r
+import java.awt.Stroke;\r
+import java.awt.geom.AffineTransform;\r
+import java.awt.geom.Rectangle2D;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.Set;\r
+\r
+import org.simantics.g2d.canvas.Hints;\r
+import org.simantics.g2d.connection.ConnectionEntity;\r
+import org.simantics.g2d.connection.IConnectionAdvisor;\r
+import org.simantics.g2d.element.handler.SceneGraph;\r
+import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType;\r
+import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;\r
+import org.simantics.g2d.image.Image;\r
+import org.simantics.g2d.utils.Alignment;\r
+import org.simantics.scenegraph.Node;\r
+import org.simantics.utils.datastructures.Callback;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+/**\r
+ * @author Toni Kalajainen\r
+ */\r
+public class ElementHints {\r
+\r
+    /**\r
+     * For attaching a paintable scene graph node to a diagram element.\r
+     */\r
+    public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE");\r
+\r
+    /**\r
+     * For attaching a callback to an element that is invoked when KEY_SG_NODE\r
+     * is initialized and set.\r
+     */\r
+    public static final Key KEY_SG_CALLBACK = new SceneGraphNodeKey(Callback.class, "SG_NODE_CALLBACK");\r
+\r
+    /**\r
+     * For describing the local affine transformation of an element.\r
+     */\r
+    public static final Key KEY_TRANSFORM = new KeyOf(AffineTransform.class, "TRANSFORM");\r
+\r
+    /**\r
+     * For defining the rectangular boundaries of an element.\r
+     */\r
+    public static final Key KEY_BOUNDS = new KeyOf(Rectangle2D.class, "BOUNDS");\r
+\r
+    /**\r
+     * For defining the parent element of an element to create element hierarchy\r
+     * in otherwise flat diagrams.\r
+     */\r
+    public static final Key KEY_PARENT_ELEMENT = new KeyOf(IElement.class, "PARENT_ELEMENT");\r
+\r
+    /**\r
+     * A collection of {@link SceneGraph} instances. Used for decorating the\r
+     * owner element. Run-time decorators are not touched by back-end\r
+     * synchronization, they are controlled purely from the diagram run-time\r
+     * code. If modified, the {@link Hints#KEY_DIRTY} hint should be set with\r
+     * the value {@link Hints#VALUE_SG_DIRTY} to update the scenegraph of the\r
+     * element.\r
+     * \r
+     * @deprecated diagram profile styles should be used instead\r
+     */\r
+    public static final Key KEY_DECORATORS = new KeyOf(Collection.class, "DECORATORS");\r
+\r
+    public static final Key KEY_ANCHOR = new KeyOf(IElement.class, "ANCHOR");\r
+\r
+    public static final Key KEY_TEXT = new KeyOf(String.class, "TEXT");\r
+    public static final Key KEY_FONT = new KeyOf(Font.class, "FONT");\r
+\r
+    public static final Key KEY_TEXT_COLOR = new KeyOf(Color.class, "TEXT_COLOR");\r
+    public static final Key KEY_BORDER_COLOR = new KeyOf(Color.class, "BORDER_COLOR");\r
+    public static final Key KEY_FILL_COLOR = new KeyOf(Color.class, "FILL_COLOR");\r
+    public static final Key KEY_ADDITIONAL_COLOR = new KeyOf(Color.class, "ADDITIONAL_COLOR");\r
+    public static final Key KEY_STROKE = new KeyOf(Stroke.class, "STROKE");\r
+\r
+    public static final Key KEY_ENABLED = new KeyOf(Boolean.class, "ENABLED");\r
+\r
+    public static final Key KEY_EDGE_STROKE = new KeyOf(Stroke.class, "EDGE_STROKE");\r
+    public static final Key KEY_EDGE_STROKE_TYPE = new KeyOf(StrokeType.class, "EDGE_STROKE_TYPE");\r
+    public static final Key KEY_BEGIN_ARROW = new KeyOf(ArrowType.class, "BEGIN_ARROW");\r
+    public static final Key KEY_END_ARROW = new KeyOf(ArrowType.class, "END_ARROW");\r
+    public static final Key KEY_BEGIN_ARROW_SIZE = new KeyOf(Double.class, "BEGIN_ARROW_SIZE");\r
+    public static final Key KEY_END_ARROW_SIZE = new KeyOf(Double.class, "END_ARROW_SIZE");\r
+\r
+    /** Source of data in external data model */\r
+    public static final Key KEY_OBJECT = new KeyOf(Object.class, "OBJECT");\r
+\r
+    /**\r
+     * Used for identifying elements that should be ignored in all matters\r
+     * concerning rendering/measuring/interaction.\r
+     */\r
+    public static final Key KEY_HIDDEN = new KeyOf(HideState.class, "HIDDEN");\r
+\r
+    /**\r
+     * Used for specifying the name prefix of the scene graph node to generate\r
+     * for the owner element. See {@link ElementUtils#generateNodeId(IElement)}.\r
+     */\r
+    public static final Key KEY_SG_NAME = new KeyOf(String.class, "SG_NAME");\r
+\r
+    /** Points to the external data model object which this element is a copy of. */\r
+    public static final Key KEY_COPY_OF_OBJECT = new KeyOf(Object.class, "COPY_OF_OBJECT");\r
+\r
+    /** Value of a widget */\r
+    public static final Key KEY_VALUE = new KeyOf(Double.class, "VALUE");\r
+    public static final Key KEY_MIN_VALUE = new KeyOf(Double.class, "MIN_VALUE");\r
+    public static final Key KEY_MAX_VALUE = new KeyOf(Double.class, "MAX_VALUE");\r
+\r
+    /** Is widget locked (unusable) */\r
+    public static final Key KEY_LOCKED = new KeyOf(Boolean.class, "LOCKED");\r
+\r
+    public static final Key KEY_SELECTED = new KeyOf(Boolean.class, "SELECTED");\r
+\r
+    /** Is mouse cursor on top of element **/ \r
+    public static final Key KEY_HOVER = new KeyOf(Boolean.class, "HOVER");\r
+    \r
+    /** Can the element be resized **/\r
+    public static final Key KEY_RESIZABLE = new KeyOf(Boolean.class, "RESIZABLE");    \r
+\r
+    public static final Key KEY_IMAGE = new KeyOf(Image.class, "IMAGE");\r
+\r
+    /**\r
+     * Composition rule for element painting. If this hint is found from an\r
+     * element, it should be applied before painting the element. The only\r
+     * implementation of {@link Composite} is {@link AlphaComposite} so that\r
+     * should be used.\r
+     */\r
+    public static final Key KEY_COMPOSITE = new KeyOf(Composite.class, "COMPOSITE");\r
+\r
+    /**\r
+     * An optional type hint for a connection to be created. This hint is used\r
+     * for storing something returned by\r
+     * {@link IConnectionAdvisor#canBeConnected(Object, IElement, org.simantics.g2d.diagram.handler.Topology.Terminal, IElement, org.simantics.g2d.diagram.handler.Topology.Terminal)}\r
+     */\r
+    public static final Key KEY_CONNECTION_TYPE = new KeyOf(Object.class, "CONNECTION_TYPE");\r
+\r
+    public static final Key KEY_HORIZONTAL_ALIGN = new KeyOf(Alignment.class, "HORIZONTAL_ALIGN");\r
+\r
+    public static final Key KEY_VERTICAL_ALIGN   = new KeyOf(Alignment.class, "VERTICAL_ALIGN");\r
+\r
+    /**\r
+     * For storing a connection entity within each connection and connection\r
+     * part element.\r
+     */\r
+    public static final Key KEY_CONNECTION_ENTITY = new KeyOf(ConnectionEntity.class, "CONNECTION_ENTITY");\r
+\r
+    /**\r
+     * A set of ILayer instances identifying the layers the element containing\r
+     * this hint can be considered to be visible on.\r
+     */\r
+    public static final Key KEY_VISIBLE_LAYERS = new KeyOf(Set.class, "VISIBLE_LAYERS");\r
+\r
+    /**\r
+     * A set of ILayer instances identifying the layers the element containing\r
+     * this hint can be considered to be focusable on.\r
+     */\r
+    public static final Key KEY_FOCUS_LAYERS = new KeyOf(Set.class, "FOCUS_LAYERS");\r
+\r
+    /**\r
+     * Properties map\r
+     */\r
+    public static final Key KEY_ELEMENT_PROPERTIES = new KeyOf(Properties.class, "ELEMENT_PROPERTIES");\r
+\r
+    public static class Properties extends HashMap<String, Object> {\r
+        private static final long serialVersionUID = 6986415032113675720L;\r
+    }\r
+\r
+    /**\r
+     * A base class for keys that are to be considered discardable in\r
+     * synchronization.\r
+     */\r
+    public static class DiscardableKey extends KeyOf {\r
+        public DiscardableKey(Class<?> clazz) {\r
+            super(clazz);\r
+        }\r
+        public DiscardableKey(Class<?> clazz, String string) {\r
+            super(clazz, string);\r
+        }\r
+    }\r
+\r
+}\r