edu.rice.cs.drjava.ui.config
Class OptionComponent<T,C extends JComponent>

java.lang.Object
  extended by edu.rice.cs.drjava.ui.config.OptionComponent<T,C>
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BooleanOptionComponent, ButtonComponent, ColorOptionComponent, DirectoryOptionComponent, FileOptionComponent, FontOptionComponent, ForcedChoiceOptionComponent, IntegerOptionComponent, KeyStrokeOptionComponent, LabelComponent, StringOptionComponent, ToolbarOptionComponent, VectorOptionComponent

public abstract class OptionComponent<T,C extends JComponent>
extends Object
implements Serializable

The graphical form of an Option. Provides a way to see the values of Option while running DrJava and perform live updating of Options.

Version:
$Id: OptionComponent.java 5232 2010-04-24 00:14:05Z mgricken $
See Also:
Serialized Form

Nested Class Summary
static interface OptionComponent.ChangeListener
          Interface for change listener.
 
Field Summary
private  Vector<OptionComponent.ChangeListener> _changeListeners
          List of change listeners.
protected  boolean _entireColumn
           
protected  C _guiComponent
           
protected  JLabel _label
           
protected  String _labelText
           
protected  Option<T> _option
           
protected  SwingFrame _parent
           
 
Constructor Summary
OptionComponent(Option<T> option, String labelText, SwingFrame parent)
           
OptionComponent(String labelText, SwingFrame parent)
          Special constructor for degenerate option components does not take an option.
 
Method Summary
 void addChangeListener(OptionComponent.ChangeListener listener)
          Adds a change listener to this component.
 C getComponent()
          Returns the JComponent to display for this OptionComponent.
 boolean getEntireColumn()
          Whether the component should occupy the entire column.
 JLabel getLabel()
           
 String getLabelText()
           
 Option<T> getOption()
           
protected  void notifyChangeListeners()
          Notify all change listeners of a change.
 void removeChangeListener(OptionComponent.ChangeListener listener)
          Removes a change listener to this component.
 void resetToCurrent()
          Resets the entry field to reflect the actual stored value for the option.
 void resetToDefault()
          Resets the actual value of the component to the original default.
 void setComponent(C component)
          Set the JComponent to display for this OptionComponent.
abstract  void setDescription(String description)
          Sets the detailed description text for all components in this OptionComponent.
 OptionComponent<T,C> setEntireColumn(boolean entireColumn)
          Whether the component should occupy the entire column.
abstract  void setValue(T value)
          Sets the value that is currently displayed by this component.
 void showErrorMessage(String title, OptionParseException e)
           
 void showErrorMessage(String title, String value, String message)
           
abstract  boolean updateConfig()
          Updates the appropriate configuration option with the new value if different from the old one and legal.
 boolean useEntireColumn()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_option

protected final Option<T> _option

_label

protected final JLabel _label

_parent

protected final SwingFrame _parent

_entireColumn

protected volatile boolean _entireColumn

_labelText

protected volatile String _labelText

_guiComponent

protected volatile C extends JComponent _guiComponent

_changeListeners

private volatile Vector<OptionComponent.ChangeListener> _changeListeners
List of change listeners. A volatile Vector is used here because a race involving operations on this field was encountered in MainFrameTest during _frame.pack() in initialization. It previously was a nonvolatile ArrayList.

Constructor Detail

OptionComponent

public OptionComponent(Option<T> option,
                       String labelText,
                       SwingFrame parent)

OptionComponent

public OptionComponent(String labelText,
                       SwingFrame parent)
Special constructor for degenerate option components does not take an option.

Parameters:
labelText - Text for descriptive label of this option.
parent - The parent frame.
Method Detail

getOption

public Option<T> getOption()

getLabelText

public String getLabelText()

getLabel

public JLabel getLabel()

useEntireColumn

public boolean useEntireColumn()

getComponent

public C getComponent()
Returns the JComponent to display for this OptionComponent.


setComponent

public void setComponent(C component)
Set the JComponent to display for this OptionComponent.

Parameters:
component - GUI component

setDescription

public abstract void setDescription(String description)
Sets the detailed description text for all components in this OptionComponent. Should be called by subclasses that wish to display a description.

Parameters:
description - the description of the component

setEntireColumn

public OptionComponent<T,C> setEntireColumn(boolean entireColumn)
Whether the component should occupy the entire column.


getEntireColumn

public boolean getEntireColumn()
Whether the component should occupy the entire column.


updateConfig

public abstract boolean updateConfig()
Updates the appropriate configuration option with the new value if different from the old one and legal. Any changes should be done immediately so that current and future references to the Option should reflect the changes.

Returns:
false, if value is invalid; otherwise true. This method may spawn asynchronous event thread tasks via firing OptionListeners and textField DocumentListeners.

resetToCurrent

public void resetToCurrent()
Resets the entry field to reflect the actual stored value for the option.


resetToDefault

public void resetToDefault()
Resets the actual value of the component to the original default.


setValue

public abstract void setValue(T value)
Sets the value that is currently displayed by this component.


showErrorMessage

public void showErrorMessage(String title,
                             OptionParseException e)

showErrorMessage

public void showErrorMessage(String title,
                             String value,
                             String message)

addChangeListener

public void addChangeListener(OptionComponent.ChangeListener listener)
Adds a change listener to this component.

Parameters:
listener - listener to add

removeChangeListener

public void removeChangeListener(OptionComponent.ChangeListener listener)
Removes a change listener to this component.

Parameters:
listener - listener to remove

notifyChangeListeners

protected void notifyChangeListeners()
Notify all change listeners of a change. Notification performed in the event thread.