home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / awt / SplashScreen.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  4.1 KB  |  186 lines

  1. package java.awt;
  2.  
  3. import java.awt.image.BufferedImage;
  4. import java.awt.image.DataBuffer;
  5. import java.awt.image.DataBufferInt;
  6. import java.awt.image.SinglePixelPackedSampleModel;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.io.InputStream;
  10. import java.net.MalformedURLException;
  11. import java.net.URL;
  12. import java.net.URLConnection;
  13.  
  14. public final class SplashScreen {
  15.    private BufferedImage image;
  16.    private long splashPtr;
  17.    private boolean wasClosed;
  18.    private URL imageURL;
  19.    private static SplashScreen theInstance = null;
  20.  
  21.    SplashScreen(long var1) {
  22.       this.splashPtr = var1;
  23.       this.wasClosed = false;
  24.    }
  25.  
  26.    public static synchronized SplashScreen getSplashScreen() {
  27.       if (GraphicsEnvironment.isHeadless()) {
  28.          throw new HeadlessException();
  29.       } else {
  30.          if (theInstance == null) {
  31.             System.loadLibrary("splashscreen");
  32.             long var0 = _getInstance();
  33.             if (var0 == 0L) {
  34.                return null;
  35.             }
  36.  
  37.             if (!_isVisible(var0)) {
  38.                return null;
  39.             }
  40.  
  41.             theInstance = new SplashScreen(var0);
  42.          }
  43.  
  44.          return theInstance.isVisible() ? theInstance : null;
  45.       }
  46.    }
  47.  
  48.    public void setImageURL(URL var1) throws NullPointerException, IOException, IllegalStateException {
  49.       this.checkVisible();
  50.       URLConnection var2 = var1.openConnection();
  51.       var2.connect();
  52.       int var3 = var2.getContentLength();
  53.       InputStream var4 = var2.getInputStream();
  54.       byte[] var5 = new byte[var3];
  55.       int var6 = 0;
  56.  
  57.       while(true) {
  58.          int var7 = var4.available();
  59.          if (var7 <= 0) {
  60.             var7 = 1;
  61.          }
  62.  
  63.          if (var6 + var7 > var3) {
  64.             var3 = var6 * 2;
  65.             if (var6 + var7 > var3) {
  66.                var3 = var7 + var6;
  67.             }
  68.  
  69.             byte[] var8 = var5;
  70.             var5 = new byte[var3];
  71.             System.arraycopy(var8, 0, var5, 0, var6);
  72.          }
  73.  
  74.          int var11 = var4.read(var5, var6, var7);
  75.          if (var11 < 0) {
  76.             synchronized(this) {
  77.                if (!_setImageData(this.splashPtr, var5)) {
  78.                   throw new IOException("Bad image format or i/o error when loading image");
  79.                }
  80.  
  81.                this.imageURL = var1;
  82.                return;
  83.             }
  84.          }
  85.  
  86.          var6 += var11;
  87.       }
  88.    }
  89.  
  90.    private void checkVisible() {
  91.       if (!this.isVisible()) {
  92.          throw new IllegalStateException("no splash screen available");
  93.       }
  94.    }
  95.  
  96.    public synchronized URL getImageURL() throws IllegalStateException {
  97.       this.checkVisible();
  98.       if (this.imageURL == null) {
  99.          try {
  100.             String var1 = _getImageFileName(this.splashPtr);
  101.             String var2 = _getImageJarName(this.splashPtr);
  102.             if (var1 != null) {
  103.                if (var2 != null) {
  104.                   this.imageURL = new URL("jar:" + (new File(var2)).toURL().toString() + "!/" + var1);
  105.                } else {
  106.                   this.imageURL = (new File(var1)).toURL();
  107.                }
  108.             }
  109.          } catch (MalformedURLException var3) {
  110.          }
  111.       }
  112.  
  113.       return this.imageURL;
  114.    }
  115.  
  116.    public Rectangle getBounds() throws IllegalStateException {
  117.       this.checkVisible();
  118.       return _getBounds(this.splashPtr);
  119.    }
  120.  
  121.    public Dimension getSize() throws IllegalStateException {
  122.       return this.getBounds().getSize();
  123.    }
  124.  
  125.    public Graphics2D createGraphics() throws IllegalStateException {
  126.       if (this.image == null) {
  127.          Dimension var1 = this.getSize();
  128.          this.image = new BufferedImage(var1.width, var1.height, 2);
  129.       }
  130.  
  131.       return this.image.createGraphics();
  132.    }
  133.  
  134.    public void update() throws IllegalStateException {
  135.       this.checkVisible();
  136.       if (this.image == null) {
  137.          throw new IllegalStateException("no overlay image available");
  138.       } else {
  139.          DataBuffer var1 = this.image.getRaster().getDataBuffer();
  140.          if (!(var1 instanceof DataBufferInt)) {
  141.             throw new AssertionError("Overlay image DataBuffer is of invalid type == " + var1.getClass().getName());
  142.          } else {
  143.             int var2 = var1.getNumBanks();
  144.             if (var2 != 1) {
  145.                throw new AssertionError("Invalid number of banks ==" + var2 + " in overlay image DataBuffer");
  146.             } else if (!(this.image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
  147.                throw new AssertionError("Overlay image has invalid sample model == " + this.image.getSampleModel().getClass().getName());
  148.             } else {
  149.                SinglePixelPackedSampleModel var3 = (SinglePixelPackedSampleModel)this.image.getSampleModel();
  150.                int var4 = var3.getScanlineStride();
  151.                Rectangle var5 = this.image.getRaster().getBounds();
  152.                int[] var6 = ((DataBufferInt)var1).getData();
  153.                _update(this.splashPtr, var6, var5.x, var5.y, var5.width, var5.height, var4);
  154.             }
  155.          }
  156.       }
  157.    }
  158.  
  159.    public synchronized void close() throws IllegalStateException {
  160.       this.checkVisible();
  161.       _close(this.splashPtr);
  162.       this.image = null;
  163.       this.wasClosed = true;
  164.    }
  165.  
  166.    public boolean isVisible() {
  167.       return !this.wasClosed && _isVisible(this.splashPtr);
  168.    }
  169.  
  170.    private static native void _update(long var0, int[] var2, int var3, int var4, int var5, int var6, int var7);
  171.  
  172.    private static native boolean _isVisible(long var0);
  173.  
  174.    private static native Rectangle _getBounds(long var0);
  175.  
  176.    private static native long _getInstance();
  177.  
  178.    private static native void _close(long var0);
  179.  
  180.    private static native String _getImageFileName(long var0);
  181.  
  182.    private static native String _getImageJarName(long var0);
  183.  
  184.    private static native boolean _setImageData(long var0, byte[] var2);
  185. }
  186.