1 package org.columba.mail.gui.config.general; 17 18 import java.awt.BorderLayout ; 19 import java.awt.Color ; 20 import java.awt.GridLayout ; 21 import java.awt.event.ActionEvent ; 22 import java.awt.event.ActionListener ; 23 import java.awt.event.KeyEvent ; 24 import java.util.Enumeration ; 25 import java.util.Vector ; 26 27 import javax.swing.BorderFactory ; 28 import javax.swing.JButton ; 29 import javax.swing.JCheckBox ; 30 import javax.swing.JColorChooser ; 31 import javax.swing.JComboBox ; 32 import javax.swing.JComponent ; 33 import javax.swing.JDialog ; 34 import javax.swing.JFrame ; 35 import javax.swing.JLabel ; 36 import javax.swing.JOptionPane ; 37 import javax.swing.JPanel ; 38 import javax.swing.JSpinner ; 39 import javax.swing.KeyStroke ; 40 import javax.swing.SpinnerNumberModel ; 41 import javax.swing.SwingConstants ; 42 43 import org.columba.api.plugin.IExtension; 44 import org.columba.api.plugin.IExtensionHandler; 45 import org.columba.api.plugin.IExtensionHandlerKeys; 46 import org.columba.api.plugin.PluginHandlerNotFoundException; 47 import org.columba.core.gui.base.ButtonWithMnemonic; 48 import org.columba.core.gui.base.CheckBoxWithMnemonic; 49 import org.columba.core.gui.base.LabelWithMnemonic; 50 import org.columba.core.gui.base.SingleSideEtchedBorder; 51 import org.columba.core.gui.util.DialogHeaderPanel; 52 import org.columba.core.help.HelpManager; 53 import org.columba.core.plugin.PluginManager; 54 import org.columba.mail.config.ComposerItem; 55 import org.columba.mail.config.MailConfig; 56 import org.columba.mail.config.OptionsItem; 57 import org.columba.mail.util.MailResourceLoader; 58 59 import com.jgoodies.forms.builder.DefaultFormBuilder; 60 import com.jgoodies.forms.layout.FormLayout; 61 62 67 public class MailOptionsDialog extends JDialog implements ActionListener { 68 protected JButton okButton; 69 70 protected JButton cancelButton; 71 72 protected JButton helpButton; 73 74 protected CheckBoxWithMnemonic markCheckBox; 75 76 protected JSpinner markSpinner; 77 78 protected CheckBoxWithMnemonic preferHtmlCheckBox; 79 80 protected CheckBoxWithMnemonic disableHtmlCheckBox; 81 82 protected CheckBoxWithMnemonic enableSmiliesCheckBox; 83 84 protected CheckBoxWithMnemonic quotedColorCheckBox; 85 86 protected JButton quotedColorButton; 87 88 protected JCheckBox emptyTrashCheckBox; 89 90 protected CheckBoxWithMnemonic emptySubjectCheckBox; 91 92 protected CheckBoxWithMnemonic sendHtmlMultipartCheckBox; 93 94 protected CheckBoxWithMnemonic showAttachmentsInlineCheckBox; 95 96 private JLabel selectedBrowserLabel; 97 98 protected JComboBox selectedBrowserComboBox; 99 100 protected LabelWithMnemonic forwardLabel; 101 102 protected JComboBox forwardComboBox; 103 104 public MailOptionsDialog(JFrame frame) { 105 super(frame, MailResourceLoader.getString("dialog", "general", 106 "dialog_title"), true); 107 108 initComponents(); 109 110 layoutComponents(); 111 112 updateComponents(true); 113 114 pack(); 115 setLocationRelativeTo(null); 116 setVisible(true); 117 } 118 119 public void updateComponents(boolean b) { 120 OptionsItem optionsItem = MailConfig.getInstance().getOptionsItem(); 121 ComposerItem composerItem = MailConfig.getInstance().getComposerItem(); 122 123 if (b) { 124 125 showAttachmentsInlineCheckBox.setSelected(optionsItem 126 .getBooleanWithDefault(OptionsItem.MESSAGEVIEWER, 127 OptionsItem.INLINE_ATTACHMENTS_BOOL, false)); 128 129 selectedBrowserComboBox.setSelectedItem(optionsItem 130 .getStringWithDefault(OptionsItem.MESSAGEVIEWER, 131 OptionsItem.SELECTED_BROWSER, "Default")); 132 133 int delay = optionsItem.getIntegerWithDefault( 134 OptionsItem.MARKASREAD, OptionsItem.DELAY_INT, 2); 135 boolean enable = optionsItem.getBooleanWithDefault( 136 OptionsItem.MARKASREAD, OptionsItem.ENABLED_BOOL, true); 137 138 markCheckBox.setSelected(enable); 139 markSpinner.setValue(new Integer (delay)); 140 141 boolean enableSmilies = optionsItem.getBooleanWithDefault( 142 OptionsItem.MESSAGEVIEWER_SMILIES, 143 OptionsItem.ENABLED_BOOL, true); 144 145 enableSmiliesCheckBox.setSelected(enableSmilies); 146 147 boolean preferHtml = optionsItem.getBooleanWithDefault( 148 OptionsItem.HTML, OptionsItem.PREFER_BOOL, true); 149 150 preferHtmlCheckBox.setSelected(preferHtml); 151 152 boolean disablehtml = optionsItem.getBooleanWithDefault( 153 OptionsItem.HTML, OptionsItem.DISABLE_BOOL, true); 154 155 disableHtmlCheckBox.setSelected(disablehtml); 156 157 boolean askSubject = composerItem.getBooleanWithDefault( 158 ComposerItem.SUBJECT, ComposerItem.ASK_IF_EMPTY_BOOL, true); 159 160 emptySubjectCheckBox.setSelected(askSubject); 161 162 boolean sendHtml = composerItem.getBooleanWithDefault( 163 ComposerItem.HTML, ComposerItem.SEND_AS_MULTIPART, true); 164 165 sendHtmlMultipartCheckBox.setSelected(sendHtml); 166 167 int forwardStyle = composerItem.getIntegerWithDefault( 168 ComposerItem.FORWARD, ComposerItem.STYLE, 0); 169 170 forwardComboBox.setSelectedIndex(forwardStyle); 171 172 } else { 173 174 optionsItem.setInteger(OptionsItem.MARKASREAD, 175 OptionsItem.DELAY_INT, ((Integer ) markSpinner.getValue()) 176 .intValue()); 177 178 optionsItem.setBoolean(OptionsItem.MARKASREAD, 179 OptionsItem.ENABLED_BOOL, markCheckBox.isSelected()); 180 181 optionsItem.notifyObservers(OptionsItem.MARKASREAD); 184 185 optionsItem.setBoolean(OptionsItem.MESSAGEVIEWER_SMILIES, 186 OptionsItem.ENABLED_BOOL, enableSmiliesCheckBox 187 .isSelected()); 188 189 optionsItem.setBoolean(OptionsItem.MESSAGEVIEWER, 190 OptionsItem.INLINE_ATTACHMENTS_BOOL, 191 showAttachmentsInlineCheckBox.isSelected()); 192 193 optionsItem.setString(OptionsItem.MESSAGEVIEWER, 194 OptionsItem.SELECTED_BROWSER, 195 (String ) selectedBrowserComboBox.getSelectedItem()); 196 197 optionsItem.notifyObservers(OptionsItem.SELECTED_BROWSER); 200 201 optionsItem.notifyObservers(OptionsItem.MESSAGEVIEWER_SMILIES); 204 205 optionsItem.setBoolean(OptionsItem.HTML, OptionsItem.PREFER_BOOL, 206 preferHtmlCheckBox.isSelected()); 207 208 optionsItem.setBoolean(OptionsItem.HTML, OptionsItem.DISABLE_BOOL, 209 disableHtmlCheckBox.isSelected()); 210 211 composerItem.setBoolean(ComposerItem.SUBJECT, 212 ComposerItem.ASK_IF_EMPTY_BOOL, emptySubjectCheckBox 213 .isSelected()); 214 215 composerItem.notifyObservers(ComposerItem.SUBJECT); 218 219 composerItem.setBoolean(ComposerItem.HTML, 220 ComposerItem.SEND_AS_MULTIPART, sendHtmlMultipartCheckBox 221 .isSelected()); 222 composerItem.notifyObservers(ComposerItem.HTML); 224 225 composerItem.setInteger(ComposerItem.FORWARD, ComposerItem.STYLE, 226 forwardComboBox.getSelectedIndex()); 227 228 composerItem.notifyObservers(ComposerItem.FORWARD); 231 232 } 233 } 234 235 protected void initComponents() { 236 markCheckBox = new CheckBoxWithMnemonic(MailResourceLoader.getString( 238 "dialog", "general", "mark_messages_read")); 239 240 markSpinner = new JSpinner (); 241 markSpinner.setModel(new SpinnerNumberModel (1, 0, 99, 1)); 242 243 emptyTrashCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 244 .getString("dialog", "general", "empty_trash")); 245 emptyTrashCheckBox.setEnabled(false); 246 247 enableSmiliesCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 248 .getString("dialog", "general", "enable_smilies")); 249 250 quotedColorCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 251 .getString("dialog", "general", "color_quoted_text")); 252 quotedColorButton = new JButton ("..."); 253 quotedColorButton.setActionCommand("COLOR"); 254 quotedColorButton.addActionListener(this); 255 256 preferHtmlCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 257 .getString("dialog", "general", "prefer_html")); 258 disableHtmlCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 259 .getString("dialog", "general", "disable_html")); 260 emptySubjectCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 262 .getString("dialog", "general", "ask_on_empty_subject")); 263 264 sendHtmlMultipartCheckBox = new CheckBoxWithMnemonic(MailResourceLoader 265 .getString("dialog", "general", "send_html_multipart")); 266 267 forwardLabel = new LabelWithMnemonic(MailResourceLoader.getString( 268 "dialog", "general", "forward_as")); 269 270 String [] items = { 271 MailResourceLoader.getString("dialog", "general", 272 "forward_as_attachment"), 273 MailResourceLoader.getString("dialog", "general", 274 "forward_as_quoted") }; 275 276 forwardComboBox = new JComboBox (items); 277 278 showAttachmentsInlineCheckBox = new CheckBoxWithMnemonic( 279 "Show Attachments &Inline"); 280 showAttachmentsInlineCheckBox.setActionCommand("ATTACHMENTS_INLINE"); 281 showAttachmentsInlineCheckBox.addActionListener(this); 282 283 selectedBrowserLabel = new JLabel ("Message Renderer"); 284 Vector <String > v = new Vector <String >(); 285 try { 286 IExtensionHandler handler = PluginManager.getInstance().getExtensionHandler(IExtensionHandlerKeys.ORG_COLUMBA_CORE_HTMLVIEWER); 287 Enumeration e = handler.getExtensionEnumeration(); 288 while (e.hasMoreElements()) { 289 IExtension ext = (IExtension) e.nextElement(); 290 String id = ext.getMetadata().getId(); 291 v.add(id); 292 } 293 } catch (PluginHandlerNotFoundException e) { 294 e.printStackTrace(); 295 } 296 selectedBrowserComboBox = new JComboBox (v.toArray(new String [0])); 297 selectedBrowserComboBox.setSelectedIndex(0); 298 selectedBrowserComboBox.addActionListener(new ActionListener (){ 299 public void actionPerformed(ActionEvent e) { 300 if ( selectedBrowserComboBox.getSelectedIndex() != 0) 301 JOptionPane 302 .showMessageDialog(MailOptionsDialog.this, 303 "This is an experimental feature and therefore requires a restart of Columba"); 304 }}); 305 306 okButton = new ButtonWithMnemonic(MailResourceLoader.getString( 308 "global", "ok")); 309 okButton.setActionCommand("OK"); 310 okButton.addActionListener(this); 311 312 cancelButton = new ButtonWithMnemonic(MailResourceLoader.getString( 313 "global", "cancel")); 314 cancelButton.setActionCommand("CANCEL"); 315 cancelButton.addActionListener(this); 316 317 helpButton = new ButtonWithMnemonic(MailResourceLoader.getString( 318 "global", "help")); 319 320 HelpManager.getInstance().enableHelpOnButton(helpButton, 322 "configuring_columba_7"); 323 HelpManager.getInstance().enableHelpKey(getRootPane(), 324 "configuring_columba_7"); 325 } 326 327 protected void layoutComponents() { 328 JPanel contentPane = new JPanel (); 329 setContentPane(contentPane); 330 contentPane.setLayout(new BorderLayout ()); 331 332 FormLayout layout = new FormLayout( 334 "12dlu, default, 3dlu, max(10dlu;default), 3dlu, default", 335 336 ""); 339 DefaultFormBuilder builder = new DefaultFormBuilder(layout); 341 342 builder.setDefaultDialogBorder(); 344 345 builder.setLeadingColumnOffset(1); 347 348 builder.appendSeparator(MailResourceLoader.getString("dialog", 350 "general", "general")); 351 builder.nextLine(); 352 353 builder.append(preferHtmlCheckBox, 4); 354 builder.nextLine(); 355 builder.append(disableHtmlCheckBox, 4); 356 builder.nextLine(); 357 builder.append(enableSmiliesCheckBox, 4); 358 builder.nextLine(); 359 362 363 364 365 371 builder.append(markCheckBox, markSpinner); 372 builder.nextLine(); 373 builder.append(selectedBrowserLabel, selectedBrowserComboBox); 374 builder.nextLine(); 375 376 378 builder.appendSeparator(MailResourceLoader.getString("dialog", 379 "general", "composing_messages")); 380 builder.nextLine(); 381 382 builder.append(emptySubjectCheckBox, 4); 383 builder.nextLine(); 384 385 builder.append(sendHtmlMultipartCheckBox, 4); 386 builder.nextLine(); 387 388 builder.append(forwardLabel, forwardComboBox); 389 builder.nextLine(); 390 391 395 contentPane.add(builder.getPanel(), BorderLayout.CENTER); 396 397 JPanel bottomPanel = new JPanel (new BorderLayout (0, 0)); 399 bottomPanel.setBorder(new SingleSideEtchedBorder(SwingConstants.TOP)); 400 401 JPanel buttonPanel = new JPanel (new GridLayout (1, 3, 6, 0)); 402 buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); 403 404 buttonPanel.add(okButton); 405 406 buttonPanel.add(cancelButton); 407 buttonPanel.add(helpButton); 408 409 bottomPanel.add(buttonPanel, BorderLayout.EAST); 410 contentPane.add(bottomPanel, BorderLayout.SOUTH); 411 412 getRootPane().setDefaultButton(okButton); 413 getRootPane().registerKeyboardAction(this, "CANCEL", 414 KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), 415 JComponent.WHEN_IN_FOCUSED_WINDOW); 416 417 contentPane.add(new DialogHeaderPanel("Mail Options", "Change email-specific options"), BorderLayout.NORTH); 418 419 } 420 421 public void actionPerformed(ActionEvent event) { 422 String action = event.getActionCommand(); 423 424 if (action.equals("OK")) { 425 setVisible(false); 426 427 updateComponents(false); 428 } else if (action.equals("CANCEL")) { 429 setVisible(false); 430 } else if (action.equals("COLOR")) { 431 Color newColor = JColorChooser.showDialog(this, MailResourceLoader 433 .getString("dialog", "general", "choose_text_color"), null); 434 435 if (newColor != null) { 436 quotedColorButton.setBackground(newColor); 437 } 438 } 439 } 440 } | Popular Tags |