KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.suberic.pooka.gui.filter;
2 import net.suberic.pooka.gui.search.*;
3 import net.suberic.pooka.*;
4 import net.suberic.util.gui.propedit.*;
5 import net.suberic.util.VariableBundle;
6 import javax.swing.*;
7 import java.util.Vector JavaDoc;
8
9 /**
10  * This is a class that lets you choose your filter actions.
11  */

12 public class FilterEditorPane extends LabelValuePropertyEditor implements java.awt.event.ItemListener JavaDoc {
13
14   JLabel label;
15   JComboBox typeCombo;
16   JPanel filterConfigPanel;
17   java.awt.CardLayout JavaDoc layout;
18
19   java.util.HashMap JavaDoc editorTable;
20
21   /**
22    * Configures the FilterEditorPane.
23    */

24   public void configureEditor(String JavaDoc propertyName, String JavaDoc template, String JavaDoc propertyBaseName, PropertyEditorManager newManager) {
25     configureBasic(propertyName, template, propertyBaseName, newManager);
26
27     getLogger().fine("property is " + property + "; editorTemplate is " + editorTemplate);
28
29     editorTable = new java.util.HashMap JavaDoc();
30
31     // create the label
32
label = new JLabel(manager.getProperty(editorTemplate + ".label", "Action"));
33
34     // find out if we're a display filter or a backend filter
35
String JavaDoc filterType = manager.getProperty(editorTemplate + ".filterType", "display");
36
37     // create the combo
38
Vector JavaDoc filterLabels = null;
39     if (filterType.equalsIgnoreCase("display"))
40       filterLabels = Pooka.getSearchManager().getDisplayFilterLabels();
41     else
42       filterLabels = Pooka.getSearchManager().getBackendFilterLabels();
43
44     typeCombo = new JComboBox(filterLabels);
45     typeCombo.addItemListener(this);
46
47
48     // create the filterConfigPanel.
49

50     String JavaDoc currentClassValue = manager.getProperty(property + ".class", "");
51     String JavaDoc selectedLabel = null;
52
53     filterConfigPanel = new JPanel();
54     layout = new java.awt.CardLayout JavaDoc();
55     filterConfigPanel.setLayout(layout);
56     for (int i = 0; i < filterLabels.size(); i++) {
57       String JavaDoc label = (String JavaDoc) filterLabels.elementAt(i);
58       FilterEditor currentEditor = Pooka.getSearchManager().getEditorForFilterLabel(label);
59       currentEditor.configureEditor(manager, property);
60
61       filterConfigPanel.add(label, currentEditor);
62       editorTable.put(label, currentEditor);
63
64       if (selectedLabel == null && currentClassValue != null && currentClassValue.equalsIgnoreCase(currentEditor.getFilterClassValue()))
65         selectedLabel = label;
66     }
67
68     if (selectedLabel != null)
69       typeCombo.setSelectedItem(selectedLabel);
70
71     JPanel tmpPanel = new JPanel();
72     SpringLayout layout = new SpringLayout();
73     tmpPanel.setLayout(layout);
74
75     tmpPanel.add(typeCombo);
76     tmpPanel.add(filterConfigPanel);
77
78     layout.putConstraint(SpringLayout.NORTH, typeCombo, 0, SpringLayout.NORTH, tmpPanel);
79     layout.putConstraint(SpringLayout.WEST, typeCombo, 0, SpringLayout.WEST, tmpPanel);
80     layout.putConstraint(SpringLayout.SOUTH, tmpPanel, 0, SpringLayout.SOUTH, typeCombo);
81     layout.putConstraint(SpringLayout.WEST, filterConfigPanel, 5, SpringLayout.EAST, typeCombo);
82     layout.putConstraint(SpringLayout.EAST, tmpPanel, 5, SpringLayout.EAST, filterConfigPanel);
83
84     tmpPanel.setPreferredSize(new java.awt.Dimension JavaDoc(tmpPanel.getPreferredSize().width, typeCombo.getMinimumSize().height));
85     tmpPanel.setMaximumSize(new java.awt.Dimension JavaDoc(Integer.MAX_VALUE, typeCombo.getMinimumSize().height));
86
87     this.add(label);
88     this.add(tmpPanel);
89
90     labelComponent = label;
91     valueComponent = tmpPanel;
92
93     resetDefaultValue();
94   }
95
96   /**
97    * Sets the value for this PropertyEditor.
98    */

99   public void setValue() throws PropertyValueVetoException {
100     validateProperty();
101     getFilterEditor().setValue();
102   }
103
104   /**
105    * Validates this PropertyEditor.
106    */

107   public void validateProperty() throws PropertyValueVetoException {
108     getFilterEditor().validate();
109   }
110
111   /**
112    * Returns the currently selected FilterEditor.
113    */

114   public FilterEditor getFilterEditor() {
115     return (FilterEditor) editorTable.get(typeCombo.getSelectedItem());
116   }
117
118   /**
119    * Gets the value that would be set by this PropertyEditor.
120    */

121   public java.util.Properties JavaDoc getValue() {
122     return getFilterEditor().getValue();
123   }
124
125   /**
126    * Resets the current Editor to its original value.
127    */

128   public void resetDefaultValue() {
129     // get the current value, if any
130
String JavaDoc currentLabel = Pooka.getSearchManager().getLabelForFilterClass(manager.getProperty(property + ".class", ""));
131     if (currentLabel != null) {
132       typeCombo.setSelectedItem(currentLabel);
133     } else {
134       typeCombo.setSelectedIndex(0);
135     }
136
137     FilterEditor currentEditor = getFilterEditor();
138
139   }
140
141   /**
142    * This handles the switch of the filterConfigPanel when the typeCombo
143    * value changes.
144    */

145   public void itemStateChanged(java.awt.event.ItemEvent JavaDoc e) {
146     String JavaDoc selectedString = (String JavaDoc) typeCombo.getSelectedItem();
147
148     layout.show(filterConfigPanel, selectedString);
149   }
150
151   /**
152    * Run when the PropertyEditor may have changed enabled states.
153    */

154   protected void updateEditorEnabled() {
155     typeCombo.setEnabled(isEditorEnabled());
156   }
157
158 }
159
Popular Tags