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
This commit is contained in:
@@ -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
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2003 Walter Korman
|
// Copyright (C) 2003 Walter Korman
|
||||||
@@ -59,6 +59,10 @@ public class SystemInfo
|
|||||||
/** The maximum amount of memory available in kilobytes. */
|
/** The maximum amount of memory available in kilobytes. */
|
||||||
public long maxMemory;
|
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}. */
|
/** The video display bit depth; see {@link DisplayMode}. */
|
||||||
public int bitDepth;
|
public int bitDepth;
|
||||||
|
|
||||||
@@ -104,15 +108,23 @@ public class SystemInfo
|
|||||||
maxMemory = rtime.maxMemory() / 1024;
|
maxMemory = rtime.maxMemory() / 1024;
|
||||||
|
|
||||||
// determine video display information
|
// determine video display information
|
||||||
GraphicsEnvironment env =
|
isHeadless = GraphicsEnvironment.isHeadless();
|
||||||
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
if (!isHeadless) {
|
||||||
GraphicsDevice gd = env.getDefaultScreenDevice();
|
try {
|
||||||
DisplayMode mode = gd.getDisplayMode();
|
GraphicsEnvironment env =
|
||||||
bitDepth = mode.getBitDepth();
|
GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
refreshRate = mode.getRefreshRate() / 1024;
|
GraphicsDevice gd = env.getDefaultScreenDevice();
|
||||||
isFullScreen = (gd.getFullScreenWindow() != null);
|
DisplayMode mode = gd.getDisplayMode();
|
||||||
displayWidth = mode.getWidth();
|
bitDepth = mode.getBitDepth();
|
||||||
displayHeight = mode.getHeight();
|
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 ()
|
public String videoToString ()
|
||||||
{
|
{
|
||||||
|
if (isHeadless) {
|
||||||
|
return "headless or unavailable";
|
||||||
|
}
|
||||||
|
|
||||||
String sdepth = (bitDepth == -1) ? "unknown bit depth" :
|
String sdepth = (bitDepth == -1) ? "unknown bit depth" :
|
||||||
bitDepth + "-bit";
|
bitDepth + "-bit";
|
||||||
String srate = (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) ?
|
String srate = (refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) ?
|
||||||
|
|||||||
Reference in New Issue
Block a user