ecologylab.appframework.types.prefs.gui
Class PrefEditorWidgets

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.appframework.types.prefs.gui.PrefEditorWidgets
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.ChangeListener
Direct Known Subclasses:
PrefsEditor

public class PrefEditorWidgets
extends Debug
implements javax.swing.event.ChangeListener

Contains methods for creating widgets associated with Prefs.

Author:
Zachary O. Toups (toupsz@cs.tamu.edu)

Field Summary
static java.lang.String IDENTIFIER_SPINNER
          The string that will be added to the metapref's id, to create a unique identifier for a jComponent.
protected  java.util.HashMap<java.lang.String,java.util.LinkedHashMap<java.lang.String,Scope<javax.swing.JComponent>>> jCatComponentsMap
          Okay, this is really, really important.
protected  javax.swing.JPanel jContentPane
          Content pane within base window for GUI
protected  MetaPrefSet metaPrefSet
          Set of MetaPrefs
protected  PrefSet prefSet
          Set of Prefs
protected static int RIGHT_GUI_INSET
          The inset between the right side of the gui panel and the right side of values.
protected  ParsedURL savePrefsPURL
          PURL to save prefs.xml to
protected static int TEXT_FIELD_PADDING
          The padding between the default value in a text field and either side of the text field.
 
Constructor Summary
PrefEditorWidgets(MetaPrefSet metaPrefSet, PrefSet prefSet, ParsedURL savePrefsPURL)
          The base function that you call to construct the prefs editor GUI.
 
Method Summary
 void actionSavePreferences()
          Save the preferences; called by #createApplyButton() and #createSaveButton().
protected  javax.swing.JCheckBox createCheckBox(javax.swing.JPanel panel, MetaPref mp)
          Creates a check box.
protected  javax.swing.JComboBox createDropDown(javax.swing.JPanel panel, MetaPref mp)
          Creates a drop down menu; combo box.
protected  javax.swing.JSlider createSlider(javax.swing.JPanel panel, MetaPref mp, java.lang.String labelAndName, boolean valuesAreAltered, int valueAlteredBy)
          Creates a slider.
protected  javax.swing.JSpinner createSpinner(javax.swing.JPanel panel, MetaPref mp)
          Creates a spinner.
protected  javax.swing.JTextField createTextField(javax.swing.JPanel panel, MetaPref mp)
          Creates a text field.
 javax.swing.JPanel getJContentPane()
          Get the jContentPane for the editor.
protected  Scope<javax.swing.JComponent> jCatComponentsMap(MetaPref mp)
          Returns the ObjectRegistry for this MetaPref's jComponents.
protected  javax.swing.JComponent lookupComponent(MetaPref mp, java.lang.String labelAndName)
          Returns a JComponent from the ObjectRegistry by name
 void registerComponent(MetaPref mp, java.lang.String labelAndName, javax.swing.JComponent jComponent)
          Registers a JComponent with the ObjectRegistry
protected  void savePrefs()
           
 void stateChanged(javax.swing.event.ChangeEvent e)
          This is for sliders; when we move the slider, we need to update the tooltip and force it to display.
 void updatePrefsFromWidgets()
          Queries all widgets and updates their associated Prefs; this will cascade and cause each Pref to notify all PrefChangedListeners associated with Pref.
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

IDENTIFIER_SPINNER

public static final java.lang.String IDENTIFIER_SPINNER
The string that will be added to the metapref's id, to create a unique identifier for a jComponent.

See Also:
Constant Field Values

RIGHT_GUI_INSET

protected static final int RIGHT_GUI_INSET
The inset between the right side of the gui panel and the right side of values.

See Also:
Constant Field Values

TEXT_FIELD_PADDING

protected static final int TEXT_FIELD_PADDING
The padding between the default value in a text field and either side of the text field.

See Also:
Constant Field Values

jCatComponentsMap

protected java.util.HashMap<java.lang.String,java.util.LinkedHashMap<java.lang.String,Scope<javax.swing.JComponent>>> jCatComponentsMap
Okay, this is really, really important. The map goes like this: CategoryName to (MetaPrefName to (Array of JComponents)) So for each category, you get a sorted map of the metaprefs in that category. From that map you can get a list of all the components for a metapref by name.


metaPrefSet

protected MetaPrefSet metaPrefSet
Set of MetaPrefs


prefSet

protected PrefSet prefSet
Set of Prefs


savePrefsPURL

