]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/DiagramHints.java
Even more fixes to layers
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / diagram / DiagramHints.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.diagram;
13
14 import java.awt.Color;
15 import java.awt.Point;
16 import java.awt.geom.Point2D;
17 import java.util.List;
18 import java.util.Map;
19
20 import org.simantics.g2d.canvas.ICanvasContext;
21 import org.simantics.g2d.canvas.ICanvasParticipant;
22 import org.simantics.g2d.connection.IConnectionAdvisor;
23 import org.simantics.g2d.diagram.handler.impl.PickContextImpl;
24 import org.simantics.g2d.diagram.participant.ElementPainter;
25 import org.simantics.g2d.element.IElement;
26 import org.simantics.g2d.element.handler.ElementLayerListener;
27 import org.simantics.g2d.layers.ILayers;
28 import org.simantics.g2d.layers.ILayersEditor;
29 import org.simantics.g2d.routing.IRouter2;
30 import org.simantics.scenegraph.INode;
31 import org.simantics.scenegraph.g2d.snap.ISnapAdvisor;
32 import org.simantics.utils.datastructures.hints.IHintContext.Key;
33 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
34 import org.simantics.utils.page.MarginUtils.Margins;
35
36 /**
37  * These hints are meant to be used with IDiagram instances.
38  * 
39  * @author Toni Kalajainen
40  */
41 public class DiagramHints {
42
43     /**
44      * A hint for disabling painting of the diagram the hint is associated with.
45      * 
46      * <p>
47      * By default diagram viewers perform a zoom-to-fit operation on the opened
48      * diagram immediately after opening. Sometimes it is desirable to allow
49      * disabling of this fitting process. Due to the SWT/AWT interplay nature of
50      * diagram editors, the process of zoom-to-fit is rather asynchronous and
51      * needs to schedule runnables into the toolkit threads. Since editor
52      * opening is synchronously performed in the SWT thread we can safely veto
53      * the zoom-to-fit operation by removing this hint from the diagram after
54      * opening the editor.
55      * 
56      * <p>
57      * Can also be set for an {@link ICanvasContext} to enable or disable
58      * initial zoom to fit for the context regardless of the diagram in
59      * question.
60      */
61     public static final Key KEY_INITIAL_ZOOM_TO_FIT   = new KeyOf(Boolean.class, "INITIAL_ZOOM_TO_FIT");
62
63     /** Diagram */
64     public static final Key KEY_DIAGRAM               = new KeyOf(IDiagram.class, "DIAGRAM");
65
66     public static final Key KEY_SELECTION_FRAME_COLOR = new KeyOf(Color.class, "SELECTION_FRAME_COLOR");
67
68     public static final Key KEY_TEXT                  = new KeyOf(String.class, "DIAGRAM_TEXT");
69
70     public static final Key KEY_CANVAS_COLOR          = new KeyOf(Color.class, "CANVAS_COLOR");
71
72     // Layer composition List<LayerInfo>
73     public static final Key KEY_LAYER_COMPOSITION     = new KeyOf(List.class, "LAYER_COMPOSITION");
74
75     // public static final Key KEY_BOUNDS = ElementHints.KEY_BOUNDS;
76
77     public final static Key KEY_MARGINS               = new KeyOf(Margins.class, "MARGINS");
78
79     public final static Key KEY_MARGINS_NO_RULER      = new KeyOf(Margins.class, "MARGINS_NO_RULER");
80
81     /**
82      * For diagrams, this hint defines the default routing algorithm applied to
83      * any connection that does not defined its own routing. For connection
84      * elements, this hint defines the selected connection-specific routing
85      * strategy.
86      */
87     public static final Key ROUTE_ALGORITHM           = new KeyOf(IRouter2.class, "ROUTE_ALGORITHM");
88
89     public static final Key PROPERTIES                = new KeyOf(Map.class, "PROPERTIES");
90
91     public static final Key CONNECTION_ADVISOR        = new KeyOf(IConnectionAdvisor.class, "CONNECTION_ADVISOR");
92
93     public static final Key SNAP_ADVISOR              = new KeyOf(ISnapAdvisor.class, "SNAP_ADVISOR");
94
95     public static final Key KEY_LAYERS                = new KeyOf(ILayers.class, "LAYERS");
96
97     public static final Key KEY_LAYERS_EDITOR         = new KeyOf(ILayersEditor.class, "LAYERS_EDITOR");
98
99     public static final Key KEY_ELEMENT_LAYER_LISTENER = new KeyOf(ElementLayerListener.class, "ELEMENT_LAYER_LISTENER");
100
101     public static final Key KEY_FIXED_LAYERS          = new KeyOf(String[].class, "FIXED_LAYERS");
102
103     public static final Key KEY_MUTATOR                = new KeyOf(DiagramMutator.class, "MUTATIONS");
104
105     public static final Key KEY_NAVIGATION_ENABLED = new KeyOf(Boolean.class, "NAVIGATION_ENABLED");
106
107     /**
108      * A hint for describing the target rasterized size of element images in a
109      * diagram. This is useful for UI components like the symbol library which
110      * always shows symbols in a certain size in pixels. Images are generally
111      * pre-rasterized and mipmapped in order to speed up SVG rendering. This
112      * allows making sure that the symbol is properly rasterized at its target
113      * resolution instead of having to resort to mipmaps. If this hint is not provided,
114      * a default procedure for resolving the mipmap sizes is followed.
115      */
116     public static final Key KEY_ELEMENT_RASTER_TARGET_SIZE = new KeyOf(Point.class, "ELEMENT_RASTER_TARGET_SIZE");
117
118     /**
119      * This hint is used to mark an element that is being inline edited on a
120      * diagram. This hint can be used for example to make sure that only one
121      * element is being inline edited at any given time on a single diagram.
122      */
123     public static final Key KEY_ACTIVE_INLINE_EDITOR = new KeyOf(ICanvasParticipant.class, "ACTIVE_INLINE_EDITOR");
124
125     /**
126      * <code>true</code> to allow connection branching. <code>null</code> or
127      * <code>false</code> will disable connection branching.
128      * 
129      * This is a hint for editing, not for visualisation.
130      * 
131      * If the hint is not present, the default interpretation should be to allow branching.
132      */
133     public static final Key KEY_ALLOW_CONNECTION_BRANCHING = new KeyOf(Boolean.class, "ALLOW_CONNECTION_BRANCHING");
134
135     /**
136      * <code>true</code> to create flags when connections are left in the air,
137      * <code>null</code> or <code>false</code> will leave the connections
138      * hanging in the air.
139      * 
140      * This is a hint for editing, not for visualisation.
141      * 
142      * If the hint is not present, the default interpretation should be not to
143      * use connection flags.
144      */
145     public static final Key KEY_USE_CONNECTION_FLAGS = new KeyOf(Boolean.class, "USE_CONNECTION_FLAGS");
146
147     /**
148      * <code>true</code> to allow adding of route points into connections or
149      * <code>false</code> to deny route points from being added/created.
150      * 
151      * This is a hint for editing, not for visualisation.
152      * 
153      * If the hint is not present, the default interpretation should be to use
154      * route points
155      */
156     public static final Key KEY_ALLOW_ROUTE_POINTS = new KeyOf(Boolean.class, "ALLOW_ROUTE_POINTS");
157
158
159     /**
160      * A Hint for other participants to use for showing the context menu at the
161      * control position specified by the Point2D argument.
162      */
163     public static final Key SHOW_POPUP_MENU                = new KeyOf(Point2D.class, "SHOW_POPUP_MENU_CMD");
164
165     /**
166      * Screen position of mouse on canvas control when the menu was invoked to
167      * be opened. For use by menu contributions.
168      */
169     public static final Key POPUP_MENU_CONTROL_POSITION    = new KeyOf(Point2D.class, "POPUP_MENU_CONTROL_POSITION");
170
171     /**
172      * Canvas position of mouse on canvas control when the menu was invoked to
173      * be opened. For use by menu contributions.
174      */
175     public static final Key POPUP_MENU_CANVAS_POSITION     = new KeyOf(Point2D.class, "POPUP_MENU_CANVAS_POSITION");
176
177     /**
178      * {@link System#currentTimeMillis()} from the time of processing the popup
179      * menu show event.
180      */
181     public static final Key POPUP_MENU_SHOWN               = new KeyOf(Long.class, "POPUP_MENU_SHOWN");
182
183     /**
184      * {@link System#currentTimeMillis()} from the time of processing the popup
185      * menu hide event.
186      */
187     public static final Key POPUP_MENU_HIDDEN              = new KeyOf(Long.class, "POPUP_MENU_HIDDEN");
188
189     /**
190      * For specifying a user-defined padding for selections
191      *
192      * @since 1.33.0
193      */
194     public static final Key SELECTION_PADDING_SCALE_FACTOR = new KeyOf(Double.class, "SELECTION_PADDING_SCALE_FACTOR");
195
196     /**
197      * An optional cache map that maps scene graph {@link INode}s to
198      * {@link IElement}s to speed up IElement lookups based on SG nodes.
199      * 
200      * @since 1.36.0
201      * @see PickContextImpl
202      * @see ElementPainter
203      */
204     public static final Key NODE_TO_ELEMENT_MAP = new KeyOf(Map.class, "NODE_TO_ELEMENT_MAP");
205
206 }