com.jme.system
Class PropertiesGameSettings

java.lang.Object
  extended by com.jme.system.AbstractGameSettings
      extended by com.jme.system.PropertiesGameSettings
All Implemented Interfaces:
GameSettings
Direct Known Subclasses:
BaseGame.BaseGameSettings

public class PropertiesGameSettings
extends AbstractGameSettings

PropertiesGameSettings handles loading and saving a properties file that defines the display settings. A property file is identified during creation of the object. The properties file should have the following format:


 FREQ=60
 RENDERER=LWJGL
 WIDTH=1280
 HEIGHT=1024
 DEPTH=32
 FULLSCREEN=false
 

Version:
$Revision: 4131 $
Author:
Mark Powell

Field Summary
 
Fields inherited from class com.jme.system.AbstractGameSettings
defaultAlphaBits, defaultDepth, defaultDepthBits, defaultFramerate, defaultFrequency, defaultFullscreen, defaultHeight, defaultMusic, defaultRenderer, defaultSamples, defaultSettingsWidgetImage, defaultSFX, defaultStencilBits, defaultVerticalSync, defaultWidth, isNew
 
Fields inherited from interface com.jme.system.GameSettings
DEFAULT_ALPHA_BITS, DEFAULT_DEPTH, DEFAULT_DEPTH_BITS, DEFAULT_FRAMERATE, DEFAULT_FREQUENCY, DEFAULT_FULLSCREEN, DEFAULT_HEIGHT, DEFAULT_MUSIC, DEFAULT_RENDERER, DEFAULT_SAMPLES, DEFAULT_SFX, DEFAULT_STENCIL_BITS, DEFAULT_VERTICAL_SYNC, DEFAULT_WIDTH
 
Constructor Summary
PropertiesGameSettings(java.lang.String userFile)
          Legacy wrapper constructor
PropertiesGameSettings(java.lang.String personalFilename, java.lang.String dfltsFilename)
          Constructor creates the PropertiesGameSettings object for use.
 
Method Summary
 void clear()
          Clears all settings.
 java.lang.String get(java.lang.String key)
          get takes an arbitrary string as a key and returns any value associated with it, null if none.
 java.lang.String get(java.lang.String name, java.lang.String defaultValue)
           
 int getAlphaBits()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 boolean getBoolean(java.lang.String name, boolean defaultValue)
           
 byte[] getByteArray(java.lang.String name, byte[] defaultValue)
           
 int getDepth()
          getDepth returns the depth as read from the properties file.
 int getDepthBits()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 double getDouble(java.lang.String name, double defaultValue)
           
 float getFloat(java.lang.String name, float defaultValue)
           
 int getFramerate()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 int getFreq()
          Deprecated. Use method getFrequency instead.
 int getFrequency()
          getFrequency returns the frequency of the monitor as read from the properties file.
 boolean getFullscreen()
          Deprecated. Use method isFullscreen instead.
 int getHeight()
          getHeight returns the height as read from the properties file.
 int getInt(java.lang.String name, int defaultValue)
           
 long getLong(java.lang.String name, long defaultValue)
           
 java.lang.Object getObject(java.lang.String name, java.lang.Object defaultValue)
           
 java.lang.String getRenderer()
          getRenderer returns the requested rendering API, or the default.
 int getSamples()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 int getStencilBits()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 int getWidth()
          getWidth returns the width as read from the properties file.
 boolean isFullscreen()
          isFullscreen returns the fullscreen flag as read from the properties file.
 boolean isMusic()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 boolean isSFX()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 boolean isVerticalSync()
          If the properties file does not contain the setting or was not read properly, the default value is returned.
 boolean load()
          load attempts to load the properties file defined during instantiation and put all properties in the table.
 void remove(java.lang.String name)
          Removes specified property, if present.
 void save()
          Persists current property mappings to designated file, overwriting if file already present.
 boolean save(int width, int height, int depth, int freq, boolean fullscreen, java.lang.String renderer)
          Deprecated.  
 void set(java.lang.String name, java.lang.String value)
          Sets a property.
 void setAlphaBits(int alphaBits)
          Sets the alpha bits for use with the renderer.
 void setBoolean(java.lang.String name, boolean value)
           
 void setByteArray(java.lang.String name, byte[] value)
           
 void setDepth(int depth)
          Sets the depth for the screen.
 void setDepthBits(int depthBits)
          Sets the depth bits for use with the renderer.
 void setDouble(java.lang.String name, double value)
           
 void setFloat(java.lang.String name, float value)
           
 void setFramerate(int framerate)
          Sets the framerate.
 void setFrequency(int freq)
          Sets the screen refresh frequency.
 void setFullscreen(boolean fullscreen)
          Sets the fullscreen status for the screen.
 void setHeight(int height)
          Sets the height for the screen.
 void setInt(java.lang.String name, int value)
           
 void setLong(java.lang.String name, long value)
           
 void setMusic(boolean music)
          Sets the enabled status of music.
 void setObject(java.lang.String name, java.lang.Object value)
          Not implemented.
 void setRenderer(java.lang.String renderer)
          Sets the rendering API.
 void setSamples(int samples)
          Sets the number of samples to use for the multisample buffer.
 void setSFX(boolean sfx)
          Sets the enabled status of sound effects.
 void setStencilBits(int stencilBits)
          Sets the stencil bits for use with the renderer.
 void setVerticalSync(boolean verticalSync)
          Sets the state of vertical synchronization.
 void setWidth(int width)
          Sets the width for the screen.
 void wrappedSave()
          save() method which throws only a RuntimeExceptin.
 
