KickJava   Java API By Example, From Geeks To Geeks.

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


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.mail.gui.config.filter.plugins;
19
20 import java.awt.GridBagConstraints JavaDoc;
21 import java.awt.GridBagLayout JavaDoc;
22 import java.awt.Insets JavaDoc;
23
24 import javax.swing.JButton JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27
28 import org.columba.api.plugin.IExtensionHandler;
29 import org.columba.api.plugin.IExtensionInterface;
30 import org.columba.core.filter.FilterCriteria;
31 import org.columba.core.gui.base.ComboMenu;
32 import org.columba.mail.gui.config.filter.CriteriaList;
33
34 public class DefaultCriteriaRow implements IExtensionInterface {
35
36     protected FilterCriteria criteria;
37
38     protected CriteriaList criteriaList;
39
40     protected JPanel JavaDoc panel;
41
42     protected JButton JavaDoc removeButton;
43
44     protected GridBagLayout JavaDoc gridbag = new GridBagLayout JavaDoc();
45
46     protected GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
47
48     IExtensionHandler pluginHandler;
49
50     protected int count;
51
52     private ComboMenu comboMenu;
53
54     public DefaultCriteriaRow(IExtensionHandler pluginHandler,
55             CriteriaList criteriaList, FilterCriteria c) {
56         this.pluginHandler = pluginHandler;
57
58         this.criteria = c;
59         this.criteriaList = criteriaList;
60
61         panel = new JPanel JavaDoc();
62
63         initComponents();
64
65         updateComponents(true);
66
67     }
68
69     public void updateComponents(boolean b) {
70         if (b) {
71             String JavaDoc conditionString = criteria.getTypeString();
72
73             comboMenu.setText(conditionString);
74
75         } else {
76
77             String JavaDoc conditionString = comboMenu.getText();
78             criteria.setTypeString(conditionString);
79
80         }
81     }
82
83     public void initComponents() {
84         panel.setLayout(gridbag);
85
86         comboMenu = new ComboMenu();
87         String JavaDoc[] ids = pluginHandler.getPluginIdList();
88         for (String JavaDoc element : ids) {
89             // TODO localize filter action names
90
comboMenu.addMenuItem(element, element);
91         }
92         comboMenu.setText(criteria.getTypeString());
93         comboMenu.addItemListener(criteriaList);
94
95         c.fill = GridBagConstraints.VERTICAL;
96         c.weightx = 1.0;
97         c.insets = new Insets JavaDoc(2, 2, 2, 2);
98         c.gridx = 0;
99         c.anchor = GridBagConstraints.WEST;
100         c.gridwidth = 1;
101
102         gridbag.setConstraints(comboMenu, c);
103
104         panel.add(comboMenu);
105
106         count = 0;
107     }
108
109     public JPanel JavaDoc getContentPane() {
110         return panel;
111     }
112
113     public void addComponent(JComponent JavaDoc component) {
114         c.gridx = ++count;
115         gridbag.setConstraints(component, c);
116         panel.add(component);
117     }
118
119     /**
120      * Returns the criteria.
121      *
122      * @return FilterCriteria
123      */

124     public FilterCriteria getCriteria() {
125         return criteria;
126     }
127
128     /**
129      * Returns the pluginHandler.
130      *
131      * @return AbstractPluginHandler
132      */

133     public IExtensionHandler getPluginHandler() {
134         return pluginHandler;
135     }
136
137     /**
138      * Sets the pluginHandler.
139      *
140      * @param pluginHandler
141      * The pluginHandler to set
142      */

143     public void setPluginHandler(IExtensionHandler pluginHandler) {
144         this.pluginHandler = pluginHandler;
145     }
146
147 }
Popular Tags