JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / swingjs / j2s / jssun / awt / image / InputStreamImageSource.js
1 Clazz.declarePackage ("jssun.awt.image");\r
2 Clazz.load (["java.awt.image.ImageProducer", "jssun.awt.image.ImageFetchable"], "jssun.awt.image.InputStreamImageSource", ["java.lang.SecurityException", "$.Thread", "jssun.awt.image.ImageConsumerQueue", "$.ImageFetcher"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.consumers = null;\r
5 this.decoder = null;\r
6 this.decoders = null;\r
7 this.awaitingFetch = false;\r
8 Clazz.instantialize (this, arguments);\r
9 }, jssun.awt.image, "InputStreamImageSource", null, [java.awt.image.ImageProducer, jssun.awt.image.ImageFetchable]);\r
10 Clazz.defineMethod (c$, "countConsumers", \r
11 function (cq) {\r
12 var i = 0;\r
13 while (cq != null) {\r
14 i++;\r
15 cq = cq.next;\r
16 }\r
17 return i;\r
18 }, "jssun.awt.image.ImageConsumerQueue");\r
19 Clazz.defineMethod (c$, "countConsumers", \r
20 function () {\r
21 var id = this.decoders;\r
22 var i = this.countConsumers (this.consumers);\r
23 while (id != null) {\r
24 i += this.countConsumers (id.queue);\r
25 id = id.next;\r
26 }\r
27 return i;\r
28 });\r
29 Clazz.defineMethod (c$, "addConsumer", \r
30 function (ic) {\r
31 this.addConsumer (ic, false);\r
32 }, "java.awt.image.ImageConsumer");\r
33 Clazz.defineMethod (c$, "printQueue", \r
34 function (cq, prefix) {\r
35 while (cq != null) {\r
36 System.out.println (prefix + cq);\r
37 cq = cq.next;\r
38 }\r
39 }, "jssun.awt.image.ImageConsumerQueue,~S");\r
40 Clazz.defineMethod (c$, "printQueues", \r
41 function (title) {\r
42 System.out.println (title + "[ -----------");\r
43 this.printQueue (this.consumers, "  ");\r
44 for (var id = this.decoders; id != null; id = id.next) {\r
45 System.out.println ("    " + id);\r
46 this.printQueue (id.queue, "      ");\r
47 }\r
48 System.out.println ("----------- ]" + title);\r
49 }, "~S");\r
50 Clazz.defineMethod (c$, "addConsumer", \r
51 function (ic, produce) {\r
52 for (var id = this.decoders; id != null; id = id.next) {\r
53 if (id.isConsumer (ic)) {\r
54 return;\r
55 }}\r
56 var cq = this.consumers;\r
57 while (cq != null && cq.consumer !== ic) {\r
58 cq = cq.next;\r
59 }\r
60 if (cq == null) {\r
61 cq =  new jssun.awt.image.ImageConsumerQueue (this, ic);\r
62 cq.next = this.consumers;\r
63 this.consumers = cq;\r
64 } else {\r
65 if (!cq.secure) {\r
66 var context = null;\r
67 var security = System.getSecurityManager ();\r
68 if (security != null) {\r
69 context = security.getSecurityContext ();\r
70 }if (cq.securityContext == null) {\r
71 cq.securityContext = context;\r
72 } else if (!cq.securityContext.equals (context)) {\r
73 this.errorConsumer (cq, false);\r
74 throw  new SecurityException ("Applets are trading image data!");\r
75 }}cq.interested = true;\r
76 }if (produce && this.decoder == null) {\r
77 this.startProduction ();\r
78 }}, "java.awt.image.ImageConsumer,~B");\r
79 Clazz.overrideMethod (c$, "isConsumer", \r
80 function (ic) {\r
81 for (var id = this.decoders; id != null; id = id.next) {\r
82 if (id.isConsumer (ic)) {\r
83 return true;\r
84 }}\r
85 return jssun.awt.image.ImageConsumerQueue.isConsumer (this.consumers, ic);\r
86 }, "java.awt.image.ImageConsumer");\r
87 Clazz.defineMethod (c$, "errorAllConsumers", \r
88  function (cq, needReload) {\r
89 while (cq != null) {\r
90 if (cq.interested) {\r
91 this.errorConsumer (cq, needReload);\r
92 }cq = cq.next;\r
93 }\r
94 }, "jssun.awt.image.ImageConsumerQueue,~B");\r
95 Clazz.defineMethod (c$, "errorConsumer", \r
96  function (cq, needReload) {\r
97 cq.consumer.imageComplete (1);\r
98 this.removeConsumer (cq.consumer);\r
99 }, "jssun.awt.image.ImageConsumerQueue,~B");\r
100 Clazz.overrideMethod (c$, "removeConsumer", \r
101 function (ic) {\r
102 for (var id = this.decoders; id != null; id = id.next) {\r
103 id.removeConsumer (ic);\r
104 }\r
105 this.consumers = jssun.awt.image.ImageConsumerQueue.removeConsumer (this.consumers, ic, false);\r
106 }, "java.awt.image.ImageConsumer");\r
107 Clazz.defineMethod (c$, "startProduction", \r
108 function (ic) {\r
109 this.addConsumer (ic, true);\r
110 }, "java.awt.image.ImageConsumer");\r
111 Clazz.defineMethod (c$, "startProduction", \r
112  function () {\r
113 if (!this.awaitingFetch) {\r
114 jssun.awt.image.ImageFetcher.add (this);\r
115 this.awaitingFetch = true;\r
116 }});\r
117 Clazz.overrideMethod (c$, "requestTopDownLeftRightResend", \r
118 function (ic) {\r
119 }, "java.awt.image.ImageConsumer");\r
120 Clazz.defineMethod (c$, "decoderForType", \r
121 function (is, content_type) {\r
122 return null;\r
123 }, "java.io.InputStream,~S");\r
124 Clazz.defineMethod (c$, "getDecoder", \r
125 function (is) {\r
126 return null;\r
127 }, "java.io.InputStream");\r
128 Clazz.overrideMethod (c$, "doFetch", \r
129 function () {\r
130 {\r
131 if (this.consumers == null) {\r
132 this.awaitingFetch = false;\r
133 return;\r
134 }}var imgd = this.getDecoder ();\r
135 if (imgd == null) {\r
136 this.badDecoder ();\r
137 } else {\r
138 this.setDecoder (imgd);\r
139 try {\r
140 imgd.produceImage ();\r
141 } catch (e$$) {\r
142 if (Clazz.exceptionOf (e$$, java.io.IOException)) {\r
143 var e = e$$;\r
144 {\r
145 e.printStackTrace ();\r
146 }\r
147 } else if (Clazz.exceptionOf (e$$, jssun.awt.image.ImageFormatException)) {\r
148 var e = e$$;\r
149 {\r
150 e.printStackTrace ();\r
151 }\r
152 } else {\r
153 throw e$$;\r
154 }\r
155 } finally {\r
156 this.removeDecoder (imgd);\r
157 if (Thread.currentThread ().isInterrupted () || !Thread.currentThread ().isAlive ()) {\r
158 this.errorAllConsumers (imgd.queue, true);\r
159 } else {\r
160 this.errorAllConsumers (imgd.queue, false);\r
161 }}\r
162 }});\r
163 Clazz.defineMethod (c$, "badDecoder", \r
164  function () {\r
165 var cq;\r
166 {\r
167 cq = this.consumers;\r
168 this.consumers = null;\r
169 this.awaitingFetch = false;\r
170 }this.errorAllConsumers (cq, false);\r
171 });\r
172 Clazz.defineMethod (c$, "setDecoder", \r
173  function (mydecoder) {\r
174 var cq;\r
175 {\r
176 mydecoder.next = this.decoders;\r
177 this.decoders = mydecoder;\r
178 this.decoder = mydecoder;\r
179 cq = this.consumers;\r
180 mydecoder.queue = cq;\r
181 this.consumers = null;\r
182 this.awaitingFetch = false;\r
183 }}, "jssun.awt.image.ImageDecoder");\r
184 Clazz.defineMethod (c$, "removeDecoder", \r
185  function (mydecoder) {\r
186 this.doneDecoding (mydecoder);\r
187 var idprev = null;\r
188 for (var id = this.decoders; id != null; id = id.next) {\r
189 if (id === mydecoder) {\r
190 if (idprev == null) {\r
191 this.decoders = id.next;\r
192 } else {\r
193 idprev.next = id.next;\r
194 }break;\r
195 }idprev = id;\r
196 }\r
197 }, "jssun.awt.image.ImageDecoder");\r
198 Clazz.defineMethod (c$, "doneDecoding", \r
199 function (mydecoder) {\r
200 if (this.decoder === mydecoder) {\r
201 this.decoder = null;\r
202 if (this.consumers != null) {\r
203 this.startProduction ();\r
204 }}}, "jssun.awt.image.ImageDecoder");\r
205 Clazz.defineMethod (c$, "latchConsumers", \r
206 function (id) {\r
207 this.doneDecoding (id);\r
208 }, "jssun.awt.image.ImageDecoder");\r
209 Clazz.defineMethod (c$, "flush", \r
210 function () {\r
211 this.decoder = null;\r
212 });\r
213 });\r