1 19 package org.columba.mail.gui.config.account; 20 21 import java.awt.BorderLayout ; 22 import java.awt.GridLayout ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import java.awt.event.KeyEvent ; 26 27 import javax.swing.BorderFactory ; 28 import javax.swing.JComponent ; 29 import javax.swing.JDialog ; 30 import javax.swing.JPanel ; 31 import javax.swing.JTabbedPane ; 32 import javax.swing.KeyStroke ; 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 48 49 public class AccountDialog extends JDialog implements ActionListener { 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 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 ()); 102 103 JPanel mainPanel = new JPanel (); 104 mainPanel.setLayout(new BorderLayout ()); 105 106 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", "identity"), 112 identityPanel); 113 114 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 tp.add(MailResourceLoader.getString("dialog", "account", "security"), 134 securityPanel); 135 136 138 tp.add("Spam Filter", spamPanel); 139 140 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.createEmptyBorder(12, 12, 12, 12)); 157 158 ButtonWithMnemonic cancelButton = new ButtonWithMnemonic( 159 MailResourceLoader.getString("global", "cancel")); 160 161 cancelButton.addActionListener(this); 163 cancelButton.setActionCommand("CANCEL"); 165 ButtonWithMnemonic okButton = new ButtonWithMnemonic(MailResourceLoader 166 .getString("global", "ok")); 167 168 okButton.addActionListener(this); 170 okButton.setActionCommand("OK"); okButton.setDefaultCapable(true); 172 getRootPane().setDefaultButton(okButton); 173 174 ButtonWithMnemonic helpButton = new ButtonWithMnemonic( 175 MailResourceLoader.getString("global", "help")); 176 177 HelpManager.getInstance().enableHelpOnButton(helpButton, 179 "configuring_columba"); 180 181 JPanel buttonPanel = new JPanel (); 182 buttonPanel.setLayout(new GridLayout (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 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 e) { 228 String action = e.getActionCommand(); 229 230 if (action.equals("OK")) { 232 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 server.updateConfig(); 250 251 } else { 252 int uid = accountItem.getUid(); 254 255 IMAPRootFolder folder = (IMAPRootFolder) FolderTreeModel 256 .getInstance().getImapFolder(uid); 257 folder.updateConfiguration(); 258 } 259 260 MailCheckingManager.getInstance() 262 .restartTimer(accountItem.getUid()); 263 264 MailCheckingManager.getInstance().update(); 266 267 setVisible(false); 268 } else if (action.equals("CANCEL")) { 269 setVisible(false); 270 } 271 } 272 } | Popular Tags |