import java.beans.*; import java.util.*; public class SmileyEditor extends PropertyEditorSupport implements SmileyEmotions { protected Vector nameValues; //------------------------------------------------------------------- // SmileyEditor Constructor //------------------------------------------------------------------- public SmileyEditor() { // 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]); } } //------------------------------------------------------------------- // getAsText() translates the internal value representation to a String //------------------------------------------------------------------- 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"; } } //------------------------------------------------------------------- // setAsText() translates a String into the internal value representation. //------------------------------------------------------------------- public void setAsText(String text) throws IllegalArgumentException { int propertyValue; propertyValue = nameValues.indexOf(text); if ( propertyValue == -1 ) { throw new IllegalArgumentException("value is not a valid smiley emotion"); } setValue( new Integer(propertyValue) ); // setValue() needs objects.. } } // End of Class SmileyEditor