⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 userconfigdialog.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
字号:
/*** $Id: UserConfigDialog.java,v 1.4 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may redistribute it and/or modify it under the terms of the GNU** General Public License as published by the Free Software Foundation.** Version 2 of the license should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail;import java.awt.Container;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Frame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.border.EmptyBorder; import org.icemail.util.AWTUtilities; import org.icemail.util.ComponentFactory; import org.icemail.util.JFCUtilities; import org.icemail.util.UserProperties; /** * A dialog which allows the user options to be configured. * The options are stored as part of the configuration properties. * * @see Configuration */public class UserConfigDialog  extends JDialog{  private JTextField fromAddrField_;  private JTextField fromPersonalField;  private JTextField replytoAddrField;  private JTextField replytoPersonalField;  private JTextField organizationField;  /**   * Construct a dialog for configuring user options.   *   * @param parent parent frame to return to after disposed   */  public  UserConfigDialog( Frame parent ) {    super( parent, true );    establishContents();    pack();    Dimension sz = getPreferredSize();    int w = UserProperties.getProperty( "userConfigDialog.width", sz.width );    int h = UserProperties.getProperty( "userConfigDialog.height", sz.height );    setSize( w, h );    setLocation( AWTUtilities.computeDialogLocation( this ) );    addWindowListener( new IWindowAdapter() );  }//............................................................  private void  saveUserConfig() {    Configuration config = Configuration.getInstance();    String fromAddr = fromAddrField_.getText();    if ( fromAddr != null && fromAddr.length() > 0 ) {      config.setProperty( Configuration.P_FROM_ADDRESS, fromAddr );    } else {      config.removeProperty( Configuration.P_FROM_ADDRESS );    }    String fromPers = this.fromPersonalField.getText();    if ( fromPers != null && fromPers.length() > 0 ) {      config.setProperty( Configuration.P_FROM_PERSONAL, fromPers );    } else {      config.removeProperty( Configuration.P_FROM_PERSONAL );    }    String replytoAddr = this.replytoAddrField.getText();    if ( replytoAddr != null && replytoAddr.length() > 0 ) {      config.setProperty( Configuration.P_REPLYTO_ADDRESS, replytoAddr );    } else {      config.removeProperty( Configuration.P_REPLYTO_ADDRESS );    }    String replytoPers = this.replytoPersonalField.getText();    if ( replytoPers != null && replytoPers.length() > 0 ) {      config.setProperty ( Configuration.P_REPLYTO_PERSONAL, replytoPers );    } else {      config.removeProperty( Configuration.P_REPLYTO_PERSONAL );    }    String organ = this.organizationField.getText();    if ( organ != null && organ.length() > 0 ) {      config.setProperty( Configuration.P_ORGANIZATION, organ );    } else {      config.removeProperty( Configuration.P_ORGANIZATION );    }    config.saveProperties();  }  private void  establishContents() {    setTitle( ICEMail.getBundle().getString( "UserConfig.Title" ) );    Container cont = getContentPane();    cont.setLayout( new GridBagLayout() );    ActionListener xlistener = new IActionListener();    int row = 0;    JPanel namePan = new JPanel();    namePan.setLayout( new GridBagLayout() );    namePan.setBorder( new EmptyBorder( 4, 4, 4, 4 ) );    AWTUtilities.constrain( cont, namePan, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.NORTH,      0, row++, 2, 1, 1.0, 0.0 );    int subRow = 0;    JLabel  lbl;    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "UserConfig.FromAddress" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 );    fromAddrField_ =      ComponentFactory.getTextField( ICEMail.getBundle(), "UserConfig.FromAddress", null );    fromAddrField_.setText( UserProperties.getProperty( Configuration.P_FROM_ADDRESS, "" ) );    AWTUtilities.constrain( namePan, fromAddrField_, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 );    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "UserConfig.FromPersonal" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 );    this.fromPersonalField =      ComponentFactory.getTextField( ICEMail.getBundle(), "UserConfig.FromPersonal", null );    this.fromPersonalField.setText(        UserProperties.getProperty( Configuration.P_FROM_PERSONAL, "" ) );    AWTUtilities.constrain( namePan, this.fromPersonalField, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 );    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "UserConfig.ReplyToAddress" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 );    this.replytoAddrField =      ComponentFactory.getTextField( ICEMail.getBundle(), "UserConfig.ReplyToAddress", null );    this.replytoAddrField.setText(        UserProperties.getProperty( Configuration.P_REPLYTO_ADDRESS, "" ) );    AWTUtilities.constrain( namePan, this.replytoAddrField, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 );    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "UserConfig.ReplyToPersonal" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 );    this.replytoPersonalField =      ComponentFactory.getTextField( ICEMail.getBundle(), "UserConfig.ReplyToPersonal", null );    this.replytoPersonalField.setText(        UserProperties.getProperty( Configuration.P_REPLYTO_PERSONAL, "" ) );    AWTUtilities.constrain( namePan, this.replytoPersonalField, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 );    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "UserConfig.Organization" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, subRow, 1, 1, 0.0, 0.0 );    this.organizationField =      ComponentFactory.getTextField( ICEMail.getBundle(), "UserConfig.Organization", null );    this.organizationField.setText(        UserProperties.getProperty( Configuration.P_ORGANIZATION, "" ) );    AWTUtilities.constrain( namePan, this.organizationField, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, subRow++, 1, 1, 1.0, 0.0 );    JPanel btnPan = new JPanel();    btnPan.setLayout( new GridBagLayout() );    btnPan.setBorder( JFCUtilities.StandardBorder );    AWTUtilities.constrain( cont, btnPan, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 0.0 );    JButton btn;    btn = ComponentFactory.getButton( ICEMail.getBundle(), "UserConfig.Save",                                      xlistener, null );    AWTUtilities.constrain( btnPan, btn, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, 0, 1, 1, 1.0, 0.0 );    btn = ComponentFactory.getButton( ICEMail.getBundle(), "UserConfig.Cancel",                                      xlistener, null );    AWTUtilities.constrain( btnPan, btn, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 1, 0, 1, 1, 1.0, 0.0 );  }//............................................................  private class IActionListener    implements ActionListener  {    /**     * Invoked when an action occurs.     * <p>     * Implementation of java.awt.event.ActionListener.actionPerformed()     *     * @param event the action event that occured     */    public void    actionPerformed( ActionEvent event ) {      boolean disposeIt = false;      String command = event.getActionCommand();      if ( command.equals( "SAVE" ) ) {        saveUserConfig();        disposeIt = true;      } else if ( command.equals( "CANCEL" ) ) {        disposeIt = true;      }      if ( disposeIt )        dispose();    }  }//............................................................  /**   * A internal class to handle the closing of window by the window manager,   * i.e. disposing of the window properly.   */  private class IWindowAdapter    extends WindowAdapter  {    public void    windowClosing( WindowEvent event ) {      event.getWindow().dispose();    }    public void    windowActivated( WindowEvent event ) {      if ( fromAddrField_ != null ) {        fromAddrField_.requestFocus();        fromAddrField_.selectAll();      }    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -