org.deken.game.graphics
Class DisplayManager

java.lang.Object
  extended by org.deken.game.graphics.DisplayManager

public class DisplayManager
extends java.lang.Object

Title: DisplayManager

Description: This manager handles initializing and displaying to full screen graphics modes. Several DisplayModes are defined for common screen settings. They are provided as a starting point.

The refresh rate is set based on the user's current refresh rate. Since, the refresh rate can cause headache or nausea in some people, it is best not to change a user's refresh rate.

Copyright: Copyright (c) 2005

Version:
1.0
Author:
Gary Deken

Nested Class Summary
static class DisplayManager.ScreenSize
           
 
Field Summary
static int COLOR_DEPTH_16
           
static int COLOR_DEPTH_32
           
static int COLOR_DEPTH_8
           
 
Constructor Summary
DisplayManager(javax.swing.JFrame jFrame)
           
 
Method Summary
 java.awt.DisplayMode[] getCommonDisplayModes()
          getCommonDisplayModes
 java.awt.DisplayMode[] getCompatibleDisplayModes()
          getCompatibleDisplayModes
 java.awt.DisplayMode getCurrentDisplayMode()
          getCurrentDisplayMode
static java.awt.DisplayMode getDisplayMode(DisplayManager.ScreenSize screenSize, int colorDepth)
          getDisplayMode
static java.awt.DisplayMode getDisplayMode(DisplayManager.ScreenSize screenSize, int colorDepth, int refreshRate)
           
 java.awt.GraphicsDevice getGraphicsDevice()
           
 java.awt.DisplayMode getPerferredCompatibleMode()
          getPerferredCompatibleMode
static void hideCursor(java.awt.Component component)
           
 boolean isDisplayModeCompatible(java.awt.DisplayMode checkMode)
          isDisplayModeCompatible
 void restoreScreen()
          restoreScreen
 void setFullScreen(java.awt.DisplayMode displayMode)
          setFullScreen
 void setFullScreen(java.awt.DisplayMode displayMode, int buffering)
          setFullScreen
static void showCursor(boolean show, java.awt.Component component)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COLOR_DEPTH_16

public static final int COLOR_DEPTH_16
See Also:
Constant Field Values

COLOR_DEPTH_32

public static final int COLOR_DEPTH_32
See Also:
Constant Field Values

COLOR_DEPTH_8

public static final int COLOR_DEPTH_8
See Also:
Constant Field Values
Constructor Detail

DisplayManager

public DisplayManager(javax.swing.JFrame jFrame)
Parameters:
jFrame -
Method Detail

getDisplayMode

public static java.awt.DisplayMode getDisplayMode(DisplayManager.ScreenSize screenSize,
                                                  int colorDepth)
getDisplayMode

Taking the constants for screen size and color depth, this returns a display mode.

Parameters:
screenSize - int
colorDepth - int
Returns:
DisplayMode

getDisplayMode

public static java.awt.DisplayMode getDisplayMode(DisplayManager.ScreenSize screenSize,
                                                  int colorDepth,
                                                  int refreshRate)

hideCursor

public static void hideCursor(java.awt.Component component)

showCursor

public static void showCursor(boolean show,
                              java.awt.Component component)

isDisplayModeCompatible

public boolean isDisplayModeCompatible(java.awt.DisplayMode checkMode)
isDisplayModeCompatible

This method checks if the desired display mode is compatible.

Parameters:
checkMode - DisplayMode
Returns:
boolean

restoreScreen

public void restoreScreen()
restoreScreen

Restores the screen's display mode back to the user's settings in the desktop environment.


getCommonDisplayModes

public java.awt.DisplayMode[] getCommonDisplayModes()
getCommonDisplayModes

Returns:
DisplayMode[]

getCompatibleDisplayModes

public java.awt.DisplayMode[] getCompatibleDisplayModes()
getCompatibleDisplayModes

Returns a list of DisplayModes for the computer the code is running on. This is useful to allow the user to change to a DisplayMode that he can see.

Returns:
DisplayMode[]

getCurrentDisplayMode

public java.awt.DisplayMode getCurrentDisplayMode()
getCurrentDisplayMode

This is useful for allowing the user to see that the current setting is.

Returns:
DisplayMode

getGraphicsDevice

public java.awt.GraphicsDevice getGraphicsDevice()

getPerferredCompatibleMode

public java.awt.DisplayMode getPerferredCompatibleMode()
getPerferredCompatibleMode

This returns a valid Display Mode that is either 800x600 or 640x480, with a bitdepth of 32, 26 or 8 and a refresh rate of 60.

Returns:
DisplayMode

setFullScreen

public void setFullScreen(java.awt.DisplayMode displayMode)
setFullScreen

This calls setFullScreen(DisplayMode displayMode, int buffering) setting the buffer strategy to 2.

Parameters:
displayMode - DisplayMode

setFullScreen

public void setFullScreen(java.awt.DisplayMode displayMode,
                          int buffering)
setFullScreen

This method causes a JFrame to enter full screen mode and changes the display mode, changing the resolution, color bit depth and refresh rate. If the specified display mode is null or not compatible with this device, or if the display mode cannot be changed on this system, the current display mode is used.

This sets a user defined buffering strategy, but sets a default color of a blue background and white text with a sans serif 24 size font.

Parameters:
displayMode - DisplayMode
buffering - int