001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.mail.gui.config.account;
017:
018: import java.awt.event.ActionEvent;
019: import java.awt.event.ActionListener;
020:
021: import javax.swing.JCheckBox;
022: import javax.swing.JLabel;
023: import javax.swing.JPanel;
024: import javax.swing.JSpinner;
025: import javax.swing.JTextField;
026: import javax.swing.SpinnerNumberModel;
027:
028: import org.columba.core.gui.base.CheckBoxWithMnemonic;
029: import org.columba.mail.config.PopItem;
030: import org.columba.mail.util.MailResourceLoader;
031:
032: import com.jgoodies.forms.builder.DefaultFormBuilder;
033: import com.jgoodies.forms.layout.FormLayout;
034:
035: /**
036: *
037: * @author freddy
038: * @version
039: */
040: public class PopAttributPanel implements ActionListener {
041: private PopItem item;
042:
043: private JCheckBox leaveOnServerCheckBox;
044:
045: private JCheckBox excludeCheckBox;
046:
047: private JCheckBox removeOldMessagesCheckBox;
048:
049: private JSpinner olderThanSpinner;
050:
051: private JLabel daysLabel;
052:
053: private JCheckBox limitMessageDownloadCheckBox;
054:
055: private JTextField limitMessageDownloadTextField;
056:
057: public PopAttributPanel(PopItem item) {
058: super ();
059: this .item = item;
060:
061: initComponents();
062: }
063:
064: public void updateComponents(boolean b) {
065:
066: if (b) {
067: leaveOnServerCheckBox.setSelected(item
068: .getBoolean(PopItem.LEAVE_MESSAGES_ON_SERVER));
069: removeOldMessagesCheckBox.setSelected(item
070: .getBooleanWithDefault(
071: PopItem.REMOVE_OLD_FROM_SERVER, false));
072:
073: updateRemoveOldMessagesEnabled();
074:
075: olderThanSpinner.getModel().setValue(
076: new Integer(item.getIntegerWithDefault(
077: PopItem.OLDER_THAN, 30)));
078:
079: excludeCheckBox.setSelected(item.getBooleanWithDefault(
080: PopItem.EXCLUDE_FROM_CHECKALL, false));
081:
082: limitMessageDownloadCheckBox.setSelected(item
083: .getBoolean(PopItem.ENABLE_DOWNLOAD_LIMIT));
084:
085: limitMessageDownloadTextField.setText(item
086: .get(PopItem.DOWNLOAD_LIMIT));
087:
088: } else {
089: item.setBoolean(PopItem.REMOVE_OLD_FROM_SERVER,
090: removeOldMessagesCheckBox.isSelected());
091:
092: item.setInteger(PopItem.OLDER_THAN,
093: ((SpinnerNumberModel) olderThanSpinner.getModel())
094: .getNumber().intValue());
095:
096: item.setBoolean(PopItem.LEAVE_MESSAGES_ON_SERVER,
097: leaveOnServerCheckBox.isSelected()); //$NON-NLS-1$
098:
099: item.setBoolean(PopItem.EXCLUDE_FROM_CHECKALL,
100: excludeCheckBox.isSelected()); //$NON-NLS-1$
101:
102: item.setString(PopItem.DOWNLOAD_LIMIT,
103: limitMessageDownloadTextField.getText());
104:
105: item.setBoolean(PopItem.ENABLE_DOWNLOAD_LIMIT,
106: limitMessageDownloadCheckBox.isSelected());
107:
108: }
109: }
110:
111: /**
112: *
113: */
114: private void updateRemoveOldMessagesEnabled() {
115: removeOldMessagesCheckBox.setEnabled(leaveOnServerCheckBox
116: .isSelected());
117: olderThanSpinner.setEnabled(leaveOnServerCheckBox.isSelected());
118: daysLabel.setEnabled(leaveOnServerCheckBox.isSelected());
119: }
120:
121: public void createPanel(DefaultFormBuilder builder) {
122: JPanel panel;
123: FormLayout l;
124: DefaultFormBuilder b;
125:
126: builder.appendSeparator(MailResourceLoader.getString("dialog",
127: "account", "options"));
128:
129: builder.append(leaveOnServerCheckBox, 4);
130: builder.nextLine();
131:
132: builder.setLeadingColumnOffset(2);
133:
134: panel = new JPanel();
135: l = new FormLayout(
136: "default, 3dlu, min(50;default), 3dlu, default",
137: // 2 columns
138: ""); // rows are added dynamically (no need to define them
139: // here)
140:
141: // create a form builder
142: b = new DefaultFormBuilder(l, panel);
143: b.append(removeOldMessagesCheckBox);
144: b.append(olderThanSpinner);
145: b.append(daysLabel);
146: builder.append(panel, 3);
147: builder.nextLine();
148:
149: builder.setLeadingColumnOffset(1);
150: builder.append(excludeCheckBox, 4);
151: builder.nextLine();
152:
153: panel = new JPanel();
154: l = new FormLayout(
155: "max(100;default), 3dlu, left:max(50dlu;default)",
156:
157: // 2 columns
158: ""); // rows are added dynamically (no need to define them
159: // here)
160:
161: // create a form builder
162: b = new DefaultFormBuilder(l, panel);
163: b.append(limitMessageDownloadCheckBox,
164: limitMessageDownloadTextField);
165:
166: builder.append(panel, 4);
167:
168: }
169:
170: protected void initComponents() {
171: leaveOnServerCheckBox = new CheckBoxWithMnemonic(
172: MailResourceLoader.getString("dialog", "account",
173: PopItem.LEAVE_MESSAGES_ON_SERVER));
174: leaveOnServerCheckBox.setActionCommand("LEAVE_ON_SERVER");
175: leaveOnServerCheckBox.addActionListener(this );
176:
177: limitMessageDownloadCheckBox = new CheckBoxWithMnemonic(
178: MailResourceLoader.getString("dialog", "account",
179: "limit_message_download_to"));
180:
181: limitMessageDownloadCheckBox
182: .setActionCommand("LIMIT_MESSAGE_DOWNLOAD");
183: limitMessageDownloadCheckBox.addActionListener(this );
184:
185: limitMessageDownloadTextField = new JTextField();
186:
187: excludeCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
188: .getString("dialog", "account",
189: "exclude_from_fetch_all"));
190:
191: removeOldMessagesCheckBox = new CheckBoxWithMnemonic(
192: MailResourceLoader.getString("dialog", "account",
193: PopItem.REMOVE_OLD_FROM_SERVER));
194:
195: olderThanSpinner = new JSpinner(new SpinnerNumberModel(1, 1,
196: Integer.MAX_VALUE, 1));
197:
198: daysLabel = new JLabel(MailResourceLoader.getString("dialog",
199: "account", "days"));
200:
201: }
202:
203: public void actionPerformed(ActionEvent e) {
204: String action = e.getActionCommand();
205:
206: if (action.equals("LIMIT_MESSAGE_DOWNLOAD")) {
207: limitMessageDownloadTextField
208: .setEnabled(limitMessageDownloadCheckBox
209: .isSelected());
210: } else if (action.equals("LEAVE_ON_SERVER")) {
211: updateRemoveOldMessagesEnabled();
212: }
213: }
214: }
|