net.ctdp.rfdynhud.widgets
Class WidgetsConfiguration

java.lang.Object
  extended by net.ctdp.rfdynhud.widgets.WidgetsConfiguration
All Implemented Interfaces:
PropertiesKeeper

public class WidgetsConfiguration
extends java.lang.Object
implements PropertiesKeeper

The WidgetsConfiguration handles the drawing of all visible widgets.

Author:
Marvin Froehlich (CTDP)

Nested Class Summary
static interface WidgetsConfiguration.ConfigurationLoadListener
           
 
Constructor Summary
WidgetsConfiguration(int gameResX, int gameResY)
          Creates a new WidgetsConfiguration.
 
Method Summary
 boolean addBorderAlias(java.lang.String alias, java.lang.String border)
          Maps a new border alias to its filename.
 boolean addNamedColor(java.lang.String name, java.awt.Color color)
          Maps a new named color.
 boolean addNamedFont(java.lang.String name, java.lang.String fontStr)
          Maps a new named font.
 java.lang.String findFreeName(java.lang.String baseName)
          Finds a free name starting with 'baseName'.
 java.util.Set<java.lang.String> getBorderAliases()
          Gets all currently mapped font names.
 java.lang.String getBorderName(java.lang.String alias)
          Gets a border filename from the map or null, if not found.
 java.util.Set<java.lang.String> getColorNames()
          Gets all currently mapped color names.
 java.util.Set<java.lang.String> getFontNames()
          Gets all currently mapped font names.
 GameResolution getGameResolution()
           
 int getId()
           
 InputMappings getInputMappings()
           
 java.lang.String getName()
           
 java.awt.Color getNamedColor(java.lang.String name)
          Gets a named color from the map or null, if not found.
 java.awt.Font getNamedFont(java.lang.String name)
          Gets a named font from the map or null, if not found.
 java.lang.String getNamedFontString(java.lang.String name)
          Gets a named font from the map or null, if not found.
 java.lang.Boolean getNamedFontVirtual(java.lang.String name)
          Gets a named font's virtual flag from the map or null, if not found.
 int getNumWidgets()
          Gets the number of Widgets in this manager.
 void getProperties(PropertiesContainer propsCont, boolean forceAll)
          Puts all editable properties to the editor.
 boolean getUseClassScoring()
          Gets whether class relative scoring is enabled or not.
 Widget getWidget(int index)
          Gets the index-th Widget from this manager.
 Widget getWidget(java.lang.String name)
          Gets the Widget with the specified name from this manager.
<W extends Widget>
W
getWidgetByClass(java.lang.Class<W> clazz, boolean includeSubclasses)
          Searches the Widgets in the WidgetsConfiguration for those of the passed type.
 boolean isValid()
           
 void loadProperty(PropertyLoader loader)
          Loads (and parses) a certain property from a config file.
 void onPropertyChanged(Property property, java.lang.Object oldValue, java.lang.Object newValue)
          Invoked when a kept Property has changed.
 java.lang.String removeBorderAlias(java.lang.String alias)
          Removes a mapped border alias.
 java.awt.Color removeNamedColor(java.lang.String name)
          Removes a mapped named color.
 java.awt.Font removeNamedFont(java.lang.String name)
          Removes a mapped named font.
 void renameBorder(java.lang.String oldName, java.lang.String newName)
           
 void renameColor(java.lang.String oldName, java.lang.String newName)
          Renames the color.
 void renameFont(java.lang.String oldName, java.lang.String newName)
           
 void resetBorders(java.lang.String oldName, java.lang.String newValue)
           
 void resetColors(java.lang.String oldName, java.lang.String newValue)
          Reset colors to defaults.
 void resetFonts(java.lang.String oldName, java.lang.String newValue)
           
 void saveProperties(PropertyWriter writer)
          Saves all settings to the config file.
 void setAllDirtyFlags()
          Sets the dirty flags on all Widgets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WidgetsConfiguration

public WidgetsConfiguration(int gameResX,
                            int gameResY)
Creates a new WidgetsConfiguration.

Parameters:
gameResX -
gameResY -
Method Detail

getId

public final int getId()

getName

public final java.lang.String getName()

isValid

public final boolean isValid()

findFreeName

public java.lang.String findFreeName(java.lang.String baseName)
Finds a free name starting with 'baseName'.

Parameters:
baseName - the name prefix
Returns:
the found free name.

getNumWidgets

public final int getNumWidgets()
Gets the number of Widgets in this manager.

Returns:
the number of Widgets in this manager.

getWidget

public final Widget getWidget(int index)
Gets the index-th Widget from this manager.

Parameters:
index - the Widget's index
Returns:
the index-th Widget from this manager.

getWidget

public final Widget getWidget(java.lang.String name)
Gets the Widget with the specified name from this manager.

Parameters:
name - the Widget's name
Returns:
the Widget with the specified name from this manager.

getWidgetByClass

public final <W extends Widget> W getWidgetByClass(java.lang.Class<W> clazz,
                                                   boolean includeSubclasses)
Searches the Widgets in the WidgetsConfiguration for those of the passed type.

