开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from Stefan/Java8Source
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
develop
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (2)
master
develop
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
develop
Java8Source
/
src
/
java
/
awt
/
SplashScreen.java
Java8Source
/
src
/
java
/
awt
/
SplashScreen.java
SplashScreen.java 16.38 KB
一键复制 编辑 原始数据 按行查看 历史
Stefan 提交于 2020年08月11日 23:17 +08:00 . 初始化
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.awt;
import java.io.IOException;
import java.awt.image.*;
import java.net.URL;
import java.net.URLConnection;
import java.io.File;
import sun.util.logging.PlatformLogger;
import sun.awt.image.SunWritableRaster;
/**
* The splash screen can be displayed at application startup, before the
* Java Virtual Machine (JVM) starts. The splash screen is displayed as an
* undecorated window containing an image. You can use GIF, JPEG, or PNG files
* for the image. Animation is supported for the GIF format, while transparency
* is supported both for GIF and PNG. The window is positioned at the center
* of the screen. The position on multi-monitor systems is not specified. It is
* platform and implementation dependent. The splash screen window is closed
* automatically as soon as the first window is displayed by Swing/AWT (may be
* also closed manually using the Java API, see below).
* <P>
* If your application is packaged in a jar file, you can use the
* "SplashScreen-Image" option in a manifest file to show a splash screen.
* Place the image in the jar archive and specify the path in the option.
* The path should not have a leading slash.
* <BR>
* For example, in the <code>manifest.mf</code> file:
* <PRE>
* Manifest-Version: 1.0
* Main-Class: Test
* SplashScreen-Image: filename.gif
* </PRE>
* <P>
* If the Java implementation provides the command-line interface and you run
* your application by using the command line or a shortcut, use the Java
* application launcher option to show a splash screen. The Oracle reference
* implementation allows you to specify the splash screen image location with
* the {@code -splash:} option.
* <BR>
* For example:
* <PRE>
* java -splash:filename.gif Test
* </PRE>
* The command line interface has higher precedence over the manifest
* setting.
* <p>
* The splash screen will be displayed as faithfully as possible to present the
* whole splash screen image given the limitations of the target platform and
* display.
* <p>
* It is implied that the specified image is presented on the screen "as is",
* i.e. preserving the exact color values as specified in the image file. Under
* certain circumstances, though, the presented image may differ, e.g. when
* applying color dithering to present a 32 bits per pixel (bpp) image on a 16
* or 8 bpp screen. The native platform display configuration may also affect
* the colors of the displayed image (e.g. color profiles, etc.)
* <p>
* The {@code SplashScreen} class provides the API for controlling the splash
* screen. This class may be used to close the splash screen, change the splash
* screen image, get the splash screen native window position/size, and paint
* in the splash screen. It cannot be used to create the splash screen. You
* should use the options provided by the Java implementation for that.
* <p>
* This class cannot be instantiated. Only a single instance of this class
* can exist, and it may be obtained by using the {@link #getSplashScreen()}
* static method. In case the splash screen has not been created at
* application startup via the command line or manifest file option,
* the <code>getSplashScreen</code> method returns <code>null</code>.
*
* @author Oleg Semenov
* @since 1.6
*/
public final class SplashScreen {
SplashScreen(long ptr) { // non-public constructor
splashPtr = ptr;
}
/**
* Returns the {@code SplashScreen} object used for
* Java startup splash screen control on systems that support display.
*
* @throws UnsupportedOperationException if the splash screen feature is not
* supported by the current toolkit
* @throws HeadlessException if {@code GraphicsEnvironment.isHeadless()}
* returns true
* @return the {@link SplashScreen} instance, or <code>null</code> if there is
* none or it has already been closed
*/
public static SplashScreen getSplashScreen() {
synchronized (SplashScreen.class) {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
// SplashScreen class is now a singleton
if (!wasClosed && theInstance == null) {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("splashscreen");
return null;
}
});
long ptr = _getInstance();
if (ptr != 0 && _isVisible(ptr)) {
theInstance = new SplashScreen(ptr);
}
}
return theInstance;
}
}
/**
* 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.
*
* @param imageURL the non-<code>null</code> URL for the new
* splash screen image
* @throws NullPointerException if {@code imageURL} is <code>null</code>
* @throws IOException if there was an error while loading the image
* @throws IllegalStateException if the splash screen has already been
* closed
*/
public void setImageURL(URL imageURL) throws NullPointerException, IOException, IllegalStateException {
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(SplashScreen.class) {
checkVisible();
if (!_setImageData(splashPtr, buf)) {
throw new IOException("Bad image format or i/o error when loading image");
}
this.imageURL = imageURL;
}
}
private void checkVisible() {
if (!isVisible()) {
throw new IllegalStateException("no splash screen available");
}
}
/**
* Returns the current splash screen image.
*
* @return URL for the current splash screen image file
* @throws IllegalStateException if the splash screen has already been closed
*/
public URL getImageURL() throws IllegalStateException {
synchronized (SplashScreen.class) {
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) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("MalformedURLException caught in the getImageURL() method", e);
}
}
}
return imageURL;
}
}
/**
* 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.
* <p>
* You cannot control the size or position of the splash screen.
* The splash screen size is adjusted automatically when the image changes.
* <p>
* The image may contain transparent areas, and thus the reported bounds may
* be larger than the visible splash screen image on the screen.
*
* @return a {@code Rectangle} containing the splash screen bounds
* @throws IllegalStateException if the splash screen has already been closed
*/
public Rectangle getBounds() throws IllegalStateException {
synchronized (SplashScreen.class) {
checkVisible();
float scale = _getScaleFactor(splashPtr);
Rectangle bounds = _getBounds(splashPtr);
assert scale > 0;
if (scale > 0 && scale != 1) {
bounds.setSize((int) (bounds.getWidth() / scale),
(int) (bounds.getHeight() / scale));
}
return bounds;
}
}
/**
* 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.
* <p>
* You cannot control the size or position of the splash screen.
* The splash screen size is adjusted automatically when the image changes.
* <p>
* The image may contain transparent areas, and thus the reported size may
* be larger than the visible splash screen image on the screen.
*
* @return a {@link Dimension} object indicating the splash screen size
* @throws IllegalStateException if the splash screen has already been closed
*/
public Dimension getSize() throws IllegalStateException {
return getBounds().getSize();
}
/**
* 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
* <code>SplashScreen</code> when you want the splash screen to be
* updated immediately.
* <p>
* The pixel (0, 0) in the coordinate space of the graphics context
* corresponds to the origin of the splash screen native window bounds (see
* {@link #getBounds()}).
*
* @return graphics context for the splash screen overlay surface
* @throws IllegalStateException if the splash screen has already been closed
*/
public Graphics2D createGraphics() throws IllegalStateException {
synchronized (SplashScreen.class) {
checkVisible();
if (image==null) {
// get unscaled splash image size
Dimension dim = _getBounds(splashPtr).getSize();
image = new BufferedImage(dim.width, dim.height,
BufferedImage.TYPE_INT_ARGB);
}
float scale = _getScaleFactor(splashPtr);
Graphics2D g = image.createGraphics();
assert (scale > 0);
if (scale <= 0) {
scale = 1;
}
g.scale(scale, scale);
return g;
}
}
/**
* Updates the splash window with current contents of the overlay image.
*
* @throws IllegalStateException if the overlay image does not exist;
* for example, if {@code createGraphics} has never been called,
* or if the splash screen has already been closed
*/
public void update() throws IllegalStateException {
BufferedImage image;
synchronized (SplashScreen.class) {
checkVisible();
image = this.image;
}
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();
// Note that we steal the data array here, but just for reading
// so we do not need to mark the DataBuffer dirty...
int[] data = SunWritableRaster.stealData((DataBufferInt)buf, 0);
synchronized(SplashScreen.class) {
checkVisible();
_update(splashPtr, data, rect.x, rect.y, rect.width, rect.height, scanlineStride);
}
}
/**
* Hides the splash screen, closes the window, and releases all associated
* resources.
*
* @throws IllegalStateException if the splash screen has already been closed
*/
public void close() throws IllegalStateException {
synchronized (SplashScreen.class) {
checkVisible();
_close(splashPtr);
image = null;
SplashScreen.markClosed();
}
}
static void markClosed() {
synchronized (SplashScreen.class) {
wasClosed = true;
theInstance = null;
}
}
/**
* 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.
* <p>
* Note that the native platform may delay presenting the splash screen
* native window on the screen. The return value of {@code true} for this
* method only guarantees that the conditions to hide the splash screen
* window have not occurred yet.
*
* @return true if the splash screen is visible (has not been closed yet),
* false otherwise
*/
public boolean isVisible() {
synchronized (SplashScreen.class) {
return !wasClosed && _isVisible(splashPtr);
}
}
private BufferedImage image; // overlay image
private final long splashPtr; // pointer to native Splash structure
private static boolean wasClosed = false;
private URL imageURL;
/**
* The instance reference for the singleton.
* (<code>null</code> if no instance exists yet.)
*
* @see #getSplashScreen
* @see #close
*/
private static SplashScreen theInstance = null;
private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.SplashScreen");
private native static void _update(long splashPtr, int[] data, int x, int y, int width, int height, int scanlineStride);
private native static boolean _isVisible(long splashPtr);
private native static Rectangle _getBounds(long splashPtr);
private native static long _getInstance();
private native static void _close(long splashPtr);
private native static String _getImageFileName(long splashPtr);
private native static String _getImageJarName(long SplashPtr);
private native static boolean _setImageData(long SplashPtr, byte[] data);
private native static float _getScaleFactor(long SplashPtr);
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/x_bao/Java8Source.git
git@gitee.com:x_bao/Java8Source.git
x_bao
Java8Source
Java8Source
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /