248024436865a526565b90cf6d4a33af043c087a
[jalviewjs.git] / site / swingjs / j2s / javax / swing / RepaintManager.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["java.util.HashMap", "java.awt.Rectangle"], "javax.swing.RepaintManager", ["java.lang.StringBuffer", "$.Thread", "java.util.ArrayList", "$.HashSet", "$.IdentityHashMap", "java.applet.Applet", "java.awt.Frame", "$.Toolkit", "$.Window", "java.awt.event.InvocationEvent", "javax.swing.CellRendererPane", "$.JComponent", "$.SwingUtilities", "jssun.awt.AWTAccessor", "$.AppContext", "$.SunToolkit", "swingjs.JSToolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.volatileMap = null;
5 this.hwDirtyComponents = null;
6 this.dirtyComponents = null;
7 this.tmpDirtyComponents = null;
8 this.invalidComponents = null;
9 this.runnableList = null;
10 this.paintDepth = 0;
11 this.painting = false;
12 this.repaintRoot = null;
13 this.paintThread = null;
14 this.processingRunnable = null;
15 this.myComponent = null;
16 this.tmp = null;
17 if (!Clazz.isClassDefined ("javax.swing.RepaintManager.ProcessingRunnable")) {
18 javax.swing.RepaintManager.$RepaintManager$ProcessingRunnable$ ();
19 }
20 Clazz.instantialize (this, arguments);
21 }, javax.swing, "RepaintManager");
22 Clazz.prepareFields (c$, function () {
23 this.volatileMap =  new java.util.HashMap (1);
24 this.tmp =  new java.awt.Rectangle ();
25 });
26 c$.currentManager = Clazz.defineMethod (c$, "currentManager", 
27 function (c) {
28 var appContext = jssun.awt.AppContext.getAppContext ();
29 var rm = appContext.get (javax.swing.RepaintManager.repaintManagerKey);
30 if (rm == null) {
31 rm =  new javax.swing.RepaintManager ();
32 rm.set (c);
33 appContext.put (javax.swing.RepaintManager.repaintManagerKey, rm);
34 }return rm;
35 }, "java.awt.Component");
36 c$.setCurrentManager = Clazz.defineMethod (c$, "setCurrentManager", 
37 function (aRepaintManager) {
38 if (aRepaintManager != null) {
39 javax.swing.SwingUtilities.appContextPut (javax.swing.RepaintManager.repaintManagerKey, aRepaintManager);
40 } else {
41 javax.swing.SwingUtilities.appContextRemove (javax.swing.RepaintManager.repaintManagerKey);
42 }}, "javax.swing.RepaintManager");
43 Clazz.makeConstructor (c$, 
44  function () {
45 this.processingRunnable = Clazz.innerTypeInstance (javax.swing.RepaintManager.ProcessingRunnable, this, null);
46 });
47 Clazz.defineMethod (c$, "set", 
48  function (c) {
49 this.myComponent = c;
50 this.dirtyComponents =  new java.util.IdentityHashMap ();
51 this.tmpDirtyComponents =  new java.util.IdentityHashMap ();
52 this.hwDirtyComponents =  new java.util.IdentityHashMap ();
53 }, "java.awt.Component");
54 Clazz.defineMethod (c$, "addInvalidComponent", 
55 function (invalidComponent) {
56 var validateRoot = null;
57 for (var c = invalidComponent; c != null; c = c.getParent ()) {
58 if ((Clazz.instanceOf (c, javax.swing.CellRendererPane))) {
59 return;
60 }if ((Clazz.instanceOf (c, javax.swing.JComponent)) && ((c).isValidateRoot ())) {
61 validateRoot = c;
62 break;
63 }}
64 if (validateRoot == null) {
65 return;
66 }var root = null;
67 for (var c = validateRoot; c != null; c = c.getParent ()) {
68 if (!c.isVisible ()) {
69 return;
70 }if ((Clazz.instanceOf (c, java.awt.Window)) || (Clazz.instanceOf (c, java.applet.Applet))) {
71 root = c;
72 break;
73 }}
74 if (root == null) {
75 return;
76 }if (this.invalidComponents == null) {
77 this.invalidComponents =  new java.util.ArrayList ();
78 } else {
79 var n = this.invalidComponents.size ();
80 for (var i = 0; i < n; i++) {
81 if (validateRoot === this.invalidComponents.get (i)) {
82 return;
83 }}
84 }this.invalidComponents.add (validateRoot);
85 this.scheduleProcessingRunnable (root);
86 }, "javax.swing.JComponent");
87 Clazz.defineMethod (c$, "removeInvalidComponent", 
88 function (component) {
89 if (this.invalidComponents != null) {
90 var index = this.invalidComponents.indexOf (component);
91 if (index != -1) {
92 this.invalidComponents.remove (index);
93 }}}, "javax.swing.JComponent");
94 Clazz.defineMethod (c$, "addDirtyRegion0", 
95  function (c, x, y, w, h) {
96 {
97 var g = c.getGraphics();
98 if (g == null || g.gc == null)return;
99 }if ((w <= 0) || (h <= 0) || (c == null)) {
100 return;
101 }if ((c.getWidth () <= 0) || (c.getHeight () <= 0)) {
102 return;
103 }if (this.extendDirtyRegion (c, x, y, w, h)) {
104 return;
105 }var root = null;
106 for (var p = c; p != null; p = p.getParent ()) {
107 if (!p.isVisible () || p.getPeer () == null) {
108 return;
109 }if ((Clazz.instanceOf (p, java.awt.Window)) || (Clazz.instanceOf (p, java.applet.Applet))) {
110 if (Clazz.instanceOf (p, java.awt.Frame) && ((p).getExtendedState () & 1) == 1) {
111 return;
112 }root = p;
113 break;
114 }}
115 if (root == null) return;
116 {
117 if (this.extendDirtyRegion (c, x, y, w, h)) {
118 return;
119 }this.dirtyComponents.put (c,  new java.awt.Rectangle (x, y, w, h));
120 }this.scheduleProcessingRunnable (c);
121 }, "java.awt.Container,~N,~N,~N,~N");
122 Clazz.defineMethod (c$, "addDirtyRegion", 
123 function (c, x, y, w, h) {
124 this.addDirtyRegion0 (c, x, y, w, h);
125 }, "javax.swing.JComponent,~N,~N,~N,~N");
126 Clazz.defineMethod (c$, "addDirtyRegion", 
127 function (window, x, y, w, h) {
128 this.addDirtyRegion0 (window, x, y, w, h);
129 }, "java.awt.Window,~N,~N,~N,~N");
130 Clazz.defineMethod (c$, "addDirtyRegion", 
131 function (applet, x, y, w, h) {
132 this.addDirtyRegion0 (applet, x, y, w, h);
133 }, "java.applet.Applet,~N,~N,~N,~N");
134 Clazz.defineMethod (c$, "scheduleHeavyWeightPaints", 
135 function () {
136 var hws;
137 {
138 if (this.hwDirtyComponents.size () == 0) {
139 return;
140 }hws = this.hwDirtyComponents;
141 this.hwDirtyComponents =  new java.util.IdentityHashMap ();
142 }for (var hw, $hw = hws.keySet ().iterator (); $hw.hasNext () && ((hw = $hw.next ()) || true);) {
143 var dirty = hws.get (hw);
144 if (Clazz.instanceOf (hw, java.awt.Window)) {
145 this.addDirtyRegion (hw, dirty.x, dirty.y, dirty.width, dirty.height);
146 } else if (Clazz.instanceOf (hw, java.applet.Applet)) {
147 this.addDirtyRegion (hw, dirty.x, dirty.y, dirty.width, dirty.height);
148 } else {
149 this.addDirtyRegion0 (hw, dirty.x, dirty.y, dirty.width, dirty.height);
150 }}
151 });
152 Clazz.defineMethod (c$, "nativeAddDirtyRegion", 
153 function (appContext, c, x, y, w, h) {
154 if (w > 0 && h > 0) {
155 {
156 var dirty = this.hwDirtyComponents.get (c);
157 if (dirty == null) {
158 this.hwDirtyComponents.put (c,  new java.awt.Rectangle (x, y, w, h));
159 } else {
160 this.hwDirtyComponents.put (c, javax.swing.SwingUtilities.computeUnion (x, y, w, h, dirty));
161 }}this.scheduleProcessingRunnable (appContext);
162 }}, "jssun.awt.AppContext,java.awt.Container,~N,~N,~N,~N");
163 Clazz.defineMethod (c$, "extendDirtyRegion", 
164  function (c, x, y, w, h) {
165 var r = this.dirtyComponents.get (c);
166 if (r != null) {
167 javax.swing.SwingUtilities.computeUnion (x, y, w, h, r);
168 return true;
169 }return false;
170 }, "java.awt.Component,~N,~N,~N,~N");
171 Clazz.defineMethod (c$, "getDirtyRegion", 
172 function (aComponent) {
173 var r = null;
174 {
175 r = this.dirtyComponents.get (aComponent);
176 }if (r == null) return  new java.awt.Rectangle (0, 0, 0, 0);
177  else return  new java.awt.Rectangle (r);
178 }, "javax.swing.JComponent");
179 Clazz.defineMethod (c$, "markCompletelyDirty", 
180 function (aComponent) {
181 this.addDirtyRegion (aComponent, 0, 0, 2147483647, 2147483647);
182 }, "javax.swing.JComponent");
183 Clazz.defineMethod (c$, "markCompletelyClean", 
184 function (aComponent) {
185 {
186 this.dirtyComponents.remove (aComponent);
187 }}, "javax.swing.JComponent");
188 Clazz.defineMethod (c$, "isCompletelyDirty", 
189 function (aComponent) {
190 var r;
191 r = this.getDirtyRegion (aComponent);
192 if (r.width == 2147483647 && r.height == 2147483647) return true;
193  else return false;
194 }, "javax.swing.JComponent");
195 Clazz.defineMethod (c$, "validateInvalidComponents", 
196 function () {
197 var ic;
198 {
199 if (this.invalidComponents == null) {
200 return;
201 }ic = this.invalidComponents;
202 this.invalidComponents = null;
203 }var n = ic.size ();
204 for (var i = 0; i < n; i++) {
205 var c = ic.get (i);
206 c.validate ();
207 }
208 });
209 Clazz.defineMethod (c$, "prePaintDirtyRegions", 
210  function () {
211 var dirtyComponents;
212 var runnableList;
213 {
214 dirtyComponents = this.dirtyComponents;
215 runnableList = this.runnableList;
216 this.runnableList = null;
217 }if (runnableList != null) {
218 for (var runnable, $runnable = runnableList.iterator (); $runnable.hasNext () && ((runnable = $runnable.next ()) || true);) {
219 runnable.run ();
220 }
221 }this.paintDirtyRegions ();
222 if (dirtyComponents.size () > 0) {
223 this.paintDirtyRegions1 (dirtyComponents);
224 }});
225 Clazz.defineMethod (c$, "updateWindows", 
226  function (dirtyComponents) {
227 var toolkit = java.awt.Toolkit.getDefaultToolkit ();
228 if (!(Clazz.instanceOf (toolkit, jssun.awt.SunToolkit) && (toolkit).needUpdateWindow ())) {
229 return dirtyComponents;
230 }var windows =  new java.util.HashSet ();
231 var dirtyComps = dirtyComponents.keySet ();
232 for (var it = dirtyComps.iterator (); it.hasNext (); ) {
233 var dirty = it.next ();
234 var window = Clazz.instanceOf (dirty, java.awt.Window) ? dirty : javax.swing.SwingUtilities.getWindowAncestor (dirty);
235 if (window != null && !jssun.awt.AWTAccessor.getWindowAccessor ().isOpaque (window)) {
236 it.remove ();
237 windows.add (window);
238 }}
239 for (var window, $window = windows.iterator (); $window.hasNext () && ((window = $window.next ()) || true);) {
240 jssun.awt.AWTAccessor.getWindowAccessor ().updateWindow (window, null);
241 }
242 return dirtyComponents;
243 }, "java.util.Map");
244 Clazz.defineMethod (c$, "paintDirtyRegions", 
245 function () {
246 {
247 var tmp = this.tmpDirtyComponents;
248 this.tmpDirtyComponents = this.dirtyComponents;
249 this.dirtyComponents = tmp;
250 this.dirtyComponents.clear ();
251 }this.paintDirtyRegions1 (this.tmpDirtyComponents);
252 });
253 Clazz.defineMethod (c$, "paintDirtyRegions1", 
254  function (tmpDirtyComponents) {
255 if (tmpDirtyComponents.isEmpty ()) {
256 return;
257 }this.updateWindows (tmpDirtyComponents);
258 var roots =  new java.util.ArrayList (tmpDirtyComponents.size ());
259 for (var dirty, $dirty = tmpDirtyComponents.keySet ().iterator (); $dirty.hasNext () && ((dirty = $dirty.next ()) || true);) {
260 this.collectDirtyComponents (tmpDirtyComponents, dirty, roots);
261 }
262 var count = roots.size ();
263 this.painting = true;
264 try {
265 for (var j = 0; j < count; j++) {
266 var i = j;
267 var dirtyComponent = roots.get (j);
268 var rect = tmpDirtyComponents.get (dirtyComponent);
269 var localBoundsH = dirtyComponent.getHeight ();
270 var localBoundsW = dirtyComponent.getWidth ();
271 javax.swing.SwingUtilities.computeIntersection (0, 0, localBoundsW, localBoundsH, rect);
272 if (Clazz.instanceOf (dirtyComponent, javax.swing.JComponent)) {
273 (dirtyComponent).paintImmediately (rect.x, rect.y, rect.width, rect.height);
274 } else if (dirtyComponent.isShowing ()) {
275 var g = javax.swing.JComponent.safelyGetGraphics (dirtyComponent, dirtyComponent);
276 if (g != null) {
277 try {
278 dirtyComponent.paint (g);
279 } finally {
280 g.dispose ();
281 }
282 }}if (this.repaintRoot != null) {
283 this.adjustRoots (this.repaintRoot, roots, i + 1);
284 count = roots.size ();
285 this.repaintRoot.paintImmediately (0, 0, this.repaintRoot.getWidth (), this.repaintRoot.getHeight ());
286 this.repaintRoot = null;
287 }}
288 } finally {
289 this.painting = false;
290 }
291 tmpDirtyComponents.clear ();
292 }, "java.util.Map");
293 Clazz.defineMethod (c$, "adjustRoots", 
294  function (root, roots, index) {
295 for (var i = roots.size () - 1; i >= index; i--) {
296 var c = roots.get (i);
297 for (; ; ) {
298 if (c === root || c == null || !(Clazz.instanceOf (c, javax.swing.JComponent))) {
299 break;
300 }c = c.getParent ();
301 }
302 if (c === root) {
303 roots.remove (i);
304 }}
305 }, "javax.swing.JComponent,java.util.List,~N");
306 Clazz.defineMethod (c$, "collectDirtyComponents", 
307 function (dirtyComponents, dirtyComponent, roots) {
308 var dx;
309 var dy;
310 var rootDx;
311 var rootDy;
312 var component;
313 var rootDirtyComponent;
314 var parent;
315 component = rootDirtyComponent = dirtyComponent;
316 var x = dirtyComponent.getX ();
317 var y = dirtyComponent.getY ();
318 var w = dirtyComponent.getWidth ();
319 var h = dirtyComponent.getHeight ();
320 dx = rootDx = 0;
321 dy = rootDy = 0;
322 this.tmp.setBounds (dirtyComponents.get (dirtyComponent));
323 javax.swing.SwingUtilities.computeIntersection (0, 0, w, h, this.tmp);
324 if (this.tmp.isEmpty ()) {
325 return;
326 }for (; ; ) {
327 if (!(Clazz.instanceOf (component, javax.swing.JComponent))) break;
328 parent = component.getParent ();
329 if (parent == null) break;
330 component = parent;
331 dx += x;
332 dy += y;
333 this.tmp.setLocation (this.tmp.x + x, this.tmp.y + y);
334 x = component.getX ();
335 y = component.getY ();
336 w = component.getWidth ();
337 h = component.getHeight ();
338 this.tmp = javax.swing.SwingUtilities.computeIntersection (0, 0, w, h, this.tmp);
339 if (this.tmp.isEmpty ()) {
340 return;
341 }if (dirtyComponents.get (component) != null) {
342 rootDirtyComponent = component;
343 rootDx = dx;
344 rootDy = dy;
345 }}
346 if (dirtyComponent !== rootDirtyComponent) {
347 var r;
348 this.tmp.setLocation (this.tmp.x + rootDx - dx, this.tmp.y + rootDy - dy);
349 r = dirtyComponents.get (rootDirtyComponent);
350 javax.swing.SwingUtilities.computeUnion (this.tmp.x, this.tmp.y, this.tmp.width, this.tmp.height, r);
351 }if (!roots.contains (rootDirtyComponent)) roots.add (rootDirtyComponent);
352 }, "java.util.Map,java.awt.Component,java.util.List");
353 Clazz.overrideMethod (c$, "toString", 
354 function () {
355 var sb =  new StringBuffer ();
356 if (this.dirtyComponents != null) sb.append ("" + this.dirtyComponents);
357 return sb.toString ();
358 });
359 Clazz.defineMethod (c$, "getOffscreenBuffer", 
360 function (c, proposedWidth, proposedHeight) {
361 return null;
362 }, "java.awt.Component,~N,~N");
363 Clazz.defineMethod (c$, "getVolatileOffscreenBuffer", 
364 function (c, proposedWidth, proposedHeight) {
365 var config = c.getGraphicsConfiguration ();
366 var maxSize = this.getDoubleBufferMaximumSize ();
367 var width = proposedWidth < 1 ? 1 : (proposedWidth > maxSize.width ? maxSize.width : proposedWidth);
368 var height = proposedHeight < 1 ? 1 : (proposedHeight > maxSize.height ? maxSize.height : proposedHeight);
369 var image = this.volatileMap.get (config);
370 if (image == null || image.getWidth () < width || image.getHeight () < height) {
371 if (image != null) {
372 image.flush ();
373 }image = config.createCompatibleVolatileImage (width, height);
374 this.volatileMap.put (config, image);
375 }return image;
376 }, "java.awt.Component,~N,~N");
377 Clazz.defineMethod (c$, "setDoubleBufferMaximumSize", 
378 function (d) {
379 }, "java.awt.Dimension");
380 Clazz.defineMethod (c$, "getDoubleBufferMaximumSize", 
381 function () {
382 return null;
383 });
384 Clazz.defineMethod (c$, "setDoubleBufferingEnabled", 
385 function (aFlag) {
386 }, "~B");
387 Clazz.defineMethod (c$, "resetDoubleBuffer", 
388 function () {
389 });
390 Clazz.defineMethod (c$, "resetVolatileDoubleBuffer", 
391 function (gc) {
392 var image = this.volatileMap.remove (gc);
393 if (image != null) {
394 image.flush ();
395 }}, "java.awt.GraphicsConfiguration");
396 Clazz.defineMethod (c$, "useVolatileDoubleBuffer", 
397 function () {
398 return javax.swing.RepaintManager.volatileImageBufferEnabled;
399 });
400 Clazz.defineMethod (c$, "isPaintingThread", 
401  function () {
402 return (Thread.currentThread () === this.paintThread);
403 });
404 Clazz.defineMethod (c$, "paint", 
405 function (paintingComponent, bufferComponent, g, x, y, w, h) {
406 paintingComponent.paintToOffscreen (g, x, y, w, h, x + w, y + h);
407 }, "javax.swing.JComponent,javax.swing.JComponent,java.awt.Graphics,~N,~N,~N,~N");
408 Clazz.defineMethod (c$, "beginPaint", 
409 function () {
410 var multiThreadedPaint = false;
411 var paintDepth = 0;
412 var currentThread = Thread.currentThread ();
413 {
414 paintDepth = this.paintDepth;
415 if (this.paintThread == null || currentThread === this.paintThread) {
416 this.paintThread = currentThread;
417 this.paintDepth++;
418 } else {
419 multiThreadedPaint = true;
420 }}});
421 Clazz.defineMethod (c$, "endPaint", 
422 function () {
423 if (this.isPaintingThread ()) {
424 }});
425 Clazz.defineMethod (c$, "doubleBufferingChanged", 
426 function (rootPane) {
427 }, "javax.swing.JRootPane");
428 Clazz.defineMethod (c$, "scheduleProcessingRunnable", 
429  function (c) {
430 this.scheduleProcessingRunnable (c.getAppContext ());
431 }, "java.awt.Component");
432 Clazz.defineMethod (c$, "scheduleProcessingRunnable", 
433  function (context) {
434 if (this.processingRunnable.markPending ()) {
435 jssun.awt.SunToolkit.getSystemEventQueueImplPP (context).postEvent ( new java.awt.event.InvocationEvent (java.awt.Toolkit.getDefaultToolkit (), this.processingRunnable));
436 }}, "jssun.awt.AppContext");
437 c$.$RepaintManager$ProcessingRunnable$ = function () {
438 Clazz.pu$h(self.c$);
439 c$ = Clazz.decorateAsClass (function () {
440 Clazz.prepareCallback (this, arguments);
441 this.pending = false;
442 Clazz.instantialize (this, arguments);
443 }, javax.swing.RepaintManager, "ProcessingRunnable", null, Runnable);
444 Clazz.defineMethod (c$, "markPending", 
445 function () {
446 if (!this.pending) {
447 this.pending = true;
448 return true;
449 }return false;
450 });
451 Clazz.overrideMethod (c$, "run", 
452 function () {
453 {
454 this.pending = false;
455 }this.b$["javax.swing.RepaintManager"].scheduleHeavyWeightPaints ();
456 this.b$["javax.swing.RepaintManager"].validateInvalidComponents ();
457 this.b$["javax.swing.RepaintManager"].prePaintDirtyRegions ();
458 swingjs.JSToolkit.forceRepaint (this.b$["javax.swing.RepaintManager"].myComponent);
459 });
460 c$ = Clazz.p0p ();
461 };
462 Clazz.defineStatics (c$,
463 "HANDLE_TOP_LEVEL_PAINT", false);
464 c$.repaintManagerKey = c$.prototype.repaintManagerKey = javax.swing.RepaintManager;
465 Clazz.defineStatics (c$,
466 "volatileImageBufferEnabled", true);
467 {
468 javax.swing.RepaintManager.volatileImageBufferEnabled = false;
469 var headless = false;
470 if (javax.swing.RepaintManager.volatileImageBufferEnabled && headless) {
471 javax.swing.RepaintManager.volatileImageBufferEnabled = false;
472 }javax.swing.RepaintManager.HANDLE_TOP_LEVEL_PAINT = true;
473 }});