Lines 15-20
Link Here
|
15 |
import java.util.Iterator; |
15 |
import java.util.Iterator; |
16 |
import java.util.List; |
16 |
import java.util.List; |
17 |
import java.util.Map; |
17 |
import java.util.Map; |
|
|
18 |
import java.util.Collections; |
18 |
|
19 |
|
19 |
import org.eclipse.swt.SWT; |
20 |
import org.eclipse.swt.SWT; |
20 |
import org.eclipse.swt.SWTException; |
21 |
import org.eclipse.swt.SWTException; |
Lines 58-80
Link Here
|
58 |
|
59 |
|
59 |
private boolean updating; |
60 |
private boolean updating; |
60 |
private boolean validating; |
61 |
private boolean validating; |
61 |
private RunnableChain afterUpdate; |
62 |
private List afterUpdate = new ArrayList(); |
62 |
|
|
|
63 |
private static class RunnableChain { |
64 |
RunnableChain next; |
65 |
Runnable run; |
66 |
|
67 |
RunnableChain(Runnable run, RunnableChain next) { |
68 |
this.run = run; |
69 |
this.next = next; |
70 |
} |
71 |
|
72 |
void run() { |
73 |
if (next != null) |
74 |
next.run(); |
75 |
run.run(); |
76 |
} |
77 |
} |
78 |
|
63 |
|
79 |
/** |
64 |
/** |
80 |
* Empty constructor. |
65 |
* Empty constructor. |
Lines 147-155
Link Here
|
147 |
* is being painted. Otherwise, notification already occurs in repairDamage(). |
132 |
* is being painted. Otherwise, notification already occurs in repairDamage(). |
148 |
*/ |
133 |
*/ |
149 |
Rectangle rect = graphics.getClip(new Rectangle()); |
134 |
Rectangle rect = graphics.getClip(new Rectangle()); |
150 |
HashMap map = new HashMap(); |
135 |
firePainting(rect, Collections.singletonMap(root, rect)); |
151 |
map.put(root, rect); |
|
|
152 |
firePainting(rect, map); |
153 |
} |
136 |
} |
154 |
performValidation(); |
137 |
performValidation(); |
155 |
root.paint(graphics); |
138 |
root.paint(graphics); |
Lines 179-190
Link Here
|
179 |
performValidation(); |
162 |
performValidation(); |
180 |
updateQueued = false; |
163 |
updateQueued = false; |
181 |
repairDamage(); |
164 |
repairDamage(); |
182 |
if (afterUpdate != null) { |
165 |
if (!afterUpdate.isEmpty()) { |
183 |
RunnableChain chain = afterUpdate; |
166 |
List work = afterUpdate; |
184 |
afterUpdate = null; |
167 |
afterUpdate = new ArrayList(); |
185 |
chain.run(); //chain may queue additional Runnable. |
168 |
run(work); // additional Runnable may be queued during run |
186 |
if (afterUpdate != null) |
169 |
if (!afterUpdate.isEmpty()) |
187 |
queueWork(); |
170 |
queueWork(); |
188 |
} |
171 |
} |
189 |
} finally { |
172 |
} finally { |
190 |
updating = false; |
173 |
updating = false; |
Lines 192-208
Link Here
|
192 |
} |
175 |
} |
193 |
|
176 |
|
194 |
/** |
177 |
/** |
|
|
178 |
* Runs a list of Runnable. |
179 |
* |
180 |
* @param runnables the list of runnable to run |
181 |
*/ |
182 |
private void run(List runnables) { |
183 |
for(int i=0; i<runnables.size(); ++i) { |
184 |
((Runnable)runnables.get(i)).run(); |
185 |
} |
186 |
} |
187 |
|
188 |
/** |
195 |
* @see UpdateManager#performValidation() |
189 |
* @see UpdateManager#performValidation() |
196 |
*/ |
190 |
*/ |
197 |
public void performValidation() { |
191 |
public void performValidation() { |
198 |
if (invalidFigures.isEmpty() || validating) |
192 |
if (invalidFigures.isEmpty() || validating) |
199 |
return; |
193 |
return; |
200 |
try { |
194 |
try { |
201 |
IFigure fig; |
|
|
202 |
validating = true; |
195 |
validating = true; |
203 |
fireValidating(); |
196 |
fireValidating(); |
204 |
for (int i = 0; i < invalidFigures.size(); i++) { |
197 |
for (int i = 0; i < invalidFigures.size(); i++) { |
205 |
fig = (IFigure) invalidFigures.get(i); |
198 |
IFigure fig = (IFigure) invalidFigures.get(i); |
206 |
invalidFigures.set(i, null); |
199 |
invalidFigures.set(i, null); |
207 |
fig.validate(); |
200 |
fig.validate(); |
208 |
} |
201 |
} |
Lines 260-273
Link Here
|
260 |
*/ |
253 |
*/ |
261 |
protected void repairDamage() { |
254 |
protected void repairDamage() { |
262 |
Iterator keys = dirtyRegions.keySet().iterator(); |
255 |
Iterator keys = dirtyRegions.keySet().iterator(); |
263 |
Rectangle contribution; |
|
|
264 |
IFigure figure; |
265 |
IFigure walker; |
266 |
|
256 |
|
267 |
while (keys.hasNext()) { |
257 |
while (keys.hasNext()) { |
268 |
figure = (IFigure)keys.next(); |
258 |
IFigure figure = (IFigure)keys.next(); |
269 |
walker = figure.getParent(); |
259 |
IFigure walker = figure.getParent(); |
270 |
contribution = (Rectangle)dirtyRegions.get(figure); |
260 |
Rectangle contribution = (Rectangle)dirtyRegions.get(figure); |
271 |
//A figure can't paint beyond its own bounds |
261 |
//A figure can't paint beyond its own bounds |
272 |
contribution.intersect(figure.getBounds()); |
262 |
contribution.intersect(figure.getBounds()); |
273 |
while (!contribution.isEmpty() && walker != null) { |
263 |
while (!contribution.isEmpty() && walker != null) { |
Lines 303-309
Link Here
|
303 |
* @param runnable the runnable |
293 |
* @param runnable the runnable |
304 |
*/ |
294 |
*/ |
305 |
public synchronized void runWithUpdate(Runnable runnable) { |
295 |
public synchronized void runWithUpdate(Runnable runnable) { |
306 |
afterUpdate = new RunnableChain(runnable, afterUpdate); |
296 |
afterUpdate.add(runnable); |
307 |
if (!updating) |
297 |
if (!updating) |
308 |
queueWork(); |
298 |
queueWork(); |
309 |
} |
299 |
} |