hmi.util
Class Screen

java.lang.Object
  extended by hmi.util.Screen

public final class Screen
extends Object

A utility class for dealing with screen setting, like setting the display to "fullscreen", setting the cursor, makeing the cursor invisible, etcetera. The most usefull methods are : setFullScreen(Frame frame) setInvisibleCursor(Component c) setCursor(Component c, int cursorType) restoreCursor(Component c) It is possible to set the display mode, dealing with refresh rate and screen resolution; with LCD monitors this is usually not desirable, since refresh rates are fixed, and screen resolution has only one optimal setting.

Author:
Job Zwiers

Field Summary
static int CURRENT_VALUE
          constants that can be used as parameters for Screen methods like setFullScreen(), selectDisplayModes
private static int CURSORSIZE
           
private static GraphicsDevice defaultDevice
           
private static int[] DEFAULTSCREENSIZELIST
          value for selecting a default list of display modes
private static int EXPECTEDLABELLENGTH
           
static int HIGHCOLOR
           
static int MAX
           
private static int MAXDIMENSION
           
static int MIN
           
private static Cursor noCursor
           
private static Cursor prevCursor
           
static int SHOWBITDEPTH
           
static int SHOWFULLDISPLAYMODE
           
static int SHOWREFRESHRATE
           
static int SHOWSCREENSIZE
          values for tuning the displayModeToLabel method
static int TRUECOLOR
           
 
Constructor Summary
private Screen()
           
 
Method Summary
private static void checkDefaultDevice()
           
static Predicate<DisplayMode> displayModeFilter(int minWidth, int minHeight, int maxWidth, int maxHeight, int minBitDepth, int maxBitDepth, int minRefreshRate, int maxRefreshRate)
          yields a Predicate that selects only DisplayModes with the specified bitDepth and refreshRate
static String displayModeToLabel(DisplayMode mode, int labelMode)
          Detemines a String that represents a DisplayMode, in human readable form.
static String displayModeToString(DisplayMode mode)
           
static int getBitDepth()
          returns the current color bit depth for the default screen device
static DisplayMode getDisplayMode()
          returns the current DisplayMode for the default screen device
static DisplayMode[] getDisplayModes()
          returns the array of all available DisplayModes for the (default) screen device.
static String getDisplayModeString()
          returns a String that describes the current DisplayMode
static int getHeight()
          returns the current screen height for the default screen device
static int getRefreshRate()
          returns the current refresh rate for the default screen device
static int getWidth()
          returns the current screen width for the default screen device
static void printDisplayModes()
          prints all available DisplayModes
static void restoreCursor(Component c)
          Restores the Cursor that was saved before by setInvisibleCursor(c).
static DisplayMode selectBestDisplayMode(int width, int height, int bitDepth, int refreshRate)
          selects an available DisplayMode that matches the specified characteristics as far as possible.
static ArrayList<DisplayMode> selectDisplayModeRange(int minWidth, int minHeight, int maxWidth, int maxHeight, int minBitDepth, int maxBitDepth, int minRefreshRate, int maxRefreshRate)
          returns a List with available DisplayModes, satisfying the specified constraints.
