228 }
229 }
230
231 /**
232 * Returns the bounds of the splash screen window as a {@link Rectangle}.
233 * This may be useful if, for example, you want to replace the splash
234 * screen with your window at the same location.
235 * <p>
236 * You cannot control the size or position of the splash screen.
237 * The splash screen size is adjusted automatically when the image changes.
238 * <p>
239 * The image may contain transparent areas, and thus the reported bounds may
240 * be larger than the visible splash screen image on the screen.
241 *
242 * @return a {@code Rectangle} containing the splash screen bounds
243 * @throws IllegalStateException if the splash screen has already been closed
244 */
245 public Rectangle getBounds() throws IllegalStateException {
246 synchronized (SplashScreen.class) {
247 checkVisible();
248 return _getBounds(splashPtr);
249 }
250 }
251
252 /**
253 * Returns the size of the splash screen window as a {@link Dimension}.
254 * This may be useful if, for example,
255 * you want to draw on the splash screen overlay surface.
256 * <p>
257 * You cannot control the size or position of the splash screen.
258 * The splash screen size is adjusted automatically when the image changes.
259 * <p>
260 * The image may contain transparent areas, and thus the reported size may
261 * be larger than the visible splash screen image on the screen.
262 *
263 * @return a {@link Dimension} object indicating the splash screen size
264 * @throws IllegalStateException if the splash screen has already been closed
265 */
266 public Dimension getSize() throws IllegalStateException {
267 return getBounds().getSize();
268 }
270 /**
271 * Creates a graphics context (as a {@link Graphics2D} object) for the splash
272 * screen overlay image, which allows you to draw over the splash screen.
273 * Note that you do not draw on the main image but on the image that is
274 * displayed over the main image using alpha blending. Also note that drawing
275 * on the overlay image does not necessarily update the contents of splash
276 * screen window. You should call {@code update()} on the
277 * <code>SplashScreen</code> when you want the splash screen to be
278 * updated immediately.
279 * <p>
280 * The pixel (0, 0) in the coordinate space of the graphics context
281 * corresponds to the origin of the splash screen native window bounds (see
282 * {@link #getBounds()}).
283 *
284 * @return graphics context for the splash screen overlay surface
285 * @throws IllegalStateException if the splash screen has already been closed
286 */
287 public Graphics2D createGraphics() throws IllegalStateException {
288 synchronized (SplashScreen.class) {
289 if (image==null) {
290 Dimension dim = getSize();
291 image = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
292 }
293 return image.createGraphics();
294 }
295 }
296
297 /**
298 * Updates the splash window with current contents of the overlay image.
299 *
300 * @throws IllegalStateException if the overlay image does not exist;
301 * for example, if {@code createGraphics} has never been called,
302 * or if the splash screen has already been closed
303 */
304 public void update() throws IllegalStateException {
305 BufferedImage image;
306 synchronized (SplashScreen.class) {
307 checkVisible();
308 image = this.image;
309 }
310 if (image == null) {
311 throw new IllegalStateException("no overlay image available");
312 }
313 DataBuffer buf = image.getRaster().getDataBuffer();
384
385 /**
386 * The instance reference for the singleton.
387 * (<code>null</code> if no instance exists yet.)
388 *
389 * @see #getSplashScreen
390 * @see #close
391 */
392 private static SplashScreen theInstance = null;
393
394 private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.SplashScreen");
395
396 private native static void _update(long splashPtr, int[] data, int x, int y, int width, int height, int scanlineStride);
397 private native static boolean _isVisible(long splashPtr);
398 private native static Rectangle _getBounds(long splashPtr);
399 private native static long _getInstance();
400 private native static void _close(long splashPtr);
401 private native static String _getImageFileName(long splashPtr);
402 private native static String _getImageJarName(long SplashPtr);
403 private native static boolean _setImageData(long SplashPtr, byte[] data);
404
405 };
|
228 }
229 }
230
231 /**
232 * Returns the bounds of the splash screen window as a {@link Rectangle}.
233 * This may be useful if, for example, you want to replace the splash
234 * screen with your window at the same location.
235 * <p>
236 * You cannot control the size or position of the splash screen.
237 * The splash screen size is adjusted automatically when the image changes.
238 * <p>
239 * The image may contain transparent areas, and thus the reported bounds may
240 * be larger than the visible splash screen image on the screen.
241 *
242 * @return a {@code Rectangle} containing the splash screen bounds
243 * @throws IllegalStateException if the splash screen has already been closed
244 */
245 public Rectangle getBounds() throws IllegalStateException {
246 synchronized (SplashScreen.class) {
247 checkVisible();
248 float scale = _getScaleFactor(splashPtr);
249 Rectangle bounds = _getBounds(splashPtr);
250 assert scale > 0;
251 if (scale > 0 && scale != 1) {
252 bounds.setSize((int) (bounds.getWidth() / scale),
253 (int) (bounds.getWidth() / scale));
254 }
255 return bounds;
256 }
257 }
258
259 /**
260 * Returns the size of the splash screen window as a {@link Dimension}.
261 * This may be useful if, for example,
262 * you want to draw on the splash screen overlay surface.
263 * <p>
264 * You cannot control the size or position of the splash screen.
265 * The splash screen size is adjusted automatically when the image changes.
266 * <p>
267 * The image may contain transparent areas, and thus the reported size may
268 * be larger than the visible splash screen image on the screen.
269 *
270 * @return a {@link Dimension} object indicating the splash screen size
271 * @throws IllegalStateException if the splash screen has already been closed
272 */
273 public Dimension getSize() throws IllegalStateException {
274 return getBounds().getSize();
275 }
277 /**
278 * Creates a graphics context (as a {@link Graphics2D} object) for the splash
279 * screen overlay image, which allows you to draw over the splash screen.
280 * Note that you do not draw on the main image but on the image that is
281 * displayed over the main image using alpha blending. Also note that drawing
282 * on the overlay image does not necessarily update the contents of splash
283 * screen window. You should call {@code update()} on the
284 * <code>SplashScreen</code> when you want the splash screen to be
285 * updated immediately.
286 * <p>
287 * The pixel (0, 0) in the coordinate space of the graphics context
288 * corresponds to the origin of the splash screen native window bounds (see
289 * {@link #getBounds()}).
290 *
291 * @return graphics context for the splash screen overlay surface
292 * @throws IllegalStateException if the splash screen has already been closed
293 */
294 public Graphics2D createGraphics() throws IllegalStateException {
295 synchronized (SplashScreen.class) {
296 if (image==null) {
297 // get unscaled splash image size
298 Dimension dim = _getBounds(splashPtr).getSize();
299 image = new BufferedImage(dim.width, dim.height,
300 BufferedImage.TYPE_INT_ARGB);
301 }
302 float scale = _getScaleFactor(splashPtr);
303 Graphics2D g = image.createGraphics();
304 assert (scale > 0);
305 if (scale <= 0) {
306 scale = 1;
307 }
308 g.scale(scale, scale);
309 return g;
310 }
311 }
312
313 /**
314 * Updates the splash window with current contents of the overlay image.
315 *
316 * @throws IllegalStateException if the overlay image does not exist;
317 * for example, if {@code createGraphics} has never been called,
318 * or if the splash screen has already been closed
319 */
320 public void update() throws IllegalStateException {
321 BufferedImage image;
322 synchronized (SplashScreen.class) {
323 checkVisible();
324 image = this.image;
325 }
326 if (image == null) {
327 throw new IllegalStateException("no overlay image available");
328 }
329 DataBuffer buf = image.getRaster().getDataBuffer();
400
401 /**
402 * The instance reference for the singleton.
403 * (<code>null</code> if no instance exists yet.)
404 *
405 * @see #getSplashScreen
406 * @see #close
407 */
408 private static SplashScreen theInstance = null;
409
410 private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.SplashScreen");
411
412 private native static void _update(long splashPtr, int[] data, int x, int y, int width, int height, int scanlineStride);
413 private native static boolean _isVisible(long splashPtr);
414 private native static Rectangle _getBounds(long splashPtr);
415 private native static long _getInstance();
416 private native static void _close(long splashPtr);
417 private native static String _getImageFileName(long splashPtr);
418 private native static String _getImageJarName(long SplashPtr);
419 private native static boolean _setImageData(long SplashPtr, byte[] data);
420 private native static float _getScaleFactor(long SplashPtr);
421
422 };
|