< prev index next >

src/java.desktop/share/classes/java/awt/Toolkit.java

Print this page




  52 
  53 import sun.awt.AWTAccessor;
  54 import sun.awt.AWTPermissions;
  55 import sun.awt.AppContext;
  56 import sun.awt.HeadlessToolkit;
  57 import sun.awt.PeerEvent;
  58 import sun.awt.SunToolkit;
  59 import sun.util.CoreResourceBundleControl;
  60 
  61 import java.security.AccessController;
  62 import java.security.PrivilegedAction;
  63 import java.util.Arrays;
  64 import java.util.ServiceLoader;
  65 import java.util.Set;
  66 import java.util.stream.Collectors;
  67 import javax.accessibility.AccessibilityProvider;
  68 
  69 /**
  70  * This class is the abstract superclass of all actual
  71  * implementations of the Abstract Window Toolkit. Subclasses of
  72  * the <code>Toolkit</code> class are used to bind the various components
  73  * to particular native toolkit implementations.
  74  * <p>
  75  * Many GUI events may be delivered to user
  76  * asynchronously, if the opposite is not specified explicitly.
  77  * As well as
  78  * many GUI operations may be performed asynchronously.
  79  * This fact means that if the state of a component is set, and then
  80  * the state immediately queried, the returned value may not yet
  81  * reflect the requested change.  This behavior includes, but is not
  82  * limited to:
  83  * <ul>
  84  * <li>Scrolling to a specified position.
  85  * <br>For example, calling <code>ScrollPane.setScrollPosition</code>
  86  *     and then <code>getScrollPosition</code> may return an incorrect
  87  *     value if the original request has not yet been processed.
  88  *
  89  * <li>Moving the focus from one component to another.
  90  * <br>For more information, see
  91  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html#transferTiming">Timing
  92  * Focus Transfers</a>, a section in
  93  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing
  94  * Tutorial</a>.
  95  *
  96  * <li>Making a top-level container visible.
  97  * <br>Calling <code>setVisible(true)</code> on a <code>Window</code>,
  98  *     <code>Frame</code> or <code>Dialog</code> may occur
  99  *     asynchronously.
 100  *
 101  * <li>Setting the size or location of a top-level container.
 102  * <br>Calls to <code>setSize</code>, <code>setBounds</code> or
 103  *     <code>setLocation</code> on a <code>Window</code>,
 104  *     <code>Frame</code> or <code>Dialog</code> are forwarded
 105  *     to the underlying window management system and may be
 106  *     ignored or modified.  See {@link java.awt.Window} for
 107  *     more information.
 108  * </ul>
 109  * <p>
 110  * Most applications should not call any of the methods in this
 111  * class directly. The methods defined by <code>Toolkit</code> are
 112  * the "glue" that joins the platform-independent classes in the
 113  * <code>java.awt</code> package with their counterparts in
 114  * <code>java.awt.peer</code>. Some methods defined by
 115  * <code>Toolkit</code> query the native operating system directly.
 116  *
 117  * @author      Sami Shaio
 118  * @author      Arthur van Hoff
 119  * @author      Fred Ecks
 120  * @since       1.0
 121  */
 122 public abstract class Toolkit {
 123 
 124     // The following method is called by the private method
 125     // <code>updateSystemColors</code> in <code>SystemColor</code>.
 126 
 127     /**
 128      * Fills in the integer array that is supplied as an argument
 129      * with the current system color values.
 130      *
 131      * @param     systemColors an integer array.
 132      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 133      * returns true
 134      * @see       java.awt.GraphicsEnvironment#isHeadless
 135      * @since     1.1


 230      * @see       #setDynamicLayout(boolean dynamic)
 231      * @see       #isDynamicLayoutSet()
 232      * @see       #getDesktopProperty(String propertyName)
 233      * @see       java.awt.GraphicsEnvironment#isHeadless
 234      * @since     1.4
 235      */
 236     public boolean isDynamicLayoutActive()
 237         throws HeadlessException {
 238         GraphicsEnvironment.checkHeadless();
 239 
 240         if (this != Toolkit.getDefaultToolkit()) {
 241             return Toolkit.getDefaultToolkit().isDynamicLayoutActive();
 242         } else {
 243             return false;
 244         }
 245     }
 246 
 247     /**
 248      * Gets the size of the screen.  On systems with multiple displays, the
 249      * primary display is used.  Multi-screen aware display dimensions are
 250      * available from <code>GraphicsConfiguration</code> and
 251      * <code>GraphicsDevice</code>.
 252      * @return    the size of this toolkit's screen, in pixels.
 253      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 254      * returns true
 255      * @see       java.awt.GraphicsConfiguration#getBounds
 256      * @see       java.awt.GraphicsDevice#getDisplayMode
 257      * @see       java.awt.GraphicsEnvironment#isHeadless
 258      */
 259     public abstract Dimension getScreenSize()
 260         throws HeadlessException;
 261 
 262     /**
 263      * Returns the screen resolution in dots-per-inch.
 264      * @return    this toolkit's screen resolution, in dots-per-inch.
 265      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 266      * returns true
 267      * @see       java.awt.GraphicsEnvironment#isHeadless
 268      */
 269     public abstract int getScreenResolution()
 270         throws HeadlessException;
 271 
 272     /**
 273      * Gets the insets of the screen.
 274      * @param     gc a <code>GraphicsConfiguration</code>
 275      * @return    the insets of this toolkit's screen, in pixels.
 276      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 277      * returns true
 278      * @see       java.awt.GraphicsEnvironment#isHeadless
 279      * @since     1.4
 280      */
 281     public Insets getScreenInsets(GraphicsConfiguration gc)
 282         throws HeadlessException {
 283         GraphicsEnvironment.checkHeadless();
 284         if (this != Toolkit.getDefaultToolkit()) {
 285             return Toolkit.getDefaultToolkit().getScreenInsets(gc);
 286         } else {
 287             return new Insets(0, 0, 0, 0);
 288         }
 289     }
 290 
 291     /**
 292      * Determines the color model of this toolkit's screen.
 293      * <p>
 294      * <code>ColorModel</code> is an abstract class that
 295      * encapsulates the ability to translate between the
 296      * pixel values of an image and its red, green, blue,
 297      * and alpha components.
 298      * <p>
 299      * This toolkit method is called by the
 300      * <code>getColorModel</code> method
 301      * of the <code>Component</code> class.
 302      * @return    the color model of this toolkit's screen.
 303      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 304      * returns true
 305      * @see       java.awt.GraphicsEnvironment#isHeadless
 306      * @see       java.awt.image.ColorModel
 307      * @see       java.awt.Component#getColorModel
 308      */
 309     public abstract ColorModel getColorModel()
 310         throws HeadlessException;
 311 
 312     /**
 313      * Returns the names of the available fonts in this toolkit.<p>
 314      * For 1.1, the following font names are deprecated (the replacement
 315      * name follows):
 316      * <ul>
 317      * <li>TimesRoman (use Serif)
 318      * <li>Helvetica (use SansSerif)
 319      * <li>Courier (use Monospaced)
 320      * </ul><p>
 321      * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
 322      * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
 323      * those characters.
 324      * @return    the names of the available fonts in this toolkit.
 325      * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
 326      * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
 327      */
 328     @Deprecated
 329     public abstract String[] getFontList();
 330 
 331     /**
 332      * Gets the screen device metrics for rendering of the font.
 333      * @param     font   a font
 334      * @return    the screen metrics of the specified font in this toolkit
 335      * @deprecated  As of JDK version 1.2, replaced by the <code>Font</code>
 336      *          method <code>getLineMetrics</code>.
 337      * @see java.awt.font.LineMetrics
 338      * @see java.awt.Font#getLineMetrics
 339      * @see java.awt.GraphicsEnvironment#getScreenDevices
 340      */
 341     @Deprecated
 342     public abstract FontMetrics getFontMetrics(Font font);
 343 
 344     /**
 345      * Synchronizes this toolkit's graphics state. Some window systems
 346      * may do buffering of graphics events.
 347      * <p>
 348      * This method ensures that the display is up-to-date. It is useful
 349      * for animation.
 350      */
 351     public abstract void sync();
 352 
 353     /**
 354      * The default toolkit.
 355      */
 356     private static Toolkit toolkit;


 589                     } catch (final IllegalAccessException ignored) {
 590                         throw new AWTError("Could not access Toolkit: " + nm);
 591                     }
 592                     return null;
 593                 }
 594             });
 595             if (!GraphicsEnvironment.isHeadless()) {
 596                 loadAssistiveTechnologies();
 597             }
 598         }
 599         return toolkit;
 600     }
 601 
 602     /**
 603      * Returns an image which gets pixel data from the specified file,
 604      * whose format can be either GIF, JPEG or PNG.
 605      * The underlying toolkit attempts to resolve multiple requests
 606      * with the same filename to the same returned Image.
 607      * <p>
 608      * Since the mechanism required to facilitate this sharing of
 609      * <code>Image</code> objects may continue to hold onto images
 610      * that are no longer in use for an indefinite period of time,
 611      * developers are encouraged to implement their own caching of
 612      * images by using the {@link #createImage(java.lang.String) createImage}
 613      * variant wherever available.
 614      * If the image data contained in the specified file changes,
 615      * the <code>Image</code> object returned from this method may
 616      * still contain stale information which was loaded from the
 617      * file after a prior call.
 618      * Previously loaded image data can be manually discarded by
 619      * calling the {@link Image#flush flush} method on the
 620      * returned <code>Image</code>.
 621      * <p>
 622      * This method first checks if there is a security manager installed.
 623      * If so, the method calls the security manager's
 624      * <code>checkRead</code> method with the file specified to ensure
 625      * that the access to the image is allowed.
 626      * @param     filename   the name of a file containing pixel data
 627      *                         in a recognized file format.
 628      * @return    an image which gets its pixel data from
 629      *                         the specified file.
 630      * @throws SecurityException  if a security manager exists and its
 631      *                            checkRead method doesn't allow the operation.
 632      * @see #createImage(java.lang.String)
 633      */
 634     public abstract Image getImage(String filename);
 635 
 636     /**
 637      * Returns an image which gets pixel data from the specified URL.
 638      * The pixel data referenced by the specified URL must be in one
 639      * of the following formats: GIF, JPEG or PNG.
 640      * The underlying toolkit attempts to resolve multiple requests
 641      * with the same URL to the same returned Image.
 642      * <p>
 643      * Since the mechanism required to facilitate this sharing of
 644      * <code>Image</code> objects may continue to hold onto images
 645      * that are no longer in use for an indefinite period of time,
 646      * developers are encouraged to implement their own caching of
 647      * images by using the {@link #createImage(java.net.URL) createImage}
 648      * variant wherever available.
 649      * If the image data stored at the specified URL changes,
 650      * the <code>Image</code> object returned from this method may
 651      * still contain stale information which was fetched from the
 652      * URL after a prior call.
 653      * Previously loaded image data can be manually discarded by
 654      * calling the {@link Image#flush flush} method on the
 655      * returned <code>Image</code>.
 656      * <p>
 657      * This method first checks if there is a security manager installed.
 658      * If so, the method calls the security manager's
 659      * <code>checkPermission</code> method with the
 660      * url.openConnection().getPermission() permission to ensure
 661      * that the access to the image is allowed. For compatibility
 662      * with pre-1.2 security managers, if the access is denied with
 663      * <code>FilePermission</code> or <code>SocketPermission</code>,
 664      * the method throws the <code>SecurityException</code>
 665      * if the corresponding 1.1-style SecurityManager.checkXXX method
 666      * also denies permission.
 667      * @param     url   the URL to use in fetching the pixel data.
 668      * @return    an image which gets its pixel data from
 669      *                         the specified URL.
 670      * @throws SecurityException  if a security manager exists and its
 671      *                            checkPermission method doesn't allow
 672      *                            the operation.
 673      * @see #createImage(java.net.URL)
 674      */
 675     public abstract Image getImage(URL url);
 676 
 677     /**
 678      * Returns an image which gets pixel data from the specified file.
 679      * The returned Image is a new object which will not be shared
 680      * with any other caller of this method or its getImage variant.
 681      * <p>
 682      * This method first checks if there is a security manager installed.
 683      * If so, the method calls the security manager's
 684      * <code>checkRead</code> method with the specified file to ensure
 685      * that the image creation is allowed.
 686      * @param     filename   the name of a file containing pixel data
 687      *                         in a recognized file format.
 688      * @return    an image which gets its pixel data from
 689      *                         the specified file.
 690      * @throws SecurityException  if a security manager exists and its
 691      *                            checkRead method doesn't allow the operation.
 692      * @see #getImage(java.lang.String)
 693      */
 694     public abstract Image createImage(String filename);
 695 
 696     /**
 697      * Returns an image which gets pixel data from the specified URL.
 698      * The returned Image is a new object which will not be shared
 699      * with any other caller of this method or its getImage variant.
 700      * <p>
 701      * This method first checks if there is a security manager installed.
 702      * If so, the method calls the security manager's
 703      * <code>checkPermission</code> method with the
 704      * url.openConnection().getPermission() permission to ensure
 705      * that the image creation is allowed. For compatibility
 706      * with pre-1.2 security managers, if the access is denied with
 707      * <code>FilePermission</code> or <code>SocketPermission</code>,
 708      * the method throws <code>SecurityException</code>
 709      * if the corresponding 1.1-style SecurityManager.checkXXX method
 710      * also denies permission.
 711      * @param     url   the URL to use in fetching the pixel data.
 712      * @return    an image which gets its pixel data from
 713      *                         the specified URL.
 714      * @throws SecurityException  if a security manager exists and its
 715      *                            checkPermission method doesn't allow
 716      *                            the operation.
 717      * @see #getImage(java.net.URL)
 718      */
 719     public abstract Image createImage(URL url);
 720 
 721     /**
 722      * Prepares an image for rendering.
 723      * <p>
 724      * If the values of the width and height arguments are both
 725      * <code>-1</code>, this method prepares the image for rendering
 726      * on the default screen; otherwise, this method prepares an image
 727      * for rendering on the default screen at the specified width and height.
 728      * <p>
 729      * The image data is downloaded asynchronously in another thread,
 730      * and an appropriately scaled screen representation of the image is
 731      * generated.
 732      * <p>
 733      * This method is called by components <code>prepareImage</code>
 734      * methods.
 735      * <p>
 736      * Information on the flags returned by this method can be found
 737      * with the definition of the <code>ImageObserver</code> interface.
 738 
 739      * @param     image      the image for which to prepare a
 740      *                           screen representation.
 741      * @param     width      the width of the desired screen
 742      *                           representation, or <code>-1</code>.
 743      * @param     height     the height of the desired screen
 744      *                           representation, or <code>-1</code>.
 745      * @param     observer   the <code>ImageObserver</code>
 746      *                           object to be notified as the
 747      *                           image is being prepared.
 748      * @return    <code>true</code> if the image has already been
 749      *                 fully prepared; <code>false</code> otherwise.
 750      * @see       java.awt.Component#prepareImage(java.awt.Image,
 751      *                 java.awt.image.ImageObserver)
 752      * @see       java.awt.Component#prepareImage(java.awt.Image,
 753      *                 int, int, java.awt.image.ImageObserver)
 754      * @see       java.awt.image.ImageObserver
 755      */
 756     public abstract boolean prepareImage(Image image, int width, int height,
 757                                          ImageObserver observer);
 758 
 759     /**
 760      * Indicates the construction status of a specified image that is
 761      * being prepared for display.
 762      * <p>
 763      * If the values of the width and height arguments are both
 764      * <code>-1</code>, this method returns the construction status of
 765      * a screen representation of the specified image in this toolkit.
 766      * Otherwise, this method returns the construction status of a
 767      * scaled representation of the image at the specified width
 768      * and height.
 769      * <p>
 770      * This method does not cause the image to begin loading.
 771      * An application must call <code>prepareImage</code> to force
 772      * the loading of an image.
 773      * <p>
 774      * This method is called by the component's <code>checkImage</code>
 775      * methods.
 776      * <p>
 777      * Information on the flags returned by this method can be found
 778      * with the definition of the <code>ImageObserver</code> interface.
 779      * @param     image   the image whose status is being checked.
 780      * @param     width   the width of the scaled version whose status is
 781      *                 being checked, or <code>-1</code>.
 782      * @param     height  the height of the scaled version whose status
 783      *                 is being checked, or <code>-1</code>.
 784      * @param     observer   the <code>ImageObserver</code> object to be
 785      *                 notified as the image is being prepared.
 786      * @return    the bitwise inclusive <strong>OR</strong> of the
 787      *                 <code>ImageObserver</code> flags for the
 788      *                 image data that is currently available.
 789      * @see       java.awt.Toolkit#prepareImage(java.awt.Image,
 790      *                 int, int, java.awt.image.ImageObserver)
 791      * @see       java.awt.Component#checkImage(java.awt.Image,
 792      *                 java.awt.image.ImageObserver)
 793      * @see       java.awt.Component#checkImage(java.awt.Image,
 794      *                 int, int, java.awt.image.ImageObserver)
 795      * @see       java.awt.image.ImageObserver
 796      */
 797     public abstract int checkImage(Image image, int width, int height,
 798                                    ImageObserver observer);
 799 
 800     /**
 801      * Creates an image with the specified image producer.
 802      * @param     producer the image producer to be used.
 803      * @return    an image with the specified image producer.
 804      * @see       java.awt.Image
 805      * @see       java.awt.image.ImageProducer
 806      * @see       java.awt.Component#createImage(java.awt.image.ImageProducer)
 807      */


 823     }
 824 
 825     /**
 826      * Creates an image which decodes the image stored in the specified
 827      * byte array, and at the specified offset and length.
 828      * The data must be in some image format, such as GIF or JPEG,
 829      * that is supported by this toolkit.
 830      * @param     imagedata   an array of bytes, representing
 831      *                         image data in a supported image format.
 832      * @param     imageoffset  the offset of the beginning
 833      *                         of the data in the array.
 834      * @param     imagelength  the length of the data in the array.
 835      * @return    an image.
 836      * @since     1.1
 837      */
 838     public abstract Image createImage(byte[] imagedata,
 839                                       int imageoffset,
 840                                       int imagelength);
 841 
 842     /**
 843      * Gets a <code>PrintJob</code> object which is the result of initiating
 844      * a print operation on the toolkit's platform.
 845      * <p>
 846      * Each actual implementation of this method should first check if there
 847      * is a security manager installed. If there is, the method should call
 848      * the security manager's <code>checkPrintJobAccess</code> method to
 849      * ensure initiation of a print operation is allowed. If the default
 850      * implementation of <code>checkPrintJobAccess</code> is used (that is,
 851      * that method is not overriden), then this results in a call to the
 852      * security manager's <code>checkPermission</code> method with a <code>
 853      * RuntimePermission("queuePrintJob")</code> permission.
 854      *
 855      * @param   frame the parent of the print dialog. May not be null.
 856      * @param   jobtitle the title of the PrintJob. A null title is equivalent
 857      *          to "".
 858      * @param   props a Properties object containing zero or more properties.
 859      *          Properties are not standardized and are not consistent across
 860      *          implementations. Because of this, PrintJobs which require job
 861      *          and page control should use the version of this function which
 862      *          takes JobAttributes and PageAttributes objects. This object
 863      *          may be updated to reflect the user's job choices on exit. May
 864      *          be null.
 865      * @return  a <code>PrintJob</code> object, or <code>null</code> if the
 866      *          user cancelled the print job.
 867      * @throws  NullPointerException if frame is null
 868      * @throws  SecurityException if this thread is not allowed to initiate a
 869      *          print job request
 870      * @see     java.awt.GraphicsEnvironment#isHeadless
 871      * @see     java.awt.PrintJob
 872      * @see     java.lang.RuntimePermission
 873      * @since   1.1
 874      */
 875     public abstract PrintJob getPrintJob(Frame frame, String jobtitle,
 876                                          Properties props);
 877 
 878     /**
 879      * Gets a <code>PrintJob</code> object which is the result of initiating
 880      * a print operation on the toolkit's platform.
 881      * <p>
 882      * Each actual implementation of this method should first check if there
 883      * is a security manager installed. If there is, the method should call
 884      * the security manager's <code>checkPrintJobAccess</code> method to
 885      * ensure initiation of a print operation is allowed. If the default
 886      * implementation of <code>checkPrintJobAccess</code> is used (that is,
 887      * that method is not overriden), then this results in a call to the
 888      * security manager's <code>checkPermission</code> method with a <code>
 889      * RuntimePermission("queuePrintJob")</code> permission.
 890      *
 891      * @param   frame the parent of the print dialog. May not be null.
 892      * @param   jobtitle the title of the PrintJob. A null title is equivalent
 893      *          to "".
 894      * @param   jobAttributes a set of job attributes which will control the
 895      *          PrintJob. The attributes will be updated to reflect the user's
 896      *          choices as outlined in the JobAttributes documentation. May be
 897      *          null.
 898      * @param   pageAttributes a set of page attributes which will control the
 899      *          PrintJob. The attributes will be applied to every page in the
 900      *          job. The attributes will be updated to reflect the user's
 901      *          choices as outlined in the PageAttributes documentation. May be
 902      *          null.
 903      * @return  a <code>PrintJob</code> object, or <code>null</code> if the
 904      *          user cancelled the print job.
 905      * @throws  NullPointerException if frame is null
 906      * @throws  IllegalArgumentException if pageAttributes specifies differing
 907      *          cross feed and feed resolutions. Also if this thread has
 908      *          access to the file system and jobAttributes specifies
 909      *          print to file, and the specified destination file exists but
 910      *          is a directory rather than a regular file, does not exist but
 911      *          cannot be created, or cannot be opened for any other reason.
 912      *          However in the case of print to file, if a dialog is also
 913      *          requested to be displayed then the user will be given an
 914      *          opportunity to select a file and proceed with printing.
 915      *          The dialog will ensure that the selected output file
 916      *          is valid before returning from this method.
 917      * @throws  SecurityException if this thread is not allowed to initiate a
 918      *          print job request, or if jobAttributes specifies print to file,
 919      *          and this thread is not allowed to access the file system
 920      * @see     java.awt.PrintJob
 921      * @see     java.awt.GraphicsEnvironment#isHeadless
 922      * @see     java.lang.RuntimePermission
 923      * @see     java.awt.JobAttributes


 935                                                            pageAttributes);
 936         } else {
 937             return getPrintJob(frame, jobtitle, null);
 938         }
 939     }
 940 
 941     /**
 942      * Emits an audio beep depending on native system settings and hardware
 943      * capabilities.
 944      * @since     1.1
 945      */
 946     public abstract void beep();
 947 
 948     /**
 949      * Gets the singleton instance of the system Clipboard which interfaces
 950      * with clipboard facilities provided by the native platform. This
 951      * clipboard enables data transfer between Java programs and native
 952      * applications which use native clipboard facilities.
 953      * <p>
 954      * In addition to any and all default formats text returned by the system
 955      * Clipboard's <code>getTransferData()</code> method is available in the
 956      * following flavors:
 957      * <ul>
 958      * <li>DataFlavor.stringFlavor</li>
 959      * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li>
 960      * </ul>
 961      * As with <code>java.awt.datatransfer.StringSelection</code>, if the
 962      * requested flavor is <code>DataFlavor.plainTextFlavor</code>, or an
 963      * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of
 964      * the system Clipboard's <code>getTransferData()</code> method for <code>
 965      * DataFlavor.plainTextFlavor</code>, and equivalent DataFlavors, is
 966      * inconsistent with the definition of <code>DataFlavor.plainTextFlavor
 967      * </code>. Because of this, support for <code>
 968      * DataFlavor.plainTextFlavor</code>, and equivalent flavors, is
 969      * <b>deprecated</b>.
 970      * <p>
 971      * Each actual implementation of this method should first check if there
 972      * is a security manager installed. If there is, the method should call
 973      * the security manager's {@link SecurityManager#checkPermission
 974      * checkPermission} method to check {@code AWTPermission("accessClipboard")}.
 975      *
 976      * @return    the system Clipboard
 977      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 978      * returns true
 979      * @see       java.awt.GraphicsEnvironment#isHeadless
 980      * @see       java.awt.datatransfer.Clipboard
 981      * @see       java.awt.datatransfer.StringSelection
 982      * @see       java.awt.datatransfer.DataFlavor#stringFlavor
 983      * @see       java.awt.datatransfer.DataFlavor#plainTextFlavor
 984      * @see       java.io.Reader
 985      * @see       java.awt.AWTPermission
 986      * @since     1.1
 987      */
 988     public abstract Clipboard getSystemClipboard()
 989         throws HeadlessException;
 990 
 991     /**
 992      * Gets the singleton instance of the system selection as a
 993      * <code>Clipboard</code> object. This allows an application to read and
 994      * modify the current, system-wide selection.
 995      * <p>
 996      * An application is responsible for updating the system selection whenever
 997      * the user selects text, using either the mouse or the keyboard.
 998      * Typically, this is implemented by installing a
 999      * <code>FocusListener</code> on all <code>Component</code>s which support
1000      * text selection, and, between <code>FOCUS_GAINED</code> and
1001      * <code>FOCUS_LOST</code> events delivered to that <code>Component</code>,
1002      * updating the system selection <code>Clipboard</code> when the selection
1003      * changes inside the <code>Component</code>. Properly updating the system
1004      * selection ensures that a Java application will interact correctly with
1005      * native applications and other Java applications running simultaneously
1006      * on the system. Note that <code>java.awt.TextComponent</code> and
1007      * <code>javax.swing.text.JTextComponent</code> already adhere to this
1008      * policy. When using these classes, and their subclasses, developers need
1009      * not write any additional code.
1010      * <p>
1011      * Some platforms do not support a system selection <code>Clipboard</code>.
1012      * On those platforms, this method will return <code>null</code>. In such a
1013      * case, an application is absolved from its responsibility to update the
1014      * system selection <code>Clipboard</code> as described above.
1015      * <p>
1016      * Each actual implementation of this method should first check if there
1017      * is a security manager installed. If there is, the method should call
1018      * the security manager's {@link SecurityManager#checkPermission
1019      * checkPermission} method to check {@code AWTPermission("accessClipboard")}.
1020      *
1021      * @return the system selection as a <code>Clipboard</code>, or
1022      *         <code>null</code> if the native platform does not support a
1023      *         system selection <code>Clipboard</code>
1024      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1025      *            returns true
1026      *
1027      * @see java.awt.datatransfer.Clipboard
1028      * @see java.awt.event.FocusListener
1029      * @see java.awt.event.FocusEvent#FOCUS_GAINED
1030      * @see java.awt.event.FocusEvent#FOCUS_LOST
1031      * @see TextComponent
1032      * @see javax.swing.text.JTextComponent
1033      * @see AWTPermission
1034      * @see GraphicsEnvironment#isHeadless
1035      * @since 1.4
1036      */
1037     public Clipboard getSystemSelection() throws HeadlessException {
1038         GraphicsEnvironment.checkHeadless();
1039 
1040         if (this != Toolkit.getDefaultToolkit()) {
1041             return Toolkit.getDefaultToolkit().getSystemSelection();
1042         } else {
1043             GraphicsEnvironment.checkHeadless();
1044             return null;
1045         }
1046     }
1047 
1048     /**
1049      * Determines which modifier key is the appropriate accelerator
1050      * key for menu shortcuts.
1051      * <p>
1052      * Menu shortcuts, which are embodied in the
1053      * <code>MenuShortcut</code> class, are handled by the
1054      * <code>MenuBar</code> class.
1055      * <p>
1056      * By default, this method returns <code>Event.CTRL_MASK</code>.
1057      * Toolkit implementations should override this method if the
1058      * <b>Control</b> key isn't the correct key for accelerators.
1059      * @return    the modifier mask on the <code>Event</code> class
1060      *                 that is used for menu shortcuts on this toolkit.
1061      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1062      * returns true
1063      * @see       java.awt.GraphicsEnvironment#isHeadless
1064      * @see       java.awt.MenuBar
1065      * @see       java.awt.MenuShortcut
1066      * @since     1.1
1067      */
1068     public int getMenuShortcutKeyMask() throws HeadlessException {
1069         GraphicsEnvironment.checkHeadless();
1070 
1071         return Event.CTRL_MASK;
1072     }
1073 
1074     /**
1075      * Returns whether the given locking key on the keyboard is currently in
1076      * its "on" state.
1077      * Valid key codes are
1078      * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
1079      * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
1080      * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
1081      * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
1082      *
1083      * @param  keyCode the key code
1084      * @return {@code true} if the given key is currently in its "on" state;
1085      *          otherwise {@code false}
1086      * @exception java.lang.IllegalArgumentException if <code>keyCode</code>
1087      * is not one of the valid key codes
1088      * @exception java.lang.UnsupportedOperationException if the host system doesn't
1089      * allow getting the state of this key programmatically, or if the keyboard
1090      * doesn't have this key
1091      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1092      * returns true
1093      * @see       java.awt.GraphicsEnvironment#isHeadless
1094      * @since 1.3
1095      */
1096     public boolean getLockingKeyState(int keyCode)
1097         throws UnsupportedOperationException
1098     {
1099         GraphicsEnvironment.checkHeadless();
1100 
1101         if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
1102                keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
1103             throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
1104         }
1105         throw new UnsupportedOperationException("Toolkit.getLockingKeyState");
1106     }
1107 
1108     /**
1109      * Sets the state of the given locking key on the keyboard.
1110      * Valid key codes are
1111      * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
1112      * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
1113      * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
1114      * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
1115      * <p>
1116      * Depending on the platform, setting the state of a locking key may
1117      * involve event processing and therefore may not be immediately
1118      * observable through getLockingKeyState.
1119      *
1120      * @param  keyCode the key code
1121      * @param  on the state of the key
1122      * @exception java.lang.IllegalArgumentException if <code>keyCode</code>
1123      * is not one of the valid key codes
1124      * @exception java.lang.UnsupportedOperationException if the host system doesn't
1125      * allow setting the state of this key programmatically, or if the keyboard
1126      * doesn't have this key
1127      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1128      * returns true
1129      * @see       java.awt.GraphicsEnvironment#isHeadless
1130      * @since 1.3
1131      */
1132     public void setLockingKeyState(int keyCode, boolean on)
1133         throws UnsupportedOperationException
1134     {
1135         GraphicsEnvironment.checkHeadless();
1136 
1137         if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
1138                keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
1139             throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState");
1140         }
1141         throw new UnsupportedOperationException("Toolkit.setLockingKeyState");
1142     }


