import java.beans.*; import java.util.*; public class SmileyEditor2 extends PropertyEditorSupport implements SmileyEmotions { protected Vector nameValues; //------------------------------------------------------------------- // SmileyEditor Constructor //------------------------------------------------------------------- public SmileyEditor2() { // initialize our Vector for easy smiley name-to-int lookups nameValues = new Vector(); for (int i=0; i < smileyNames.length; i++) { nameValues.addElement(smileyNames[i]); } } //------------------------------------------------------------------- // This example editor only supports value editing using strings to // represent values. //------------------------------------------------------------------- public String getAsText() { Integer smileNo; int smile; smileNo = (Integer)getValue(); smile = smileNo.intValue(); if ( smile >= 0 && smile < smileyNames.length ) { return smileyNames[ smileNo.intValue() ]; } else { return "Illegal value"; } } //------------------------------------------------------------------- // //------------------------------------------------------------------- public void setAsText(String text) throws IllegalArgumentException { int propertyValue; Integer propVal; propertyValue = nameValues.indexOf(text); if ( propertyValue == -1 ) { throw new IllegalArgumentException( "value is not a valid smiley emotion"); } propVal = new Integer(propertyValue); setValue(propVal); } public String[] getTags() { String[] tags; tags = smileyNames; return tags; } } // End of Class SmileyEditor2