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

📄 storeconfigdialog.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*** $Id: StoreConfigDialog.java,v 1.7 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.GridLayout;import java.awt.Frame;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.util.Vector;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.mail.Provider;import javax.mail.URLName;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JDialog; import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JScrollPane;import javax.swing.JTextField;import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; 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 stores (URLs) to be created, modified and deleted. * The options are stored as part of the configuration properties. And if the * list of stores changes, the tree of stores is re-loaded. * * @see Configuration * @see FolderTreePanel */public class StoreConfigDialog  extends JDialog{  private static final String[] NAMESPC_COMBO_DEFAULT = { "", "#mh/%", "%" };  private boolean        hasChanged_ = false;  private JList          storeList_;  private JTextField     nameField_;  private JTextField     hostField_;  private JTextField     userField_;  private JPasswordField passField_;  private JTextField     fileField_;  private JTextField     urlField_;  private JComboBox      nameSpaceCombo_;  private JComboBox      providerCombo_;  private Vector         providers_ = new Vector();  /**   * Construct a dialog for maintaining stores.   *   * @param parent parent frame to return to after disposed   */  public  StoreConfigDialog( Frame parent ) {    super( parent, true );        establishContents();    pack();    Dimension sz = getSize();    int w = UserProperties.getProperty( "storeConfigDialog.width", sz.width );    int h = UserProperties.getProperty( "storeConfigDialog.height", sz.height );    setSize( w, h );    setLocation( AWTUtilities.computeDialogLocation( this ) );  }//............................................................  private void  removeStore() {    String xstoreName = nameField_.getText();    if ( xstoreName.length() < 1 ) {      ComponentFactory.showDialog( ICEMail.getBundle(), "StoreConfig.DeleteError",                                   0, JOptionPane.WARNING_MESSAGE, null );    } else {      Vector xnamelist =        UserProperties.getStringVector( Configuration.P_STORE_LIST, new Vector() );      if ( xnamelist.contains( xstoreName ) ) {        xnamelist.removeElement( xstoreName );        Configuration.getInstance().setStringArray( Configuration.P_STORE_LIST, xnamelist );        Configuration.getInstance().removeProperty( Configuration.PP_STORE_URL + xstoreName );        Configuration.getInstance().removeProperty( Configuration.PP_STORE_NMSPC + xstoreName );        Configuration.getInstance().saveProperties();        storeList_.setListData( xnamelist );        storeList_.repaint( 100 );        clearFields();        hasChanged_ = true;      }    }  }  // NOTE that we have to store the *actual* password,  //      not the "hidden" one with asterisks.  private void  saveStore() {    String xstoreName = nameField_.getText();    String xurlStr = getStoreURL( false );    if ( xstoreName.length() < 1 || xurlStr.length() < 1 ) {      ComponentFactory.showDialog( ICEMail.getBundle(), "StoreConfig.SaveError",                                   0, JOptionPane.WARNING_MESSAGE, null );    } else {      Vector xnamelist = UserProperties.getStringVector( Configuration.P_STORE_LIST,                                                        new Vector() );      if ( ! xnamelist.contains( xstoreName ) ) {        xnamelist.addElement( xstoreName );        storeList_.setListData( xnamelist );        Configuration.getInstance().setStringArray( Configuration.P_STORE_LIST, xnamelist );      }      Configuration.getInstance().setProperty( Configuration.PP_STORE_URL + xstoreName,                                               xurlStr );      String xnamespace = (String)nameSpaceCombo_.getSelectedItem();      if ( xnamespace != null && xnamespace.length() > 0 ) {        Configuration.getInstance().setProperty( Configuration.PP_STORE_NMSPC + xstoreName,                                                 xnamespace );      } else {        Configuration.getInstance().removeProperty( Configuration.PP_STORE_NMSPC + xstoreName );      }      Configuration.getInstance().saveProperties();      hasChanged_ = true;      storeList_.setSelectedValue( xstoreName, true );      storeList_.repaint( 100 );    }  }  private void  clearFields() {    nameField_.setText( "" );    hostField_.setText( "" );    userField_.setText( "" );    passField_.setText( "" );    fileField_.setText( "" );    urlField_.setText( "" );    providerCombo_.setSelectedIndex( 0 );    nameSpaceCombo_.setSelectedItem( "" );    storeList_.getSelectionModel().clearSelection();    nameField_.requestFocus();    providerCombo_.repaint( 50 );    nameSpaceCombo_.repaint( 50 );  }  /**   *   * @param hidePassword true if the password is all asterisks   */  private String  getStoreURL( boolean hidePassword ) {    int      xindex = providerCombo_.getSelectedIndex();    Provider xprovider = (Provider)providers_.elementAt( xindex );    String   prov = (String)xprovider.getProtocol();    String   host = hostField_.getText();    String   user = userField_.getText();    char[] passCh = passField_.getPassword();    if ( hidePassword ) {      for ( int i = 0 ; i < passCh.length ; ++i ) {        passCh[i] = '*';      }    }    String pass = new String( passCh );    String file = fileField_.getText();    URLName url = new URLName( prov, host, -1, file, user, pass );    return url.toString();  }  private void  establishContents() {    setTitle( ICEMail.getBundle().getString( "StoreConfig.Title" ) );    Container cont = getContentPane();    cont.setLayout( new GridBagLayout() );    ActionListener xlistener = new IActionListener();    int row = 0;    JPanel listPan = new JPanel();    listPan.setLayout( new GridBagLayout() );    listPan.setBorder( new EmptyBorder( 4, 4, 4, 4 ) );    AWTUtilities.constrain( cont, listPan, GridBagConstraints.BOTH,                            GridBagConstraints.CENTER, 0, 0, 1, 2, 0.3, 1.0 );    String[] nameList = UserProperties.getStringArray( Configuration.P_STORE_LIST, null );    if ( nameList == null )      storeList_ = new JList();

⌨️ 快捷键说明

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