static ArrayList<DisplayMode> selectDisplayModes()
          returns a List of DisplayModes that have TRUECOLOR bit depth (32 bit(), and have the same refresh rate as the current refresh rate.
static ArrayList<DisplayMode> selectDisplayModes(int[] preferredScreenSizes)
          returns a List of DisplayModes that have TRUECOLOR bit depth (32 bit(), and have the same refresh rate as the current refresh rate.
static ArrayList<DisplayMode> selectDisplayModes(int[] preferredScreenSizes, int minBitDepth, int maxBitDepth, int minRefreshRate, int maxRefreshRate)
          returns a List of DisplayModes that have bit depth and refresh rate within the specified range.
static ArrayList<DisplayMode> selectFilteredDisplayModes(Predicate<DisplayMode> filter)
          returns the array of all available DisplayModes that satisfy the specified filter Predicate.
static void setCursor(Component c, int cursorType)
          Sets a cursor for the specified Component.
static void setFullScreen(Frame frame)
          tries to set the screen to "fullscreen" mode.
static void setFullScreen(Frame frame, DisplayMode mode)
          tries to set the screen resolution.
static void setFullScreen(Frame frame, int width, int height)
          tries to set the screen resolution.
static void setFullScreen(Frame frame, int width, int height, int bitDepth)
          tries to set the screen resolution.
static void setFullScreen(Frame frame, int width, int height, int bitDepth, int refreshRate)
          tries to set the screen resolution.
static void setInvisibleCursor(Component c)
          Sets an "invisble" cursor for the specified Component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURRENT_VALUE

public static final int CURRENT_VALUE
constants that can be used as parameters for Screen methods like setFullScreen(), selectDisplayModes

See Also:
Constant Field Values

HIGHCOLOR

public static final int HIGHCOLOR
See Also:
Constant Field Values

TRUECOLOR

public static final int TRUECOLOR
See Also:
Constant Field Values

MAX

public static final int MAX
See Also:
Constant Field Values

MIN

public static final int MIN
See Also:
Constant Field Values

DEFAULTSCREENSIZELIST

private static final int[] DEFAULTSCREENSIZELIST
value for selecting a default list of display modes


SHOWSCREENSIZE

public static final int SHOWSCREENSIZE
values for tuning the displayModeToLabel method

See Also:
Constant Field Values

SHOWBITDEPTH

public static final int SHOWBITDEPTH
See Also:
Constant Field Values

SHOWREFRESHRATE

public static final int SHOWREFRESHRATE
See Also:
Constant Field Values

SHOWFULLDISPLAYMODE

public static final int SHOWFULLDISPLAYMODE
See Also:
Constant Field Values

EXPECTEDLABELLENGTH

private static final int EXPECTEDLABELLENGTH
See Also:
Constant Field Values

MAXDIMENSION

private static final int MAXDIMENSION
See Also:
Constant Field Values

CURSORSIZE

private static final int CURSORSIZE
See Also:
Constant Field Values

defaultDevice

private static GraphicsDevice defaultDevice

noCursor

private static Cursor noCursor

prevCursor

private static Cursor prevCursor
Constructor Detail

Screen

private Screen()
Method Detail

getDisplayModes

public static DisplayMode[] getDisplayModes()
returns the array of all available DisplayModes for the (default) screen device. Each DisplayMode specifies screen resolution, color bit depth, and refresh rate.


displayModeFilter

public static Predicate<DisplayMode> displayModeFilter(int minWidth,
                                                       int minHeight,
                                                       int maxWidth,
                                                       int maxHeight,
                                                       int minBitDepth,
                                                       int maxBitDepth,
                                                       int minRefreshRate,
                                                       int maxRefreshRate)
yields a Predicate that selects only DisplayModes with the specified bitDepth and refreshRate


selectFilteredDisplayModes

public static ArrayList<DisplayMode> selectFilteredDisplayModes(Predicate<DisplayMode> filter)
returns the array of all available DisplayModes that satisfy the specified filter Predicate.


selectDisplayModeRange

public static ArrayList<DisplayMode> selectDisplayModeRange(int minWidth,
                                                            int minHeight,
                                                            int maxWidth,
                                                            int maxHeight,
                                                            int minBitDepth,
                                                            int maxBitDepth,
                                                            int minRefreshRate,
                                                            int maxRefreshRate)
returns a List with available DisplayModes, satisfying the specified constraints. Value can be specified as CURRENT_VALUE, in which case the value for the current display mode is used. bit depth can also be specified as HIGHCOLOR (16 bit) or TRUECOLOR (32 bit).


selectDisplayModes

public static ArrayList<DisplayMode> selectDisplayModes()
returns a List of DisplayModes that have TRUECOLOR bit depth (32 bit(), and have the same refresh rate as the current refresh rate. Moreover, the width and height combination must be one of the combinations taken from DEFAULTSCREENSIZELIST


selectDisplayModes

public static ArrayList<DisplayMode> selectDisplayModes(int[] preferredScreenSizes)
returns a List of DisplayModes that have TRUECOLOR bit depth (32 bit(), and have the same refresh rate as the current refresh rate. Moreover, the width and height combination must be one of the combinations in the preferredScreenSizes array. For instance, new int[] { 640, 480, 800, 600, 1024, 768 } would specify a list of popular screen sizes: 640 X 480, 800 X 600, 1024 X 768.


selectDisplayModes

public static ArrayList<DisplayMode> selectDisplayModes(int[] preferredScreenSizes,
                                                        int minBitDepth,
                                                        int maxBitDepth,
                                                        int minRefreshRate,
                                                        int maxRefreshRate)
returns a List of DisplayModes that have bit depth and refresh rate within the specified range. Moreover, the width and height combination must be one of the combinations in the preferredScreenSizes array. For instance, new int[] { 640, 480, 800, 600, 1024, 768 } would specify a list of popular screen sizes: 640 X 480, 800 X 600, 1024 X 768.


getDisplayMode

public static DisplayMode getDisplayMode()
returns the current DisplayMode for the default screen device


getRefreshRate

public static int getRefreshRate()
returns the current refresh rate for the default screen device


getBitDepth

public static int getBitDepth()
returns the current color bit depth for the default screen device


getWidth

public static int getWidth()
returns the current screen width for the default screen device


getHeight

public static int getHeight()
returns the current screen height for the default screen device


getDisplayModeString

public static String getDisplayModeString()
returns a String that describes the current DisplayMode


displayModeToString

public static String displayModeToString(DisplayMode mode)

displayModeToLabel

public static String displayModeToLabel(DisplayMode mode,
                                        int labelMode)
Detemines a String that represents a DisplayMode, in human readable form. Width and Depth are always shown in the form width X depth. BitDepth and/or Refresh Rate are optionally appended, like for example: TrueColor (32 bit), 60 Hz


printDisplayModes

public static void printDisplayModes()
prints all available DisplayModes


selectBestDisplayMode

public static DisplayMode selectBestDisplayMode(int width,
                                                int height,
                                                int bitDepth,
                                                int refreshRate)
selects an available DisplayMode that matches the specified characteristics as far as possible. If refreshRate is specified as Screen.CURRENT_VALUE, the current refresh rate is assumed. The bitDepth should be Screen.HIGHCOLOR (16 bit), Screen.TRUECOLOR (32 bit) or Screen.CURRENT_VALUE; (TRUECOLOR is almost always the preferred mode.) Similarly, width and height can be specified as Screen.CURRENT_VALUE. For instance, selectDisplayMode(Screen.CURRENT_VALUE, Screen.CURRENT_VALUE, Screen.TRUECOLOR, Screen.CURRENT_VALUE) will ensure true color mode, but will not change other display settings. If no perfect match is found, lower refresh rates(no higher rates) and different bitDepths are tried, if possible. If no matching mode can be found at all, a null mode is returned.


setFullScreen

public static void setFullScreen(Frame frame)
tries to set the screen to "fullscreen" mode. Under Windows XP this turns out to be "maximized", although the isFullScreenSupported() query returns true. Note that window decoration (i.e. the title/button bar at the top, and the borders around, should be turned off seperately, by means of the setUndecorated(true) method for the applications's (J)Frame. The boolean result denotes whether full screen mode has been set succesfully.


setFullScreen

public static void setFullScreen(Frame frame,
                                 int width,
                                 int height)
tries to set the screen resolution. This requires that full screen mode has been set.


setFullScreen

public static void setFullScreen(Frame frame,
                                 int width,
                                 int height,
                                 int bitDepth)
tries to set the screen resolution. This requires that full screen mode has been set.


setFullScreen

public static void setFullScreen(Frame frame,
                                 int width,
                                 int height,
                                 int bitDepth,
                                 int refreshRate)
tries to set the screen resolution. This requires that full screen mode has been set.


setFullScreen

public static void setFullScreen(Frame frame,
                                 DisplayMode mode)
tries to set the screen resolution. This requires that full screen mode has been set.


setInvisibleCursor

public static void setInvisibleCursor(Component c)
Sets an "invisble" cursor for the specified Component. The current Cursor is saved, and can be restored later on by calling restoreCursor(c). Note that the cursor is not really gone, but just invisible. Mouse events are still possible, and must be handled in an appropriate way.


setCursor

public static void setCursor(Component c,
                             int cursorType)
Sets a cursor for the specified Component. The specified cursor type must be one of the constants defined in java.awt.Cursor, like CROSSHAIR_CURSOR, HAND_CURSOR etc. The current Cursor is saved, and can be restored later on by calling restoreCursor(c).


restoreCursor

public static void restoreCursor(Component c)
Restores the Cursor that was saved before by setInvisibleCursor(c).


checkDefaultDevice

private static void checkDefaultDevice()