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:
019: package org.columba.mail.gui.config.account;
020:
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import javax.swing.ButtonGroup;
025: import javax.swing.JButton;
026: import javax.swing.JCheckBox;
027: import javax.swing.JRadioButton;
028:
029: import org.columba.api.gui.frame.IFrameMediator;
030: import org.columba.core.gui.base.ButtonWithMnemonic;
031: import org.columba.core.gui.base.CheckBoxWithMnemonic;
032: import org.columba.core.gui.base.MultiLineLabel;
033: import org.columba.core.gui.base.RadioButtonWithMnemonic;
034: import org.columba.mail.config.AccountItem;
035: import org.columba.mail.config.SpamItem;
036: import org.columba.mail.folder.IMailFolder;
037: import org.columba.mail.folder.IMailbox;
038: import org.columba.mail.gui.tree.FolderTreeModel;
039: import org.columba.mail.gui.tree.util.SelectFolderDialog;
040: import org.columba.mail.gui.tree.util.TreeNodeList;
041: import org.columba.mail.util.MailResourceLoader;
042:
043: import com.jgoodies.forms.builder.DefaultFormBuilder;
044: import com.jgoodies.forms.layout.FormLayout;
045:
046: /**
047: * Panel for spam options.
048: *
049: * @author fdietz
050: */
051: public class SpamPanel extends DefaultPanel implements ActionListener {
052:
053: private AccountItem item;
054:
055: private JCheckBox enableCheckBox;
056:
057: private JCheckBox addressCheckBox;
058:
059: private JCheckBox incomingCheckBox;
060:
061: private JCheckBox markCheckBox;
062:
063: private JRadioButton incomingTrashRadioButton;
064:
065: private JRadioButton incomingMoveToRadioButton;
066:
067: private JButton incomingChooseFolderButton;
068:
069: private JRadioButton markTrashRadioButton;
070:
071: private JRadioButton markMoveToRadioButton;
072:
073: private JButton markChooseFolderButton;
074:
075: private MultiLineLabel label;
076:
077: private IFrameMediator mediator;
078:
079: public SpamPanel(IFrameMediator mediator, AccountItem item) {
080: this .item = item;
081: this .mediator = mediator;
082:
083: initComponents();
084: updateComponents(true);
085: layoutComponents();
086: }
087:
088: protected void initComponents() {
089: enableCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
090: .getString("dialog", "account", "enable_filter"));
091: enableCheckBox.setActionCommand("ENABLE");
092: enableCheckBox.addActionListener(this );
093:
094: addressCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
095: .getString("dialog", "account", "dont_mark_message"));
096:
097: incomingCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
098: .getString("dialog", "account",
099: "move_incoming_messages"));
100: incomingCheckBox.setActionCommand("INCOMING");
101: incomingCheckBox.addActionListener(this );
102:
103: incomingChooseFolderButton = new ButtonWithMnemonic("Inbox");
104: incomingChooseFolderButton.setActionCommand("INCOMING_BUTTON");
105: incomingChooseFolderButton.addActionListener(this );
106:
107: incomingTrashRadioButton = new RadioButtonWithMnemonic(
108: MailResourceLoader.getString("dialog", "account",
109: "trash_folder"));
110: incomingMoveToRadioButton = new RadioButtonWithMnemonic(
111: MailResourceLoader.getString("dialog", "account",
112: "move_to"));
113: ButtonGroup group = new ButtonGroup();
114: group.add(incomingTrashRadioButton);
115: group.add(incomingMoveToRadioButton);
116:
117: markCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
118: .getString("dialog", "account", "when_marking_message"));
119: markCheckBox.setActionCommand("MARK");
120: markCheckBox.addActionListener(this );
121:
122: markTrashRadioButton = new RadioButtonWithMnemonic(
123: MailResourceLoader.getString("dialog", "account",
124: "move_to_trash_folder"));
125: markMoveToRadioButton = new RadioButtonWithMnemonic(
126: MailResourceLoader.getString("dialog", "account",
127: "move_to"));
128: ButtonGroup group2 = new ButtonGroup();
129: group2.add(markTrashRadioButton);
130: group2.add(markMoveToRadioButton);
131:
132: markChooseFolderButton = new ButtonWithMnemonic("Inbox");
133: markChooseFolderButton.setActionCommand("MARK_BUTTON");
134: markChooseFolderButton.addActionListener(this );
135:
136: label = new MultiLineLabel(MailResourceLoader.getString(
137: "dialog", "account", "spam_intro"));
138: }
139:
140: protected void layoutComponents() {
141: // Create a FormLayout instance.
142: FormLayout layout = new FormLayout(
143: "10dlu, 10dlu, max(100;default), 3dlu, max(150dlu;default):grow, 3dlu",
144:
145: // 2 columns
146: ""); // rows are added dynamically (no need to define them
147:
148: // here)
149: DefaultFormBuilder builder = new DefaultFormBuilder(layout,
150: this );
151: builder.setLeadingColumnOffset(1);
152:
153: // create EmptyBorder between components and dialog-frame
154: builder.setDefaultDialogBorder();
155:
156: builder.setLeadingColumnOffset(1);
157:
158: builder.appendSeparator(MailResourceLoader.getString("dialog",
159: "account", "separator_adaptive_spam_filter"));
160:
161: builder.append(label, 4);
162: builder.nextLine();
163:
164: builder.append(enableCheckBox, 4);
165: builder.nextLine();
166:
167: builder.appendSeparator(MailResourceLoader.getString("dialog",
168: "account", "separator_filter_options"));
169: builder.nextLine();
170:
171: builder.append(addressCheckBox, 4);
172: builder.nextLine();
173:
174: builder.append(incomingCheckBox, 4);
175: builder.nextLine();
176:
177: builder.setLeadingColumnOffset(2);
178:
179: builder.append(incomingTrashRadioButton, 3);
180: builder.nextLine();
181: builder.append(incomingMoveToRadioButton, 1);
182: builder.append(incomingChooseFolderButton, 2);
183:
184: builder.setLeadingColumnOffset(1);
185:
186: builder.append(markCheckBox, 4);
187: builder.nextLine();
188:
189: builder.setLeadingColumnOffset(2);
190:
191: builder.append(markTrashRadioButton, 3);
192: builder.nextLine();
193:
194: builder.append(markMoveToRadioButton, 1);
195: builder.append(markChooseFolderButton, 2);
196: }
197:
198: public void updateComponents(boolean b) {
199: SpamItem spam = item.getSpamItem();
200:
201: if (b) {
202: enableCheckBox.setSelected(spam.isEnabled());
203:
204: incomingCheckBox.setSelected(spam
205: .isMoveIncomingJunkMessagesEnabled());
206:
207: IMailbox folder = (IMailbox) FolderTreeModel.getInstance()
208: .getFolder(spam.getIncomingCustomFolder());
209: String treePath = folder.getTreePath();
210: incomingChooseFolderButton.setText(treePath);
211:
212: incomingMoveToRadioButton.setSelected(!spam
213: .isIncomingTrashSelected());
214:
215: incomingTrashRadioButton.setSelected(spam
216: .isIncomingTrashSelected());
217:
218: markCheckBox.setSelected(spam
219: .isMoveMessageWhenMarkingEnabled());
220:
221: folder = (IMailbox) FolderTreeModel.getInstance()
222: .getFolder(spam.getMoveCustomFolder());
223: treePath = folder.getTreePath();
224: markChooseFolderButton.setText(treePath);
225:
226: markMoveToRadioButton.setSelected(!spam
227: .isMoveTrashSelected());
228: markTrashRadioButton
229: .setSelected(spam.isMoveTrashSelected());
230: addressCheckBox.setSelected(spam.checkAddressbook());
231:
232: enableComponents(enableCheckBox.isSelected());
233: } else {
234: spam.setEnabled(enableCheckBox.isSelected());
235:
236: spam.enableMoveIncomingJunkMessage(incomingCheckBox
237: .isSelected());
238: spam
239: .enableMoveMessageWhenMarking(markCheckBox
240: .isSelected());
241:
242: spam.selectedIncomingTrash(incomingTrashRadioButton
243: .isSelected());
244: spam.selectMoveTrash(markTrashRadioButton.isSelected());
245:
246: TreeNodeList list = new TreeNodeList(
247: incomingChooseFolderButton.getText());
248: IMailbox folder = (IMailbox) FolderTreeModel.getInstance()
249: .getFolder(list);
250:
251: if (folder == null) {
252: // user didn't select any folder
253: // -> make Inbox the default folder
254: folder = (IMailbox) FolderTreeModel.getInstance()
255: .getFolder("101");
256: }
257:
258: String uid = folder.getId();
259: spam.setIncomingCustomFolder(uid);
260:
261: list = new TreeNodeList(markChooseFolderButton.getText());
262: folder = (IMailbox) FolderTreeModel.getInstance()
263: .getFolder(list);
264:
265: if (folder == null) {
266: // user didn't select any folder
267: // -> make Inbox the default folder
268: folder = (IMailbox) FolderTreeModel.getInstance()
269: .getFolder("101");
270: }
271:
272: uid = folder.getId();
273: spam.setMoveCustomFolder(uid);
274: spam.enableCheckAddressbook(addressCheckBox.isSelected());
275: }
276: }
277:
278: public void actionPerformed(ActionEvent arg0) {
279: String action = arg0.getActionCommand();
280:
281: if (action.equals("ENABLE")) {
282: enableComponents(enableCheckBox.isSelected());
283: } else if (action.equals("INCOMING")) {
284: enableIncoming(incomingCheckBox.isSelected());
285: } else if (action.equals("MARK")) {
286: enableMark(markCheckBox.isSelected());
287: } else if (action.equals("MARK_BUTTON")) {
288: SelectFolderDialog dialog = new SelectFolderDialog(mediator);
289: if (dialog.success()) {
290: IMailFolder folder = (IMailFolder) dialog
291: .getSelectedFolder();
292:
293: String treePath = folder.getTreePath();
294: markChooseFolderButton.setText(treePath);
295: }
296: } else if (action.equals("INCOMING_BUTTON")) {
297: SelectFolderDialog dialog = new SelectFolderDialog(mediator);
298: if (dialog.success()) {
299: IMailFolder folder = (IMailFolder) dialog
300: .getSelectedFolder();
301:
302: String treePath = folder.getTreePath();
303: incomingChooseFolderButton.setText(treePath);
304: }
305: }
306: }
307:
308: private void enableComponents(boolean enable) {
309: addressCheckBox.setEnabled(enable);
310:
311: incomingCheckBox.setEnabled(enable);
312: enableIncoming(enable);
313:
314: markCheckBox.setEnabled(enable);
315: enableMark(enable);
316: }
317:
318: private void enableIncoming(boolean enable) {
319: incomingChooseFolderButton.setEnabled(incomingCheckBox
320: .isSelected());
321: incomingMoveToRadioButton.setEnabled(incomingCheckBox
322: .isSelected());
323: incomingTrashRadioButton.setEnabled(incomingCheckBox
324: .isSelected());
325: }
326:
327: private void enableMark(boolean enable) {
328: markChooseFolderButton.setEnabled(markCheckBox.isSelected());
329: markMoveToRadioButton.setEnabled(markCheckBox.isSelected());
330: markTrashRadioButton.setEnabled(markCheckBox.isSelected());
331: }
332: }
|