Type Parameters:
W - the return type
Parameters:
clazz - the return type restriction
includeSubclasses - whether to search for the specific class only or also for subclasses of it
Returns:
the first matching Widget or null.

setAllDirtyFlags

public void setAllDirtyFlags()
Sets the dirty flags on all Widgets.


getInputMappings

public final InputMappings getInputMappings()

getGameResolution

public final GameResolution getGameResolution()

addNamedColor

public boolean addNamedColor(java.lang.String name,
                             java.awt.Color color)
Maps a new named color.

Parameters:
name - the name
color - the color
Returns:
changed?

getNamedColor

public final java.awt.Color getNamedColor(java.lang.String name)
Gets a named color from the map or null, if not found.

Parameters:
name - the name
Returns:
a named color from the map or null, if not found.

getColorNames

public final java.util.Set<java.lang.String> getColorNames()
Gets all currently mapped color names.

Returns:
all currently mapped color names.

removeNamedColor

public java.awt.Color removeNamedColor(java.lang.String name)
Removes a mapped named color.

Parameters:
name - the name
Returns:
the previously mapped color.

renameColor

public void renameColor(java.lang.String oldName,
                        java.lang.String newName)
Renames the color.

Parameters:
oldName - the old name
newName - the new name

resetColors

public void resetColors(java.lang.String oldName,
                        java.lang.String newValue)
Reset colors to defaults.

Parameters:
oldName - the old name
newValue - the new name

addNamedFont

public boolean addNamedFont(java.lang.String name,
                            java.lang.String fontStr)
Maps a new named font.

Parameters:
name - the name
fontStr - tje font definition
Returns:
changed?

getNamedFont

public final java.awt.Font getNamedFont(java.lang.String name)
Gets a named font from the map or null, if not found.

Parameters:
name - the name
Returns:
a named font from the map or null, if not found.

getNamedFontString

public final java.lang.String getNamedFontString(java.lang.String name)
Gets a named font from the map or null, if not found.

Parameters:
name - the name
Returns:
a named font from the map or null, if not found.

getNamedFontVirtual

public final java.lang.Boolean getNamedFontVirtual(java.lang.String name)
Gets a named font's virtual flag from the map or null, if not found.

Parameters:
name - the name
Returns:
a named font's virtual flag from the map or null, if not found.

getFontNames

public final java.util.Set<java.lang.String> getFontNames()
Gets all currently mapped font names.

Returns:
all currently mapped font names.

removeNamedFont

public java.awt.Font removeNamedFont(java.lang.String name)
Removes a mapped named font.

Parameters:
name - the name
Returns:
the previously mapped font.

renameFont

public void renameFont(java.lang.String oldName,
                       java.lang.String newName)

resetFonts

public void resetFonts(java.lang.String oldName,
                       java.lang.String newValue)

addBorderAlias

public boolean addBorderAlias(java.lang.String alias,
                              java.lang.String border)
Maps a new border alias to its filename.

Parameters:
alias - the alias name
border - the border
Returns:
changed?

getBorderName

public final java.lang.String getBorderName(java.lang.String alias)
Gets a border filename from the map or null, if not found.

Parameters:
alias - the alias name
Returns:
a border filename from the map or null, if not found.

getBorderAliases

public final java.util.Set<java.lang.String> getBorderAliases()
Gets all currently mapped font names.

Returns:
all currently mapped font names.

removeBorderAlias

public java.lang.String removeBorderAlias(java.lang.String alias)
Removes a mapped border alias.

Parameters:
alias - the alias name
Returns:
the previously mapped border alias.

renameBorder

public void renameBorder(java.lang.String oldName,
                         java.lang.String newName)

resetBorders

public void resetBorders(java.lang.String oldName,
                         java.lang.String newValue)

getUseClassScoring

public final boolean getUseClassScoring()
Gets whether class relative scoring is enabled or not.

Returns:
whether class relative scoring is enabled or not.

onPropertyChanged

public void onPropertyChanged(Property property,
                              java.lang.Object oldValue,
                              java.lang.Object newValue)
Invoked when a kept Property has changed.

Specified by:
onPropertyChanged in interface PropertiesKeeper
Parameters:
property - the changed property
oldValue - the old value
newValue - the new value

saveProperties

public void saveProperties(PropertyWriter writer)
                    throws java.io.IOException
Saves all settings to the config file.

Specified by:
saveProperties in interface PropertiesKeeper
Parameters:
writer - the widgets configuration writer to write properties to
Throws:
java.io.IOException - if something went wrong

loadProperty

public void loadProperty(PropertyLoader loader)
Loads (and parses) a certain property from a config file.

Specified by:
loadProperty in interface PropertiesKeeper
Parameters:
loader - the property loader to load properties from

getProperties

public void getProperties(PropertiesContainer propsCont,
                          boolean forceAll)
Puts all editable properties to the editor.

Specified by:
getProperties in interface PropertiesKeeper
Parameters:
propsCont - the container to add the properties to
forceAll - If true, all properties provided by this PropertiesKeeper must be added. If false, only the properties, that are relevant for the current PropertiesKeeper's situation have to be added, some can be ignored.