1 Clazz.declarePackage ("jssun.awt.image");
2 Clazz.load (["java.lang.Thread", "$.StringBuffer"], ["jssun.awt.image.FetcherInfo", "$.ImageFetcher"], ["java.util.Vector", "jssun.awt.AppContext"], function () {
3 c$ = Clazz.declareType (jssun.awt.image, "ImageFetcher", Thread);
4 Clazz.makeConstructor (c$,
5 function (threadGroup, index) {
6 Clazz.superConstructor (this, jssun.awt.image.ImageFetcher, [threadGroup, "Image Fetcher " + index]);
9 c$.add = Clazz.defineMethod (c$, "add",
11 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
13 if (!info.waitList.contains (src)) {
14 info.waitList.addElement (src);
15 if (info.numWaiting == 0 && info.numFetchers < info.fetchers.length) {
16 jssun.awt.image.ImageFetcher.createFetchers (info);
17 }info.waitList.notify ();
18 }}}, "jssun.awt.image.ImageFetchable");
19 c$.remove = Clazz.defineMethod (c$, "remove",
21 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
23 if (info.waitList.contains (src)) {
24 info.waitList.removeElement (src);
25 }}}, "jssun.awt.image.ImageFetchable");
26 c$.isFetcher = Clazz.defineMethod (c$, "isFetcher",
28 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
30 for (var i = 0; i < info.fetchers.length; i++) {
31 if (info.fetchers[i] === t) {
36 c$.amFetcher = Clazz.defineMethod (c$, "amFetcher",
38 return jssun.awt.image.ImageFetcher.isFetcher (Thread.currentThread ());
40 c$.nextImage = Clazz.defineMethod (c$, "nextImage",
42 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
45 var end = System.currentTimeMillis () + 5000;
47 while (info.waitList.size () == 0) {
48 var now = System.currentTimeMillis ();
53 info.waitList.wait (end - now);
55 if (Clazz.exceptionOf (e, InterruptedException)) {
64 src = info.waitList.elementAt (0);
65 info.waitList.removeElement (src);
69 Clazz.overrideMethod (c$, "run",
71 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
75 if (Clazz.exceptionOf (e, Exception)) {
82 var me = Thread.currentThread ();
83 for (var i = 0; i < info.fetchers.length; i++) {
84 if (info.fetchers[i] === me) {
85 info.fetchers[i] = null;
90 Clazz.defineMethod (c$, "fetchloop",
92 var me = Thread.currentThread ();
93 while (jssun.awt.image.ImageFetcher.isFetcher (me)) {
94 Thread.interrupted ();
96 var src = jssun.awt.image.ImageFetcher.nextImage ();
102 if (Clazz.exceptionOf (e, Exception)) {
103 System.err.println ("Uncaught error fetching image:");
104 e.printStackTrace ();
109 jssun.awt.image.ImageFetcher.stoppingAnimation (me);
112 c$.startingAnimation = Clazz.defineMethod (c$, "startingAnimation",
114 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
115 var me = Thread.currentThread ();
117 for (var i = 0; i < info.fetchers.length; i++) {
118 if (info.fetchers[i] === me) {
119 info.fetchers[i] = null;
121 me.setName ("Image Animator " + i);
122 if (info.waitList.size () > info.numWaiting) {
123 jssun.awt.image.ImageFetcher.createFetchers (info);
127 me.setName ("Image Animator");
129 c$.stoppingAnimation = Clazz.defineMethod (c$, "stoppingAnimation",
131 var info = jssun.awt.image.FetcherInfo.getFetcherInfo ();
134 for (var i = 0; i < info.fetchers.length; i++) {
135 if (info.fetchers[i] === me) {
137 }if (info.fetchers[i] == null) {
141 info.fetchers[index] = me;
143 me.setName ("Image Fetcher " + index);
146 c$.createFetchers = Clazz.defineMethod (c$, "createFetchers",
148 var appContext = jssun.awt.AppContext.getAppContext ();
149 var threadGroup = appContext.getThreadGroup ();
150 var fetcherThreadGroup;
152 if (threadGroup.getParent () != null) {
153 fetcherThreadGroup = threadGroup;
155 threadGroup = Thread.currentThread ().getThreadGroup ();
156 var parent = threadGroup.getParent ();
157 while ((parent != null) && (parent.getParent () != null)) {
158 threadGroup = parent;
159 parent = threadGroup.getParent ();
161 fetcherThreadGroup = threadGroup;
163 if (Clazz.exceptionOf (e, SecurityException)) {
164 fetcherThreadGroup = appContext.getThreadGroup ();
169 var fetcherGroup = fetcherThreadGroup;
170 for (var i = 0; i < info.fetchers.length; i++) {
171 if (info.fetchers[i] == null) {
172 info.fetchers[i] = new jssun.awt.image.ImageFetcher (fetcherGroup, i);
173 info.fetchers[i].start ();
178 }, "jssun.awt.image.FetcherInfo");
179 Clazz.defineStatics (c$,
184 c$ = Clazz.decorateAsClass (function () {
185 this.fetchers = null;
186 this.numFetchers = 0;
188 this.waitList = null;
189 Clazz.instantialize (this, arguments);
190 }, jssun.awt.image, "FetcherInfo");
191 Clazz.makeConstructor (c$,
193 this.fetchers = new Array (4);
194 this.numFetchers = 0;
196 this.waitList = new java.util.Vector ();
198 c$.getFetcherInfo = Clazz.defineMethod (c$, "getFetcherInfo",
200 var appContext = jssun.awt.AppContext.getAppContext ();
202 var info = appContext.get (jssun.awt.image.FetcherInfo.FETCHER_INFO_KEY);
204 info = new jssun.awt.image.FetcherInfo ();
205 appContext.put (jssun.awt.image.FetcherInfo.FETCHER_INFO_KEY, info);
208 Clazz.defineStatics (c$,
209 "MAX_NUM_FETCHERS_PER_APPCONTEXT", 4);
210 c$.FETCHER_INFO_KEY = c$.prototype.FETCHER_INFO_KEY = new StringBuffer ("FetcherInfo");