48 |
import java.util.Comparator; |
import java.util.Comparator; |
49 |
import java.util.HashMap; |
import java.util.HashMap; |
50 |
import java.util.Iterator; |
import java.util.Iterator; |
51 |
|
import java.util.WeakHashMap; |
52 |
|
|
53 |
/** |
/** |
54 |
* <p>The repaint manager holds a set of dirty regions, invalid components, |
* <p>The repaint manager holds a set of dirty regions, invalid components, |
66 |
*/ |
*/ |
67 |
public class RepaintManager |
public class RepaintManager |
68 |
{ |
{ |
69 |
|
/** |
70 |
|
* The current repaint managers, indexed by their ThreadGroups. |
71 |
|
*/ |
72 |
|
static WeakHashMap currentRepaintManagers; |
73 |
|
|
74 |
/** |
/** |
75 |
* <p>A helper class which is placed into the system event queue at |
* <p>A helper class which is placed into the system event queue at |
76 |
* various times in order to facilitate repainting and layout. There is |
* various times in order to facilitate repainting and layout. There is |
107 |
|
|
108 |
public void run() |
public void run() |
109 |
{ |
{ |
110 |
RepaintManager rm = RepaintManager.globalManager; |
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); |
111 |
|
RepaintManager rm = |
112 |
|
(RepaintManager) currentRepaintManagers.get(threadGroup); |
113 |
setLive(false); |
setLive(false); |
114 |
rm.validateInvalidComponents(); |
rm.validateInvalidComponents(); |
115 |
rm.paintDirtyRegions(); |
rm.paintDirtyRegions(); |
256 |
|
|
257 |
|
|
258 |
/** |
/** |
|
* The global, shared RepaintManager instance. This is reused for all |
|
|
* components in all windows. This is package-private to avoid an accessor |
|
|
* method. |
|
|
* |
|
|
* @see #currentManager(JComponent) |
|
|
* @see #setCurrentManager |
|
|
*/ |
|
|
static RepaintManager globalManager; |
|
|
|
|
|
/** |
|
259 |
* Create a new RepaintManager object. |
* Create a new RepaintManager object. |
260 |
*/ |
*/ |
261 |
public RepaintManager() |
public RepaintManager() |
272 |
} |
} |
273 |
|
|
274 |
/** |
/** |
275 |
* Get the value of the shared {@link #globalManager} instance, possibly |
* Returns the <code>RepaintManager</code> for the current thread's |
276 |
* returning a special manager associated with the specified |
* thread group. The default implementation ignores the |
277 |
* component. The default implementaiton ignores the component parameter. |
* <code>component</code> parameter and returns the same repaint manager |
278 |
|
* for all components. |
279 |
* |
* |
280 |
* @param component A component to look up the manager of |
* @param component a component to look up the manager of |
281 |
* |
* |
282 |
* @return The current repaint manager |
* @return the current repaint manager for the calling thread's thread group |
283 |
|
* and the specified component |
284 |
* |
* |
285 |
* @see #setCurrentManager |
* @see #setCurrentManager |
286 |
*/ |
*/ |
287 |
public static RepaintManager currentManager(Component component) |
public static RepaintManager currentManager(Component component) |
288 |
{ |
{ |
289 |
if (globalManager == null) |
if (currentRepaintManagers == null) |
290 |
globalManager = new RepaintManager(); |
currentRepaintManagers = new WeakHashMap(); |
291 |
return globalManager; |
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); |
292 |
|
RepaintManager currentManager = |
293 |
|
(RepaintManager) currentRepaintManagers.get(threadGroup); |
294 |
|
if (currentManager == null) |
295 |
|
{ |
296 |
|
currentManager = new RepaintManager(); |
297 |
|
currentRepaintManagers.put(threadGroup, currentManager); |
298 |
|
} |
299 |
|
return currentManager; |
300 |
} |
} |
301 |
|
|
302 |
/** |
/** |
303 |
* Get the value of the shared {@link #globalManager} instance, possibly |
* Returns the <code>RepaintManager</code> for the current thread's |
304 |
* returning a special manager associated with the specified |
* thread group. The default implementation ignores the |
305 |
* component. The default implementaiton ignores the component parameter. |
* <code>component</code> parameter and returns the same repaint manager |
306 |
|
* for all components. |
307 |
* |
* |
308 |
* @param component A component to look up the manager of |
* This method is only here for backwards compatibility with older versions |
309 |
|
* of Swing and simply forwards to {@link #currentManager(Component)}. |
310 |
* |
* |
311 |
* @return The current repaint manager |
* @param component a component to look up the manager of |
312 |
|
* |
313 |
|
* @return the current repaint manager for the calling thread's thread group |
314 |
|
* and the specified component |
315 |
* |
* |
316 |
* @see #setCurrentManager |
* @see #setCurrentManager |
317 |
*/ |
*/ |
321 |
} |
} |
322 |
|
|
323 |
/** |
/** |
324 |
* Set the value of the shared {@link #globalManager} instance. |
* Sets the repaint manager for the calling thread's thread group. |
325 |
* |
* |
326 |
* @param manager The new value of the shared instance |
* @param manager the repaint manager to set for the current thread's thread |
327 |
|
* group |
328 |
* |
* |
329 |
* @see #currentManager(JComponent) |
* @see #currentManager(Component) |
330 |
*/ |
*/ |
331 |
public static void setCurrentManager(RepaintManager manager) |
public static void setCurrentManager(RepaintManager manager) |
332 |
{ |
{ |
333 |
globalManager = manager; |
if (currentRepaintManagers == null) |
334 |
|
currentRepaintManagers = new WeakHashMap(); |
335 |
|
|
336 |
|
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); |
337 |
|
currentRepaintManagers.put(threadGroup, manager); |
338 |
} |
} |
339 |
|
|
340 |
/** |
/** |