Class sunsoft.jws.visual.rt.type.BaseEnum
All Packages Class Hierarchy This Package Previous Next Index
Class sunsoft.jws.visual.rt.type.BaseEnum
java.lang.Object
|
+----sunsoft.jws.visual.rt.type.BaseEnum
- public class BaseEnum
- extends Object
- implements Cloneable
Base class for types that implement enumerations (in the C style) where
an integer signifies an important answer to a multiple-choice question.
Sub-classers are supposed to supply the list of strings that describe the
enumerations values available (and their corresponding integer values)
in their static initializers. Sub-classes should set up their own
instance of the BaseEnumHelper class to hold their enumeration definition.
When you sub-class off of BaseEnum, Visual Java will automatically
recognize your type as an enumeration, and offer a choice menu in
the attribute editor of Visual Java for selecting the value of an
attribute of that type.
The AlignmentEnum, shown below, is used for setting whether the
text in a Label will appear on the left, center, or right.
To use the example below to create a new enumerated type, copy
everything and then modify the imports and static constructor to use
the constants and names for the choices you'd like to offer in your
enumeration.
The addConverter call will register your type with Visual Java's
type conversion interface and make it understood that this type is
an enumeration. Change the
"sunsoft.jws.visual.rt.type.AlignmentEnum" argument to reflect the
package name and class of your new enumerated type.
package sunsoft.jws.visual.rt.type;
import sunsoft.jws.visual.rt.type.BaseEnum;
import sunsoft.jws.visual.rt.type.BaseEnumHelper;
import sunsoft.jws.visual.rt.type.Converter;
import java.awt.Label;
public class AlignmentEnum extends BaseEnum {
private static BaseEnumHelper helper = new BaseEnumHelper();
static {
helper.add(Label.LEFT, "left");
helper.add(Label.CENTER, "center");
helper.add(Label.RIGHT, "right");
helper.setDefaultChoice(Label.LEFT);
Converter.addConverter("sunsoft.jws.visual.rt.type.AlignmentEnum",
"sunsoft.jws.visual.rt.type.BaseEnumConverter");
}
public AlignmentEnum() {
super();
}
public AlignmentEnum(int choice) {
super(choice);
}
public AlignmentEnum(String choice) {
super(choice);
}
protected BaseEnumHelper getHelper() {
return(helper);
}
}
- See Also:
- BaseEnumHelper, AlignmentEnum, Label
-
currentChoice
- The currently selected value from the enum.
-
BaseEnum()
- Constructor, sets the choice to the default.
-
BaseEnum(int)
- Constructor to use when integer value is available.
-
BaseEnum(String)
- Constructor to use when string of choice is available.
-
clone()
- Returns a copy of this enumeration instance.
-
descriptions()
- Returns an array containing all of the String descriptions
available in this enum.
-
elements()
- Returns a java.util.Enumeration of the String descriptions
available in this enum.
-
equals(Object)
- Returns true if this enumeration instance and the one given have
the same selection made.
-
getHelper()
- Gets the helper class that stores the enum definition.
-
intValue()
- Returns the int value of the current selection from the enumeration.
-
set(int)
- Sets the enumeration to the given integer value.
-
set(String)
- Sets the enumeration to the given string value.
-
toString()
- Returns the String description of the current selection from the
enumeration.
currentChoice
protected Integer currentChoice
- The currently selected value from the enum.
BaseEnum
protected BaseEnum()
- Constructor, sets the choice to the default.
BaseEnum
protected BaseEnum(int choice)
- Constructor to use when integer value is available.
- Parameters:
- choice - enumerated value
BaseEnum
protected BaseEnum(String choice)
- Constructor to use when string of choice is available.
- Parameters:
- choice - enumerated value
getHelper
protected abstract BaseEnumHelper getHelper()
- Gets the helper class that stores the enum definition.
Each sub-classer should override this so that a different
class-wide instance of BaseEnumHelper is returned. If there
weren't a mechanism like this, then all sub-classers would be
sharing a single helper, and that would be bad.
- Returns:
- a helper use by all enumeration instances of a single class
set
public void set(int choice)
- Sets the enumeration to the given integer value. Checks validity
of the choice.
- Parameters:
- choice - enumerated value
- Throws: Error
- when an invalid choice is given
set
public void set(String choice)
- Sets the enumeration to the given string value. Checks validity
of the choice.
- Parameters:
- choice - string version of the enumerated value
- Throws: Error
- when an invalid choice is given
intValue
public int intValue()
- Returns the int value of the current selection from the enumeration.
toString
public String toString()
- Returns the String description of the current selection from the
enumeration.
- Overrides:
- toString in class Object
elements
public Enumeration elements()
- Returns a java.util.Enumeration of the String descriptions
available in this enum.
descriptions
public String[] descriptions()
- Returns an array containing all of the String descriptions
available in this enum.
clone
public Object clone()
- Returns a copy of this enumeration instance.
- Overrides:
- clone in class Object
equals
public boolean equals(Object obj)
- Returns true if this enumeration instance and the one given have
the same selection made.
- Overrides:
- equals in class Object
All Packages Class Hierarchy This Package Previous Next Index