1 /*
2 * Copyright (c) 1997, 2013, 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
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 = 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 /**
128 * Tests whether or not a display, keyboard, and mouse can be
129 * supported in this environment. If this method returns true,
|
1 /*
2 * Copyright (c) 1997, 2014, 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
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.class.cast(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 /**
128 * Tests whether or not a display, keyboard, and mouse can be
129 * supported in this environment. If this method returns true,
|