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

Variable Index

 o currentChoice
The currently selected value from the enum.

Constructor Index

 o BaseEnum()
Constructor, sets the choice to the default.
 o BaseEnum(int)
Constructor to use when integer value is available.
 o BaseEnum(String)
Constructor to use when string of choice is available.

Method Index

 o clone()
Returns a copy of this enumeration instance.
 o descriptions()
Returns an array containing all of the String descriptions available in this enum.
 o elements()
Returns a java.util.Enumeration of the String descriptions available in this enum.
 o equals(Object)
Returns true if this enumeration instance and the one given have the same selection made.
 o getHelper()
Gets the helper class that stores the enum definition.
 o intValue()
Returns the int value of the current selection from the enumeration.
 o set(int)
Sets the enumeration to the given integer value.
 o set(String)
Sets the enumeration to the given string value.
 o toString()
Returns the String description of the current selection from the enumeration.

Variables

 o currentChoice
  protected Integer currentChoice
The currently selected value from the enum.

Constructors

 o BaseEnum
  protected BaseEnum()
Constructor, sets the choice to the default.
 o BaseEnum
  protected BaseEnum(int choice)
Constructor to use when integer value is available.
Parameters:
choice - enumerated value
 o BaseEnum
  protected BaseEnum(String choice)
Constructor to use when string of choice is available.
Parameters:
choice - enumerated value

Methods

 o 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
 o 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
 o 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
 o intValue
  public int intValue()
Returns the int value of the current selection from the enumeration.
 o toString
  public String toString()
Returns the String description of the current selection from the enumeration.
Overrides:
toString in class Object
 o elements
  public Enumeration elements()
Returns a java.util.Enumeration of the String descriptions available in this enum.
 o descriptions
  public String[] descriptions()
Returns an array containing all of the String descriptions available in this enum.
 o clone
  public Object clone()
Returns a copy of this enumeration instance.
Overrides:
clone in class Object
 o 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