KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > filter > plugins > DateCriteriaRow


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.config.filter.plugins;
17
18 import java.awt.event.ActionEvent JavaDoc;
19 import java.awt.event.ActionListener JavaDoc;
20 import java.text.DateFormat JavaDoc;
21 import java.text.ParseException JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import javax.swing.JButton JavaDoc;
25 import javax.swing.JComboBox JavaDoc;
26 import javax.swing.JDialog JavaDoc;
27
28 import org.columba.api.plugin.IExtensionHandler;
29 import org.columba.core.filter.FilterCriteria;
30 import org.columba.core.gui.dialog.DateChooserDialog;
31 import org.columba.mail.gui.config.filter.CriteriaList;
32 import org.frapuccino.swing.ActiveWindowTracker;
33
34 public class DateCriteriaRow extends DefaultCriteriaRow implements
35         ActionListener JavaDoc {
36     private JComboBox JavaDoc matchComboBox;
37
38     private JButton JavaDoc dateButton;
39
40     private Date JavaDoc date;
41
42     public static DateFormat JavaDoc dateFormat = DateFormat.getDateInstance();
43
44     public DateCriteriaRow(IExtensionHandler pluginHandler,
45             CriteriaList criteriaList, FilterCriteria c) {
46         super(pluginHandler, criteriaList, c);
47     }
48
49     public void updateComponents(boolean b) {
50         super.updateComponents(b);
51
52         if (b) {
53             matchComboBox.setSelectedItem(criteria.getCriteriaString());
54             try {
55                 date = dateFormat.parse(criteria.getPatternString());
56             } catch (ParseException JavaDoc e) {
57                 // Fall back to today
58
date = new Date JavaDoc();
59             }
60
61             // textField.setText(criteria.getPattern());
62
dateButton.setText(dateFormat.format(date));
63         } else {
64             criteria
65                     .setCriteriaString((String JavaDoc) matchComboBox.getSelectedItem());
66
67             // criteria.setPattern((String) textField.getText());
68
criteria.setPatternString((String JavaDoc) dateButton.getText());
69         }
70     }
71
72     public void initComponents() {
73         super.initComponents();
74
75         matchComboBox = new JComboBox JavaDoc();
76         matchComboBox.addItem("before");
77         matchComboBox.addItem("after");
78
79         addComponent(matchComboBox);
80
81         dateButton = new JButton JavaDoc("date");
82         dateButton.setActionCommand("DATE");
83         dateButton.addActionListener(this);
84
85         addComponent(dateButton);
86     }
87
88     public void actionPerformed(ActionEvent JavaDoc ev) {
89         String JavaDoc action = ev.getActionCommand();
90
91         if (action.equals("DATE")) {
92
93             DateChooserDialog dialog = new DateChooserDialog((JDialog JavaDoc) ActiveWindowTracker.findActiveWindow());
94
95             dialog.setDate(date);
96             dialog.setVisible(true);
97
98             if (dialog.success() == true) {
99                 // Ok
100
date = dialog.getDate();
101                 dateButton.setText(dateFormat.format(date));
102             } else {
103                 // cancel
104
}
105         }
106     }
107 }
108
Popular Tags