1 /* 2 * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. 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 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 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 * 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. 24 */ 25 26 package java.awt; 27 28 import java.beans.PropertyChangeEvent; 29 import java.awt.event.*; 30 import java.awt.peer.*; 31 import java.awt.im.InputMethodHighlight; 32 import java.awt.image.ImageObserver; 33 import java.awt.image.ImageProducer; 34 import java.awt.image.ColorModel; 35 import java.awt.datatransfer.Clipboard; 36 import java.awt.dnd.DragSource; 37 import java.awt.dnd.DragGestureRecognizer; 38 import java.awt.dnd.DragGestureEvent; 39 import java.awt.dnd.DragGestureListener; 40 import java.awt.dnd.InvalidDnDOperationException; 41 import java.awt.dnd.peer.DragSourceContextPeer; 42 import java.net.URL; 43 import java.io.File; 44 import java.io.FileInputStream; 45 46 import java.util.*; 47 import java.beans.PropertyChangeListener; 48 import java.beans.PropertyChangeSupport; 49 import sun.awt.AppContext; 50 51 import sun.awt.HeadlessToolkit; 52 import sun.awt.NullComponentPeer; 53 import sun.awt.PeerEvent; 54 import sun.awt.SunToolkit; 55 import sun.awt.AWTAccessor; 56 import sun.awt.AWTPermissions; 57 58 import sun.util.CoreResourceBundleControl; 59 60 /** 61 * This class is the abstract superclass of all actual 62 * implementations of the Abstract Window Toolkit. Subclasses of 63 * the <code>Toolkit</code> class are used to bind the various components 64 * to particular native toolkit implementations. 65 * <p> 66 * Many GUI events may be delivered to user 67 * asynchronously, if the opposite is not specified explicitly. 68 * As well as 69 * many GUI operations may be performed asynchronously. 70 * This fact means that if the state of a component is set, and then 71 * the state immediately queried, the returned value may not yet 72 * reflect the requested change. This behavior includes, but is not 73 * limited to: 74 * <ul> 75 * <li>Scrolling to a specified position. 76 * <br>For example, calling <code>ScrollPane.setScrollPosition</code> 77 * and then <code>getScrollPosition</code> may return an incorrect 78 * value if the original request has not yet been processed. 79 * 80 * <li>Moving the focus from one component to another. 81 * <br>For more information, see 82 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html#transferTiming">Timing 83 * Focus Transfers</a>, a section in 84 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing 85 * Tutorial</a>. 86 * 87 * <li>Making a top-level container visible. 88 * <br>Calling <code>setVisible(true)</code> on a <code>Window</code>, 89 * <code>Frame</code> or <code>Dialog</code> may occur 90 * asynchronously. 91 * 92 * <li>Setting the size or location of a top-level container. 93 * <br>Calls to <code>setSize</code>, <code>setBounds</code> or 94 * <code>setLocation</code> on a <code>Window</code>, 95 * <code>Frame</code> or <code>Dialog</code> are forwarded 96 * to the underlying window management system and may be 97 * ignored or modified. See {@link java.awt.Window} for 98 * more information. 99 * </ul> 100 * <p> 101 * Most applications should not call any of the methods in this 102 * class directly. The methods defined by <code>Toolkit</code> are 103 * the "glue" that joins the platform-independent classes in the 104 * <code>java.awt</code> package with their counterparts in 105 * <code>java.awt.peer</code>. Some methods defined by 106 * <code>Toolkit</code> query the native operating system directly. 107 * 108 * @author Sami Shaio 109 * @author Arthur van Hoff 110 * @author Fred Ecks 111 * @since 1.0 112 */ 113 public abstract class Toolkit { 114 115 /** 116 * Creates this toolkit's implementation of the <code>Desktop</code> 117 * using the specified peer interface. 118 * @param target the desktop to be implemented 119 * @return this toolkit's implementation of the <code>Desktop</code> 120 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 121 * returns true 122 * @see java.awt.GraphicsEnvironment#isHeadless 123 * @see java.awt.Desktop 124 * @see java.awt.peer.DesktopPeer 125 * @since 1.6 126 */ 127 protected abstract DesktopPeer createDesktopPeer(Desktop target) 128 throws HeadlessException; 129 130 131 /** 132 * Creates this toolkit's implementation of <code>Button</code> using 133 * the specified peer interface. 134 * @param target the button to be implemented. 135 * @return this toolkit's implementation of <code>Button</code>. 136 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 137 * returns true 138 * @see java.awt.GraphicsEnvironment#isHeadless 139 * @see java.awt.Button 140 * @see java.awt.peer.ButtonPeer 141 */ 142 protected abstract ButtonPeer createButton(Button target) 143 throws HeadlessException; 144 145 /** 146 * Creates this toolkit's implementation of <code>TextField</code> using 147 * the specified peer interface. 148 * @param target the text field to be implemented. 149 * @return this toolkit's implementation of <code>TextField</code>. 150 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 151 * returns true 152 * @see java.awt.GraphicsEnvironment#isHeadless 153 * @see java.awt.TextField 154 * @see java.awt.peer.TextFieldPeer 155 */ 156 protected abstract TextFieldPeer createTextField(TextField target) 157 throws HeadlessException; 158 159 /** 160 * Creates this toolkit's implementation of <code>Label</code> using 161 * the specified peer interface. 162 * @param target the label to be implemented. 163 * @return this toolkit's implementation of <code>Label</code>. 164 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 165 * returns true 166 * @see java.awt.GraphicsEnvironment#isHeadless 167 * @see java.awt.Label 168 * @see java.awt.peer.LabelPeer 169 */ 170 protected abstract LabelPeer createLabel(Label target) 171 throws HeadlessException; 172 173 /** 174 * Creates this toolkit's implementation of <code>List</code> using 175 * the specified peer interface. 176 * @param target the list to be implemented. 177 * @return this toolkit's implementation of <code>List</code>. 178 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 179 * returns true 180 * @see java.awt.GraphicsEnvironment#isHeadless 181 * @see java.awt.List 182 * @see java.awt.peer.ListPeer 183 */ 184 protected abstract ListPeer createList(java.awt.List target) 185 throws HeadlessException; 186 187 /** 188 * Creates this toolkit's implementation of <code>Checkbox</code> using 189 * the specified peer interface. 190 * @param target the check box to be implemented. 191 * @return this toolkit's implementation of <code>Checkbox</code>. 192 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 193 * returns true 194 * @see java.awt.GraphicsEnvironment#isHeadless 195 * @see java.awt.Checkbox 196 * @see java.awt.peer.CheckboxPeer 197 */ 198 protected abstract CheckboxPeer createCheckbox(Checkbox target) 199 throws HeadlessException; 200 201 /** 202 * Creates this toolkit's implementation of <code>Scrollbar</code> using 203 * the specified peer interface. 204 * @param target the scroll bar to be implemented. 205 * @return this toolkit's implementation of <code>Scrollbar</code>. 206 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 207 * returns true 208 * @see java.awt.GraphicsEnvironment#isHeadless 209 * @see java.awt.Scrollbar 210 * @see java.awt.peer.ScrollbarPeer 211 */ 212 protected abstract ScrollbarPeer createScrollbar(Scrollbar target) 213 throws HeadlessException; 214 215 /** 216 * Creates this toolkit's implementation of <code>ScrollPane</code> using 217 * the specified peer interface. 218 * @param target the scroll pane to be implemented. 219 * @return this toolkit's implementation of <code>ScrollPane</code>. 220 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 221 * returns true 222 * @see java.awt.GraphicsEnvironment#isHeadless 223 * @see java.awt.ScrollPane 224 * @see java.awt.peer.ScrollPanePeer 225 * @since 1.1 226 */ 227 protected abstract ScrollPanePeer createScrollPane(ScrollPane target) 228 throws HeadlessException; 229 230 /** 231 * Creates this toolkit's implementation of <code>TextArea</code> using 232 * the specified peer interface. 233 * @param target the text area to be implemented. 234 * @return this toolkit's implementation of <code>TextArea</code>. 235 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 236 * returns true 237 * @see java.awt.GraphicsEnvironment#isHeadless 238 * @see java.awt.TextArea 239 * @see java.awt.peer.TextAreaPeer 240 */ 241 protected abstract TextAreaPeer createTextArea(TextArea target) 242 throws HeadlessException; 243 244 /** 245 * Creates this toolkit's implementation of <code>Choice</code> using 246 * the specified peer interface. 247 * @param target the choice to be implemented. 248 * @return this toolkit's implementation of <code>Choice</code>. 249 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 250 * returns true 251 * @see java.awt.GraphicsEnvironment#isHeadless 252 * @see java.awt.Choice 253 * @see java.awt.peer.ChoicePeer 254 */ 255 protected abstract ChoicePeer createChoice(Choice target) 256 throws HeadlessException; 257 258 /** 259 * Creates this toolkit's implementation of <code>Frame</code> using 260 * the specified peer interface. 261 * @param target the frame to be implemented. 262 * @return this toolkit's implementation of <code>Frame</code>. 263 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 264 * returns true 265 * @see java.awt.GraphicsEnvironment#isHeadless 266 * @see java.awt.Frame 267 * @see java.awt.peer.FramePeer 268 */ 269 protected abstract FramePeer createFrame(Frame target) 270 throws HeadlessException; 271 272 /** 273 * Creates this toolkit's implementation of <code>Canvas</code> using 274 * the specified peer interface. 275 * @param target the canvas to be implemented. 276 * @return this toolkit's implementation of <code>Canvas</code>. 277 * @see java.awt.Canvas 278 * @see java.awt.peer.CanvasPeer 279 */ 280 protected abstract CanvasPeer createCanvas(Canvas target); 281 282 /** 283 * Creates this toolkit's implementation of <code>Panel</code> using 284 * the specified peer interface. 285 * @param target the panel to be implemented. 286 * @return this toolkit's implementation of <code>Panel</code>. 287 * @see java.awt.Panel 288 * @see java.awt.peer.PanelPeer 289 */ 290 protected abstract PanelPeer createPanel(Panel target); 291 292 /** 293 * Creates this toolkit's implementation of <code>Window</code> using 294 * the specified peer interface. 295 * @param target the window to be implemented. 296 * @return this toolkit's implementation of <code>Window</code>. 297 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 298 * returns true 299 * @see java.awt.GraphicsEnvironment#isHeadless 300 * @see java.awt.Window 301 * @see java.awt.peer.WindowPeer 302 */ 303 protected abstract WindowPeer createWindow(Window target) 304 throws HeadlessException; 305 306 /** 307 * Creates this toolkit's implementation of <code>Dialog</code> using 308 * the specified peer interface. 309 * @param target the dialog to be implemented. 310 * @return this toolkit's implementation of <code>Dialog</code>. 311 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 312 * returns true 313 * @see java.awt.GraphicsEnvironment#isHeadless 314 * @see java.awt.Dialog 315 * @see java.awt.peer.DialogPeer 316 */ 317 protected abstract DialogPeer createDialog(Dialog target) 318 throws HeadlessException; 319 320 /** 321 * Creates this toolkit's implementation of <code>MenuBar</code> using 322 * the specified peer interface. 323 * @param target the menu bar to be implemented. 324 * @return this toolkit's implementation of <code>MenuBar</code>. 325 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 326 * returns true 327 * @see java.awt.GraphicsEnvironment#isHeadless 328 * @see java.awt.MenuBar 329 * @see java.awt.peer.MenuBarPeer 330 */ 331 protected abstract MenuBarPeer createMenuBar(MenuBar target) 332 throws HeadlessException; 333 334 /** 335 * Creates this toolkit's implementation of <code>Menu</code> using 336 * the specified peer interface. 337 * @param target the menu to be implemented. 338 * @return this toolkit's implementation of <code>Menu</code>. 339 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 340 * returns true 341 * @see java.awt.GraphicsEnvironment#isHeadless 342 * @see java.awt.Menu 343 * @see java.awt.peer.MenuPeer 344 */ 345 protected abstract MenuPeer createMenu(Menu target) 346 throws HeadlessException; 347 348 /** 349 * Creates this toolkit's implementation of <code>PopupMenu</code> using 350 * the specified peer interface. 351 * @param target the popup menu to be implemented. 352 * @return this toolkit's implementation of <code>PopupMenu</code>. 353 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 354 * returns true 355 * @see java.awt.GraphicsEnvironment#isHeadless 356 * @see java.awt.PopupMenu 357 * @see java.awt.peer.PopupMenuPeer 358 * @since 1.1 359 */ 360 protected abstract PopupMenuPeer createPopupMenu(PopupMenu target) 361 throws HeadlessException; 362 363 /** 364 * Creates this toolkit's implementation of <code>MenuItem</code> using 365 * the specified peer interface. 366 * @param target the menu item to be implemented. 367 * @return this toolkit's implementation of <code>MenuItem</code>. 368 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 369 * returns true 370 * @see java.awt.GraphicsEnvironment#isHeadless 371 * @see java.awt.MenuItem 372 * @see java.awt.peer.MenuItemPeer 373 */ 374 protected abstract MenuItemPeer createMenuItem(MenuItem target) 375 throws HeadlessException; 376 377 /** 378 * Creates this toolkit's implementation of <code>FileDialog</code> using 379 * the specified peer interface. 380 * @param target the file dialog to be implemented. 381 * @return this toolkit's implementation of <code>FileDialog</code>. 382 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 383 * returns true 384 * @see java.awt.GraphicsEnvironment#isHeadless 385 * @see java.awt.FileDialog 386 * @see java.awt.peer.FileDialogPeer 387 */ 388 protected abstract FileDialogPeer createFileDialog(FileDialog target) 389 throws HeadlessException; 390 391 /** 392 * Creates this toolkit's implementation of <code>CheckboxMenuItem</code> using 393 * the specified peer interface. 394 * @param target the checkbox menu item to be implemented. 395 * @return this toolkit's implementation of <code>CheckboxMenuItem</code>. 396 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 397 * returns true 398 * @see java.awt.GraphicsEnvironment#isHeadless 399 * @see java.awt.CheckboxMenuItem 400 * @see java.awt.peer.CheckboxMenuItemPeer 401 */ 402 protected abstract CheckboxMenuItemPeer createCheckboxMenuItem( 403 CheckboxMenuItem target) throws HeadlessException; 404 405 /** 406 * Obtains this toolkit's implementation of helper class for 407 * <code>MouseInfo</code> operations. 408 * @return this toolkit's implementation of helper for <code>MouseInfo</code> 409 * @throws UnsupportedOperationException if this operation is not implemented 410 * @see java.awt.peer.MouseInfoPeer 411 * @see java.awt.MouseInfo 412 * @since 1.5 413 */ 414 protected MouseInfoPeer getMouseInfoPeer() { 415 throw new UnsupportedOperationException("Not implemented"); 416 } 417 418 private static LightweightPeer lightweightMarker; 419 420 /** 421 * Creates a peer for a component or container. This peer is windowless 422 * and allows the Component and Container classes to be extended directly 423 * to create windowless components that are defined entirely in java. 424 * 425 * @param target The Component to be created. 426 * @return the peer for the specified component 427 */ 428 protected LightweightPeer createComponent(Component target) { 429 if (lightweightMarker == null) { 430 lightweightMarker = new NullComponentPeer(); 431 } 432 return lightweightMarker; 433 } 434 435 /** 436 * Creates this toolkit's implementation of <code>Font</code> using 437 * the specified peer interface. 438 * @param name the font to be implemented 439 * @param style the style of the font, such as <code>PLAIN</code>, 440 * <code>BOLD</code>, <code>ITALIC</code>, or a combination 441 * @return this toolkit's implementation of <code>Font</code> 442 * @see java.awt.Font 443 * @see java.awt.peer.FontPeer 444 * @see java.awt.GraphicsEnvironment#getAllFonts 445 * @deprecated see java.awt.GraphicsEnvironment#getAllFonts 446 */ 447 @Deprecated 448 protected abstract FontPeer getFontPeer(String name, int style); 449 450 // The following method is called by the private method 451 // <code>updateSystemColors</code> in <code>SystemColor</code>. 452 453 /** 454 * Fills in the integer array that is supplied as an argument 455 * with the current system color values. 456 * 457 * @param systemColors an integer array. 458 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 459 * returns true 460 * @see java.awt.GraphicsEnvironment#isHeadless 461 * @since 1.1 462 */ 463 protected void loadSystemColors(int[] systemColors) 464 throws HeadlessException { 465 GraphicsEnvironment.checkHeadless(); 466 } 467 468 /** 469 * Controls whether the layout of Containers is validated dynamically 470 * during resizing, or statically, after resizing is complete. 471 * Use {@code isDynamicLayoutActive()} to detect if this feature enabled 472 * in this program and is supported by this operating system 473 * and/or window manager. 474 * Note that this feature is supported not on all platforms, and 475 * conversely, that this feature cannot be turned off on some platforms. 476 * On these platforms where dynamic layout during resizing is not supported 477 * (or is always supported), setting this property has no effect. 478 * Note that this feature can be set or unset as a property of the 479 * operating system or window manager on some platforms. On such 480 * platforms, the dynamic resize property must be set at the operating 481 * system or window manager level before this method can take effect. 482 * This method does not change support or settings of the underlying 483 * operating system or 484 * window manager. The OS/WM support can be 485 * queried using getDesktopProperty("awt.dynamicLayoutSupported") method. 486 * 487 * @param dynamic If true, Containers should re-layout their 488 * components as the Container is being resized. If false, 489 * the layout will be validated after resizing is completed. 490 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 491 * returns true 492 * @see #isDynamicLayoutSet() 493 * @see #isDynamicLayoutActive() 494 * @see #getDesktopProperty(String propertyName) 495 * @see java.awt.GraphicsEnvironment#isHeadless 496 * @since 1.4 497 */ 498 public void setDynamicLayout(final boolean dynamic) 499 throws HeadlessException { 500 GraphicsEnvironment.checkHeadless(); 501 if (this != getDefaultToolkit()) { 502 getDefaultToolkit().setDynamicLayout(dynamic); 503 } 504 } 505 506 /** 507 * Returns whether the layout of Containers is validated dynamically 508 * during resizing, or statically, after resizing is complete. 509 * Note: this method returns the value that was set programmatically; 510 * it does not reflect support at the level of the operating system 511 * or window manager for dynamic layout on resizing, or the current 512 * operating system or window manager settings. The OS/WM support can 513 * be queried using getDesktopProperty("awt.dynamicLayoutSupported"). 514 * 515 * @return true if validation of Containers is done dynamically, 516 * false if validation is done after resizing is finished. 517 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 518 * returns true 519 * @see #setDynamicLayout(boolean dynamic) 520 * @see #isDynamicLayoutActive() 521 * @see #getDesktopProperty(String propertyName) 522 * @see java.awt.GraphicsEnvironment#isHeadless 523 * @since 1.4 524 */ 525 protected boolean isDynamicLayoutSet() 526 throws HeadlessException { 527 GraphicsEnvironment.checkHeadless(); 528 529 if (this != Toolkit.getDefaultToolkit()) { 530 return Toolkit.getDefaultToolkit().isDynamicLayoutSet(); 531 } else { 532 return false; 533 } 534 } 535 536 /** 537 * Returns whether dynamic layout of Containers on resize is 538 * currently active (both set in program 539 *( {@code isDynamicLayoutSet()} ) 540 *, and supported 541 * by the underlying operating system and/or window manager). 542 * If dynamic layout is currently inactive then Containers 543 * re-layout their components when resizing is completed. As a result 544 * the {@code Component.validate()} method will be invoked only 545 * once per resize. 546 * If dynamic layout is currently active then Containers 547 * re-layout their components on every native resize event and 548 * the {@code validate()} method will be invoked each time. 549 * The OS/WM support can be queried using 550 * the getDesktopProperty("awt.dynamicLayoutSupported") method. 551 * 552 * @return true if dynamic layout of Containers on resize is 553 * currently active, false otherwise. 554 * @exception HeadlessException if the GraphicsEnvironment.isHeadless() 555 * method returns true 556 * @see #setDynamicLayout(boolean dynamic) 557 * @see #isDynamicLayoutSet() 558 * @see #getDesktopProperty(String propertyName) 559 * @see java.awt.GraphicsEnvironment#isHeadless 560 * @since 1.4 561 */ 562 public boolean isDynamicLayoutActive() 563 throws HeadlessException { 564 GraphicsEnvironment.checkHeadless(); 565 566 if (this != Toolkit.getDefaultToolkit()) { 567 return Toolkit.getDefaultToolkit().isDynamicLayoutActive(); 568 } else { 569 return false; 570 } 571 } 572 573 /** 574 * Gets the size of the screen. On systems with multiple displays, the 575 * primary display is used. Multi-screen aware display dimensions are 576 * available from <code>GraphicsConfiguration</code> and 577 * <code>GraphicsDevice</code>. 578 * @return the size of this toolkit's screen, in pixels. 579 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 580 * returns true 581 * @see java.awt.GraphicsConfiguration#getBounds 582 * @see java.awt.GraphicsDevice#getDisplayMode 583 * @see java.awt.GraphicsEnvironment#isHeadless 584 */ 585 public abstract Dimension getScreenSize() 586 throws HeadlessException; 587 588 /** 589 * Returns the screen resolution in dots-per-inch. 590 * @return this toolkit's screen resolution, in dots-per-inch. 591 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 592 * returns true 593 * @see java.awt.GraphicsEnvironment#isHeadless 594 */ 595 public abstract int getScreenResolution() 596 throws HeadlessException; 597 598 /** 599 * Gets the insets of the screen. 600 * @param gc a <code>GraphicsConfiguration</code> 601 * @return the insets of this toolkit's screen, in pixels. 602 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 603 * returns true 604 * @see java.awt.GraphicsEnvironment#isHeadless 605 * @since 1.4 606 */ 607 public Insets getScreenInsets(GraphicsConfiguration gc) 608 throws HeadlessException { 609 GraphicsEnvironment.checkHeadless(); 610 if (this != Toolkit.getDefaultToolkit()) { 611 return Toolkit.getDefaultToolkit().getScreenInsets(gc); 612 } else { 613 return new Insets(0, 0, 0, 0); 614 } 615 } 616 617 /** 618 * Determines the color model of this toolkit's screen. 619 * <p> 620 * <code>ColorModel</code> is an abstract class that 621 * encapsulates the ability to translate between the 622 * pixel values of an image and its red, green, blue, 623 * and alpha components. 624 * <p> 625 * This toolkit method is called by the 626 * <code>getColorModel</code> method 627 * of the <code>Component</code> class. 628 * @return the color model of this toolkit's screen. 629 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 630 * returns true 631 * @see java.awt.GraphicsEnvironment#isHeadless 632 * @see java.awt.image.ColorModel 633 * @see java.awt.Component#getColorModel 634 */ 635 public abstract ColorModel getColorModel() 636 throws HeadlessException; 637 638 /** 639 * Returns the names of the available fonts in this toolkit.<p> 640 * For 1.1, the following font names are deprecated (the replacement 641 * name follows): 642 * <ul> 643 * <li>TimesRoman (use Serif) 644 * <li>Helvetica (use SansSerif) 645 * <li>Courier (use Monospaced) 646 * </ul><p> 647 * The ZapfDingbats fontname is also deprecated in 1.1 but the characters 648 * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports 649 * those characters. 650 * @return the names of the available fonts in this toolkit. 651 * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()} 652 * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames() 653 */ 654 @Deprecated 655 public abstract String[] getFontList(); 656 657 /** 658 * Gets the screen device metrics for rendering of the font. 659 * @param font a font 660 * @return the screen metrics of the specified font in this toolkit 661 * @deprecated As of JDK version 1.2, replaced by the <code>Font</code> 662 * method <code>getLineMetrics</code>. 663 * @see java.awt.font.LineMetrics 664 * @see java.awt.Font#getLineMetrics 665 * @see java.awt.GraphicsEnvironment#getScreenDevices 666 */ 667 @Deprecated 668 public abstract FontMetrics getFontMetrics(Font font); 669 670 /** 671 * Synchronizes this toolkit's graphics state. Some window systems 672 * may do buffering of graphics events. 673 * <p> 674 * This method ensures that the display is up-to-date. It is useful 675 * for animation. 676 */ 677 public abstract void sync(); 678 679 /** 680 * The default toolkit. 681 */ 682 private static Toolkit toolkit; 683 684 /** 685 * Used internally by the assistive technologies functions; set at 686 * init time and used at load time 687 */ 688 private static String atNames; 689 690 /** 691 * Initializes properties related to assistive technologies. 692 * These properties are used both in the loadAssistiveProperties() 693 * function below, as well as other classes in the jdk that depend 694 * on the properties (such as the use of the screen_magnifier_present 695 * property in Java2D hardware acceleration initialization). The 696 * initialization of the properties must be done before the platform- 697 * specific Toolkit class is instantiated so that all necessary 698 * properties are set up properly before any classes dependent upon them 699 * are initialized. 700 */ 701 private static void initAssistiveTechnologies() { 702 703 // Get accessibility properties 704 final String sep = File.separator; 705 final Properties properties = new Properties(); 706 707 708 atNames = java.security.AccessController.doPrivileged( 709 new java.security.PrivilegedAction<String>() { 710 public String run() { 711 712 // Try loading the per-user accessibility properties file. 713 try { 714 File propsFile = new File( 715 System.getProperty("user.home") + 716 sep + ".accessibility.properties"); 717 FileInputStream in = 718 new FileInputStream(propsFile); 719 720 // Inputstream has been buffered in Properties class 721 properties.load(in); 722 in.close(); 723 } catch (Exception e) { 724 // Per-user accessibility properties file does not exist 725 } 726 727 // Try loading the system-wide accessibility properties 728 // file only if a per-user accessibility properties 729 // file does not exist or is empty. 730 if (properties.size() == 0) { 731 try { 732 File propsFile = new File( 733 System.getProperty("java.home") + sep + "conf" + 734 sep + "accessibility.properties"); 735 FileInputStream in = 736 new FileInputStream(propsFile); 737 738 // Inputstream has been buffered in Properties class 739 properties.load(in); 740 in.close(); 741 } catch (Exception e) { 742 // System-wide accessibility properties file does 743 // not exist; 744 } 745 } 746 747 // Get whether a screen magnifier is present. First check 748 // the system property and then check the properties file. 749 String magPresent = System.getProperty("javax.accessibility.screen_magnifier_present"); 750 if (magPresent == null) { 751 magPresent = properties.getProperty("screen_magnifier_present", null); 752 if (magPresent != null) { 753 System.setProperty("javax.accessibility.screen_magnifier_present", magPresent); 754 } 755 } 756 757 // Get the names of any assistive technolgies to load. First 758 // check the system property and then check the properties 759 // file. 760 String classNames = System.getProperty("javax.accessibility.assistive_technologies"); 761 if (classNames == null) { 762 classNames = properties.getProperty("assistive_technologies", null); 763 if (classNames != null) { 764 System.setProperty("javax.accessibility.assistive_technologies", classNames); 765 } 766 } 767 return classNames; 768 } 769 }); 770 } 771 772 /** 773 * Loads additional classes into the VM, using the property 774 * 'assistive_technologies' specified in the Sun reference 775 * implementation by a line in the 'accessibility.properties' 776 * file. The form is "assistive_technologies=..." where 777 * the "..." is a comma-separated list of assistive technology 778 * classes to load. Each class is loaded in the order given 779 * and a single instance of each is created using 780 * Class.forName(class).newInstance(). All errors are handled 781 * via an AWTError exception. 782 * 783 * <p>The assumption is made that assistive technology classes are supplied 784 * as part of INSTALLED (as opposed to: BUNDLED) extensions or specified 785 * on the class path 786 * (and therefore can be loaded using the class loader returned by 787 * a call to <code>ClassLoader.getSystemClassLoader</code>, whose 788 * delegation parent is the extension class loader for installed 789 * extensions). 790 */ 791 private static void loadAssistiveTechnologies() { 792 // Load any assistive technologies 793 if (atNames != null) { 794 ClassLoader cl = ClassLoader.getSystemClassLoader(); 795 StringTokenizer parser = new StringTokenizer(atNames," ,"); 796 String atName; 797 while (parser.hasMoreTokens()) { 798 atName = parser.nextToken(); 799 try { 800 Class<?> clazz; 801 if (cl != null) { 802 clazz = cl.loadClass(atName); 803 } else { 804 clazz = Class.forName(atName); 805 } 806 clazz.newInstance(); 807 } catch (ClassNotFoundException e) { 808 throw new AWTError("Assistive Technology not found: " 809 + atName); 810 } catch (InstantiationException e) { 811 throw new AWTError("Could not instantiate Assistive" 812 + " Technology: " + atName); 813 } catch (IllegalAccessException e) { 814 throw new AWTError("Could not access Assistive" 815 + " Technology: " + atName); 816 } catch (Exception e) { 817 throw new AWTError("Error trying to install Assistive" 818 + " Technology: " + atName + " " + e); 819 } 820 } 821 } 822 } 823 824 /** 825 * Gets the default toolkit. 826 * <p> 827 * If a system property named <code>"java.awt.headless"</code> is set 828 * to <code>true</code> then the headless implementation 829 * of <code>Toolkit</code> is used. 830 * <p> 831 * If there is no <code>"java.awt.headless"</code> or it is set to 832 * <code>false</code> and there is a system property named 833 * <code>"awt.toolkit"</code>, 834 * that property is treated as the name of a class that is a subclass 835 * of <code>Toolkit</code>; 836 * otherwise the default platform-specific implementation of 837 * <code>Toolkit</code> is used. 838 * <p> 839 * Also loads additional classes into the VM, using the property 840 * 'assistive_technologies' specified in the Sun reference 841 * implementation by a line in the 'accessibility.properties' 842 * file. The form is "assistive_technologies=..." where 843 * the "..." is a comma-separated list of assistive technology 844 * classes to load. Each class is loaded in the order given 845 * and a single instance of each is created using 846 * Class.forName(class).newInstance(). This is done just after 847 * the AWT toolkit is created. All errors are handled via an 848 * AWTError exception. 849 * @return the default toolkit. 850 * @exception AWTError if a toolkit could not be found, or 851 * if one could not be accessed or instantiated. 852 */ 853 public static synchronized Toolkit getDefaultToolkit() { 854 if (toolkit == null) { 855 java.security.AccessController.doPrivileged( 856 new java.security.PrivilegedAction<Void>() { 857 public Void run() { 858 Class<?> cls = null; 859 String nm = System.getProperty("awt.toolkit"); 860 try { 861 cls = Class.forName(nm); 862 } catch (ClassNotFoundException e) { 863 ClassLoader cl = ClassLoader.getSystemClassLoader(); 864 if (cl != null) { 865 try { 866 cls = cl.loadClass(nm); 867 } catch (final ClassNotFoundException ignored) { 868 throw new AWTError("Toolkit not found: " + nm); 869 } 870 } 871 } 872 try { 873 if (cls != null) { 874 toolkit = (Toolkit)cls.newInstance(); 875 if (GraphicsEnvironment.isHeadless()) { 876 toolkit = new HeadlessToolkit(toolkit); 877 } 878 } 879 } catch (final InstantiationException ignored) { 880 throw new AWTError("Could not instantiate Toolkit: " + nm); 881 } catch (final IllegalAccessException ignored) { 882 throw new AWTError("Could not access Toolkit: " + nm); 883 } 884 return null; 885 } 886 }); 887 loadAssistiveTechnologies(); 888 } 889 return toolkit; 890 } 891 892 /** 893 * Returns an image which gets pixel data from the specified file, 894 * whose format can be either GIF, JPEG or PNG. 895 * The underlying toolkit attempts to resolve multiple requests 896 * with the same filename to the same returned Image. 897 * <p> 898 * Since the mechanism required to facilitate this sharing of 899 * <code>Image</code> objects may continue to hold onto images 900 * that are no longer in use for an indefinite period of time, 901 * developers are encouraged to implement their own caching of 902 * images by using the {@link #createImage(java.lang.String) createImage} 903 * variant wherever available. 904 * If the image data contained in the specified file changes, 905 * the <code>Image</code> object returned from this method may 906 * still contain stale information which was loaded from the 907 * file after a prior call. 908 * Previously loaded image data can be manually discarded by 909 * calling the {@link Image#flush flush} method on the 910 * returned <code>Image</code>. 911 * <p> 912 * This method first checks if there is a security manager installed. 913 * If so, the method calls the security manager's 914 * <code>checkRead</code> method with the file specified to ensure 915 * that the access to the image is allowed. 916 * @param filename the name of a file containing pixel data 917 * in a recognized file format. 918 * @return an image which gets its pixel data from 919 * the specified file. 920 * @throws SecurityException if a security manager exists and its 921 * checkRead method doesn't allow the operation. 922 * @see #createImage(java.lang.String) 923 */ 924 public abstract Image getImage(String filename); 925 926 /** 927 * Returns an image which gets pixel data from the specified URL. 928 * The pixel data referenced by the specified URL must be in one 929 * of the following formats: GIF, JPEG or PNG. 930 * The underlying toolkit attempts to resolve multiple requests 931 * with the same URL to the same returned Image. 932 * <p> 933 * Since the mechanism required to facilitate this sharing of 934 * <code>Image</code> objects may continue to hold onto images 935 * that are no longer in use for an indefinite period of time, 936 * developers are encouraged to implement their own caching of 937 * images by using the {@link #createImage(java.net.URL) createImage} 938 * variant wherever available. 939 * If the image data stored at the specified URL changes, 940 * the <code>Image</code> object returned from this method may 941 * still contain stale information which was fetched from the 942 * URL after a prior call. 943 * Previously loaded image data can be manually discarded by 944 * calling the {@link Image#flush flush} method on the 945 * returned <code>Image</code>. 946 * <p> 947 * This method first checks if there is a security manager installed. 948 * If so, the method calls the security manager's 949 * <code>checkPermission</code> method with the 950 * url.openConnection().getPermission() permission to ensure 951 * that the access to the image is allowed. For compatibility 952 * with pre-1.2 security managers, if the access is denied with 953 * <code>FilePermission</code> or <code>SocketPermission</code>, 954 * the method throws the <code>SecurityException</code> 955 * if the corresponding 1.1-style SecurityManager.checkXXX method 956 * also denies permission. 957 * @param url the URL to use in fetching the pixel data. 958 * @return an image which gets its pixel data from 959 * the specified URL. 960 * @throws SecurityException if a security manager exists and its 961 * checkPermission method doesn't allow 962 * the operation. 963 * @see #createImage(java.net.URL) 964 */ 965 public abstract Image getImage(URL url); 966 967 /** 968 * Returns an image which gets pixel data from the specified file. 969 * The returned Image is a new object which will not be shared 970 * with any other caller of this method or its getImage variant. 971 * <p> 972 * This method first checks if there is a security manager installed. 973 * If so, the method calls the security manager's 974 * <code>checkRead</code> method with the specified file to ensure 975 * that the image creation is allowed. 976 * @param filename the name of a file containing pixel data 977 * in a recognized file format. 978 * @return an image which gets its pixel data from 979 * the specified file. 980 * @throws SecurityException if a security manager exists and its 981 * checkRead method doesn't allow the operation. 982 * @see #getImage(java.lang.String) 983 */ 984 public abstract Image createImage(String filename); 985 986 /** 987 * Returns an image which gets pixel data from the specified URL. 988 * The returned Image is a new object which will not be shared 989 * with any other caller of this method or its getImage variant. 990 * <p> 991 * This method first checks if there is a security manager installed. 992 * If so, the method calls the security manager's 993 * <code>checkPermission</code> method with the 994 * url.openConnection().getPermission() permission to ensure 995 * that the image creation is allowed. For compatibility 996 * with pre-1.2 security managers, if the access is denied with 997 * <code>FilePermission</code> or <code>SocketPermission</code>, 998 * the method throws <code>SecurityException</code> 999 * if the corresponding 1.1-style SecurityManager.checkXXX method 1000 * also denies permission. 1001 * @param url the URL to use in fetching the pixel data. 1002 * @return an image which gets its pixel data from 1003 * the specified URL. 1004 * @throws SecurityException if a security manager exists and its 1005 * checkPermission method doesn't allow 1006 * the operation. 1007 * @see #getImage(java.net.URL) 1008 */ 1009 public abstract Image createImage(URL url); 1010 1011 /** 1012 * Prepares an image for rendering. 1013 * <p> 1014 * If the values of the width and height arguments are both 1015 * <code>-1</code>, this method prepares the image for rendering 1016 * on the default screen; otherwise, this method prepares an image 1017 * for rendering on the default screen at the specified width and height. 1018 * <p> 1019 * The image data is downloaded asynchronously in another thread, 1020 * and an appropriately scaled screen representation of the image is 1021 * generated. 1022 * <p> 1023 * This method is called by components <code>prepareImage</code> 1024 * methods. 1025 * <p> 1026 * Information on the flags returned by this method can be found 1027 * with the definition of the <code>ImageObserver</code> interface. 1028 1029 * @param image the image for which to prepare a 1030 * screen representation. 1031 * @param width the width of the desired screen 1032 * representation, or <code>-1</code>. 1033 * @param height the height of the desired screen 1034 * representation, or <code>-1</code>. 1035 * @param observer the <code>ImageObserver</code> 1036 * object to be notified as the 1037 * image is being prepared. 1038 * @return <code>true</code> if the image has already been 1039 * fully prepared; <code>false</code> otherwise. 1040 * @see java.awt.Component#prepareImage(java.awt.Image, 1041 * java.awt.image.ImageObserver) 1042 * @see java.awt.Component#prepareImage(java.awt.Image, 1043 * int, int, java.awt.image.ImageObserver) 1044 * @see java.awt.image.ImageObserver 1045 */ 1046 public abstract boolean prepareImage(Image image, int width, int height, 1047 ImageObserver observer); 1048 1049 /** 1050 * Indicates the construction status of a specified image that is 1051 * being prepared for display. 1052 * <p> 1053 * If the values of the width and height arguments are both 1054 * <code>-1</code>, this method returns the construction status of 1055 * a screen representation of the specified image in this toolkit. 1056 * Otherwise, this method returns the construction status of a 1057 * scaled representation of the image at the specified width 1058 * and height. 1059 * <p> 1060 * This method does not cause the image to begin loading. 1061 * An application must call <code>prepareImage</code> to force 1062 * the loading of an image. 1063 * <p> 1064 * This method is called by the component's <code>checkImage</code> 1065 * methods. 1066 * <p> 1067 * Information on the flags returned by this method can be found 1068 * with the definition of the <code>ImageObserver</code> interface. 1069 * @param image the image whose status is being checked. 1070 * @param width the width of the scaled version whose status is 1071 * being checked, or <code>-1</code>. 1072 * @param height the height of the scaled version whose status 1073 * is being checked, or <code>-1</code>. 1074 * @param observer the <code>ImageObserver</code> object to be 1075 * notified as the image is being prepared. 1076 * @return the bitwise inclusive <strong>OR</strong> of the 1077 * <code>ImageObserver</code> flags for the 1078 * image data that is currently available. 1079 * @see java.awt.Toolkit#prepareImage(java.awt.Image, 1080 * int, int, java.awt.image.ImageObserver) 1081 * @see java.awt.Component#checkImage(java.awt.Image, 1082 * java.awt.image.ImageObserver) 1083 * @see java.awt.Component#checkImage(java.awt.Image, 1084 * int, int, java.awt.image.ImageObserver) 1085 * @see java.awt.image.ImageObserver 1086 */ 1087 public abstract int checkImage(Image image, int width, int height, 1088 ImageObserver observer); 1089 1090 /** 1091 * Creates an image with the specified image producer. 1092 * @param producer the image producer to be used. 1093 * @return an image with the specified image producer. 1094 * @see java.awt.Image 1095 * @see java.awt.image.ImageProducer 1096 * @see java.awt.Component#createImage(java.awt.image.ImageProducer) 1097 */ 1098 public abstract Image createImage(ImageProducer producer); 1099 1100 /** 1101 * Creates an image which decodes the image stored in the specified 1102 * byte array. 1103 * <p> 1104 * The data must be in some image format, such as GIF or JPEG, 1105 * that is supported by this toolkit. 1106 * @param imagedata an array of bytes, representing 1107 * image data in a supported image format. 1108 * @return an image. 1109 * @since 1.1 1110 */ 1111 public Image createImage(byte[] imagedata) { 1112 return createImage(imagedata, 0, imagedata.length); 1113 } 1114 1115 /** 1116 * Creates an image which decodes the image stored in the specified 1117 * byte array, and at the specified offset and length. 1118 * The data must be in some image format, such as GIF or JPEG, 1119 * that is supported by this toolkit. 1120 * @param imagedata an array of bytes, representing 1121 * image data in a supported image format. 1122 * @param imageoffset the offset of the beginning 1123 * of the data in the array. 1124 * @param imagelength the length of the data in the array. 1125 * @return an image. 1126 * @since 1.1 1127 */ 1128 public abstract Image createImage(byte[] imagedata, 1129 int imageoffset, 1130 int imagelength); 1131 1132 /** 1133 * Gets a <code>PrintJob</code> object which is the result of initiating 1134 * a print operation on the toolkit's platform. 1135 * <p> 1136 * Each actual implementation of this method should first check if there 1137 * is a security manager installed. If there is, the method should call 1138 * the security manager's <code>checkPrintJobAccess</code> method to 1139 * ensure initiation of a print operation is allowed. If the default 1140 * implementation of <code>checkPrintJobAccess</code> is used (that is, 1141 * that method is not overriden), then this results in a call to the 1142 * security manager's <code>checkPermission</code> method with a <code> 1143 * RuntimePermission("queuePrintJob")</code> permission. 1144 * 1145 * @param frame the parent of the print dialog. May not be null. 1146 * @param jobtitle the title of the PrintJob. A null title is equivalent 1147 * to "". 1148 * @param props a Properties object containing zero or more properties. 1149 * Properties are not standardized and are not consistent across 1150 * implementations. Because of this, PrintJobs which require job 1151 * and page control should use the version of this function which 1152 * takes JobAttributes and PageAttributes objects. This object 1153 * may be updated to reflect the user's job choices on exit. May 1154 * be null. 1155 * @return a <code>PrintJob</code> object, or <code>null</code> if the 1156 * user cancelled the print job. 1157 * @throws NullPointerException if frame is null 1158 * @throws SecurityException if this thread is not allowed to initiate a 1159 * print job request 1160 * @see java.awt.GraphicsEnvironment#isHeadless 1161 * @see java.awt.PrintJob 1162 * @see java.lang.RuntimePermission 1163 * @since 1.1 1164 */ 1165 public abstract PrintJob getPrintJob(Frame frame, String jobtitle, 1166 Properties props); 1167 1168 /** 1169 * Gets a <code>PrintJob</code> object which is the result of initiating 1170 * a print operation on the toolkit's platform. 1171 * <p> 1172 * Each actual implementation of this method should first check if there 1173 * is a security manager installed. If there is, the method should call 1174 * the security manager's <code>checkPrintJobAccess</code> method to 1175 * ensure initiation of a print operation is allowed. If the default 1176 * implementation of <code>checkPrintJobAccess</code> is used (that is, 1177 * that method is not overriden), then this results in a call to the 1178 * security manager's <code>checkPermission</code> method with a <code> 1179 * RuntimePermission("queuePrintJob")</code> permission. 1180 * 1181 * @param frame the parent of the print dialog. May not be null. 1182 * @param jobtitle the title of the PrintJob. A null title is equivalent 1183 * to "". 1184 * @param jobAttributes a set of job attributes which will control the 1185 * PrintJob. The attributes will be updated to reflect the user's 1186 * choices as outlined in the JobAttributes documentation. May be 1187 * null. 1188 * @param pageAttributes a set of page attributes which will control the 1189 * PrintJob. The attributes will be applied to every page in the 1190 * job. The attributes will be updated to reflect the user's 1191 * choices as outlined in the PageAttributes documentation. May be 1192 * null. 1193 * @return a <code>PrintJob</code> object, or <code>null</code> if the 1194 * user cancelled the print job. 1195 * @throws NullPointerException if frame is null 1196 * @throws IllegalArgumentException if pageAttributes specifies differing 1197 * cross feed and feed resolutions. Also if this thread has 1198 * access to the file system and jobAttributes specifies 1199 * print to file, and the specified destination file exists but 1200 * is a directory rather than a regular file, does not exist but 1201 * cannot be created, or cannot be opened for any other reason. 1202 * However in the case of print to file, if a dialog is also 1203 * requested to be displayed then the user will be given an 1204 * opportunity to select a file and proceed with printing. 1205 * The dialog will ensure that the selected output file 1206 * is valid before returning from this method. 1207 * @throws SecurityException if this thread is not allowed to initiate a 1208 * print job request, or if jobAttributes specifies print to file, 1209 * and this thread is not allowed to access the file system 1210 * @see java.awt.PrintJob 1211 * @see java.awt.GraphicsEnvironment#isHeadless 1212 * @see java.lang.RuntimePermission 1213 * @see java.awt.JobAttributes 1214 * @see java.awt.PageAttributes 1215 * @since 1.3 1216 */ 1217 public PrintJob getPrintJob(Frame frame, String jobtitle, 1218 JobAttributes jobAttributes, 1219 PageAttributes pageAttributes) { 1220 // Override to add printing support with new job/page control classes 1221 1222 if (this != Toolkit.getDefaultToolkit()) { 1223 return Toolkit.getDefaultToolkit().getPrintJob(frame, jobtitle, 1224 jobAttributes, 1225 pageAttributes); 1226 } else { 1227 return getPrintJob(frame, jobtitle, null); 1228 } 1229 } 1230 1231 /** 1232 * Emits an audio beep depending on native system settings and hardware 1233 * capabilities. 1234 * @since 1.1 1235 */ 1236 public abstract void beep(); 1237 1238 /** 1239 * Gets the singleton instance of the system Clipboard which interfaces 1240 * with clipboard facilities provided by the native platform. This 1241 * clipboard enables data transfer between Java programs and native 1242 * applications which use native clipboard facilities. 1243 * <p> 1244 * In addition to any and all default formats text returned by the system 1245 * Clipboard's <code>getTransferData()</code> method is available in the 1246 * following flavors: 1247 * <ul> 1248 * <li>DataFlavor.stringFlavor</li> 1249 * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li> 1250 * </ul> 1251 * As with <code>java.awt.datatransfer.StringSelection</code>, if the 1252 * requested flavor is <code>DataFlavor.plainTextFlavor</code>, or an 1253 * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of 1254 * the system Clipboard's <code>getTransferData()</code> method for <code> 1255 * DataFlavor.plainTextFlavor</code>, and equivalent DataFlavors, is 1256 * inconsistent with the definition of <code>DataFlavor.plainTextFlavor 1257 * </code>. Because of this, support for <code> 1258 * DataFlavor.plainTextFlavor</code>, and equivalent flavors, is 1259 * <b>deprecated</b>. 1260 * <p> 1261 * Each actual implementation of this method should first check if there 1262 * is a security manager installed. If there is, the method should call 1263 * the security manager's {@link SecurityManager#checkPermission 1264 * checkPermission} method to check {@code AWTPermission("accessClipboard")}. 1265 * 1266 * @return the system Clipboard 1267 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1268 * returns true 1269 * @see java.awt.GraphicsEnvironment#isHeadless 1270 * @see java.awt.datatransfer.Clipboard 1271 * @see java.awt.datatransfer.StringSelection 1272 * @see java.awt.datatransfer.DataFlavor#stringFlavor 1273 * @see java.awt.datatransfer.DataFlavor#plainTextFlavor 1274 * @see java.io.Reader 1275 * @see java.awt.AWTPermission 1276 * @since 1.1 1277 */ 1278 public abstract Clipboard getSystemClipboard() 1279 throws HeadlessException; 1280 1281 /** 1282 * Gets the singleton instance of the system selection as a 1283 * <code>Clipboard</code> object. This allows an application to read and 1284 * modify the current, system-wide selection. 1285 * <p> 1286 * An application is responsible for updating the system selection whenever 1287 * the user selects text, using either the mouse or the keyboard. 1288 * Typically, this is implemented by installing a 1289 * <code>FocusListener</code> on all <code>Component</code>s which support 1290 * text selection, and, between <code>FOCUS_GAINED</code> and 1291 * <code>FOCUS_LOST</code> events delivered to that <code>Component</code>, 1292 * updating the system selection <code>Clipboard</code> when the selection 1293 * changes inside the <code>Component</code>. Properly updating the system 1294 * selection ensures that a Java application will interact correctly with 1295 * native applications and other Java applications running simultaneously 1296 * on the system. Note that <code>java.awt.TextComponent</code> and 1297 * <code>javax.swing.text.JTextComponent</code> already adhere to this 1298 * policy. When using these classes, and their subclasses, developers need 1299 * not write any additional code. 1300 * <p> 1301 * Some platforms do not support a system selection <code>Clipboard</code>. 1302 * On those platforms, this method will return <code>null</code>. In such a 1303 * case, an application is absolved from its responsibility to update the 1304 * system selection <code>Clipboard</code> as described above. 1305 * <p> 1306 * Each actual implementation of this method should first check if there 1307 * is a security manager installed. If there is, the method should call 1308 * the security manager's {@link SecurityManager#checkPermission 1309 * checkPermission} method to check {@code AWTPermission("accessClipboard")}. 1310 * 1311 * @return the system selection as a <code>Clipboard</code>, or 1312 * <code>null</code> if the native platform does not support a 1313 * system selection <code>Clipboard</code> 1314 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1315 * returns true 1316 * 1317 * @see java.awt.datatransfer.Clipboard 1318 * @see java.awt.event.FocusListener 1319 * @see java.awt.event.FocusEvent#FOCUS_GAINED 1320 * @see java.awt.event.FocusEvent#FOCUS_LOST 1321 * @see TextComponent 1322 * @see javax.swing.text.JTextComponent 1323 * @see AWTPermission 1324 * @see GraphicsEnvironment#isHeadless 1325 * @since 1.4 1326 */ 1327 public Clipboard getSystemSelection() throws HeadlessException { 1328 GraphicsEnvironment.checkHeadless(); 1329 1330 if (this != Toolkit.getDefaultToolkit()) { 1331 return Toolkit.getDefaultToolkit().getSystemSelection(); 1332 } else { 1333 GraphicsEnvironment.checkHeadless(); 1334 return null; 1335 } 1336 } 1337 1338 /** 1339 * Determines which modifier key is the appropriate accelerator 1340 * key for menu shortcuts. 1341 * <p> 1342 * Menu shortcuts, which are embodied in the 1343 * <code>MenuShortcut</code> class, are handled by the 1344 * <code>MenuBar</code> class. 1345 * <p> 1346 * By default, this method returns <code>Event.CTRL_MASK</code>. 1347 * Toolkit implementations should override this method if the 1348 * <b>Control</b> key isn't the correct key for accelerators. 1349 * @return the modifier mask on the <code>Event</code> class 1350 * that is used for menu shortcuts on this toolkit. 1351 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1352 * returns true 1353 * @see java.awt.GraphicsEnvironment#isHeadless 1354 * @see java.awt.MenuBar 1355 * @see java.awt.MenuShortcut 1356 * @since 1.1 1357 */ 1358 public int getMenuShortcutKeyMask() throws HeadlessException { 1359 GraphicsEnvironment.checkHeadless(); 1360 1361 return Event.CTRL_MASK; 1362 } 1363 1364 /** 1365 * Returns whether the given locking key on the keyboard is currently in 1366 * its "on" state. 1367 * Valid key codes are 1368 * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK}, 1369 * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK}, 1370 * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and 1371 * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}. 1372 * 1373 * @param keyCode the key code 1374 * @return {@code true} if the given key is currently in its "on" state; 1375 * otherwise {@code false} 1376 * @exception java.lang.IllegalArgumentException if <code>keyCode</code> 1377 * is not one of the valid key codes 1378 * @exception java.lang.UnsupportedOperationException if the host system doesn't 1379 * allow getting the state of this key programmatically, or if the keyboard 1380 * doesn't have this key 1381 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1382 * returns true 1383 * @see java.awt.GraphicsEnvironment#isHeadless 1384 * @since 1.3 1385 */ 1386 public boolean getLockingKeyState(int keyCode) 1387 throws UnsupportedOperationException 1388 { 1389 GraphicsEnvironment.checkHeadless(); 1390 1391 if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || 1392 keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) { 1393 throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState"); 1394 } 1395 throw new UnsupportedOperationException("Toolkit.getLockingKeyState"); 1396 } 1397 1398 /** 1399 * Sets the state of the given locking key on the keyboard. 1400 * Valid key codes are 1401 * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK}, 1402 * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK}, 1403 * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and 1404 * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}. 1405 * <p> 1406 * Depending on the platform, setting the state of a locking key may 1407 * involve event processing and therefore may not be immediately 1408 * observable through getLockingKeyState. 1409 * 1410 * @param keyCode the key code 1411 * @param on the state of the key 1412 * @exception java.lang.IllegalArgumentException if <code>keyCode</code> 1413 * is not one of the valid key codes 1414 * @exception java.lang.UnsupportedOperationException if the host system doesn't 1415 * allow setting the state of this key programmatically, or if the keyboard 1416 * doesn't have this key 1417 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1418 * returns true 1419 * @see java.awt.GraphicsEnvironment#isHeadless 1420 * @since 1.3 1421 */ 1422 public void setLockingKeyState(int keyCode, boolean on) 1423 throws UnsupportedOperationException 1424 { 1425 GraphicsEnvironment.checkHeadless(); 1426 1427 if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || 1428 keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) { 1429 throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState"); 1430 } 1431 throw new UnsupportedOperationException("Toolkit.setLockingKeyState"); 1432 } 1433 1434 /** 1435 * Give native peers the ability to query the native container 1436 * given a native component (eg the direct parent may be lightweight). 1437 * 1438 * @param c the component to fetch the container for 1439 * @return the native container object for the component 1440 */ 1441 protected static Container getNativeContainer(Component c) { 1442 return c.getNativeContainer(); 1443 } 1444 1445 /** 1446 * Creates a new custom cursor object. 1447 * If the image to display is invalid, the cursor will be hidden (made 1448 * completely transparent), and the hotspot will be set to (0, 0). 1449 * 1450 * <p>Note that multi-frame images are invalid and may cause this 1451 * method to hang. 1452 * 1453 * @param cursor the image to display when the cursor is activated 1454 * @param hotSpot the X and Y of the large cursor's hot spot; the 1455 * hotSpot values must be less than the Dimension returned by 1456 * <code>getBestCursorSize</code> 1457 * @param name a localized description of the cursor, for Java Accessibility use 1458 * @exception IndexOutOfBoundsException if the hotSpot values are outside 1459 * the bounds of the cursor 1460 * @return the cursor created 1461 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1462 * returns true 1463 * @see java.awt.GraphicsEnvironment#isHeadless 1464 * @since 1.2 1465 */ 1466 public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) 1467 throws IndexOutOfBoundsException, HeadlessException 1468 { 1469 // Override to implement custom cursor support. 1470 if (this != Toolkit.getDefaultToolkit()) { 1471 return Toolkit.getDefaultToolkit(). 1472 createCustomCursor(cursor, hotSpot, name); 1473 } else { 1474 return new Cursor(Cursor.DEFAULT_CURSOR); 1475 } 1476 } 1477 1478 /** 1479 * Returns the supported cursor dimension which is closest to the desired 1480 * sizes. Systems which only support a single cursor size will return that 1481 * size regardless of the desired sizes. Systems which don't support custom 1482 * cursors will return a dimension of 0, 0. <p> 1483 * Note: if an image is used whose dimensions don't match a supported size 1484 * (as returned by this method), the Toolkit implementation will attempt to 1485 * resize the image to a supported size. 1486 * Since converting low-resolution images is difficult, 1487 * no guarantees are made as to the quality of a cursor image which isn't a 1488 * supported size. It is therefore recommended that this method 1489 * be called and an appropriate image used so no image conversion is made. 1490 * 1491 * @param preferredWidth the preferred cursor width the component would like 1492 * to use. 1493 * @param preferredHeight the preferred cursor height the component would like 1494 * to use. 1495 * @return the closest matching supported cursor size, or a dimension of 0,0 if 1496 * the Toolkit implementation doesn't support custom cursors. 1497 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1498 * returns true 1499 * @see java.awt.GraphicsEnvironment#isHeadless 1500 * @since 1.2 1501 */ 1502 public Dimension getBestCursorSize(int preferredWidth, 1503 int preferredHeight) throws HeadlessException { 1504 GraphicsEnvironment.checkHeadless(); 1505 1506 // Override to implement custom cursor support. 1507 if (this != Toolkit.getDefaultToolkit()) { 1508 return Toolkit.getDefaultToolkit(). 1509 getBestCursorSize(preferredWidth, preferredHeight); 1510 } else { 1511 return new Dimension(0, 0); 1512 } 1513 } 1514 1515 /** 1516 * Returns the maximum number of colors the Toolkit supports in a custom cursor 1517 * palette.<p> 1518 * Note: if an image is used which has more colors in its palette than 1519 * the supported maximum, the Toolkit implementation will attempt to flatten the 1520 * palette to the maximum. Since converting low-resolution images is difficult, 1521 * no guarantees are made as to the quality of a cursor image which has more 1522 * colors than the system supports. It is therefore recommended that this method 1523 * be called and an appropriate image used so no image conversion is made. 1524 * 1525 * @return the maximum number of colors, or zero if custom cursors are not 1526 * supported by this Toolkit implementation. 1527 * @exception HeadlessException if GraphicsEnvironment.isHeadless() 1528 * returns true 1529 * @see java.awt.GraphicsEnvironment#isHeadless 1530 * @since 1.2 1531 */ 1532 public int getMaximumCursorColors() throws HeadlessException { 1533 GraphicsEnvironment.checkHeadless(); 1534 1535 // Override to implement custom cursor support. 1536 if (this != Toolkit.getDefaultToolkit()) { 1537 return Toolkit.getDefaultToolkit().getMaximumCursorColors(); 1538 } else { 1539 return 0; 1540 } 1541 } 1542 1543 /** 1544 * Returns whether Toolkit supports this state for 1545 * <code>Frame</code>s. This method tells whether the <em>UI 1546 * concept</em> of, say, maximization or iconification is 1547 * supported. It will always return false for "compound" states 1548 * like <code>Frame.ICONIFIED|Frame.MAXIMIZED_VERT</code>. 1549 * In other words, the rule of thumb is that only queries with a 1550 * single frame state constant as an argument are meaningful. 1551 * <p>Note that supporting a given concept is a platform- 1552 * dependent feature. Due to native limitations the Toolkit 1553 * object may report a particular state as supported, however at 1554 * the same time the Toolkit object will be unable to apply the 1555 * state to a given frame. This circumstance has two following 1556 * consequences: 1557 * <ul> 1558 * <li>Only the return value of {@code false} for the present 1559 * method actually indicates that the given state is not 1560 * supported. If the method returns {@code true} the given state 1561 * may still be unsupported and/or unavailable for a particular 1562 * frame. 1563 * <li>The developer should consider examining the value of the 1564 * {@link java.awt.event.WindowEvent#getNewState} method of the 1565 * {@code WindowEvent} received through the {@link 1566 * java.awt.event.WindowStateListener}, rather than assuming 1567 * that the state given to the {@code setExtendedState()} method 1568 * will be definitely applied. For more information see the 1569 * documentation for the {@link Frame#setExtendedState} method. 1570 * </ul> 1571 * 1572 * @param state one of named frame state constants. 1573 * @return <code>true</code> is this frame state is supported by 1574 * this Toolkit implementation, <code>false</code> otherwise. 1575 * @exception HeadlessException 1576 * if <code>GraphicsEnvironment.isHeadless()</code> 1577 * returns <code>true</code>. 1578 * @see java.awt.Window#addWindowStateListener 1579 * @since 1.4 1580 */ 1581 public boolean isFrameStateSupported(int state) 1582 throws HeadlessException 1583 { 1584 GraphicsEnvironment.checkHeadless(); 1585 1586 if (this != Toolkit.getDefaultToolkit()) { 1587 return Toolkit.getDefaultToolkit(). 1588 isFrameStateSupported(state); 1589 } else { 1590 return (state == Frame.NORMAL); // others are not guaranteed 1591 } 1592 } 1593 1594 /** 1595 * Support for I18N: any visible strings should be stored in 1596 * sun.awt.resources.awt.properties. The ResourceBundle is stored 1597 * here, so that only one copy is maintained. 1598 */ 1599 private static ResourceBundle resources; 1600 private static ResourceBundle platformResources; 1601 1602 // called by platform toolkit 1603 private static void setPlatformResources(ResourceBundle bundle) { 1604 platformResources = bundle; 1605 } 1606 1607 /** 1608 * Initialize JNI field and method ids 1609 */ 1610 private static native void initIDs(); 1611 1612 /** 1613 * WARNING: This is a temporary workaround for a problem in the 1614 * way the AWT loads native libraries. A number of classes in the 1615 * AWT package have a native method, initIDs(), which initializes 1616 * the JNI field and method ids used in the native portion of 1617 * their implementation. 1618 * 1619 * Since the use and storage of these ids is done by the 1620 * implementation libraries, the implementation of these method is 1621 * provided by the particular AWT implementations (for example, 1622 * "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The 1623 * problem is that this means that the native libraries must be 1624 * loaded by the java.* classes, which do not necessarily know the 1625 * names of the libraries to load. A better way of doing this 1626 * would be to provide a separate library which defines java.awt.* 1627 * initIDs, and exports the relevant symbols out to the 1628 * implementation libraries. 1629 * 1630 * For now, we know it's done by the implementation, and we assume 1631 * that the name of the library is "awt". -br. 1632 * 1633 * If you change loadLibraries(), please add the change to 1634 * java.awt.image.ColorModel.loadLibraries(). Unfortunately, 1635 * classes can be loaded in java.awt.image that depend on 1636 * libawt and there is no way to call Toolkit.loadLibraries() 1637 * directly. -hung 1638 */ 1639 private static boolean loaded = false; 1640 static void loadLibraries() { 1641 if (!loaded) { 1642 java.security.AccessController.doPrivileged( 1643 new java.security.PrivilegedAction<Void>() { 1644 public Void run() { 1645 System.loadLibrary("awt"); 1646 return null; 1647 } 1648 }); 1649 loaded = true; 1650 } 1651 } 1652 1653 static { 1654 AWTAccessor.setToolkitAccessor( 1655 new AWTAccessor.ToolkitAccessor() { 1656 @Override 1657 public void setPlatformResources(ResourceBundle bundle) { 1658 Toolkit.setPlatformResources(bundle); 1659 } 1660 }); 1661 1662 java.security.AccessController.doPrivileged( 1663 new java.security.PrivilegedAction<Void>() { 1664 public Void run() { 1665 try { 1666 resources = 1667 ResourceBundle.getBundle("sun.awt.resources.awt", 1668 CoreResourceBundleControl.getRBControlInstance()); 1669 } catch (MissingResourceException e) { 1670 // No resource file; defaults will be used. 1671 } 1672 return null; 1673 } 1674 }); 1675 1676 // ensure that the proper libraries are loaded 1677 loadLibraries(); 1678 initAssistiveTechnologies(); 1679 if (!GraphicsEnvironment.isHeadless()) { 1680 initIDs(); 1681 } 1682 } 1683 1684 /** 1685 * Gets a property with the specified key and default. 1686 * This method returns defaultValue if the property is not found. 1687 * 1688 * @param key the key 1689 * @param defaultValue the default value 1690 * @return the value of the property or the default value 1691 * if the property was not found 1692 */ 1693 public static String getProperty(String key, String defaultValue) { 1694 // first try platform specific bundle 1695 if (platformResources != null) { 1696 try { 1697 return platformResources.getString(key); 1698 } 1699 catch (MissingResourceException e) {} 1700 } 1701 1702 // then shared one 1703 if (resources != null) { 1704 try { 1705 return resources.getString(key); 1706 } 1707 catch (MissingResourceException e) {} 1708 } 1709 1710 return defaultValue; 1711 } 1712 1713 /** 1714 * Get the application's or applet's EventQueue instance. 1715 * Depending on the Toolkit implementation, different EventQueues 1716 * may be returned for different applets. Applets should 1717 * therefore not assume that the EventQueue instance returned 1718 * by this method will be shared by other applets or the system. 1719 * 1720 * <p> If there is a security manager then its 1721 * {@link SecurityManager#checkPermission checkPermission} method 1722 * is called to check {@code AWTPermission("accessEventQueue")}. 1723 * 1724 * @return the <code>EventQueue</code> object 1725 * @throws SecurityException 1726 * if a security manager is set and it denies access to 1727 * the {@code EventQueue} 1728 * @see java.awt.AWTPermission 1729 */ 1730 public final EventQueue getSystemEventQueue() { 1731 SecurityManager security = System.getSecurityManager(); 1732 if (security != null) { 1733 security.checkPermission(AWTPermissions.CHECK_AWT_EVENTQUEUE_PERMISSION); 1734 } 1735 return getSystemEventQueueImpl(); 1736 } 1737 1738 /** 1739 * Gets the application's or applet's <code>EventQueue</code> 1740 * instance, without checking access. For security reasons, 1741 * this can only be called from a <code>Toolkit</code> subclass. 1742 * @return the <code>EventQueue</code> object 1743 */ 1744 protected abstract EventQueue getSystemEventQueueImpl(); 1745 1746 /* Accessor method for use by AWT package routines. */ 1747 static EventQueue getEventQueue() { 1748 return getDefaultToolkit().getSystemEventQueueImpl(); 1749 } 1750 1751 /** 1752 * Creates the peer for a DragSourceContext. 1753 * Always throws InvalidDndOperationException if 1754 * GraphicsEnvironment.isHeadless() returns true. 1755 * 1756 * @param dge the {@code DragGestureEvent} 1757 * @return the peer created 1758 * @see java.awt.GraphicsEnvironment#isHeadless 1759 */ 1760 public abstract DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException; 1761 1762 /** 1763 * Creates a concrete, platform dependent, subclass of the abstract 1764 * DragGestureRecognizer class requested, and associates it with the 1765 * DragSource, Component and DragGestureListener specified. 1766 * 1767 * subclasses should override this to provide their own implementation 1768 * 1769 * @param <T> the type of DragGestureRecognizer to create 1770 * @param abstractRecognizerClass The abstract class of the required recognizer 1771 * @param ds The DragSource 1772 * @param c The Component target for the DragGestureRecognizer 1773 * @param srcActions The actions permitted for the gesture 1774 * @param dgl The DragGestureListener 1775 * 1776 * @return the new object or null. Always returns null if 1777 * GraphicsEnvironment.isHeadless() returns true. 1778 * @see java.awt.GraphicsEnvironment#isHeadless 1779 */ 1780 public <T extends DragGestureRecognizer> T 1781 createDragGestureRecognizer(Class<T> abstractRecognizerClass, 1782 DragSource ds, Component c, int srcActions, 1783 DragGestureListener dgl) 1784 { 1785 return null; 1786 } 1787 1788 /** 1789 * Obtains a value for the specified desktop property. 1790 * 1791 * A desktop property is a uniquely named value for a resource that 1792 * is Toolkit global in nature. Usually it also is an abstract 1793 * representation for an underlying platform dependent desktop setting. 1794 * For more information on desktop properties supported by the AWT see 1795 * <a href="doc-files/DesktopProperties.html">AWT Desktop Properties</a>. 1796 * 1797 * @param propertyName the property name 1798 * @return the value for the specified desktop property 1799 */ 1800 public final synchronized Object getDesktopProperty(String propertyName) { 1801 // This is a workaround for headless toolkits. It would be 1802 // better to override this method but it is declared final. 1803 // "this instanceof" syntax defeats polymorphism. 1804 // --mm, 03/03/00 1805 if (this instanceof HeadlessToolkit) { 1806 return ((HeadlessToolkit)this).getUnderlyingToolkit() 1807 .getDesktopProperty(propertyName); 1808 } 1809 1810 if (desktopProperties.isEmpty()) { 1811 initializeDesktopProperties(); 1812 } 1813 1814 Object value; 1815 1816 // This property should never be cached 1817 if (propertyName.equals("awt.dynamicLayoutSupported")) { 1818 return getDefaultToolkit().lazilyLoadDesktopProperty(propertyName); 1819 } 1820 1821 value = desktopProperties.get(propertyName); 1822 1823 if (value == null) { 1824 value = lazilyLoadDesktopProperty(propertyName); 1825 1826 if (value != null) { 1827 setDesktopProperty(propertyName, value); 1828 } 1829 } 1830 1831 /* for property "awt.font.desktophints" */ 1832 if (value instanceof RenderingHints) { 1833 value = ((RenderingHints)value).clone(); 1834 } 1835 1836 return value; 1837 } 1838 1839 /** 1840 * Sets the named desktop property to the specified value and fires a 1841 * property change event to notify any listeners that the value has changed. 1842 * 1843 * @param name the property name 1844 * @param newValue the new property value 1845 */ 1846 protected final void setDesktopProperty(String name, Object newValue) { 1847 // This is a workaround for headless toolkits. It would be 1848 // better to override this method but it is declared final. 1849 // "this instanceof" syntax defeats polymorphism. 1850 // --mm, 03/03/00 1851 if (this instanceof HeadlessToolkit) { 1852 ((HeadlessToolkit)this).getUnderlyingToolkit() 1853 .setDesktopProperty(name, newValue); 1854 return; 1855 } 1856 Object oldValue; 1857 1858 synchronized (this) { 1859 oldValue = desktopProperties.get(name); 1860 desktopProperties.put(name, newValue); 1861 } 1862 1863 // Don't fire change event if old and new values are null. 1864 // It helps to avoid recursive resending of WM_THEMECHANGED 1865 if (oldValue != null || newValue != null) { 1866 desktopPropsSupport.firePropertyChange(name, oldValue, newValue); 1867 } 1868 } 1869 1870 /** 1871 * An opportunity to lazily evaluate desktop property values. 1872 * @return the desktop property or null 1873 * @param name the name 1874 */ 1875 protected Object lazilyLoadDesktopProperty(String name) { 1876 return null; 1877 } 1878 1879 /** 1880 * initializeDesktopProperties 1881 */ 1882 protected void initializeDesktopProperties() { 1883 } 1884 1885 /** 1886 * Adds the specified property change listener for the named desktop 1887 * property. When a {@link java.beans.PropertyChangeListenerProxy} object is added, 1888 * its property name is ignored, and the wrapped listener is added. 1889 * If {@code name} is {@code null} or {@code pcl} is {@code null}, 1890 * no exception is thrown and no action is performed. 1891 * 1892 * @param name The name of the property to listen for 1893 * @param pcl The property change listener 1894 * @see PropertyChangeSupport#addPropertyChangeListener(String, 1895 PropertyChangeListener) 1896 * @since 1.2 1897 */ 1898 public void addPropertyChangeListener(String name, PropertyChangeListener pcl) { 1899 desktopPropsSupport.addPropertyChangeListener(name, pcl); 1900 } 1901 1902 /** 1903 * Removes the specified property change listener for the named 1904 * desktop property. When a {@link java.beans.PropertyChangeListenerProxy} object 1905 * is removed, its property name is ignored, and 1906 * the wrapped listener is removed. 1907 * If {@code name} is {@code null} or {@code pcl} is {@code null}, 1908 * no exception is thrown and no action is performed. 1909 * 1910 * @param name The name of the property to remove 1911 * @param pcl The property change listener 1912 * @see PropertyChangeSupport#removePropertyChangeListener(String, 1913 PropertyChangeListener) 1914 * @since 1.2 1915 */ 1916 public void removePropertyChangeListener(String name, PropertyChangeListener pcl) { 1917 desktopPropsSupport.removePropertyChangeListener(name, pcl); 1918 } 1919 1920 /** 1921 * Returns an array of all the property change listeners 1922 * registered on this toolkit. The returned array 1923 * contains {@link java.beans.PropertyChangeListenerProxy} objects 1924 * that associate listeners with the names of desktop properties. 1925 * 1926 * @return all of this toolkit's {@link PropertyChangeListener} 1927 * objects wrapped in {@code java.beans.PropertyChangeListenerProxy} objects 1928 * or an empty array if no listeners are added 1929 * 1930 * @see PropertyChangeSupport#getPropertyChangeListeners() 1931 * @since 1.4 1932 */ 1933 public PropertyChangeListener[] getPropertyChangeListeners() { 1934 return desktopPropsSupport.getPropertyChangeListeners(); 1935 } 1936 1937 /** 1938 * Returns an array of all property change listeners 1939 * associated with the specified name of a desktop property. 1940 * 1941 * @param propertyName the named property 1942 * @return all of the {@code PropertyChangeListener} objects 1943 * associated with the specified name of a desktop property 1944 * or an empty array if no such listeners are added 1945 * 1946 * @see PropertyChangeSupport#getPropertyChangeListeners(String) 1947 * @since 1.4 1948 */ 1949 public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { 1950 return desktopPropsSupport.getPropertyChangeListeners(propertyName); 1951 } 1952 1953 /** 1954 * The desktop properties. 1955 */ 1956 protected final Map<String,Object> desktopProperties = 1957 new HashMap<String,Object>(); 1958 /** 1959 * The desktop properties change support. 1960 */ 1961 protected final PropertyChangeSupport desktopPropsSupport = 1962 Toolkit.createPropertyChangeSupport(this); 1963 1964 /** 1965 * Returns whether the always-on-top mode is supported by this toolkit. 1966 * To detect whether the always-on-top mode is supported for a 1967 * particular Window, use {@link Window#isAlwaysOnTopSupported}. 1968 * @return <code>true</code>, if current toolkit supports the always-on-top mode, 1969 * otherwise returns <code>false</code> 1970 * @see Window#isAlwaysOnTopSupported 1971 * @see Window#setAlwaysOnTop(boolean) 1972 * @since 1.6 1973 */ 1974 public boolean isAlwaysOnTopSupported() { 1975 return true; 1976 } 1977 1978 /** 1979 * Returns whether the given modality type is supported by this toolkit. If 1980 * a dialog with unsupported modality type is created, then 1981 * <code>Dialog.ModalityType.MODELESS</code> is used instead. 1982 * 1983 * @param modalityType modality type to be checked for support by this toolkit 1984 * 1985 * @return <code>true</code>, if current toolkit supports given modality 1986 * type, <code>false</code> otherwise 1987 * 1988 * @see java.awt.Dialog.ModalityType 1989 * @see java.awt.Dialog#getModalityType 1990 * @see java.awt.Dialog#setModalityType 1991 * 1992 * @since 1.6 1993 */ 1994 public abstract boolean isModalityTypeSupported(Dialog.ModalityType modalityType); 1995 1996 /** 1997 * Returns whether the given modal exclusion type is supported by this 1998 * toolkit. If an unsupported modal exclusion type property is set on a window, 1999 * then <code>Dialog.ModalExclusionType.NO_EXCLUDE</code> is used instead. 2000 * 2001 * @param modalExclusionType modal exclusion type to be checked for support by this toolkit 2002 * 2003 * @return <code>true</code>, if current toolkit supports given modal exclusion 2004 * type, <code>false</code> otherwise 2005 * 2006 * @see java.awt.Dialog.ModalExclusionType 2007 * @see java.awt.Window#getModalExclusionType 2008 * @see java.awt.Window#setModalExclusionType 2009 * 2010 * @since 1.6 2011 */ 2012 public abstract boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType); 2013 2014 // 8014718: logging has been removed from SunToolkit 2015 2016 private static final int LONG_BITS = 64; 2017 private int[] calls = new int[LONG_BITS]; 2018 private static volatile long enabledOnToolkitMask; 2019 private AWTEventListener eventListener = null; 2020 private WeakHashMap<AWTEventListener, SelectiveAWTEventListener> listener2SelectiveListener = new WeakHashMap<>(); 2021 2022 /* 2023 * Extracts a "pure" AWTEventListener from a AWTEventListenerProxy, 2024 * if the listener is proxied. 2025 */ 2026 static private AWTEventListener deProxyAWTEventListener(AWTEventListener l) 2027 { 2028 AWTEventListener localL = l; 2029 2030 if (localL == null) { 2031 return null; 2032 } 2033 // if user passed in a AWTEventListenerProxy object, extract 2034 // the listener 2035 if (l instanceof AWTEventListenerProxy) { 2036 localL = ((AWTEventListenerProxy)l).getListener(); 2037 } 2038 return localL; 2039 } 2040 2041 /** 2042 * Adds an AWTEventListener to receive all AWTEvents dispatched 2043 * system-wide that conform to the given <code>eventMask</code>. 2044 * <p> 2045 * First, if there is a security manager, its <code>checkPermission</code> 2046 * method is called with an 2047 * <code>AWTPermission("listenToAllAWTEvents")</code> permission. 2048 * This may result in a SecurityException. 2049 * <p> 2050 * <code>eventMask</code> is a bitmask of event types to receive. 2051 * It is constructed by bitwise OR-ing together the event masks 2052 * defined in <code>AWTEvent</code>. 2053 * <p> 2054 * Note: event listener use is not recommended for normal 2055 * application use, but are intended solely to support special 2056 * purpose facilities including support for accessibility, 2057 * event record/playback, and diagnostic tracing. 2058 * 2059 * If listener is null, no exception is thrown and no action is performed. 2060 * 2061 * @param listener the event listener. 2062 * @param eventMask the bitmask of event types to receive 2063 * @throws SecurityException 2064 * if a security manager exists and its 2065 * <code>checkPermission</code> method doesn't allow the operation. 2066 * @see #removeAWTEventListener 2067 * @see #getAWTEventListeners 2068 * @see SecurityManager#checkPermission 2069 * @see java.awt.AWTEvent 2070 * @see java.awt.AWTPermission 2071 * @see java.awt.event.AWTEventListener 2072 * @see java.awt.event.AWTEventListenerProxy 2073 * @since 1.2 2074 */ 2075 public void addAWTEventListener(AWTEventListener listener, long eventMask) { 2076 AWTEventListener localL = deProxyAWTEventListener(listener); 2077 2078 if (localL == null) { 2079 return; 2080 } 2081 SecurityManager security = System.getSecurityManager(); 2082 if (security != null) { 2083 security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION); 2084 } 2085 synchronized (this) { 2086 SelectiveAWTEventListener selectiveListener = 2087 listener2SelectiveListener.get(localL); 2088 2089 if (selectiveListener == null) { 2090 // Create a new selectiveListener. 2091 selectiveListener = new SelectiveAWTEventListener(localL, 2092 eventMask); 2093 listener2SelectiveListener.put(localL, selectiveListener); 2094 eventListener = ToolkitEventMulticaster.add(eventListener, 2095 selectiveListener); 2096 } 2097 // OR the eventMask into the selectiveListener's event mask. 2098 selectiveListener.orEventMasks(eventMask); 2099 2100 enabledOnToolkitMask |= eventMask; 2101 2102 long mask = eventMask; 2103 for (int i=0; i<LONG_BITS; i++) { 2104 // If no bits are set, break out of loop. 2105 if (mask == 0) { 2106 break; 2107 } 2108 if ((mask & 1L) != 0) { // Always test bit 0. 2109 calls[i]++; 2110 } 2111 mask >>>= 1; // Right shift, fill with zeros on left. 2112 } 2113 } 2114 } 2115 2116 /** 2117 * Removes an AWTEventListener from receiving dispatched AWTEvents. 2118 * <p> 2119 * First, if there is a security manager, its <code>checkPermission</code> 2120 * method is called with an 2121 * <code>AWTPermission("listenToAllAWTEvents")</code> permission. 2122 * This may result in a SecurityException. 2123 * <p> 2124 * Note: event listener use is not recommended for normal 2125 * application use, but are intended solely to support special 2126 * purpose facilities including support for accessibility, 2127 * event record/playback, and diagnostic tracing. 2128 * 2129 * If listener is null, no exception is thrown and no action is performed. 2130 * 2131 * @param listener the event listener. 2132 * @throws SecurityException 2133 * if a security manager exists and its 2134 * <code>checkPermission</code> method doesn't allow the operation. 2135 * @see #addAWTEventListener 2136 * @see #getAWTEventListeners 2137 * @see SecurityManager#checkPermission 2138 * @see java.awt.AWTEvent 2139 * @see java.awt.AWTPermission 2140 * @see java.awt.event.AWTEventListener 2141 * @see java.awt.event.AWTEventListenerProxy 2142 * @since 1.2 2143 */ 2144 public void removeAWTEventListener(AWTEventListener listener) { 2145 AWTEventListener localL = deProxyAWTEventListener(listener); 2146 2147 if (listener == null) { 2148 return; 2149 } 2150 SecurityManager security = System.getSecurityManager(); 2151 if (security != null) { 2152 security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION); 2153 } 2154 2155 synchronized (this) { 2156 SelectiveAWTEventListener selectiveListener = 2157 listener2SelectiveListener.get(localL); 2158 2159 if (selectiveListener != null) { 2160 listener2SelectiveListener.remove(localL); 2161 int[] listenerCalls = selectiveListener.getCalls(); 2162 for (int i=0; i<LONG_BITS; i++) { 2163 calls[i] -= listenerCalls[i]; 2164 assert calls[i] >= 0: "Negative Listeners count"; 2165 2166 if (calls[i] == 0) { 2167 enabledOnToolkitMask &= ~(1L<<i); 2168 } 2169 } 2170 } 2171 eventListener = ToolkitEventMulticaster.remove(eventListener, 2172 (selectiveListener == null) ? localL : selectiveListener); 2173 } 2174 } 2175 2176 static boolean enabledOnToolkit(long eventMask) { 2177 return (enabledOnToolkitMask & eventMask) != 0; 2178 } 2179 2180 synchronized int countAWTEventListeners(long eventMask) { 2181 int ci = 0; 2182 for (; eventMask != 0; eventMask >>>= 1, ci++) { 2183 } 2184 ci--; 2185 return calls[ci]; 2186 } 2187 /** 2188 * Returns an array of all the <code>AWTEventListener</code>s 2189 * registered on this toolkit. 2190 * If there is a security manager, its {@code checkPermission} 2191 * method is called with an 2192 * {@code AWTPermission("listenToAllAWTEvents")} permission. 2193 * This may result in a SecurityException. 2194 * Listeners can be returned 2195 * within <code>AWTEventListenerProxy</code> objects, which also contain 2196 * the event mask for the given listener. 2197 * Note that listener objects 2198 * added multiple times appear only once in the returned array. 2199 * 2200 * @return all of the <code>AWTEventListener</code>s or an empty 2201 * array if no listeners are currently registered 2202 * @throws SecurityException 2203 * if a security manager exists and its 2204 * <code>checkPermission</code> method doesn't allow the operation. 2205 * @see #addAWTEventListener 2206 * @see #removeAWTEventListener 2207 * @see SecurityManager#checkPermission 2208 * @see java.awt.AWTEvent 2209 * @see java.awt.AWTPermission 2210 * @see java.awt.event.AWTEventListener 2211 * @see java.awt.event.AWTEventListenerProxy 2212 * @since 1.4 2213 */ 2214 public AWTEventListener[] getAWTEventListeners() { 2215 SecurityManager security = System.getSecurityManager(); 2216 if (security != null) { 2217 security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION); 2218 } 2219 synchronized (this) { 2220 EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class); 2221 2222 AWTEventListener[] ret = new AWTEventListener[la.length]; 2223 for (int i = 0; i < la.length; i++) { 2224 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i]; 2225 AWTEventListener tempL = sael.getListener(); 2226 //assert tempL is not an AWTEventListenerProxy - we should 2227 // have weeded them all out 2228 // don't want to wrap a proxy inside a proxy 2229 ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL); 2230 } 2231 return ret; 2232 } 2233 } 2234 2235 /** 2236 * Returns an array of all the <code>AWTEventListener</code>s 2237 * registered on this toolkit which listen to all of the event 2238 * types specified in the {@code eventMask} argument. 2239 * If there is a security manager, its {@code checkPermission} 2240 * method is called with an 2241 * {@code AWTPermission("listenToAllAWTEvents")} permission. 2242 * This may result in a SecurityException. 2243 * Listeners can be returned 2244 * within <code>AWTEventListenerProxy</code> objects, which also contain 2245 * the event mask for the given listener. 2246 * Note that listener objects 2247 * added multiple times appear only once in the returned array. 2248 * 2249 * @param eventMask the bitmask of event types to listen for 2250 * @return all of the <code>AWTEventListener</code>s registered 2251 * on this toolkit for the specified 2252 * event types, or an empty array if no such listeners 2253 * are currently registered 2254 * @throws SecurityException 2255 * if a security manager exists and its 2256 * <code>checkPermission</code> method doesn't allow the operation. 2257 * @see #addAWTEventListener 2258 * @see #removeAWTEventListener 2259 * @see SecurityManager#checkPermission 2260 * @see java.awt.AWTEvent 2261 * @see java.awt.AWTPermission 2262 * @see java.awt.event.AWTEventListener 2263 * @see java.awt.event.AWTEventListenerProxy 2264 * @since 1.4 2265 */ 2266 public AWTEventListener[] getAWTEventListeners(long eventMask) { 2267 SecurityManager security = System.getSecurityManager(); 2268 if (security != null) { 2269 security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION); 2270 } 2271 synchronized (this) { 2272 EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class); 2273 2274 java.util.List<AWTEventListenerProxy> list = new ArrayList<>(la.length); 2275 2276 for (int i = 0; i < la.length; i++) { 2277 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i]; 2278 if ((sael.getEventMask() & eventMask) == eventMask) { 2279 //AWTEventListener tempL = sael.getListener(); 2280 list.add(new AWTEventListenerProxy(sael.getEventMask(), 2281 sael.getListener())); 2282 } 2283 } 2284 return list.toArray(new AWTEventListener[0]); 2285 } 2286 } 2287 2288 /* 2289 * This method notifies any AWTEventListeners that an event 2290 * is about to be dispatched. 2291 * 2292 * @param theEvent the event which will be dispatched. 2293 */ 2294 void notifyAWTEventListeners(AWTEvent theEvent) { 2295 // This is a workaround for headless toolkits. It would be 2296 // better to override this method but it is declared package private. 2297 // "this instanceof" syntax defeats polymorphism. 2298 // --mm, 03/03/00 2299 if (this instanceof HeadlessToolkit) { 2300 ((HeadlessToolkit)this).getUnderlyingToolkit() 2301 .notifyAWTEventListeners(theEvent); 2302 return; 2303 } 2304 2305 AWTEventListener eventListener = this.eventListener; 2306 if (eventListener != null) { 2307 eventListener.eventDispatched(theEvent); 2308 } 2309 } 2310 2311 static private class ToolkitEventMulticaster extends AWTEventMulticaster 2312 implements AWTEventListener { 2313 // Implementation cloned from AWTEventMulticaster. 2314 2315 ToolkitEventMulticaster(AWTEventListener a, AWTEventListener b) { 2316 super(a, b); 2317 } 2318 2319 @SuppressWarnings("overloads") 2320 static AWTEventListener add(AWTEventListener a, 2321 AWTEventListener b) { 2322 if (a == null) return b; 2323 if (b == null) return a; 2324 return new ToolkitEventMulticaster(a, b); 2325 } 2326 2327 @SuppressWarnings("overloads") 2328 static AWTEventListener remove(AWTEventListener l, 2329 AWTEventListener oldl) { 2330 return (AWTEventListener) removeInternal(l, oldl); 2331 } 2332 2333 // #4178589: must overload remove(EventListener) to call our add() 2334 // instead of the static addInternal() so we allocate a 2335 // ToolkitEventMulticaster instead of an AWTEventMulticaster. 2336 // Note: this method is called by AWTEventListener.removeInternal(), 2337 // so its method signature must match AWTEventListener.remove(). 2338 protected EventListener remove(EventListener oldl) { 2339 if (oldl == a) return b; 2340 if (oldl == b) return a; 2341 AWTEventListener a2 = (AWTEventListener)removeInternal(a, oldl); 2342 AWTEventListener b2 = (AWTEventListener)removeInternal(b, oldl); 2343 if (a2 == a && b2 == b) { 2344 return this; // it's not here 2345 } 2346 return add(a2, b2); 2347 } 2348 2349 public void eventDispatched(AWTEvent event) { 2350 ((AWTEventListener)a).eventDispatched(event); 2351 ((AWTEventListener)b).eventDispatched(event); 2352 } 2353 } 2354 2355 private class SelectiveAWTEventListener implements AWTEventListener { 2356 AWTEventListener listener; 2357 private long eventMask; 2358 // This array contains the number of times to call the eventlistener 2359 // for each event type. 2360 int[] calls = new int[Toolkit.LONG_BITS]; 2361 2362 public AWTEventListener getListener() {return listener;} 2363 public long getEventMask() {return eventMask;} 2364 public int[] getCalls() {return calls;} 2365 2366 public void orEventMasks(long mask) { 2367 eventMask |= mask; 2368 // For each event bit set in mask, increment its call count. 2369 for (int i=0; i<Toolkit.LONG_BITS; i++) { 2370 // If no bits are set, break out of loop. 2371 if (mask == 0) { 2372 break; 2373 } 2374 if ((mask & 1L) != 0) { // Always test bit 0. 2375 calls[i]++; 2376 } 2377 mask >>>= 1; // Right shift, fill with zeros on left. 2378 } 2379 } 2380 2381 SelectiveAWTEventListener(AWTEventListener l, long mask) { 2382 listener = l; 2383 eventMask = mask; 2384 } 2385 2386 public void eventDispatched(AWTEvent event) { 2387 long eventBit = 0; // Used to save the bit of the event type. 2388 if (((eventBit = eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 && 2389 event.id >= ComponentEvent.COMPONENT_FIRST && 2390 event.id <= ComponentEvent.COMPONENT_LAST) 2391 || ((eventBit = eventMask & AWTEvent.CONTAINER_EVENT_MASK) != 0 && 2392 event.id >= ContainerEvent.CONTAINER_FIRST && 2393 event.id <= ContainerEvent.CONTAINER_LAST) 2394 || ((eventBit = eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0 && 2395 event.id >= FocusEvent.FOCUS_FIRST && 2396 event.id <= FocusEvent.FOCUS_LAST) 2397 || ((eventBit = eventMask & AWTEvent.KEY_EVENT_MASK) != 0 && 2398 event.id >= KeyEvent.KEY_FIRST && 2399 event.id <= KeyEvent.KEY_LAST) 2400 || ((eventBit = eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0 && 2401 event.id == MouseEvent.MOUSE_WHEEL) 2402 || ((eventBit = eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0 && 2403 (event.id == MouseEvent.MOUSE_MOVED || 2404 event.id == MouseEvent.MOUSE_DRAGGED)) 2405 || ((eventBit = eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0 && 2406 event.id != MouseEvent.MOUSE_MOVED && 2407 event.id != MouseEvent.MOUSE_DRAGGED && 2408 event.id != MouseEvent.MOUSE_WHEEL && 2409 event.id >= MouseEvent.MOUSE_FIRST && 2410 event.id <= MouseEvent.MOUSE_LAST) 2411 || ((eventBit = eventMask & AWTEvent.WINDOW_EVENT_MASK) != 0 && 2412 (event.id >= WindowEvent.WINDOW_FIRST && 2413 event.id <= WindowEvent.WINDOW_LAST)) 2414 || ((eventBit = eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 && 2415 event.id >= ActionEvent.ACTION_FIRST && 2416 event.id <= ActionEvent.ACTION_LAST) 2417 || ((eventBit = eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0 && 2418 event.id >= AdjustmentEvent.ADJUSTMENT_FIRST && 2419 event.id <= AdjustmentEvent.ADJUSTMENT_LAST) 2420 || ((eventBit = eventMask & AWTEvent.ITEM_EVENT_MASK) != 0 && 2421 event.id >= ItemEvent.ITEM_FIRST && 2422 event.id <= ItemEvent.ITEM_LAST) 2423 || ((eventBit = eventMask & AWTEvent.TEXT_EVENT_MASK) != 0 && 2424 event.id >= TextEvent.TEXT_FIRST && 2425 event.id <= TextEvent.TEXT_LAST) 2426 || ((eventBit = eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0 && 2427 event.id >= InputMethodEvent.INPUT_METHOD_FIRST && 2428 event.id <= InputMethodEvent.INPUT_METHOD_LAST) 2429 || ((eventBit = eventMask & AWTEvent.PAINT_EVENT_MASK) != 0 && 2430 event.id >= PaintEvent.PAINT_FIRST && 2431 event.id <= PaintEvent.PAINT_LAST) 2432 || ((eventBit = eventMask & AWTEvent.INVOCATION_EVENT_MASK) != 0 && 2433 event.id >= InvocationEvent.INVOCATION_FIRST && 2434 event.id <= InvocationEvent.INVOCATION_LAST) 2435 || ((eventBit = eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0 && 2436 event.id == HierarchyEvent.HIERARCHY_CHANGED) 2437 || ((eventBit = eventMask & AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK) != 0 && 2438 (event.id == HierarchyEvent.ANCESTOR_MOVED || 2439 event.id == HierarchyEvent.ANCESTOR_RESIZED)) 2440 || ((eventBit = eventMask & AWTEvent.WINDOW_STATE_EVENT_MASK) != 0 && 2441 event.id == WindowEvent.WINDOW_STATE_CHANGED) 2442 || ((eventBit = eventMask & AWTEvent.WINDOW_FOCUS_EVENT_MASK) != 0 && 2443 (event.id == WindowEvent.WINDOW_GAINED_FOCUS || 2444 event.id == WindowEvent.WINDOW_LOST_FOCUS)) 2445 || ((eventBit = eventMask & sun.awt.SunToolkit.GRAB_EVENT_MASK) != 0 && 2446 (event instanceof sun.awt.UngrabEvent))) { 2447 // Get the index of the call count for this event type. 2448 // Instead of using Math.log(...) we will calculate it with 2449 // bit shifts. That's what previous implementation looked like: 2450 // 2451 // int ci = (int) (Math.log(eventBit)/Math.log(2)); 2452 int ci = 0; 2453 for (long eMask = eventBit; eMask != 0; eMask >>>= 1, ci++) { 2454 } 2455 ci--; 2456 // Call the listener as many times as it was added for this 2457 // event type. 2458 for (int i=0; i<calls[ci]; i++) { 2459 listener.eventDispatched(event); 2460 } 2461 } 2462 } 2463 } 2464 2465 /** 2466 * Returns a map of visual attributes for the abstract level description 2467 * of the given input method highlight, or null if no mapping is found. 2468 * The style field of the input method highlight is ignored. The map 2469 * returned is unmodifiable. 2470 * @param highlight input method highlight 2471 * @return style attribute map, or <code>null</code> 2472 * @exception HeadlessException if 2473 * <code>GraphicsEnvironment.isHeadless</code> returns true 2474 * @see java.awt.GraphicsEnvironment#isHeadless 2475 * @since 1.3 2476 */ 2477 public abstract Map<java.awt.font.TextAttribute,?> 2478 mapInputMethodHighlight(InputMethodHighlight highlight) 2479 throws HeadlessException; 2480 2481 private static PropertyChangeSupport createPropertyChangeSupport(Toolkit toolkit) { 2482 if (toolkit instanceof SunToolkit || toolkit instanceof HeadlessToolkit) { 2483 return new DesktopPropertyChangeSupport(toolkit); 2484 } else { 2485 return new PropertyChangeSupport(toolkit); 2486 } 2487 } 2488 2489 @SuppressWarnings("serial") 2490 private static class DesktopPropertyChangeSupport extends PropertyChangeSupport { 2491 2492 private static final StringBuilder PROP_CHANGE_SUPPORT_KEY = 2493 new StringBuilder("desktop property change support key"); 2494 private final Object source; 2495 2496 public DesktopPropertyChangeSupport(Object sourceBean) { 2497 super(sourceBean); 2498 source = sourceBean; 2499 } 2500 2501 @Override 2502 public synchronized void addPropertyChangeListener( 2503 String propertyName, 2504 PropertyChangeListener listener) 2505 { 2506 PropertyChangeSupport pcs = (PropertyChangeSupport) 2507 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2508 if (null == pcs) { 2509 pcs = new PropertyChangeSupport(source); 2510 AppContext.getAppContext().put(PROP_CHANGE_SUPPORT_KEY, pcs); 2511 } 2512 pcs.addPropertyChangeListener(propertyName, listener); 2513 } 2514 2515 @Override 2516 public synchronized void removePropertyChangeListener( 2517 String propertyName, 2518 PropertyChangeListener listener) 2519 { 2520 PropertyChangeSupport pcs = (PropertyChangeSupport) 2521 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2522 if (null != pcs) { 2523 pcs.removePropertyChangeListener(propertyName, listener); 2524 } 2525 } 2526 2527 @Override 2528 public synchronized PropertyChangeListener[] getPropertyChangeListeners() 2529 { 2530 PropertyChangeSupport pcs = (PropertyChangeSupport) 2531 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2532 if (null != pcs) { 2533 return pcs.getPropertyChangeListeners(); 2534 } else { 2535 return new PropertyChangeListener[0]; 2536 } 2537 } 2538 2539 @Override 2540 public synchronized PropertyChangeListener[] getPropertyChangeListeners(String propertyName) 2541 { 2542 PropertyChangeSupport pcs = (PropertyChangeSupport) 2543 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2544 if (null != pcs) { 2545 return pcs.getPropertyChangeListeners(propertyName); 2546 } else { 2547 return new PropertyChangeListener[0]; 2548 } 2549 } 2550 2551 @Override 2552 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { 2553 PropertyChangeSupport pcs = (PropertyChangeSupport) 2554 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2555 if (null == pcs) { 2556 pcs = new PropertyChangeSupport(source); 2557 AppContext.getAppContext().put(PROP_CHANGE_SUPPORT_KEY, pcs); 2558 } 2559 pcs.addPropertyChangeListener(listener); 2560 } 2561 2562 @Override 2563 public synchronized void removePropertyChangeListener(PropertyChangeListener listener) { 2564 PropertyChangeSupport pcs = (PropertyChangeSupport) 2565 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2566 if (null != pcs) { 2567 pcs.removePropertyChangeListener(listener); 2568 } 2569 } 2570 2571 /* 2572 * we do expect that all other fireXXX() methods of java.beans.PropertyChangeSupport 2573 * use this method. If this will be changed we will need to change this class. 2574 */ 2575 @Override 2576 public void firePropertyChange(final PropertyChangeEvent evt) { 2577 Object oldValue = evt.getOldValue(); 2578 Object newValue = evt.getNewValue(); 2579 String propertyName = evt.getPropertyName(); 2580 if (oldValue != null && newValue != null && oldValue.equals(newValue)) { 2581 return; 2582 } 2583 Runnable updater = new Runnable() { 2584 public void run() { 2585 PropertyChangeSupport pcs = (PropertyChangeSupport) 2586 AppContext.getAppContext().get(PROP_CHANGE_SUPPORT_KEY); 2587 if (null != pcs) { 2588 pcs.firePropertyChange(evt); 2589 } 2590 } 2591 }; 2592 final AppContext currentAppContext = AppContext.getAppContext(); 2593 for (AppContext appContext : AppContext.getAppContexts()) { 2594 if (null == appContext || appContext.isDisposed()) { 2595 continue; 2596 } 2597 if (currentAppContext == appContext) { 2598 updater.run(); 2599 } else { 2600 final PeerEvent e = new PeerEvent(source, updater, PeerEvent.ULTIMATE_PRIORITY_EVENT); 2601 SunToolkit.postEvent(appContext, e); 2602 } 2603 } 2604 } 2605 } 2606 2607 /** 2608 * Reports whether events from extra mouse buttons are allowed to be processed and posted into 2609 * {@code EventQueue}. 2610 * <br> 2611 * To change the returned value it is necessary to set the {@code sun.awt.enableExtraMouseButtons} 2612 * property before the {@code Toolkit} class initialization. This setting could be done on the application 2613 * startup by the following command: 2614 * <pre> 2615 * java -Dsun.awt.enableExtraMouseButtons=false Application 2616 * </pre> 2617 * Alternatively, the property could be set in the application by using the following code: 2618 * <pre> 2619 * System.setProperty("sun.awt.enableExtraMouseButtons", "true"); 2620 * </pre> 2621 * before the {@code Toolkit} class initialization. 2622 * If not set by the time of the {@code Toolkit} class initialization, this property will be 2623 * initialized with {@code true}. 2624 * Changing this value after the {@code Toolkit} class initialization will have no effect. 2625 * 2626 * @exception HeadlessException if GraphicsEnvironment.isHeadless() returns true 2627 * @return {@code true} if events from extra mouse buttons are allowed to be processed and posted; 2628 * {@code false} otherwise 2629 * @see System#getProperty(String propertyName) 2630 * @see System#setProperty(String propertyName, String value) 2631 * @see java.awt.EventQueue 2632 * @since 1.7 2633 */ 2634 public boolean areExtraMouseButtonsEnabled() throws HeadlessException { 2635 GraphicsEnvironment.checkHeadless(); 2636 2637 return Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled(); 2638 } 2639 }