author | malenkov |
Wed, 30 Apr 2014 19:28:05 +0400 | |
changeset 24544 | c0133e7c7162 |
parent 23328 | 4c53a6ebc779 |
child 24969 | afa6934dd8e8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing; |
|
26 |
||
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.event.*; |
|
30 |
import java.awt.image.VolatileImage; |
|
16092 | 31 |
import java.security.AccessControlContext; |
2 | 32 |
import java.security.AccessController; |
16092 | 33 |
import java.security.PrivilegedAction; |
2 | 34 |
import java.util.*; |
16092 | 35 |
import java.util.concurrent.atomic.AtomicInteger; |
2 | 36 |
import java.applet.*; |
37 |
||
2451 | 38 |
import sun.awt.AWTAccessor; |
2 | 39 |
import sun.awt.AppContext; |
40 |
import sun.awt.DisplayChangedListener; |
|
41 |
import sun.awt.SunToolkit; |
|
42 |
import sun.java2d.SunGraphicsEnvironment; |
|
16092 | 43 |
import sun.misc.JavaSecurityAccess; |
44 |
import sun.misc.SharedSecrets; |
|
2 | 45 |
import sun.security.action.GetPropertyAction; |
46 |
||
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
47 |
import com.sun.java.swing.SwingUtilities3; |
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
48 |
import sun.swing.SwingAccessor; |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
49 |
import sun.swing.SwingUtilities2.RepaintListener; |
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
50 |
|
2 | 51 |
/** |
52 |
* This class manages repaint requests, allowing the number |
|
53 |
* of repaints to be minimized, for example by collapsing multiple |
|
54 |
* requests into a single repaint for members of a component tree. |
|
55 |
* <p> |
|
56 |
* As of 1.6 <code>RepaintManager</code> handles repaint requests |
|
57 |
* for Swing's top level components (<code>JApplet</code>, |
|
58 |
* <code>JWindow</code>, <code>JFrame</code> and <code>JDialog</code>). |
|
59 |
* Any calls to <code>repaint</code> on one of these will call into the |
|
60 |
* appropriate <code>addDirtyRegion</code> method. |
|
61 |
* |
|
62 |
* @author Arnaud Weber |
|
63 |
*/ |
|
64 |
public class RepaintManager |
|
65 |
{ |
|
66 |
/** |
|
67 |
* Whether or not the RepaintManager should handle paint requests |
|
68 |
* for top levels. |
|
69 |
*/ |
|
70 |
static final boolean HANDLE_TOP_LEVEL_PAINT; |
|
71 |
||
72 |
private static final short BUFFER_STRATEGY_NOT_SPECIFIED = 0; |
|
73 |
private static final short BUFFER_STRATEGY_SPECIFIED_ON = 1; |
|
74 |
private static final short BUFFER_STRATEGY_SPECIFIED_OFF = 2; |
|
75 |
||
76 |
private static final short BUFFER_STRATEGY_TYPE; |
|
77 |
||
78 |
/** |
|
79 |
* Maps from GraphicsConfiguration to VolatileImage. |
|
80 |
*/ |
|
81 |
private Map<GraphicsConfiguration,VolatileImage> volatileMap = new |
|
82 |
HashMap<GraphicsConfiguration,VolatileImage>(1); |
|
83 |
||
84 |
// |
|
85 |
// As of 1.6 Swing handles scheduling of paint events from native code. |
|
86 |
// That is, SwingPaintEventDispatcher is invoked on the toolkit thread, |
|
87 |
// which in turn invokes nativeAddDirtyRegion. Because this is invoked |
|
88 |
// from the native thread we can not invoke any public methods and so |
|
89 |
// we introduce these added maps. So, any time nativeAddDirtyRegion is |
|
90 |
// invoked the region is added to hwDirtyComponents and a work request |
|
91 |
// is scheduled. When the work request is processed all entries in |
|
92 |
// this map are pushed to the real map (dirtyComponents) and then |
|
93 |
// painted with the rest of the components. |
|
94 |
// |
|
95 |
private Map<Container,Rectangle> hwDirtyComponents; |
|
96 |
||
97 |
private Map<Component,Rectangle> dirtyComponents; |
|
98 |
private Map<Component,Rectangle> tmpDirtyComponents; |
|
99 |
private java.util.List<Component> invalidComponents; |
|
100 |
||
101 |
// List of Runnables that need to be processed before painting from AWT. |
|
102 |
private java.util.List<Runnable> runnableList; |
|
103 |
||
104 |
boolean doubleBufferingEnabled = true; |
|
105 |
||
106 |
private Dimension doubleBufferMaxSize; |
|
107 |
||
108 |
// Support for both the standard and volatile offscreen buffers exists to |
|
109 |
// provide backwards compatibility for the [rare] programs which may be |
|
110 |
// calling getOffScreenBuffer() and not expecting to get a VolatileImage. |
|
111 |
// Swing internally is migrating to use *only* the volatile image buffer. |
|
112 |
||
113 |
// Support for standard offscreen buffer |
|
114 |
// |
|
115 |
DoubleBufferInfo standardDoubleBuffer; |
|
116 |
||
117 |
/** |
|
118 |
* Object responsible for hanlding core paint functionality. |
|
119 |
*/ |
|
120 |
private PaintManager paintManager; |
|
121 |
||
122 |
private static final Object repaintManagerKey = RepaintManager.class; |
|
123 |
||
124 |
// Whether or not a VolatileImage should be used for double-buffered painting |
|
125 |
static boolean volatileImageBufferEnabled = true; |
|
126 |
/** |
|
13233 | 127 |
* Type of VolatileImage which should be used for double-buffered |
128 |
* painting. |
|
129 |
*/ |
|
130 |
private static final int volatileBufferType; |
|
131 |
/** |
|
2 | 132 |
* Value of the system property awt.nativeDoubleBuffering. |
133 |
*/ |
|
134 |
private static boolean nativeDoubleBuffering; |
|
135 |
||
136 |
// The maximum number of times Swing will attempt to use the VolatileImage |
|
137 |
// buffer during a paint operation. |
|
138 |
private static final int VOLATILE_LOOP_MAX = 2; |
|
139 |
||
140 |
/** |
|
141 |
* Number of <code>beginPaint</code> that have been invoked. |
|
142 |
*/ |
|
143 |
private int paintDepth = 0; |
|
144 |
||
145 |
/** |
|
146 |
* Type of buffer strategy to use. Will be one of the BUFFER_STRATEGY_ |
|
147 |
* constants. |
|
148 |
*/ |
|
149 |
private short bufferStrategyType; |
|
150 |
||
151 |
// |
|
152 |
// BufferStrategyPaintManager has the unique characteristic that it |
|
153 |
// must deal with the buffer being lost while painting to it. For |
|
154 |
// example, if we paint a component and show it and the buffer has |
|
155 |
// become lost we must repaint the whole window. To deal with that |
|
156 |
// the PaintManager calls into repaintRoot, and if we're still in |
|
157 |
// the process of painting the repaintRoot field is set to the JRootPane |
|
158 |
// and after the current JComponent.paintImmediately call finishes |
|
159 |
// paintImmediately will be invoked on the repaintRoot. In this |
|
160 |
// way we don't try to show garbage to the screen. |
|
161 |
// |
|
162 |
/** |
|
163 |
* True if we're in the process of painting the dirty regions. This is |
|
164 |
* set to true in <code>paintDirtyRegions</code>. |
|
165 |
*/ |
|
166 |
private boolean painting; |
|
167 |
/** |
|
168 |
* If the PaintManager calls into repaintRoot during painting this field |
|
169 |
* will be set to the root. |
|
170 |
*/ |
|
171 |
private JComponent repaintRoot; |
|
172 |
||
173 |
/** |
|
174 |
* The Thread that has initiated painting. If null it |
|
175 |
* indicates painting is not currently in progress. |
|
176 |
*/ |
|
177 |
private Thread paintThread; |
|
178 |
||
179 |
/** |
|
180 |
* Runnable used to process all repaint/revalidate requests. |
|
181 |
*/ |
|
182 |
private final ProcessingRunnable processingRunnable; |
|
183 |
||
16092 | 184 |
private final static JavaSecurityAccess javaSecurityAccess = |
185 |
SharedSecrets.getJavaSecurityAccess(); |
|
186 |
||
2 | 187 |
|
188 |
static { |
|
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
189 |
SwingAccessor.setRepaintManagerAccessor(new SwingAccessor.RepaintManagerAccessor() { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
190 |
@Override |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
191 |
public void addRepaintListener(RepaintManager rm, RepaintListener l) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
192 |
rm.addRepaintListener(l); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
193 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
194 |
@Override |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
195 |
public void removeRepaintListener(RepaintManager rm, RepaintListener l) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
196 |
rm.removeRepaintListener(l); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
197 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
198 |
}); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
199 |
|
2 | 200 |
volatileImageBufferEnabled = "true".equals(AccessController. |
201 |
doPrivileged(new GetPropertyAction( |
|
202 |
"swing.volatileImageBufferEnabled", "true"))); |
|
203 |
boolean headless = GraphicsEnvironment.isHeadless(); |
|
204 |
if (volatileImageBufferEnabled && headless) { |
|
205 |
volatileImageBufferEnabled = false; |
|
206 |
} |
|
207 |
nativeDoubleBuffering = "true".equals(AccessController.doPrivileged( |
|
208 |
new GetPropertyAction("awt.nativeDoubleBuffering"))); |
|
209 |
String bs = AccessController.doPrivileged( |
|
210 |
new GetPropertyAction("swing.bufferPerWindow")); |
|
211 |
if (headless) { |
|
212 |
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF; |
|
213 |
} |
|
214 |
else if (bs == null) { |
|
215 |
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_NOT_SPECIFIED; |
|
216 |
} |
|
217 |
else if ("true".equals(bs)) { |
|
218 |
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_ON; |
|
219 |
} |
|
220 |
else { |
|
221 |
BUFFER_STRATEGY_TYPE = BUFFER_STRATEGY_SPECIFIED_OFF; |
|
222 |
} |
|
223 |
HANDLE_TOP_LEVEL_PAINT = "true".equals(AccessController.doPrivileged( |
|
224 |
new GetPropertyAction("swing.handleTopLevelPaint", "true"))); |
|
225 |
GraphicsEnvironment ge = GraphicsEnvironment. |
|
226 |
getLocalGraphicsEnvironment(); |
|
227 |
if (ge instanceof SunGraphicsEnvironment) { |
|
228 |
((SunGraphicsEnvironment)ge).addDisplayChangedListener( |
|
229 |
new DisplayChangedHandler()); |
|
230 |
} |
|
13233 | 231 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
232 |
if ((tk instanceof SunToolkit) |
|
233 |
&& ((SunToolkit) tk).isSwingBackbufferTranslucencySupported()) { |
|
234 |
volatileBufferType = Transparency.TRANSLUCENT; |
|
235 |
} else { |
|
236 |
volatileBufferType = Transparency.OPAQUE; |
|
237 |
} |
|
2 | 238 |
} |
239 |
||
240 |
/** |
|
241 |
* Return the RepaintManager for the calling thread given a Component. |
|
242 |
* |
|
243 |
* @param c a Component -- unused in the default implementation, but could |
|
244 |
* be used by an overridden version to return a different RepaintManager |
|
245 |
* depending on the Component |
|
246 |
* @return the RepaintManager object |
|
247 |
*/ |
|
248 |
public static RepaintManager currentManager(Component c) { |
|
249 |
// Note: DisplayChangedRunnable passes in null as the component, so if |
|
250 |
// component is ever used to determine the current |
|
251 |
// RepaintManager, DisplayChangedRunnable will need to be modified |
|
252 |
// accordingly. |
|
253 |
return currentManager(AppContext.getAppContext()); |
|
254 |
} |
|
255 |
||
256 |
/** |
|
257 |
* Returns the RepaintManager for the specified AppContext. If |
|
258 |
* a RepaintManager has not been created for the specified |
|
259 |
* AppContext this will return null. |
|
260 |
*/ |
|
261 |
static RepaintManager currentManager(AppContext appContext) { |
|
262 |
RepaintManager rm = (RepaintManager)appContext.get(repaintManagerKey); |
|
263 |
if (rm == null) { |
|
264 |
rm = new RepaintManager(BUFFER_STRATEGY_TYPE); |
|
265 |
appContext.put(repaintManagerKey, rm); |
|
266 |
} |
|
267 |
return rm; |
|
268 |
} |
|
269 |
||
270 |
/** |
|
271 |
* Return the RepaintManager for the calling thread given a JComponent. |
|
272 |
* <p> |
|
273 |
* Note: This method exists for backward binary compatibility with earlier |
|
274 |
* versions of the Swing library. It simply returns the result returned by |
|
275 |
* {@link #currentManager(Component)}. |
|
276 |
* |
|
277 |
* @param c a JComponent -- unused |
|
278 |
* @return the RepaintManager object |
|
279 |
*/ |
|
280 |
public static RepaintManager currentManager(JComponent c) { |
|
281 |
return currentManager((Component)c); |
|
282 |
} |
|
283 |
||
284 |
||
285 |
/** |
|
286 |
* Set the RepaintManager that should be used for the calling |
|
287 |
* thread. <b>aRepaintManager</b> will become the current RepaintManager |
|
288 |
* for the calling thread's thread group. |
|
289 |
* @param aRepaintManager the RepaintManager object to use |
|
290 |
*/ |
|
291 |
public static void setCurrentManager(RepaintManager aRepaintManager) { |
|
292 |
if (aRepaintManager != null) { |
|
293 |
SwingUtilities.appContextPut(repaintManagerKey, aRepaintManager); |
|
294 |
} else { |
|
295 |
SwingUtilities.appContextRemove(repaintManagerKey); |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
/** |
|
300 |
* Create a new RepaintManager instance. You rarely call this constructor. |
|
301 |
* directly. To get the default RepaintManager, use |
|
302 |
* RepaintManager.currentManager(JComponent) (normally "this"). |
|
303 |
*/ |
|
304 |
public RepaintManager() { |
|
305 |
// Because we can't know what a subclass is doing with the |
|
306 |
// volatile image we immediately punt in subclasses. If this |
|
307 |
// poses a problem we'll need a more sophisticated detection algorithm, |
|
308 |
// or API. |
|
309 |
this(BUFFER_STRATEGY_SPECIFIED_OFF); |
|
310 |
} |
|
311 |
||
312 |
private RepaintManager(short bufferStrategyType) { |
|
313 |
// If native doublebuffering is being used, do NOT use |
|
314 |
// Swing doublebuffering. |
|
315 |
doubleBufferingEnabled = !nativeDoubleBuffering; |
|
316 |
synchronized(this) { |
|
317 |
dirtyComponents = new IdentityHashMap<Component,Rectangle>(); |
|
318 |
tmpDirtyComponents = new IdentityHashMap<Component,Rectangle>(); |
|
319 |
this.bufferStrategyType = bufferStrategyType; |
|
320 |
hwDirtyComponents = new IdentityHashMap<Container,Rectangle>(); |
|
321 |
} |
|
322 |
processingRunnable = new ProcessingRunnable(); |
|
323 |
} |
|
324 |
||
325 |
private void displayChanged() { |
|
326 |
clearImages(); |
|
327 |
} |
|
328 |
||
329 |
/** |
|
330 |
* Mark the component as in need of layout and queue a runnable |
|
331 |
* for the event dispatching thread that will validate the components |
|
332 |
* first isValidateRoot() ancestor. |
|
333 |
* |
|
334 |
* @see JComponent#isValidateRoot |
|
335 |
* @see #removeInvalidComponent |
|
336 |
*/ |
|
337 |
public synchronized void addInvalidComponent(JComponent invalidComponent) |
|
338 |
{ |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
339 |
RepaintManager delegate = getDelegate(invalidComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
340 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
341 |
delegate.addInvalidComponent(invalidComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
342 |
return; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
343 |
} |
4261 | 344 |
Component validateRoot = |
345 |
SwingUtilities.getValidateRoot(invalidComponent, true); |
|
2 | 346 |
|
347 |
if (validateRoot == null) { |
|
348 |
return; |
|
349 |
} |
|
350 |
||
351 |
/* Lazily create the invalidateComponents vector and add the |
|
352 |
* validateRoot if it's not there already. If this validateRoot |
|
353 |
* is already in the vector, we're done. |
|
354 |
*/ |
|
355 |
if (invalidComponents == null) { |
|
356 |
invalidComponents = new ArrayList<Component>(); |
|
357 |
} |
|
358 |
else { |
|
359 |
int n = invalidComponents.size(); |
|
360 |
for(int i = 0; i < n; i++) { |
|
361 |
if(validateRoot == invalidComponents.get(i)) { |
|
362 |
return; |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
invalidComponents.add(validateRoot); |
|
367 |
||
368 |
// Queue a Runnable to invoke paintDirtyRegions and |
|
369 |
// validateInvalidComponents. |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16092
diff
changeset
|
370 |
scheduleProcessingRunnable(SunToolkit.targetToAppContext(invalidComponent)); |
2 | 371 |
} |
372 |
||
373 |
||
374 |
/** |
|
375 |
* Remove a component from the list of invalid components. |
|
376 |
* |
|
377 |
* @see #addInvalidComponent |
|
378 |
*/ |
|
379 |
public synchronized void removeInvalidComponent(JComponent component) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
380 |
RepaintManager delegate = getDelegate(component); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
381 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
382 |
delegate.removeInvalidComponent(component); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
383 |
return; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
384 |
} |
2 | 385 |
if(invalidComponents != null) { |
386 |
int index = invalidComponents.indexOf(component); |
|
387 |
if(index != -1) { |
|
388 |
invalidComponents.remove(index); |
|
389 |
} |
|
390 |
} |
|
391 |
} |
|
392 |
||
393 |
||
394 |
/** |
|
395 |
* Add a component in the list of components that should be refreshed. |
|
396 |
* If <i>c</i> already has a dirty region, the rectangle <i>(x,y,w,h)</i> |
|
397 |
* will be unioned with the region that should be redrawn. |
|
398 |
* |
|
399 |
* @see JComponent#repaint |
|
400 |
*/ |
|
401 |
private void addDirtyRegion0(Container c, int x, int y, int w, int h) { |
|
402 |
/* Special cases we don't have to bother with. |
|
403 |
*/ |
|
404 |
if ((w <= 0) || (h <= 0) || (c == null)) { |
|
405 |
return; |
|
406 |
} |
|
407 |
||
408 |
if ((c.getWidth() <= 0) || (c.getHeight() <= 0)) { |
|
409 |
return; |
|
410 |
} |
|
411 |
||
412 |
if (extendDirtyRegion(c, x, y, w, h)) { |
|
413 |
// Component was already marked as dirty, region has been |
|
414 |
// extended, no need to continue. |
|
415 |
return; |
|
416 |
} |
|
417 |
||
418 |
/* Make sure that c and all it ancestors (up to an Applet or |
|
419 |
* Window) are visible. This loop has the same effect as |
|
420 |
* checking c.isShowing() (and note that it's still possible |
|
421 |
* that c is completely obscured by an opaque ancestor in |
|
422 |
* the specified rectangle). |
|
423 |
*/ |
|
424 |
Component root = null; |
|
425 |
||
426 |
// Note: We can't synchronize around this, Frame.getExtendedState |
|
427 |
// is synchronized so that if we were to synchronize around this |
|
428 |
// it could lead to the possibility of getting locks out |
|
429 |
// of order and deadlocking. |
|
430 |
for (Container p = c; p != null; p = p.getParent()) { |
|
431 |
if (!p.isVisible() || (p.getPeer() == null)) { |
|
432 |
return; |
|
433 |
} |
|
434 |
if ((p instanceof Window) || (p instanceof Applet)) { |
|
435 |
// Iconified frames are still visible! |
|
436 |
if (p instanceof Frame && |
|
437 |
(((Frame)p).getExtendedState() & Frame.ICONIFIED) == |
|
438 |
Frame.ICONIFIED) { |
|
439 |
return; |
|
440 |
} |
|
441 |
root = p; |
|
442 |
break; |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
if (root == null) return; |
|
447 |
||
448 |
synchronized(this) { |
|
449 |
if (extendDirtyRegion(c, x, y, w, h)) { |
|
450 |
// In between last check and this check another thread |
|
451 |
// queued up runnable, can bail here. |
|
452 |
return; |
|
453 |
} |
|
454 |
dirtyComponents.put(c, new Rectangle(x, y, w, h)); |
|
455 |
} |
|
456 |
||
457 |
// Queue a Runnable to invoke paintDirtyRegions and |
|
458 |
// validateInvalidComponents. |
|
18231
2948d734293d
8011695: [tck-red] Application can not be run, the Security Warning dialog is gray.
leonidr
parents:
16092
diff
changeset
|
459 |
scheduleProcessingRunnable(SunToolkit.targetToAppContext(c)); |
2 | 460 |
} |
461 |
||
462 |
/** |
|
463 |
* Add a component in the list of components that should be refreshed. |
|
464 |
* If <i>c</i> already has a dirty region, the rectangle <i>(x,y,w,h)</i> |
|
465 |
* will be unioned with the region that should be redrawn. |
|
466 |
* |
|
467 |
* @param c Component to repaint, null results in nothing happening. |
|
468 |
* @param x X coordinate of the region to repaint |
|
469 |
* @param y Y coordinate of the region to repaint |
|
470 |
* @param w Width of the region to repaint |
|
471 |
* @param h Height of the region to repaint |
|
472 |
* @see JComponent#repaint |
|
473 |
*/ |
|
474 |
public void addDirtyRegion(JComponent c, int x, int y, int w, int h) |
|
475 |
{ |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
476 |
RepaintManager delegate = getDelegate(c); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
477 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
478 |
delegate.addDirtyRegion(c, x, y, w, h); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
479 |
return; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
480 |
} |
2 | 481 |
addDirtyRegion0(c, x, y, w, h); |
482 |
} |
|
483 |
||
484 |
/** |
|
485 |
* Adds <code>window</code> to the list of <code>Component</code>s that |
|
486 |
* need to be repainted. |
|
487 |
* |
|
488 |
* @param window Window to repaint, null results in nothing happening. |
|
489 |
* @param x X coordinate of the region to repaint |
|
490 |
* @param y Y coordinate of the region to repaint |
|
491 |
* @param w Width of the region to repaint |
|
492 |
* @param h Height of the region to repaint |
|
493 |
* @see JFrame#repaint |
|
494 |
* @see JWindow#repaint |
|
495 |
* @see JDialog#repaint |
|
496 |
* @since 1.6 |
|
497 |
*/ |
|
498 |
public void addDirtyRegion(Window window, int x, int y, int w, int h) { |
|
499 |
addDirtyRegion0(window, x, y, w, h); |
|
500 |
} |
|
501 |
||
502 |
/** |
|
503 |
* Adds <code>applet</code> to the list of <code>Component</code>s that |
|
504 |
* need to be repainted. |
|
505 |
* |
|
506 |
* @param applet Applet to repaint, null results in nothing happening. |
|
507 |
* @param x X coordinate of the region to repaint |
|
508 |
* @param y Y coordinate of the region to repaint |
|
509 |
* @param w Width of the region to repaint |
|
510 |
* @param h Height of the region to repaint |
|
511 |
* @see JApplet#repaint |
|
512 |
* @since 1.6 |
|
513 |
*/ |
|
514 |
public void addDirtyRegion(Applet applet, int x, int y, int w, int h) { |
|
515 |
addDirtyRegion0(applet, x, y, w, h); |
|
516 |
} |
|
517 |
||
518 |
void scheduleHeavyWeightPaints() { |
|
519 |
Map<Container,Rectangle> hws; |
|
520 |
||
521 |
synchronized(this) { |
|
522 |
if (hwDirtyComponents.size() == 0) { |
|
523 |
return; |
|
524 |
} |
|
525 |
hws = hwDirtyComponents; |
|
526 |
hwDirtyComponents = new IdentityHashMap<Container,Rectangle>(); |
|
527 |
} |
|
528 |
for (Container hw : hws.keySet()) { |
|
529 |
Rectangle dirty = hws.get(hw); |
|
530 |
if (hw instanceof Window) { |
|
531 |
addDirtyRegion((Window)hw, dirty.x, dirty.y, |
|
532 |
dirty.width, dirty.height); |
|
533 |
} |
|
534 |
else if (hw instanceof Applet) { |
|
535 |
addDirtyRegion((Applet)hw, dirty.x, dirty.y, |
|
536 |
dirty.width, dirty.height); |
|
537 |
} |
|
538 |
else { // SwingHeavyWeight |
|
539 |
addDirtyRegion0(hw, dirty.x, dirty.y, |
|
540 |
dirty.width, dirty.height); |
|
541 |
} |
|
542 |
} |
|
543 |
} |
|
544 |
||
545 |
// |
|
546 |
// This is called from the toolkit thread when a native expose is |
|
547 |
// received. |
|
548 |
// |
|
549 |
void nativeAddDirtyRegion(AppContext appContext, Container c, |
|
550 |
int x, int y, int w, int h) { |
|
551 |
if (w > 0 && h > 0) { |
|
552 |
synchronized(this) { |
|
553 |
Rectangle dirty = hwDirtyComponents.get(c); |
|
554 |
if (dirty == null) { |
|
555 |
hwDirtyComponents.put(c, new Rectangle(x, y, w, h)); |
|
556 |
} |
|
557 |
else { |
|
558 |
hwDirtyComponents.put(c, SwingUtilities.computeUnion( |
|
559 |
x, y, w, h, dirty)); |
|
560 |
} |
|
561 |
} |
|
562 |
scheduleProcessingRunnable(appContext); |
|
563 |
} |
|
564 |
} |
|
565 |
||
566 |
// |
|
567 |
// This is called from the toolkit thread when awt needs to run a |
|
568 |
// Runnable before we paint. |
|
569 |
// |
|
16092 | 570 |
void nativeQueueSurfaceDataRunnable(AppContext appContext, |
571 |
final Component c, final Runnable r) |
|
572 |
{ |
|
2 | 573 |
synchronized(this) { |
574 |
if (runnableList == null) { |
|
575 |
runnableList = new LinkedList<Runnable>(); |
|
576 |
} |
|
16092 | 577 |
runnableList.add(new Runnable() { |
578 |
public void run() { |
|
579 |
AccessControlContext stack = AccessController.getContext(); |
|
580 |
AccessControlContext acc = |
|
581 |
AWTAccessor.getComponentAccessor().getAccessControlContext(c); |
|
582 |
javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() { |
|
583 |
public Void run() { |
|
584 |
r.run(); |
|
585 |
return null; |
|
586 |
} |
|
587 |
}, stack, acc); |
|
588 |
} |
|
589 |
}); |
|
2 | 590 |
} |
591 |
scheduleProcessingRunnable(appContext); |
|
592 |
} |
|
593 |
||
594 |
/** |
|
595 |
* Extends the dirty region for the specified component to include |
|
596 |
* the new region. |
|
597 |
* |
|
598 |
* @return false if <code>c</code> is not yet marked dirty. |
|
599 |
*/ |
|
600 |
private synchronized boolean extendDirtyRegion( |
|
601 |
Component c, int x, int y, int w, int h) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
602 |
Rectangle r = dirtyComponents.get(c); |
2 | 603 |
if (r != null) { |
604 |
// A non-null r implies c is already marked as dirty, |
|
605 |
// and that the parent is valid. Therefore we can |
|
606 |
// just union the rect and bail. |
|
607 |
SwingUtilities.computeUnion(x, y, w, h, r); |
|
608 |
return true; |
|
609 |
} |
|
610 |
return false; |
|
611 |
} |
|
612 |
||
613 |
/** Return the current dirty region for a component. |
|
614 |
* Return an empty rectangle if the component is not |
|
615 |
* dirty. |
|
616 |
*/ |
|
617 |
public Rectangle getDirtyRegion(JComponent aComponent) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
618 |
RepaintManager delegate = getDelegate(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
619 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
620 |
return delegate.getDirtyRegion(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
621 |
} |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
622 |
Rectangle r; |
2 | 623 |
synchronized(this) { |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
624 |
r = dirtyComponents.get(aComponent); |
2 | 625 |
} |
626 |
if(r == null) |
|
627 |
return new Rectangle(0,0,0,0); |
|
628 |
else |
|
629 |
return new Rectangle(r); |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Mark a component completely dirty. <b>aComponent</b> will be |
|
634 |
* completely painted during the next paintDirtyRegions() call. |
|
635 |
*/ |
|
636 |
public void markCompletelyDirty(JComponent aComponent) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
637 |
RepaintManager delegate = getDelegate(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
638 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
639 |
delegate.markCompletelyDirty(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
640 |
return; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
641 |
} |
2 | 642 |
addDirtyRegion(aComponent,0,0,Integer.MAX_VALUE,Integer.MAX_VALUE); |
643 |
} |
|
644 |
||
645 |
/** |
|
646 |
* Mark a component completely clean. <b>aComponent</b> will not |
|
647 |
* get painted during the next paintDirtyRegions() call. |
|
648 |
*/ |
|
649 |
public void markCompletelyClean(JComponent aComponent) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
650 |
RepaintManager delegate = getDelegate(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
651 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
652 |
delegate.markCompletelyClean(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
653 |
return; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
654 |
} |
2 | 655 |
synchronized(this) { |
656 |
dirtyComponents.remove(aComponent); |
|
657 |
} |
|
658 |
} |
|
659 |
||
660 |
/** |
|
661 |
* Convenience method that returns true if <b>aComponent</b> will be completely |
|
662 |
* painted during the next paintDirtyRegions(). If computing dirty regions is |
|
663 |
* expensive for your component, use this method and avoid computing dirty region |
|
664 |
* if it return true. |
|
665 |
*/ |
|
666 |
public boolean isCompletelyDirty(JComponent aComponent) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
667 |
RepaintManager delegate = getDelegate(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
668 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
669 |
return delegate.isCompletelyDirty(aComponent); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
670 |
} |
2 | 671 |
Rectangle r; |
672 |
||
673 |
r = getDirtyRegion(aComponent); |
|
674 |
if(r.width == Integer.MAX_VALUE && |
|
675 |
r.height == Integer.MAX_VALUE) |
|
676 |
return true; |
|
677 |
else |
|
678 |
return false; |
|
679 |
} |
|
680 |
||
681 |
||
682 |
/** |
|
683 |
* Validate all of the components that have been marked invalid. |
|
684 |
* @see #addInvalidComponent |
|
685 |
*/ |
|
686 |
public void validateInvalidComponents() { |
|
16092 | 687 |
final java.util.List<Component> ic; |
2 | 688 |
synchronized(this) { |
16092 | 689 |
if (invalidComponents == null) { |
2 | 690 |
return; |
691 |
} |
|
692 |
ic = invalidComponents; |
|
693 |
invalidComponents = null; |
|
694 |
} |
|
695 |
int n = ic.size(); |
|
696 |
for(int i = 0; i < n; i++) { |
|
16092 | 697 |
final Component c = ic.get(i); |
698 |
AccessControlContext stack = AccessController.getContext(); |
|
699 |
AccessControlContext acc = |
|
700 |
AWTAccessor.getComponentAccessor().getAccessControlContext(c); |
|
701 |
javaSecurityAccess.doIntersectionPrivilege( |
|
702 |
new PrivilegedAction<Void>() { |
|
703 |
public Void run() { |
|
704 |
c.validate(); |
|
705 |
return null; |
|
706 |
} |
|
707 |
}, stack, acc); |
|
2 | 708 |
} |
709 |
} |
|
710 |
||
711 |
||
712 |
/** |
|
713 |
* This is invoked to process paint requests. It's needed |
|
21278 | 714 |
* for backward compatibility in so far as RepaintManager would previously |
2 | 715 |
* not see paint requests for top levels, so, we have to make sure |
716 |
* a subclass correctly paints any dirty top levels. |
|
717 |
*/ |
|
718 |
private void prePaintDirtyRegions() { |
|
719 |
Map<Component,Rectangle> dirtyComponents; |
|
720 |
java.util.List<Runnable> runnableList; |
|
721 |
synchronized(this) { |
|
722 |
dirtyComponents = this.dirtyComponents; |
|
723 |
runnableList = this.runnableList; |
|
724 |
this.runnableList = null; |
|
725 |
} |
|
726 |
if (runnableList != null) { |
|
727 |
for (Runnable runnable : runnableList) { |
|
728 |
runnable.run(); |
|
729 |
} |
|
730 |
} |
|
731 |
paintDirtyRegions(); |
|
732 |
if (dirtyComponents.size() > 0) { |
|
733 |
// This'll only happen if a subclass isn't correctly dealing |
|
734 |
// with toplevels. |
|
735 |
paintDirtyRegions(dirtyComponents); |
|
736 |
} |
|
737 |
} |
|
738 |
||
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
739 |
private void updateWindows(Map<Component,Rectangle> dirtyComponents) { |
2451 | 740 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
741 |
if (!(toolkit instanceof SunToolkit && |
|
742 |
((SunToolkit)toolkit).needUpdateWindow())) |
|
743 |
{ |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
744 |
return; |
2451 | 745 |
} |
746 |
||
747 |
Set<Window> windows = new HashSet<Window>(); |
|
748 |
Set<Component> dirtyComps = dirtyComponents.keySet(); |
|
749 |
for (Iterator<Component> it = dirtyComps.iterator(); it.hasNext();) { |
|
750 |
Component dirty = it.next(); |
|
751 |
Window window = dirty instanceof Window ? |
|
752 |
(Window)dirty : |
|
753 |
SwingUtilities.getWindowAncestor(dirty); |
|
754 |
if (window != null && |
|
3237 | 755 |
!window.isOpaque()) |
2451 | 756 |
{ |
757 |
windows.add(window); |
|
758 |
} |
|
759 |
} |
|
760 |
||
761 |
for (Window window : windows) { |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
762 |
AWTAccessor.getWindowAccessor().updateWindow(window); |
2451 | 763 |
} |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
764 |
} |
2451 | 765 |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
766 |
boolean isPainting() { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
767 |
return painting; |
2451 | 768 |
} |
769 |
||
2 | 770 |
/** |
771 |
* Paint all of the components that have been marked dirty. |
|
772 |
* |
|
773 |
* @see #addDirtyRegion |
|
774 |
*/ |
|
775 |
public void paintDirtyRegions() { |
|
776 |
synchronized(this) { // swap for thread safety |
|
777 |
Map<Component,Rectangle> tmp = tmpDirtyComponents; |
|
778 |
tmpDirtyComponents = dirtyComponents; |
|
779 |
dirtyComponents = tmp; |
|
780 |
dirtyComponents.clear(); |
|
781 |
} |
|
782 |
paintDirtyRegions(tmpDirtyComponents); |
|
783 |
} |
|
784 |
||
16092 | 785 |
private void paintDirtyRegions( |
786 |
final Map<Component,Rectangle> tmpDirtyComponents) |
|
787 |
{ |
|
788 |
if (tmpDirtyComponents.isEmpty()) { |
|
2 | 789 |
return; |
790 |
} |
|
791 |
||
16092 | 792 |
final java.util.List<Component> roots = |
793 |
new ArrayList<Component>(tmpDirtyComponents.size()); |
|
2 | 794 |
for (Component dirty : tmpDirtyComponents.keySet()) { |
795 |
collectDirtyComponents(tmpDirtyComponents, dirty, roots); |
|
796 |
} |
|
797 |
||
16092 | 798 |
final AtomicInteger count = new AtomicInteger(roots.size()); |
2 | 799 |
painting = true; |
800 |
try { |
|
16092 | 801 |
for (int j=0 ; j < count.get(); j++) { |
802 |
final int i = j; |
|
803 |
final Component dirtyComponent = roots.get(j); |
|
804 |
AccessControlContext stack = AccessController.getContext(); |
|
805 |
AccessControlContext acc = |
|
806 |
AWTAccessor.getComponentAccessor().getAccessControlContext(dirtyComponent); |
|
807 |
javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() { |
|
808 |
public Void run() { |
|
809 |
Rectangle rect = tmpDirtyComponents.get(dirtyComponent); |
|
810 |
// Sometimes when RepaintManager is changed during the painting |
|
811 |
// we may get null here, see #6995769 for details |
|
812 |
if (rect == null) { |
|
813 |
return null; |
|
814 |
} |
|
2 | 815 |
|
16092 | 816 |
int localBoundsH = dirtyComponent.getHeight(); |
817 |
int localBoundsW = dirtyComponent.getWidth(); |
|
818 |
SwingUtilities.computeIntersection(0, |
|
819 |
0, |
|
820 |
localBoundsW, |
|
821 |
localBoundsH, |
|
822 |
rect); |
|
823 |
if (dirtyComponent instanceof JComponent) { |
|
824 |
((JComponent)dirtyComponent).paintImmediately( |
|
825 |
rect.x,rect.y,rect.width, rect.height); |
|
2 | 826 |
} |
16092 | 827 |
else if (dirtyComponent.isShowing()) { |
828 |
Graphics g = JComponent.safelyGetGraphics( |
|
829 |
dirtyComponent, dirtyComponent); |
|
830 |
// If the Graphics goes away, it means someone disposed of |
|
831 |
// the window, don't do anything. |
|
832 |
if (g != null) { |
|
833 |
g.setClip(rect.x, rect.y, rect.width, rect.height); |
|
834 |
try { |
|
835 |
dirtyComponent.paint(g); |
|
836 |
} finally { |
|
837 |
g.dispose(); |
|
838 |
} |
|
839 |
} |
|
840 |
} |
|
841 |
// If the repaintRoot has been set, service it now and |
|
842 |
// remove any components that are children of repaintRoot. |
|
843 |
if (repaintRoot != null) { |
|
844 |
adjustRoots(repaintRoot, roots, i + 1); |
|
845 |
count.set(roots.size()); |
|
846 |
paintManager.isRepaintingRoot = true; |
|
847 |
repaintRoot.paintImmediately(0, 0, repaintRoot.getWidth(), |
|
848 |
repaintRoot.getHeight()); |
|
849 |
paintManager.isRepaintingRoot = false; |
|
850 |
// Only service repaintRoot once. |
|
851 |
repaintRoot = null; |
|
852 |
} |
|
853 |
||
854 |
return null; |
|
2 | 855 |
} |
16092 | 856 |
}, stack, acc); |
2 | 857 |
} |
858 |
} finally { |
|
859 |
painting = false; |
|
860 |
} |
|
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
861 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
862 |
updateWindows(tmpDirtyComponents); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
863 |
|
2 | 864 |
tmpDirtyComponents.clear(); |
865 |
} |
|
866 |
||
867 |
||
868 |
/** |
|
869 |
* Removes any components from roots that are children of |
|
870 |
* root. |
|
871 |
*/ |
|
872 |
private void adjustRoots(JComponent root, |
|
873 |
java.util.List<Component> roots, int index) { |
|
874 |
for (int i = roots.size() - 1; i >= index; i--) { |
|
875 |
Component c = roots.get(i); |
|
876 |
for(;;) { |
|
877 |
if (c == root || c == null || !(c instanceof JComponent)) { |
|
878 |
break; |
|
879 |
} |
|
880 |
c = c.getParent(); |
|
881 |
} |
|
882 |
if (c == root) { |
|
883 |
roots.remove(i); |
|
884 |
} |
|
885 |
} |
|
886 |
} |
|
887 |
||
888 |
Rectangle tmp = new Rectangle(); |
|
889 |
||
890 |
void collectDirtyComponents(Map<Component,Rectangle> dirtyComponents, |
|
891 |
Component dirtyComponent, |
|
892 |
java.util.List<Component> roots) { |
|
893 |
int dx, dy, rootDx, rootDy; |
|
894 |
Component component, rootDirtyComponent,parent; |
|
895 |
Rectangle cBounds; |
|
896 |
||
897 |
// Find the highest parent which is dirty. When we get out of this |
|
898 |
// rootDx and rootDy will contain the translation from the |
|
899 |
// rootDirtyComponent's coordinate system to the coordinates of the |
|
900 |
// original dirty component. The tmp Rect is also used to compute the |
|
901 |
// visible portion of the dirtyRect. |
|
902 |
||
903 |
component = rootDirtyComponent = dirtyComponent; |
|
904 |
||
905 |
int x = dirtyComponent.getX(); |
|
906 |
int y = dirtyComponent.getY(); |
|
907 |
int w = dirtyComponent.getWidth(); |
|
908 |
int h = dirtyComponent.getHeight(); |
|
909 |
||
910 |
dx = rootDx = 0; |
|
911 |
dy = rootDy = 0; |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
912 |
tmp.setBounds(dirtyComponents.get(dirtyComponent)); |
2 | 913 |
|
914 |
// System.out.println("Collect dirty component for bound " + tmp + |
|
915 |
// "component bounds is " + cBounds);; |
|
916 |
SwingUtilities.computeIntersection(0,0,w,h,tmp); |
|
917 |
||
918 |
if (tmp.isEmpty()) { |
|
919 |
// System.out.println("Empty 1"); |
|
920 |
return; |
|
921 |
} |
|
922 |
||
923 |
for(;;) { |
|
924 |
if(!(component instanceof JComponent)) |
|
925 |
break; |
|
926 |
||
927 |
parent = component.getParent(); |
|
928 |
if(parent == null) |
|
929 |
break; |
|
930 |
||
931 |
component = parent; |
|
932 |
||
933 |
dx += x; |
|
934 |
dy += y; |
|
935 |
tmp.setLocation(tmp.x + x, tmp.y + y); |
|
936 |
||
937 |
x = component.getX(); |
|
938 |
y = component.getY(); |
|
939 |
w = component.getWidth(); |
|
940 |
h = component.getHeight(); |
|
941 |
tmp = SwingUtilities.computeIntersection(0,0,w,h,tmp); |
|
942 |
||
943 |
if (tmp.isEmpty()) { |
|
944 |
// System.out.println("Empty 2"); |
|
945 |
return; |
|
946 |
} |
|
947 |
||
948 |
if (dirtyComponents.get(component) != null) { |
|
949 |
rootDirtyComponent = component; |
|
950 |
rootDx = dx; |
|
951 |
rootDy = dy; |
|
952 |
} |
|
953 |
} |
|
954 |
||
955 |
if (dirtyComponent != rootDirtyComponent) { |
|
956 |
Rectangle r; |
|
957 |
tmp.setLocation(tmp.x + rootDx - dx, |
|
958 |
tmp.y + rootDy - dy); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
959 |
r = dirtyComponents.get(rootDirtyComponent); |
2 | 960 |
SwingUtilities.computeUnion(tmp.x,tmp.y,tmp.width,tmp.height,r); |
961 |
} |
|
962 |
||
963 |
// If we haven't seen this root before, then we need to add it to the |
|
964 |
// list of root dirty Views. |
|
965 |
||
966 |
if (!roots.contains(rootDirtyComponent)) |
|
967 |
roots.add(rootDirtyComponent); |
|
968 |
} |
|
969 |
||
970 |
||
971 |
/** |
|
972 |
* Returns a string that displays and identifies this |
|
973 |
* object's properties. |
|
974 |
* |
|
975 |
* @return a String representation of this object |
|
976 |
*/ |
|
977 |
public synchronized String toString() { |
|
978 |
StringBuffer sb = new StringBuffer(); |
|
979 |
if(dirtyComponents != null) |
|
980 |
sb.append("" + dirtyComponents); |
|
981 |
return sb.toString(); |
|
982 |
} |
|
983 |
||
984 |
||
985 |
/** |
|
986 |
* Return the offscreen buffer that should be used as a double buffer with |
|
987 |
* the component <code>c</code>. |
|
988 |
* By default there is a double buffer per RepaintManager. |
|
989 |
* The buffer might be smaller than <code>(proposedWidth,proposedHeight)</code> |
|
990 |
* This happens when the maximum double buffer size as been set for the receiving |
|
991 |
* repaint manager. |
|
992 |
*/ |
|
993 |
public Image getOffscreenBuffer(Component c,int proposedWidth,int proposedHeight) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
994 |
RepaintManager delegate = getDelegate(c); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
995 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
996 |
return delegate.getOffscreenBuffer(c, proposedWidth, proposedHeight); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
997 |
} |
2 | 998 |
return _getOffscreenBuffer(c, proposedWidth, proposedHeight); |
999 |
} |
|
1000 |
||
1001 |
/** |
|
1002 |
* Return a volatile offscreen buffer that should be used as a |
|
1003 |
* double buffer with the specified component <code>c</code>. |
|
1004 |
* The image returned will be an instance of VolatileImage, or null |
|
1005 |
* if a VolatileImage object could not be instantiated. |
|
1006 |
* This buffer might be smaller than <code>(proposedWidth,proposedHeight)</code>. |
|
1007 |
* This happens when the maximum double buffer size has been set for this |
|
1008 |
* repaint manager. |
|
1009 |
* |
|
1010 |
* @see java.awt.image.VolatileImage |
|
1011 |
* @since 1.4 |
|
1012 |
*/ |
|
1013 |
public Image getVolatileOffscreenBuffer(Component c, |
|
1014 |
int proposedWidth,int proposedHeight) { |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1015 |
RepaintManager delegate = getDelegate(c); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1016 |
if (delegate != null) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1017 |
return delegate.getVolatileOffscreenBuffer(c, proposedWidth, |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1018 |
proposedHeight); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1019 |
} |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1020 |
|
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1021 |
// If the window is non-opaque, it's double-buffered at peer's level |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1022 |
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); |
3237 | 1023 |
if (!w.isOpaque()) { |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1024 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1025 |
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1026 |
return null; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1027 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1028 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1029 |
|
2 | 1030 |
GraphicsConfiguration config = c.getGraphicsConfiguration(); |
1031 |
if (config == null) { |
|
1032 |
config = GraphicsEnvironment.getLocalGraphicsEnvironment(). |
|
1033 |
getDefaultScreenDevice().getDefaultConfiguration(); |
|
1034 |
} |
|
1035 |
Dimension maxSize = getDoubleBufferMaximumSize(); |
|
1036 |
int width = proposedWidth < 1 ? 1 : |
|
1037 |
(proposedWidth > maxSize.width? maxSize.width : proposedWidth); |
|
1038 |
int height = proposedHeight < 1 ? 1 : |
|
1039 |
(proposedHeight > maxSize.height? maxSize.height : proposedHeight); |
|
1040 |
VolatileImage image = volatileMap.get(config); |
|
1041 |
if (image == null || image.getWidth() < width || |
|
1042 |
image.getHeight() < height) { |
|
1043 |
if (image != null) { |
|
1044 |
image.flush(); |
|
1045 |
} |
|
13233 | 1046 |
image = config.createCompatibleVolatileImage(width, height, |
1047 |
volatileBufferType); |
|
2 | 1048 |
volatileMap.put(config, image); |
1049 |
} |
|
1050 |
return image; |
|
1051 |
} |
|
1052 |
||
1053 |
private Image _getOffscreenBuffer(Component c, int proposedWidth, int proposedHeight) { |
|
1054 |
Dimension maxSize = getDoubleBufferMaximumSize(); |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
1055 |
DoubleBufferInfo doubleBuffer; |
2 | 1056 |
int width, height; |
1057 |
||
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1058 |
// If the window is non-opaque, it's double-buffered at peer's level |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1059 |
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c); |
3237 | 1060 |
if (!w.isOpaque()) { |
2808
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1061 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1062 |
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) { |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1063 |
return null; |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1064 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1065 |
} |
a139a919f645
6794764: Translucent windows are completely repainted on every paint event, on Windows
art
parents:
2460
diff
changeset
|
1066 |
|
2 | 1067 |
if (standardDoubleBuffer == null) { |
1068 |
standardDoubleBuffer = new DoubleBufferInfo(); |
|
1069 |
} |
|
1070 |
doubleBuffer = standardDoubleBuffer; |
|
1071 |
||
1072 |
width = proposedWidth < 1? 1 : |
|
1073 |
(proposedWidth > maxSize.width? maxSize.width : proposedWidth); |
|
1074 |
height = proposedHeight < 1? 1 : |
|
1075 |
(proposedHeight > maxSize.height? maxSize.height : proposedHeight); |
|
1076 |
||
1077 |
if (doubleBuffer.needsReset || (doubleBuffer.image != null && |
|
1078 |
(doubleBuffer.size.width < width || |
|
1079 |
doubleBuffer.size.height < height))) { |
|
1080 |
doubleBuffer.needsReset = false; |
|
1081 |
if (doubleBuffer.image != null) { |
|
1082 |
doubleBuffer.image.flush(); |
|
1083 |
doubleBuffer.image = null; |
|
1084 |
} |
|
1085 |
width = Math.max(doubleBuffer.size.width, width); |
|
1086 |
height = Math.max(doubleBuffer.size.height, height); |
|
1087 |
} |
|
1088 |
||
1089 |
Image result = doubleBuffer.image; |
|
1090 |
||
1091 |
if (doubleBuffer.image == null) { |
|
1092 |
result = c.createImage(width , height); |
|
1093 |
doubleBuffer.size = new Dimension(width, height); |
|
1094 |
if (c instanceof JComponent) { |
|
1095 |
((JComponent)c).setCreatedDoubleBuffer(true); |
|
1096 |
doubleBuffer.image = result; |
|
1097 |
} |
|
1098 |
// JComponent will inform us when it is no longer valid |
|
1099 |
// (via removeNotify) we have no such hook to other components, |
|
1100 |
// therefore we don't keep a ref to the Component |
|
1101 |
// (indirectly through the Image) by stashing the image. |
|
1102 |
} |
|
1103 |
return result; |
|
1104 |
} |
|
1105 |
||
1106 |
||
1107 |
/** Set the maximum double buffer size. **/ |
|
1108 |
public void setDoubleBufferMaximumSize(Dimension d) { |
|
1109 |
doubleBufferMaxSize = d; |
|
1110 |
if (doubleBufferMaxSize == null) { |
|
1111 |
clearImages(); |
|
1112 |
} else { |
|
1113 |
clearImages(d.width, d.height); |
|
1114 |
} |
|
1115 |
} |
|
1116 |
||
1117 |
private void clearImages() { |
|
1118 |
clearImages(0, 0); |
|
1119 |
} |
|
1120 |
||
1121 |
private void clearImages(int width, int height) { |
|
1122 |
if (standardDoubleBuffer != null && standardDoubleBuffer.image != null) { |
|
1123 |
if (standardDoubleBuffer.image.getWidth(null) > width || |
|
1124 |
standardDoubleBuffer.image.getHeight(null) > height) { |
|
1125 |
standardDoubleBuffer.image.flush(); |
|
1126 |
standardDoubleBuffer.image = null; |
|
1127 |
} |
|
1128 |
} |
|
1129 |
// Clear out the VolatileImages |
|
11268 | 1130 |
Iterator<GraphicsConfiguration> gcs = volatileMap.keySet().iterator(); |
2 | 1131 |
while (gcs.hasNext()) { |
11268 | 1132 |
GraphicsConfiguration gc = gcs.next(); |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
1133 |
VolatileImage image = volatileMap.get(gc); |
2 | 1134 |
if (image.getWidth() > width || image.getHeight() > height) { |
1135 |
image.flush(); |
|
1136 |
gcs.remove(); |
|
1137 |
} |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
1141 |
/** |
|
1142 |
* Returns the maximum double buffer size. |
|
1143 |
* |
|
1144 |
* @return a Dimension object representing the maximum size |
|
1145 |
*/ |
|
1146 |
public Dimension getDoubleBufferMaximumSize() { |
|
1147 |
if (doubleBufferMaxSize == null) { |
|
1148 |
try { |
|
1149 |
Rectangle virtualBounds = new Rectangle(); |
|
1150 |
GraphicsEnvironment ge = GraphicsEnvironment. |
|
1151 |
getLocalGraphicsEnvironment(); |
|
1152 |
for (GraphicsDevice gd : ge.getScreenDevices()) { |
|
1153 |
GraphicsConfiguration gc = gd.getDefaultConfiguration(); |
|
1154 |
virtualBounds = virtualBounds.union(gc.getBounds()); |
|
1155 |
} |
|
1156 |
doubleBufferMaxSize = new Dimension(virtualBounds.width, |
|
1157 |
virtualBounds.height); |
|
1158 |
} catch (HeadlessException e) { |
|
1159 |
doubleBufferMaxSize = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE); |
|
1160 |
} |
|
1161 |
} |
|
1162 |
return doubleBufferMaxSize; |
|
1163 |
} |
|
1164 |
||
1165 |
/** |
|
1166 |
* Enables or disables double buffering in this RepaintManager. |
|
1167 |
* CAUTION: The default value for this property is set for optimal |
|
1168 |
* paint performance on the given platform and it is not recommended |
|
1169 |
* that programs modify this property directly. |
|
1170 |
* |
|
1171 |
* @param aFlag true to activate double buffering |
|
1172 |
* @see #isDoubleBufferingEnabled |
|
1173 |
*/ |
|
1174 |
public void setDoubleBufferingEnabled(boolean aFlag) { |
|
1175 |
doubleBufferingEnabled = aFlag; |
|
1176 |
PaintManager paintManager = getPaintManager(); |
|
1177 |
if (!aFlag && paintManager.getClass() != PaintManager.class) { |
|
1178 |
setPaintManager(new PaintManager()); |
|
1179 |
} |
|
1180 |
} |
|
1181 |
||
1182 |
/** |
|
1183 |
* Returns true if this RepaintManager is double buffered. |
|
1184 |
* The default value for this property may vary from platform |
|
1185 |
* to platform. On platforms where native double buffering |
|
1186 |
* is supported in the AWT, the default value will be <code>false</code> |
|
1187 |
* to avoid unnecessary buffering in Swing. |
|
1188 |
* On platforms where native double buffering is not supported, |
|
1189 |
* the default value will be <code>true</code>. |
|
1190 |
* |
|
1191 |
* @return true if this object is double buffered |
|
1192 |
*/ |
|
1193 |
public boolean isDoubleBufferingEnabled() { |
|
1194 |
return doubleBufferingEnabled; |
|
1195 |
} |
|
1196 |
||
1197 |
/** |
|
1198 |
* This resets the double buffer. Actually, it marks the double buffer |
|
1199 |
* as invalid, the double buffer will then be recreated on the next |
|
1200 |
* invocation of getOffscreenBuffer. |
|
1201 |
*/ |
|
1202 |
void resetDoubleBuffer() { |
|
1203 |
if (standardDoubleBuffer != null) { |
|
1204 |
standardDoubleBuffer.needsReset = true; |
|
1205 |
} |
|
1206 |
} |
|
1207 |
||
1208 |
/** |
|
1209 |
* This resets the volatile double buffer. |
|
1210 |
*/ |
|
1211 |
void resetVolatileDoubleBuffer(GraphicsConfiguration gc) { |
|
1212 |
Image image = volatileMap.remove(gc); |
|
1213 |
if (image != null) { |
|
1214 |
image.flush(); |
|
1215 |
} |
|
1216 |
} |
|
1217 |
||
1218 |
/** |
|
1219 |
* Returns true if we should use the <code>Image</code> returned |
|
1220 |
* from <code>getVolatileOffscreenBuffer</code> to do double buffering. |
|
1221 |
*/ |
|
1222 |
boolean useVolatileDoubleBuffer() { |
|
1223 |
return volatileImageBufferEnabled; |
|
1224 |
} |
|
1225 |
||
1226 |
/** |
|
1227 |
* Returns true if the current thread is the thread painting. This |
|
1228 |
* will return false if no threads are painting. |
|
1229 |
*/ |
|
1230 |
private synchronized boolean isPaintingThread() { |
|
1231 |
return (Thread.currentThread() == paintThread); |
|
1232 |
} |
|
1233 |
// |
|
1234 |
// Paint methods. You very, VERY rarely need to invoke these. |
|
1235 |
// They are invoked directly from JComponent's painting code and |
|
1236 |
// when painting happens outside the normal flow: DefaultDesktopManager |
|
1237 |
// and JViewport. If you end up needing these methods in other places be |
|
1238 |
// careful that you don't get stuck in a paint loop. |
|
1239 |
// |
|
1240 |
||
1241 |
/** |
|
1242 |
* Paints a region of a component |
|
1243 |
* |
|
1244 |
* @param paintingComponent Component to paint |
|
1245 |
* @param bufferComponent Component to obtain buffer for |
|
1246 |
* @param g Graphics to paint to |
|
1247 |
* @param x X-coordinate |
|
1248 |
* @param y Y-coordinate |
|
1249 |
* @param w Width |
|
1250 |
* @param h Height |
|
1251 |
*/ |
|
1252 |
void paint(JComponent paintingComponent, |
|
1253 |
JComponent bufferComponent, Graphics g, |
|
1254 |
int x, int y, int w, int h) { |
|
1255 |
PaintManager paintManager = getPaintManager(); |
|
1256 |
if (!isPaintingThread()) { |
|
1257 |
// We're painting to two threads at once. PaintManager deals |
|
1258 |
// with this a bit better than BufferStrategyPaintManager, use |
|
1259 |
// it to avoid possible exceptions/corruption. |
|
1260 |
if (paintManager.getClass() != PaintManager.class) { |
|
1261 |
paintManager = new PaintManager(); |
|
1262 |
paintManager.repaintManager = this; |
|
1263 |
} |
|
1264 |
} |
|
1265 |
if (!paintManager.paint(paintingComponent, bufferComponent, g, |
|
1266 |
x, y, w, h)) { |
|
1267 |
g.setClip(x, y, w, h); |
|
1268 |
paintingComponent.paintToOffscreen(g, x, y, w, h, x + w, y + h); |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
/** |
|
1273 |
* Does a copy area on the specified region. |
|
1274 |
* |
|
1275 |
* @param clip Whether or not the copyArea needs to be clipped to the |
|
1276 |
* Component's bounds. |
|
1277 |
*/ |
|
1278 |
void copyArea(JComponent c, Graphics g, int x, int y, int w, int h, |
|
1279 |
int deltaX, int deltaY, boolean clip) { |
|
1280 |
getPaintManager().copyArea(c, g, x, y, w, h, deltaX, deltaY, clip); |
|
1281 |
} |
|
1282 |
||
23280
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1283 |
private java.util.List<RepaintListener> repaintListeners = new ArrayList<>(1); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1284 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1285 |
private void addRepaintListener(RepaintListener l) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1286 |
repaintListeners.add(l); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1287 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1288 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1289 |
private void removeRepaintListener(RepaintListener l) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1290 |
repaintListeners.remove(l); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1291 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1292 |
|
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1293 |
/** |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1294 |
* Notify the attached repaint listeners that an area of the {@code c} component |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1295 |
* has been immediately repainted, that is without scheduling a repaint runnable, |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1296 |
* due to performing a "blit" (via calling the {@code copyArea} method). |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1297 |
* |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1298 |
* @param c the component |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1299 |
* @param x the x coordinate of the area |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1300 |
* @param y the y coordinate of the area |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1301 |
* @param w the width of the area |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1302 |
* @param h the height of the area |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1303 |
*/ |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1304 |
void notifyRepaintPerformed(JComponent c, int x, int y, int w, int h) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1305 |
for (RepaintListener l : repaintListeners) { |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1306 |
l.repaintPerformed(c, x, y, w, h); |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1307 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1308 |
} |
df31f522531f
8033233: [JLightweightFrame] support default JViewport BLIT_SCROLL_MODE
ant
parents:
21278
diff
changeset
|
1309 |
|
2 | 1310 |
/** |
1311 |
* Invoked prior to any paint/copyArea method calls. This will |
|
1312 |
* be followed by an invocation of <code>endPaint</code>. |
|
1313 |
* <b>WARNING</b>: Callers of this method need to wrap the call |
|
1314 |
* in a <code>try/finally</code>, otherwise if an exception is thrown |
|
1315 |
* during the course of painting the RepaintManager may |
|
1316 |
* be left in a state in which the screen is not updated, eg: |
|
1317 |
* <pre> |
|
1318 |
* repaintManager.beginPaint(); |
|
1319 |
* try { |
|
1320 |
* repaintManager.paint(...); |
|
1321 |
* } finally { |
|
1322 |
* repaintManager.endPaint(); |
|
1323 |
* } |
|
1324 |
* </pre> |
|
1325 |
*/ |
|
1326 |
void beginPaint() { |
|
1327 |
boolean multiThreadedPaint = false; |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
1291
diff
changeset
|
1328 |
int paintDepth; |
2 | 1329 |
Thread currentThread = Thread.currentThread(); |
1330 |
synchronized(this) { |
|
1331 |
paintDepth = this.paintDepth; |
|
1332 |
if (paintThread == null || currentThread == paintThread) { |
|
1333 |
paintThread = currentThread; |
|
1334 |
this.paintDepth++; |
|
1335 |
} else { |
|
1336 |
multiThreadedPaint = true; |
|
1337 |
} |
|
1338 |
} |
|
1339 |
if (!multiThreadedPaint && paintDepth == 0) { |
|
1340 |
getPaintManager().beginPaint(); |
|
1341 |
} |
|
1342 |
} |
|
1343 |
||
1344 |
/** |
|
1345 |
* Invoked after <code>beginPaint</code> has been invoked. |
|
1346 |
*/ |
|
1347 |
void endPaint() { |
|
1348 |
if (isPaintingThread()) { |
|
1349 |
PaintManager paintManager = null; |
|
1350 |
synchronized(this) { |
|
1351 |
if (--paintDepth == 0) { |
|
1352 |
paintManager = getPaintManager(); |
|
1353 |
} |
|
1354 |
} |
|
1355 |
if (paintManager != null) { |
|
1356 |
paintManager.endPaint(); |
|
1357 |
synchronized(this) { |
|
1358 |
paintThread = null; |
|
1359 |
} |
|
1360 |
} |
|
1361 |
} |
|
1362 |
} |
|
1363 |
||
1364 |
/** |
|
1365 |
* If possible this will show a previously rendered portion of |
|
1366 |
* a Component. If successful, this will return true, otherwise false. |
|
1367 |
* <p> |
|
1368 |
* WARNING: This method is invoked from the native toolkit thread, be |
|
1369 |
* very careful as to what methods this invokes! |
|
1370 |
*/ |
|
1371 |
boolean show(Container c, int x, int y, int w, int h) { |
|
1372 |
return getPaintManager().show(c, x, y, w, h); |
|
1373 |
} |
|
1374 |
||
1375 |
/** |
|
1376 |
* Invoked when the doubleBuffered or useTrueDoubleBuffering |
|
1377 |
* properties of a JRootPane change. This may come in on any thread. |
|
1378 |
*/ |
|
1379 |
void doubleBufferingChanged(JRootPane rootPane) { |
|
1380 |
getPaintManager().doubleBufferingChanged(rootPane); |
|
1381 |
} |
|
1382 |
||
1383 |
/** |
|
1384 |
* Sets the <code>PaintManager</code> that is used to handle all |
|
1385 |
* double buffered painting. |
|
1386 |
* |
|
1387 |
* @param paintManager The PaintManager to use. Passing in null indicates |
|
1388 |
* the fallback PaintManager should be used. |
|
1389 |
*/ |
|
1390 |
void setPaintManager(PaintManager paintManager) { |
|
1391 |
if (paintManager == null) { |
|
1392 |
paintManager = new PaintManager(); |
|
1393 |
} |
|
1394 |
PaintManager oldPaintManager; |
|
1395 |
synchronized(this) { |
|
1396 |
oldPaintManager = this.paintManager; |
|
1397 |
this.paintManager = paintManager; |
|
1398 |
paintManager.repaintManager = this; |
|
1399 |
} |
|
1400 |
if (oldPaintManager != null) { |
|
1401 |
oldPaintManager.dispose(); |
|
1402 |
} |
|
1403 |
} |
|
1404 |
||
1405 |
private synchronized PaintManager getPaintManager() { |
|
1406 |
if (paintManager == null) { |
|
1407 |
PaintManager paintManager = null; |
|
1408 |
if (doubleBufferingEnabled && !nativeDoubleBuffering) { |
|
1409 |
switch (bufferStrategyType) { |
|
1410 |
case BUFFER_STRATEGY_NOT_SPECIFIED: |
|
1832
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1411 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1412 |
if (tk instanceof SunToolkit) { |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1413 |
SunToolkit stk = (SunToolkit) tk; |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1414 |
if (stk.useBufferPerWindow()) { |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1415 |
paintManager = new BufferStrategyPaintManager(); |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1416 |
} |
2 | 1417 |
} |
1418 |
break; |
|
1419 |
case BUFFER_STRATEGY_SPECIFIED_ON: |
|
1420 |
paintManager = new BufferStrategyPaintManager(); |
|
1421 |
break; |
|
1422 |
default: |
|
1423 |
break; |
|
1424 |
} |
|
1425 |
} |
|
1426 |
// null case handled in setPaintManager |
|
1427 |
setPaintManager(paintManager); |
|
1428 |
} |
|
1429 |
return paintManager; |
|
1430 |
} |
|
1431 |
||
1432 |
private void scheduleProcessingRunnable(AppContext context) { |
|
1433 |
if (processingRunnable.markPending()) { |
|
1832
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1434 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1435 |
if (tk instanceof SunToolkit) { |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1436 |
SunToolkit.getSystemEventQueueImplPP(context). |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1437 |
postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1438 |
processingRunnable)); |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1439 |
} else { |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1440 |
Toolkit.getDefaultToolkit().getSystemEventQueue(). |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1441 |
postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1442 |
processingRunnable)); |
0a885bee1070
6759311: RepaintManager casts Tookit to SunToolkit without instanceof check
rkennke
parents:
1301
diff
changeset
|
1443 |
} |
2 | 1444 |
} |
1445 |
} |
|
1446 |
||
1447 |
||
1448 |
/** |
|
1449 |
* PaintManager is used to handle all double buffered painting for |
|
1450 |
* Swing. Subclasses should call back into the JComponent method |
|
1451 |
* <code>paintToOffscreen</code> to handle the actual painting. |
|
1452 |
*/ |
|
1453 |
static class PaintManager { |
|
1454 |
/** |
|
1455 |
* RepaintManager the PaintManager has been installed on. |
|
1456 |
*/ |
|
1457 |
protected RepaintManager repaintManager; |
|
1458 |
boolean isRepaintingRoot; |
|
1459 |
||
1460 |
/** |
|
1461 |
* Paints a region of a component |
|
1462 |
* |
|
1463 |
* @param paintingComponent Component to paint |
|
1464 |
* @param bufferComponent Component to obtain buffer for |
|
1465 |
* @param g Graphics to paint to |
|
1466 |
* @param x X-coordinate |
|
1467 |
* @param y Y-coordinate |
|
1468 |
* @param w Width |
|
1469 |
* @param h Height |
|
1470 |
* @return true if painting was successful. |
|
1471 |
*/ |
|
1472 |
public boolean paint(JComponent paintingComponent, |
|
1473 |
JComponent bufferComponent, Graphics g, |
|
1474 |
int x, int y, int w, int h) { |
|
1475 |
// First attempt to use VolatileImage buffer for performance. |
|
1476 |
// If this fails (which should rarely occur), fallback to a |
|
1477 |
// standard Image buffer. |
|
1478 |
boolean paintCompleted = false; |
|
1479 |
Image offscreen; |
|
1480 |
if (repaintManager.useVolatileDoubleBuffer() && |
|
1481 |
(offscreen = getValidImage(repaintManager. |
|
1482 |
getVolatileOffscreenBuffer(bufferComponent, w, h))) != null) { |
|
1483 |
VolatileImage vImage = (java.awt.image.VolatileImage)offscreen; |
|
1484 |
GraphicsConfiguration gc = bufferComponent. |
|
1485 |
getGraphicsConfiguration(); |
|
1486 |
for (int i = 0; !paintCompleted && |
|
1487 |
i < RepaintManager.VOLATILE_LOOP_MAX; i++) { |
|
1488 |
if (vImage.validate(gc) == |
|
1489 |
VolatileImage.IMAGE_INCOMPATIBLE) { |
|
1490 |
repaintManager.resetVolatileDoubleBuffer(gc); |
|
1491 |
offscreen = repaintManager.getVolatileOffscreenBuffer( |
|
1492 |
bufferComponent,w, h); |
|
1493 |
vImage = (java.awt.image.VolatileImage)offscreen; |
|
1494 |
} |
|
1495 |
paintDoubleBuffered(paintingComponent, vImage, g, x, y, |
|
1496 |
w, h); |
|
1497 |
paintCompleted = !vImage.contentsLost(); |
|
1498 |
} |
|
1499 |
} |
|
1500 |
// VolatileImage painting loop failed, fallback to regular |
|
1501 |
// offscreen buffer |
|
1502 |
if (!paintCompleted && (offscreen = getValidImage( |
|
1503 |
repaintManager.getOffscreenBuffer( |
|
1504 |
bufferComponent, w, h))) != null) { |
|
1505 |
paintDoubleBuffered(paintingComponent, offscreen, g, x, y, w, |
|
1506 |
h); |
|
1507 |
paintCompleted = true; |
|
1508 |
} |
|
1509 |
return paintCompleted; |
|
1510 |
} |
|
1511 |
||
1512 |
/** |
|
1513 |
* Does a copy area on the specified region. |
|
1514 |
*/ |
|
1515 |
public void copyArea(JComponent c, Graphics g, int x, int y, int w, |
|
1516 |
int h, int deltaX, int deltaY, boolean clip) { |
|
1517 |
g.copyArea(x, y, w, h, deltaX, deltaY); |
|
1518 |
} |
|
1519 |
||
1520 |
/** |
|
1521 |
* Invoked prior to any calls to paint or copyArea. |
|
1522 |
*/ |
|
1523 |
public void beginPaint() { |
|
1524 |
} |
|
1525 |
||
1526 |
/** |
|
1527 |
* Invoked to indicate painting has been completed. |
|
1528 |
*/ |
|
1529 |
public void endPaint() { |
|
1530 |
} |
|
1531 |
||
1532 |
/** |
|
1533 |
* Shows a region of a previously rendered component. This |
|
1534 |
* will return true if successful, false otherwise. The default |
|
1535 |
* implementation returns false. |
|
1536 |
*/ |
|
1537 |
public boolean show(Container c, int x, int y, int w, int h) { |
|
1538 |
return false; |
|
1539 |
} |
|
1540 |
||
1541 |
/** |
|
1542 |
* Invoked when the doubleBuffered or useTrueDoubleBuffering |
|
1543 |
* properties of a JRootPane change. This may come in on any thread. |
|
1544 |
*/ |
|
1545 |
public void doubleBufferingChanged(JRootPane rootPane) { |
|
1546 |
} |
|
1547 |
||
1548 |
/** |
|
1549 |
* Paints a portion of a component to an offscreen buffer. |
|
1550 |
*/ |
|
1551 |
protected void paintDoubleBuffered(JComponent c, Image image, |
|
1552 |
Graphics g, int clipX, int clipY, |
|
1553 |
int clipW, int clipH) { |
|
1554 |
Graphics osg = image.getGraphics(); |
|
1555 |
int bw = Math.min(clipW, image.getWidth(null)); |
|
1556 |
int bh = Math.min(clipH, image.getHeight(null)); |
|
1557 |
int x,y,maxx,maxy; |
|
1558 |
||
1559 |
try { |
|
1560 |
for(x = clipX, maxx = clipX+clipW; x < maxx ; x += bw ) { |
|
1561 |
for(y=clipY, maxy = clipY + clipH; y < maxy ; y += bh) { |
|
1562 |
osg.translate(-x, -y); |
|
1563 |
osg.setClip(x,y,bw,bh); |
|
13233 | 1564 |
if (volatileBufferType != Transparency.OPAQUE |
1565 |
&& osg instanceof Graphics2D) { |
|
1566 |
final Graphics2D g2d = (Graphics2D) osg; |
|
1567 |
final Color oldBg = g2d.getBackground(); |
|
1568 |
g2d.setBackground(c.getBackground()); |
|
1569 |
g2d.clearRect(x, y, bw, bh); |
|
1570 |
g2d.setBackground(oldBg); |
|
1571 |
} |
|
2 | 1572 |
c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy); |
1573 |
g.setClip(x, y, bw, bh); |
|
13233 | 1574 |
if (volatileBufferType != Transparency.OPAQUE |
1575 |
&& g instanceof Graphics2D) { |
|
1576 |
final Graphics2D g2d = (Graphics2D) g; |
|
1577 |
final Composite oldComposite = g2d.getComposite(); |
|
1578 |
g2d.setComposite(AlphaComposite.Src); |
|
1579 |
g2d.drawImage(image, x, y, c); |
|
1580 |
g2d.setComposite(oldComposite); |
|
1581 |
} else { |
|
1582 |
g.drawImage(image, x, y, c); |
|
1583 |
} |
|
2 | 1584 |
osg.translate(x, y); |
1585 |
} |
|
1586 |
} |
|
1587 |
} finally { |
|
1588 |
osg.dispose(); |
|
1589 |
} |
|
1590 |
} |
|
1591 |
||
1592 |
/** |
|
1593 |
* If <code>image</code> is non-null with a positive size it |
|
1594 |
* is returned, otherwise null is returned. |
|
1595 |
*/ |
|
1596 |
private Image getValidImage(Image image) { |
|
1597 |
if (image != null && image.getWidth(null) > 0 && |
|
1598 |
image.getHeight(null) > 0) { |
|
1599 |
return image; |
|
1600 |
} |
|
1601 |
return null; |
|
1602 |
} |
|
1603 |
||
1604 |
/** |
|
1605 |
* Schedules a repaint for the specified component. This differs |
|
1606 |
* from <code>root.repaint</code> in that if the RepaintManager is |
|
1607 |
* currently processing paint requests it'll process this request |
|
1608 |
* with the current set of requests. |
|
1609 |
*/ |
|
1610 |
protected void repaintRoot(JComponent root) { |
|
1611 |
assert (repaintManager.repaintRoot == null); |
|
1612 |
if (repaintManager.painting) { |
|
1613 |
repaintManager.repaintRoot = root; |
|
1614 |
} |
|
1615 |
else { |
|
1616 |
root.repaint(); |
|
1617 |
} |
|
1618 |
} |
|
1619 |
||
1620 |
/** |
|
1621 |
* Returns true if the component being painted is the root component |
|
1622 |
* that was previously passed to <code>repaintRoot</code>. |
|
1623 |
*/ |
|
1624 |
protected boolean isRepaintingRoot() { |
|
1625 |
return isRepaintingRoot; |
|
1626 |
} |
|
1627 |
||
1628 |
/** |
|
1629 |
* Cleans up any state. After invoked the PaintManager will no |
|
1630 |
* longer be used anymore. |
|
1631 |
*/ |
|
1632 |
protected void dispose() { |
|
1633 |
} |
|
1634 |
} |
|
1635 |
||
1636 |
||
1637 |
private class DoubleBufferInfo { |
|
1638 |
public Image image; |
|
1639 |
public Dimension size; |
|
1640 |
public boolean needsReset = false; |
|
1641 |
} |
|
1642 |
||
1643 |
||
1644 |
/** |
|
1645 |
* Listener installed to detect display changes. When display changes, |
|
1646 |
* schedules a callback to notify all RepaintManagers of the display |
|
1647 |
* changes. Only one DisplayChangedHandler is ever installed. The |
|
1648 |
* singleton instance will schedule notification for all AppContexts. |
|
1649 |
*/ |
|
1650 |
private static final class DisplayChangedHandler implements |
|
1651 |
DisplayChangedListener { |
|
1652 |
public void displayChanged() { |
|
1653 |
scheduleDisplayChanges(); |
|
1654 |
} |
|
1655 |
||
1656 |
public void paletteChanged() { |
|
1657 |
} |
|
1658 |
||
1659 |
private void scheduleDisplayChanges() { |
|
1660 |
// To avoid threading problems, we notify each RepaintManager |
|
1661 |
// on the thread it was created on. |
|
1662 |
for (Object c : AppContext.getAppContexts()) { |
|
1663 |
AppContext context = (AppContext) c; |
|
1664 |
synchronized(context) { |
|
1665 |
if (!context.isDisposed()) { |
|
1666 |
EventQueue eventQueue = (EventQueue)context.get( |
|
1667 |
AppContext.EVENT_QUEUE_KEY); |
|
1668 |
if (eventQueue != null) { |
|
1669 |
eventQueue.postEvent(new InvocationEvent( |
|
1670 |
Toolkit.getDefaultToolkit(), |
|
1671 |
new DisplayChangedRunnable())); |
|
1672 |
} |
|
1673 |
} |
|
1674 |
} |
|
1675 |
} |
|
1676 |
} |
|
1677 |
} |
|
1678 |
||
1679 |
||
1680 |
private static final class DisplayChangedRunnable implements Runnable { |
|
1681 |
public void run() { |
|
1682 |
RepaintManager.currentManager((JComponent)null).displayChanged(); |
|
1683 |
} |
|
1684 |
} |
|
1685 |
||
1686 |
||
1687 |
/** |
|
1688 |
* Runnable used to process all repaint/revalidate requests. |
|
1689 |
*/ |
|
1690 |
private final class ProcessingRunnable implements Runnable { |
|
1691 |
// If true, we're wainting on the EventQueue. |
|
1692 |
private boolean pending; |
|
1693 |
||
1694 |
/** |
|
1695 |
* Marks this processing runnable as pending. If this was not |
|
1696 |
* already marked as pending, true is returned. |
|
1697 |
*/ |
|
1698 |
public synchronized boolean markPending() { |
|
1699 |
if (!pending) { |
|
1700 |
pending = true; |
|
1701 |
return true; |
|
1702 |
} |
|
1703 |
return false; |
|
1704 |
} |
|
1705 |
||
1706 |
public void run() { |
|
1707 |
synchronized (this) { |
|
1708 |
pending = false; |
|
1709 |
} |
|
1710 |
// First pass, flush any heavy paint events into real paint |
|
1711 |
// events. If there are pending heavy weight requests this will |
|
1712 |
// result in q'ing this request up one more time. As |
|
1713 |
// long as no other requests come in between now and the time |
|
1714 |
// the second one is processed nothing will happen. This is not |
|
1715 |
// ideal, but the logic needed to suppress the second request is |
|
1716 |
// more headache than it's worth. |
|
1717 |
scheduleHeavyWeightPaints(); |
|
1718 |
// Do the actual validation and painting. |
|
1719 |
validateInvalidComponents(); |
|
1720 |
prePaintDirtyRegions(); |
|
1721 |
} |
|
1722 |
} |
|
1291
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1723 |
private RepaintManager getDelegate(Component c) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1724 |
RepaintManager delegate = SwingUtilities3.getDelegateRepaintManager(c); |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1725 |
if (this == delegate) { |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1726 |
delegate = null; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1727 |
} |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1728 |
return delegate; |
e56898d6642d
6608456: need API to define RepaintManager per components hierarchy
idk
parents:
2
diff
changeset
|
1729 |
} |
2 | 1730 |
} |