| java.lang.Object com.jidesoft.converter.EnumConverter
EnumConverter | public class EnumConverter implements ObjectConverter(Code) | | A typical way to define a constant is to use int as the value type. For example, in SwingConstants, the following values
are defined.
public static final int CENTER = 0;
public static final int TOP = 1;
public static final int LEFT = 2;
public static final int BOTTOM = 3;
public static final int RIGHT = 4;
Before JDK1.5, there is no enum type, so this is one way to define enumeration.
When you use it, you just need to define a int field say _locaton and the
valid value for _location is one of the values above. If you want to display
it in UI and allow user to specify the value of _location, problem comes.
You don't want to use 0, 1, 2, 3, 4 as the value doesn't mean anything from user point of view.
You want user to be able to use meanful names such as "Center", "Top", "Left", "Bottom", "Right".
Obviously you need a converter here to convert from integer in an enum to string, such as converting from 0 to "Center" and vice versa.
That's what EnumConverter for.
Combining with EnumCellConverter, EnumCellEditor,
you can easily use combobox to choose value for _location like the example above using
meanful strings.
|
EnumConverter | public EnumConverter(String name, Class> type, Object[] objects, String[] strings, Object defaultValue)(Code) | | Creates an EnumConverter.
Parameters: name - the name of the converter. The name is used to create ConverterContext and later on the EditorContext. Parameters: type - the type of the element in objects array. Parameters: objects - the objects array. All elements in the objects array should have the same type. Parameters: strings - the strings array. It contains the meanful names for the elements in objects array.They should one to one match with each other. The length of strings array should be the same as that of objects array. Otherwise IllegalArgumentExceptio will be thrown. Parameters: defaultValue - the default value |
fromString | public Object fromString(String string, ConverterContext context)(Code) | | Converts the string to the object. It will find the string from the strings array and find the matching
object from objects array.
Parameters: string - the string to be converted Parameters: context - the converter context. the object of the string. |
getContext | public ConverterContext getContext()(Code) | | Gets the converter context of this converter. The name of the context
is the name of the converter where you pass in to EnumConverter's constructor.
the converter context of this converter. |
getDefault | public Object getDefault()(Code) | | Gets the default value of the converter if it failed to find the matching object for a particular string.
the default value. |
getName | public String getName()(Code) | | Gets the name of the converter.
the name of the converter. |
getObjects | public Object[] getObjects()(Code) | | Gets the objects array.
the objects array. |
getStrings | public String[] getStrings()(Code) | | Gets the strings array.
the strings array. |
getType | public Class> getType()(Code) | | Gets the type of the converter.
the type of the converter. |
toString | public String toString(Object object, ConverterContext context)(Code) | | Converts the object to string. It will find the object from the objects array and find the matching string
from strings array.
Parameters: object - the object to be converted. Parameters: context - the converter context. the string for the object. |
|
|