Methods inherited from class com.jme.system.AbstractGameSettings
assignDefaults, getDefaultSettingsWidgetImage, isNew, loadBoolean, loadInteger, normalizeName, setIsNew
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesGameSettings

public PropertiesGameSettings(java.lang.String userFile)
Legacy wrapper constructor

See Also:
PropertiesGameSettings(String, String)

PropertiesGameSettings

public PropertiesGameSettings(java.lang.String personalFilename,
                              java.lang.String dfltsFilename)
Constructor creates the PropertiesGameSettings object for use.

Parameters:
personalFilename - the properties file to use, read from filesystem. Must not be null.
dfltsFilename - the properties file to use, read from CLASSPATH. Null to not seek any runtime defaults file.
Throws:
JmeException - if the personalFilename is null.
Method Detail

load

public boolean load()
load attempts to load the properties file defined during instantiation and put all properties in the table. If there is a problem loading or reading the file, false is returned. If all goes well, true is returned.

Returns:
the success of the load, true indicated success and false indicates failure.

save

public void save()
          throws java.io.IOException
Persists current property mappings to designated file, overwriting if file already present.

Throws:
java.io.IOException - for I/O failures

save

public boolean save(int width,
                    int height,
                    int depth,
                    int freq,
                    boolean fullscreen,
                    java.lang.String renderer)
Deprecated. 

save(int, int, int, int, boolean, String) overwrites the properties file with the given parameters.

Parameters:
width - the width of the resolution.
height - the height of the resolution.
depth - the bits per pixel.
freq - the frequency of the monitor.
fullscreen - use fullscreen or not.
Returns:
true if save was successful, false otherwise.

getWidth

public int getWidth()
getWidth returns the width as read from the properties file. If the properties file does not contain width or was not read properly, the default width is returned.

Returns:
the width determined by the properties file, or the default.

getHeight

public int getHeight()
getHeight returns the height as read from the properties file. If the properties file does not contain height or was not read properly, the default height is returned.

Returns:
the height determined by the properties file, or the default.

getDepth

public int getDepth()
getDepth returns the depth as read from the properties file. If the properties file does not contain depth or was not read properly, the default depth is returned.

Returns:
the depth determined by the properties file, or the default.

getFrequency

public int getFrequency()
getFrequency returns the frequency of the monitor as read from the properties file. If the properties file does not contain frequency or was not read properly the default frequency is returned.

Returns:
the frequency determined by the properties file, or the default.
See Also:
GameSettings.getFrequency()

isFullscreen

public boolean isFullscreen()
isFullscreen returns the fullscreen flag as read from the properties file. If the properties file does not contain the fullscreen flag or was not read properly, the default value is returned.

Returns:
the fullscreen flag determined by the properties file, or the default.
See Also:
PreferencesGameSettings.isFullscreen()

getRenderer

public java.lang.String getRenderer()
getRenderer returns the requested rendering API, or the default.

Returns:
the rendering API or the default.

get

public java.lang.String get(java.lang.String key)
get takes an arbitrary string as a key and returns any value associated with it, null if none.

Parameters:
key - the key to use for data retrieval.
Returns:
the string associated with the key, null if none.

clear

public void clear()
Description copied from interface: GameSettings
Clears all settings.

This removes all settings. As a result, get*() will return the default value, but this is very different from setting default values. If all settings are removed, users will automatically receive updated system or game default settings. If a user were to set (then save) default values, they would always retrieve those values regardless to any changes to defaults.

clear() followed by save() will persist an indication that there are no values saved.

See Also:
GameSettings.clear()

get

public java.lang.String get(java.lang.String name,
                            java.lang.String defaultValue)
See Also:
GameSettings.get(String, String)

getAlphaBits

public int getAlphaBits()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
int
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.getAlphaBits()

getDepthBits

public int getDepthBits()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
int
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.getDepthBits()

getFramerate

public int getFramerate()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
int
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.getFramerate()

getSamples

public int getSamples()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
int
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.getSamples()

getStencilBits

public int getStencilBits()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
int
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.getStencilBits()

isMusic

public boolean isMusic()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
boolean
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.isMusic()

isSFX

public boolean isSFX()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
boolean
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.isSFX()

isVerticalSync

public boolean isVerticalSync()
If the properties file does not contain the setting or was not read properly, the default value is returned.

Returns:
boolean
Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.isVerticalSync()

getFreq

public int getFreq()
Deprecated. Use method getFrequency instead.

Legacy method.

See Also:
getFrequency()

getFullscreen

public boolean getFullscreen()
Deprecated. Use method isFullscreen instead.

Legacy method.

See Also:
isFullscreen()

getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean defaultValue)
See Also:
GameSettings.getBoolean(String, boolean)

