author | henryjen |
Tue, 10 Jun 2014 16:18:54 -0700 | |
changeset 24865 | 09b1d992ca72 |
parent 23010 | 6dadb192ad81 |
child 25552 | 96abb01815f6 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18178
diff
changeset
|
2 |
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package java.awt; |
|
26 |
||
27 |
import java.io.IOException; |
|
28 |
import java.awt.image.*; |
|
29 |
import java.net.URL; |
|
30 |
import java.net.URLConnection; |
|
31 |
import java.io.File; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
32 |
import sun.util.logging.PlatformLogger; |
2 | 33 |
import sun.awt.image.SunWritableRaster; |
34 |
||
35 |
/** |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
36 |
* The splash screen can be displayed at application startup, before the |
2 | 37 |
* Java Virtual Machine (JVM) starts. The splash screen is displayed as an |
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
38 |
* undecorated window containing an image. You can use GIF, JPEG, or PNG files |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
39 |
* for the image. Animation is supported for the GIF format, while transparency |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
40 |
* is supported both for GIF and PNG. The window is positioned at the center |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
41 |
* of the screen. The position on multi-monitor systems is not specified. It is |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
42 |
* platform and implementation dependent. The splash screen window is closed |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
43 |
* automatically as soon as the first window is displayed by Swing/AWT (may be |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
44 |
* also closed manually using the Java API, see below). |
2 | 45 |
* <P> |
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
46 |
* If your application is packaged in a jar file, you can use the |
2 | 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> |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
57 |
* <P> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
58 |
* If the Java implementation provides the command-line interface and you run |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
59 |
* your application by using the command line or a shortcut, use the Java |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
60 |
* application launcher option to show a splash screen. The Oracle reference |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
61 |
* implementation allows you to specify the splash screen image location with |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
62 |
* the {@code -splash:} option. |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
63 |
* <BR> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
64 |
* For example: |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
65 |
* <PRE> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
66 |
* java -splash:filename.gif Test |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
67 |
* </PRE> |
2 | 68 |
* The command line interface has higher precedence over the manifest |
69 |
* setting. |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
70 |
* <p> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
71 |
* The splash screen will be displayed as faithfully as possible to present the |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
72 |
* whole splash screen image given the limitations of the target platform and |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
73 |
* display. |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
74 |
* <p> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
75 |
* It is implied that the specified image is presented on the screen "as is", |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
76 |
* i.e. preserving the exact color values as specified in the image file. Under |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
77 |
* certain circumstances, though, the presented image may differ, e.g. when |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
78 |
* applying color dithering to present a 32 bits per pixel (bpp) image on a 16 |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
79 |
* or 8 bpp screen. The native platform display configuration may also affect |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
80 |
* the colors of the displayed image (e.g. color profiles, etc.) |
2 | 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 |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
84 |
* screen image, get the splash screen native window position/size, and paint |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
85 |
* in the splash screen. It cannot be used to create the splash screen. You |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
86 |
* should use the options provided by the Java implementation for that. |
2 | 87 |
* <p> |
88 |
* This class cannot be instantiated. Only a single instance of this class |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
89 |
* can exist, and it may be obtained by using the {@link #getSplashScreen()} |
2 | 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 |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
105 |
* Java startup splash screen control on systems that support display. |
2 | 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( |
|
12559
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
7775
diff
changeset
|
122 |
new java.security.PrivilegedAction<Void>() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
7775
diff
changeset
|
123 |
public Void run() { |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
7775
diff
changeset
|
124 |
System.loadLibrary("splashscreen"); |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
7775
diff
changeset
|
125 |
return null; |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
7775
diff
changeset
|
126 |
} |
9456ceada8b1
7164376: Replace use of sun.security.action.LoadLibraryAction with System.loadLibrary
mchung
parents:
7775
diff
changeset
|
127 |
}); |
2 | 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 |
} |
|
168 |
// check for enough room in buffer, realloc if needed |
|
169 |
// the buffer always grows in size 2x minimum |
|
170 |
if (off + available > length) { |
|
171 |
length = off*2; |
|
172 |
if (off + available > length) { |
|
173 |
length = available+off; |
|
174 |
} |
|
175 |
byte[] oldBuf = buf; |
|
176 |
buf = new byte[length]; |
|
177 |
System.arraycopy(oldBuf, 0, buf, 0, off); |
|
178 |
} |
|
179 |
// now read the data |
|
180 |
int result = stream.read(buf, off, available); |
|
181 |
if (result < 0) { |
|
182 |
break; |
|
183 |
} |
|
184 |
off += result; |
|
185 |
} |
|
186 |
synchronized(SplashScreen.class) { |
|
187 |
checkVisible(); |
|
188 |
if (!_setImageData(splashPtr, buf)) { |
|
189 |
throw new IOException("Bad image format or i/o error when loading image"); |
|
190 |
} |
|
191 |
this.imageURL = imageURL; |
|
192 |
} |
|
193 |
} |
|
194 |
||
195 |
private void checkVisible() { |
|
196 |
if (!isVisible()) { |
|
197 |
throw new IllegalStateException("no splash screen available"); |
|
198 |
} |
|
199 |
} |
|
200 |
/** |
|
201 |
* Returns the current splash screen image. |
|
202 |
* |
|
203 |
* @return URL for the current splash screen image file |
|
204 |
* @throws IllegalStateException if the splash screen has already been closed |
|
205 |
*/ |
|
206 |
public URL getImageURL() throws IllegalStateException { |
|
207 |
synchronized (SplashScreen.class) { |
|
208 |
checkVisible(); |
|
209 |
if (imageURL == null) { |
|
210 |
try { |
|
211 |
String fileName = _getImageFileName(splashPtr); |
|
212 |
String jarName = _getImageJarName(splashPtr); |
|
213 |
if (fileName != null) { |
|
214 |
if (jarName != null) { |
|
215 |
imageURL = new URL("jar:"+(new File(jarName).toURL().toString())+"!/"+fileName); |
|
216 |
} else { |
|
217 |
imageURL = new File(fileName).toURL(); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
catch(java.net.MalformedURLException e) { |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
12559
diff
changeset
|
222 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
223 |
log.fine("MalformedURLException caught in the getImageURL() method", e); |
2 | 224 |
} |
225 |
} |
|
226 |
} |
|
227 |
return imageURL; |
|
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. |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
238 |
* <p> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
239 |
* The image may contain transparent areas, and thus the reported bounds may |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
240 |
* be larger than the visible splash screen image on the screen. |
2 | 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. |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
259 |
* <p> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
260 |
* The image may contain transparent areas, and thus the reported size may |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
261 |
* be larger than the visible splash screen image on the screen. |
2 | 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 |
} |
|
269 |
||
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. |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
279 |
* <p> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
280 |
* The pixel (0, 0) in the coordinate space of the graphics context |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
281 |
* corresponds to the origin of the splash screen native window bounds (see |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
282 |
* {@link #getBounds()}). |
2 | 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(); |
|
314 |
if (!(buf instanceof DataBufferInt)) { |
|
315 |
throw new AssertionError("Overlay image DataBuffer is of invalid type == "+buf.getClass().getName()); |
|
316 |
} |
|
317 |
int numBanks = buf.getNumBanks(); |
|
318 |
if (numBanks!=1) { |
|
319 |
throw new AssertionError("Invalid number of banks =="+numBanks+" in overlay image DataBuffer"); |
|
320 |
} |
|
321 |
if (!(image.getSampleModel() instanceof SinglePixelPackedSampleModel)) { |
|
322 |
throw new AssertionError("Overlay image has invalid sample model == "+image.getSampleModel().getClass().getName()); |
|
323 |
} |
|
324 |
SinglePixelPackedSampleModel sm = (SinglePixelPackedSampleModel)image.getSampleModel(); |
|
325 |
int scanlineStride = sm.getScanlineStride(); |
|
326 |
Rectangle rect = image.getRaster().getBounds(); |
|
327 |
// Note that we steal the data array here, but just for reading |
|
328 |
// so we do not need to mark the DataBuffer dirty... |
|
329 |
int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0); |
|
330 |
synchronized(SplashScreen.class) { |
|
331 |
checkVisible(); |
|
332 |
_update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
/** |
|
337 |
* Hides the splash screen, closes the window, and releases all associated |
|
338 |
* resources. |
|
339 |
* |
|
340 |
* @throws IllegalStateException if the splash screen has already been closed |
|
341 |
*/ |
|
342 |
public void close() throws IllegalStateException { |
|
343 |
synchronized (SplashScreen.class) { |
|
344 |
checkVisible(); |
|
345 |
_close(splashPtr); |
|
346 |
image = null; |
|
6823
cff6c85026c4
6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents:
5506
diff
changeset
|
347 |
SplashScreen.markClosed(); |
cff6c85026c4
6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents:
5506
diff
changeset
|
348 |
} |
cff6c85026c4
6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents:
5506
diff
changeset
|
349 |
} |
cff6c85026c4
6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents:
5506
diff
changeset
|
350 |
|
cff6c85026c4
6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents:
5506
diff
changeset
|
351 |
static void markClosed() { |
cff6c85026c4
6990352: SplashScreen.getSplashScreen() does not return null for implicitly closed splash screen
anthony
parents:
5506
diff
changeset
|
352 |
synchronized (SplashScreen.class) { |
2 | 353 |
wasClosed = true; |
354 |
theInstance = null; |
|
355 |
} |
|
356 |
} |
|
357 |
||
358 |
||
359 |
/** |
|
360 |
* Determines whether the splash screen is visible. The splash screen may |
|
361 |
* be hidden using {@link #close()}, it is also hidden automatically when |
|
362 |
* the first AWT/Swing window is made visible. |
|
7765
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
363 |
* <p> |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
364 |
* Note that the native platform may delay presenting the splash screen |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
365 |
* native window on the screen. The return value of {@code true} for this |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
366 |
* method only guarantees that the conditions to hide the splash screen |
a9e4a2c0600e
6993803: Request to update SplashScreen specification
anthony
parents:
6823
diff
changeset
|
367 |
* window have not occurred yet. |
2 | 368 |
* |
369 |
* @return true if the splash screen is visible (has not been closed yet), |
|
370 |
* false otherwise |
|
371 |
*/ |
|
372 |
public boolean isVisible() { |
|
373 |
synchronized (SplashScreen.class) { |
|
374 |
return !wasClosed && _isVisible(splashPtr); |
|
375 |
} |
|
376 |
} |
|
377 |
||
378 |
private BufferedImage image; // overlay image |
|
379 |
||
380 |
private final long splashPtr; // pointer to native Splash structure |
|
381 |
private static boolean wasClosed = false; |
|
382 |
||
383 |
private URL imageURL; |
|
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 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
394 |
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.SplashScreen"); |
2 | 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 |
}; |