KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > config > account > AccountDialog


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

19 package org.columba.mail.gui.config.account;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.GridLayout JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.awt.event.KeyEvent JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JComponent JavaDoc;
29 import javax.swing.JDialog JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31 import javax.swing.JTabbedPane JavaDoc;
32 import javax.swing.KeyStroke JavaDoc;
33
34 import org.columba.api.gui.frame.IFrameMediator;
35 import org.columba.core.gui.base.ButtonWithMnemonic;
36 import org.columba.core.help.HelpManager;
37 import org.columba.mail.config.AccountItem;
38 import org.columba.mail.folder.imap.IMAPRootFolder;
39 import org.columba.mail.gui.tree.FolderTreeModel;
40 import org.columba.mail.mailchecking.MailCheckingManager;
41 import org.columba.mail.pop3.POP3Server;
42 import org.columba.mail.pop3.POP3ServerCollection;
43 import org.columba.mail.util.MailResourceLoader;
44
45 /**
46  * Dialog for managing accounts and their settings.
47  */

48
49 public class AccountDialog extends JDialog JavaDoc implements ActionListener JavaDoc {
50
51     private AccountItem accountItem;
52
53     private IdentityPanel identityPanel;
54
55     private IncomingServerPanel incomingServerPanel;
56
57     private OutgoingServerPanel outgoingServerPanel;
58
59     private SecurityPanel securityPanel;
60
61     private ReceiveOptionsPanel receiveOptionsPanel;
62
63     private SpamPanel spamPanel;
64
65     private JTabbedPane JavaDoc tp;
66
67     private IFrameMediator mediator;
68
69     public AccountDialog(IFrameMediator mediator, AccountItem item) {
70         super(mediator.getView().getFrame(), true);
71
72         this.mediator = mediator;
73         setTitle(MailResourceLoader.getString("dialog", "account",
74                 "preferences_for")
75                 + " " + item.getName());
76         this.accountItem = item;
77         createPanels();
78         initComponents();
79
80         pack();
81         setLocationRelativeTo(null);
82         setVisible(true);
83     }
84
85     protected void createPanels() {
86         identityPanel = new IdentityPanel(accountItem);
87
88         receiveOptionsPanel = new ReceiveOptionsPanel(accountItem);
89
90         incomingServerPanel = new IncomingServerPanel(this, accountItem,
91                 receiveOptionsPanel);
92
93         outgoingServerPanel = new OutgoingServerPanel(this, accountItem);
94
95         securityPanel = new SecurityPanel(accountItem.getPGPItem());
96
97         spamPanel = new SpamPanel(mediator, accountItem);
98     }
99
100     protected void initComponents() {
101         getContentPane().setLayout(new BorderLayout JavaDoc());
102
103         JPanel JavaDoc mainPanel = new JPanel JavaDoc();
104         mainPanel.setLayout(new BorderLayout JavaDoc());
105
106         // mainPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
107
tp = new JTabbedPane JavaDoc();
108         tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
109         tp.setBorder(BorderFactory.createEmptyBorder(5, 10, 0, 10));
110
111         tp.add(MailResourceLoader.getString("dialog", "account", "identity"),
112                 identityPanel);
113
114         //$NON-NLS-1$
115
String JavaDoc 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", "security"),
134                 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 JavaDoc createButtonPanel() {
153         JPanel JavaDoc bottom = new JPanel JavaDoc();
154         bottom.setLayout(new BorderLayout JavaDoc());
155
156         bottom.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
157
158         ButtonWithMnemonic cancelButton = new ButtonWithMnemonic(
159                 MailResourceLoader.getString("global", "cancel"));
160
161         //$NON-NLS-1$ //$NON-NLS-2$
162
cancelButton.addActionListener(this);
163         cancelButton.setActionCommand("CANCEL"); //$NON-NLS-1$
164

165         ButtonWithMnemonic okButton = new ButtonWithMnemonic(MailResourceLoader
166                 .getString("global", "ok"));
167
168         //$NON-NLS-1$ //$NON-NLS-2$
169
okButton.addActionListener(this);
170         okButton.setActionCommand("OK"); //$NON-NLS-1$
171
okButton.setDefaultCapable(true);
172         getRootPane().setDefaultButton(okButton);
173
174         ButtonWithMnemonic helpButton = new ButtonWithMnemonic(
175                 MailResourceLoader.getString("global", "help"));
176
177         // associate with JavaHelp
178
HelpManager.getInstance().enableHelpOnButton(helpButton,
179                 "configuring_columba");
180
181         JPanel JavaDoc buttonPanel = new JPanel JavaDoc();
182         buttonPanel.setLayout(new GridLayout JavaDoc(1, 3, 6, 0));
183         buttonPanel.add(okButton);
184         buttonPanel.add(cancelButton);
185         buttonPanel.add(helpButton);
186
187         bottom.add(buttonPanel, BorderLayout.EAST);
188
189         return bottom;
190     }
191
192     /**
193      * Check if user entered valid data in all panels
194      * <p>
195      * Note, that we also select the panel.
196      *
197      * @return true, if data is valid. false, otherwise
198      */

199     protected boolean isFinished() {
200         boolean result = identityPanel.isFinished();
201
202         if (!result) {
203             tp.setSelectedComponent(identityPanel);
204
205             return false;
206         }
207
208         result = incomingServerPanel.isFinished();
209
210         if (!result) {
211             tp.setSelectedComponent(incomingServerPanel);
212
213             return false;
214         }
215
216         result = outgoingServerPanel.isFinished();
217
218         if (!result) {
219             tp.setSelectedComponent(outgoingServerPanel);
220
221             return false;
222         }
223
224         return true;
225     }
226
227     public void actionPerformed(ActionEvent JavaDoc e) {
228         String JavaDoc action = e.getActionCommand();
229
230         if (action.equals("OK")) //$NON-NLS-1$
231
{
232             // check if the user entered valid data
233
if (!isFinished()) {
234                 return;
235             }
236
237             identityPanel.updateComponents(false);
238             incomingServerPanel.updateComponents(false);
239             receiveOptionsPanel.updateComponents(false);
240             outgoingServerPanel.updateComponents(false);
241             securityPanel.updateComponents(false);
242             spamPanel.updateComponents(false);
243
244             if (accountItem.isPopAccount()) {
245                 int uid = accountItem.getUid();
246                 POP3Server server = POP3ServerCollection.getInstance().uidGet(
247                         uid);
248                 // update configuration
249
server.updateConfig();
250
251             } else {
252                 // update tree label
253
int uid = accountItem.getUid();
254
255                 IMAPRootFolder folder = (IMAPRootFolder) FolderTreeModel
256                         .getInstance().getImapFolder(uid);
257                 folder.updateConfiguration();
258             }
259
260             // restart timer
261
MailCheckingManager.getInstance()
262                     .restartTimer(accountItem.getUid());
263
264             // notify all observers
265
MailCheckingManager.getInstance().update();
266
267             setVisible(false);
268         } else if (action.equals("CANCEL")) {
269             setVisible(false);
270         }
271     }
272 }
Popular Tags