< prev index next >

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

Print this page




 451      *
 452      * @param s the error message
 453      * @param e the original exception
 454      * @throws the new AWTError including the cause (the original exception)
 455      */
 456     private static void newAWTError(Throwable e, String s) {
 457         AWTError newAWTError = new AWTError(s);
 458         newAWTError.initCause(e);
 459         throw newAWTError;
 460     }
 461 
 462     /**
 463      * When a service provider for Assistive Technology is not found look for a
 464      * supporting class on the class path and instantiate it.
 465      *
 466      * @param atName the name of the class to be loaded
 467      */
 468     private static void fallbackToLoadClassForAT(String atName) {
 469         try {
 470             Class<?> c = Class.forName(atName, false, ClassLoader.getSystemClassLoader());
 471             c.newInstance();
 472         } catch (ClassNotFoundException e) {
 473             newAWTError(e, "Assistive Technology not found: " + atName);
 474         } catch (InstantiationException e) {
 475             newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
 476         } catch (IllegalAccessException e) {
 477             newAWTError(e, "Could not access Assistive Technology: " + atName);
 478         } catch (Exception e) {
 479             newAWTError(e, "Error trying to install Assistive Technology: " + atName);
 480         }
 481     }
 482 
 483     /**
 484      * Loads accessibility support using the property assistive_technologies.
 485      * The form is assistive_technologies= followed by a comma-separated list of
 486      * assistive technology providers to load.  The order in which providers are
 487      * loaded is determined by the order in which the ServiceLoader discovers
 488      * implementations of the AccessibilityProvider interface, not by the order
 489      * of provider names in the property list.  When a provider is found its
 490      * accessibility implementation will be started by calling the provider's
 491      * activate method.  All errors are handled via an AWTError exception.


 566         if (toolkit == null) {
 567             java.security.AccessController.doPrivileged(
 568                     new java.security.PrivilegedAction<Void>() {
 569                 public Void run() {
 570                     Class<?> cls = null;
 571                     String nm = System.getProperty("awt.toolkit");
 572                     try {
 573                         cls = Class.forName(nm);
 574                     } catch (ClassNotFoundException e) {
 575                         ClassLoader cl = ClassLoader.getSystemClassLoader();
 576                         if (cl != null) {
 577                             try {
 578                                 cls = cl.loadClass(nm);
 579                             } catch (final ClassNotFoundException ignored) {
 580                                 throw new AWTError("Toolkit not found: " + nm);
 581                             }
 582                         }
 583                     }
 584                     try {
 585                         if (cls != null) {
 586                             toolkit = (Toolkit)cls.newInstance();
 587                             if (GraphicsEnvironment.isHeadless()) {
 588                                 toolkit = new HeadlessToolkit(toolkit);
 589                             }
 590                         }
 591                     } catch (final InstantiationException ignored) {
 592                         throw new AWTError("Could not instantiate Toolkit: " + nm);
 593                     } catch (final IllegalAccessException ignored) {
 594                         throw new AWTError("Could not access Toolkit: " + nm);
 595                     }
 596                     return null;
 597                 }
 598             });
 599             if (!GraphicsEnvironment.isHeadless()) {
 600                 loadAssistiveTechnologies();
 601             }
 602         }
 603         return toolkit;
 604     }
 605 
 606     /**
 607      * Returns an image which gets pixel data from the specified file,
 608      * whose format can be either GIF, JPEG or PNG.
 609      * The underlying toolkit attempts to resolve multiple requests
 610      * with the same filename to the same returned Image.
 611      * <p>
 612      * Since the mechanism required to facilitate this sharing of
 613      * {@code Image} objects may continue to hold onto images
 614      * that are no longer in use for an indefinite period of time,




 451      *
 452      * @param s the error message
 453      * @param e the original exception
 454      * @throws the new AWTError including the cause (the original exception)
 455      */
 456     private static void newAWTError(Throwable e, String s) {
 457         AWTError newAWTError = new AWTError(s);
 458         newAWTError.initCause(e);
 459         throw newAWTError;
 460     }
 461 
 462     /**
 463      * When a service provider for Assistive Technology is not found look for a
 464      * supporting class on the class path and instantiate it.
 465      *
 466      * @param atName the name of the class to be loaded
 467      */
 468     private static void fallbackToLoadClassForAT(String atName) {
 469         try {
 470             Class<?> c = Class.forName(atName, false, ClassLoader.getSystemClassLoader());
 471             c.getConstructor().newInstance();
 472         } catch (ClassNotFoundException e) {
 473             newAWTError(e, "Assistive Technology not found: " + atName);
 474         } catch (InstantiationException e) {
 475             newAWTError(e, "Could not instantiate Assistive Technology: " + atName);
 476         } catch (IllegalAccessException e) {
 477             newAWTError(e, "Could not access Assistive Technology: " + atName);
 478         } catch (Exception e) {
 479             newAWTError(e, "Error trying to install Assistive Technology: " + atName);
 480         }
 481     }
 482 
 483     /**
 484      * Loads accessibility support using the property assistive_technologies.
 485      * The form is assistive_technologies= followed by a comma-separated list of
 486      * assistive technology providers to load.  The order in which providers are
 487      * loaded is determined by the order in which the ServiceLoader discovers
 488      * implementations of the AccessibilityProvider interface, not by the order
 489      * of provider names in the property list.  When a provider is found its
 490      * accessibility implementation will be started by calling the provider's
 491      * activate method.  All errors are handled via an AWTError exception.


 566         if (toolkit == null) {
 567             java.security.AccessController.doPrivileged(
 568                     new java.security.PrivilegedAction<Void>() {
 569                 public Void run() {
 570                     Class<?> cls = null;
 571                     String nm = System.getProperty("awt.toolkit");
 572                     try {
 573                         cls = Class.forName(nm);
 574                     } catch (ClassNotFoundException e) {
 575                         ClassLoader cl = ClassLoader.getSystemClassLoader();
 576                         if (cl != null) {
 577                             try {
 578                                 cls = cl.loadClass(nm);
 579                             } catch (final ClassNotFoundException ignored) {
 580                                 throw new AWTError("Toolkit not found: " + nm);
 581                             }
 582                         }
 583                     }
 584                     try {
 585                         if (cls != null) {
 586                             toolkit = (Toolkit)cls.getConstructor().newInstance();
 587                             if (GraphicsEnvironment.isHeadless()) {
 588                                 toolkit = new HeadlessToolkit(toolkit);
 589                             }
 590                         }
 591                     } catch (final ReflectiveOperationException ignored) {
 592                         throw new AWTError("Could not create Toolkit: " + nm);


 593                     }
 594                     return null;
 595                 }
 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,


< prev index next >