src/share/classes/java/awt/GraphicsEnvironment.java

Print this page




  78      */
  79     public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
  80         if (localEnv == null) {
  81             localEnv = createGE();
  82         }
  83 
  84         return localEnv;
  85     }
  86 
  87     /**
  88      * Creates and returns the GraphicsEnvironment, according to the
  89      * system property 'java.awt.graphicsenv'.
  90      *
  91      * @return the graphics environment
  92      */
  93     private static GraphicsEnvironment createGE() {
  94         GraphicsEnvironment ge;
  95         String nm = AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null));
  96         try {
  97 //          long t0 = System.currentTimeMillis();
  98             Class geCls;
  99             try {
 100                 // First we try if the bootclassloader finds the requested
 101                 // class. This way we can avoid to run in a privileged block.
 102                 geCls = Class.forName(nm);
 103             } catch (ClassNotFoundException ex) {
 104                 // If the bootclassloader fails, we try again with the
 105                 // application classloader.
 106                 ClassLoader cl = ClassLoader.getSystemClassLoader();
 107                 geCls = Class.forName(nm, true, cl);
 108             }
 109             ge = (GraphicsEnvironment) geCls.newInstance();
 110 //          long t1 = System.currentTimeMillis();
 111 //          System.out.println("GE creation took " + (t1-t0)+ "ms.");
 112             if (isHeadless()) {
 113                 ge = new HeadlessGraphicsEnvironment(ge);
 114             }
 115         } catch (ClassNotFoundException e) {
 116             throw new Error("Could not find class: "+nm);
 117         } catch (InstantiationException e) {
 118             throw new Error("Could not instantiate Graphics Environment: "
 119                             + nm);
 120         } catch (IllegalAccessException e) {
 121             throw new Error ("Could not access Graphics Environment: "
 122                              + nm);
 123         }
 124         return ge;
 125     }
 126 
 127     /**


 144      * @return warning message if headless state is assumed by default;
 145      * null otherwise
 146      * @since 1.5
 147      */
 148     static String getHeadlessMessage() {
 149         if (headless == null) {
 150             getHeadlessProperty(); // initialize the values
 151         }
 152         return defaultHeadless != Boolean.TRUE ? null :
 153             "\nNo X11 DISPLAY variable was set, " +
 154             "but this program performed an operation which requires it.";
 155     }
 156 
 157     /**
 158      * @return the value of the property "java.awt.headless"
 159      * @since 1.4
 160      */
 161     private static boolean getHeadlessProperty() {
 162         if (headless == null) {
 163             java.security.AccessController.doPrivileged(
 164             new java.security.PrivilegedAction() {
 165                 public Object run() {
 166                     String nm = System.getProperty("java.awt.headless");
 167 
 168                     if (nm == null) {
 169                         /* No need to ask for DISPLAY when run in a browser */
 170                         if (System.getProperty("javaplugin.version") != null) {
 171                             headless = defaultHeadless = Boolean.FALSE;
 172                         } else {
 173                             String osName = System.getProperty("os.name");
 174                             if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
 175                                     System.getProperty("awt.toolkit")))
 176                             {
 177                                 headless = defaultHeadless = Boolean.TRUE;
 178                             } else {
 179                                 headless = defaultHeadless =
 180                                     Boolean.valueOf(("Linux".equals(osName) ||
 181                                                      "SunOS".equals(osName) ||
 182                                                      "FreeBSD".equals(osName) ||
 183                                                      "NetBSD".equals(osName) ||
 184                                                      "OpenBSD".equals(osName)) &&




  78      */
  79     public static synchronized GraphicsEnvironment getLocalGraphicsEnvironment() {
  80         if (localEnv == null) {
  81             localEnv = createGE();
  82         }
  83 
  84         return localEnv;
  85     }
  86 
  87     /**
  88      * Creates and returns the GraphicsEnvironment, according to the
  89      * system property 'java.awt.graphicsenv'.
  90      *
  91      * @return the graphics environment
  92      */
  93     private static GraphicsEnvironment createGE() {
  94         GraphicsEnvironment ge;
  95         String nm = AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null));
  96         try {
  97 //          long t0 = System.currentTimeMillis();
  98             Class<GraphicsEnvironment> geCls;
  99             try {
 100                 // First we try if the bootclassloader finds the requested
 101                 // class. This way we can avoid to run in a privileged block.
 102                 geCls = (Class<GraphicsEnvironment>)Class.forName(nm);
 103             } catch (ClassNotFoundException ex) {
 104                 // If the bootclassloader fails, we try again with the
 105                 // application classloader.
 106                 ClassLoader cl = ClassLoader.getSystemClassLoader();
 107                 geCls = (Class<GraphicsEnvironment>)Class.forName(nm, true, cl);
 108             }
 109             ge = (GraphicsEnvironment) geCls.newInstance();
 110 //          long t1 = System.currentTimeMillis();
 111 //          System.out.println("GE creation took " + (t1-t0)+ "ms.");
 112             if (isHeadless()) {
 113                 ge = new HeadlessGraphicsEnvironment(ge);
 114             }
 115         } catch (ClassNotFoundException e) {
 116             throw new Error("Could not find class: "+nm);
 117         } catch (InstantiationException e) {
 118             throw new Error("Could not instantiate Graphics Environment: "
 119                             + nm);
 120         } catch (IllegalAccessException e) {
 121             throw new Error ("Could not access Graphics Environment: "
 122                              + nm);
 123         }
 124         return ge;
 125     }
 126 
 127     /**


 144      * @return warning message if headless state is assumed by default;
 145      * null otherwise
 146      * @since 1.5
 147      */
 148     static String getHeadlessMessage() {
 149         if (headless == null) {
 150             getHeadlessProperty(); // initialize the values
 151         }
 152         return defaultHeadless != Boolean.TRUE ? null :
 153             "\nNo X11 DISPLAY variable was set, " +
 154             "but this program performed an operation which requires it.";
 155     }
 156 
 157     /**
 158      * @return the value of the property "java.awt.headless"
 159      * @since 1.4
 160      */
 161     private static boolean getHeadlessProperty() {
 162         if (headless == null) {
 163             java.security.AccessController.doPrivileged(
 164             new java.security.PrivilegedAction<Object>() {
 165                 public Object run() {
 166                     String nm = System.getProperty("java.awt.headless");
 167 
 168                     if (nm == null) {
 169                         /* No need to ask for DISPLAY when run in a browser */
 170                         if (System.getProperty("javaplugin.version") != null) {
 171                             headless = defaultHeadless = Boolean.FALSE;
 172                         } else {
 173                             String osName = System.getProperty("os.name");
 174                             if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
 175                                     System.getProperty("awt.toolkit")))
 176                             {
 177                                 headless = defaultHeadless = Boolean.TRUE;
 178                             } else {
 179                                 headless = defaultHeadless =
 180                                     Boolean.valueOf(("Linux".equals(osName) ||
 181                                                      "SunOS".equals(osName) ||
 182                                                      "FreeBSD".equals(osName) ||
 183                                                      "NetBSD".equals(osName) ||
 184                                                      "OpenBSD".equals(osName)) &&