edu.rice.cs.drjava.config
Class ResourceBundleConfiguration

java.lang.Object
  extended by edu.rice.cs.drjava.config.Configuration
      extended by edu.rice.cs.drjava.config.SavableConfiguration
          extended by edu.rice.cs.drjava.config.FileConfiguration
              extended by edu.rice.cs.drjava.config.ResourceBundleConfiguration

public class ResourceBundleConfiguration
extends FileConfiguration

A configuration in a resource bundle.

Version:
$Id: ResourceBundleConfiguration.java 5246 2010-05-07 19:10:44Z mgricken $

Field Summary
protected  ResourceBundle _bundle
          Resource bundle containing the configuration.
protected  String _resourceBundleName
          Name of the resource bundle.
protected  FileConfiguration _shadowed
          Shadowed configuration used if the resource bundle does not define an option.
 
Fields inherited from class edu.rice.cs.drjava.config.FileConfiguration
file
 
Fields inherited from class edu.rice.cs.drjava.config.Configuration
_startupException, map
 
Constructor Summary
ResourceBundleConfiguration(String resourceBundleName, FileConfiguration shadowed)
          Initializes this Configuration object with the given OptionMap.
 
Method Summary
<T> void
addOptionListener(Option<T> op, OptionListener<T> l)
          Adds an OptionListener to the given Option, to be notified each time the option changes.
<T> T
getSetting(Option<T> op)
          Gets the current value of the given Option.
<T> boolean
isEditable(Option<T> op)
          Return true if the option is editable.
 void loadConfiguration()
          Calls SavableConfiguration.loadConfiguration, which loads all values from the file, based on the defaults in OptionConstants.
 void loadConfiguration(InputStream is)
          Creates an OptionMapLoader with the values loaded from the InputStream (and defaults where values weren't specified) and loads them into this Configuration's OptionMap.
<T> void
removeOptionListener(Option<T> op, OptionListener<T> l)
          Removes an OptionListener from an Option to which it was listening.
 void resetToDefaults()
          Resets to the default values, overwriting any existing values.
 void saveConfiguration()
          Saves the current settings to the stored properties file.
 void saveConfiguration(OutputStream os, String header)
          Used to save the values from this Configuration into the given OutputStream as a Properties file.
 void saveConfiguration(String header)
          Saves the current settings to the stored properties file.
<T> T
setSetting(Option<T> op, T value)
          Sets the given option to the given value and notifies all listeners of that option of the change.
 String toString()
          Returns a string representation of the contents of the OptionMap.
 
Methods inherited from class edu.rice.cs.drjava.config.FileConfiguration
getFile
 
Methods inherited from class edu.rice.cs.drjava.config.Configuration
getOptionMap, getStartupException, hadStartupException, storeStartupException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_resourceBundleName

protected final String _resourceBundleName
Name of the resource bundle.


_bundle

protected final ResourceBundle _bundle
Resource bundle containing the configuration.


_shadowed

protected final FileConfiguration _shadowed
Shadowed configuration used if the resource bundle does not define an option.

Constructor Detail

ResourceBundleConfiguration

public ResourceBundleConfiguration(String resourceBundleName,
                                   FileConfiguration shadowed)
Initializes this Configuration object with the given OptionMap.

Parameters:
resourceBundleName - name of the resource bundle
shadowed - configuration that should be used if the resource bundle does not define an option.
Method Detail

setSetting

public <T> T setSetting(Option<T> op,
                        T value)
Sets the given option to the given value and notifies all listeners of that option of the change.

Overrides:
setSetting in class Configuration
Parameters:
op - Option to set
value - New value for the option

getSetting

public <T> T getSetting(Option<T> op)
Gets the current value of the given Option.

Overrides:
getSetting in class Configuration

isEditable

public <T> boolean isEditable(Option<T> op)
Return true if the option is editable. If it was defined in the resource bundle, it is not editable.

Overrides:
isEditable in class Configuration

resetToDefaults

public void resetToDefaults()
Resets to the default values, overwriting any existing values.

Overrides:
resetToDefaults in class Configuration

toString

public String toString()
Returns a string representation of the contents of the OptionMap.

Overrides:
toString in class Configuration

loadConfiguration

public void loadConfiguration()
                       throws IOException
Calls SavableConfiguration.loadConfiguration, which loads all values from the file, based on the defaults in OptionConstants.

Overrides:
loadConfiguration in class FileConfiguration
Throws:
IOException

saveConfiguration

public void saveConfiguration()
                       throws IOException
Saves the current settings to the stored properties file.

Overrides:
saveConfiguration in class FileConfiguration
Throws:
IOException

saveConfiguration

public void saveConfiguration(String header)
                       throws IOException
Saves the current settings to the stored properties file.

Overrides:
saveConfiguration in class FileConfiguration
Parameters:
header - Description of the properties list
Throws:
IOException

loadConfiguration

public void loadConfiguration(InputStream is)
                       throws IOException
Creates an OptionMapLoader with the values loaded from the InputStream (and defaults where values weren't specified) and loads them into this Configuration's OptionMap.

Overrides:
loadConfiguration in class SavableConfiguration
Parameters:
is - InputStream containing properties-style keys and values
Throws:
IOException

saveConfiguration

public void saveConfiguration(OutputStream os,
                              String header)
                       throws IOException
Used to save the values from this Configuration into the given OutputStream as a Properties file. The elements weren't ordered, so now the properties are written in the same way as the about dialog. Values equal to their defaults are not written to disk.

Overrides:
saveConfiguration in class SavableConfiguration
Throws:
IOException

addOptionListener

public <T> void addOptionListener(Option<T> op,
                                  OptionListener<T> l)
Adds an OptionListener to the given Option, to be notified each time the option changes.

Overrides:
addOptionListener in class Configuration
Parameters:
op - Option to listen for changes on
l - OptionListener wishing to listen

removeOptionListener

public <T> void removeOptionListener(Option<T> op,
                                     OptionListener<T> l)
Removes an OptionListener from an Option to which it was listening.

Overrides:
removeOptionListener in class Configuration