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

📄 mainframe.java

📁 一个用java写的mail.里面的代码值得我们去研究!学习。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*** $Id: MainFrame.java,v 1.11 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.Component;import java.awt.Container;import java.awt.Cursor;import java.awt.Dimension;import java.awt.FileDialog;import java.awt.Rectangle;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 java.net.URL;import java.util.Hashtable;import javax.help.CSH;import javax.help.HelpBroker;import javax.help.HelpSet;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.SwingUtilities;import javax.swing.UIManager;import javax.swing.UnsupportedLookAndFeelException;import org.icemail.Package;import org.icemail.smime.SMIMELibrary;import org.icemail.util.ComponentFactory;import org.icemail.util.UserProperties;/** * Class MainFrame */public class MainFrame  extends JFrame{  private static final int Debug_ = Package.DEBUG ? Package.getLevel( "MainFrame" ) : 0;  private static final String NEWMAIL_PREFIX = "@";  private static MainFrame  Instance_;  private MainPanel         mainPanel_;    private Cursor            saveCursor = null;  private Hashtable         saveCursors = new Hashtable();  /**   * Default constructor, private to disable multiple instantiations.   */  private  MainFrame() {    super();    setTitle( ICEMail.getBundle().getString( "MainFrame.Title" ) );    mainPanel_ = new MainPanel();        getContentPane().add( mainPanel_ );    establishMenuBar();    addWindowListener( new IWindowAdapter() );    pack();    loadLayoutProperties();  }  /**   * Get the SINGLE instance of the frame, creating it if necessary.   *   * @return the SINGLE instance of the frame   */  public static synchronized MainFrame  getInstance() {    if ( MainFrame.Instance_ == null ) {      MainFrame.Instance_ = new MainFrame();    }    return MainFrame.Instance_;  }//............................................................  public void  loadLayoutProperties() {    Dimension sz = getSize();    Rectangle bounds = Configuration.getBounds( Configuration.P_MAIN_WINDOW,                                                new Rectangle( 20, 20, sz.width, sz.height ) );    setBounds( bounds );    mainPanel_.loadLayoutProperties();  }  public void  saveLayoutProperties() {    Configuration.saveBounds( Configuration.P_MAIN_WINDOW, getBounds() );    mainPanel_.saveLayoutProperties();  }//............................................................  private void  changeLookAndFeel( String classname ) {    if ( Package.DEBUG && Package.isTraceable( "MainFrame" ) ) {      System.out.println( "MainFrame.changeLookAndFeel(s): " + classname );    }    String plafName;    int index = classname.lastIndexOf( classname );    if ( index < 0 ) {      plafName = classname;    } else {      plafName = classname.substring( index + 1 );    }    try {      UIManager.setLookAndFeel( classname );      SwingUtilities.updateComponentTreeUI( getRootPane() );    } catch ( IllegalAccessException ex ) {      lookAndFeelExMessage( plafName, classname, ex.getMessage(),                                 "could not be accessed" );    } catch ( InstantiationException ex ) {      lookAndFeelExMessage( plafName, classname, ex.getMessage(),                                 "could not be instantiated" );    } catch ( ClassNotFoundException ex ) {      lookAndFeelExMessage( plafName, classname, ex.getMessage(),                                 "could not be located" );    } catch ( UnsupportedLookAndFeelException ex ) {      lookAndFeelExMessage( plafName, classname, ex.getMessage(),                                 "is not supported on this platform" );    }  }  private void  lookAndFeelExMessage( String name, String className, String exMsg, String msg ) {    System.err.println( "Look and feel '" + name + "' " + msg + "." );        if ( exMsg.length() > 0 )      System.err.println( "\t" + exMsg );  }//............................................................  public void  toggleTitleHilite( boolean on ) {    String title = getTitle();    if ( on ) {      if ( ! title.startsWith( NEWMAIL_PREFIX ) ) {        setTitle( NEWMAIL_PREFIX + title );      }    } else {      if ( title.startsWith( NEWMAIL_PREFIX ) ) {        setTitle( title.substring( 1 ) );      }    }  }  private void  establishMenuBar() {    if ( Package.DEBUG && Package.isTraceable( "MainFrame" ) ) {      System.out.println( "MainFrame.establishMenuBar()" );    }    JMenuBar xmenubar = new JMenuBar();    JMenu    xmenu;    // file menu    xmenu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "MainFrame.File",                                              new FileMenuActionListener() );    xmenubar.add( xmenu );    // edit menu    xmenu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "MainFrame.Edit",                                              new EditMenuActionListener() );    xmenubar.add( xmenu );    // mail menu    addMailMenu( xmenubar );    // configuration menu    addConfigureMenu( xmenubar );    // help menu    addHelpMenu( xmenubar );    // look and feel menu    boolean showUI = UserProperties.getProperty( "displayUIMenu", false );        if ( showUI ) {      addLookAndFeelMenu( xmenubar );    }    setJMenuBar( xmenubar );  }  private void  addMailMenu( JMenuBar mbar ) {    JMenu menu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "MainFrame.Mail",                                                   new MailMenuActionListener() );    if ( ICEMail.getSMIMELibrary() == null ) {      int xitems = menu.getItemCount();      JMenuItem xitem;      for ( int xindex = 0; xindex < xitems; xindex++ ) {        xitem = menu.getItem( xindex );        if ( xitem != null && xitem.getActionCommand().equals( "TOGGLESMIME" ) ) {          xitem.setEnabled( false );        }      }    }    mbar.add( menu );  }  private void  addConfigureMenu( JMenuBar mbar ) {    JMenu menu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "MainFrame.Config",                                                   new ConfigureMenuActionListener() );    if ( ICEMail.getSMIMELibrary() == null ) {      int xitems = menu.getItemCount();      JMenuItem xitem;      for ( int xindex = 0; xindex < xitems; xindex++ ) {        xitem = menu.getItem( xindex );        if ( xitem != null && xitem.getActionCommand().equals( "SECURITY" ) ) {          xitem.setEnabled( false );        }      }    }    mbar.add( menu );  }  private void  addHelpMenu( JMenuBar menubar ) {    HelpMenuActionListener xlistener = new HelpMenuActionListener();    JMenu xmenu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "MainFrame.Help",                                                    xlistener );  // setup online help    String     xurlstring = "org/icemail/mail/doc/help/help.hs";    HelpBroker xhelpbroker = null;    try {      Class xclass = Class.forName( "javax.help.HelpSet" );      ClassLoader xloader = MainFrame.class.getClassLoader();      URL xurl = HelpSet.findHelpSet( xloader, xurlstring );      if ( xurl == null ) {        String xstring = ICEMail.getBundle().getString( "Exception.missingHelpURL" );        throw new Exception( xstring );      }      HelpSet xhelpset = new HelpSet( xloader, xurl );      xhelpbroker = xhelpset.createHelpBroker();    } catch ( Exception ex ) {      Object[] xargs = new Object[2];      xargs[0] = xurlstring;      xargs[1] = ex.toString();      ComponentFactory.showDialog( ICEMail.getBundle(), "MainFrame.HelpError",                                   0, JOptionPane.WARNING_MESSAGE, xargs );    }      int xitems = xmenu.getItemCount();    JMenuItem xitem;    for ( int xindex = 0; xindex < xitems; xindex++ ) {      xitem = xmenu.getItem( xindex );      if ( xitem != null && xitem.getActionCommand().equals( "JAVAHELP" ) ) {        if ( xhelpbroker == null )          xitem.setEnabled( false );        else          xitem.addActionListener( new CSH.DisplayHelpFromSource( xhelpbroker ) );      }    }    menubar.add( xmenu );  }  private void  addLookAndFeelMenu( JMenuBar mbar ) {    if ( Package.DEBUG && Package.isTraceable( "MainFrame" ) ) {

⌨️ 快捷键说明

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