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

📄 viewasdialog.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
字号:
/*** $Id: ViewAsDialog.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.GridLayout;import java.awt.Font;import java.awt.Frame;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.util.Enumeration;import java.util.Vector;import javax.activation.CommandInfo;import javax.activation.CommandMap;import javax.mail.Part;import javax.mail.MessagingException;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.border.EmptyBorder;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;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 to select an alternative MIME type for * viewing attachments. * * @see QuickViewer */public class ViewAsDialog  extends JDialog{  private JTextField typeField_;  private String     contentType_ = null;  /**   * Construct a dialog for selecting an alternative MIME type for the given part.   *   * @param parent parent frame to return to after disposed   * @param part   the part to be viewed   */  public  ViewAsDialog( Frame parent, Part part ) {    super( parent, true );    establishDialogContents( part );    pack();    Dimension sz = getPreferredSize();    sz.width = UserProperties.getProperty( "viewAsDialog.width", sz.width );    sz.height = UserProperties.getProperty( "viewAsDialog.height", sz.height );    setSize( sz );    Point location = AWTUtilities.computeDialogLocation( this, sz.width, sz.height );    setLocation( location );    invalidate();    validate();  }  public String  getViewAsType() {    return contentType_;  }//............................................................  private Vector  getContentTypes() {    Vector result = UserProperties.getStringVector( "viewAsTypeList", new Vector() );    Enumeration xenum = Configuration.getInstance().getMailcapTypes();    while ( xenum.hasMoreElements() ) {      String xtype = (String)xenum.nextElement();      if ( ! result.contains( xtype ) ) {        result.addElement( xtype );      }    }    return result;  }  private boolean  validateType() {    contentType_ = typeField_.getText();    CommandInfo ci =      CommandMap.getDefaultCommandMap().getCommand( contentType_, "view" );    if ( ci == null ) {      Object[] xargs = new Object[1];      xargs[0] = contentType_;      ComponentFactory.showDialog( ICEMail.getBundle(), "ViewAs.NoViewer",                                   0, JOptionPane.ERROR_MESSAGE, xargs );      return false;    }    return true;  }  private void  establishDialogContents( Part part ) {    setTitle( ICEMail.getBundle().getString( "ViewAs.Title" ) );    Container content = getContentPane();    ActionListener xlistener = new IActionListener();    JTextArea  propsText = new JTextArea();    propsText.setEditable( false );    propsText.setBorder( JFCUtilities.StandardBorder );    propsText.setFont( UserProperties.getFont( "viewAsDialog.properties.font",                                               new Font( "Dialog", Font.BOLD, 12 ) ) );    StringBuffer propBuf = new StringBuffer( 1024 );    propBuf.append( ICEMail.getBundle().getString( "ViewAs.PartProperties" ) );    try {      propBuf.append( "\n  Filename: " );      propBuf.append( MessageUtilities.getFileName( part ) );      propBuf.append( "\n  Content-Type: " );      propBuf.append( MessageUtilities.getContentType( part ).toString() );      propBuf.append( "\n  Size: " );      propBuf.append( part.getSize() );      propBuf.append( "\n  Description: " );      propBuf.append( part.getDescription() );      propBuf.append( "\n  Disposition: " );      propBuf.append( part.getDisposition() );    } catch ( MessagingException ex ) {      propBuf.append( "\n  *** Exception: " );      propBuf.append( ex.getMessage() );    }    propsText.setText( propBuf.toString() );    JScrollPane scroller = new JScrollPane();    scroller.getViewport().add( propsText );    scroller.setMinimumSize( new Dimension( 75, 50 ) );    JPanel namePanel = new JPanel();    namePanel.setLayout( new GridBagLayout() );    namePanel.setBorder( JFCUtilities.StandardBorder );    JLabel lbl;    lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "ViewAs" );    lbl.setBorder( new EmptyBorder( 2, 2, 2, 4 ) );    lbl.setHorizontalAlignment( JLabel.RIGHT );    AWTUtilities.constrain( namePanel, lbl, GridBagConstraints.NONE,                            GridBagConstraints.CENTER, 0, 0, 1, 1, 0.0, 0.0 );    typeField_ =      ComponentFactory.getTextField( ICEMail.getBundle(), "ViewAs", null );    AWTUtilities.constrain( namePanel, typeField_, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 1, 0, 1, 1, 1.0, 0.0 );    Vector contentTypes = getContentTypes();    JList  typeList = new JList( contentTypes );    typeList.addListSelectionListener( new IListSelectionListener() );    typeList.addMouseListener( new IMouseAdapter() );    JScrollPane listScroller = new JScrollPane();    listScroller.getViewport().add( typeList );    listScroller.setMinimumSize( new Dimension( 75, 50 ) );    JPanel btnPan = new JPanel();    btnPan.setBorder( JFCUtilities.StandardBorder );    btnPan.setLayout( new GridLayout( 1, 1, 20, 20 ) );    JButton     btn;    btn = ComponentFactory.getButton( ICEMail.getBundle(), "ViewAs.View",                                      xlistener, null );    btnPan.add( btn );    btn = ComponentFactory.getButton( ICEMail.getBundle(), "ViewAs.Cancel",                                      xlistener, null );    btnPan.add( btn );    content.setLayout( new GridBagLayout() );    int row = 0;    AWTUtilities.constrain( content, scroller, GridBagConstraints.BOTH,                            GridBagConstraints.CENTER, 0, row++, 1, 1, 1.0, 0.4 );    AWTUtilities.constrain( content, listScroller, GridBagConstraints.BOTH,                            GridBagConstraints.CENTER, 0, row++, 1, 1, 1.0, 0.6 );    AWTUtilities.constrain( content, namePanel, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, row++, 1, 1, 1.0, 0.0 );    AWTUtilities.constrain( content, btnPan, GridBagConstraints.HORIZONTAL,                            GridBagConstraints.CENTER, 0, row++, 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 ) {      String command = event.getActionCommand();      if ( command.equals( "VIEW" ) ) {        if ( validateType() ) {          dispose();        }      } else if ( command.equals( "CANCEL" ) ) {        contentType_ = null;        dispose();      }    }  }//............................................................  private class IListSelectionListener    implements ListSelectionListener  {    public void    valueChanged( ListSelectionEvent event ) {      if ( ! event.getValueIsAdjusting() ) {        JList xlist = (JList)event.getSource();        typeField_.setText( (String) xlist.getSelectedValue() );      }    }  }//............................................................  private class IMouseAdapter    extends MouseAdapter  {    public void    mouseClicked( MouseEvent event ) {      if( event.getClickCount() == 2 && validateType() ) {        dispose();      }    }  }}

⌨️ 快捷键说明

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