com.brackeen.javagamebook.graphics
Class ScreenManager

java.lang.Object
  extended bycom.brackeen.javagamebook.graphics.ScreenManager

public class ScreenManager
extends java.lang.Object

The ScreenManager class manages initializing and displaying full screen graphics modes.


Constructor Summary
ScreenManager()
          Creates a new ScreenManager object.
 
Method Summary
 java.awt.image.BufferedImage createCompatibleImage(int w, int h, int transparancy)
          Creates an image compatible with the current display.
 boolean displayModesMatch(java.awt.DisplayMode mode1, java.awt.DisplayMode mode2)
          Determines if two display modes "match".
 java.awt.DisplayMode findFirstCompatibleMode(java.awt.DisplayMode[] modes)
          Returns the first compatible mode in a list of modes.
 java.awt.DisplayMode[] getCompatibleDisplayModes()
          Returns a list of compatible display modes for the default device on the system.
 java.awt.DisplayMode getCurrentDisplayMode()
          Returns the current display mode.
 javax.swing.JFrame getFullScreenWindow()
          Returns the window currently used in full screen mode.
 java.awt.Graphics2D getGraphics()
          Gets the graphics context for the display.
 int getHeight()
          Returns the height of the window currently used in full screen mode.
 int getWidth()
          Returns the width of the window currently used in full screen mode.
 void restoreScreen()
          Restores the screen's display mode.
 void setFullScreen(java.awt.DisplayMode displayMode)
          Enters full screen mode and changes the display mode.
 void update()
          Updates the display.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScreenManager

public ScreenManager()
Creates a new ScreenManager object.

Method Detail

getCompatibleDisplayModes

public java.awt.DisplayMode[] getCompatibleDisplayModes()
Returns a list of compatible display modes for the default device on the system.


findFirstCompatibleMode

public java.awt.DisplayMode findFirstCompatibleMode(java.awt.DisplayMode[] modes)
Returns the first compatible mode in a list of modes. Returns null if no modes are compatible.


getCurrentDisplayMode

public java.awt.DisplayMode getCurrentDisplayMode()
Returns the current display mode.


displayModesMatch

public boolean displayModesMatch(java.awt.DisplayMode mode1,
                                 java.awt.DisplayMode mode2)
Determines if two display modes "match". Two display modes match if they have the same resolution, bit depth, and refresh rate. The bit depth is ignored if one of the modes has a bit depth of DisplayMode.BIT_DEPTH_MULTI. Likewise, the refresh rate is ignored if one of the modes has a refresh rate of DisplayMode.REFRESH_RATE_UNKNOWN.


setFullScreen

public void setFullScreen(java.awt.DisplayMode displayMode)
Enters full screen mode and changes the display mode. 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.

The display uses a BufferStrategy with 2 buffers.


getGraphics

public java.awt.Graphics2D getGraphics()
Gets the graphics context for the display. The ScreenManager uses double buffering, so applications must call update() to show any graphics drawn.

The application must dispose of the graphics object.


update

public void update()
Updates the display.


getFullScreenWindow

public javax.swing.JFrame getFullScreenWindow()
Returns the window currently used in full screen mode. Returns null if the device is not in full screen mode.


getWidth

public int getWidth()
Returns the width of the window currently used in full screen mode. Returns 0 if the device is not in full screen mode.


getHeight

public int getHeight()
Returns the height of the window currently used in full screen mode. Returns 0 if the device is not in full screen mode.


restoreScreen

public void restoreScreen()
Restores the screen's display mode.


createCompatibleImage

public java.awt.image.BufferedImage createCompatibleImage(int w,
                                                          int h,
                                                          int transparancy)
Creates an image compatible with the current display.