Methods Summary |
---|
private static native void | _close(long splashPtr)
|
private static native java.awt.Rectangle | _getBounds(long splashPtr)
|
private static native java.lang.String | _getImageFileName(long splashPtr)
|
private static native java.lang.String | _getImageJarName(long SplashPtr)
|
private static native long | _getInstance()
|
private static native boolean | _isVisible(long splashPtr)
|
private static native boolean | _setImageData(long SplashPtr, byte[] data)
|
private static native void | _update(long splashPtr, int[] data, int x, int y, int width, int height, int scanlineStride)
|
private void | checkVisible()
if (!isVisible()) {
throw new IllegalStateException("no splash screen available");
}
|
public synchronized void | close()Hides the splash screen, closes the window, and releases all associated
resources.
checkVisible();
_close(splashPtr);
image = null;
wasClosed = true;
// There should be resetting the theInstance to null to prevent memory
// leak. But it brings some more problems with the bug 6382748, so we
// let the limited leak to stay.
|
public java.awt.Graphics2D | createGraphics()Creates a graphics context (as a {@link Graphics2D} object) for the splash
screen overlay image, which allows you to draw over the splash screen.
Note that you do not draw on the main image but on the image that is
displayed over the main image using alpha blending. Also note that drawing
on the overlay image does not necessarily update the contents of splash
screen window. You should call {@code update()} on the
SplashScreen when you want the splash screen to be
updated immediately.
if (image==null) {
Dimension dim = getSize();
image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
}
return image.createGraphics();
|
public java.awt.Rectangle | getBounds()Returns the bounds of the splash screen window as a {@link Rectangle}.
This may be useful if, for example, you want to replace the splash
screen with your window at the same location.
You cannot control the size or position of the splash screen.
The splash screen size is adjusted automatically when the image changes.
checkVisible();
return _getBounds(splashPtr);
|
public synchronized java.net.URL | getImageURL()Returns the current splash screen image.
checkVisible();
if (imageURL == null) {
try {
String fileName = _getImageFileName(splashPtr);
String jarName = _getImageJarName(splashPtr);
if (fileName != null) {
if (jarName != null) {
imageURL = new URL("jar:"+(new File(jarName).toURL().toString())+"!/"+fileName);
} else {
imageURL = new File(fileName).toURL();
}
}
}
catch(java.net.MalformedURLException e) {
// we'll just return null in this case
}
}
return imageURL;
|
public java.awt.Dimension | getSize()Returns the size of the splash screen window as a {@link Dimension}.
This may be useful if, for example,
you want to draw on the splash screen overlay surface.
You cannot control the size or position of the splash screen.
The splash screen size is adjusted automatically when the image changes.
return getBounds().getSize();
|
public static synchronized java.awt.SplashScreen | getSplashScreen()Returns the {@code SplashScreen} object used for
Java startup splash screen control.
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
// SplashScreen class is now a singleton
if (SplashScreen.theInstance == null) {
java.security.AccessController.doPrivileged(
new sun.security.action.LoadLibraryAction("splashscreen"));
long ptr = _getInstance();
if (ptr == 0) {
return null;
}
if (!_isVisible(ptr)) {
return null;
}
SplashScreen.theInstance = new SplashScreen(ptr);
}
return (theInstance.isVisible() ? theInstance : null);
|
public boolean | isVisible()Determines whether the splash screen is visible. The splash screen may
be hidden using {@link #close()}, it is also hidden automatically when
the first AWT/Swing window is made visible.
return !wasClosed && _isVisible(splashPtr);
|
public void | setImageURL(java.net.URL imageURL)Changes the splash screen image. The new image is loaded from the
specified URL; GIF, JPEG and PNG image formats are supported.
The method returns after the image has finished loading and the window
has been updated.
The splash screen window is resized according to the size of
the image and is centered on the screen.
checkVisible();
URLConnection connection = imageURL.openConnection();
connection.connect();
int length = connection.getContentLength();
java.io.InputStream stream = connection.getInputStream();
byte[] buf = new byte[length];
int off = 0;
while(true) {
// check for available data
int available = stream.available();
if (available <= 0) {
// no data available... well, let's try reading one byte
// we'll see what happens then
available = 1;
}
// check for enough room in buffer, realloc if needed
// the buffer always grows in size 2x minimum
if (off + available > length) {
length = off*2;
if (off + available > length) {
length = available+off;
}
byte[] oldBuf = buf;
buf = new byte[length];
System.arraycopy(oldBuf, 0, buf, 0, off);
}
// now read the data
int result = stream.read(buf, off, available);
if (result < 0) {
break;
}
off += result;
}
synchronized(this) {
if (!_setImageData(splashPtr, buf)) {
throw new IOException("Bad image format or i/o error when loading image");
}
this.imageURL = imageURL;
}
|
public void | update()Updates the splash window with current contents of the overlay image.
checkVisible();
if (image == null) {
throw new IllegalStateException("no overlay image available");
}
DataBuffer buf = image.getRaster().getDataBuffer();
if (!(buf instanceof DataBufferInt)) {
throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName());
}
int numBanks = buf.getNumBanks();
if (numBanks!=1) {
throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer");
}
if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) {
throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName());
}
SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel();
int scanlineStride = sm.getScanlineStride();
Rectangle rect = image.getRaster().getBounds();
int[] data = ((DataBufferInt)buf).getData();
_update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
|