import java.beans.*; import java.io.*; import java.awt.*; public class FontStyleEditor extends PropertyEditorSupport { protected int fontStyle = Font.PLAIN; public Object getValue() { return new Integer(fontStyle); } public void setValue(Object o) { Integer f = (Integer) o; fontStyle = f.intValue(); } public String[] getTags() { String[] s = {"Plain", "Bold", "Italic", "Bold-Italic"}; return s; } public String getAsText() { switch (fontStyle) { case(Font.PLAIN) : return "Plain"; case(Font.BOLD) : return "Bold"; case(Font.ITALIC) : return "Italic"; case(Font.BOLD | Font.ITALIC) : return "Bold-Italic"; default: return "Plain"; } } public void setAsText(String text) throws IllegalArgumentException { if (text.equalsIgnoreCase("plain")) { fontStyle = Font.PLAIN; } else if (text.equalsIgnoreCase("bold")) { fontStyle = Font.BOLD; } else if (text.equalsIgnoreCase("italic")) { fontStyle = Font.ITALIC; } else if (text.equalsIgnoreCase("bold-italic")) { fontStyle = Font.BOLD | Font.ITALIC; } else { throw new IllegalArgumentException(text + " is not a valid style."); } } }