001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.gui.table;
019:
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022:
023: import javax.swing.BorderFactory;
024: import javax.swing.JButton;
025: import javax.swing.JLabel;
026: import javax.swing.JPanel;
027: import javax.swing.JTextField;
028: import javax.swing.event.DocumentEvent;
029: import javax.swing.event.DocumentListener;
030:
031: import org.columba.addressbook.gui.table.model.FilterDecorator;
032:
033: import com.jgoodies.forms.builder.PanelBuilder;
034: import com.jgoodies.forms.layout.CellConstraints;
035: import com.jgoodies.forms.layout.FormLayout;
036:
037: public class FilterToolbar extends JPanel implements ActionListener {
038: public JButton searchButton;
039:
040: private TableController table;
041:
042: private JLabel label;
043:
044: private JTextField textField;
045:
046: private JButton clearButton;
047:
048: public FilterToolbar(TableController table) {
049: super ();
050:
051: this .table = table;
052:
053: initComponents();
054: layoutComponents();
055:
056: textField.getDocument().addDocumentListener(
057: new MyDocumentListener());
058: }
059:
060: protected void initComponents() {
061: label = new JLabel("Name or email contains:");
062:
063: textField = new JTextField(12);
064:
065: clearButton = new JButton("Clear");
066: clearButton.setActionCommand("CLEAR");
067: clearButton.addActionListener(this );
068: }
069:
070: protected void layoutComponents() {
071: setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
072:
073: FormLayout l = new FormLayout(
074: "3dlu, default, 3dlu, fill:default:grow, 3dlu, default, 3dlu",
075: "fill:default:grow");
076: PanelBuilder b = new PanelBuilder(l, this );
077:
078: CellConstraints c = new CellConstraints();
079:
080: b.add(label, c.xy(2, 1));
081: b.add(textField, c.xy(4, 1));
082: b.add(clearButton, c.xy(6, 1));
083:
084: }
085:
086: public void update() {
087: table.getAddressbookModel().update();
088: }
089:
090: public void actionPerformed(ActionEvent e) {
091: String action = e.getActionCommand();
092:
093: if (action.equals("CLEAR")) {
094: textField.setText("");
095: }
096: }
097:
098: class MyDocumentListener implements DocumentListener {
099:
100: public void insertUpdate(DocumentEvent e) {
101: update();
102: }
103:
104: public void removeUpdate(DocumentEvent e) {
105: update();
106: }
107:
108: public void changedUpdate(DocumentEvent 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: }
|