< prev index next >

src/java.desktop/share/classes/java/awt/SplashScreen.java

Print this page




  31 import java.io.File;
  32 import sun.util.logging.PlatformLogger;
  33 import sun.awt.image.SunWritableRaster;
  34 
  35 /**
  36  * The splash screen can be displayed at application startup, before the
  37  * Java Virtual Machine (JVM) starts. The splash screen is displayed as an
  38  * undecorated window containing an image. You can use GIF, JPEG, or PNG files
  39  * for the image. Animation is supported for the GIF format, while transparency
  40  * is supported both for GIF and PNG.  The window is positioned at the center
  41  * of the screen. The position on multi-monitor systems is not specified. It is
  42  * platform and implementation dependent.  The splash screen window is closed
  43  * automatically as soon as the first window is displayed by Swing/AWT (may be
  44  * also closed manually using the Java API, see below).
  45  * <P>
  46  * If your application is packaged in a jar file, you can use the
  47  * "SplashScreen-Image" option in a manifest file to show a splash screen.
  48  * Place the image in the jar archive and specify the path in the option.
  49  * The path should not have a leading slash.
  50  * <BR>
  51  * For example, in the <code>manifest.mf</code> file:
  52  * <PRE>
  53  * Manifest-Version: 1.0
  54  * Main-Class: Test
  55  * SplashScreen-Image: filename.gif
  56  * </PRE>
  57  * <P>
  58  * If the Java implementation provides the command-line interface and you run
  59  * your application by using the command line or a shortcut, use the Java
  60  * application launcher option to show a splash screen. The Oracle reference
  61  * implementation allows you to specify the splash screen image location with
  62  * the {@code -splash:} option.
  63  * <BR>
  64  * For example:
  65  * <PRE>
  66  * java -splash:filename.gif Test
  67  * </PRE>
  68  * The command line interface has higher precedence over the manifest
  69  * setting.
  70  * <p>
  71  * The splash screen will be displayed as faithfully as possible to present the
  72  * whole splash screen image given the limitations of the target platform and
  73  * display.
  74  * <p>
  75  * It is implied that the specified image is presented on the screen "as is",
  76  * i.e. preserving the exact color values as specified in the image file. Under
  77  * certain circumstances, though, the presented image may differ, e.g. when
  78  * applying color dithering to present a 32 bits per pixel (bpp) image on a 16
  79  * or 8 bpp screen. The native platform display configuration may also affect
  80  * the colors of the displayed image (e.g.  color profiles, etc.)
  81  * <p>
  82  * The {@code SplashScreen} class provides the API for controlling the splash
  83  * screen. This class may be used to close the splash screen, change the splash
  84  * screen image, get the splash screen native window position/size, and paint
  85  * in the splash screen. It cannot be used to create the splash screen. You
  86  * should use the options provided by the Java implementation for that.
  87  * <p>
  88  * This class cannot be instantiated. Only a single instance of this class
  89  * can exist, and it may be obtained by using the {@link #getSplashScreen()}
  90  * static method. In case the splash screen has not been created at
  91  * application startup via the command line or manifest file option,
  92  * the <code>getSplashScreen</code> method returns <code>null</code>.
  93  *
  94  * @author Oleg Semenov
  95  * @since 1.6
  96  */
  97 public final class SplashScreen {
  98 
  99     SplashScreen(long ptr) { // non-public constructor
 100         splashPtr = ptr;
 101     }
 102 
 103     /**
 104      * Returns the {@code SplashScreen} object used for
 105      * Java startup splash screen control on systems that support display.
 106      *
 107      * @throws UnsupportedOperationException if the splash screen feature is not
 108      *         supported by the current toolkit
 109      * @throws HeadlessException if {@code GraphicsEnvironment.isHeadless()}
 110      *         returns true
 111      * @return the {@link SplashScreen} instance, or <code>null</code> if there is
 112      *         none or it has already been closed
 113      */
 114     public static  SplashScreen getSplashScreen() {
 115         synchronized (SplashScreen.class) {
 116             if (GraphicsEnvironment.isHeadless()) {
 117                 throw new HeadlessException();
 118             }
 119             // SplashScreen class is now a singleton
 120             if (!wasClosed && theInstance == null) {
 121                 java.security.AccessController.doPrivileged(
 122                     new java.security.PrivilegedAction<Void>() {
 123                         public Void run() {
 124                             System.loadLibrary("splashscreen");
 125                             return null;
 126                         }
 127                     });
 128                 long ptr = _getInstance();
 129                 if (ptr != 0 && _isVisible(ptr)) {
 130                     theInstance = new SplashScreen(ptr);
 131                 }
 132             }
 133             return theInstance;
 134         }
 135     }
 136 
 137     /**
 138      * Changes the splash screen image. The new image is loaded from the
 139      * specified URL; GIF, JPEG and PNG image formats are supported.
 140      * The method returns after the image has finished loading and the window
 141      * has been updated.
 142      * The splash screen window is resized according to the size of
 143      * the image and is centered on the screen.
 144      *
 145      * @param imageURL the non-<code>null</code> URL for the new
 146      *        splash screen image
 147      * @throws NullPointerException if {@code imageURL} is <code>null</code>
 148      * @throws IOException if there was an error while loading the image
 149      * @throws IllegalStateException if the splash screen has already been
 150      *         closed
 151      */
 152     public void setImageURL(URL imageURL) throws NullPointerException, IOException, IllegalStateException {
 153         checkVisible();
 154         URLConnection connection = imageURL.openConnection();
 155         connection.connect();
 156         int length = connection.getContentLength();
 157         java.io.InputStream stream = connection.getInputStream();
 158         byte[] buf = new byte[length];
 159         int off = 0;
 160         while(true) {
 161             // check for available data
 162             int available = stream.available();
 163             if (available <= 0) {
 164                 // no data available... well, let's try reading one byte
 165                 // we'll see what happens then
 166                 available = 1;
 167             }


 265      * You cannot control the size or position of the splash screen.
 266      * The splash screen size is adjusted automatically when the image changes.
 267      * <p>
 268      * The image may contain transparent areas, and thus the reported size may
 269      * be larger than the visible splash screen image on the screen.
 270      *
 271      * @return a {@link Dimension} object indicating the splash screen size
 272      * @throws IllegalStateException if the splash screen has already been closed
 273      */
 274     public Dimension getSize() throws IllegalStateException {
 275         return getBounds().getSize();
 276     }
 277 
 278     /**
 279      * Creates a graphics context (as a {@link Graphics2D} object) for the splash
 280      * screen overlay image, which allows you to draw over the splash screen.
 281      * Note that you do not draw on the main image but on the image that is
 282      * displayed over the main image using alpha blending. Also note that drawing
 283      * on the overlay image does not necessarily update the contents of splash
 284      * screen window. You should call {@code update()} on the
 285      * <code>SplashScreen</code> when you want the splash screen to be
 286      * updated immediately.
 287      * <p>
 288      * The pixel (0, 0) in the coordinate space of the graphics context
 289      * corresponds to the origin of the splash screen native window bounds (see
 290      * {@link #getBounds()}).
 291      *
 292      * @return graphics context for the splash screen overlay surface
 293      * @throws IllegalStateException if the splash screen has already been closed
 294      */
 295     public Graphics2D createGraphics() throws IllegalStateException {
 296         synchronized (SplashScreen.class) {
 297             checkVisible();
 298             if (image==null) {
 299                 // get unscaled splash image size
 300                 Dimension dim = _getBounds(splashPtr).getSize();
 301                 image = new BufferedImage(dim.width, dim.height,
 302                         BufferedImage.TYPE_INT_ARGB);
 303             }
 304             float scale = _getScaleFactor(splashPtr);
 305             Graphics2D g = image.createGraphics();


 385      * window have not occurred yet.
 386      *
 387      * @return true if the splash screen is visible (has not been closed yet),
 388      *         false otherwise
 389      */
 390     public boolean isVisible() {
 391         synchronized (SplashScreen.class) {
 392             return !wasClosed && _isVisible(splashPtr);
 393         }
 394     }
 395 
 396     private BufferedImage image; // overlay image
 397 
 398     private final long splashPtr; // pointer to native Splash structure
 399     private static boolean wasClosed = false;
 400 
 401     private URL imageURL;
 402 
 403     /**
 404      * The instance reference for the singleton.
 405      * (<code>null</code> if no instance exists yet.)
 406      *
 407      * @see #getSplashScreen
 408      * @see #close
 409      */
 410     private static SplashScreen theInstance = null;
 411 
 412     private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.SplashScreen");
 413 
 414     private static native void _update(long splashPtr, int[] data, int x, int y, int width, int height, int scanlineStride);
 415     private static native boolean _isVisible(long splashPtr);
 416     private static native Rectangle _getBounds(long splashPtr);
 417     private static native long _getInstance();
 418     private static native void _close(long splashPtr);
 419     private static native String _getImageFileName(long splashPtr);
 420     private static native String _getImageJarName(long SplashPtr);
 421     private static native boolean _setImageData(long SplashPtr, byte[] data);
 422     private static native float _getScaleFactor(long SplashPtr);
 423 
 424 }


  31 import java.io.File;
  32 import sun.util.logging.PlatformLogger;
  33 import sun.awt.image.SunWritableRaster;
  34 
  35 /**
  36  * The splash screen can be displayed at application startup, before the
  37  * Java Virtual Machine (JVM) starts. The splash screen is displayed as an
  38  * undecorated window containing an image. You can use GIF, JPEG, or PNG files
  39  * for the image. Animation is supported for the GIF format, while transparency
  40  * is supported both for GIF and PNG.  The window is positioned at the center
  41  * of the screen. The position on multi-monitor systems is not specified. It is
  42  * platform and implementation dependent.  The splash screen window is closed
  43  * automatically as soon as the first window is displayed by Swing/AWT (may be
  44  * also closed manually using the Java API, see below).
  45  * <P>
  46  * If your application is packaged in a jar file, you can use the
  47  * "SplashScreen-Image" option in a manifest file to show a splash screen.
  48  * Place the image in the jar archive and specify the path in the option.
  49  * The path should not have a leading slash.
  50  * <BR>
  51  * For example, in the {@code manifest.mf} file:
  52  * <PRE>
  53  * Manifest-Version: 1.0
  54  * Main-Class: Test
  55  * SplashScreen-Image: filename.gif
  56  * </PRE>
  57  * <P>
  58  * If the Java implementation provides the command-line interface and you run
  59  * your application by using the command line or a shortcut, use the Java
  60  * application launcher option to show a splash screen. The Oracle reference
  61  * implementation allows you to specify the splash screen image location with
  62  * the {@code -splash:} option.
  63  * <BR>
  64  * For example:
  65  * <PRE>
  66  * java -splash:filename.gif Test
  67  * </PRE>
  68  * The command line interface has higher precedence over the manifest
  69  * setting.
  70  * <p>
  71  * The splash screen will be displayed as faithfully as possible to present the
  72  * whole splash screen image given the limitations of the target platform and
  73  * display.
  74  * <p>
  75  * It is implied that the specified image is presented on the screen "as is",
  76  * i.e. preserving the exact color values as specified in the image file. Under
  77  * certain circumstances, though, the presented image may differ, e.g. when
  78  * applying color dithering to present a 32 bits per pixel (bpp) image on a 16
  79  * or 8 bpp screen. The native platform display configuration may also affect
  80  * the colors of the displayed image (e.g.  color profiles, etc.)
  81  * <p>
  82  * The {@code SplashScreen} class provides the API for controlling the splash
  83  * screen. This class may be used to close the splash screen, change the splash
  84  * screen image, get the splash screen native window position/size, and paint
  85  * in the splash screen. It cannot be used to create the splash screen. You
  86  * should use the options provided by the Java implementation for that.
  87  * <p>
  88  * This class cannot be instantiated. Only a single instance of this class
  89  * can exist, and it may be obtained by using the {@link #getSplashScreen()}
  90  * static method. In case the splash screen has not been created at
  91  * application startup via the command line or manifest file option,
  92  * the {@code getSplashScreen} method returns {@code null}.
  93  *
  94  * @author Oleg Semenov
  95  * @since 1.6
  96  */
  97 public final class SplashScreen {
  98 
  99     SplashScreen(long ptr) { // non-public constructor
 100         splashPtr = ptr;
 101     }
 102 
 103     /**
 104      * Returns the {@code SplashScreen} object used for
 105      * Java startup splash screen control on systems that support display.
 106      *
 107      * @throws UnsupportedOperationException if the splash screen feature is not
 108      *         supported by the current toolkit
 109      * @throws HeadlessException if {@code GraphicsEnvironment.isHeadless()}
 110      *         returns true
 111      * @return the {@link SplashScreen} instance, or {@code null} if there is
 112      *         none or it has already been closed
 113      */
 114     public static  SplashScreen getSplashScreen() {
 115         synchronized (SplashScreen.class) {
 116             if (GraphicsEnvironment.isHeadless()) {
 117                 throw new HeadlessException();
 118             }
 119             // SplashScreen class is now a singleton
 120             if (!wasClosed && theInstance == null) {
 121                 java.security.AccessController.doPrivileged(
 122                     new java.security.PrivilegedAction<Void>() {
 123                         public Void run() {
 124                             System.loadLibrary("splashscreen");
 125                             return null;
 126                         }
 127                     });
 128                 long ptr = _getInstance();
 129                 if (ptr != 0 && _isVisible(ptr)) {
 130                     theInstance = new SplashScreen(ptr);
 131                 }
 132             }
 133             return theInstance;
 134         }
 135     }
 136 
 137     /**
 138      * Changes the splash screen image. The new image is loaded from the
 139      * specified URL; GIF, JPEG and PNG image formats are supported.
 140      * The method returns after the image has finished loading and the window
 141      * has been updated.
 142      * The splash screen window is resized according to the size of
 143      * the image and is centered on the screen.
 144      *
 145      * @param imageURL the non-{@code null} URL for the new
 146      *        splash screen image
 147      * @throws NullPointerException if {@code imageURL} is {@code null}
 148      * @throws IOException if there was an error while loading the image
 149      * @throws IllegalStateException if the splash screen has already been
 150      *         closed
 151      */
 152     public void setImageURL(URL imageURL) throws NullPointerException, IOException, IllegalStateException {
 153         checkVisible();
 154         URLConnection connection = imageURL.openConnection();
 155         connection.connect();
 156         int length = connection.getContentLength();
 157         java.io.InputStream stream = connection.getInputStream();
 158         byte[] buf = new byte[length];
 159         int off = 0;
 160         while(true) {
 161             // check for available data
 162             int available = stream.available();
 163             if (available <= 0) {
 164                 // no data available... well, let's try reading one byte
 165                 // we'll see what happens then
 166                 available = 1;
 167             }


 265      * You cannot control the size or position of the splash screen.
 266      * The splash screen size is adjusted automatically when the image changes.
 267      * <p>
 268      * The image may contain transparent areas, and thus the reported size may
 269      * be larger than the visible splash screen image on the screen.
 270      *
 271      * @return a {@link Dimension} object indicating the splash screen size
 272      * @throws IllegalStateException if the splash screen has already been closed
 273      */
 274     public Dimension getSize() throws IllegalStateException {
 275         return getBounds().getSize();
 276     }
 277 
 278     /**
 279      * Creates a graphics context (as a {@link Graphics2D} object) for the splash
 280      * screen overlay image, which allows you to draw over the splash screen.
 281      * Note that you do not draw on the main image but on the image that is
 282      * displayed over the main image using alpha blending. Also note that drawing
 283      * on the overlay image does not necessarily update the contents of splash
 284      * screen window. You should call {@code update()} on the
 285      * {@code SplashScreen} when you want the splash screen to be
 286      * updated immediately.
 287      * <p>
 288      * The pixel (0, 0) in the coordinate space of the graphics context
 289      * corresponds to the origin of the splash screen native window bounds (see
 290      * {@link #getBounds()}).
 291      *
 292      * @return graphics context for the splash screen overlay surface
 293      * @throws IllegalStateException if the splash screen has already been closed
 294      */
 295     public Graphics2D createGraphics() throws IllegalStateException {
 296         synchronized (SplashScreen.class) {
 297             checkVisible();
 298             if (image==null) {
 299                 // get unscaled splash image size
 300                 Dimension dim = _getBounds(splashPtr).getSize();
 301                 image = new BufferedImage(dim.width, dim.height,
 302                         BufferedImage.TYPE_INT_ARGB);
 303             }
 304             float scale = _getScaleFactor(splashPtr);
 305             Graphics2D g = image.createGraphics();


 385      * window have not occurred yet.
 386      *
 387      * @return true if the splash screen is visible (has not been closed yet),
 388      *         false otherwise
 389      */
 390     public boolean isVisible() {
 391         synchronized (SplashScreen.class) {
 392             return !wasClosed && _isVisible(splashPtr);
 393         }
 394     }
 395 
 396     private BufferedImage image; // overlay image
 397 
 398     private final long splashPtr; // pointer to native Splash structure
 399     private static boolean wasClosed = false;
 400 
 401     private URL imageURL;
 402 
 403     /**
 404      * The instance reference for the singleton.
 405      * ({@code null} if no instance exists yet.)
 406      *
 407      * @see #getSplashScreen
 408      * @see #close
 409      */
 410     private static SplashScreen theInstance = null;
 411 
 412     private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.SplashScreen");
 413 
 414     private static native void _update(long splashPtr, int[] data, int x, int y, int width, int height, int scanlineStride);
 415     private static native boolean _isVisible(long splashPtr);
 416     private static native Rectangle _getBounds(long splashPtr);
 417     private static native long _getInstance();
 418     private static native void _close(long splashPtr);
 419     private static native String _getImageFileName(long splashPtr);
 420     private static native String _getImageJarName(long SplashPtr);
 421     private static native boolean _setImageData(long SplashPtr, byte[] data);
 422     private static native float _getScaleFactor(long SplashPtr);
 423 
 424 }
< prev index next >