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