From: <ka...@us...> - 2010-07-25 12:18:23
|
Revision: 3388 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3388&view=rev Author: kappa1 Date: 2010-07-25 12:18:17 +0000 (Sun, 25 Jul 2010) Log Message: ----------- AppletLoader: actually fail with error message if logo images are not found or an error occurs when they are loaded, added missing MediaTracker step. Also prevent paint thread from null pointer exception when this happens. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2010-07-25 11:40:58 UTC (rev 3387) +++ trunk/LWJGL/src/java/org/lwjgl/util/applet/AppletLoader.java 2010-07-25 12:18:17 UTC (rev 3388) @@ -405,7 +405,6 @@ * @see java.awt.Container#paint(java.awt.Graphics) */ public void paint(Graphics g) { - // don't paint loader if applet loaded if(state == STATE_DONE) { return; @@ -416,16 +415,21 @@ offscreen = createImage(getWidth(), getHeight()); // create buffers for animated gifs - logoBuffer = createImage(logo.getWidth(null), logo.getHeight(null)); - progressbarBuffer = createImage(logo.getWidth(null), logo.getHeight(null)); + if (logo != null) { + logoBuffer = createImage(logo.getWidth(null), logo.getHeight(null)); + // add image observer, it will notify when next animated gif frame is ready + offscreen.getGraphics().drawImage(logo, 0, 0, this); + // in case image is not animated fill image buffer once + imageUpdate(logo, ImageObserver.FRAMEBITS, 0, 0, 0, 0); + } - // add image observer, it will notify when next animated gif frame is ready - offscreen.getGraphics().drawImage(logo, 0, 0, this); - offscreen.getGraphics().drawImage(progressbar, 0, 0, this); - - // in case image is not animated fill image buffers once - imageUpdate(logo, ImageObserver.FRAMEBITS, 0, 0, 0, 0); - imageUpdate(progressbar, ImageObserver.FRAMEBITS, 0, 0, 0, 0); + if (progressbar != null) { + progressbarBuffer = createImage(progressbar.getWidth(null), progressbar.getHeight(null)); + // add image observer, it will notify when next animated gif frame is ready + offscreen.getGraphics().drawImage(progressbar, 0, 0, this); + // in case image is not animated fill image buffer once + imageUpdate(progressbar, ImageObserver.FRAMEBITS, 0, 0, 0, 0); + } } // draw everything onto an image before drawing to avoid flicker @@ -436,14 +440,6 @@ og.setColor(bgColor); og.fillRect(0, 0, offscreen.getWidth(null), offscreen.getHeight(null)); - // get logo position so its in the middle of applet - int x = 0, y = 0; - - if(logo != null && !fatalError) { - x = (offscreen.getWidth(null) - logo.getWidth(null)) / 2; - y = (offscreen.getHeight(null) - logo.getHeight(null)) / 2; - } - og.setColor(fgColor); String message = getDescriptionForState(); @@ -464,12 +460,22 @@ painting = true; + // get logo position so its in the middle of applet + int x = 0, y = 0; + + if(logo != null) { + x = (offscreen.getWidth(null) - logo.getWidth(null)) / 2; + y = (offscreen.getHeight(null) - logo.getHeight(null)) / 2; + } + // draw logo - og.drawImage(logoBuffer, x, y, this); + if (logo != null) og.drawImage(logoBuffer, x, y, this); // draw message int messageX = (offscreen.getWidth(null) - fm.stringWidth(message)) / 2; - int messageY = y + logoBuffer.getHeight(null) + 20; + int messageY = y + 20; + if (logo != null) messageY += logoBuffer.getHeight(null); + og.drawString(message, messageX, messageY); // draw subtaskmessage, if any @@ -479,9 +485,11 @@ } // draw loading bar, clipping it depending on percentage done - int barSize = (progressbarBuffer.getWidth(null) * percentage) / 100; - og.clipRect(0, 0, x + barSize, offscreen.getHeight(null)); - og.drawImage(progressbarBuffer, x, y, this); + if (progressbar != null) { + int barSize = (progressbarBuffer.getWidth(null) * percentage) / 100; + og.clipRect(0, 0, x + barSize, offscreen.getHeight(null)); + og.drawImage(progressbarBuffer, x, y, this); + } painting = false; } @@ -519,7 +527,7 @@ g.fillRect(0, 0, buffer.getWidth(null), buffer.getHeight(null)); // buffer background is cleared, so draw logo under progressbar - if (img == progressbar) g.drawImage(logoBuffer, 0, 0, null); + if (img == progressbar && logo != null) g.drawImage(logoBuffer, 0, 0, null); g.drawImage(img, 0, 0, this); g.dispose(); @@ -1438,7 +1446,10 @@ tracker.addImage(image, 0); tracker.waitForAll(); - return image; + // if no errors return image + if (!tracker.isErrorAny()) { + return image; + } } catch (Exception e) { /* */ } @@ -1572,5 +1583,4 @@ } } - } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |