KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > gui > table > FilterToolbar


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.gui.table;
19
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22
23 import javax.swing.BorderFactory JavaDoc;
24 import javax.swing.JButton JavaDoc;
25 import javax.swing.JLabel JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.JTextField JavaDoc;
28 import javax.swing.event.DocumentEvent JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30
31 import org.columba.addressbook.gui.table.model.FilterDecorator;
32
33 import com.jgoodies.forms.builder.PanelBuilder;
34 import com.jgoodies.forms.layout.CellConstraints;
35 import com.jgoodies.forms.layout.FormLayout;
36
37
38 public class FilterToolbar extends JPanel JavaDoc implements ActionListener JavaDoc {
39     public JButton JavaDoc searchButton;
40
41     private TableController table;
42
43     private JLabel JavaDoc label;
44
45     private JTextField JavaDoc textField;
46
47     private JButton JavaDoc clearButton;
48
49     public FilterToolbar(TableController table) {
50         super();
51
52         this.table = table;
53
54         initComponents();
55         layoutComponents();
56
57         textField.getDocument().addDocumentListener(new MyDocumentListener());
58     }
59
60     protected void initComponents() {
61         label = new JLabel JavaDoc("Name or email contains:");
62
63         textField = new JTextField JavaDoc(12);
64
65         clearButton = new JButton JavaDoc("Clear");
66         clearButton.setActionCommand("CLEAR");
67         clearButton.addActionListener(this);
68     }
69
70     protected void layoutComponents() {
71         setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
72
73         FormLayout l = new FormLayout(
74                 "3dlu, default, 3dlu, fill:default:grow, 3dlu, default, 3dlu",
75                 "fill:default:grow");
76         PanelBuilder b = new PanelBuilder(l, this);
77
78         CellConstraints c = new CellConstraints();
79
80         b.add(label, c.xy(2, 1));
81         b.add(textField, c.xy(4, 1));
82         b.add(clearButton, c.xy(6, 1));
83
84     }
85
86     public void update() {
87         table.getAddressbookModel().update();
88     }
89
90     public void actionPerformed(ActionEvent JavaDoc e) {
91         String JavaDoc action = e.getActionCommand();
92
93         if (action.equals("CLEAR")) {
94             textField.setText("");
95         }
96     }
97
98     class MyDocumentListener implements DocumentListener JavaDoc {
99
100         public void insertUpdate(DocumentEvent JavaDoc e) {
101             update();
102         }
103
104         public void removeUpdate(DocumentEvent JavaDoc e) {
105             update();
106         }
107
108         public void changedUpdate(DocumentEvent JavaDoc e) {
109             // Plain text components don't fire these events
110
}
111
112         public void update() {
113             FilterDecorator model = table.getFilterDecorator();
114             model.setPattern(textField.getText());
115             table.getAddressbookModel().fireTableDataChanged();
116         }
117     }
118 }
Popular Tags