y.option
Class EnumOptionItem

java.lang.Object
  |
  +--y.option.OptionItem
        |
        +--y.option.EnumOptionItem

public class EnumOptionItem
extends OptionItem

An option item for a value that is chosen from a fixed range of possible values.

Provides an editor based on JComboBox.


Field Summary
 
Fields inherited from class y.option.OptionItem
COLOR_UNDEFINED, name, UNDEFINED
 
Constructor Summary
EnumOptionItem(String name)
          Creates an empty instance of EnumOptionItem.
EnumOptionItem(String name, Object[] values, int valueIndex)
          Creates a new instance of EnumOptionItem.
EnumOptionItem(String name, Object[] values, Object value)
          Creates a new instance of EnumOptionItem.
 
Method Summary
 void add(Object item)
          Convenience method that just calls EnumOptionItem.add(Object, Object) with item as both of the arguments
 void add(Object item, Object i18nKey)
          Populates the choices for this EnumOptionItem.
 void addAll(Map itemI18nPairs)
          This method is a convenience for the EnumOptionItem.add(Object, Object) method.
 boolean adoptEditorValue()
          Adopts the value from the editor component to the item.
 JComponent getEditor()
          Returns the editor component for the this option item.
 JComponent getEditor(GuiFactory gf, String parentName)
          Returns the editor component for the this option item.
 Object[] getEnumRange()
          Returns the range of possible values.
 int getIndex()
          Returns the index of the currently set value
 Object getInterpretedValue()
          This method can be used in conjunction with the empty constructor and the EnumOptionItem.add(Object, Object) method.
 String getStringValue()
          Returns the stringified value of this option item if the classType property is set, it uses the y.util.Serialization class to perform its task, otherwise it will return null.
 String getType()
          Returns "Enum"
 Object getValue()
          Returns the value of this option item
 void resetValue()
          Resets the value of this item to its initial value.
 void setEnum(Object[] values)
          Sets the range of possible values.
 void setEnum(Object[] values, Object value)
          Sets the range of possible values.
 void setInterpretedValue(Object valueObject)
          This method can be used in conjunction with the empty constructor and the EnumOptionItem.add(Object, Object) method.
 void setItemListener(ItemListener l)
          Sets the ItemListener for the editor component being used.
 void setRenderer(ListCellRenderer r)
          Sets the ListCellRenderer for the editor component used.
 void setStringValue(String value)
          Sets the stringified value of this option item if the classType property is set, it uses the y.util.Serialization class to perform its task, otherwise it will return null.
 void setUsingIntegers(boolean use)
           
 void setValue(Object v)
          Sets the current value of this option item.
 
Methods inherited from class y.option.OptionItem
checkEditorValue, getClassType, getName, getTipText, isValueUndefined, setClassType, setTipText, setValueUndefined, wantsVisibleName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnumOptionItem

public EnumOptionItem(String name,
                      Object[] values,
                      Object value)
Creates a new instance of EnumOptionItem.

Parameters:
name - the name of this item
values - the possible values of the option
value - the initial value of the option (must be contained in values)

EnumOptionItem

public EnumOptionItem(String name)
Creates an empty instance of EnumOptionItem. Subsequent calls to EnumOptionItem.addAll(java.util.Map), EnumOptionItem.add(Object) and EnumOptionItem.add(Object, Object) can be used to fill the Item with possible choices.

Parameters:
name - the name of this item

EnumOptionItem

public EnumOptionItem(String name,
                      Object[] values,
                      int valueIndex)
Creates a new instance of EnumOptionItem.

Parameters:
name - the name of this item
values - the possible values of the option
valueIndex - the array index of the initial value.
Method Detail

getType

public String getType()
Returns "Enum"

Specified by:
getType in class OptionItem

addAll

public void addAll(Map itemI18nPairs)
This method is a convenience for the EnumOptionItem.add(Object, Object) method. For all entries in the map, the add method will be called using the keys as the first argument and the values as the second one.


add

public void add(Object item)
Convenience method that just calls EnumOptionItem.add(Object, Object) with item as both of the arguments


add

public void add(Object item,
                Object i18nKey)
Populates the choices for this EnumOptionItem. This item will keep a mapping between the two arguments. The item can can be queried and set using the EnumOptionItem.getInterpretedValue() and EnumOptionItem.setInterpretedValue(Object) methods. The i18nKey will be used as the internal "value".

Parameters:
item - the item that can be queried and set using the EnumOptionItem.getInterpretedValue() and EnumOptionItem.setInterpretedValue(Object) methods.
i18nKey - the value as it would have been set using the 3 argument constructor

getInterpretedValue

public Object getInterpretedValue()
This method can be used in conjunction with the empty constructor and the EnumOptionItem.add(Object, Object) method. It will not return the internal "value"/i18nKey, but the item, that was the first argument of the add method.

Returns:
the value associated with the current value.

setInterpretedValue

public void setInterpretedValue(Object valueObject)
This method can be used in conjunction with the empty constructor and the EnumOptionItem.add(Object, Object) method. It will set the corresponding internal "value"/i18nKey, for the item, which has previously been passed to the add method as the first value.


getValue

public Object getValue()
Description copied from class: OptionItem
Returns the value of this option item

Specified by:
getValue in class OptionItem

setValue

public void setValue(Object v)
Sets the current value of this option item. If v is of type Integer then it's int value is considered to be the index of the current value. If v is of type String it's value will be set as current value.

Specified by:
setValue in class OptionItem

setUsingIntegers

public void setUsingIntegers(boolean use)

getIndex

public int getIndex()
Returns the index of the currently set value


adoptEditorValue

public boolean adoptEditorValue()
Description copied from class: OptionItem
Adopts the value from the editor component to the item.

Specified by:
adoptEditorValue in class OptionItem

getEnumRange

public Object[] getEnumRange()
Returns the range of possible values.


setEnum

public void setEnum(Object[] values,
                    Object value)
Sets the range of possible values.

Parameters:
values - the value range
value - the initial value

setEnum

public void setEnum(Object[] values)
Sets the range of possible values. Selectes the first value from the given range as initial value.

Parameters:
values - the value range

setItemListener

public void setItemListener(ItemListener l)
Sets the ItemListener for the editor component being used.


setRenderer

public void setRenderer(ListCellRenderer r)
Sets the ListCellRenderer for the editor component used.


resetValue

public void resetValue()
Description copied from class: OptionItem
Resets the value of this item to its initial value.

Specified by:
resetValue in class OptionItem

getEditor

public JComponent getEditor()
Description copied from class: OptionItem
Returns the editor component for the this option item. Note: Use the getEditor(GuiFactory,String) variant instead.

Specified by:
getEditor in class OptionItem

getEditor

public JComponent getEditor(GuiFactory gf,
                            String parentName)
Description copied from class: OptionItem
Returns the editor component for the this option item. Uses the given GuiFactory the create its content. The default implementation calls the no-arg getEditor() method to preserve backward compatibility. However it is suggested to override this method in order to make use of the GuiFactory.

Overrides:
getEditor in class OptionItem

setStringValue

public void setStringValue(String value)
Sets the stringified value of this option item if the classType property is set, it uses the y.util.Serialization class to perform its task, otherwise it will return null.

Overrides:
setStringValue in class OptionItem

getStringValue

public String getStringValue()
Returns the stringified value of this option item if the classType property is set, it uses the y.util.Serialization class to perform its task, otherwise it will return null.

Overrides:
getStringValue in class OptionItem

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003