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.BorderLayout;
022: import java.awt.GridLayout;
023: import java.awt.event.ActionEvent;
024: import java.awt.event.ActionListener;
025: import java.awt.event.KeyEvent;
026:
027: import javax.swing.BorderFactory;
028: import javax.swing.JComponent;
029: import javax.swing.JDialog;
030: import javax.swing.JPanel;
031: import javax.swing.JTabbedPane;
032: import javax.swing.KeyStroke;
033:
034: import org.columba.api.gui.frame.IFrameMediator;
035: import org.columba.core.gui.base.ButtonWithMnemonic;
036: import org.columba.core.help.HelpManager;
037: import org.columba.mail.config.AccountItem;
038: import org.columba.mail.folder.imap.IMAPRootFolder;
039: import org.columba.mail.gui.tree.FolderTreeModel;
040: import org.columba.mail.mailchecking.MailCheckingManager;
041: import org.columba.mail.pop3.POP3Server;
042: import org.columba.mail.pop3.POP3ServerCollection;
043: import org.columba.mail.util.MailResourceLoader;
044:
045: /**
046: * Dialog for managing accounts and their settings.
047: */
048:
049: public class AccountDialog extends JDialog implements ActionListener {
050:
051: private AccountItem accountItem;
052:
053: private IdentityPanel identityPanel;
054:
055: private IncomingServerPanel incomingServerPanel;
056:
057: private OutgoingServerPanel outgoingServerPanel;
058:
059: private SecurityPanel securityPanel;
060:
061: private ReceiveOptionsPanel receiveOptionsPanel;
062:
063: private SpamPanel spamPanel;
064:
065: private JTabbedPane tp;
066:
067: private IFrameMediator mediator;
068:
069: public AccountDialog(IFrameMediator mediator, AccountItem item) {
070: super (mediator.getView().getFrame(), true);
071:
072: this .mediator = mediator;
073: setTitle(MailResourceLoader.getString("dialog", "account",
074: "preferences_for")
075: + " " + item.getName());
076: this .accountItem = item;
077: createPanels();
078: initComponents();
079:
080: pack();
081: setLocationRelativeTo(null);
082: setVisible(true);
083: }
084:
085: protected void createPanels() {
086: identityPanel = new IdentityPanel(accountItem);
087:
088: receiveOptionsPanel = new ReceiveOptionsPanel(accountItem);
089:
090: incomingServerPanel = new IncomingServerPanel(this ,
091: accountItem, receiveOptionsPanel);
092:
093: outgoingServerPanel = new OutgoingServerPanel(this , accountItem);
094:
095: securityPanel = new SecurityPanel(accountItem.getPGPItem());
096:
097: spamPanel = new SpamPanel(mediator, accountItem);
098: }
099:
100: protected void initComponents() {
101: getContentPane().setLayout(new BorderLayout());
102:
103: JPanel mainPanel = new JPanel();
104: mainPanel.setLayout(new BorderLayout());
105:
106: // mainPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
107: tp = new JTabbedPane();
108: tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
109: tp.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
110:
111: tp.add(MailResourceLoader.getString("dialog", "account",
112: "identity"), identityPanel);
113:
114: //$NON-NLS-1$
115: String incomingServerPanelTitle = MailResourceLoader.getString(
116: "dialog", "account", "incomingserver");
117:
118: if (accountItem.isPopAccount()) {
119: incomingServerPanelTitle += " (POP3)";
120: } else {
121: incomingServerPanelTitle += " (IMAP4)";
122: }
123:
124: tp.add(incomingServerPanelTitle, incomingServerPanel);
125:
126: tp.add(MailResourceLoader.getString("dialog", "account",
127: "receiveoptions"), receiveOptionsPanel);
128:
129: tp.add(MailResourceLoader.getString("dialog", "account",
130: "outgoingserver"), outgoingServerPanel);
131:
132: //$NON-NLS-1$
133: tp.add(MailResourceLoader.getString("dialog", "account",
134: "security"), securityPanel);
135:
136: // @author: fdietz
137:
138: tp.add("Spam Filter", spamPanel);
139:
140: //$NON-NLS-1$
141: mainPanel.add(tp, BorderLayout.CENTER);
142:
143: getContentPane().add(mainPanel, BorderLayout.CENTER);
144: getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
145: getRootPane().registerKeyboardAction(this , "CANCEL",
146: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
147: JComponent.WHEN_IN_FOCUSED_WINDOW);
148: HelpManager.getInstance().enableHelpKey(getRootPane(),
149: "configuring_columba");
150: }
151:
152: protected JPanel createButtonPanel() {
153: JPanel bottom = new JPanel();
154: bottom.setLayout(new BorderLayout());
155:
156: bottom.setBorder(BorderFactory
157: .createEmptyBorder(12, 12, 12, 12));
158:
159: ButtonWithMnemonic cancelButton = new ButtonWithMnemonic(
160: MailResourceLoader.getString("global", "cancel"));
161:
162: //$NON-NLS-1$ //$NON-NLS-2$
163: cancelButton.addActionListener(this );
164: cancelButton.setActionCommand("CANCEL"); //$NON-NLS-1$
165:
166: ButtonWithMnemonic okButton = new ButtonWithMnemonic(
167: MailResourceLoader.getString("global", "ok"));
168:
169: //$NON-NLS-1$ //$NON-NLS-2$
170: okButton.addActionListener(this );
171: okButton.setActionCommand("OK"); //$NON-NLS-1$
172: okButton.setDefaultCapable(true);
173: getRootPane().setDefaultButton(okButton);
174:
175: ButtonWithMnemonic helpButton = new ButtonWithMnemonic(
176: MailResourceLoader.getString("global", "help"));
177:
178: // associate with JavaHelp
179: HelpManager.getInstance().enableHelpOnButton(helpButton,
180: "configuring_columba");
181:
182: JPanel buttonPanel = new JPanel();
183: buttonPanel.setLayout(new GridLayout(1, 3, 6, 0));
184: buttonPanel.add(okButton);
185: buttonPanel.add(cancelButton);
186: buttonPanel.add(helpButton);
187:
188: bottom.add(buttonPanel, BorderLayout.EAST);
189:
190: return bottom;
191: }
192:
193: /**
194: * Check if user entered valid data in all panels
195: * <p>
196: * Note, that we also select the panel.
197: *
198: * @return true, if data is valid. false, otherwise
199: */
200: protected boolean isFinished() {
201: boolean result = identityPanel.isFinished();
202:
203: if (!result) {
204: tp.setSelectedComponent(identityPanel);
205:
206: return false;
207: }
208:
209: result = incomingServerPanel.isFinished();
210:
211: if (!result) {
212: tp.setSelectedComponent(incomingServerPanel);
213:
214: return false;
215: }
216:
217: result = outgoingServerPanel.isFinished();
218:
219: if (!result) {
220: tp.setSelectedComponent(outgoingServerPanel);
221:
222: return false;
223: }
224:
225: return true;
226: }
227:
228: public void actionPerformed(ActionEvent e) {
229: String action = e.getActionCommand();
230:
231: if (action.equals("OK")) //$NON-NLS-1$
232: {
233: // check if the user entered valid data
234: if (!isFinished()) {
235: return;
236: }
237:
238: identityPanel.updateComponents(false);
239: incomingServerPanel.updateComponents(false);
240: receiveOptionsPanel.updateComponents(false);
241: outgoingServerPanel.updateComponents(false);
242: securityPanel.updateComponents(false);
243: spamPanel.updateComponents(false);
244:
245: if (accountItem.isPopAccount()) {
246: int uid = accountItem.getUid();
247: POP3Server server = POP3ServerCollection.getInstance()
248: .uidGet(uid);
249: // update configuration
250: server.updateConfig();
251:
252: } else {
253: // update tree label
254: int uid = accountItem.getUid();
255:
256: IMAPRootFolder folder = (IMAPRootFolder) FolderTreeModel
257: .getInstance().getImapFolder(uid);
258: folder.updateConfiguration();
259: }
260:
261: // restart timer
262: MailCheckingManager.getInstance().restartTimer(
263: accountItem.getUid());
264:
265: // notify all observers
266: MailCheckingManager.getInstance().update();
267:
268: setVisible(false);
269: } else if (action.equals("CANCEL")) {
270: setVisible(false);
271: }
272: }
273: }
|