91 * 92 * @return the graphics environment 93 */ 94 private static GraphicsEnvironment createGE() { 95 GraphicsEnvironment ge; 96 String nm = AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null)); 97 try { 98 // long t0 = System.currentTimeMillis(); 99 Class<?> geCls; 100 try { 101 // First we try if the bootstrap class loader finds the 102 // requested class. This way we can avoid to run in a privileged 103 // block. 104 geCls = Class.forName(nm); 105 } catch (ClassNotFoundException ex) { 106 // If the bootstrap class loader fails, we try again with the 107 // application class loader. 108 ClassLoader cl = ClassLoader.getSystemClassLoader(); 109 geCls = Class.forName(nm, true, cl); 110 } 111 ge = (GraphicsEnvironment)geCls.newInstance(); 112 // long t1 = System.currentTimeMillis(); 113 // System.out.println("GE creation took " + (t1-t0)+ "ms."); 114 if (isHeadless()) { 115 ge = new HeadlessGraphicsEnvironment(ge); 116 } 117 } catch (ClassNotFoundException e) { 118 throw new Error("Could not find class: "+nm); 119 } catch (InstantiationException e) { 120 throw new Error("Could not instantiate Graphics Environment: " 121 + nm); 122 } catch (IllegalAccessException e) { 123 throw new Error ("Could not access Graphics Environment: " 124 + nm); 125 } 126 return ge; 127 } 128 129 /** 130 * Tests whether or not a display, keyboard, and mouse can be 131 * supported in this environment. If this method returns true, 132 * a HeadlessException is thrown from areas of the Toolkit 133 * and GraphicsEnvironment that are dependent on a display, 134 * keyboard, or mouse. 135 * @return {@code true} if this environment cannot support 136 * a display, keyboard, and mouse; {@code false} 137 * otherwise 138 * @see java.awt.HeadlessException 139 * @since 1.4 140 */ 141 public static boolean isHeadless() { 142 return getHeadlessProperty(); 143 } 144 | 91 * 92 * @return the graphics environment 93 */ 94 private static GraphicsEnvironment createGE() { 95 GraphicsEnvironment ge; 96 String nm = AccessController.doPrivileged(new GetPropertyAction("java.awt.graphicsenv", null)); 97 try { 98 // long t0 = System.currentTimeMillis(); 99 Class<?> geCls; 100 try { 101 // First we try if the bootstrap class loader finds the 102 // requested class. This way we can avoid to run in a privileged 103 // block. 104 geCls = Class.forName(nm); 105 } catch (ClassNotFoundException ex) { 106 // If the bootstrap class loader fails, we try again with the 107 // application class loader. 108 ClassLoader cl = ClassLoader.getSystemClassLoader(); 109 geCls = Class.forName(nm, true, cl); 110 } 111 ge = (GraphicsEnvironment)geCls.getConstructor().newInstance(); 112 // long t1 = System.currentTimeMillis(); 113 // System.out.println("GE creation took " + (t1-t0)+ "ms."); 114 if (isHeadless()) { 115 ge = new HeadlessGraphicsEnvironment(ge); 116 } 117 } catch (ClassNotFoundException e) { 118 throw new Error("Could not find class: "+nm); 119 } catch (ReflectiveOperationException | IllegalArgumentException e) { 120 throw new Error("Could not instantiate Graphics Environment: " 121 + nm); 122 } 123 return ge; 124 } 125 126 /** 127 * Tests whether or not a display, keyboard, and mouse can be 128 * supported in this environment. If this method returns true, 129 * a HeadlessException is thrown from areas of the Toolkit 130 * and GraphicsEnvironment that are dependent on a display, 131 * keyboard, or mouse. 132 * @return {@code true} if this environment cannot support 133 * a display, keyboard, and mouse; {@code false} 134 * otherwise 135 * @see java.awt.HeadlessException 136 * @since 1.4 137 */ 138 public static boolean isHeadless() { 139 return getHeadlessProperty(); 140 } 141 |