1146      * given a native component (eg the direct parent may be lightweight).
1147      *
1148      * @param  c the component to fetch the container for
1149      * @return the native container object for the component
1150      */
1151     protected static Container getNativeContainer(Component c) {
1152         return c.getNativeContainer();
1153     }
1154 
1155     /**
1156      * Creates a new custom cursor object.
1157      * If the image to display is invalid, the cursor will be hidden (made
1158      * completely transparent), and the hotspot will be set to (0, 0).
1159      *
1160      * <p>Note that multi-frame images are invalid and may cause this
1161      * method to hang.
1162      *
1163      * @param cursor the image to display when the cursor is activated
1164      * @param hotSpot the X and Y of the large cursor's hot spot; the
1165      *   hotSpot values must be less than the Dimension returned by
1166      *   <code>getBestCursorSize</code>
1167      * @param     name a localized description of the cursor, for Java Accessibility use
1168      * @exception IndexOutOfBoundsException if the hotSpot values are outside
1169      *   the bounds of the cursor
1170      * @return the cursor created
1171      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1172      * returns true
1173      * @see       java.awt.GraphicsEnvironment#isHeadless
1174      * @since     1.2
1175      */
1176     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
1177         throws IndexOutOfBoundsException, HeadlessException
1178     {
1179         // Override to implement custom cursor support.
1180         if (this != Toolkit.getDefaultToolkit()) {
1181             return Toolkit.getDefaultToolkit().
1182                 createCustomCursor(cursor, hotSpot, name);
1183         } else {
1184             return new Cursor(Cursor.DEFAULT_CURSOR);
1185         }
1186     }


1235      * @return    the maximum number of colors, or zero if custom cursors are not
1236      * supported by this Toolkit implementation.
1237      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1238      * returns true
1239      * @see       java.awt.GraphicsEnvironment#isHeadless
1240      * @since     1.2
1241      */
1242     public int getMaximumCursorColors() throws HeadlessException {
1243         GraphicsEnvironment.checkHeadless();
1244 
1245         // Override to implement custom cursor support.
1246         if (this != Toolkit.getDefaultToolkit()) {
1247             return Toolkit.getDefaultToolkit().getMaximumCursorColors();
1248         } else {
1249             return 0;
1250         }
1251     }
1252 
1253     /**
1254      * Returns whether Toolkit supports this state for
1255      * <code>Frame</code>s.  This method tells whether the <em>UI
1256      * concept</em> of, say, maximization or iconification is
1257      * supported.  It will always return false for "compound" states
1258      * like <code>Frame.ICONIFIED|Frame.MAXIMIZED_VERT</code>.
1259      * In other words, the rule of thumb is that only queries with a
1260      * single frame state constant as an argument are meaningful.
1261      * <p>Note that supporting a given concept is a platform-
1262      * dependent feature. Due to native limitations the Toolkit
1263      * object may report a particular state as supported, however at
1264      * the same time the Toolkit object will be unable to apply the
1265      * state to a given frame.  This circumstance has two following
1266      * consequences:
1267      * <ul>
1268      * <li>Only the return value of {@code false} for the present
1269      * method actually indicates that the given state is not
1270      * supported. If the method returns {@code true} the given state
1271      * may still be unsupported and/or unavailable for a particular
1272      * frame.
1273      * <li>The developer should consider examining the value of the
1274      * {@link java.awt.event.WindowEvent#getNewState} method of the
1275      * {@code WindowEvent} received through the {@link
1276      * java.awt.event.WindowStateListener}, rather than assuming
1277      * that the state given to the {@code setExtendedState()} method
1278      * will be definitely applied. For more information see the
1279      * documentation for the {@link Frame#setExtendedState} method.
1280      * </ul>
1281      *
1282      * @param state one of named frame state constants.
1283      * @return <code>true</code> is this frame state is supported by
1284      *     this Toolkit implementation, <code>false</code> otherwise.
1285      * @exception HeadlessException
1286      *     if <code>GraphicsEnvironment.isHeadless()</code>
1287      *     returns <code>true</code>.
1288      * @see java.awt.Window#addWindowStateListener
1289      * @since   1.4
1290      */
1291     public boolean isFrameStateSupported(int state)
1292         throws HeadlessException
1293     {
1294         GraphicsEnvironment.checkHeadless();
1295 
1296         if (this != Toolkit.getDefaultToolkit()) {
1297             return Toolkit.getDefaultToolkit().
1298                 isFrameStateSupported(state);
1299         } else {
1300             return (state == Frame.NORMAL); // others are not guaranteed
1301         }
1302     }
1303 
1304     /**
1305      * Support for I18N: any visible strings should be stored in
1306      * sun.awt.resources.awt.properties.  The ResourceBundle is stored
1307      * here, so that only one copy is maintained.


1414             try {
1415                 return resources.getString(key);
1416             }
1417             catch (MissingResourceException e) {}
1418         }
1419 
1420         return defaultValue;
1421     }
1422 
1423     /**
1424      * Get the application's or applet's EventQueue instance.
1425      * Depending on the Toolkit implementation, different EventQueues
1426      * may be returned for different applets.  Applets should
1427      * therefore not assume that the EventQueue instance returned
1428      * by this method will be shared by other applets or the system.
1429      *
1430      * <p> If there is a security manager then its
1431      * {@link SecurityManager#checkPermission checkPermission} method
1432      * is called to check {@code AWTPermission("accessEventQueue")}.
1433      *
1434      * @return    the <code>EventQueue</code> object
1435      * @throws  SecurityException
1436      *          if a security manager is set and it denies access to
1437      *          the {@code EventQueue}
1438      * @see     java.awt.AWTPermission
1439     */
1440     public final EventQueue getSystemEventQueue() {
1441         SecurityManager security = System.getSecurityManager();
1442         if (security != null) {
1443             security.checkPermission(AWTPermissions.CHECK_AWT_EVENTQUEUE_PERMISSION);
1444         }
1445         return getSystemEventQueueImpl();
1446     }
1447 
1448     /**
1449      * Gets the application's or applet's <code>EventQueue</code>
1450      * instance, without checking access.  For security reasons,
1451      * this can only be called from a <code>Toolkit</code> subclass.
1452      * @return the <code>EventQueue</code> object
1453      */
1454     protected abstract EventQueue getSystemEventQueueImpl();
1455 
1456     /* Accessor method for use by AWT package routines. */
1457     static EventQueue getEventQueue() {
1458         return getDefaultToolkit().getSystemEventQueueImpl();
1459     }
1460 
1461     /**
1462      * Creates a concrete, platform dependent, subclass of the abstract
1463      * DragGestureRecognizer class requested, and associates it with the
1464      * DragSource, Component and DragGestureListener specified.
1465      *
1466      * subclasses should override this to provide their own implementation
1467      *
1468      * @param <T> the type of DragGestureRecognizer to create
1469      * @param abstractRecognizerClass The abstract class of the required recognizer
1470      * @param ds                      The DragSource
1471      * @param c                       The Component target for the DragGestureRecognizer
1472      * @param srcActions              The actions permitted for the gesture


1647      */
1648     public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
1649         return desktopPropsSupport.getPropertyChangeListeners(propertyName);
1650     }
1651 
1652     /**
1653      * The desktop properties.
1654      */
1655     protected final Map<String,Object> desktopProperties =
1656             new HashMap<String,Object>();
1657     /**
1658      * The desktop properties change support.
1659      */
1660     protected final PropertyChangeSupport desktopPropsSupport =
1661             Toolkit.createPropertyChangeSupport(this);
1662 
1663     /**
1664      * Returns whether the always-on-top mode is supported by this toolkit.
1665      * To detect whether the always-on-top mode is supported for a
1666      * particular Window, use {@link Window#isAlwaysOnTopSupported}.
1667      * @return <code>true</code>, if current toolkit supports the always-on-top mode,
1668      *     otherwise returns <code>false</code>
1669      * @see Window#isAlwaysOnTopSupported
1670      * @see Window#setAlwaysOnTop(boolean)
1671      * @since 1.6
1672      */
1673     public boolean isAlwaysOnTopSupported() {
1674         return true;
1675     }
1676 
1677     /**
1678      * Returns whether the given modality type is supported by this toolkit. If
1679      * a dialog with unsupported modality type is created, then
1680      * <code>Dialog.ModalityType.MODELESS</code> is used instead.
1681      *
1682      * @param modalityType modality type to be checked for support by this toolkit
1683      *
1684      * @return <code>true</code>, if current toolkit supports given modality
1685      *     type, <code>false</code> otherwise
1686      *
1687      * @see java.awt.Dialog.ModalityType
1688      * @see java.awt.Dialog#getModalityType
1689      * @see java.awt.Dialog#setModalityType
1690      *
1691      * @since 1.6
1692      */
1693     public abstract boolean isModalityTypeSupported(Dialog.ModalityType modalityType);
1694 
1695     /**
1696      * Returns whether the given modal exclusion type is supported by this
1697      * toolkit. If an unsupported modal exclusion type property is set on a window,
1698      * then <code>Dialog.ModalExclusionType.NO_EXCLUDE</code> is used instead.
1699      *
1700      * @param modalExclusionType modal exclusion type to be checked for support by this toolkit
1701      *
1702      * @return <code>true</code>, if current toolkit supports given modal exclusion
1703      *     type, <code>false</code> otherwise
1704      *
1705      * @see java.awt.Dialog.ModalExclusionType
1706      * @see java.awt.Window#getModalExclusionType
1707      * @see java.awt.Window#setModalExclusionType
1708      *
1709      * @since 1.6
1710      */
1711     public abstract boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType);
1712 
1713     // 8014718: logging has been removed from SunToolkit
1714 
1715     private static final int LONG_BITS = 64;
1716     private int[] calls = new int[LONG_BITS];
1717     private static volatile long enabledOnToolkitMask;
1718     private AWTEventListener eventListener = null;
1719     private WeakHashMap<AWTEventListener, SelectiveAWTEventListener> listener2SelectiveListener = new WeakHashMap<>();
1720 
1721     /*
1722      * Extracts a "pure" AWTEventListener from a AWTEventListenerProxy,
1723      * if the listener is proxied.
1724      */
1725     private static AWTEventListener deProxyAWTEventListener(AWTEventListener l)
1726     {
1727         AWTEventListener localL = l;
1728 
1729         if (localL == null) {
1730             return null;
1731         }
1732         // if user passed in a AWTEventListenerProxy object, extract
1733         // the listener
1734         if (l instanceof AWTEventListenerProxy) {
1735             localL = ((AWTEventListenerProxy)l).getListener();
1736         }
1737         return localL;
1738     }
1739 
1740     /**
1741      * Adds an AWTEventListener to receive all AWTEvents dispatched
1742      * system-wide that conform to the given <code>eventMask</code>.
1743      * <p>
1744      * First, if there is a security manager, its <code>checkPermission</code>
1745      * method is called with an
1746      * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
1747      * This may result in a SecurityException.
1748      * <p>
1749      * <code>eventMask</code> is a bitmask of event types to receive.
1750      * It is constructed by bitwise OR-ing together the event masks
1751      * defined in <code>AWTEvent</code>.
1752      * <p>
1753      * Note:  event listener use is not recommended for normal
1754      * application use, but are intended solely to support special
1755      * purpose facilities including support for accessibility,
1756      * event record/playback, and diagnostic tracing.
1757      *
1758      * If listener is null, no exception is thrown and no action is performed.
1759      *
1760      * @param    listener   the event listener.
1761      * @param    eventMask  the bitmask of event types to receive
1762      * @throws SecurityException
1763      *        if a security manager exists and its
1764      *        <code>checkPermission</code> method doesn't allow the operation.
1765      * @see      #removeAWTEventListener
1766      * @see      #getAWTEventListeners
1767      * @see      SecurityManager#checkPermission
1768      * @see      java.awt.AWTEvent
1769      * @see      java.awt.AWTPermission
1770      * @see      java.awt.event.AWTEventListener
1771      * @see      java.awt.event.AWTEventListenerProxy
1772      * @since    1.2
1773      */
1774     public void addAWTEventListener(AWTEventListener listener, long eventMask) {
1775         AWTEventListener localL = deProxyAWTEventListener(listener);
1776 
1777         if (localL == null) {
1778             return;
1779         }
1780         SecurityManager security = System.getSecurityManager();
1781         if (security != null) {
1782           security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1783         }
1784         synchronized (this) {


1798 
1799             enabledOnToolkitMask |= eventMask;
1800 
1801             long mask = eventMask;
1802             for (int i=0; i<LONG_BITS; i++) {
1803                 // If no bits are set, break out of loop.
1804                 if (mask == 0) {
1805                     break;
1806                 }
1807                 if ((mask & 1L) != 0) {  // Always test bit 0.
1808                     calls[i]++;
1809                 }
1810                 mask >>>= 1;  // Right shift, fill with zeros on left.
1811             }
1812         }
1813     }
1814 
1815     /**
1816      * Removes an AWTEventListener from receiving dispatched AWTEvents.
1817      * <p>
1818      * First, if there is a security manager, its <code>checkPermission</code>
1819      * method is called with an
1820      * <code>AWTPermission("listenToAllAWTEvents")</code> permission.
1821      * This may result in a SecurityException.
1822      * <p>
1823      * Note:  event listener use is not recommended for normal
1824      * application use, but are intended solely to support special
1825      * purpose facilities including support for accessibility,
1826      * event record/playback, and diagnostic tracing.
1827      *
1828      * If listener is null, no exception is thrown and no action is performed.
1829      *
1830      * @param    listener   the event listener.
1831      * @throws SecurityException
1832      *        if a security manager exists and its
1833      *        <code>checkPermission</code> method doesn't allow the operation.
1834      * @see      #addAWTEventListener
1835      * @see      #getAWTEventListeners
1836      * @see      SecurityManager#checkPermission
1837      * @see      java.awt.AWTEvent
1838      * @see      java.awt.AWTPermission
1839      * @see      java.awt.event.AWTEventListener
1840      * @see      java.awt.event.AWTEventListenerProxy
1841      * @since    1.2
1842      */
1843     public void removeAWTEventListener(AWTEventListener listener) {
1844         AWTEventListener localL = deProxyAWTEventListener(listener);
1845 
1846         if (listener == null) {
1847             return;
1848         }
1849         SecurityManager security = System.getSecurityManager();
1850         if (security != null) {
1851             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1852         }
1853 


1867                     }
1868                 }
1869             }
1870             eventListener = ToolkitEventMulticaster.remove(eventListener,
1871             (selectiveListener == null) ? localL : selectiveListener);
1872         }
1873     }
1874 
1875     static boolean enabledOnToolkit(long eventMask) {
1876         return (enabledOnToolkitMask & eventMask) != 0;
1877         }
1878 
1879     synchronized int countAWTEventListeners(long eventMask) {
1880         int ci = 0;
1881         for (; eventMask != 0; eventMask >>>= 1, ci++) {
1882         }
1883         ci--;
1884         return calls[ci];
1885     }
1886     /**
1887      * Returns an array of all the <code>AWTEventListener</code>s
1888      * registered on this toolkit.
1889      * If there is a security manager, its {@code checkPermission}
1890      * method is called with an
1891      * {@code AWTPermission("listenToAllAWTEvents")} permission.
1892      * This may result in a SecurityException.
1893      * Listeners can be returned
1894      * within <code>AWTEventListenerProxy</code> objects, which also contain
1895      * the event mask for the given listener.
1896      * Note that listener objects
1897      * added multiple times appear only once in the returned array.
1898      *
1899      * @return all of the <code>AWTEventListener</code>s or an empty
1900      *         array if no listeners are currently registered
1901      * @throws SecurityException
1902      *        if a security manager exists and its
1903      *        <code>checkPermission</code> method doesn't allow the operation.
1904      * @see      #addAWTEventListener
1905      * @see      #removeAWTEventListener
1906      * @see      SecurityManager#checkPermission
1907      * @see      java.awt.AWTEvent
1908      * @see      java.awt.AWTPermission
1909      * @see      java.awt.event.AWTEventListener
1910      * @see      java.awt.event.AWTEventListenerProxy
1911      * @since 1.4
1912      */
1913     public AWTEventListener[] getAWTEventListeners() {
1914         SecurityManager security = System.getSecurityManager();
1915         if (security != null) {
1916             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1917         }
1918         synchronized (this) {
1919             EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
1920 
1921             AWTEventListener[] ret = new AWTEventListener[la.length];
1922             for (int i = 0; i < la.length; i++) {
1923                 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
1924                 AWTEventListener tempL = sael.getListener();
1925                 //assert tempL is not an AWTEventListenerProxy - we should
1926                 // have weeded them all out
1927                 // don't want to wrap a proxy inside a proxy
1928                 ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL);
1929             }
1930             return ret;
1931         }
1932     }
1933 
1934     /**
1935      * Returns an array of all the <code>AWTEventListener</code>s
1936      * registered on this toolkit which listen to all of the event
1937      * types specified in the {@code eventMask} argument.
1938      * If there is a security manager, its {@code checkPermission}
1939      * method is called with an
1940      * {@code AWTPermission("listenToAllAWTEvents")} permission.
1941      * This may result in a SecurityException.
1942      * Listeners can be returned
1943      * within <code>AWTEventListenerProxy</code> objects, which also contain
1944      * the event mask for the given listener.
1945      * Note that listener objects
1946      * added multiple times appear only once in the returned array.
1947      *
1948      * @param  eventMask the bitmask of event types to listen for
1949      * @return all of the <code>AWTEventListener</code>s registered
1950      *         on this toolkit for the specified
1951      *         event types, or an empty array if no such listeners
1952      *         are currently registered
1953      * @throws SecurityException
1954      *        if a security manager exists and its
1955      *        <code>checkPermission</code> method doesn't allow the operation.
1956      * @see      #addAWTEventListener
1957      * @see      #removeAWTEventListener
1958      * @see      SecurityManager#checkPermission
1959      * @see      java.awt.AWTEvent
1960      * @see      java.awt.AWTPermission
1961      * @see      java.awt.event.AWTEventListener
1962      * @see      java.awt.event.AWTEventListenerProxy
1963      * @since 1.4
1964      */
1965     public AWTEventListener[] getAWTEventListeners(long eventMask) {
1966         SecurityManager security = System.getSecurityManager();
1967         if (security != null) {
1968             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1969         }
1970         synchronized (this) {
1971             EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
1972 
1973             java.util.List<AWTEventListenerProxy> list = new ArrayList<>(la.length);
1974 
1975             for (int i = 0; i < la.length; i++) {


2150                 // int ci = (int) (Math.log(eventBit)/Math.log(2));
2151                 int ci = 0;
2152                 for (long eMask = eventBit; eMask != 0; eMask >>>= 1, ci++) {
2153                 }
2154                 ci--;
2155                 // Call the listener as many times as it was added for this
2156                 // event type.
2157                 for (int i=0; i<calls[ci]; i++) {
2158                     listener.eventDispatched(event);
2159                 }
2160             }
2161         }
2162     }
2163 
2164     /**
2165      * Returns a map of visual attributes for the abstract level description
2166      * of the given input method highlight, or null if no mapping is found.
2167      * The style field of the input method highlight is ignored. The map
2168      * returned is unmodifiable.
2169      * @param highlight input method highlight
2170      * @return style attribute map, or <code>null</code>
2171      * @exception HeadlessException if
2172      *     <code>GraphicsEnvironment.isHeadless</code> returns true
2173      * @see       java.awt.GraphicsEnvironment#isHeadless
2174      * @since 1.3
2175      */
2176     public abstract Map<java.awt.font.TextAttribute,?>
2177         mapInputMethodHighlight(InputMethodHighlight highlight)
2178         throws HeadlessException;
2179 
2180     private static PropertyChangeSupport createPropertyChangeSupport(Toolkit toolkit) {
2181         if (toolkit instanceof SunToolkit || toolkit instanceof HeadlessToolkit) {
2182             return new DesktopPropertyChangeSupport(toolkit);
2183         } else {
2184             return new PropertyChangeSupport(toolkit);
2185         }
2186     }
2187 
2188     @SuppressWarnings("serial")
2189     private static class DesktopPropertyChangeSupport extends PropertyChangeSupport {
2190 
2191         private static final StringBuilder PROP_CHANGE_SUPPORT_KEY =
2192                 new StringBuilder("desktop property change support key");




  52 
  53 import sun.awt.AWTAccessor;
  54 import sun.awt.AWTPermissions;
  55 import sun.awt.AppContext;
  56 import sun.awt.HeadlessToolkit;
  57 import sun.awt.PeerEvent;
  58 import sun.awt.SunToolkit;
  59 import sun.util.CoreResourceBundleControl;
  60 
  61 import java.security.AccessController;
  62 import java.security.PrivilegedAction;
  63 import java.util.Arrays;
  64 import java.util.ServiceLoader;
  65 import java.util.Set;
  66 import java.util.stream.Collectors;
  67 import javax.accessibility.AccessibilityProvider;
  68 
  69 /**
  70  * This class is the abstract superclass of all actual
  71  * implementations of the Abstract Window Toolkit. Subclasses of
  72  * the {@code Toolkit} class are used to bind the various components
  73  * to particular native toolkit implementations.
  74  * <p>
  75  * Many GUI events may be delivered to user
  76  * asynchronously, if the opposite is not specified explicitly.
  77  * As well as
  78  * many GUI operations may be performed asynchronously.
  79  * This fact means that if the state of a component is set, and then
  80  * the state immediately queried, the returned value may not yet
  81  * reflect the requested change.  This behavior includes, but is not
  82  * limited to:
  83  * <ul>
  84  * <li>Scrolling to a specified position.
  85  * <br>For example, calling {@code ScrollPane.setScrollPosition}
  86  *     and then {@code getScrollPosition} may return an incorrect
  87  *     value if the original request has not yet been processed.
  88  *
  89  * <li>Moving the focus from one component to another.
  90  * <br>For more information, see
  91  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html#transferTiming">Timing
  92  * Focus Transfers</a>, a section in
  93  * <a href="http://java.sun.com/docs/books/tutorial/uiswing/">The Swing
  94  * Tutorial</a>.
  95  *
  96  * <li>Making a top-level container visible.
  97  * <br>Calling {@code setVisible(true)} on a {@code Window},
  98  *     {@code Frame} or {@code Dialog} may occur
  99  *     asynchronously.
 100  *
 101  * <li>Setting the size or location of a top-level container.
 102  * <br>Calls to {@code setSize}, {@code setBounds} or
 103  *     {@code setLocation} on a {@code Window},
 104  *     {@code Frame} or {@code Dialog} are forwarded
 105  *     to the underlying window management system and may be
 106  *     ignored or modified.  See {@link java.awt.Window} for
 107  *     more information.
 108  * </ul>
 109  * <p>
 110  * Most applications should not call any of the methods in this
 111  * class directly. The methods defined by {@code Toolkit} are
 112  * the "glue" that joins the platform-independent classes in the
 113  * {@code java.awt} package with their counterparts in
 114  * {@code java.awt.peer}. Some methods defined by
 115  * {@code Toolkit} query the native operating system directly.
 116  *
 117  * @author      Sami Shaio
 118  * @author      Arthur van Hoff
 119  * @author      Fred Ecks
 120  * @since       1.0
 121  */
 122 public abstract class Toolkit {
 123 
 124     // The following method is called by the private method
 125     // <code>updateSystemColors</code> in <code>SystemColor</code>.
 126 
 127     /**
 128      * Fills in the integer array that is supplied as an argument
 129      * with the current system color values.
 130      *
 131      * @param     systemColors an integer array.
 132      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 133      * returns true
 134      * @see       java.awt.GraphicsEnvironment#isHeadless
 135      * @since     1.1


 230      * @see       #setDynamicLayout(boolean dynamic)
 231      * @see       #isDynamicLayoutSet()
 232      * @see       #getDesktopProperty(String propertyName)
 233      * @see       java.awt.GraphicsEnvironment#isHeadless
 234      * @since     1.4
 235      */
 236     public boolean isDynamicLayoutActive()
 237         throws HeadlessException {
 238         GraphicsEnvironment.checkHeadless();
 239 
 240         if (this != Toolkit.getDefaultToolkit()) {
 241             return Toolkit.getDefaultToolkit().isDynamicLayoutActive();
 242         } else {
 243             return false;
 244         }
 245     }
 246 
 247     /**
 248      * Gets the size of the screen.  On systems with multiple displays, the
 249      * primary display is used.  Multi-screen aware display dimensions are
 250      * available from {@code GraphicsConfiguration} and
 251      * {@code GraphicsDevice}.
 252      * @return    the size of this toolkit's screen, in pixels.
 253      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 254      * returns true
 255      * @see       java.awt.GraphicsConfiguration#getBounds
 256      * @see       java.awt.GraphicsDevice#getDisplayMode
 257      * @see       java.awt.GraphicsEnvironment#isHeadless
 258      */
 259     public abstract Dimension getScreenSize()
 260         throws HeadlessException;
 261 
 262     /**
 263      * Returns the screen resolution in dots-per-inch.
 264      * @return    this toolkit's screen resolution, in dots-per-inch.
 265      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 266      * returns true
 267      * @see       java.awt.GraphicsEnvironment#isHeadless
 268      */
 269     public abstract int getScreenResolution()
 270         throws HeadlessException;
 271 
 272     /**
 273      * Gets the insets of the screen.
 274      * @param     gc a {@code GraphicsConfiguration}
 275      * @return    the insets of this toolkit's screen, in pixels.
 276      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 277      * returns true
 278      * @see       java.awt.GraphicsEnvironment#isHeadless
 279      * @since     1.4
 280      */
 281     public Insets getScreenInsets(GraphicsConfiguration gc)
 282         throws HeadlessException {
 283         GraphicsEnvironment.checkHeadless();
 284         if (this != Toolkit.getDefaultToolkit()) {
 285             return Toolkit.getDefaultToolkit().getScreenInsets(gc);
 286         } else {
 287             return new Insets(0, 0, 0, 0);
 288         }
 289     }
 290 
 291     /**
 292      * Determines the color model of this toolkit's screen.
 293      * <p>
 294      * {@code ColorModel} is an abstract class that
 295      * encapsulates the ability to translate between the
 296      * pixel values of an image and its red, green, blue,
 297      * and alpha components.
 298      * <p>
 299      * This toolkit method is called by the
 300      * {@code getColorModel} method
 301      * of the {@code Component} class.
 302      * @return    the color model of this toolkit's screen.
 303      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 304      * returns true
 305      * @see       java.awt.GraphicsEnvironment#isHeadless
 306      * @see       java.awt.image.ColorModel
 307      * @see       java.awt.Component#getColorModel
 308      */
 309     public abstract ColorModel getColorModel()
 310         throws HeadlessException;
 311 
 312     /**
 313      * Returns the names of the available fonts in this toolkit.<p>
 314      * For 1.1, the following font names are deprecated (the replacement
 315      * name follows):
 316      * <ul>
 317      * <li>TimesRoman (use Serif)
 318      * <li>Helvetica (use SansSerif)
 319      * <li>Courier (use Monospaced)
 320      * </ul><p>
 321      * The ZapfDingbats fontname is also deprecated in 1.1 but the characters
 322      * are defined in Unicode starting at 0x2700, and as of 1.1 Java supports
 323      * those characters.
 324      * @return    the names of the available fonts in this toolkit.
 325      * @deprecated see {@link java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()}
 326      * @see java.awt.GraphicsEnvironment#getAvailableFontFamilyNames()
 327      */
 328     @Deprecated
 329     public abstract String[] getFontList();
 330 
 331     /**
 332      * Gets the screen device metrics for rendering of the font.
 333      * @param     font   a font
 334      * @return    the screen metrics of the specified font in this toolkit
 335      * @deprecated  As of JDK version 1.2, replaced by the {@code Font}
 336      *          method {@code getLineMetrics}.
 337      * @see java.awt.font.LineMetrics
 338      * @see java.awt.Font#getLineMetrics
 339      * @see java.awt.GraphicsEnvironment#getScreenDevices
 340      */
 341     @Deprecated
 342     public abstract FontMetrics getFontMetrics(Font font);
 343 
 344     /**
 345      * Synchronizes this toolkit's graphics state. Some window systems
 346      * may do buffering of graphics events.
 347      * <p>
 348      * This method ensures that the display is up-to-date. It is useful
 349      * for animation.
 350      */
 351     public abstract void sync();
 352 
 353     /**
 354      * The default toolkit.
 355      */
 356     private static Toolkit toolkit;


 589                     } catch (final IllegalAccessException ignored) {
 590                         throw new AWTError("Could not access Toolkit: " + nm);
 591                     }
 592                     return null;
 593                 }
 594             });
 595             if (!GraphicsEnvironment.isHeadless()) {
 596                 loadAssistiveTechnologies();
 597             }
 598         }
 599         return toolkit;
 600     }
 601 
 602     /**
 603      * Returns an image which gets pixel data from the specified file,
 604      * whose format can be either GIF, JPEG or PNG.
 605      * The underlying toolkit attempts to resolve multiple requests
 606      * with the same filename to the same returned Image.
 607      * <p>
 608      * Since the mechanism required to facilitate this sharing of
 609      * {@code Image} objects may continue to hold onto images
 610      * that are no longer in use for an indefinite period of time,
 611      * developers are encouraged to implement their own caching of
 612      * images by using the {@link #createImage(java.lang.String) createImage}
 613      * variant wherever available.
 614      * If the image data contained in the specified file changes,
 615      * the {@code Image} object returned from this method may
 616      * still contain stale information which was loaded from the
 617      * file after a prior call.
 618      * Previously loaded image data can be manually discarded by
 619      * calling the {@link Image#flush flush} method on the
 620      * returned {@code Image}.
 621      * <p>
 622      * This method first checks if there is a security manager installed.
 623      * If so, the method calls the security manager's
 624      * {@code checkRead} method with the file specified to ensure
 625      * that the access to the image is allowed.
 626      * @param     filename   the name of a file containing pixel data
 627      *                         in a recognized file format.
 628      * @return    an image which gets its pixel data from
 629      *                         the specified file.
 630      * @throws SecurityException  if a security manager exists and its
 631      *                            checkRead method doesn't allow the operation.
 632      * @see #createImage(java.lang.String)
 633      */
 634     public abstract Image getImage(String filename);
 635 
 636     /**
 637      * Returns an image which gets pixel data from the specified URL.
 638      * The pixel data referenced by the specified URL must be in one
 639      * of the following formats: GIF, JPEG or PNG.
 640      * The underlying toolkit attempts to resolve multiple requests
 641      * with the same URL to the same returned Image.
 642      * <p>
 643      * Since the mechanism required to facilitate this sharing of
 644      * {@code Image} objects may continue to hold onto images
 645      * that are no longer in use for an indefinite period of time,
 646      * developers are encouraged to implement their own caching of
 647      * images by using the {@link #createImage(java.net.URL) createImage}
 648      * variant wherever available.
 649      * If the image data stored at the specified URL changes,
 650      * the {@code Image} object returned from this method may
 651      * still contain stale information which was fetched from the
 652      * URL after a prior call.
 653      * Previously loaded image data can be manually discarded by
 654      * calling the {@link Image#flush flush} method on the
 655      * returned {@code Image}.
 656      * <p>
 657      * This method first checks if there is a security manager installed.
 658      * If so, the method calls the security manager's
 659      * {@code checkPermission} method with the
 660      * url.openConnection().getPermission() permission to ensure
 661      * that the access to the image is allowed. For compatibility
 662      * with pre-1.2 security managers, if the access is denied with
 663      * {@code FilePermission} or {@code SocketPermission},
 664      * the method throws the {@code SecurityException}
 665      * if the corresponding 1.1-style SecurityManager.checkXXX method
 666      * also denies permission.
 667      * @param     url   the URL to use in fetching the pixel data.
 668      * @return    an image which gets its pixel data from
 669      *                         the specified URL.
 670      * @throws SecurityException  if a security manager exists and its
 671      *                            checkPermission method doesn't allow
 672      *                            the operation.
 673      * @see #createImage(java.net.URL)
 674      */
 675     public abstract Image getImage(URL url);
 676 
 677     /**
 678      * Returns an image which gets pixel data from the specified file.
 679      * The returned Image is a new object which will not be shared
 680      * with any other caller of this method or its getImage variant.
 681      * <p>
 682      * This method first checks if there is a security manager installed.
 683      * If so, the method calls the security manager's
 684      * {@code checkRead} method with the specified file to ensure
 685      * that the image creation is allowed.
 686      * @param     filename   the name of a file containing pixel data
 687      *                         in a recognized file format.
 688      * @return    an image which gets its pixel data from
 689      *                         the specified file.
 690      * @throws SecurityException  if a security manager exists and its
 691      *                            checkRead method doesn't allow the operation.
 692      * @see #getImage(java.lang.String)
 693      */
 694     public abstract Image createImage(String filename);
 695 
 696     /**
 697      * Returns an image which gets pixel data from the specified URL.
 698      * The returned Image is a new object which will not be shared
 699      * with any other caller of this method or its getImage variant.
 700      * <p>
 701      * This method first checks if there is a security manager installed.
 702      * If so, the method calls the security manager's
 703      * {@code checkPermission} method with the
 704      * url.openConnection().getPermission() permission to ensure
 705      * that the image creation is allowed. For compatibility
 706      * with pre-1.2 security managers, if the access is denied with
 707      * {@code FilePermission} or {@code SocketPermission},
 708      * the method throws {@code SecurityException}
 709      * if the corresponding 1.1-style SecurityManager.checkXXX method
 710      * also denies permission.
 711      * @param     url   the URL to use in fetching the pixel data.
 712      * @return    an image which gets its pixel data from
 713      *                         the specified URL.
 714      * @throws SecurityException  if a security manager exists and its
 715      *                            checkPermission method doesn't allow
 716      *                            the operation.
 717      * @see #getImage(java.net.URL)
 718      */
 719     public abstract Image createImage(URL url);
 720 
 721     /**
 722      * Prepares an image for rendering.
 723      * <p>
 724      * If the values of the width and height arguments are both
 725      * {@code -1}, this method prepares the image for rendering
 726      * on the default screen; otherwise, this method prepares an image
 727      * for rendering on the default screen at the specified width and height.
 728      * <p>
 729      * The image data is downloaded asynchronously in another thread,
 730      * and an appropriately scaled screen representation of the image is
 731      * generated.
 732      * <p>
 733      * This method is called by components {@code prepareImage}
 734      * methods.
 735      * <p>
 736      * Information on the flags returned by this method can be found
 737      * with the definition of the {@code ImageObserver} interface.
 738 
 739      * @param     image      the image for which to prepare a
 740      *                           screen representation.
 741      * @param     width      the width of the desired screen
 742      *                           representation, or {@code -1}.
 743      * @param     height     the height of the desired screen
 744      *                           representation, or {@code -1}.
 745      * @param     observer   the {@code ImageObserver}
 746      *                           object to be notified as the
 747      *                           image is being prepared.
 748      * @return    {@code true} if the image has already been
 749      *                 fully prepared; {@code false} otherwise.
 750      * @see       java.awt.Component#prepareImage(java.awt.Image,
 751      *                 java.awt.image.ImageObserver)
 752      * @see       java.awt.Component#prepareImage(java.awt.Image,
 753      *                 int, int, java.awt.image.ImageObserver)
 754      * @see       java.awt.image.ImageObserver
 755      */
 756     public abstract boolean prepareImage(Image image, int width, int height,
 757                                          ImageObserver observer);
 758 
 759     /**
 760      * Indicates the construction status of a specified image that is
 761      * being prepared for display.
 762      * <p>
 763      * If the values of the width and height arguments are both
 764      * {@code -1}, this method returns the construction status of
 765      * a screen representation of the specified image in this toolkit.
 766      * Otherwise, this method returns the construction status of a
 767      * scaled representation of the image at the specified width
 768      * and height.
 769      * <p>
 770      * This method does not cause the image to begin loading.
 771      * An application must call {@code prepareImage} to force
 772      * the loading of an image.
 773      * <p>
 774      * This method is called by the component's {@code checkImage}
 775      * methods.
 776      * <p>
 777      * Information on the flags returned by this method can be found
 778      * with the definition of the {@code ImageObserver} interface.
 779      * @param     image   the image whose status is being checked.
 780      * @param     width   the width of the scaled version whose status is
 781      *                 being checked, or {@code -1}.
 782      * @param     height  the height of the scaled version whose status
 783      *                 is being checked, or {@code -1}.
 784      * @param     observer   the {@code ImageObserver} object to be
 785      *                 notified as the image is being prepared.
 786      * @return    the bitwise inclusive <strong>OR</strong> of the
 787      *                 {@code ImageObserver} flags for the
 788      *                 image data that is currently available.
 789      * @see       java.awt.Toolkit#prepareImage(java.awt.Image,
 790      *                 int, int, java.awt.image.ImageObserver)
 791      * @see       java.awt.Component#checkImage(java.awt.Image,
 792      *                 java.awt.image.ImageObserver)
 793      * @see       java.awt.Component#checkImage(java.awt.Image,
 794      *                 int, int, java.awt.image.ImageObserver)
 795      * @see       java.awt.image.ImageObserver
 796      */
 797     public abstract int checkImage(Image image, int width, int height,
 798                                    ImageObserver observer);
 799 
 800     /**
 801      * Creates an image with the specified image producer.
 802      * @param     producer the image producer to be used.
 803      * @return    an image with the specified image producer.
 804      * @see       java.awt.Image
 805      * @see       java.awt.image.ImageProducer
 806      * @see       java.awt.Component#createImage(java.awt.image.ImageProducer)
 807      */


 823     }
 824 
 825     /**
 826      * Creates an image which decodes the image stored in the specified
 827      * byte array, and at the specified offset and length.
 828      * The data must be in some image format, such as GIF or JPEG,
 829      * that is supported by this toolkit.
 830      * @param     imagedata   an array of bytes, representing
 831      *                         image data in a supported image format.
 832      * @param     imageoffset  the offset of the beginning
 833      *                         of the data in the array.
 834      * @param     imagelength  the length of the data in the array.
 835      * @return    an image.
 836      * @since     1.1
 837      */
 838     public abstract Image createImage(byte[] imagedata,
 839                                       int imageoffset,
 840                                       int imagelength);
 841 
 842     /**
 843      * Gets a {@code PrintJob} object which is the result of initiating
 844      * a print operation on the toolkit's platform.
 845      * <p>
 846      * Each actual implementation of this method should first check if there
 847      * is a security manager installed. If there is, the method should call
 848      * the security manager's {@code checkPrintJobAccess} method to
 849      * ensure initiation of a print operation is allowed. If the default
 850      * implementation of {@code checkPrintJobAccess} is used (that is,
 851      * that method is not overriden), then this results in a call to the
 852      * security manager's {@code checkPermission} method with a
 853      * {@code RuntimePermission("queuePrintJob")} permission.
 854      *
 855      * @param   frame the parent of the print dialog. May not be null.
 856      * @param   jobtitle the title of the PrintJob. A null title is equivalent
 857      *          to "".
 858      * @param   props a Properties object containing zero or more properties.
 859      *          Properties are not standardized and are not consistent across
 860      *          implementations. Because of this, PrintJobs which require job
 861      *          and page control should use the version of this function which
 862      *          takes JobAttributes and PageAttributes objects. This object
 863      *          may be updated to reflect the user's job choices on exit. May
 864      *          be null.
 865      * @return  a {@code PrintJob} object, or {@code null} if the
 866      *          user cancelled the print job.
 867      * @throws  NullPointerException if frame is null
 868      * @throws  SecurityException if this thread is not allowed to initiate a
 869      *          print job request
 870      * @see     java.awt.GraphicsEnvironment#isHeadless
 871      * @see     java.awt.PrintJob
 872      * @see     java.lang.RuntimePermission
 873      * @since   1.1
 874      */
 875     public abstract PrintJob getPrintJob(Frame frame, String jobtitle,
 876                                          Properties props);
 877 
 878     /**
 879      * Gets a {@code PrintJob} object which is the result of initiating
 880      * a print operation on the toolkit's platform.
 881      * <p>
 882      * Each actual implementation of this method should first check if there
 883      * is a security manager installed. If there is, the method should call
 884      * the security manager's {@code checkPrintJobAccess} method to
 885      * ensure initiation of a print operation is allowed. If the default
 886      * implementation of {@code checkPrintJobAccess} is used (that is,
 887      * that method is not overriden), then this results in a call to the
 888      * security manager's {@code checkPermission} method with a
 889      * {@code RuntimePermission("queuePrintJob")} permission.
 890      *
 891      * @param   frame the parent of the print dialog. May not be null.
 892      * @param   jobtitle the title of the PrintJob. A null title is equivalent
 893      *          to "".
 894      * @param   jobAttributes a set of job attributes which will control the
 895      *          PrintJob. The attributes will be updated to reflect the user's
 896      *          choices as outlined in the JobAttributes documentation. May be
 897      *          null.
 898      * @param   pageAttributes a set of page attributes which will control the
 899      *          PrintJob. The attributes will be applied to every page in the
 900      *          job. The attributes will be updated to reflect the user's
 901      *          choices as outlined in the PageAttributes documentation. May be
 902      *          null.
 903      * @return  a {@code PrintJob} object, or {@code null} if the
 904      *          user cancelled the print job.
 905      * @throws  NullPointerException if frame is null
 906      * @throws  IllegalArgumentException if pageAttributes specifies differing
 907      *          cross feed and feed resolutions. Also if this thread has
 908      *          access to the file system and jobAttributes specifies
 909      *          print to file, and the specified destination file exists but
 910      *          is a directory rather than a regular file, does not exist but
 911      *          cannot be created, or cannot be opened for any other reason.
 912      *          However in the case of print to file, if a dialog is also
 913      *          requested to be displayed then the user will be given an
 914      *          opportunity to select a file and proceed with printing.
 915      *          The dialog will ensure that the selected output file
 916      *          is valid before returning from this method.
 917      * @throws  SecurityException if this thread is not allowed to initiate a
 918      *          print job request, or if jobAttributes specifies print to file,
 919      *          and this thread is not allowed to access the file system
 920      * @see     java.awt.PrintJob
 921      * @see     java.awt.GraphicsEnvironment#isHeadless
 922      * @see     java.lang.RuntimePermission
 923      * @see     java.awt.JobAttributes


 935                                                            pageAttributes);
 936         } else {
 937             return getPrintJob(frame, jobtitle, null);
 938         }
 939     }
 940 
 941     /**
 942      * Emits an audio beep depending on native system settings and hardware
 943      * capabilities.
 944      * @since     1.1
 945      */
 946     public abstract void beep();
 947 
 948     /**
 949      * Gets the singleton instance of the system Clipboard which interfaces
 950      * with clipboard facilities provided by the native platform. This
 951      * clipboard enables data transfer between Java programs and native
 952      * applications which use native clipboard facilities.
 953      * <p>
 954      * In addition to any and all default formats text returned by the system
 955      * Clipboard's {@code getTransferData()} method is available in the
 956      * following flavors:
 957      * <ul>
 958      * <li>DataFlavor.stringFlavor</li>
 959      * <li>DataFlavor.plainTextFlavor (<b>deprecated</b>)</li>
 960      * </ul>
 961      * As with {@code java.awt.datatransfer.StringSelection}, if the
 962      * requested flavor is {@code DataFlavor.plainTextFlavor}, or an
 963      * equivalent flavor, a Reader is returned. <b>Note:</b> The behavior of
 964      * the system Clipboard's {@code getTransferData()} method for
 965      * {@code DataFlavor.plainTextFlavor}, and equivalent DataFlavors, is
 966      * inconsistent with the definition of {@code DataFlavor.plainTextFlavor}.
 967      * Because of this, support for
 968      * {@code DataFlavor.plainTextFlavor}, and equivalent flavors, is
 969      * <b>deprecated</b>.
 970      * <p>
 971      * Each actual implementation of this method should first check if there
 972      * is a security manager installed. If there is, the method should call
 973      * the security manager's {@link SecurityManager#checkPermission
 974      * checkPermission} method to check {@code AWTPermission("accessClipboard")}.
 975      *
 976      * @return    the system Clipboard
 977      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
 978      * returns true
 979      * @see       java.awt.GraphicsEnvironment#isHeadless
 980      * @see       java.awt.datatransfer.Clipboard
 981      * @see       java.awt.datatransfer.StringSelection
 982      * @see       java.awt.datatransfer.DataFlavor#stringFlavor
 983      * @see       java.awt.datatransfer.DataFlavor#plainTextFlavor
 984      * @see       java.io.Reader
 985      * @see       java.awt.AWTPermission
 986      * @since     1.1
 987      */
 988     public abstract Clipboard getSystemClipboard()
 989         throws HeadlessException;
 990 
 991     /**
 992      * Gets the singleton instance of the system selection as a
 993      * {@code Clipboard} object. This allows an application to read and
 994      * modify the current, system-wide selection.
 995      * <p>
 996      * An application is responsible for updating the system selection whenever
 997      * the user selects text, using either the mouse or the keyboard.
 998      * Typically, this is implemented by installing a
 999      * {@code FocusListener} on all {@code Component}s which support
1000      * text selection, and, between {@code FOCUS_GAINED} and
1001      * {@code FOCUS_LOST} events delivered to that {@code Component},
1002      * updating the system selection {@code Clipboard} when the selection
1003      * changes inside the {@code Component}. Properly updating the system
1004      * selection ensures that a Java application will interact correctly with
1005      * native applications and other Java applications running simultaneously
1006      * on the system. Note that {@code java.awt.TextComponent} and
1007      * {@code javax.swing.text.JTextComponent} already adhere to this
1008      * policy. When using these classes, and their subclasses, developers need
1009      * not write any additional code.
1010      * <p>
1011      * Some platforms do not support a system selection {@code Clipboard}.
1012      * On those platforms, this method will return {@code null}. In such a
1013      * case, an application is absolved from its responsibility to update the
1014      * system selection {@code Clipboard} as described above.
1015      * <p>
1016      * Each actual implementation of this method should first check if there
1017      * is a security manager installed. If there is, the method should call
1018      * the security manager's {@link SecurityManager#checkPermission
1019      * checkPermission} method to check {@code AWTPermission("accessClipboard")}.
1020      *
1021      * @return the system selection as a {@code Clipboard}, or
1022      *         {@code null} if the native platform does not support a
1023      *         system selection {@code Clipboard}
1024      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1025      *            returns true
1026      *
1027      * @see java.awt.datatransfer.Clipboard
1028      * @see java.awt.event.FocusListener
1029      * @see java.awt.event.FocusEvent#FOCUS_GAINED
1030      * @see java.awt.event.FocusEvent#FOCUS_LOST
1031      * @see TextComponent
1032      * @see javax.swing.text.JTextComponent
1033      * @see AWTPermission
1034      * @see GraphicsEnvironment#isHeadless
1035      * @since 1.4
1036      */
1037     public Clipboard getSystemSelection() throws HeadlessException {
1038         GraphicsEnvironment.checkHeadless();
1039 
1040         if (this != Toolkit.getDefaultToolkit()) {
1041             return Toolkit.getDefaultToolkit().getSystemSelection();
1042         } else {
1043             GraphicsEnvironment.checkHeadless();
1044             return null;
1045         }
1046     }
1047 
1048     /**
1049      * Determines which modifier key is the appropriate accelerator
1050      * key for menu shortcuts.
1051      * <p>
1052      * Menu shortcuts, which are embodied in the
1053      * {@code MenuShortcut} class, are handled by the
1054      * {@code MenuBar} class.
1055      * <p>
1056      * By default, this method returns {@code Event.CTRL_MASK}.
1057      * Toolkit implementations should override this method if the
1058      * <b>Control</b> key isn't the correct key for accelerators.
1059      * @return    the modifier mask on the {@code Event} class
1060      *                 that is used for menu shortcuts on this toolkit.
1061      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1062      * returns true
1063      * @see       java.awt.GraphicsEnvironment#isHeadless
1064      * @see       java.awt.MenuBar
1065      * @see       java.awt.MenuShortcut
1066      * @since     1.1
1067      */
1068     public int getMenuShortcutKeyMask() throws HeadlessException {
1069         GraphicsEnvironment.checkHeadless();
1070 
1071         return Event.CTRL_MASK;
1072     }
1073 
1074     /**
1075      * Returns whether the given locking key on the keyboard is currently in
1076      * its "on" state.
1077      * Valid key codes are
1078      * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
1079      * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
1080      * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
1081      * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
1082      *
1083      * @param  keyCode the key code
1084      * @return {@code true} if the given key is currently in its "on" state;
1085      *          otherwise {@code false}
1086      * @exception java.lang.IllegalArgumentException if {@code keyCode}
1087      * is not one of the valid key codes
1088      * @exception java.lang.UnsupportedOperationException if the host system doesn't
1089      * allow getting the state of this key programmatically, or if the keyboard
1090      * doesn't have this key
1091      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1092      * returns true
1093      * @see       java.awt.GraphicsEnvironment#isHeadless
1094      * @since 1.3
1095      */
1096     public boolean getLockingKeyState(int keyCode)
1097         throws UnsupportedOperationException
1098     {
1099         GraphicsEnvironment.checkHeadless();
1100 
1101         if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
1102                keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
1103             throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
1104         }
1105         throw new UnsupportedOperationException("Toolkit.getLockingKeyState");
1106     }
1107 
1108     /**
1109      * Sets the state of the given locking key on the keyboard.
1110      * Valid key codes are
1111      * {@link java.awt.event.KeyEvent#VK_CAPS_LOCK VK_CAPS_LOCK},
1112      * {@link java.awt.event.KeyEvent#VK_NUM_LOCK VK_NUM_LOCK},
1113      * {@link java.awt.event.KeyEvent#VK_SCROLL_LOCK VK_SCROLL_LOCK}, and
1114      * {@link java.awt.event.KeyEvent#VK_KANA_LOCK VK_KANA_LOCK}.
1115      * <p>
1116      * Depending on the platform, setting the state of a locking key may
1117      * involve event processing and therefore may not be immediately
1118      * observable through getLockingKeyState.
1119      *
1120      * @param  keyCode the key code
1121      * @param  on the state of the key
1122      * @exception java.lang.IllegalArgumentException if {@code keyCode}
1123      * is not one of the valid key codes
1124      * @exception java.lang.UnsupportedOperationException if the host system doesn't
1125      * allow setting the state of this key programmatically, or if the keyboard
1126      * doesn't have this key
1127      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1128      * returns true
1129      * @see       java.awt.GraphicsEnvironment#isHeadless
1130      * @since 1.3
1131      */
1132     public void setLockingKeyState(int keyCode, boolean on)
1133         throws UnsupportedOperationException
1134     {
1135         GraphicsEnvironment.checkHeadless();
1136 
1137         if (! (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK ||
1138                keyCode == KeyEvent.VK_SCROLL_LOCK || keyCode == KeyEvent.VK_KANA_LOCK)) {
1139             throw new IllegalArgumentException("invalid key for Toolkit.setLockingKeyState");
1140         }
1141         throw new UnsupportedOperationException("Toolkit.setLockingKeyState");
1142     }


1146      * given a native component (eg the direct parent may be lightweight).
1147      *
1148      * @param  c the component to fetch the container for
1149      * @return the native container object for the component
1150      */
1151     protected static Container getNativeContainer(Component c) {
1152         return c.getNativeContainer();
1153     }
1154 
1155     /**
1156      * Creates a new custom cursor object.
1157      * If the image to display is invalid, the cursor will be hidden (made
1158      * completely transparent), and the hotspot will be set to (0, 0).
1159      *
1160      * <p>Note that multi-frame images are invalid and may cause this
1161      * method to hang.
1162      *
1163      * @param cursor the image to display when the cursor is activated
1164      * @param hotSpot the X and Y of the large cursor's hot spot; the
1165      *   hotSpot values must be less than the Dimension returned by
1166      *   {@code getBestCursorSize}
1167      * @param     name a localized description of the cursor, for Java Accessibility use
1168      * @exception IndexOutOfBoundsException if the hotSpot values are outside
1169      *   the bounds of the cursor
1170      * @return the cursor created
1171      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1172      * returns true
1173      * @see       java.awt.GraphicsEnvironment#isHeadless
1174      * @since     1.2
1175      */
1176     public Cursor createCustomCursor(Image cursor, Point hotSpot, String name)
1177         throws IndexOutOfBoundsException, HeadlessException
1178     {
1179         // Override to implement custom cursor support.
1180         if (this != Toolkit.getDefaultToolkit()) {
1181             return Toolkit.getDefaultToolkit().
1182                 createCustomCursor(cursor, hotSpot, name);
1183         } else {
1184             return new Cursor(Cursor.DEFAULT_CURSOR);
1185         }
1186     }