protected ParsedURL savePrefsPURL
PURL to save prefs.xml to


jContentPane

protected javax.swing.JPanel jContentPane
Content pane within base window for GUI

Constructor Detail

PrefEditorWidgets

public PrefEditorWidgets(MetaPrefSet metaPrefSet,
                         PrefSet prefSet,
                         ParsedURL savePrefsPURL)
The base function that you call to construct the prefs editor GUI. This requires that the MetaPrefSet and PrefSet be instantiated and populated prior to call. This function creates the entire GUI and handles all actions for it.

Parameters:
metaPrefSet - Set of MetaPrefs
prefSet - Set of Prefs
savePrefsPURL - ParsedURL to save prefs.xml to
isStandalone - Whether or not we're calling this standalone
Method Detail

createTextField

protected javax.swing.JTextField createTextField(javax.swing.JPanel panel,
                                                 MetaPref mp)
Creates a text field.

Parameters:
panel - JPanel this field will be associated with.
mp - MetaPref this field is for.
Returns:
JTextField with properties initialized to parameters.

createCheckBox

protected javax.swing.JCheckBox createCheckBox(javax.swing.JPanel panel,
                                               MetaPref mp)
Creates a check box.

Parameters:
panel - JPanel this button will be associated with.
mp - MetaPref this checkbox is being created for.
Returns:
JCheckBox with properties initialized to parameters.

createDropDown

protected javax.swing.JComboBox createDropDown(javax.swing.JPanel panel,
                                               MetaPref mp)
Creates a drop down menu; combo box.

Parameters:
panel - JPanel this field will be associated with.
mp - MetaPref this combo box is being created for.
Returns:
JComboBox with properties initialized to parameters.

createSlider

protected javax.swing.JSlider createSlider(javax.swing.JPanel panel,
                                           MetaPref mp,
                                           java.lang.String labelAndName,
                                           boolean valuesAreAltered,
                                           int valueAlteredBy)
Creates a slider.

Parameters:
panel - JPanel this slider will be associated with.
mp - MetaPref this slider is being created for.
labelAndName - Name of slider
valuesAreAltered - Whether or not the values of the metapref/pref need to be altered for the slider.
valueAlteredBy - How much the metapref/pref values are multiplied/ divided by. Only used if valuesAreAltered=true.
Returns:
JSlider with properties initialized to parameters.

createSpinner

protected javax.swing.JSpinner createSpinner(javax.swing.JPanel panel,
                                             MetaPref mp)
Creates a spinner. This is a text field with up/down arrows that allow you to increase/decrease the value in the text box.

Parameters:
panel - JPanel this spinner will be associated with.
mp - MetaPref this spinner is being created for.
Returns:
JSpinner with properties initialized to parameters.

jCatComponentsMap

protected Scope<javax.swing.JComponent> jCatComponentsMap(MetaPref mp)
Returns the ObjectRegistry for this MetaPref's jComponents.

Parameters:
mp - MetaPref whose jComponents we want.
Returns:
ObjectRegistry for MetaPref's jComponents.

registerComponent

public void registerComponent(MetaPref mp,
                              java.lang.String labelAndName,
                              javax.swing.JComponent jComponent)
Registers a JComponent with the ObjectRegistry

Parameters:
mp - metapref we want to register
labelAndName - label/name to add to the metapref's id to identify a particular jComponent. must be UNIQUE.
jComponent - jComponent to register

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
This is for sliders; when we move the slider, we need to update the tooltip and force it to display. TODO: change placement of tooltip

Specified by:
stateChanged in interface javax.swing.event.ChangeListener

updatePrefsFromWidgets

public void updatePrefsFromWidgets()
Queries all widgets and updates their associated Prefs; this will cascade and cause each Pref to notify all PrefChangedListeners associated with Pref.


lookupComponent

protected javax.swing.JComponent lookupComponent(MetaPref mp,
                                                 java.lang.String labelAndName)
Returns a JComponent from the ObjectRegistry by name

Parameters:
mp - metapref to look up
labelAndName - the label/name that was added to the metapref's id to identify a particular jComponent
Returns:
JComponent matching labelAndName from ObjectRegistry

savePrefs

protected void savePrefs()

actionSavePreferences

public void actionSavePreferences()
Save the preferences; called by #createApplyButton() and #createSaveButton(). Saves the prefs to savePrefsPURL.


getJContentPane

public javax.swing.JPanel getJContentPane()
Get the jContentPane for the editor.

Returns: