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.mail.gui.config.account;
019:
020: import java.awt.Font;
021: import java.awt.GridBagConstraints;
022: import java.awt.GridBagLayout;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.io.File;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.ButtonGroup;
029: import javax.swing.JButton;
030: import javax.swing.JCheckBox;
031: import javax.swing.JFileChooser;
032: import javax.swing.JLabel;
033: import javax.swing.JPanel;
034: import javax.swing.JRadioButton;
035: import javax.swing.JSpinner;
036: import javax.swing.SpinnerNumberModel;
037:
038: import org.columa.core.config.IDefaultItem;
039: import org.columba.core.gui.base.CheckBoxWithMnemonic;
040: import org.columba.core.gui.base.LabelWithMnemonic;
041: import org.columba.mail.config.AccountItem;
042: import org.columba.mail.config.IncomingItem;
043: import org.columba.mail.util.MailResourceLoader;
044:
045: import com.jgoodies.forms.builder.DefaultFormBuilder;
046: import com.jgoodies.forms.layout.FormLayout;
047:
048: /**
049: * @author frd
050: *
051: * To change this generated comment edit the template variable "typecomment":
052: * Window>Preferences>Java>Templates. To enable and disable the creation of type
053: * comments go to Window>Preferences>Java>Code Generation.
054: */
055: public class ReceiveOptionsPanel extends DefaultPanel implements
056: ActionListener {
057:
058: private AccountItem item;
059:
060: private JCheckBox playsoundCheckBox;
061:
062: private JCheckBox autodownloadCheckBox;
063:
064: private JSpinner intervalCheckingSpinner;
065:
066: private JLabel intervalCheckingLabel;
067:
068: private JLabel intervalCheckingLabel2;
069:
070: private JCheckBox intervalCheckingCheckBox;
071:
072: private JRadioButton defaultRadioButton;
073:
074: private JRadioButton chooseRadioButton;
075:
076: private JButton chooseButton;
077:
078: private PopAttributPanel popPanel;
079:
080: private ImapAttributPanel imapPanel;
081:
082: public ReceiveOptionsPanel(AccountItem item) {
083: this .item = item;
084:
085: initComponents();
086:
087: updateComponents(true);
088: }
089:
090: protected void showDefaultAccountWarning() {
091: setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
092:
093: GridBagLayout mainLayout = new GridBagLayout();
094: GridBagConstraints mainConstraints = new GridBagConstraints();
095:
096: setLayout(mainLayout);
097:
098: mainConstraints = new GridBagConstraints();
099: mainConstraints.weighty = 1.0;
100: mainConstraints.gridwidth = GridBagConstraints.REMAINDER;
101:
102: JLabel label = new JLabel(MailResourceLoader.getString(
103: "dialog", "account", "using_default_account_settings"));
104: Font newFont = label.getFont().deriveFont(Font.BOLD);
105: label.setFont(newFont);
106: mainLayout.setConstraints(label, mainConstraints);
107: add(label);
108: }
109:
110: protected void layoutComponents() {
111: // Create a FormLayout instance.
112: FormLayout layout = new FormLayout(
113: "10dlu, 10dlu, max(100;default), 3dlu, fill:max(150dlu;default):grow",
114:
115: // 2 columns
116: ""); // rows are added dynamically (no need to define them
117: // here)
118:
119: DefaultFormBuilder builder = new DefaultFormBuilder(layout,
120: this );
121: builder.setLeadingColumnOffset(1);
122:
123: // create EmptyBorder between components and dialog-frame
124: builder.setDefaultDialogBorder();
125:
126: // Add components to the panel:
127: builder.appendSeparator(MailResourceLoader.getString("dialog",
128: "account", "automatic_mailchecking"));
129:
130: builder.append(intervalCheckingCheckBox, 4);
131: builder.nextLine();
132:
133: // builder.setLeadingColumnOffset(2);
134: builder.setLeadingColumnOffset(2);
135: builder.append(autodownloadCheckBox, 3);
136: builder.nextLine();
137:
138: builder.append(playsoundCheckBox, 3);
139: builder.nextLine();
140:
141: JPanel panel = new JPanel();
142: FormLayout l = new FormLayout(
143: "default, 3dlu, default, 3dlu, default",
144:
145: // 2 columns
146: ""); // rows are added dynamically (no need to define them
147: // here)
148:
149: // create a form builder
150: DefaultFormBuilder b = new DefaultFormBuilder(l, panel);
151: b.append(intervalCheckingLabel, intervalCheckingSpinner,
152: intervalCheckingLabel2);
153:
154: builder.append(panel, 3);
155:
156: // b2.nextLine();
157: builder.setLeadingColumnOffset(1);
158:
159: if (item.isPopAccount()) {
160: popPanel.createPanel(builder);
161: } else {
162: imapPanel.createPanel(builder);
163:
164: // attributPanel.add(imapPanel, BorderLayout.CENTER);
165: }
166:
167: }
168:
169: protected void initComponents() {
170: intervalCheckingLabel = new LabelWithMnemonic(
171: MailResourceLoader.getString("dialog", "account",
172: "check_for_new_messages_every"));
173:
174: intervalCheckingSpinner = new JSpinner(new SpinnerNumberModel(
175: 5, 1, 100, 1));
176: intervalCheckingLabel.setLabelFor(intervalCheckingSpinner);
177:
178: intervalCheckingLabel2 = new JLabel(MailResourceLoader
179: .getString("dialog", "account", "minutes"));
180:
181: intervalCheckingCheckBox = new CheckBoxWithMnemonic(
182: MailResourceLoader.getString("dialog", "account",
183: "enable_interval_message_checking"));
184:
185: intervalCheckingCheckBox.setActionCommand("ENABLE");
186: intervalCheckingCheckBox.addActionListener(this );
187:
188: autodownloadCheckBox = new CheckBoxWithMnemonic(
189: MailResourceLoader
190: .getString(
191: "dialog",
192: "account",
193: IncomingItem.AUTOMATICALLY_DOWNLOAD_NEW_MESSAGES));
194:
195: playsoundCheckBox = new CheckBoxWithMnemonic(MailResourceLoader
196: .getString("dialog", "account",
197: "play_sound_when_new_messages_arrive"));
198:
199: playsoundCheckBox.setActionCommand("PLAYSOUND");
200: playsoundCheckBox.addActionListener(this );
201:
202: ButtonGroup group = new ButtonGroup();
203: defaultRadioButton = new JRadioButton(MailResourceLoader
204: .getString("dialog", "account", "default_soundfile"));
205:
206: group.add(defaultRadioButton);
207: chooseRadioButton = new JRadioButton(MailResourceLoader
208: .getString("dialog", "account", "choose_soundfile"));
209: group.add(chooseRadioButton);
210: chooseButton = new JButton("..");
211: chooseButton.setActionCommand("CHOOSE");
212: chooseButton.addActionListener(this );
213:
214: if (item.isPopAccount()) {
215: popPanel = new PopAttributPanel(item.getPopItem());
216:
217: } else {
218: imapPanel = new ImapAttributPanel(item.getImapItem());
219:
220: }
221: }
222:
223: public void updateComponents(boolean b) {
224: IDefaultItem receiveItem;
225:
226: if (item.isPopAccount()) {
227: receiveItem = item.getPopItem();
228: } else {
229: receiveItem = item.getImapItem();
230: }
231:
232: if (b) {
233: intervalCheckingCheckBox.setSelected(receiveItem
234: .getBoolean(IncomingItem.ENABLE_MAILCHECK));
235:
236: if (!intervalCheckingCheckBox.isSelected()) {
237: // disable components
238: defaultRadioButton.setEnabled(false);
239: autodownloadCheckBox.setEnabled(false);
240: playsoundCheckBox.setEnabled(false);
241: chooseButton.setEnabled(false);
242: intervalCheckingLabel.setEnabled(false);
243: intervalCheckingLabel2.setEnabled(false);
244: intervalCheckingSpinner.setEnabled(false);
245: chooseRadioButton.setEnabled(false);
246: }
247:
248: playsoundCheckBox.setSelected(receiveItem
249: .getBoolean(IncomingItem.ENABLE_SOUND));
250:
251: autodownloadCheckBox
252: .setSelected(receiveItem
253: .getBoolean(IncomingItem.AUTOMATICALLY_DOWNLOAD_NEW_MESSAGES));
254:
255: intervalCheckingSpinner
256: .setValue(new Integer(
257: receiveItem
258: .getIntegerWithDefault(
259: IncomingItem.MAILCHECK_INTERVAL,
260: IncomingItem.MAIL_CHECK_INTERVAL_DEFAULT_INT)));
261:
262: String soundfile = receiveItem.get(IncomingItem.SOUND_FILE);
263:
264: if (soundfile.equalsIgnoreCase(IncomingItem.DEFAULT)) {
265: defaultRadioButton.setSelected(true);
266: } else {
267: chooseRadioButton.setSelected(true);
268: }
269:
270: if (playsoundCheckBox.isSelected()) {
271: defaultRadioButton.setEnabled(true);
272: chooseRadioButton.setEnabled(true);
273: chooseButton.setEnabled(true);
274: } else {
275: defaultRadioButton.setEnabled(false);
276: chooseRadioButton.setEnabled(false);
277: chooseButton.setEnabled(false);
278: }
279:
280: chooseButton.setText(soundfile);
281:
282: boolean useDefault = receiveItem
283: .getBoolean(IncomingItem.USE_DEFAULT_ACCOUNT);
284:
285: if (useDefault) {
286: showDefaultAccountWarning();
287: } else {
288: layoutComponents();
289: }
290: } else {
291: receiveItem.setBoolean(IncomingItem.ENABLE_MAILCHECK,
292: intervalCheckingCheckBox.isSelected());
293:
294: receiveItem.setBoolean(IncomingItem.ENABLE_SOUND,
295: playsoundCheckBox.isSelected());
296:
297: receiveItem.setBoolean(
298: IncomingItem.AUTOMATICALLY_DOWNLOAD_NEW_MESSAGES,
299: autodownloadCheckBox.isSelected());
300:
301: receiveItem.setString(IncomingItem.MAILCHECK_INTERVAL,
302: ((Integer) intervalCheckingSpinner.getValue())
303: .toString());
304:
305: if (defaultRadioButton.isSelected()) {
306: receiveItem.setString(IncomingItem.SOUND_FILE,
307: IncomingItem.DEFAULT);
308: } else {
309: receiveItem.setString(IncomingItem.SOUND_FILE,
310: chooseButton.getText());
311: }
312: }
313:
314: if (item.isPopAccount()) {
315: popPanel.updateComponents(b);
316: } else {
317: imapPanel.updateComponents(b);
318: }
319: }
320:
321: public void actionPerformed(ActionEvent e) {
322: if (e.getActionCommand().equals("ENABLE")) {
323: boolean doIntervalChecking = intervalCheckingCheckBox
324: .isSelected();
325: defaultRadioButton.setEnabled(doIntervalChecking);
326: autodownloadCheckBox.setEnabled(doIntervalChecking);
327: playsoundCheckBox.setEnabled(doIntervalChecking);
328: chooseButton.setEnabled(doIntervalChecking);
329: chooseRadioButton.setEnabled(doIntervalChecking);
330: intervalCheckingLabel.setEnabled(doIntervalChecking);
331: intervalCheckingLabel2.setEnabled(doIntervalChecking);
332: intervalCheckingSpinner.setEnabled(doIntervalChecking);
333:
334: boolean playSound = playsoundCheckBox.isSelected();
335: defaultRadioButton.setEnabled(playSound);
336: chooseRadioButton.setEnabled(playSound);
337: chooseButton.setEnabled(playSound);
338: } else if (e.getActionCommand().equals("PLAYSOUND")) {
339: boolean playSound = playsoundCheckBox.isSelected();
340: defaultRadioButton.setEnabled(playSound);
341: chooseButton.setEnabled(playSound);
342: chooseRadioButton.setEnabled(playSound);
343: } else if (e.getActionCommand().equals("CHOOSE")) {
344: JFileChooser fc = new JFileChooser();
345: int returnVal = fc.showOpenDialog(this );
346:
347: if (returnVal == JFileChooser.APPROVE_OPTION) {
348: File file = fc.getSelectedFile();
349: chooseButton.setText(file.getPath());
350: }
351: }
352: }
353: }
|