comparison org.eclipse.draw2d/src/org/eclipse/draw2d/UpdateManager.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children dbfb303e8fb0
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
1 /*******************************************************************************
2 * Copyright (c) 2000, 2005 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.draw2d.UpdateManager;
14
15 import java.lang.all;
16 import org.eclipse.swt.dwthelper.Runnable;
17
18 import org.eclipse.swt.graphics.GC;
19 import org.eclipse.draw2d.geometry.Rectangle;
20 import org.eclipse.draw2d.IFigure;
21 import org.eclipse.draw2d.UpdateListener;
22 import org.eclipse.draw2d.GraphicsSource;
23
24 /**
25 * Update managers handle the job of laying out and repainting figures. A desirable
26 * implementation is to batches work to be done and collapses any redundant work. For
27 * example, clients may be making multiple changes to figures, which require laying out
28 * the same container or repainting the same region.
29 * <P>
30 * The update manager receives requests to validate certain figures, and repaint certain
31 * areas of figures. An update manager could process every request synchronously, or it
32 * could batch these requests and process them asynchronously.
33 * <P>
34 * The update process occurs in two phases. The first phase is laying out invalid figures.
35 * This phase comes first because it usually introduces additional damage regions. In some
36 * cases, while validating figures, new invalid figures may be appended to the update
37 * manager. Of course, damage regions will be reported too as figures are layed out.
38 * <P>
39 * The second phase is to repaint all damaged areas. The update manager will typically
40 * batch, clip, and union, all rectangles and perform a single paint of the overall
41 * damaged area.
42 *
43 */
44 public abstract class UpdateManager {
45
46 private UpdateListener listeners[];
47 private bool disposed;
48
49 /**
50 * Adds the dirty region defined by the coordinates on the IFigure <b>figure</b>. The
51 * update manager should repaint the dirty region in a timely fashion.
52 *
53 * @param figure the dirty figure
54 * @param x the x coordinate of the dirty region
55 * @param y the y coordinate of the dirty region
56 * @param w the width of the dirty region
57 * @param h the height of the dirty region
58 */
59 public abstract void addDirtyRegion(IFigure figure, int x, int y, int w, int h);
60
61 /**
62 * @see #addDirtyRegion(IFigure, int, int, int, int)
63 */
64 public void addDirtyRegion(IFigure figure, Rectangle rect) {
65 addDirtyRegion(figure, rect.x, rect.y, rect.width, rect.height);
66 }
67
68 /**
69 * Causes an update to occur at some time, and the given runnable to be executed
70 * following the update.
71 * @since 3.1
72 * @param run the runnable
73 */
74 public void runWithUpdate(Runnable run) { }
75
76 /**
77 * The receiver should call validate() on the IFigure <i>figure</i> in a timely fashion.
78 *
79 * @param figure the invalid figure
80 */
81 public abstract void addInvalidFigure(IFigure figure);
82
83 /**
84 * Adds the given listener to the list of listeners to be notified of painting and
85 * validation.
86 * @param listener the listener to add
87 */
88 public void addUpdateListener(UpdateListener listener) {
89 if (listener is null)
90 throw new IllegalArgumentException("");
91 if (listeners is null) {
92 listeners = new UpdateListener[1];
93 listeners[0] = listener;
94 } else {
95 int oldSize = listeners.length;
96 UpdateListener newListeners[] = new UpdateListener[oldSize + 1];
97 SimpleType!(UpdateListener).arraycopy(listeners, 0, newListeners, 0, oldSize);
98 newListeners[oldSize] = listener;
99 listeners = newListeners;
100 }
101 }
102
103 /**
104 * Called when the EditPartViewer is being disposed.
105 */
106 public void dispose() {
107 disposed = true;
108 }
109
110 /**
111 * Notifies listeners that painting is about to occur, passing them the damaged rectangle
112 * and the map of dirty regions.
113 * @param damage the damaged rectangle
114 * @param dirtyRegions map of dirty regions to figures
115 */
116 protected void firePainting(Rectangle damage, Map dirtyRegions) {
117 UpdateListener localListeners[] = listeners;
118 for (int i = 0; i < localListeners.length; i++)
119 localListeners[i].notifyPainting(damage, dirtyRegions);
120 }
121
122 /**
123 * Notifies listeners that validation is about to occur.
124 */
125 protected void fireValidating() {
126 UpdateListener localListeners[] = listeners;
127 for (int i = 0; i < localListeners.length; i++)
128 localListeners[i].notifyValidating();
129 }
130
131 /**
132 * @return whether this update manager has been disposed.
133 */
134 protected bool isDisposed() {
135 return disposed;
136 }
137
138 /**
139 * Forces an update to occur. Update managers will perform updates automatically, but may
140 * do so asynchronously. Calling this method forces a synchronous update.
141 */
142 public abstract void performUpdate();
143
144 void paint(GC gc) {
145 performUpdate(new Rectangle(gc.getClipping()));
146 }
147
148 /**
149 * Performs an update on the given exposed rectangle.
150 * @param exposed the exposed rectangle
151 */
152 public abstract void performUpdate(Rectangle exposed);
153
154 /**
155 * Removes one occurrence of the given UpdateListener by identity.
156 * @param listener the listener to remove
157 */
158 public void removeUpdateListener(UpdateListener listener) {
159 if (listener is null)
160 throw new IllegalArgumentException("");
161 for (int index = 0; index < listeners.length; index++)
162 if (listeners[index] is listener) {
163 int newSize = listeners.length - 1;
164 UpdateListener newListeners[] = null;
165 if (newSize !is 0) {
166 newListeners = new UpdateListener[newSize];
167 SimpleType!(UpdateListener).arraycopy(listeners, 0, newListeners, 0, index);
168 SimpleType!(UpdateListener).arraycopy(listeners, index + 1, newListeners, index, newSize - index);
169 } else {
170 newListeners = new UpdateListener[0];
171 }
172 listeners = newListeners;
173 return;
174 }
175 }
176
177 /**
178 * Sets the GraphicsSource for this update manager.
179 * @param gs the new GraphicsSource
180 */
181 public abstract void setGraphicsSource(GraphicsSource gs);
182
183 /**
184 * Sets the root figure.
185 * @param figure the new root figure
186 */
187 public abstract void setRoot(IFigure figure);
188
189 /**
190 * Performs a partial update if supported (validation only). Fires notification to
191 * listeners that validation has been performed. By default this method calls {@link
192 * #performUpdate()}. Subclasses should override this method to support validation
193 * without repainting.
194 *
195 * @since 3.2
196 */
197 public void performValidation() {
198 performUpdate();
199 }
200
201 }