1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.element;
14 import java.awt.AlphaComposite;
15 import java.awt.Color;
16 import java.awt.Composite;
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;
25 import java.util.function.Consumer;
27 import org.simantics.g2d.canvas.Hints;
28 import org.simantics.g2d.connection.ConnectionEntity;
29 import org.simantics.g2d.connection.IConnectionAdvisor;
30 import org.simantics.g2d.element.handler.EdgeVisuals.ArrowType;
31 import org.simantics.g2d.element.handler.EdgeVisuals.StrokeType;
32 import org.simantics.g2d.element.handler.SceneGraph;
33 import org.simantics.g2d.image.Image;
34 import org.simantics.g2d.utils.Alignment;
35 import org.simantics.scenegraph.Node;
36 import org.simantics.scenegraph.g2d.color.ColorFilter;
37 import org.simantics.utils.datastructures.hints.IHintContext.Key;
38 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
41 * @author Toni Kalajainen
43 public class ElementHints {
46 * For attaching a paintable scene graph node to a diagram element.
48 public static final Key KEY_SG_NODE = new SceneGraphNodeKey(Node.class, "SG_NODE");
51 * For attaching a callback to an element that is invoked when KEY_SG_NODE
52 * is initialized and set.
54 public static final Key KEY_SG_CALLBACK = new SceneGraphNodeKey(Consumer.class, "SG_NODE_CALLBACK");
57 * For describing the local affine transformation of an element.
59 public static final Key KEY_TRANSFORM = new KeyOf(AffineTransform.class, "TRANSFORM");
62 * For describing representation parameters of an element.
64 public static final Key KEY_PARAMETERS = new KeyOf(Map.class, "PARAMETERS");
67 * For defining the rectangular boundaries of an element.
69 public static final Key KEY_BOUNDS = new KeyOf(Rectangle2D.class, "BOUNDS");
72 * For defining the parent element of an element to create element hierarchy
73 * in otherwise flat diagrams.
75 public static final Key KEY_PARENT_ELEMENT = new KeyOf(IElement.class, "PARENT_ELEMENT");
78 * A collection of {@link SceneGraph} instances. Used for decorating the
79 * owner element. Run-time decorators are not touched by back-end
80 * synchronization, they are controlled purely from the diagram run-time
81 * code. If modified, the {@link Hints#KEY_DIRTY} hint should be set with
82 * the value {@link Hints#VALUE_SG_DIRTY} to update the scenegraph of the
85 * @deprecated diagram profile styles should be used instead
87 public static final Key KEY_DECORATORS = new KeyOf(Collection.class, "DECORATORS");
89 public static final Key KEY_ANCHOR = new KeyOf(IElement.class, "ANCHOR");
91 public static final Key KEY_TEXT = new KeyOf(String.class, "TEXT");
92 public static final Key KEY_FONT = new KeyOf(Font.class, "FONT");
94 public static final Key KEY_TEXT_COLOR = new KeyOf(Color.class, "TEXT_COLOR");
95 public static final Key KEY_BORDER_COLOR = new KeyOf(Color.class, "BORDER_COLOR");
96 public static final Key KEY_FILL_COLOR = new KeyOf(Color.class, "FILL_COLOR");
97 public static final Key KEY_ADDITIONAL_COLOR = new KeyOf(Color.class, "ADDITIONAL_COLOR");
98 public static final Key KEY_STROKE = new KeyOf(Stroke.class, "STROKE");
100 public static final Key KEY_ENABLED = new KeyOf(Boolean.class, "ENABLED");
102 public static final Key KEY_EDGE_STROKE = new KeyOf(Stroke.class, "EDGE_STROKE");
103 public static final Key KEY_EDGE_STROKE_TYPE = new KeyOf(StrokeType.class, "EDGE_STROKE_TYPE");
104 public static final Key KEY_BEGIN_ARROW = new KeyOf(ArrowType.class, "BEGIN_ARROW");
105 public static final Key KEY_END_ARROW = new KeyOf(ArrowType.class, "END_ARROW");
106 public static final Key KEY_BEGIN_ARROW_SIZE = new KeyOf(Double.class, "BEGIN_ARROW_SIZE");
107 public static final Key KEY_END_ARROW_SIZE = new KeyOf(Double.class, "END_ARROW_SIZE");
109 /** Source of data in external data model */
110 public static final Key KEY_OBJECT = new KeyOf(Object.class, "OBJECT");
111 public static final Key KEY_TYPE_CLASS = new KeyOf(String.class, "TYPE_CLASS");
114 * Used for identifying elements that should be ignored in all matters
115 * concerning rendering/measuring/interaction.
117 public static final Key KEY_HIDDEN = new KeyOf(HideState.class, "HIDDEN");
120 * Used for specifying the name prefix of the scene graph node to generate
121 * for the owner element. See {@link ElementUtils#generateNodeId(IElement)}.
123 public static final Key KEY_SG_NAME = new KeyOf(String.class, "SG_NAME");
125 /** Points to the external data model object which this element is a copy of. */
126 public static final Key KEY_COPY_OF_OBJECT = new KeyOf(Object.class, "COPY_OF_OBJECT");
128 /** Value of a widget */
129 public static final Key KEY_VALUE = new KeyOf(Double.class, "VALUE");
130 public static final Key KEY_MIN_VALUE = new KeyOf(Double.class, "MIN_VALUE");
131 public static final Key KEY_MAX_VALUE = new KeyOf(Double.class, "MAX_VALUE");
133 /** Is widget locked (unusable) */
134 public static final Key KEY_LOCKED = new KeyOf(Boolean.class, "LOCKED");
136 public static final Key KEY_SELECTED = new KeyOf(Boolean.class, "SELECTED");
138 /** Is mouse cursor on top of element **/
139 public static final Key KEY_HOVER = new KeyOf(Boolean.class, "HOVER");
141 /** Can the element be resized **/
142 public static final Key KEY_RESIZABLE = new KeyOf(Boolean.class, "RESIZABLE");
144 public static final Key KEY_IMAGE = new KeyOf(Image.class, "IMAGE");
147 * Composition rule for element painting. If this hint is found from an
148 * element, it should be applied before painting the element. The only
149 * implementation of {@link Composite} is {@link AlphaComposite} so that
152 public static final Key KEY_COMPOSITE = new KeyOf(Composite.class, "COMPOSITE");
155 * An optional type hint for a connection to be created. This hint is used
156 * for storing something returned by
157 * {@link IConnectionAdvisor#canBeConnected(Object, IElement, org.simantics.g2d.diagram.handler.Topology.Terminal, IElement, org.simantics.g2d.diagram.handler.Topology.Terminal)}
159 public static final Key KEY_CONNECTION_TYPE = new KeyOf(Object.class, "CONNECTION_TYPE");
161 public static final Key KEY_HORIZONTAL_ALIGN = new KeyOf(Alignment.class, "HORIZONTAL_ALIGN");
163 public static final Key KEY_VERTICAL_ALIGN = new KeyOf(Alignment.class, "VERTICAL_ALIGN");
166 * For storing a connection entity within each connection and connection
169 public static final Key KEY_CONNECTION_ENTITY = new KeyOf(ConnectionEntity.class, "CONNECTION_ENTITY");
172 * A set of ILayer instances identifying the layers the element containing
173 * this hint can be considered to be visible on.
175 public static final Key KEY_VISIBLE_LAYERS = new KeyOf(Set.class, "VISIBLE_LAYERS");
178 * A set of ILayer instances identifying the layers the element containing
179 * this hint can be considered to be focusable on.
181 public static final Key KEY_FOCUS_LAYERS = new KeyOf(Set.class, "FOCUS_LAYERS");
186 public static final Key KEY_ELEMENT_PROPERTIES = new KeyOf(Properties.class, "ELEMENT_PROPERTIES");
189 * Color filter to be applied when rendering nodes.
191 public static final Key KEY_COLOR_FILTER = new KeyOf(ColorFilter.class, "COLOR_FILTER");
193 public static class Properties extends HashMap<String, Object> {
194 private static final long serialVersionUID = 6986415032113675720L;
198 * A base class for keys that are to be considered discardable in
201 public static class DiscardableKey extends KeyOf {
202 public DiscardableKey(Class<?> clazz) {
205 public DiscardableKey(Class<?> clazz, String string) {
206 super(clazz, string);