01: import java.beans.*;
02: 
03: /**
04:    A property editor for enumerated types.
05: */
06: public class EnumEditor extends PropertyEditorSupport
07: {
08:    /**
09:       Constructs a property editor for an enumerated type
10:       @param cl the class object for the enumerated type
11:    */
12:    public EnumEditor(Class cl)
13:    {
14:       this.cl = cl;
15:    }
16: 
17:    public String[] getTags()
18:    {
19:       try
20:       {
21:          Object[] values = (Object[]) cl.getMethod("values").invoke(null);
22:          String[] result = new String[values.length];
23:          for (int i = 0; i < values.length; i++)
24:             result[i] = values[i].toString();
25:          return result;
26:       }
27:       catch (Exception ex)
28:       {
29:          return null;
30:       }
31:    }
32: 
33:    public String getAsText()
34:    {
35:       return getValue().toString();
36:    }
37: 
38:    public void setAsText(String s)
39:    {
40:       setValue(Enum.valueOf(cl, s));
41:    }
42: 
43:    private Class cl;
44: }