Class PropertiesGameSettings

java.lang.Object
com.ardor3d.example.PropertiesGameSettings

public class PropertiesGameSettings extends Object
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:
 <CODE>
 FREQ=60
 RENDERER=JOGL
 WIDTH=1280
 HEIGHT=1024
 DEPTH=32
 FULLSCREEN=false
 </CODE>
 
  • Field Details

    • isNew

      protected boolean isNew
    • defaultWidth

      protected static Integer defaultWidth
    • defaultHeight

      protected static Integer defaultHeight
    • defaultDepth

      protected static Integer defaultDepth
    • defaultFrequency

      protected static Integer defaultFrequency
    • defaultFullscreen

      protected static Boolean defaultFullscreen
    • defaultRenderer

      protected static String defaultRenderer
    • defaultVerticalSync

      protected static Boolean defaultVerticalSync
    • defaultDepthBits

      protected static Integer defaultDepthBits
    • defaultAlphaBits

      protected static Integer defaultAlphaBits
    • defaultStencilBits

      protected static Integer defaultStencilBits
    • defaultSamples

      protected static Integer defaultSamples
    • defaultMusic

      protected static Boolean defaultMusic
    • defaultSFX

      protected static Boolean defaultSFX
    • defaultFramerate

      protected static Integer defaultFramerate
    • defaultSettingsWidgetImage

      protected static String defaultSettingsWidgetImage
  • Constructor Details

    • PropertiesGameSettings

      public PropertiesGameSettings(String personalFilename, 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:
      Ardor3dException - if the personalFilename is null.
  • Method Details

    • clear

      public void clear()
    • get

      public String get(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.
    • get

      public String get(String name, String defaultValue)
    • getAlphaBits

      public int getAlphaBits()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      the alpha bits
      Throws:
      InternalError - in all cases
    • getBoolean

      public boolean getBoolean(String name, boolean defaultValue)
    • getByteArray

      public byte[] getByteArray(String name, byte[] defaultValue)
    • getDefaultSettingsWidgetImage

      public String getDefaultSettingsWidgetImage()
      This is only getting the "default" value, which may not be changed by end-users.
      Returns:
      the widget image of the default settings
    • 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.
    • getDepthBits

      public int getDepthBits()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      the depth bits
      Throws:
      InternalError - in all cases
    • getDouble

      public double getDouble(String name, double defaultValue)
    • getFloat

      public float getFloat(String name, float defaultValue)
    • getFramerate

      public int getFramerate()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      the frame rate
      Throws:
      InternalError - in all cases
    • 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.
    • getFullscreen

      @Deprecated public boolean getFullscreen()
      Deprecated.
      Use method isFullscreen instead.
      Legacy method.
      Returns:
      true if the full screen mode is enabled
      See Also:
    • 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.
    • getInt

      public int getInt(String name, int defaultValue)
    • getLong

      public long getLong(String name, long defaultValue)
    • getObject

      public Object getObject(String name, Object defaultValue)
    • getRenderer

      public String getRenderer()
      getRenderer returns the requested rendering API, or the default.
      Returns:
      the rendering API or the default.
    • getSamples

      public int getSamples()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      the samples
      Throws:
      InternalError - in all cases
    • getStencilBits

      public int getStencilBits()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      the stencil bits
      Throws:
      InternalError - in all cases
    • 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.
    • 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.
    • isMusic

      public boolean isMusic()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      true if the music is enabled
      Throws:
      InternalError - in all cases
    • isNew

      public boolean isNew()
    • isSFX

      public boolean isSFX()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      true if the special effects are enabled
      Throws:
      InternalError - in all cases
    • isVerticalSync

      public boolean isVerticalSync()
      If the properties file does not contain the setting or was not read properly, the default value is returned.
      Returns:
      true if the vertical sync is enabled
      Throws:
      InternalError - in all cases
    • 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.
    • remove

      public void remove(String name)
      Removes specified property, if present.
      Parameters:
      name - the name of the property to remove
    • save

      public void save() throws IOException
      Persists current property mappings to designated file, overwriting if file already present.
      Throws:
      IOException - for I/O failures
    • save

      @Deprecated public boolean save(int width, int height, int depth, int freq, boolean fullscreen, 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.
      renderer - the string denoting the renderer
      Returns:
      true if save was successful, false otherwise.
    • set

      public void set(String name, String value)
      Sets a property.
      Parameters:
      name - the name of the property
      value - the value of the property
    • setAlphaBits

      public void setAlphaBits(int alphaBits)
      Parameters:
      alphaBits - the alpha bits to set
      Throws:
      InternalError - in all cases
    • setBoolean

      public void setBoolean(String name, boolean value)
      Parameters:
      name - the name of the property
      value - the value of the property
      See Also:
    • setByteArray

      public void setByteArray(String name, byte[] value)
      Parameters:
      name - the name of the property
      value - the value of the property
      See Also:
    • setDepth

      public void setDepth(int depth)
    • setDepthBits

      public void setDepthBits(int depthBits)
      Parameters:
      depthBits - the depth bits to set
      Throws:
      InternalError - in all cases
    • setDouble

      public void setDouble(String name, double value)
      Parameters:
      name - the name of the property
      value - the value of the property
      See Also:
    • setFloat

      public void setFloat(String name, float value)
      Parameters:
      name - the name of the property
      value - the value of the property
      See Also:
    • setFramerate

      public void setFramerate(int framerate)
      Parameters:
      framerate - the frame rate
      Throws:
      InternalError - in all cases
    • setFrequency

      public void setFrequency(int freq)
    • setFullscreen

      public void setFullscreen(boolean fullscreen)
    • setHeight

      public void setHeight(int height)
    • setInt

      public void setInt(String name, int value)
      Parameters:
      name - the name of the property
      value - the value of the property
      See Also:
    • setIsNew

      public void setIsNew(boolean isNew)
    • setLong

      public void setLong(String name, long value)
      Parameters:
      name - the name of the property
      value - the value of the property
      See Also:
    • setMusic

      public void setMusic(boolean music)
      Parameters:
      music - true if the music is enabled
      Throws:
      InternalError - in all cases
    • setObject

      public void setObject(String name, Object value)
      Not implemented. Properties can not store an arbitrary Object in human-readable format. Use set(String, String) instead.
      Parameters:
      name - the name of the property
      value - the value of the property
      Throws:
      InternalError - in all cases
      See Also:
    • setRenderer

      public void setRenderer(String renderer)
    • setSamples

      public void setSamples(int samples)
      Parameters:
      samples - the samples
      Throws:
      InternalError - in all cases
    • setSFX

      public void setSFX(boolean sfx)
      Parameters:
      sfx - true if the special effects are enabled
      Throws:
      InternalError - in all cases
    • setStencilBits

      public void setStencilBits(int stencilBits)
      Parameters:
      stencilBits - the stencil bits
      Throws:
      InternalError - in all cases
    • setVerticalSync

      public void setVerticalSync(boolean verticalSync)
      Parameters:
      verticalSync - true if the vertical sync is enabled
      Throws:
      InternalError - in all cases
    • setWidth

      public void setWidth(int width)
    • wrappedSave

      public void wrappedSave()
      save() method which throws only a RuntimeException.
      See Also:
    • assignDefaults

      protected static void assignDefaults(String propFileName)
      Sets default* static variables according to GameSettings.DEFAULT_* values and an optional .properties file. Note that we are talking about defaults here, not user-specific settings.

      This method should be called once the game name is known to the subclass. To override any default with your subclass (as opposed to by using a .properties file), just set the static variable before or after calling this method (before or after depends on the precedence you want among programmatic and declarative DEFAULT_*, default* settings).

      Add new setting names by making your own method which does its own thing and calls AbstractGameSettings.assignDefaults(propfilename). Property file paths are relative to CLASSPATH element roots.
      Parameters:
      propFileName - Properties file read as CLASSPATH resource. If you give null, no properties file will be loaded.
    • loadBoolean

      public static Boolean loadBoolean(String name, Properties props)
    • loadInteger

      public static Integer loadInteger(String name, Properties props)
    • normalizeName

      protected static String normalizeName(String inName)
      Parameters:
      inName - Must be non-null
      Returns:
      normalized name. All lower-case with no shell meta-characters.