From 373b844cb284417520d250811928d8bce778e8c4 Mon Sep 17 00:00:00 2001 From: shaper Date: Wed, 15 Jan 2003 01:27:44 +0000 Subject: [PATCH] Deal gracefully with systems running with a headless AWT toolkit, or general failure to obtain the graphics environment or other video information. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1019 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/SystemInfo.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/SystemInfo.java b/projects/samskivert/src/java/com/samskivert/util/SystemInfo.java index 90761996..60bdee87 100644 --- a/projects/samskivert/src/java/com/samskivert/util/SystemInfo.java +++ b/projects/samskivert/src/java/com/samskivert/util/SystemInfo.java @@ -1,5 +1,5 @@ // -// $Id: SystemInfo.java,v 1.2 2003/01/14 22:31:27 shaper Exp $ +// $Id: SystemInfo.java,v 1.3 2003/01/15 01:27:44 shaper Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2003 Walter Korman @@ -59,6 +59,10 @@ public class SystemInfo /** The maximum amount of memory available in kilobytes. */ public long maxMemory; + /** Whether the video display is headless or video information is + * unavailable. */ + public boolean isHeadless; + /** The video display bit depth; see {@link DisplayMode}. */ public int bitDepth; @@ -104,15 +108,23 @@ public class SystemInfo maxMemory = rtime.maxMemory() / 1024; // determine video display information - GraphicsEnvironment env = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice gd = env.getDefaultScreenDevice(); - DisplayMode mode = gd.getDisplayMode(); - bitDepth = mode.getBitDepth(); - refreshRate = mode.getRefreshRate() / 1024; - isFullScreen = (gd.getFullScreenWindow() != null); - displayWidth = mode.getWidth(); - displayHeight = mode.getHeight(); + isHeadless = GraphicsEnvironment.isHeadless(); + if (!isHeadless) { + try { + GraphicsEnvironment env = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice gd = env.getDefaultScreenDevice(); + DisplayMode mode = gd.getDisplayMode(); + bitDepth = mode.getBitDepth(); + refreshRate = mode.getRefreshRate() / 1024; + isFullScreen = (gd.getFullScreenWindow() != null); + displayWidth = mode.getWidth(); + displayHeight = mode.getHeight(); + + } catch (Throwable t) { + isHeadless = true; + } + } } /** @@ -148,6 +160,10 @@ public class SystemInfo */ public String videoToString () { + if (isHeadless) { + return "headless or unavailable"; + } + String sdepth = (bitDepth == -1) ? "unknown bit depth" : bitDepth + "-bit"; String srate = (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) ?