public class Foo() { private static final Color COLOR_BACKGROUND = Color.WHITE; static { /* too late ! */ System.setProperty("java.awt.headless", "true"); System.out.println(java.awt.GraphicsEnvironment.isHeadless()); /* ---> prints false */ } public static void main() {} }
@Override public void showErrorDialog(String message) { if (!GraphicsEnvironment.isHeadless()) { final String msg = message; EventQueue.invokeLater(new Runnable() { public void run() { ErrorDialog.showDialog(msg); } }); } else { System.err.println("[JME ERROR] " + message); } }
@Override public boolean openURI (String URI) { boolean result = false; try { if (!GraphicsEnvironment.isHeadless() && Desktop.isDesktopSupported()) { if (Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop.getDesktop().browse(java.net.URI.create(URI)); result = true; } } else { Gdx.app.error("HeadlessNet", "Opening URIs on this environment is not supported. Ignoring."); } } catch (Throwable t) { Gdx.app.error("HeadlessNet", "Failed to open URI. ", t); } return result; } }
@Override public boolean openURI (String URI) { boolean result = false; try { if (!GraphicsEnvironment.isHeadless() && Desktop.isDesktopSupported()) { if (Desktop.getDesktop().isSupported(Action.BROWSE)) { Desktop.getDesktop().browse(java.net.URI.create(URI)); result = true; } } else { Gdx.app.error("HeadlessNet", "Opening URIs on this environment is not supported. Ignoring."); } } catch (Throwable t) { Gdx.app.error("HeadlessNet", "Failed to open URI. ", t); } return result; } }
private static int getMenuShortcutKeyMask() { // #152050 - work in headless environment too try { if (!GraphicsEnvironment.isHeadless()) { return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); } } catch (Throwable ex) { // OK, just assume we are headless } return Event.CTRL_MASK; }
private static void reportException(Throwable throwable) { Path logPath = LoggingContext.getLoggingPath(); if (!GraphicsEnvironment.isHeadless() && crashReportEnabled) { CrashReporter.report(throwable, logPath); } else { throwable.printStackTrace(); System.err.println("For more details, see the log files in " + logPath.toAbsolutePath().normalize()); } }
/** * The main method which throws a {@link PEBKACException} with some basic * information on how sponge works. * * @param args The program args * @throws PEBKACException always */ public static void main(String[] args) throws PEBKACException { if (!GraphicsEnvironment.isHeadless()) { JOptionPane.showMessageDialog(null, ERROR, "PEBKACException!", JOptionPane.ERROR_MESSAGE); } else { throw new PEBKACException(ERROR); } }
public InputStream progressMonitoredInputStream(InputStream in, int length, String msg) { if (GraphicsEnvironment.isHeadless()) { return in; } IGuiCallback guiCallback = project.getGuiCallback(); return guiCallback.getProgressMonitorInputStream(in, length, msg); }
/** * Launch the appropriate UI. * * @throws java.lang.Exception */ public void launch() throws Exception { // Sanity-check the loaded BCEL classes if (!CheckBcel.check()) { System.exit(1); } int launchProperty = getLaunchProperty(); if (GraphicsEnvironment.isHeadless() || launchProperty == TEXTUI) { FindBugs2.main(args); } else if (launchProperty == SHOW_HELP) { ShowHelp.main(args); } else if (launchProperty == SHOW_VERSION) { Version.main(new String[] { "-release" }); } else { Class<?> launchClass = Class.forName("edu.umd.cs.findbugs.gui2.Driver"); Method mainMethod = launchClass.getMethod("main", args.getClass()); mainMethod.invoke(null, (Object) args); } }
throw new IllegalStateException("Cannot run from EDT"); if (GraphicsEnvironment.isHeadless()) { throw new IllegalStateException("Cannot show dialog in headless environment");
if (GraphicsEnvironment.isHeadless() || args.length > 0) { handleArguments(args); } else {
@Override public Terminal createTerminal() throws IOException { // 3 different reasons for tty-based terminal: // "explicit preference", "no alternative", // ("because we can" - unless "rather not") if (forceTextTerminal || GraphicsEnvironment.isHeadless() || (System.console() != null && !preferTerminalEmulator) ) { // if tty but have no tty, but do have a port, then go telnet: if( telnetPort > 0 && System.console() == null) { return createTelnetTerminal(); } if(isOperatingSystemWindows()) { return createWindowsTerminal(); } else { return createUnixTerminal(outputStream, inputStream, charset); } } else { // while Lanterna's TerminalEmulator lacks mouse support: // if user wanted mouse AND set a telnetPort, and didn't // explicitly ask for a graphical Terminal, then go telnet: if (!preferTerminalEmulator && mouseCaptureMode != null && telnetPort > 0) { return createTelnetTerminal(); } else { return createTerminalEmulator(); } } }
if (toolStart && webRunning && !GraphicsEnvironment.isHeadless()) { loadFont(); try {
/** * checks, whether Java runs with a valid GraphicsEnvironment (usually means real screens connected) * * @return false if Java thinks it has access to screen(s), true otherwise */ public static boolean isHeadless() { return GraphicsEnvironment.isHeadless(); }
Log.info("GraphicsEnvironment.isHeadless() " + GraphicsEnvironment.isHeadless()); if (GraphicsEnvironment.isHeadless()) { Log.info("Forcing -Djava.awt.headless=true"); System.setProperty("java.awt.headless", "true");
private static int getMenuShortcutKeyMask() { // #152050 - work in headless environment too try { if (!GraphicsEnvironment.isHeadless()) { return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); } } catch (Throwable ex) { // OK, just assume we are headless } return Event.CTRL_MASK; }
import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.HeadlessException; public class TestHeadless { private static boolean isReallyHeadless() { if (GraphicsEnvironment.isHeadless()) { return true; } try { GraphicsDevice[] screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); return screenDevices == null || screenDevices.length == 0; } catch (HeadlessException e) { e.printStackTrace(); return true; } } }
public @Override Dimension getPreferredSize(JComponent c) { if (GraphicsEnvironment.isHeadless()) { // cannot create scratch graphics, so don't bother return super.getPreferredSize(c); } return calcPreferredSize((HtmlRendererImpl) c); }
public DisplayCoverageTest() { headless = GraphicsEnvironment.isHeadless(); bounds = new Rectangle(0, 0, WIDTH, WIDTH); env = new ReferencedEnvelope(bounds, DefaultEngineeringCRS.GENERIC_2D); }
@Test public void testDataV1OverpaintedArc() throws IOException, InterruptedException { // TODO: Doesn't look right PICTImageReader reader = createReader(); reader.setInput(new ByteArrayImageInputStream(DATA_V1_OVERPAINTED_ARC)); reader.read(0); BufferedImage image = reader.read(0); if (!GraphicsEnvironment.isHeadless()) { PICTImageReader.showIt(image, "dataV1CopyBits"); Thread.sleep(10000); } }