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