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

Print this page




1590      */
1591     public boolean isFrameStateSupported(int state)
1592         throws HeadlessException
1593     {
1594         GraphicsEnvironment.checkHeadless();
1595 
1596         if (this != Toolkit.getDefaultToolkit()) {
1597             return Toolkit.getDefaultToolkit().
1598                 isFrameStateSupported(state);
1599         } else {
1600             return (state == Frame.NORMAL); // others are not guaranteed
1601         }
1602     }
1603 
1604     /**
1605      * Support for I18N: any visible strings should be stored in
1606      * sun.awt.resources.awt.properties.  The ResourceBundle is stored
1607      * here, so that only one copy is maintained.
1608      */
1609     private static ResourceBundle resources;


1610 
1611     /**
1612      * Initialize JNI field and method ids
1613      */
1614     private static native void initIDs();
1615 
1616     /**
1617      * WARNING: This is a temporary workaround for a problem in the
1618      * way the AWT loads native libraries. A number of classes in the
1619      * AWT package have a native method, initIDs(), which initializes
1620      * the JNI field and method ids used in the native portion of
1621      * their implementation.
1622      *
1623      * Since the use and storage of these ids is done by the
1624      * implementation libraries, the implementation of these method is
1625      * provided by the particular AWT implementations (for example,
1626      * "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The
1627      * problem is that this means that the native libraries must be
1628      * loaded by the java.* classes, which do not necessarily know the
1629      * names of the libraries to load. A better way of doing this


1638      * java.awt.image.ColorModel.loadLibraries(). Unfortunately,
1639      * classes can be loaded in java.awt.image that depend on
1640      * libawt and there is no way to call Toolkit.loadLibraries()
1641      * directly.  -hung
1642      */
1643     private static boolean loaded = false;
1644     static void loadLibraries() {
1645         if (!loaded) {
1646             java.security.AccessController.doPrivileged(
1647                 new java.security.PrivilegedAction<Void>() {
1648                     public Void run() {
1649                         System.loadLibrary("awt");
1650                         return null;
1651                     }
1652                 });
1653             loaded = true;
1654         }
1655     }
1656 
1657     static {









1658         java.security.AccessController.doPrivileged(
1659                                  new java.security.PrivilegedAction<Void>() {
1660             public Void run() {
1661                 try {
1662                     resources =
1663                         ResourceBundle.getBundle("sun.awt.resources.awt",
1664                                                  CoreResourceBundleControl.getRBControlInstance());






1665                 } catch (MissingResourceException e) {
1666                     // No resource file; defaults will be used.
1667                 }
1668                 return null;
1669             }
1670         });
1671 
1672         // ensure that the proper libraries are loaded
1673         loadLibraries();
1674         initAssistiveTechnologies();
1675         if (!GraphicsEnvironment.isHeadless()) {
1676             initIDs();
1677         }
1678     }
1679 
1680     /**
1681      * Gets a property with the specified key and default.
1682      * This method returns defaultValue if the property is not found.
1683      */
1684     public static String getProperty(String key, String defaultValue) {









1685         if (resources != null) {
1686             try {
1687                 return resources.getString(key);
1688             }
1689             catch (MissingResourceException e) {}
1690         }
1691 
1692         return defaultValue;
1693     }
1694 
1695     /**
1696      * Get the application's or applet's EventQueue instance.
1697      * Depending on the Toolkit implementation, different EventQueues
1698      * may be returned for different applets.  Applets should
1699      * therefore not assume that the EventQueue instance returned
1700      * by this method will be shared by other applets or the system.
1701      *
1702      * <p>First, if there is a security manager, its
1703      * <code>checkAwtEventQueueAccess</code>
1704      * method is called.




1590      */
1591     public boolean isFrameStateSupported(int state)
1592         throws HeadlessException
1593     {
1594         GraphicsEnvironment.checkHeadless();
1595 
1596         if (this != Toolkit.getDefaultToolkit()) {
1597             return Toolkit.getDefaultToolkit().
1598                 isFrameStateSupported(state);
1599         } else {
1600             return (state == Frame.NORMAL); // others are not guaranteed
1601         }
1602     }
1603 
1604     /**
1605      * Support for I18N: any visible strings should be stored in
1606      * sun.awt.resources.awt.properties.  The ResourceBundle is stored
1607      * here, so that only one copy is maintained.
1608      */
1609     private static ResourceBundle resources;
1610     private static ResourceBundle platformResources;
1611 
1612 
1613     /**
1614      * Initialize JNI field and method ids
1615      */
1616     private static native void initIDs();
1617 
1618     /**
1619      * WARNING: This is a temporary workaround for a problem in the
1620      * way the AWT loads native libraries. A number of classes in the
1621      * AWT package have a native method, initIDs(), which initializes
1622      * the JNI field and method ids used in the native portion of
1623      * their implementation.
1624      *
1625      * Since the use and storage of these ids is done by the
1626      * implementation libraries, the implementation of these method is
1627      * provided by the particular AWT implementations (for example,
1628      * "Toolkit"s/Peer), such as Motif, Microsoft Windows, or Tiny. The
1629      * problem is that this means that the native libraries must be
1630      * loaded by the java.* classes, which do not necessarily know the
1631      * names of the libraries to load. A better way of doing this


1640      * java.awt.image.ColorModel.loadLibraries(). Unfortunately,
1641      * classes can be loaded in java.awt.image that depend on
1642      * libawt and there is no way to call Toolkit.loadLibraries()
1643      * directly.  -hung
1644      */
1645     private static boolean loaded = false;
1646     static void loadLibraries() {
1647         if (!loaded) {
1648             java.security.AccessController.doPrivileged(
1649                 new java.security.PrivilegedAction<Void>() {
1650                     public Void run() {
1651                         System.loadLibrary("awt");
1652                         return null;
1653                     }
1654                 });
1655             loaded = true;
1656         }
1657     }
1658 
1659     static {
1660         String osname = System.getProperty("os.name");
1661 
1662         final String platformSuffix;
1663         if (osname.contains("OS X")) {
1664             platformSuffix = "osx";
1665         }  else {
1666             platformSuffix = null;
1667         }
1668 
1669         java.security.AccessController.doPrivileged(
1670                                  new java.security.PrivilegedAction<Void>() {
1671             public Void run() {
1672                 try {
1673                     resources =
1674                         ResourceBundle.getBundle("sun.awt.resources.awt",
1675                                                  CoreResourceBundleControl.getRBControlInstance());
1676                     if (platformSuffix != null) {
1677                         platformResources =
1678                             ResourceBundle.getBundle("sun.awt.resources.awt" + platformSuffix,
1679                                                  CoreResourceBundleControl.getRBControlInstance());
1680                     }
1681 
1682                 } catch (MissingResourceException e) {
1683                     // No resource file; defaults will be used.
1684                 }
1685                 return null;
1686             }
1687         });
1688 
1689         // ensure that the proper libraries are loaded
1690         loadLibraries();
1691         initAssistiveTechnologies();
1692         if (!GraphicsEnvironment.isHeadless()) {
1693             initIDs();
1694         }
1695     }
1696 
1697     /**
1698      * Gets a property with the specified key and default.
1699      * This method returns defaultValue if the property is not found.
1700      */
1701     public static String getProperty(String key, String defaultValue) {
1702         // first try platform specific bundle
1703         if (platformResources != null) {
1704             try {
1705                 return platformResources.getString(key);
1706             }
1707             catch (MissingResourceException e) {}
1708         }
1709 
1710         // then shared one
1711         if (resources != null) {
1712             try {
1713                 return resources.getString(key);
1714             }
1715             catch (MissingResourceException e) {}
1716         }
1717 
1718         return defaultValue;
1719     }
1720 
1721     /**
1722      * Get the application's or applet's EventQueue instance.
1723      * Depending on the Toolkit implementation, different EventQueues
1724      * may be returned for different applets.  Applets should
1725      * therefore not assume that the EventQueue instance returned
1726      * by this method will be shared by other applets or the system.
1727      *
1728      * <p>First, if there is a security manager, its
1729      * <code>checkAwtEventQueueAccess</code>
1730      * method is called.