]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/canvas/Hints.java
Added mechanism to diagram IFlagType to prevent graph modifications
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / canvas / Hints.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.canvas;
13
14 import java.awt.Color;
15 import java.awt.Paint;
16 import java.awt.dnd.DnDConstants;
17 import java.awt.dnd.DragGestureRecognizer;
18 import java.awt.geom.AffineTransform;
19 import java.awt.geom.Rectangle2D;
20
21 import org.simantics.g2d.canvas.impl.ToolMode;
22 import org.simantics.g2d.dnd.DragInteractor;
23 import org.simantics.g2d.participant.CanvasBoundsParticipant;
24 import org.simantics.utils.datastructures.hints.IHintContext.Key;
25 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
26 import org.simantics.utils.datastructures.hints.IHintContext.MouseSpecificKeyOf;
27 import org.simantics.utils.page.PageDesc;
28
29 /**
30  * @author Toni Kalajainen
31  */
32 public class Hints {
33
34     public static final IToolMode POINTERTOOL              = new ToolMode("PointerTool");
35     public static final IToolMode PANTOOL                  = new ToolMode("PanTool");
36     public static final IToolMode CONNECTTOOL              = new ToolMode("ConnectTool");
37
38     /** Selected Tool */
39     public static final Key KEY_TOOL = new MouseSpecificKeyOf(0, IToolMode.class);
40
41     /** Transform that converts point from canvas to control */
42     public static final Key KEY_CANVAS_TRANSFORM = new KeyOf(AffineTransform.class, "CANVAS_TRANSFORM");
43
44     /**
45      * Rendering surface boundaries.
46      * 
47      * @see CanvasBoundsParticipant
48      */
49     public static final Key KEY_CONTROL_BOUNDS = new KeyOf(Rectangle2D.class, "CONTROL_BOUNDS");
50
51     /**
52      * Visible canvas boundaries.
53      * 
54      * @see CanvasBoundsParticipant
55      */
56     public static final Key KEY_CANVAS_BOUNDS = new KeyOf(Rectangle2D.class, "CANVAS_BOUNDS");
57
58     /** Background color - BackgroundPainter */
59     public static final Key KEY_BACKGROUND_COLOR = new KeyOf(Color.class, "BACKGROUND_COLOR");
60     public static final Key KEY_BACKGROUND_PAINT = new KeyOf(Paint.class, "BACKGROUND_PAINT");
61
62     /** The color of the grid */
63     public static final Key KEY_GRID_COLOR = new KeyOf(Color.class, "GRID_COLOR");
64
65     /** Parent canvas (in hierarchical canvas structure) */
66     public static final Key KEY_SUPER_CANVAS = new KeyOf(ICanvasContext.class, "SUPER_CANVAS");
67
68     /** Description of a page size for canvas or diagram. */
69     public static final Key KEY_PAGE_DESC = new KeyOf(PageDesc.class, "PAGE_DESC");
70
71     /** Indicate whether or not to display page bounds. */
72     public static final Key KEY_DISPLAY_PAGE = new KeyOf(Boolean.class, "DISPLAY_PAGE");
73
74     /** Indicate whether or not to display page margins. */
75     public static final Key KEY_DISPLAY_MARGINS = new KeyOf(Boolean.class, "DISPLAY_MARGINS");
76
77     /**
78      * A hint for disabling painting of the diagram the hint is associated with.
79      * Can also be used with a canvas context to signal that the nothing should
80      * be painted on the canvas.
81      */
82     public static final Key KEY_DISABLE_PAINTING = new KeyOf(Boolean.class, "DISABLE_PAINTING");
83
84     /**
85      * Used by {@link DragInteractor} during its {@link DragGestureRecognizer}
86      * initialization to get the allowed DND actions by the drag source. See
87      * {@link DnDConstants} for the values of which this value can ORed from.
88      */
89     public static final Key KEY_ALLOWED_DRAG_ACTIONS = new KeyOf(Integer.class, "ALLOWED_DRAG_ACTIONS");
90
91     /**
92      * Set to true when the canvas is rendering to a printer
93      */
94     public static final Key KEY_PRINT = new KeyOf(Boolean.class, "PRINTING");
95
96     /**
97      * Set this hint to <code>true</code> to prevent any modifications from
98      * being made to the diagram model by the diagram loading logic. Using this
99      * may be necessary for printing.
100      */
101     public static final Key KEY_DISABLE_GRAPH_MODIFICATIONS = new KeyOf(Boolean.class, "DISABLE_GRAPH_MODIFICATIONS");
102
103     private interface Dirty {}
104
105     /**
106      * The existence of this hint generically used to signal that something in
107      * the related observable has been modified that may cause it to be out of
108      * sync with its visual appearance which is represented by a scene graph.
109      * 
110      * @see #VALUE_DIRTY
111      * 
112      * @author Tuukka Lehtonen
113      */
114     public static final Key KEY_DIRTY = new KeyOf(Dirty.class, "DIRTY");
115
116     /**
117      * The value to use for indicating that the scene graph of an observable may be
118      * dirty and needs to be updated.
119      * 
120      * @see KEY_DIRTY
121      */
122     public static final Dirty VALUE_SG_DIRTY = new Dirty() {
123         @Override
124         public String toString() { return "SG_DIRTY"; }
125     };
126
127     /**
128      * The value to use for indicating that the scene graph of an observable
129      * should be updated after a delay. The delay is left up to the party
130      * tracking this hint value.
131      * 
132      * @see KEY_DIRTY
133      */
134     public static final Dirty VALUE_SG_DELAYED_UPDATE = new Dirty() {
135         @Override
136         public String toString() { return "SG_DELAYED_UPDATE"; }
137     };
138
139     /**
140      * The value to use for indicating that the z-order of diagram elements may
141      * have changed.
142      * 
143      * @see KEY_DIRTY
144      */
145     public static final Dirty VALUE_Z_ORDER_CHANGED = new Dirty() {
146         @Override
147         public String toString() { return "Z_ORDER_CHANGED"; }
148     };
149
150 }