Revision: 3825 http://vexi.svn.sourceforge.net/vexi/?rev=3825&view=rev Author: clrg Date: 2010-03-26 08:17:38 +0000 (Fri, 26 Mar 2010)
Log Message: ----------- Code cleanup only Modified Paths: -------------- trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java Modified: trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java =================================================================== --- trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java 2010-03-26 06:43:33 UTC (rev 3824) +++ trunk/core/org.vexi.core/src/org/vexi/graphics/Picture.java 2010-03-26 08:17:38 UTC (rev 3825) @@ -41,10 +41,14 @@ /** invoked when an image is fully loaded; subclasses can use this to initialize platform-specific constructs */ protected synchronized void loaded() { - if (loadedCallbacks == null) return; + if (loadedCallbacks == null) { + return; + } - for (int i=0; i<loadedCallbacks.size(); i++) - Main.SCHEDULER.add((Callable)loadedCallbacks.elementAt(i)); + int numcallbacks = loadedCallbacks.size(); + for (int i=0; i<numcallbacks; i++) { + Main.SCHEDULER.add((Callable)loadedCallbacks.elementAt(i)); + } loadedCallbacks.removeAllElements(); loadedCallbacks = null; } @@ -63,7 +67,9 @@ SoftReference ref = (SoftReference)cache.get(key); Picture ret = ref==null ? null : (Picture)ref.get(); // FIXME: is this a small memory leak? JS streams will not be GC'd. - if (ret==null) cache.put(key, new SoftReference(ret = Platform.createPicture(stream))); + if (ret==null) { + cache.put(key, new SoftReference(ret = Platform.createPicture(stream))); + } // can return ret here outside of sync block for caller to assign as callback // is executed in the same interpreter as the caller, synchronously. ret.load(callback); @@ -72,8 +78,10 @@ /** turns a stream into a Picture.Source and passes it to the callback */ private void load(final Callable callback) { - synchronized(this) { - if (isLoaded || callback == null) return; + synchronized (this) { + if (isLoaded || callback == null) { + return; + } // Previous demand for this image means it is already loading // add to callbacks and return @@ -87,27 +95,36 @@ loadedCallbacks.addElement(callback); new java.lang.Thread() { public void run() { - try { - try { - InputStream in = b == null ? - JSU.getInputStream(stream) : b.getImage(); - if (in == null) throw new JSExn("not a valid image stream"); + try { + try { + InputStream in = b == null ? + JSU.getInputStream(stream) : b.getImage(); + if (in == null) { + throw new JSExn("not a valid image stream"); + } - PushbackInputStream pbis = new PushbackInputStream(in); - int firstByte = pbis.read(); - if (firstByte == -1) throw new JSExn("empty stream reading image"); - pbis.unread(firstByte); - if ((firstByte & 0xff) == 'G') GIF.load(pbis, Picture.this); - else if ((firstByte & 0xff) == 137) PNG.load(pbis, Picture.this); - else if ((firstByte & 0xff) == 0xff) Platform.decodeJPEG(pbis, Picture.this); - else throw new JSExn("couldn't figure out image type from first byte"); - isLoaded = true; - } catch (IOException e) { - throw JSU.handleFountainExn(e); - } - } catch(JSExn e) { - loadFailed = e; - } finally { + PushbackInputStream pbis = new PushbackInputStream(in); + int firstByte = pbis.read(); + if (firstByte == -1) { + throw new JSExn("empty stream reading image"); + } + pbis.unread(firstByte); + if ((firstByte & 0xff) == 'G') { + GIF.load(pbis, Picture.this); + } else if ((firstByte & 0xff) == 137) { + PNG.load(pbis, Picture.this); + } else if ((firstByte & 0xff) == 0xff) { + Platform.decodeJPEG(pbis, Picture.this); + } else { + throw new JSExn("couldn't figure out image type from first byte"); + } + isLoaded = true; + } catch (IOException e) { + throw JSU.handleFountainExn(e); + } + } catch(JSExn e) { + loadFailed = e; + } finally { loaded(); } } }.start(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn