< prev index next >

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

Print this page




  61 import java.util.ArrayList;
  62 import java.util.Arrays;
  63 import java.util.EventListener;
  64 import java.util.HashMap;
  65 import java.util.Map;
  66 import java.util.MissingResourceException;
  67 import java.util.Properties;
  68 import java.util.ResourceBundle;
  69 import java.util.ServiceLoader;
  70 import java.util.Set;
  71 import java.util.WeakHashMap;
  72 import java.util.stream.Collectors;
  73 
  74 import javax.accessibility.AccessibilityProvider;
  75 
  76 import sun.awt.AWTAccessor;
  77 import sun.awt.AWTPermissions;
  78 import sun.awt.AppContext;
  79 import sun.awt.HeadlessToolkit;
  80 import sun.awt.PeerEvent;

  81 import sun.awt.SunToolkit;
  82 
  83 /**
  84  * This class is the abstract superclass of all actual
  85  * implementations of the Abstract Window Toolkit. Subclasses of
  86  * the {@code Toolkit} class are used to bind the various components
  87  * to particular native toolkit implementations.
  88  * <p>
  89  * Many GUI events may be delivered to user
  90  * asynchronously, if the opposite is not specified explicitly.
  91  * As well as
  92  * many GUI operations may be performed asynchronously.
  93  * This fact means that if the state of a component is set, and then
  94  * the state immediately queried, the returned value may not yet
  95  * reflect the requested change.  This behavior includes, but is not
  96  * limited to:
  97  * <ul>
  98  * <li>Scrolling to a specified position.
  99  * <br>For example, calling {@code ScrollPane.setScrollPosition}
 100  *     and then {@code getScrollPosition} may return an incorrect


 565      * <p>
 566      * The names specified in the assistive_technologies property are used to query
 567      * each service provider implementation.  If the requested name matches the
 568      * {@linkplain AccessibilityProvider#getName name} of the service provider, the
 569      * {@link AccessibilityProvider#activate} method will be invoked to activate the
 570      * matching service provider.
 571      *
 572      * @implSpec
 573      * If assistive technology service providers are not specified with a system
 574      * property this implementation will look in a properties file located as follows:
 575      * <ul>
 576      * <li> {@code ${user.home}/.accessibility.properties}
 577      * <li> {@code ${java.home}/conf/accessibility.properties}
 578      * </ul>
 579      * Only the first of these files to be located will be consulted.  The requested
 580      * service providers are specified by setting the {@code assistive_technologies=}
 581      * property.  A single provider or a comma separated list of providers can be
 582      * specified.
 583      *
 584      * @return     the default toolkit.
 585      * @exception  AWTError  if a toolkit could not be found, or
 586      *                 if one could not be accessed or instantiated.
 587      * @see java.util.ServiceLoader
 588      * @see javax.accessibility.AccessibilityProvider
 589      */
 590     public static synchronized Toolkit getDefaultToolkit() {
 591         if (toolkit == null) {
 592             java.security.AccessController.doPrivileged(
 593                     new java.security.PrivilegedAction<Void>() {
 594                 public Void run() {
 595                     Class<?> cls = null;
 596                     String nm = System.getProperty("awt.toolkit");
 597                     try {
 598                         cls = Class.forName(nm);
 599                     } catch (ClassNotFoundException e) {
 600                         ClassLoader cl = ClassLoader.getSystemClassLoader();
 601                         if (cl != null) {
 602                             try {
 603                                 cls = cl.loadClass(nm);
 604                             } catch (final ClassNotFoundException ignored) {
 605                                 throw new AWTError("Toolkit not found: " + nm);
 606                             }
 607                         }
 608                     }
 609                     try {
 610                         if (cls != null) {
 611                             toolkit = (Toolkit)cls.getConstructor().newInstance();
 612                             if (GraphicsEnvironment.isHeadless()) {
 613                                 toolkit = new HeadlessToolkit(toolkit);
 614                             }
 615                         }
 616                     } catch (final ReflectiveOperationException ignored) {
 617                         throw new AWTError("Could not create Toolkit: " + nm);
 618                     }
 619                     return null;
 620                 }
 621             });
 622             if (!GraphicsEnvironment.isHeadless()) {
 623                 loadAssistiveTechnologies();
 624             }
 625         }
 626         return toolkit;
 627     }
 628 
 629     /**
 630      * Returns an image which gets pixel data from the specified file,
 631      * whose format can be either GIF, JPEG or PNG.
 632      * The underlying toolkit attempts to resolve multiple requests
 633      * with the same filename to the same returned Image.
 634      * <p>
 635      * Since the mechanism required to facilitate this sharing of
 636      * {@code Image} objects may continue to hold onto images
 637      * that are no longer in use for an indefinite period of time,
 638      * developers are encouraged to implement their own caching of
 639      * images by using the {@link #createImage(java.lang.String) createImage}
 640      * variant wherever available.
 641      * If the image data contained in the specified file changes,




  61 import java.util.ArrayList;
  62 import java.util.Arrays;
  63 import java.util.EventListener;
  64 import java.util.HashMap;
  65 import java.util.Map;
  66 import java.util.MissingResourceException;
  67 import java.util.Properties;
  68 import java.util.ResourceBundle;
  69 import java.util.ServiceLoader;
  70 import java.util.Set;
  71 import java.util.WeakHashMap;
  72 import java.util.stream.Collectors;
  73 
  74 import javax.accessibility.AccessibilityProvider;
  75 
  76 import sun.awt.AWTAccessor;
  77 import sun.awt.AWTPermissions;
  78 import sun.awt.AppContext;
  79 import sun.awt.HeadlessToolkit;
  80 import sun.awt.PeerEvent;
  81 import sun.awt.PlatformGraphicsInfo;
  82 import sun.awt.SunToolkit;
  83 
  84 /**
  85  * This class is the abstract superclass of all actual
  86  * implementations of the Abstract Window Toolkit. Subclasses of
  87  * the {@code Toolkit} class are used to bind the various components
  88  * to particular native toolkit implementations.
  89  * <p>
  90  * Many GUI events may be delivered to user
  91  * asynchronously, if the opposite is not specified explicitly.
  92  * As well as
  93  * many GUI operations may be performed asynchronously.
  94  * This fact means that if the state of a component is set, and then
  95  * the state immediately queried, the returned value may not yet
  96  * reflect the requested change.  This behavior includes, but is not
  97  * limited to:
  98  * <ul>
  99  * <li>Scrolling to a specified position.
 100  * <br>For example, calling {@code ScrollPane.setScrollPosition}
 101  *     and then {@code getScrollPosition} may return an incorrect


 566      * <p>
 567      * The names specified in the assistive_technologies property are used to query
 568      * each service provider implementation.  If the requested name matches the
 569      * {@linkplain AccessibilityProvider#getName name} of the service provider, the
 570      * {@link AccessibilityProvider#activate} method will be invoked to activate the
 571      * matching service provider.
 572      *
 573      * @implSpec
 574      * If assistive technology service providers are not specified with a system
 575      * property this implementation will look in a properties file located as follows:
 576      * <ul>
 577      * <li> {@code ${user.home}/.accessibility.properties}
 578      * <li> {@code ${java.home}/conf/accessibility.properties}
 579      * </ul>
 580      * Only the first of these files to be located will be consulted.  The requested
 581      * service providers are specified by setting the {@code assistive_technologies=}
 582      * property.  A single provider or a comma separated list of providers can be
 583      * specified.
 584      *
 585      * @return     the default toolkit.
 586      * @throws  AWTError in case of an error loading assistive technologies.

 587      * @see java.util.ServiceLoader
 588      * @see javax.accessibility.AccessibilityProvider
 589      */
 590     public static synchronized Toolkit getDefaultToolkit() {
 591         if (toolkit == null) {
 592             toolkit = PlatformGraphicsInfo.createToolkit();
 593             if (GraphicsEnvironment.isHeadless() &&
 594                 !(toolkit instanceof HeadlessToolkit)) {


















 595                 toolkit = new HeadlessToolkit(toolkit);
 596             }







 597             if (!GraphicsEnvironment.isHeadless()) {
 598                 loadAssistiveTechnologies();
 599             }
 600         }
 601         return toolkit;
 602     }
 603 
 604     /**
 605      * Returns an image which gets pixel data from the specified file,
 606      * whose format can be either GIF, JPEG or PNG.
 607      * The underlying toolkit attempts to resolve multiple requests
 608      * with the same filename to the same returned Image.
 609      * <p>
 610      * Since the mechanism required to facilitate this sharing of
 611      * {@code Image} objects may continue to hold onto images
 612      * that are no longer in use for an indefinite period of time,
 613      * developers are encouraged to implement their own caching of
 614      * images by using the {@link #createImage(java.lang.String) createImage}
 615      * variant wherever available.
 616      * If the image data contained in the specified file changes,


< prev index next >