plugins.adufour.vars.gui.swing
Class ComboBox<T>

java.lang.Object
  extended by plugins.adufour.vars.gui.VarEditor<V>
      extended by plugins.adufour.vars.gui.swing.SwingVarEditor<T>
          extended by plugins.adufour.vars.gui.swing.ComboBox<T>
All Implemented Interfaces:
VarListener<T>
Direct Known Subclasses:
TypeChooser

public class ComboBox<T>
extends SwingVarEditor<T>


Field Summary
 
Fields inherited from class plugins.adufour.vars.gui.VarEditor
variable
 
Constructor Summary
ComboBox(Var<T> variable)
          Creates a new combo box component for the specified variable.
 
Method Summary
protected  void activateListeners()
          Activates listeners on the editor component.
protected  javax.swing.ComboBoxEditor createEditor()
           
 javax.swing.JComponent createEditorComponent()
          Creates the component to display on the graphical user interface, allowing the user to modify the variable's value via appropriate listeners (listeners should be added or removed via the VarEditor.activateListeners() and VarEditor.deactivateListeners() methods).
In order to allow multiple editors to modify the same variable, this method should always return a newly constructed component (by Swing design, a same component can only be used once per interface).
Once created, the component is stored in the final VarEditor.editorComponent field to avoid unnecessary re-creations (e.g.
protected  javax.swing.ListCellRenderer createRenderer()
           
protected  void deactivateListeners()
          Deactivates listeners on the editor component.
 void dispose()
          Dispose of resources (e.g.
 javax.swing.JComboBox getEditorComponent()
           
 void setDefaultValues(T[] values, int defaultValueIndex, boolean allowUserInput)
          Replaces the list of values available in the combo box of this variable
NOTE: this method will replace the current constraint on the variable
protected  void updateInterfaceValue()
          Updates the graphical interface component to reflect the new value of the underlying variable (accessible via the Var.getValue() method).
protected  void updateVariableValue()
           
 
Methods inherited from class plugins.adufour.vars.gui.swing.SwingVarEditor
getPreferredSize, isComponentEnabled, isComponentOpaque, setComponentToolTipText, setEditorEnabled
 
Methods inherited from class plugins.adufour.vars.gui.VarEditor
getComponentHorizontalResizeFactor, getComponentVerticalResizeFactor, getVariable, isComponentFocusable, isComponentResizeable, isNameVisible, referenceChanged, setComponentFocusable, setComponentResizeable, setEnabled, setNameVisible, valueChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComboBox

public ComboBox(Var<T> variable)
         throws java.lang.IllegalArgumentException
Creates a new combo box component for the specified variable. Note that the specified variable must have a constraint of type ValueSelectionModel

Parameters:
variable - the variable to attach to this component
Throws:
java.lang.IllegalArgumentException - if the variable has no constraint, or if the constraint is not a ValueSelectionModel
Method Detail

createEditorComponent

public javax.swing.JComponent createEditorComponent()
                                             throws java.lang.IllegalArgumentException
Description copied from class: VarEditor
Creates the component to display on the graphical user interface, allowing the user to modify the variable's value via appropriate listeners (listeners should be added or removed via the VarEditor.activateListeners() and VarEditor.deactivateListeners() methods).
In order to allow multiple editors to modify the same variable, this method should always return a newly constructed component (by Swing design, a same component can only be used once per interface).
Once created, the component is stored in the final VarEditor.editorComponent field to avoid unnecessary re-creations (e.g. during interface refresh). To bypass this optimization and force the creation of a new component for every interface refresh, consider overriding the VarEditor.getEditorComponent() method.

WARNING: this method is called within the VarEditor.VarEditor(Var) constructor, therefore all instance fields besides the final VarEditor.variable field will be null until this method returns.

Specified by:
createEditorComponent in class SwingVarEditor<T>
Returns:
a graphical input component that is linked to the variable and can be used to view or adjust the variable value
Throws:
java.lang.IllegalArgumentException

createRenderer

protected javax.swing.ListCellRenderer createRenderer()

createEditor

protected javax.swing.ComboBoxEditor createEditor()

setDefaultValues

public void setDefaultValues(T[] values,
                             int defaultValueIndex,
                             boolean allowUserInput)
Replaces the list of values available in the combo box of this variable
NOTE: this method will replace the current constraint on the variable

Parameters:
values -
defaultValueIndex -
allowUserInput -

updateVariableValue

protected void updateVariableValue()

updateInterfaceValue

protected void updateInterfaceValue()
Description copied from class: VarEditor
Updates the graphical interface component to reflect the new value of the underlying variable (accessible via the Var.getValue() method).

Specified by:
updateInterfaceValue in class VarEditor<T>

dispose

public void dispose()
Description copied from class: VarEditor
Dispose of resources (e.g. listeners, IO etc.) before releasing the editor. This method must be called by overriding implementations to ensure proper cleaning

Overrides:
dispose in class VarEditor<T>

getEditorComponent

public javax.swing.JComboBox getEditorComponent()
Overrides:
getEditorComponent in class SwingVarEditor<T>
Returns:
the graphical component used to view or modify the variable's value. By default, the returned component is the one created by the VarEditor.createEditorComponent() method during object construction. This method can be overridden to return a new component for each call (note however that this method may be called many times, e.g. during interface refresh)

activateListeners

protected void activateListeners()
Description copied from class: VarEditor
Activates listeners on the editor component. Listeners should be activated here rather than in the VarEditor.createEditorComponent() method, in order to allow the target containers to optimize the scheduling and load of events to fire, and to ensure proper garbage collection when the interface is destroyed.

Specified by:
activateListeners in class VarEditor<T>

deactivateListeners

protected void deactivateListeners()
Description copied from class: VarEditor
Deactivates listeners on the editor component. Listeners should be deactivated here rather than in the VarEditor.createEditorComponent() method, in order to allow the target containers to optimize the scheduling and load of events to fire, and to ensure proper garbage collection when the interface is destroyed.

Specified by:
deactivateListeners in class VarEditor<T>