KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > filter > FontFilterEditor


1 package net.suberic.pooka.gui.filter;
2 import javax.swing.*;
3 import java.awt.*;
4
5 /**
6  * This class allows you to choose colors for a FontFilter.
7  */

8 public class FontFilterEditor extends FilterEditor {
9   JComboBox fontCombo;
10   String JavaDoc origFontString;
11   
12   public static String JavaDoc FILTER_CLASS = "net.suberic.pooka.gui.filter.FontDisplayFilter";
13   
14   /**
15    * Configures the given FilterEditor from the given VariableBundle and
16    * property.
17    */

18   public void configureEditor(net.suberic.util.gui.propedit.PropertyEditorManager newManager, String JavaDoc propertyName) {
19     property = propertyName;
20     manager = newManager;
21     
22     origFontString = manager.getProperty(propertyName + ".style", "");
23     
24     fontCombo = createFontCombo();
25     
26     if (origFontString.equals(""))
27       fontCombo.setSelectedIndex(0);
28     else
29       fontCombo.setSelectedItem(getFontLabel(origFontString));
30     
31     this.add(fontCombo);
32     
33   }
34   
35   /**
36    * creates the font combo.
37    */

38   public JComboBox createFontCombo() {
39     java.util.Vector JavaDoc labels = new java.util.Vector JavaDoc();
40     labels.add(manager.getProperty("Font.PLAIN.label", "PLAIN"));
41     labels.add(manager.getProperty("Font.BOLD.label", "BOLD"));
42     labels.add(manager.getProperty("Font.ITALIC.label", "ITALIC"));
43     
44     return new JComboBox(labels);
45   }
46   
47   /**
48    * Returns the font label for this font.
49    */

50   public String JavaDoc getFontLabel(String JavaDoc fontType) {
51     return manager.getProperty("Font." + fontType + ".label", "");
52   }
53   
54   /**
55    * Returns the selected font type.
56    */

57   public String JavaDoc getSelectedFontType() {
58     String JavaDoc selectedString = (String JavaDoc) fontCombo.getSelectedItem();
59     if (selectedString.equalsIgnoreCase(manager.getProperty("Font.PLAIN.label", "PLAIN")))
60       return "PLAIN";
61     else if (selectedString.equalsIgnoreCase(manager.getProperty("Font.BOLD.label", "BOLD")))
62       return "BOLD";
63     else if (selectedString.equalsIgnoreCase(manager.getProperty("Font.ITALIC.label", "ITALIC")))
64       return "ITALIC";
65     else
66       return "";
67   }
68   
69   /**
70    * Gets the values that would be set by this FilterEditor.
71    */

72   public java.util.Properties JavaDoc getValue() {
73     java.util.Properties JavaDoc props = new java.util.Properties JavaDoc();
74     props.setProperty(property + ".style", getSelectedFontType());
75     props.setProperty(property + ".class", FILTER_CLASS);
76     return props;
77   }
78   
79   /**
80    * Sets the values represented by this FilterEditor in the manager.
81    */

82   public void setValue() {
83     String JavaDoc newValue = getSelectedFontType();
84     if (newValue != origFontString)
85       manager.setProperty(property + ".style", newValue);
86     
87     String JavaDoc oldClassName = manager.getProperty(property + ".class", "");
88     if (!oldClassName.equals(FILTER_CLASS))
89       manager.setProperty(property + ".class", FILTER_CLASS);
90   }
91   
92   /**
93    * Returns the class that will be set for this FilterEditor.
94    */

95   public String JavaDoc getFilterClassValue() {
96     return FILTER_CLASS;
97   }
98
99 }
100
101
102
103
104
105
106
107
108
109
Popular Tags