001: package net.suberic.pooka.gui.filter;
002:
003: import javax.swing.*;
004: import java.awt.*;
005:
006: /**
007: * This class allows you to choose colors for a FontFilter.
008: */
009: public class FontFilterEditor extends FilterEditor {
010: JComboBox fontCombo;
011: String origFontString;
012:
013: public static String FILTER_CLASS = "net.suberic.pooka.gui.filter.FontDisplayFilter";
014:
015: /**
016: * Configures the given FilterEditor from the given VariableBundle and
017: * property.
018: */
019: public void configureEditor(
020: net.suberic.util.gui.propedit.PropertyEditorManager newManager,
021: String propertyName) {
022: property = propertyName;
023: manager = newManager;
024:
025: origFontString = manager.getProperty(propertyName + ".style",
026: "");
027:
028: fontCombo = createFontCombo();
029:
030: if (origFontString.equals(""))
031: fontCombo.setSelectedIndex(0);
032: else
033: fontCombo.setSelectedItem(getFontLabel(origFontString));
034:
035: this .add(fontCombo);
036:
037: }
038:
039: /**
040: * creates the font combo.
041: */
042: public JComboBox createFontCombo() {
043: java.util.Vector labels = new java.util.Vector();
044: labels.add(manager.getProperty("Font.PLAIN.label", "PLAIN"));
045: labels.add(manager.getProperty("Font.BOLD.label", "BOLD"));
046: labels.add(manager.getProperty("Font.ITALIC.label", "ITALIC"));
047:
048: return new JComboBox(labels);
049: }
050:
051: /**
052: * Returns the font label for this font.
053: */
054: public String getFontLabel(String fontType) {
055: return manager.getProperty("Font." + fontType + ".label", "");
056: }
057:
058: /**
059: * Returns the selected font type.
060: */
061: public String getSelectedFontType() {
062: String selectedString = (String) fontCombo.getSelectedItem();
063: if (selectedString.equalsIgnoreCase(manager.getProperty(
064: "Font.PLAIN.label", "PLAIN")))
065: return "PLAIN";
066: else if (selectedString.equalsIgnoreCase(manager.getProperty(
067: "Font.BOLD.label", "BOLD")))
068: return "BOLD";
069: else if (selectedString.equalsIgnoreCase(manager.getProperty(
070: "Font.ITALIC.label", "ITALIC")))
071: return "ITALIC";
072: else
073: return "";
074: }
075:
076: /**
077: * Gets the values that would be set by this FilterEditor.
078: */
079: public java.util.Properties getValue() {
080: java.util.Properties props = new java.util.Properties();
081: props.setProperty(property + ".style", getSelectedFontType());
082: props.setProperty(property + ".class", FILTER_CLASS);
083: return props;
084: }
085:
086: /**
087: * Sets the values represented by this FilterEditor in the manager.
088: */
089: public void setValue() {
090: String newValue = getSelectedFontType();
091: if (newValue != origFontString)
092: manager.setProperty(property + ".style", newValue);
093:
094: String oldClassName = manager.getProperty(property + ".class",
095: "");
096: if (!oldClassName.equals(FILTER_CLASS))
097: manager.setProperty(property + ".class", FILTER_CLASS);
098: }
099:
100: /**
101: * Returns the class that will be set for this FilterEditor.
102: */
103: public String getFilterClassValue() {
104: return FILTER_CLASS;
105: }
106:
107: }
|