componentframe.java

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

JAVA
153
字号
/*** $Id: ComponentFrame.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.BorderLayout;import java.awt.Component;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.activation.DataSource;import javax.activation.MimeType;import javax.activation.MimeTypeParseException;import javax.swing.JFrame;/** * This class provides a frame for all viewers. * <p> * Viewers for data sources (attachements) are instantiated via Java activation * based on the mimetypes in "icemailcap". The instantiated viewer (component) * is then placed placed within a frame and displayed. * * @see QuickViewer */public class ComponentFrame  extends JFrame{  private String    contentType_;  /**   * Construct a frame to display the given component, setting the title to the given name.   * The source is used to save the layout of the window by type, i.e. type of source.   * @param component the component to display   * @param name the name of the Frame   * @param source the data source of the component   */  public  ComponentFrame( Component component, String name, DataSource source ) {    super( name );    try {      MimeType mime = new MimeType( source.getContentType() );      contentType_ = mime.getBaseType();    } catch ( MimeTypeParseException ex ) {      contentType_ = source.getContentType();    }    addWindowListener( new IWindowAdapter() );    getContentPane().setLayout( new BorderLayout( 1, 1 ) );    if ( component != null ) {      getContentPane().add( component, BorderLayout.CENTER );    }    pack();    loadLayoutProperties();  }  /**   * Load the layout properties for this frame using the content type of the viewer.   */  private void  loadLayoutProperties() {    Rectangle defBounds = Configuration.getBounds( Configuration.P_ATTACH_WINDOW,                                                   computeDefaultPosition() );    Rectangle bounds = Configuration.getBounds( Configuration.PP_ATTACH_WINDOW +                                                  contentType_.replace( '/', '.'),                                                defBounds );    setBounds( bounds );  }  /**   * Save the layout properties for this frame using the content type of the viewer.   */  private void  saveLayoutProperties() {    Configuration.saveBounds( Configuration.PP_ATTACH_WINDOW + contentType_.replace( '/', '.'),                              getBounds() );  }  /**   * Compute a default position for the frame.   *   * @return the computed retangle of the frame   */  private Rectangle  computeDefaultPosition() {    Dimension sz = getSize();    Dimension scrnSz = getToolkit().getScreenSize();    if ( sz.width > (scrnSz.width - 10) ) sz.width = scrnSz.width - 10;    if ( sz.height > (scrnSz.height - 10) ) sz.height = scrnSz.height - 10;    int x = (scrnSz.width - sz.width) / 2;    int y = (scrnSz.height - sz.height) / 3;  // Make sure we are not off the screen.    if ( x < 0 ) x = 0;    if ( y < 0 ) y = 0;  // Make sure we are not bigger than the screen.    if ( x + sz.width > scrnSz.width ) sz.width = scrnSz.width - x;    if ( y + sz.height > scrnSz.height ) sz.height = scrnSz.height - y;    return new Rectangle( x, y, sz.width, sz.height );  }//............................................................  /**   * A internal class to handle the closing of window by the window manager,   * disposing of the window properly.   */  private class IWindowAdapter    extends WindowAdapter  {    public void    windowClosing( WindowEvent event ) {      saveLayoutProperties();      event.getWindow().dispose();    }  }}

⌨️ 快捷键说明

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