1235      * @return    the maximum number of colors, or zero if custom cursors are not
1236      * supported by this Toolkit implementation.
1237      * @exception HeadlessException if GraphicsEnvironment.isHeadless()
1238      * returns true
1239      * @see       java.awt.GraphicsEnvironment#isHeadless
1240      * @since     1.2
1241      */
1242     public int getMaximumCursorColors() throws HeadlessException {
1243         GraphicsEnvironment.checkHeadless();
1244 
1245         // Override to implement custom cursor support.
1246         if (this != Toolkit.getDefaultToolkit()) {
1247             return Toolkit.getDefaultToolkit().getMaximumCursorColors();
1248         } else {
1249             return 0;
1250         }
1251     }
1252 
1253     /**
1254      * Returns whether Toolkit supports this state for
1255      * {@code Frame}s.  This method tells whether the <em>UI
1256      * concept</em> of, say, maximization or iconification is
1257      * supported.  It will always return false for "compound" states
1258      * like {@code Frame.ICONIFIED|Frame.MAXIMIZED_VERT}.
1259      * In other words, the rule of thumb is that only queries with a
1260      * single frame state constant as an argument are meaningful.
1261      * <p>Note that supporting a given concept is a platform-
1262      * dependent feature. Due to native limitations the Toolkit
1263      * object may report a particular state as supported, however at
1264      * the same time the Toolkit object will be unable to apply the
1265      * state to a given frame.  This circumstance has two following
1266      * consequences:
1267      * <ul>
1268      * <li>Only the return value of {@code false} for the present
1269      * method actually indicates that the given state is not
1270      * supported. If the method returns {@code true} the given state
1271      * may still be unsupported and/or unavailable for a particular
1272      * frame.
1273      * <li>The developer should consider examining the value of the
1274      * {@link java.awt.event.WindowEvent#getNewState} method of the
1275      * {@code WindowEvent} received through the {@link
1276      * java.awt.event.WindowStateListener}, rather than assuming
1277      * that the state given to the {@code setExtendedState()} method
1278      * will be definitely applied. For more information see the
1279      * documentation for the {@link Frame#setExtendedState} method.
1280      * </ul>
1281      *
1282      * @param state one of named frame state constants.
1283      * @return {@code true} is this frame state is supported by
1284      *     this Toolkit implementation, {@code false} otherwise.
1285      * @exception HeadlessException
1286      *     if {@code GraphicsEnvironment.isHeadless()}
1287      *     returns {@code true}.
1288      * @see java.awt.Window#addWindowStateListener
1289      * @since   1.4
1290      */
1291     public boolean isFrameStateSupported(int state)
1292         throws HeadlessException
1293     {
1294         GraphicsEnvironment.checkHeadless();
1295 
1296         if (this != Toolkit.getDefaultToolkit()) {
1297             return Toolkit.getDefaultToolkit().
1298                 isFrameStateSupported(state);
1299         } else {
1300             return (state == Frame.NORMAL); // others are not guaranteed
1301         }
1302     }
1303 
1304     /**
1305      * Support for I18N: any visible strings should be stored in
1306      * sun.awt.resources.awt.properties.  The ResourceBundle is stored
1307      * here, so that only one copy is maintained.


1414             try {
1415                 return resources.getString(key);
1416             }
1417             catch (MissingResourceException e) {}
1418         }
1419 
1420         return defaultValue;
1421     }
1422 
1423     /**
1424      * Get the application's or applet's EventQueue instance.
1425      * Depending on the Toolkit implementation, different EventQueues
1426      * may be returned for different applets.  Applets should
1427      * therefore not assume that the EventQueue instance returned
1428      * by this method will be shared by other applets or the system.
1429      *
1430      * <p> If there is a security manager then its
1431      * {@link SecurityManager#checkPermission checkPermission} method
1432      * is called to check {@code AWTPermission("accessEventQueue")}.
1433      *
1434      * @return    the {@code EventQueue} object
1435      * @throws  SecurityException
1436      *          if a security manager is set and it denies access to
1437      *          the {@code EventQueue}
1438      * @see     java.awt.AWTPermission
1439     */
1440     public final EventQueue getSystemEventQueue() {
1441         SecurityManager security = System.getSecurityManager();
1442         if (security != null) {
1443             security.checkPermission(AWTPermissions.CHECK_AWT_EVENTQUEUE_PERMISSION);
1444         }
1445         return getSystemEventQueueImpl();
1446     }
1447 
1448     /**
1449      * Gets the application's or applet's {@code EventQueue}
1450      * instance, without checking access.  For security reasons,
1451      * this can only be called from a {@code Toolkit} subclass.
1452      * @return the {@code EventQueue} object
1453      */
1454     protected abstract EventQueue getSystemEventQueueImpl();
1455 
1456     /* Accessor method for use by AWT package routines. */
1457     static EventQueue getEventQueue() {
1458         return getDefaultToolkit().getSystemEventQueueImpl();
1459     }
1460 
1461     /**
1462      * Creates a concrete, platform dependent, subclass of the abstract
1463      * DragGestureRecognizer class requested, and associates it with the
1464      * DragSource, Component and DragGestureListener specified.
1465      *
1466      * subclasses should override this to provide their own implementation
1467      *
1468      * @param <T> the type of DragGestureRecognizer to create
1469      * @param abstractRecognizerClass The abstract class of the required recognizer
1470      * @param ds                      The DragSource
1471      * @param c                       The Component target for the DragGestureRecognizer
1472      * @param srcActions              The actions permitted for the gesture


1647      */
1648     public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) {
1649         return desktopPropsSupport.getPropertyChangeListeners(propertyName);
1650     }
1651 
1652     /**
1653      * The desktop properties.
1654      */
1655     protected final Map<String,Object> desktopProperties =
1656             new HashMap<String,Object>();
1657     /**
1658      * The desktop properties change support.
1659      */
1660     protected final PropertyChangeSupport desktopPropsSupport =
1661             Toolkit.createPropertyChangeSupport(this);
1662 
1663     /**
1664      * Returns whether the always-on-top mode is supported by this toolkit.
1665      * To detect whether the always-on-top mode is supported for a
1666      * particular Window, use {@link Window#isAlwaysOnTopSupported}.
1667      * @return {@code true}, if current toolkit supports the always-on-top mode,
1668      *     otherwise returns {@code false}
1669      * @see Window#isAlwaysOnTopSupported
1670      * @see Window#setAlwaysOnTop(boolean)
1671      * @since 1.6
1672      */
1673     public boolean isAlwaysOnTopSupported() {
1674         return true;
1675     }
1676 
1677     /**
1678      * Returns whether the given modality type is supported by this toolkit. If
1679      * a dialog with unsupported modality type is created, then
1680      * {@code Dialog.ModalityType.MODELESS} is used instead.
1681      *
1682      * @param modalityType modality type to be checked for support by this toolkit
1683      *
1684      * @return {@code true}, if current toolkit supports given modality
1685      *     type, {@code false} otherwise
1686      *
1687      * @see java.awt.Dialog.ModalityType
1688      * @see java.awt.Dialog#getModalityType
1689      * @see java.awt.Dialog#setModalityType
1690      *
1691      * @since 1.6
1692      */
1693     public abstract boolean isModalityTypeSupported(Dialog.ModalityType modalityType);
1694 
1695     /**
1696      * Returns whether the given modal exclusion type is supported by this
1697      * toolkit. If an unsupported modal exclusion type property is set on a window,
1698      * then {@code Dialog.ModalExclusionType.NO_EXCLUDE} is used instead.
1699      *
1700      * @param modalExclusionType modal exclusion type to be checked for support by this toolkit
1701      *
1702      * @return {@code true}, if current toolkit supports given modal exclusion
1703      *     type, {@code false} otherwise
1704      *
1705      * @see java.awt.Dialog.ModalExclusionType
1706      * @see java.awt.Window#getModalExclusionType
1707      * @see java.awt.Window#setModalExclusionType
1708      *
1709      * @since 1.6
1710      */
1711     public abstract boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType modalExclusionType);
1712 
1713     // 8014718: logging has been removed from SunToolkit
1714 
1715     private static final int LONG_BITS = 64;
1716     private int[] calls = new int[LONG_BITS];
1717     private static volatile long enabledOnToolkitMask;
1718     private AWTEventListener eventListener = null;
1719     private WeakHashMap<AWTEventListener, SelectiveAWTEventListener> listener2SelectiveListener = new WeakHashMap<>();
1720 
1721     /*
1722      * Extracts a "pure" AWTEventListener from a AWTEventListenerProxy,
1723      * if the listener is proxied.
1724      */
1725     private static AWTEventListener deProxyAWTEventListener(AWTEventListener l)
1726     {
1727         AWTEventListener localL = l;
1728 
1729         if (localL == null) {
1730             return null;
1731         }
1732         // if user passed in a AWTEventListenerProxy object, extract
1733         // the listener
1734         if (l instanceof AWTEventListenerProxy) {
1735             localL = ((AWTEventListenerProxy)l).getListener();
1736         }
1737         return localL;
1738     }
1739 
1740     /**
1741      * Adds an AWTEventListener to receive all AWTEvents dispatched
1742      * system-wide that conform to the given {@code eventMask}.
1743      * <p>
1744      * First, if there is a security manager, its {@code checkPermission}
1745      * method is called with an
1746      * {@code AWTPermission("listenToAllAWTEvents")} permission.
1747      * This may result in a SecurityException.
1748      * <p>
1749      * {@code eventMask} is a bitmask of event types to receive.
1750      * It is constructed by bitwise OR-ing together the event masks
1751      * defined in {@code AWTEvent}.
1752      * <p>
1753      * Note:  event listener use is not recommended for normal
1754      * application use, but are intended solely to support special
1755      * purpose facilities including support for accessibility,
1756      * event record/playback, and diagnostic tracing.
1757      *
1758      * If listener is null, no exception is thrown and no action is performed.
1759      *
1760      * @param    listener   the event listener.
1761      * @param    eventMask  the bitmask of event types to receive
1762      * @throws SecurityException
1763      *        if a security manager exists and its
1764      *        {@code checkPermission} method doesn't allow the operation.
1765      * @see      #removeAWTEventListener
1766      * @see      #getAWTEventListeners
1767      * @see      SecurityManager#checkPermission
1768      * @see      java.awt.AWTEvent
1769      * @see      java.awt.AWTPermission
1770      * @see      java.awt.event.AWTEventListener
1771      * @see      java.awt.event.AWTEventListenerProxy
1772      * @since    1.2
1773      */
1774     public void addAWTEventListener(AWTEventListener listener, long eventMask) {
1775         AWTEventListener localL = deProxyAWTEventListener(listener);
1776 
1777         if (localL == null) {
1778             return;
1779         }
1780         SecurityManager security = System.getSecurityManager();
1781         if (security != null) {
1782           security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1783         }
1784         synchronized (this) {


1798 
1799             enabledOnToolkitMask |= eventMask;
1800 
1801             long mask = eventMask;
1802             for (int i=0; i<LONG_BITS; i++) {
1803                 // If no bits are set, break out of loop.
1804                 if (mask == 0) {
1805                     break;
1806                 }
1807                 if ((mask & 1L) != 0) {  // Always test bit 0.
1808                     calls[i]++;
1809                 }
1810                 mask >>>= 1;  // Right shift, fill with zeros on left.
1811             }
1812         }
1813     }
1814 
1815     /**
1816      * Removes an AWTEventListener from receiving dispatched AWTEvents.
1817      * <p>
1818      * First, if there is a security manager, its {@code checkPermission}
1819      * method is called with an
1820      * {@code AWTPermission("listenToAllAWTEvents")} permission.
1821      * This may result in a SecurityException.
1822      * <p>
1823      * Note:  event listener use is not recommended for normal
1824      * application use, but are intended solely to support special
1825      * purpose facilities including support for accessibility,
1826      * event record/playback, and diagnostic tracing.
1827      *
1828      * If listener is null, no exception is thrown and no action is performed.
1829      *
1830      * @param    listener   the event listener.
1831      * @throws SecurityException
1832      *        if a security manager exists and its
1833      *        {@code checkPermission} method doesn't allow the operation.
1834      * @see      #addAWTEventListener
1835      * @see      #getAWTEventListeners
1836      * @see      SecurityManager#checkPermission
1837      * @see      java.awt.AWTEvent
1838      * @see      java.awt.AWTPermission
1839      * @see      java.awt.event.AWTEventListener
1840      * @see      java.awt.event.AWTEventListenerProxy
1841      * @since    1.2
1842      */
1843     public void removeAWTEventListener(AWTEventListener listener) {
1844         AWTEventListener localL = deProxyAWTEventListener(listener);
1845 
1846         if (listener == null) {
1847             return;
1848         }
1849         SecurityManager security = System.getSecurityManager();
1850         if (security != null) {
1851             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1852         }
1853 


1867                     }
1868                 }
1869             }
1870             eventListener = ToolkitEventMulticaster.remove(eventListener,
1871             (selectiveListener == null) ? localL : selectiveListener);
1872         }
1873     }
1874 
1875     static boolean enabledOnToolkit(long eventMask) {
1876         return (enabledOnToolkitMask & eventMask) != 0;
1877         }
1878 
1879     synchronized int countAWTEventListeners(long eventMask) {
1880         int ci = 0;
1881         for (; eventMask != 0; eventMask >>>= 1, ci++) {
1882         }
1883         ci--;
1884         return calls[ci];
1885     }
1886     /**
1887      * Returns an array of all the {@code AWTEventListener}s
1888      * registered on this toolkit.
1889      * If there is a security manager, its {@code checkPermission}
1890      * method is called with an
1891      * {@code AWTPermission("listenToAllAWTEvents")} permission.
1892      * This may result in a SecurityException.
1893      * Listeners can be returned
1894      * within {@code AWTEventListenerProxy} objects, which also contain
1895      * the event mask for the given listener.
1896      * Note that listener objects
1897      * added multiple times appear only once in the returned array.
1898      *
1899      * @return all of the {@code AWTEventListener}s or an empty
1900      *         array if no listeners are currently registered
1901      * @throws SecurityException
1902      *        if a security manager exists and its
1903      *        {@code checkPermission} method doesn't allow the operation.
1904      * @see      #addAWTEventListener
1905      * @see      #removeAWTEventListener
1906      * @see      SecurityManager#checkPermission
1907      * @see      java.awt.AWTEvent
1908      * @see      java.awt.AWTPermission
1909      * @see      java.awt.event.AWTEventListener
1910      * @see      java.awt.event.AWTEventListenerProxy
1911      * @since 1.4
1912      */
1913     public AWTEventListener[] getAWTEventListeners() {
1914         SecurityManager security = System.getSecurityManager();
1915         if (security != null) {
1916             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1917         }
1918         synchronized (this) {
1919             EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
1920 
1921             AWTEventListener[] ret = new AWTEventListener[la.length];
1922             for (int i = 0; i < la.length; i++) {
1923                 SelectiveAWTEventListener sael = (SelectiveAWTEventListener)la[i];
1924                 AWTEventListener tempL = sael.getListener();
1925                 //assert tempL is not an AWTEventListenerProxy - we should
1926                 // have weeded them all out
1927                 // don't want to wrap a proxy inside a proxy
1928                 ret[i] = new AWTEventListenerProxy(sael.getEventMask(), tempL);
1929             }
1930             return ret;
1931         }
1932     }
1933 
1934     /**
1935      * Returns an array of all the {@code AWTEventListener}s
1936      * registered on this toolkit which listen to all of the event
1937      * types specified in the {@code eventMask} argument.
1938      * If there is a security manager, its {@code checkPermission}
1939      * method is called with an
1940      * {@code AWTPermission("listenToAllAWTEvents")} permission.
1941      * This may result in a SecurityException.
1942      * Listeners can be returned
1943      * within {@code AWTEventListenerProxy} objects, which also contain
1944      * the event mask for the given listener.
1945      * Note that listener objects
1946      * added multiple times appear only once in the returned array.
1947      *
1948      * @param  eventMask the bitmask of event types to listen for
1949      * @return all of the {@code AWTEventListener}s registered
1950      *         on this toolkit for the specified
1951      *         event types, or an empty array if no such listeners
1952      *         are currently registered
1953      * @throws SecurityException
1954      *        if a security manager exists and its
1955      *        {@code checkPermission} method doesn't allow the operation.
1956      * @see      #addAWTEventListener
1957      * @see      #removeAWTEventListener
1958      * @see      SecurityManager#checkPermission
1959      * @see      java.awt.AWTEvent
1960      * @see      java.awt.AWTPermission
1961      * @see      java.awt.event.AWTEventListener
1962      * @see      java.awt.event.AWTEventListenerProxy
1963      * @since 1.4
1964      */
1965     public AWTEventListener[] getAWTEventListeners(long eventMask) {
1966         SecurityManager security = System.getSecurityManager();
1967         if (security != null) {
1968             security.checkPermission(AWTPermissions.ALL_AWT_EVENTS_PERMISSION);
1969         }
1970         synchronized (this) {
1971             EventListener[] la = ToolkitEventMulticaster.getListeners(eventListener,AWTEventListener.class);
1972 
1973             java.util.List<AWTEventListenerProxy> list = new ArrayList<>(la.length);
1974 
1975             for (int i = 0; i < la.length; i++) {


2150                 // int ci = (int) (Math.log(eventBit)/Math.log(2));
2151                 int ci = 0;
2152                 for (long eMask = eventBit; eMask != 0; eMask >>>= 1, ci++) {
2153                 }
2154                 ci--;
2155                 // Call the listener as many times as it was added for this
2156                 // event type.
2157                 for (int i=0; i<calls[ci]; i++) {
2158                     listener.eventDispatched(event);
2159                 }
2160             }
2161         }
2162     }
2163 
2164     /**
2165      * Returns a map of visual attributes for the abstract level description
2166      * of the given input method highlight, or null if no mapping is found.
2167      * The style field of the input method highlight is ignored. The map
2168      * returned is unmodifiable.
2169      * @param highlight input method highlight
2170      * @return style attribute map, or {@code null}
2171      * @exception HeadlessException if
2172      *     {@code GraphicsEnvironment.isHeadless} returns true
2173      * @see       java.awt.GraphicsEnvironment#isHeadless
2174      * @since 1.3
2175      */
2176     public abstract Map<java.awt.font.TextAttribute,?>
2177         mapInputMethodHighlight(InputMethodHighlight highlight)
2178         throws HeadlessException;
2179 
2180     private static PropertyChangeSupport createPropertyChangeSupport(Toolkit toolkit) {
2181         if (toolkit instanceof SunToolkit || toolkit instanceof HeadlessToolkit) {
2182             return new DesktopPropertyChangeSupport(toolkit);
2183         } else {
2184             return new PropertyChangeSupport(toolkit);
2185         }
2186     }
2187 
2188     @SuppressWarnings("serial")
2189     private static class DesktopPropertyChangeSupport extends PropertyChangeSupport {
2190 
2191         private static final StringBuilder PROP_CHANGE_SUPPORT_KEY =
2192                 new StringBuilder("desktop property change support key");


< prev index next >