tempmanagerdialog.java

来自「一个用java写的mail.里面的代码值得我们去研究!学习。」· Java 代码 · 共 233 行

JAVA
233
字号
/*** $Id: TempManagerDialog.java,v 1.5 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 java.io.File;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;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 temporary file directory options to be configured. * The options are stored as part of the configuration properties. * * @see Configuration */public class TempManagerDialog  extends JDialog{  private JTextField pathField_;  /**   * Construct a dialog for configuring temporary file directory options.   *   * @param parent parent frame to return to after disposed   */  public  TempManagerDialog( Frame parent ) {    super( parent, true );    establishContents();    pack();    Dimension sz = getSize();    int w = UserProperties.getProperty( "tempManagerDialog.width", sz.width );    int h = UserProperties.getProperty( "tempManagerDialog.height", sz.height );    setSize( w, h );    setLocation( AWTUtilities.computeDialogLocation( this ) );    addWindowListener( new IWindowAdapter() );  }//............................................................  private boolean  savePath() {    String xdirectory = pathField_.getText();    if ( xdirectory != null && xdirectory.length() > 0 ) {      File    xfile = new File( xdirectory );      int     xoption = JOptionPane.YES_OPTION;      if ( ! xfile.exists() ) {        Object[] xargs = new Object[1];        xargs[0] = xdirectory;        xoption =            ComponentFactory.showDialog( ICEMail.getBundle(), "TempManager.CreateDir",                                         0, JOptionPane.INFORMATION_MESSAGE, xargs );        if ( xoption == JOptionPane.YES_OPTION ) {        // make the directory          xfile.mkdirs();        } else {        // xoption is set to something other than YES        }      }    // save the configured directory if necessary      if ( xoption == JOptionPane.YES_OPTION ) {        ICEMail.getTempFileManager().setDirectory( xdirectory );        Configuration.getInstance().setProperty( Configuration.P_TEMP_DIR, xdirectory );        Configuration.getInstance().saveProperties();        return true;      }    }    return false;  }  private void  establishContents() {    setTitle( ICEMail.getBundle().getString( "TempManager.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(), "TempManager.Directory" );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePan, lbl, GridBagConstraints.NONE,                            GridBagConstraints.WEST, 0, 0, 1, 1, 0.0, 0.0 );    pathField_ =      ComponentFactory.getTextField( ICEMail.getBundle(), "TempManager.Directory", null );    AWTUtilities.constrain( namePan, pathField_, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.WEST, 1, 0, 1, 1, 1.0, 0.0 );    String path = UserProperties.getProperty( Configuration.P_TEMP_DIR, null );    if ( path == null ) {      path = UserProperties.getProperty( Configuration.P_TEMP_DIR_GUESS, "" );    }    pathField_.setText( path );    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(), "TempManager.Save",                                      xlistener, null );    AWTUtilities.constrain( btnPan, btn, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, 0, 1, 1, 1.0, 0.0 );    btn = ComponentFactory.getButton( ICEMail.getBundle(), "TempManager.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 xdisposeIt = false;      String  xcommand = event.getActionCommand();      if ( xcommand.equals( "SAVE" ) ) {        xdisposeIt = savePath();      } else if ( xcommand.equals( "CANCEL" ) ) {        xdisposeIt = true;      }      if ( xdisposeIt )        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 ( pathField_ != null ) {        pathField_.requestFocus();        pathField_.selectAll();      }    }  }}

⌨️ 快捷键说明

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