📄 hotjavamailbrowser.java
字号:
/*** $Id: HotJavaMailBrowser.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.Component;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;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.lang.reflect.InvocationTargetException;import java.lang.reflect.Method;import java.io.Reader;import java.net.URL;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JLabel;import javax.swing.JMenuBar;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.JTextField;import javax.swing.SwingUtilities;import javax.swing.border.EmptyBorder;import sunw.hotjava.bean.AuthenticatorBean;import sunw.hotjava.bean.BrowserHistoryEvent;import sunw.hotjava.bean.BrowserHistoryListener;import sunw.hotjava.bean.HotJavaBrowserBean;import sunw.hotjava.bean.HotJavaDocumentStack;import sunw.hotjava.doc.ElementInfo;import org.icemail.util.AWTUtilities;import org.icemail.util.ComponentFactory;import org.icemail.util.UserProperties;/** * This is a wrapper for the HotJavaBrowserBean provided by Sun. * <p> * This class maintains a single instance of the bean, allowing a document * to be set (and shown) by any requesting class, i.e. help, attachments, etc. */public class HotJavaMailBrowser extends JFrame{ private static HotJavaMailBrowser Instance_ = null; private HotJavaBrowserBean hotJavaBrowserBean_ = null; private HotJavaDocumentStack hotJavaDocumentStack_ = null; private JMenuBar menuBar = null; private JPanel toolBar = null; private JTextField statusText = null; private JProgressBar progressBar = null; private JComboBox stackCombo = null; private JTextField addressText_ = null; private String currentDocName; private ActionListener actionListener_ = new IActionListener(); /** * Default constructor, private to disable multiple instantiations. */ private HotJavaMailBrowser() throws Exception { super(); instantiateBeans(); establishContents(); pack(); show(); } /** * Get the SINGLE instance of the browser, creating it if necessary. * * @return the SINGLE instance of the browser */ public static synchronized HotJavaMailBrowser getInstance() { // try to instantiate the browser if ( HotJavaMailBrowser.Instance_ == null ) { try { HotJavaMailBrowser.Instance_ = new HotJavaMailBrowser(); } catch ( Exception xex ) { HotJavaMailBrowser.Instance_ = null; } } return HotJavaMailBrowser.Instance_; } /** * Save the current layout of the browser. */ public static void saveLayoutProperties() { if ( HotJavaMailBrowser.Instance_ == null ) return; Rectangle bounds = HotJavaMailBrowser.Instance_.getBounds(); Configuration.saveBounds( Configuration.P_HOTJAVA_BROWSER, bounds ); } /** * Set and show the document from the given reader's contents. * * @param documentName the name of the document to read * @param source a reader of the document's contents */ public static void setBrowserDocumentSource( String documentName, Reader source ) { if ( HotJavaMailBrowser.getInstance() == null ) return; HotJavaMailBrowser.Instance_.showDocument( documentName, source ); } /** * Set and show the document specified by the given string. * * @param url a string containing the URL address of the document */ public static void setBrowserDocumentString( String url ) { if ( HotJavaMailBrowser.getInstance() == null ) return; HotJavaMailBrowser.Instance_.showDocument( url ); } /** * Set and show the document specified by the given URL. * * @param url the URL address of the document */ public static void setBrowserDocumentURL( URL url ) { if ( HotJavaMailBrowser.getInstance() == null ) return; HotJavaMailBrowser.Instance_.showDocument( url ); }//............................................................ private void showDocument( String documentName, Reader source ) { this.statusText.setText( "Loading '" + documentName + "'..." ); hotJavaBrowserBean_.setDocumentSource( source ); this.currentDocName = documentName; this.statusText.setText( this.currentDocName ); setVisible( true ); toFront(); } private void showDocument( URL url ) { this.statusText.setText( "Loading '" + url.toString() + "'..." ); hotJavaBrowserBean_.setDocumentURL( url ); this.currentDocName = url.toString(); this.statusText.setText( this.currentDocName ); setVisible( true ); toFront(); } private void showDocument( String urlString ) { this.statusText.setText( "Loading '" + urlString + "'..." ); hotJavaBrowserBean_.setDocumentString( urlString ); this.currentDocName = urlString; this.statusText.setText( this.currentDocName ); setVisible( true ); toFront(); } private void nextDocument() { hotJavaDocumentStack_.nextDocument(); } private void previousDocument() { hotJavaDocumentStack_.previousDocument(); } private void stopLoading() { hotJavaBrowserBean_.stopLoading(); } private void reload() { if ( hotJavaBrowserBean_.isDocumentReloadable() ) { hotJavaBrowserBean_.reload(); } } private void instantiateBeans() throws Exception { if ( hotJavaBrowserBean_ == null ) { hotJavaBrowserBean_ = new HotJavaBrowserBean(); } if ( hotJavaDocumentStack_ == null ) { hotJavaDocumentStack_ = new HotJavaDocumentStack(); } hotJavaDocumentStack_.addBrowserHistoryListener( hotJavaBrowserBean_ ); hotJavaBrowserBean_.addBrowserHistoryListener( hotJavaDocumentStack_ ); hotJavaBrowserBean_.addBrowserHistoryListener( new IHistoryListener() ); hotJavaBrowserBean_.addPropertyChangeListener( new IPropertyChangeListener() ); } private void establishContents() { setTitle( ICEMail.getBundle().getString( "HotJavaBrowser.Title" ) ); establishMenuBar(); Container content = getContentPane(); ((JPanel) content).setDoubleBuffered( true ); content.setLayout( new GridBagLayout() ); int row = 0; this.toolBar = new JPanel(); this.toolBar.setLayout( new GridBagLayout() ); AWTUtilities.constrain( content, this.toolBar, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 0, row++, 2, 1, 1.0, 0.0 ); establishToolbar( this.toolBar ); /* PrintWriter w = new PrintWriter( System.err ); org.icemail.util.DebugUtilities.printClassHierarchy( hotJavaBrowserBean_.getClass(), w, "HJB" ); org.icemail.util.DebugUtilities.printContainerComponents( hotJavaBrowserBean_, w, "HJB", true ); w.flush(); */ AWTUtilities.constrain( content, (Component)hotJavaBrowserBean_, GridBagConstraints.BOTH, GridBagConstraints.CENTER, 0, row++, 2, 1, 1.0, 1.0 ); this.statusText = new JTextField(); this.statusText.setEditable( false ); AWTUtilities.constrain( content, this.statusText, GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTH, 0, row, 2, 1, 1.0, 0.0 ); /* this.progressBar = new JProgressBar(); this.progressBar.setMinimum(0); this.progressBar.setMaximum(0); this.progressBar.setValue(0); this.statusText.setEditable( false ); AWTUtilities.constrain( content, this.progressBar, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, 1, row++, 1, 1, 0.1, 0.0 ); */ addWindowListener( new IWindowListener() ); Dimension sz = getSize(); Rectangle bounds = Configuration.getBounds( Configuration.P_HOTJAVA_BROWSER, new Rectangle( 20, 20, sz.width, sz.height ) ); setBounds( bounds ); } private void establishToolbar( JPanel toolBar ) { int col = 0; int row = 0; JButton btn; btn = ComponentFactory.getButton( ICEMail.getBundle(), "HotJavaBrowser.Stop", actionListener_, null ); AWTUtilities.constrain( toolBar, btn, GridBagConstraints.NONE, GridBagConstraints.CENTER, col++, row, 1, 1, 0.0, 0.0 ); btn = ComponentFactory.getButton( ICEMail.getBundle(), "HotJavaBrowser.Reload", actionListener_, null ); AWTUtilities.constrain( toolBar, btn, GridBagConstraints.NONE, GridBagConstraints.CENTER, col++, row, 1, 1, 0.0, 0.0 ); btn = ComponentFactory.getButton( ICEMail.getBundle(), "HotJavaBrowser.Previous", actionListener_, null ); AWTUtilities.constrain( toolBar, btn, GridBagConstraints.NONE, GridBagConstraints.CENTER, col++, row, 1, 1, 0.0, 0.0 ); btn = ComponentFactory.getButton( ICEMail.getBundle(), "HotJavaBrowser.Next", actionListener_, null ); AWTUtilities.constrain( toolBar, btn, GridBagConstraints.NONE, GridBagConstraints.CENTER, col++, row, 1, 1, 0.0, 0.0 ); JLabel lbl = ComponentFactory.getLabel( ICEMail.getBundle(), "HotJavaBrowser.Address" ); lbl.setBorder( new EmptyBorder( 0, 12, 0, 3 ) ); AWTUtilities.constrain( toolBar, lbl, GridBagConstraints.NONE, GridBagConstraints.CENTER, col++, row, 1, 1, 0.0, 0.0 ); addressText_ = ComponentFactory.getTextField( ICEMail.getBundle(), "HotJavaBrowser.Address", null ); addressText_.setEditable( true ); addressText_.addActionListener( actionListener_ ); AWTUtilities.constrain( toolBar, addressText_, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER, col, row, 1, 1, 1.0, 0.0 ); AuthenticatorBean authBean = new AuthenticatorBean(); authBean.setSize( new Dimension( 1, 1 ) ); AWTUtilities.constrain( toolBar, authBean, GridBagConstraints.NONE, GridBagConstraints.EAST, col++, row, 1, 1, 0.0, 0.0 ); } private void establishMenuBar() { this.menuBar = new JMenuBar(); JMenu menu = ComponentFactory.getMenuAndItems( ICEMail.getBundle(), "HotJavaBrowser.File", actionListener_ ) ; this.menuBar.add( menu ); setJMenuBar( this.menuBar ); }//............................................................// INNER CLASSES 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 ( event.getSource() == addressText_ ) { showDocument( addressText_.getText() ); } else if ( command.equals( "HIDE" ) ) { SwingUtilities.invokeLater( new Runnable() { public void run() { setVisible( false ); } } ); } else if ( command.equals( "SHOW" ) ) { setVisible( true ); } else if ( command.equals( "NEXTHTML" ) ) { nextDocument(); } else if ( command.equals( "PREVHTML" ) ) { previousDocument(); } else if ( command.equals( "STOPHTML" ) ) { stopLoading(); } else if ( command.equals( "RELOADHTML" ) ) { reload(); } } }//............................................................ private class IWindowListener extends WindowAdapter { public void windowClosed( WindowEvent e ) { setVisible( false ); } }//............................................................ private class IHistoryListener implements BrowserHistoryListener { public void executeHistoryCommand( BrowserHistoryEvent event ) { String docStr = hotJavaBrowserBean_.getDocumentString(); addressText_.setText( docStr ); } }//............................................................ private class IPropertyChangeListener implements PropertyChangeListener { public void propertyChange( PropertyChangeEvent event ) { String name = event.getPropertyName(); if ( name.equals( "loadingProgress" ) ) { /* Double prog = (Double) event.getNewValue(); System.err.println( "LOAD: " + prog.doubleValue() ); progressBar.setValue ( (int) (prog.doubleValue() * 100.0) ); */ } else if ( name.equals( "indicatedElement" ) ) { ElementInfo info = (ElementInfo) event.getNewValue(); String currURL = statusText.getText(); if ( info != null ) { if ( info.hrefURL != null ) { if ( ! info.hrefURL.equals( currURL ) ) { statusText.setText( info.hrefURL ); } } else if ( currURL.length() > 0 ) { statusText.setText( currentDocName ); } } else if ( currURL.length() > 0 ) { statusText.setText( currentDocName ); } } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -