< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 152      */
 153     static String getHeadlessMessage() {
 154         if (headless == null) {
 155             getHeadlessProperty(); // initialize the values
 156         }
 157         return defaultHeadless != Boolean.TRUE ? null :
 158             "\nNo X11 DISPLAY variable was set, " +
 159             "but this program performed an operation which requires it.";
 160     }
 161 
 162     /**
 163      * @return the value of the property "java.awt.headless"
 164      * @since 1.4
 165      */
 166     private static boolean getHeadlessProperty() {
 167         if (headless == null) {
 168             AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 169                 String nm = System.getProperty("java.awt.headless");
 170 
 171                 if (nm == null) {
 172                     /* No need to ask for DISPLAY when run in a browser */
 173                     if (System.getProperty("javaplugin.version") != null) {
 174                         headless = defaultHeadless = Boolean.FALSE;
 175                     } else {
 176                         String osName = System.getProperty("os.name");
 177                         if (osName.contains("OS X") && "sun.awt.HToolkit".equals(
 178                                 System.getProperty("awt.toolkit")))
 179                         {
 180                             headless = defaultHeadless = Boolean.TRUE;
 181                         } else {
 182                             final String display = System.getenv("DISPLAY");
 183                             headless = defaultHeadless =
 184                                 ("Linux".equals(osName) ||
 185                                  "SunOS".equals(osName) ||
 186                                  "FreeBSD".equals(osName) ||
 187                                  "NetBSD".equals(osName) ||
 188                                  "OpenBSD".equals(osName) ||
 189                                  "AIX".equals(osName)) &&
 190                                  (display == null || display.trim().isEmpty());
 191                         }
 192                     }
 193                 } else {
 194                     headless = Boolean.valueOf(nm);
 195                 }
 196                 return null;
 197             });
 198         }
 199         return headless;
 200     }
 201 
 202     /**
 203      * Check for headless state and throw HeadlessException if headless
 204      * @since 1.4
 205      */
 206     static void checkHeadless() throws HeadlessException {
 207         if (isHeadless()) {
 208             throw new HeadlessException();
 209         }
 210     }
 211 
 212     /**


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 152      */
 153     static String getHeadlessMessage() {
 154         if (headless == null) {
 155             getHeadlessProperty(); // initialize the values
 156         }
 157         return defaultHeadless != Boolean.TRUE ? null :
 158             "\nNo X11 DISPLAY variable was set, " +
 159             "but this program performed an operation which requires it.";
 160     }
 161 
 162     /**
 163      * @return the value of the property "java.awt.headless"
 164      * @since 1.4
 165      */
 166     private static boolean getHeadlessProperty() {
 167         if (headless == null) {
 168             AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 169                 String nm = System.getProperty("java.awt.headless");
 170 
 171                 if (nm == null) {
 172                     final String osName = System.getProperty("os.name");









 173                     final String display = System.getenv("DISPLAY");
 174                     headless = defaultHeadless =
 175                                 ("Linux".equals(osName) ||
 176                                  "SunOS".equals(osName) ||
 177                                  "FreeBSD".equals(osName) ||
 178                                  "NetBSD".equals(osName) ||
 179                                  "OpenBSD".equals(osName) ||
 180                                  "AIX".equals(osName)) &&
 181                                  (display == null || display.trim().isEmpty());


 182                 } else {
 183                     headless = Boolean.valueOf(nm);
 184                 }
 185                 return null;
 186             });
 187         }
 188         return headless;
 189     }
 190 
 191     /**
 192      * Check for headless state and throw HeadlessException if headless
 193      * @since 1.4
 194      */
 195     static void checkHeadless() throws HeadlessException {
 196         if (isHeadless()) {
 197             throw new HeadlessException();
 198         }
 199     }
 200 
 201     /**


< prev index next >