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

📄 extraheadersdialog.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
字号:
/*** $Id: ExtraHeadersDialog.java,v 1.4 2001/05/07 12:37:21 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.Frame;import java.awt.Dimension;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Container;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Vector;import java.util.Enumeration;import java.io.File;import javax.mail.Header;import javax.mail.internet.InternetHeaders;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JPanel;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JSeparator;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;/** * This class represents a dialog to change, add or delete * extra (non-standard) MIME headers. * * @see ComposeFrame */public class ExtraHeadersDialog  extends JDialog{  public static final int  NUM_HEADERS = 5;  private JCheckBox     approvedCheckBox_;  private JTextField    approvedTextField_;  private JTextField[]  hdrName_ = new JTextField[ NUM_HEADERS ];  private JTextField[]  hdrValue_ = new JTextField[ NUM_HEADERS ];  private Vector        names_ = new Vector();  private Vector        values_ = new Vector();  private String        approvedStr_ = null;  /**   * Constract a dialog, initializing the contents from the given headers.   *   * @param frame parent frame to return focus after disposal   * @param headers initial header contents   */  public  ExtraHeadersDialog( Frame frame, InternetHeaders headers ) {    super( frame, true );    establishContents( headers );    pack();    Dimension sz = getSize();    int w = UserProperties.getProperty( "extraHeaderDialog.width", sz.width );    int h = UserProperties.getProperty( "extraHeaderDialog.height", sz.height );    setSize( w, h );    setLocation( AWTUtilities.computeDialogLocation( this ) );  }  /**   * Get the contents of the dialog as a set of InternetHeaders.   * <p>   * The returned headers will have the orginal contents of those provided,   * plus any modifications, additions, or deletions when 'saved'. The   * return headers may be empty if all headers have been deleted.   *   * @return the dialog contents converted to a set of InternetHeaders   */  public InternetHeaders  getInternetHeaders() {    InternetHeaders xheaders = new InternetHeaders();    if ( approvedStr_ != null ) {      xheaders.addHeader( "Approved", approvedStr_ );    }    for ( int i = 0 ; i < names_.size() ; ++i ) {      xheaders.addHeader( (String)names_.elementAt( i ), (String)values_.elementAt( i ) );    }    return xheaders;  }//............................................................  private void  establishContents( InternetHeaders headers ) {    setTitle( ICEMail.getBundle().getString( "ExtraHeaders.Title" ) );    Container cont = getContentPane();    cont.setLayout( new GridBagLayout() );    ActionListener xlistener = new IActionListener();    int row = 0;    int cols = 3;    int subrow = 0;    JPanel aPan = new JPanel();    aPan.setLayout( new GridBagLayout() );    aPan.setBorder( new EmptyBorder( 4, 4, 4, 4 ) );    AWTUtilities.constrain( cont, aPan, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, row++, 1, 1, 1.0, 0.0 );    approvedCheckBox_ =      ComponentFactory.getCheckBox( ICEMail.getBundle(), "ExtraHeaders.Approved", false );    AWTUtilities.constrain( aPan, approvedCheckBox_, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.EAST, 0, subrow, 1, 1, 0.3, 0.0 );    approvedTextField_ =      ComponentFactory.getTextField( ICEMail.getBundle(), "ExtraHeaders.Approved", null );    AWTUtilities.constrain( aPan, approvedTextField_, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, subrow++, 1, 1, 0.7, 0.0 );    JSeparator sep = new JSeparator( JSeparator.HORIZONTAL );    AWTUtilities.constrain( aPan, sep, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, subrow++, 2, 1, 1.0, 0.0,                            new Insets( 4, 1, 5, 1 ) );    hdrName_ = new JTextField[ NUM_HEADERS ];    hdrValue_ = new JTextField[ NUM_HEADERS ];    for ( int i = 0 ; i < NUM_HEADERS ; ++i ) {      hdrName_[i] = new JTextField();      AWTUtilities.constrain( aPan, hdrName_[i], GridBagConstraints.HORIZONTAL,                              GridBagConstraints.WEST, 0, subrow, 1, 1, 0.3, 0.0 );      hdrValue_[i] = new JTextField();      AWTUtilities.constrain( aPan, hdrValue_[i], GridBagConstraints.HORIZONTAL,                              GridBagConstraints.WEST, 1, subrow++, 1, 1, 0.7, 0.0 );    }    JPanel btnPan = new JPanel();    btnPan.setLayout( new GridBagLayout() );    btnPan.setBorder( JFCUtilities.StandardBorder );    AWTUtilities.constrain( cont, btnPan, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, row++, 1, 1, 1.0, 0.0 );    JButton btn;    btn = ComponentFactory.getButton( ICEMail.getBundle(), "ExtraHeaders.Save", xlistener, null );    AWTUtilities.constrain( btnPan, btn, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, 0, 1, 1, 1.0, 0.0 );    btn = ComponentFactory.getButton( ICEMail.getBundle(), "ExtraHeaders.Cancel", xlistener, null );    AWTUtilities.constrain( btnPan, btn, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 1, 0, 1, 1, 1.0, 0.0 );    if ( headers != null ) {      int hRow = 0;      Enumeration enum = headers.getAllHeaders();      for ( ; enum.hasMoreElements() ; ) {        Header hdr = (Header) enum.nextElement();        String hdrName = hdr.getName();        String hdrValue = hdr.getValue();        if ( hdrName.equalsIgnoreCase( "Approved" ) ) {          approvedCheckBox_.setSelected( true );          approvedTextField_.setText( hdrValue );        } else {          hdrName_[hRow].setText( hdrName );          hdrValue_[hRow].setText( hdrValue );          ++hRow;        }      }    }  }//............................................................  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 ) {      String command = event.getActionCommand();      if ( command.equals( "SAVE" ) ) {        if ( approvedCheckBox_.isSelected() ) {          approvedStr_ = approvedTextField_.getText();        }        for ( int i = 0 ; i < NUM_HEADERS ; ++i ) {          String name = hdrName_[i].getText();          if ( name.length() > 0 ) {            names_.addElement( name );            values_.addElement( hdrValue_[i].getText() );          }        }      } else if ( command.equals( "CANCEL" ) ) {        approvedStr_ = null;      }      dispose();    }  }}

⌨️ 快捷键说明

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