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