cdx.scorebot.util.swing
Class SettingsFile

java.lang.Object
  extended by cdx.scorebot.util.swing.SettingsFile
All Implemented Interfaces:
java.io.Serializable

public class SettingsFile
extends java.lang.Object
implements java.io.Serializable

Stores and retrieves settings to and from a file

Author:
David Underhill
See Also:
Serialized Form

Field Summary
static int DEFAULT_MAX_RECENT_FILES
          default number recent files
 
Constructor Summary
SettingsFile()
           
 
Method Summary
 java.lang.Object get(java.lang.String key)
          gets the value of a particular setting; returns null if there is no setting by this name
static SettingsFile getFromXML()
          gets a settings file from XML; uses the default filename settings.xml
static SettingsFile getFromXML(java.lang.String fn)
          gets a settings file from XML
static SettingsFile getFromXML(java.lang.String fn, FileOpener parent, javax.swing.JMenuItem[] menus)
          gets a settings file from XML
 int getMaxRecentFiles()
          get the max number of recent files to track
 javax.swing.JMenuItem[] getMenu()
          gets the menus to which recently used menus should be appended
 java.lang.String getMostRecentFile()
          gets the most recently used file
 java.lang.String getMyFilename()
           
 FileOpener getParent()
          gets the parent class which is used to open files when a menu is clicked
 java.util.Vector<java.lang.String> getRecentFiles()
          returns a list of recently used files
 void noteFileUsed(java.lang.String file)
          update recent files; file has been used
 void populateRecentlyUsedMenus()
          Populate the attached menu with the appropriate menus (does nothing if recentlyUsedMenus or parent is set to null).
 void remove(java.lang.String key)
          removes the value of a particular setting
 void set(java.lang.String key, java.lang.Object value)
          sets the value of a particular setting
 void setMaxRecentFiles(int maxRecentFiles)
          set the max number of recent files to track
 void setMenu(javax.swing.JMenuItem[] menus)
          sets the menus to which recently used menus should be appended
 void setMyFilename(java.lang.String myFilename)
           
 void setParent(FileOpener parent)
          sets the parent class which is used to open files when a menu is clicked
 void unnoteFileUsed(java.lang.String file)
          update recent files; file is no longer available
 void writeToXML()
          saves the settings to the current settings file
 void writeToXML(java.lang.String fn)
          saves the settings to the default settings file (and sets the name to fn)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MAX_RECENT_FILES

public static final int DEFAULT_MAX_RECENT_FILES
default number recent files

See Also:
Constant Field Values
Constructor Detail

SettingsFile

public SettingsFile()
Method Detail

getRecentFiles

public java.util.Vector<java.lang.String> getRecentFiles()
returns a list of recently used files


getMaxRecentFiles

public int getMaxRecentFiles()
get the max number of recent files to track


setMaxRecentFiles

public void setMaxRecentFiles(int maxRecentFiles)
set the max number of recent files to track


get

public java.lang.Object get(java.lang.String key)
gets the value of a particular setting; returns null if there is no setting by this name

Parameters:
key - the name of the setting to get
Returns:
gets the value of the setting (null if nothing is associated with the key)

set

public void set(java.lang.String key,
                java.lang.Object value)
sets the value of a particular setting

Parameters:
key - the name of the setting to set
value - the value of the setting

remove

public void remove(java.lang.String key)
removes the value of a particular setting

Parameters:
key - the name of the setting to set

getMostRecentFile

public java.lang.String getMostRecentFile()
gets the most recently used file


noteFileUsed

public void noteFileUsed(java.lang.String file)
update recent files; file has been used

Parameters:
file - path to the file just used

unnoteFileUsed

public void unnoteFileUsed(java.lang.String file)
update recent files; file is no longer available

Parameters:
file - path to the file which is no longer available

populateRecentlyUsedMenus

public void populateRecentlyUsedMenus()
Populate the attached menu with the appropriate menus (does nothing if recentlyUsedMenus or parent is set to null).


getFromXML

public static SettingsFile getFromXML()
gets a settings file from XML; uses the default filename settings.xml


getFromXML

public static SettingsFile getFromXML(java.lang.String fn)
gets a settings file from XML

Parameters:
fn - the name of the file the settings are stored in
Returns:
the settings from the file, or a blank settings object if the file could not be read

getFromXML

public static SettingsFile getFromXML(java.lang.String fn,
                                      FileOpener parent,
                                      javax.swing.JMenuItem[] menus)
gets a settings file from XML

Parameters:
fn - the name of the file the settings are stored in
parent - the GUI which contains these menus and can open files
menus - the menus to populate with the recent files list
Returns:
the settings from the file, or a blank settings object if the file could not be read

writeToXML

public void writeToXML()
saves the settings to the current settings file


writeToXML

public void writeToXML(java.lang.String fn)
saves the settings to the default settings file (and sets the name to fn)

Parameters:
fn - the name of the file the settings are stored in

getMenu

public javax.swing.JMenuItem[] getMenu()
gets the menus to which recently used menus should be appended


setMenu

public void setMenu(javax.swing.JMenuItem[] menus)
sets the menus to which recently used menus should be appended


getParent

public FileOpener getParent()
gets the parent class which is used to open files when a menu is clicked


setParent

public void setParent(FileOpener parent)
sets the parent class which is used to open files when a menu is clicked


getMyFilename

public java.lang.String getMyFilename()

setMyFilename

public void setMyFilename(java.lang.String myFilename)