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

📄 transportdialog.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
字号:
/*** $Id: TransportDialog.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.util.Vector;import javax.mail.Provider;import javax.mail.Session;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;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 transport protocol to be configured. * The options are stored as part of the configuration properties. * * @see Configuration */public class TransportDialog  extends JDialog{  private JTextField protocolField;  private JList      transportList;  /**   * Construct a dialog for configuring transport protocol options.   *   * @param parent parent frame to return to after disposed   */  public  TransportDialog( Frame parent ) {    super( parent, true );    establishContents();    pack();    int w = UserProperties.getProperty( "transProtoDialog.width", 450 );    int h = UserProperties.getProperty( "transProtoDialog.height", 400 );    setSize( w, h );    setLocation( AWTUtilities.computeDialogLocation( this ) );  }//............................................................  private void  saveProtocol() {    String xprotocol = this.protocolField.getText();    if ( xprotocol != null && xprotocol.length() > 0 ) {      Configuration.getInstance().setProperty( Configuration.P_TRANSPORT_PROTO, xprotocol );      Configuration.getInstance().saveProperties();    }  }  private void  establishContents() {    setTitle( ICEMail.getBundle().getString( "Transport.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.CENTER, 0, row++, 2, 1, 1.0, 0.0 );    JLabel  lbl;    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Transport.Protocol" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, 0, 1, 1, 0.0, 0.0 );    this.protocolField =        ComponentFactory.getTextField( ICEMail.getBundle(), "Transport.Protocol", null );    this.protocolField.setText(        UserProperties.getProperty( Configuration.P_TRANSPORT_PROTO, "" ) );    AWTUtilities.constrain( namePan, this.protocolField, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, 0, 1, 1, 1.0, 0.0 );    int listRow = 0;    JPanel listPan = new JPanel();    listPan.setLayout( new GridBagLayout() );    listPan.setBorder( JFCUtilities.StandardBorder );    AWTUtilities.constrain( cont, listPan, GridBagConstraints.BOTH,                            GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 1.0 );    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "Transport.Available" );    lbl.setBorder( new EmptyBorder( 1, 3, 1, 1 ) );    lbl.setHorizontalAlignment( JLabel.LEFT );    AWTUtilities.constrain( listPan, lbl, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 0, listRow++, 1, 1, 1.0, 0.0 );    Vector transports = new Vector();    Session session = ICEMail.getDefaultSession();    Provider[] providers = session.getProviders();    for ( int i = 0 ; i < providers.length ; ++i ) {      if ( providers[i].getType() == Provider.Type.TRANSPORT ) {        transports.addElement( providers[i].getProtocol() );      }    }    this.transportList = new JList( transports );    this.transportList.setBorder( new EmptyBorder( 2, 2, 2, 2 ) );    this.transportList.addListSelectionListener( new IListSelectionListener() );    AWTUtilities.constrain( listPan, this.transportList, GridBagConstraints.BOTH,                            GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 1.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(), "Transport.Save",                                      xlistener, null );    AWTUtilities.constrain( btnPan, btn, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, 0, 1, 1, 1.0, 0.0 );    btn = ComponentFactory.getButton( ICEMail.getBundle(), "Transport.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" ) ) {        saveProtocol();        disposeIt = true;      } else if ( command.equals( "CANCEL" ) ) {        disposeIt = true;      }      if ( disposeIt )        dispose();    }  }//............................................................  private class IListSelectionListener    implements ListSelectionListener  {    public void    valueChanged( ListSelectionEvent event ) {      if ( ! event.getValueIsAdjusting() ) {        String transportName = (String)transportList.getSelectedValue();        if ( transportName != null ) {          protocolField.setText( transportName );        }      }    }  }}

⌨️ 快捷键说明

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