178 * palette. The native system may render the window with smaller 179 * title-bar if the window is either a {@code Frame} or a {@code 180 * Dialog} object, and if it has its decorations enabled. 181 */ 182 UTILITY, 183 184 /** 185 * Represents a <i>popup</i> window. 186 * 187 * A popup window is a temporary window such as a drop-down menu or a 188 * tooltip. On some platforms, windows of that type may be forcibly 189 * made undecorated even if they are instances of the {@code Frame} or 190 * {@code Dialog} class, and have decorations enabled. 191 */ 192 POPUP 193 } 194 195 /** 196 * This represents the warning message that is 197 * to be displayed in a non secure window. ie : 198 * a window that has a security manager installed for 199 * which calling SecurityManager.checkTopLevelWindow() 200 * is false. This message can be displayed anywhere in 201 * the window. 202 * 203 * @serial 204 * @see #getWarningString 205 */ 206 String warningString; 207 208 /** 209 * {@code icons} is the graphical way we can 210 * represent the frames and dialogs. 211 * {@code Window} can't display icon but it's 212 * being inherited by owned {@code Dialog}s. 213 * 214 * @serial 215 * @see #getIconImages 216 * @see #setIconImages(List<? extends Image>) 217 */ 218 transient java.util.List<Image> icons; 219 220 /** 221 * Holds the reference to the component which last had focus in this window 400 } 401 402 String s = java.security.AccessController.doPrivileged( 403 new GetPropertyAction("java.awt.syncLWRequests")); 404 systemSyncLWRequests = (s != null && s.equals("true")); 405 s = java.security.AccessController.doPrivileged( 406 new GetPropertyAction("java.awt.Window.locationByPlatform")); 407 locationByPlatformProp = (s != null && s.equals("true")); 408 } 409 410 /** 411 * Initialize JNI field and method IDs for fields that may be 412 accessed from C. 413 */ 414 private static native void initIDs(); 415 416 /** 417 * Constructs a new, initially invisible window in default size with the 418 * specified {@code GraphicsConfiguration}. 419 * <p> 420 * If there is a security manager, this method first calls 421 * the security manager's {@code checkTopLevelWindow} 422 * method with {@code this} 423 * as its argument to determine whether or not the window 424 * must be displayed with a warning banner. 425 * 426 * @param gc the {@code GraphicsConfiguration} of the target screen 427 * device. If {@code gc} is {@code null}, the system default 428 * {@code GraphicsConfiguration} is assumed 429 * @exception IllegalArgumentException if {@code gc} 430 * is not from a screen device 431 * @exception HeadlessException when 432 * {@code GraphicsEnvironment.isHeadless()} returns {@code true} 433 * 434 * @see java.awt.GraphicsEnvironment#isHeadless 435 * @see java.lang.SecurityManager#checkTopLevelWindow 436 */ 437 Window(GraphicsConfiguration gc) { 438 init(gc); 439 } 440 441 transient Object anchor = new Object(); 442 static class WindowDisposerRecord implements sun.java2d.DisposerRecord { 443 final WeakReference<Window> owner; 444 final WeakReference<Window> weakThis; 445 final WeakReference<AppContext> context; 446 WindowDisposerRecord(AppContext context, Window victim) { 447 owner = new WeakReference<Window>(victim.getOwner()); 448 weakThis = victim.weakThis; 449 this.context = new WeakReference<AppContext>(context); 450 } 451 public void dispose() { 452 Window parent = owner.get(); 453 if (parent != null) { 454 parent.removeOwnedWindow(weakThis); 455 } 494 495 /* offset the initial location with the original of the screen */ 496 /* and any insets */ 497 Rectangle screenBounds = gc.getBounds(); 498 Insets screenInsets = getToolkit().getScreenInsets(gc); 499 int x = getX() + screenBounds.x + screenInsets.left; 500 int y = getY() + screenBounds.y + screenInsets.top; 501 if (x != this.x || y != this.y) { 502 setLocation(x, y); 503 /* reset after setLocation */ 504 setLocationByPlatform(locationByPlatformProp); 505 } 506 507 modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; 508 509 SunToolkit.checkAndSetPolicy(this); 510 } 511 512 /** 513 * Constructs a new, initially invisible window in the default size. 514 * 515 * <p>First, if there is a security manager, its 516 * {@code checkTopLevelWindow} 517 * method is called with {@code this} 518 * as its argument 519 * to see if it's ok to display the window without a warning banner. 520 * If the default implementation of {@code checkTopLevelWindow} 521 * is used (that is, that method is not overriden), then this results in 522 * a call to the security manager's {@code checkPermission} method 523 * with an {@code AWTPermission("showWindowWithoutWarningBanner")} 524 * permission. It that method raises a SecurityException, 525 * {@code checkTopLevelWindow} returns false, otherwise it 526 * returns true. If it returns false, a warning banner is created. 527 * 528 * @exception HeadlessException when 529 * {@code GraphicsEnvironment.isHeadless()} returns {@code true} 530 * 531 * @see java.awt.GraphicsEnvironment#isHeadless 532 * @see java.lang.SecurityManager#checkTopLevelWindow 533 */ 534 Window() throws HeadlessException { 535 GraphicsEnvironment.checkHeadless(); 536 init((GraphicsConfiguration)null); 537 } 538 539 /** 540 * Constructs a new, initially invisible window with the specified 541 * {@code Frame} as its owner. The window will not be focusable 542 * unless its owner is showing on the screen. 543 * <p> 544 * If there is a security manager, this method first calls 545 * the security manager's {@code checkTopLevelWindow} 546 * method with {@code this} 547 * as its argument to determine whether or not the window 548 * must be displayed with a warning banner. 549 * 550 * @param owner the {@code Frame} to act as owner or {@code null} 551 * if this window has no owner 552 * @exception IllegalArgumentException if the {@code owner}'s 553 * {@code GraphicsConfiguration} is not from a screen device 554 * @exception HeadlessException when 555 * {@code GraphicsEnvironment.isHeadless} returns {@code true} 556 * 557 * @see java.awt.GraphicsEnvironment#isHeadless 558 * @see java.lang.SecurityManager#checkTopLevelWindow 559 * @see #isShowing 560 */ 561 public Window(Frame owner) { 562 this(owner == null ? (GraphicsConfiguration)null : 563 owner.getGraphicsConfiguration()); 564 ownedInit(owner); 565 } 566 567 /** 568 * Constructs a new, initially invisible window with the specified 569 * {@code Window} as its owner. This window will not be focusable 570 * unless its nearest owning {@code Frame} or {@code Dialog} 571 * is showing on the screen. 572 * <p> 573 * If there is a security manager, this method first calls 574 * the security manager's {@code checkTopLevelWindow} 575 * method with {@code this} 576 * as its argument to determine whether or not the window 577 * must be displayed with a warning banner. 578 * 579 * @param owner the {@code Window} to act as owner or 580 * {@code null} if this window has no owner 581 * @exception IllegalArgumentException if the {@code owner}'s 582 * {@code GraphicsConfiguration} is not from a screen device 583 * @exception HeadlessException when 584 * {@code GraphicsEnvironment.isHeadless()} returns 585 * {@code true} 586 * 587 * @see java.awt.GraphicsEnvironment#isHeadless 588 * @see java.lang.SecurityManager#checkTopLevelWindow 589 * @see #isShowing 590 * 591 * @since 1.2 592 */ 593 public Window(Window owner) { 594 this(owner == null ? (GraphicsConfiguration)null : 595 owner.getGraphicsConfiguration()); 596 ownedInit(owner); 597 } 598 599 /** 600 * Constructs a new, initially invisible window with the specified owner 601 * {@code Window} and a {@code GraphicsConfiguration} 602 * of a screen device. The Window will not be focusable unless 603 * its nearest owning {@code Frame} or {@code Dialog} 604 * is showing on the screen. 605 * <p> 606 * If there is a security manager, this method first calls 607 * the security manager's {@code checkTopLevelWindow} 608 * method with {@code this} 609 * as its argument to determine whether or not the window 610 * must be displayed with a warning banner. 611 * 612 * @param owner the window to act as owner or {@code null} 613 * if this window has no owner 614 * @param gc the {@code GraphicsConfiguration} of the target 615 * screen device; if {@code gc} is {@code null}, 616 * the system default {@code GraphicsConfiguration} is assumed 617 * @exception IllegalArgumentException if {@code gc} 618 * is not from a screen device 619 * @exception HeadlessException when 620 * {@code GraphicsEnvironment.isHeadless()} returns 621 * {@code true} 622 * 623 * @see java.awt.GraphicsEnvironment#isHeadless 624 * @see java.lang.SecurityManager#checkTopLevelWindow 625 * @see GraphicsConfiguration#getBounds 626 * @see #isShowing 627 * @since 1.3 628 */ 629 public Window(Window owner, GraphicsConfiguration gc) { 630 this(gc); 631 ownedInit(owner); 632 } 633 634 private void ownedInit(Window owner) { 635 this.parent = owner; 636 if (owner != null) { 637 owner.addOwnedWindow(weakThis); 638 } 639 640 // Fix for 6758673: this call is moved here from init(gc), because 641 // WindowDisposerRecord requires a proper value of parent field. 642 Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this)); 643 } 644 1345 peer.toBack(); 1346 } 1347 } 1348 } 1349 1350 /** 1351 * Returns the toolkit of this frame. 1352 * @return the toolkit of this window. 1353 * @see Toolkit 1354 * @see Toolkit#getDefaultToolkit 1355 * @see Component#getToolkit 1356 */ 1357 public Toolkit getToolkit() { 1358 return Toolkit.getDefaultToolkit(); 1359 } 1360 1361 /** 1362 * Gets the warning string that is displayed with this window. 1363 * If this window is insecure, the warning string is displayed 1364 * somewhere in the visible area of the window. A window is 1365 * insecure if there is a security manager, and the security 1366 * manager's {@code checkTopLevelWindow} method returns 1367 * {@code false} when this window is passed to it as an 1368 * argument. 1369 * <p> 1370 * If the window is secure, then {@code getWarningString} 1371 * returns {@code null}. If the window is insecure, this 1372 * method checks for the system property 1373 * {@code awt.appletWarning} 1374 * and returns the string value of that property. 1375 * @return the warning string for this window. 1376 * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) 1377 */ 1378 public final String getWarningString() { 1379 return warningString; 1380 } 1381 1382 private void setWarningString() { 1383 warningString = null; 1384 SecurityManager sm = System.getSecurityManager(); 1385 if (sm != null) { 1386 if (!sm.checkTopLevelWindow(this)) { 1387 // make sure the privileged action is only 1388 // for getting the property! We don't want the 1389 // above checkTopLevelWindow call to always succeed! 1390 warningString = AccessController.doPrivileged( 1391 new GetPropertyAction("awt.appletWarning", 1392 "Java Applet Window")); 1393 } 1394 } 1395 } 1396 1397 /** 1398 * Gets the {@code Locale} object that is associated 1399 * with this window, if the locale has been set. 1400 * If no locale has been set, then the default locale 1401 * is returned. 1402 * @return the locale that is set for this window. 1403 * @see java.util.Locale 1404 * @since JDK1.1 1405 */ 1406 public Locale getLocale() { 1407 if (this.locale == null) { 1408 return Locale.getDefault(); 1409 } | 178 * palette. The native system may render the window with smaller 179 * title-bar if the window is either a {@code Frame} or a {@code 180 * Dialog} object, and if it has its decorations enabled. 181 */ 182 UTILITY, 183 184 /** 185 * Represents a <i>popup</i> window. 186 * 187 * A popup window is a temporary window such as a drop-down menu or a 188 * tooltip. On some platforms, windows of that type may be forcibly 189 * made undecorated even if they are instances of the {@code Frame} or 190 * {@code Dialog} class, and have decorations enabled. 191 */ 192 POPUP 193 } 194 195 /** 196 * This represents the warning message that is 197 * to be displayed in a non secure window. ie : 198 * a window that has a security manager installed that denies 199 * {@code AWTPermission("showWindowWithoutWarningBanner")}. 200 * This message can be displayed anywhere in the window. 201 * 202 * @serial 203 * @see #getWarningString 204 */ 205 String warningString; 206 207 /** 208 * {@code icons} is the graphical way we can 209 * represent the frames and dialogs. 210 * {@code Window} can't display icon but it's 211 * being inherited by owned {@code Dialog}s. 212 * 213 * @serial 214 * @see #getIconImages 215 * @see #setIconImages(List<? extends Image>) 216 */ 217 transient java.util.List<Image> icons; 218 219 /** 220 * Holds the reference to the component which last had focus in this window 399 } 400 401 String s = java.security.AccessController.doPrivileged( 402 new GetPropertyAction("java.awt.syncLWRequests")); 403 systemSyncLWRequests = (s != null && s.equals("true")); 404 s = java.security.AccessController.doPrivileged( 405 new GetPropertyAction("java.awt.Window.locationByPlatform")); 406 locationByPlatformProp = (s != null && s.equals("true")); 407 } 408 409 /** 410 * Initialize JNI field and method IDs for fields that may be 411 accessed from C. 412 */ 413 private static native void initIDs(); 414 415 /** 416 * Constructs a new, initially invisible window in default size with the 417 * specified {@code GraphicsConfiguration}. 418 * <p> 419 * If there is a security manager, then it is invoked to check 420 * {@code AWTPermission("showWindowWithoutWarningBanner")} 421 * to determine whether or not the window must be displayed with 422 * a warning banner. 423 * 424 * @param gc the {@code GraphicsConfiguration} of the target screen 425 * device. If {@code gc} is {@code null}, the system default 426 * {@code GraphicsConfiguration} is assumed 427 * @exception IllegalArgumentException if {@code gc} 428 * is not from a screen device 429 * @exception HeadlessException when 430 * {@code GraphicsEnvironment.isHeadless()} returns {@code true} 431 * 432 * @see java.awt.GraphicsEnvironment#isHeadless 433 */ 434 Window(GraphicsConfiguration gc) { 435 init(gc); 436 } 437 438 transient Object anchor = new Object(); 439 static class WindowDisposerRecord implements sun.java2d.DisposerRecord { 440 final WeakReference<Window> owner; 441 final WeakReference<Window> weakThis; 442 final WeakReference<AppContext> context; 443 WindowDisposerRecord(AppContext context, Window victim) { 444 owner = new WeakReference<Window>(victim.getOwner()); 445 weakThis = victim.weakThis; 446 this.context = new WeakReference<AppContext>(context); 447 } 448 public void dispose() { 449 Window parent = owner.get(); 450 if (parent != null) { 451 parent.removeOwnedWindow(weakThis); 452 } 491 492 /* offset the initial location with the original of the screen */ 493 /* and any insets */ 494 Rectangle screenBounds = gc.getBounds(); 495 Insets screenInsets = getToolkit().getScreenInsets(gc); 496 int x = getX() + screenBounds.x + screenInsets.left; 497 int y = getY() + screenBounds.y + screenInsets.top; 498 if (x != this.x || y != this.y) { 499 setLocation(x, y); 500 /* reset after setLocation */ 501 setLocationByPlatform(locationByPlatformProp); 502 } 503 504 modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; 505 506 SunToolkit.checkAndSetPolicy(this); 507 } 508 509 /** 510 * Constructs a new, initially invisible window in the default size. 511 * <p> 512 * If there is a security manager set, it is invoked to check 513 * {@code AWTPermission("showWindowWithoutWarningBanner")}. 514 * If that check fails with a {@code SecurityException} then a warning 515 * banner is created. 516 * 517 * @exception HeadlessException when 518 * {@code GraphicsEnvironment.isHeadless()} returns {@code true} 519 * 520 * @see java.awt.GraphicsEnvironment#isHeadless 521 */ 522 Window() throws HeadlessException { 523 GraphicsEnvironment.checkHeadless(); 524 init((GraphicsConfiguration)null); 525 } 526 527 /** 528 * Constructs a new, initially invisible window with the specified 529 * {@code Frame} as its owner. The window will not be focusable 530 * unless its owner is showing on the screen. 531 * <p> 532 * If there is a security manager set, it is invoked to check 533 * {@code AWTPermission("showWindowWithoutWarningBanner")}. 534 * If that check fails with a {@code SecurityException} then a warning 535 * banner is created. 536 * 537 * @param owner the {@code Frame} to act as owner or {@code null} 538 * if this window has no owner 539 * @exception IllegalArgumentException if the {@code owner}'s 540 * {@code GraphicsConfiguration} is not from a screen device 541 * @exception HeadlessException when 542 * {@code GraphicsEnvironment.isHeadless} returns {@code true} 543 * 544 * @see java.awt.GraphicsEnvironment#isHeadless 545 * @see #isShowing 546 */ 547 public Window(Frame owner) { 548 this(owner == null ? (GraphicsConfiguration)null : 549 owner.getGraphicsConfiguration()); 550 ownedInit(owner); 551 } 552 553 /** 554 * Constructs a new, initially invisible window with the specified 555 * {@code Window} as its owner. This window will not be focusable 556 * unless its nearest owning {@code Frame} or {@code Dialog} 557 * is showing on the screen. 558 * <p> 559 * If there is a security manager set, it is invoked to check 560 * {@code AWTPermission("showWindowWithoutWarningBanner")}. 561 * If that check fails with a {@code SecurityException} then a 562 * warning banner is created. 563 * 564 * @param owner the {@code Window} to act as owner or 565 * {@code null} if this window has no owner 566 * @exception IllegalArgumentException if the {@code owner}'s 567 * {@code GraphicsConfiguration} is not from a screen device 568 * @exception HeadlessException when 569 * {@code GraphicsEnvironment.isHeadless()} returns 570 * {@code true} 571 * 572 * @see java.awt.GraphicsEnvironment#isHeadless 573 * @see #isShowing 574 * 575 * @since 1.2 576 */ 577 public Window(Window owner) { 578 this(owner == null ? (GraphicsConfiguration)null : 579 owner.getGraphicsConfiguration()); 580 ownedInit(owner); 581 } 582 583 /** 584 * Constructs a new, initially invisible window with the specified owner 585 * {@code Window} and a {@code GraphicsConfiguration} 586 * of a screen device. The Window will not be focusable unless 587 * its nearest owning {@code Frame} or {@code Dialog} 588 * is showing on the screen. 589 * <p> 590 * If there is a security manager set, it is invoked to check 591 * {@code AWTPermission("showWindowWithoutWarningBanner")}. If that 592 * check fails with a {@code SecurityException} then a warning banner 593 * is created. 594 * 595 * @param owner the window to act as owner or {@code null} 596 * if this window has no owner 597 * @param gc the {@code GraphicsConfiguration} of the target 598 * screen device; if {@code gc} is {@code null}, 599 * the system default {@code GraphicsConfiguration} is assumed 600 * @exception IllegalArgumentException if {@code gc} 601 * is not from a screen device 602 * @exception HeadlessException when 603 * {@code GraphicsEnvironment.isHeadless()} returns 604 * {@code true} 605 * 606 * @see java.awt.GraphicsEnvironment#isHeadless 607 * @see GraphicsConfiguration#getBounds 608 * @see #isShowing 609 * @since 1.3 610 */ 611 public Window(Window owner, GraphicsConfiguration gc) { 612 this(gc); 613 ownedInit(owner); 614 } 615 616 private void ownedInit(Window owner) { 617 this.parent = owner; 618 if (owner != null) { 619 owner.addOwnedWindow(weakThis); 620 } 621 622 // Fix for 6758673: this call is moved here from init(gc), because 623 // WindowDisposerRecord requires a proper value of parent field. 624 Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this)); 625 } 626 1327 peer.toBack(); 1328 } 1329 } 1330 } 1331 1332 /** 1333 * Returns the toolkit of this frame. 1334 * @return the toolkit of this window. 1335 * @see Toolkit 1336 * @see Toolkit#getDefaultToolkit 1337 * @see Component#getToolkit 1338 */ 1339 public Toolkit getToolkit() { 1340 return Toolkit.getDefaultToolkit(); 1341 } 1342 1343 /** 1344 * Gets the warning string that is displayed with this window. 1345 * If this window is insecure, the warning string is displayed 1346 * somewhere in the visible area of the window. A window is 1347 * insecure if there is a security manager and the security 1348 * manager denies 1349 * {@code AWTPermission("showWindowWithoutWarningBanner")}. 1350 * <p> 1351 * If the window is secure, then {@code getWarningString} 1352 * returns {@code null}. If the window is insecure, this 1353 * method checks for the system property 1354 * {@code awt.appletWarning} 1355 * and returns the string value of that property. 1356 * @return the warning string for this window. 1357 */ 1358 public final String getWarningString() { 1359 return warningString; 1360 } 1361 1362 private void setWarningString() { 1363 warningString = null; 1364 SecurityManager sm = System.getSecurityManager(); 1365 if (sm != null) { 1366 try { 1367 sm.checkPermission(SecurityConstants.AWT.TOPLEVEL_WINDOW_PERMISSION); 1368 } catch (SecurityException se) { 1369 // make sure the privileged action is only 1370 // for getting the property! We don't want the 1371 // above checkPermission call to always succeed! 1372 warningString = AccessController.doPrivileged( 1373 new GetPropertyAction("awt.appletWarning", 1374 "Java Applet Window")); 1375 } 1376 } 1377 } 1378 1379 /** 1380 * Gets the {@code Locale} object that is associated 1381 * with this window, if the locale has been set. 1382 * If no locale has been set, then the default locale 1383 * is returned. 1384 * @return the locale that is set for this window. 1385 * @see java.util.Locale 1386 * @since JDK1.1 1387 */ 1388 public Locale getLocale() { 1389 if (this.locale == null) { 1390 return Locale.getDefault(); 1391 } |