cb82955d4033042eed62cbc6950b6a7d26f84bce
[jalviewjs.git] / site / swingjs / j2s / jssun / swing / CachedPainter.js
1 Clazz.declarePackage ("jssun.swing");
2 Clazz.load (["java.util.HashMap"], "jssun.swing.CachedPainter", ["java.awt.image.BufferedImage", "$.VolatileImage", "jssun.swing.ImageCache"], function () {
3 c$ = Clazz.declareType (jssun.swing, "CachedPainter");
4 c$.getCache = Clazz.defineMethod (c$, "getCache", 
5  function (key) {
6 {
7 var cache = jssun.swing.CachedPainter.cacheMap.get (key);
8 if (cache == null) {
9 cache =  new jssun.swing.ImageCache (1);
10 jssun.swing.CachedPainter.cacheMap.put (key, cache);
11 }return cache;
12 }}, "~O");
13 Clazz.makeConstructor (c$, 
14 function (cacheCount) {
15 jssun.swing.CachedPainter.getCache (this.getClass ()).setMaxCount (cacheCount);
16 }, "~N");
17 Clazz.defineMethod (c$, "paint", 
18 function (c, g, x, y, w, h, args) {
19 if (w <= 0 || h <= 0) {
20 return;
21 }if (c != null) {
22 this.paint0 (c, g, x, y, w, h, args);
23 } else {
24 this.paint0 (c, g, x, y, w, h, args);
25 }}, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N,~A");
26 Clazz.defineMethod (c$, "paint0", 
27  function (c, g, x, y, w, h, args) {
28 var key = this.getClass ();
29 var config = this.getGraphicsConfiguration (c);
30 var cache = jssun.swing.CachedPainter.getCache (key);
31 var image = cache.getImage (key, config, w, h, args);
32 var attempts = 0;
33 do {
34 var draw = false;
35 if (Clazz.instanceOf (image, java.awt.image.VolatileImage)) {
36 switch ((image).validate (config)) {
37 case 2:
38 (image).flush ();
39 image = null;
40 break;
41 case 1:
42 draw = true;
43 break;
44 }
45 }if (image == null) {
46 image = this.createImage (c, w, h, config, args);
47 cache.setImage (key, config, w, h, args, image);
48 draw = true;
49 }if (draw) {
50 var g2 = image.getGraphics ();
51 this.paintToImage (c, image, g2, w, h, args);
52 g2.dispose ();
53 }this.paintImage (c, g, x, y, w, h, image, args);
54 } while ((Clazz.instanceOf (image, java.awt.image.VolatileImage)) && (image).contentsLost () && ++attempts < 3);
55 }, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N,~A");
56 Clazz.defineMethod (c$, "paintImage", 
57 function (c, g, x, y, w, h, image, args) {
58 g.drawImage (image, x, y, null);
59 }, "java.awt.Component,java.awt.Graphics,~N,~N,~N,~N,java.awt.Image,~A");
60 Clazz.defineMethod (c$, "createImage", 
61 function (c, w, h, config, args) {
62 if (config == null) {
63 return  new java.awt.image.BufferedImage (w, h, 1);
64 }return config.createCompatibleVolatileImage (w, h);
65 }, "java.awt.Component,~N,~N,java.awt.GraphicsConfiguration,~A");
66 Clazz.defineMethod (c$, "flush", 
67 function () {
68 {
69 jssun.swing.CachedPainter.getCache (this.getClass ()).flush ();
70 }});
71 Clazz.defineMethod (c$, "getGraphicsConfiguration", 
72  function (c) {
73 if (c == null) {
74 return null;
75 }return c.getGraphicsConfiguration ();
76 }, "java.awt.Component");
77 c$.cacheMap = c$.prototype.cacheMap =  new java.util.HashMap ();
78 });