]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/element/ElementHints.java
Merge commit 'bd5bc6e45f700e755b61bd112631796631330ecb'
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / element / ElementHints.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.g2d.element;\r
13 \r
14 import java.awt.AlphaComposite;\r
15 import java.awt.Color;\r
16 import java.awt.Composite;\r
17 import java.awt.Font;\r
18 import java.awt.Stroke;\r
19 import java.awt.geom.AffineTransform;\r
20 import java.awt.geom.Rectangle2D;\r
21 import java.util.Collection;\r
22 import java.util.HashMap;\r
23 import java.util.Set;\r
24 \r
25 import org.simantics.g2d.canvas.Hints;\r
26 import org.simantics.g2d.connection.ConnectionEntity;\r
27 import org.simantics.g2d.connection.IConnectionAdvisor;\r
28 import org.simantics.g2d.element.handler.SceneGraph;\r
29 import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType;\r
30 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;\r
31 import org.simantics.g2d.image.Image;\r
32 import org.simantics.g2d.utils.Alignment;\r
33 import org.simantics.scenegraph.Node;\r
34 import org.simantics.utils.datastructures.Callback;\r
35 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
36 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
37 \r
38 /**\r
39  * @author Toni Kalajainen\r
40  */\r
41 public class ElementHints {\r
42 \r
43     /**\r
44      * For attaching a paintable scene graph node to a diagram element.\r
45      */\r
46     public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE");\r
47 \r
48     /**\r
49      * For attaching a callback to an element that is invoked when KEY_SG_NODE\r
50      * is initialized and set.\r
51      */\r
52     public static final Key KEY_SG_CALLBACK = new SceneGraphNodeKey(Callback.class, "SG_NODE_CALLBACK");\r
53 \r
54     /**\r
55      * For describing the local affine transformation of an element.\r
56      */\r
57     public static final Key KEY_TRANSFORM = new KeyOf(AffineTransform.class, "TRANSFORM");\r
58 \r
59     /**\r
60      * For defining the rectangular boundaries of an element.\r
61      */\r
62     public static final Key KEY_BOUNDS = new KeyOf(Rectangle2D.class, "BOUNDS");\r
63 \r
64     /**\r
65      * For defining the parent element of an element to create element hierarchy\r
66      * in otherwise flat diagrams.\r
67      */\r
68     public static final Key KEY_PARENT_ELEMENT = new KeyOf(IElement.class, "PARENT_ELEMENT");\r
69 \r
70     /**\r
71      * A collection of {@link SceneGraph} instances. Used for decorating the\r
72      * owner element. Run-time decorators are not touched by back-end\r
73      * synchronization, they are controlled purely from the diagram run-time\r
74      * code. If modified, the {@link Hints#KEY_DIRTY} hint should be set with\r
75      * the value {@link Hints#VALUE_SG_DIRTY} to update the scenegraph of the\r
76      * element.\r
77      * \r
78      * @deprecated diagram profile styles should be used instead\r
79      */\r
80     public static final Key KEY_DECORATORS = new KeyOf(Collection.class, "DECORATORS");\r
81 \r
82     public static final Key KEY_ANCHOR = new KeyOf(IElement.class, "ANCHOR");\r
83 \r
84     public static final Key KEY_TEXT = new KeyOf(String.class, "TEXT");\r
85     public static final Key KEY_FONT = new KeyOf(Font.class, "FONT");\r
86 \r
87     public static final Key KEY_TEXT_COLOR = new KeyOf(Color.class, "TEXT_COLOR");\r
88     public static final Key KEY_BORDER_COLOR = new KeyOf(Color.class, "BORDER_COLOR");\r
89     public static final Key KEY_FILL_COLOR = new KeyOf(Color.class, "FILL_COLOR");\r
90     public static final Key KEY_ADDITIONAL_COLOR = new KeyOf(Color.class, "ADDITIONAL_COLOR");\r
91     public static final Key KEY_STROKE = new KeyOf(Stroke.class, "STROKE");\r
92 \r
93     public static final Key KEY_ENABLED = new KeyOf(Boolean.class, "ENABLED");\r
94 \r
95     public static final Key KEY_EDGE_STROKE = new KeyOf(Stroke.class, "EDGE_STROKE");\r
96     public static final Key KEY_EDGE_STROKE_TYPE = new KeyOf(StrokeType.class, "EDGE_STROKE_TYPE");\r
97     public static final Key KEY_BEGIN_ARROW = new KeyOf(ArrowType.class, "BEGIN_ARROW");\r
98     public static final Key KEY_END_ARROW = new KeyOf(ArrowType.class, "END_ARROW");\r
99     public static final Key KEY_BEGIN_ARROW_SIZE = new KeyOf(Double.class, "BEGIN_ARROW_SIZE");\r
100     public static final Key KEY_END_ARROW_SIZE = new KeyOf(Double.class, "END_ARROW_SIZE");\r
101 \r
102     /** Source of data in external data model */\r
103     public static final Key KEY_OBJECT = new KeyOf(Object.class, "OBJECT");\r
104 \r
105     /**\r
106      * Used for identifying elements that should be ignored in all matters\r
107      * concerning rendering/measuring/interaction.\r
108      */\r
109     public static final Key KEY_HIDDEN = new KeyOf(HideState.class, "HIDDEN");\r
110 \r
111     /**\r
112      * Used for specifying the name prefix of the scene graph node to generate\r
113      * for the owner element. See {@link ElementUtils#generateNodeId(IElement)}.\r
114      */\r
115     public static final Key KEY_SG_NAME = new KeyOf(String.class, "SG_NAME");\r
116 \r
117     /** Points to the external data model object which this element is a copy of. */\r
118     public static final Key KEY_COPY_OF_OBJECT = new KeyOf(Object.class, "COPY_OF_OBJECT");\r
119 \r
120     /** Value of a widget */\r
121     public static final Key KEY_VALUE = new KeyOf(Double.class, "VALUE");\r
122     public static final Key KEY_MIN_VALUE = new KeyOf(Double.class, "MIN_VALUE");\r
123     public static final Key KEY_MAX_VALUE = new KeyOf(Double.class, "MAX_VALUE");\r
124 \r
125     /** Is widget locked (unusable) */\r
126     public static final Key KEY_LOCKED = new KeyOf(Boolean.class, "LOCKED");\r
127 \r
128     public static final Key KEY_SELECTED = new KeyOf(Boolean.class, "SELECTED");\r
129 \r
130     /** Is mouse cursor on top of element **/ \r
131     public static final Key KEY_HOVER = new KeyOf(Boolean.class, "HOVER");\r
132     \r
133     /** Can the element be resized **/\r
134     public static final Key KEY_RESIZABLE = new KeyOf(Boolean.class, "RESIZABLE");    \r
135 \r
136     public static final Key KEY_IMAGE = new KeyOf(Image.class, "IMAGE");\r
137 \r
138     /**\r
139      * Composition rule for element painting. If this hint is found from an\r
140      * element, it should be applied before painting the element. The only\r
141      * implementation of {@link Composite} is {@link AlphaComposite} so that\r
142      * should be used.\r
143      */\r
144     public static final Key KEY_COMPOSITE = new KeyOf(Composite.class, "COMPOSITE");\r
145 \r
146     /**\r
147      * An optional type hint for a connection to be created. This hint is used\r
148      * for storing something returned by\r
149      * {@link IConnectionAdvisor#canBeConnected(Object, IElement, org.simantics.g2d.diagram.handler.Topology.Terminal, IElement, org.simantics.g2d.diagram.handler.Topology.Terminal)}\r
150      */\r
151     public static final Key KEY_CONNECTION_TYPE = new KeyOf(Object.class, "CONNECTION_TYPE");\r
152 \r
153     public static final Key KEY_HORIZONTAL_ALIGN = new KeyOf(Alignment.class, "HORIZONTAL_ALIGN");\r
154 \r
155     public static final Key KEY_VERTICAL_ALIGN   = new KeyOf(Alignment.class, "VERTICAL_ALIGN");\r
156 \r
157     /**\r
158      * For storing a connection entity within each connection and connection\r
159      * part element.\r
160      */\r
161     public static final Key KEY_CONNECTION_ENTITY = new KeyOf(ConnectionEntity.class, "CONNECTION_ENTITY");\r
162 \r
163     /**\r
164      * A set of ILayer instances identifying the layers the element containing\r
165      * this hint can be considered to be visible on.\r
166      */\r
167     public static final Key KEY_VISIBLE_LAYERS = new KeyOf(Set.class, "VISIBLE_LAYERS");\r
168 \r
169     /**\r
170      * A set of ILayer instances identifying the layers the element containing\r
171      * this hint can be considered to be focusable on.\r
172      */\r
173     public static final Key KEY_FOCUS_LAYERS = new KeyOf(Set.class, "FOCUS_LAYERS");\r
174 \r
175     /**\r
176      * Properties map\r
177      */\r
178     public static final Key KEY_ELEMENT_PROPERTIES = new KeyOf(Properties.class, "ELEMENT_PROPERTIES");\r
179 \r
180     public static class Properties extends HashMap<String, Object> {\r
181         private static final long serialVersionUID = 6986415032113675720L;\r
182     }\r
183 \r
184     /**\r
185      * A base class for keys that are to be considered discardable in\r
186      * synchronization.\r
187      */\r
188     public static class DiscardableKey extends KeyOf {\r
189         public DiscardableKey(Class<?> clazz) {\r
190             super(clazz);\r
191         }\r
192         public DiscardableKey(Class<?> clazz, String string) {\r
193             super(clazz, string);\r
194         }\r
195     }\r
196 \r
197 }\r