getByteArray

public byte[] getByteArray(java.lang.String name,
                           byte[] defaultValue)
See Also:
GameSettings.getByteArray(String, byte[])

getDouble

public double getDouble(java.lang.String name,
                        double defaultValue)
See Also:
GameSettings.getDouble(String, double)

getFloat

public float getFloat(java.lang.String name,
                      float defaultValue)
See Also:
GameSettings.getFloat(String, float)

getInt

public int getInt(java.lang.String name,
                  int defaultValue)
See Also:
GameSettings.getInt(String, int)

getLong

public long getLong(java.lang.String name,
                    long defaultValue)
See Also:
GameSettings.getLong(String, long)

getObject

public java.lang.Object getObject(java.lang.String name,
                                  java.lang.Object defaultValue)
See Also:
GameSettings.getObject(String, Object)

remove

public void remove(java.lang.String name)
Removes specified property, if present.


set

public void set(java.lang.String name,
                java.lang.String value)
Sets a property.

See Also:
GameSettings.set(String, String)

wrappedSave

public void wrappedSave()
save() method which throws only a RuntimeExceptin.

Throws:
RuntimeSetting - for IO failure
See Also:
save()

setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
Throws:
RuntimeSetting - for IO failure
See Also:
set(String, String), PreferencesGameSettings.setBoolean(String, boolean)

setByteArray

public void setByteArray(java.lang.String name,
                         byte[] value)
Throws:
RuntimeSetting - for IO failure
See Also:
set(String, String), PreferencesGameSettings.setByteArray(String, byte[])

setDouble

public void setDouble(java.lang.String name,
                      double value)
Throws:
RuntimeSetting - for IO failure
See Also:
set(String, String), PreferencesGameSettings.setDouble(String, double)

setFloat

public void setFloat(java.lang.String name,
                     float value)
Throws:
RuntimeSetting - for IO failure
See Also:
set(String, String), PreferencesGameSettings.setFloat(String, float)

setInt

public void setInt(java.lang.String name,
                   int value)
Throws:
RuntimeSetting - for IO failure
See Also:
set(String, String), PreferencesGameSettings.setInt(String, int)

setLong

public void setLong(java.lang.String name,
                    long value)
Throws:
RuntimeSetting - for IO failure
See Also:
set(String, String), PreferencesGameSettings.setLong(String, long)

setObject

public void setObject(java.lang.String name,
                      java.lang.Object value)
Not implemented. Properties can not store an arbitrary Object in human-readable format. Use set(String, String) instead.

Throws:
java.lang.InternalError - in all cases
See Also:
PreferencesGameSettings#setObject(String, boolean), set(String, String)

setWidth

public void setWidth(int width)
Description copied from interface: GameSettings
Sets the width for the screen.

See Also:
GameSettings.setWidth(int)

setHeight

public void setHeight(int height)
Description copied from interface: GameSettings
Sets the height for the screen.

See Also:
GameSettings.setHeight(int)

setDepth

public void setDepth(int depth)
Description copied from interface: GameSettings
Sets the depth for the screen.

See Also:
GameSettings.setDepth(int)

setFrequency

public void setFrequency(int freq)
Description copied from interface: GameSettings
Sets the screen refresh frequency.

See Also:
GameSettings.setFrequency(int)

setFullscreen

public void setFullscreen(boolean fullscreen)
Description copied from interface: GameSettings
Sets the fullscreen status for the screen.

See Also:
GameSettings.setFullscreen(boolean)

setRenderer

public void setRenderer(java.lang.String renderer)
Description copied from interface: GameSettings
Sets the rendering API.

See Also:
GameSettings.setRenderer(String)

setAlphaBits

public void setAlphaBits(int alphaBits)
Description copied from interface: GameSettings
Sets the alpha bits for use with the renderer.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setAlphaBits(int)

setDepthBits

public void setDepthBits(int depthBits)
Description copied from interface: GameSettings
Sets the depth bits for use with the renderer.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setDepthBits(int)

setFramerate

public void setFramerate(int framerate)
Description copied from interface: GameSettings
Sets the framerate. Use -1 to specify variable framerate.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setFramerate(int)

setMusic

public void setMusic(boolean music)
Description copied from interface: GameSettings
Sets the enabled status of music.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setMusic(boolean)

setSamples

public void setSamples(int samples)
Description copied from interface: GameSettings
Sets the number of samples to use for the multisample buffer.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setSamples(int)

setSFX

public void setSFX(boolean sfx)
Description copied from interface: GameSettings
Sets the enabled status of sound effects.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setSFX(boolean)

setStencilBits

public void setStencilBits(int stencilBits)
Description copied from interface: GameSettings
Sets the stencil bits for use with the renderer.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setStencilBits(int)

setVerticalSync

public void setVerticalSync(boolean verticalSync)
Description copied from interface: GameSettings
Sets the state of vertical synchronization. This synchronizes the game update frequency to the monitor update frequency. This can help provide a much smoother game experience and help with screen tearing.

Throws:
java.lang.InternalError - in all cases
See Also:
GameSettings.setVerticalSync(boolean)