📄 thumbelinaframe.java
字号:
// HTMLParser Library $Name: v1_6 $ - A java-based parser for HTML// http://sourceforge.org/projects/htmlparser// Copyright (C) 2003 Derrick Oswald//// Revision Control Information//// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/lexerapplications/thumbelina/ThumbelinaFrame.java,v $// $Author: derrickoswald $// $Date: 2004/09/02 02:28:14 $// $Revision: 1.4 $//// This library is free software; you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public// License as published by the Free Software Foundation; either// version 2.1 of the License, or (at your option) any later version.//// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU// Lesser General Public License for more details.//// You should have received a copy of the GNU Lesser General Public// License along with this library; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA//package org.htmlparser.lexerapplications.thumbelina;import java.awt.BorderLayout;import java.awt.Component;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowEvent;import java.awt.event.WindowListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;import java.util.prefs.BackingStoreException;import java.util.prefs.Preferences;import javax.swing.ImageIcon;import javax.swing.JCheckBoxMenuItem;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JSeparator;import org.htmlparser.lexer.Lexer;/** * Encapsulate a Thumbelina bean and add menu and preferences support. * Provides a JFrame base in which to place a Thumbelina bean, and * adds a menu system with MRU (Most Recently Used) list. * Also provides a Google search capability. * Will eventually provide Javahelp too. */public class ThumbelinaFrame extends JFrame implements WindowListener, ActionListener, ItemListener, PropertyChangeListener{ /** * Window title. */ private static final String TITLE = "Thumbelina"; /** * Preference name for frame location and size. */ private static final String FRAMESIZE = "FrameSize"; /** * Percent of screen to leave as border when no preferences available. */ private static final int BORDERPERCENT = 5; /** * Preference name for most recently used count. */ private static final String MRULENGTH = "MRULength"; /** * Preference name for most recently used maximum count. */ private static final String MRUMAX = "MRUMax"; /** * Preference prefix for most recently used list items. */ private static final String MRUPREFIX = "MRUListItem"; /** * Preference name for google query. */ private static final String GOOGLEQUERY = "GoogleQuery"; /** * Default google query when no preferences are available. */ private static final String DEFAULTGOOGLEQUERY = "thumbs"; /** * List of URLs to prime the MRU list with. */ private static final String[] DEFAULTMRULIST = { "www.a2zcds.com", "www.stoneschool.com/Japan/", "www.tommys-bookmarks.com", "www.unitedmedia.com/comics/dilbert/archive", "www.pastelartists.com", }; /** * Send Mozilla headers in request if <code>true</code>. */ private static final boolean USE_MOZILLA_HEADERS = false; /** * Preference name for status bar visibility state. */ private static final String STATUSBARSTATE = "StatusBarVisible"; /** * Preference name for history list visibility state. */ private static final String HISTORYLISTSTATE = "HistoryListVisible"; /** * Preference name for sequencer active state. */ private static final String SEQUENCERACTIVE = "SequencerActive"; /** * Preference name for background thread active state. */ private static final String BACKGROUNDTHREADACTIVE = "BackgroundThreadActive"; /** * Preference name for sequencer display speed. */ private static final String DISPLAYSPEED = "DisplaySpeed"; /** * Main menu. */ protected JMenuBar mMenu; /** * URL submenu. */ protected JMenu mURL; /** * Open menu item. */ protected JMenuItem mOpen; /** * Google menu item. */ protected JMenuItem mGoogle; /** * MRU list separator #1. */ protected JSeparator mSeparator1; /** * MRU list separator #2. */ protected JSeparator mSeparator2; /** * Exit menu item. */ protected JMenuItem mExit; /** * View submenu. */ protected JMenu mView; /** * Status bar visible menu item. */ protected JCheckBoxMenuItem mStatusVisible; /** * History list visible menu item. */ protected JCheckBoxMenuItem mHistoryVisible; /** * Vommand menu. */ protected JMenu mCommand; /** * Reset menu item. */ protected JMenuItem mReset; /** * Clear menu item */ protected JMenuItem mClear; /** * Help submenu. */ protected JMenu mHelp; /** * About menu item. */ protected JMenuItem mAbout; /** * Construct a new Thumbelina frame with an idle Thumbelina. */ public ThumbelinaFrame () { this (new Thumbelina ()); } /** * Construct a new Thumbelina frame with a Thumbelina primed with one URL. * @param url The URL to prime the Thumbelina with. * @exception MalformedURLException If the given string doesn't represent * a valid url. */ public ThumbelinaFrame (final String url) throws MalformedURLException { this (new Thumbelina (url)); } /** * Construct a new Thumbelina frame with a Thumbelina primed with one URL. * @param url The URL to prime the Thumbelina with. */ public ThumbelinaFrame (final URL url) { this (new Thumbelina (url)); } /** * Construct a new Thumbelina frame with a given Thumbelina. * @param thumbelina The Thumbelina to encapsulate. */ public ThumbelinaFrame (final Thumbelina thumbelina) { setTitle (TITLE); thumbelina.addPropertyChangeListener (this); getContentPane ().add (thumbelina, BorderLayout.CENTER); addWindowListener (this); makeMenu (); setJMenuBar (mMenu); restoreSize (); initState (); updateMenu (); } /** * Access the Thumbelina object contained in the frame. * @return The Thumbelina bean. */ public Thumbelina getThumbelina () { return ((Thumbelina)getContentPane ().getComponent (0)); } /** * Initialize the user preferences. * Reads from the existing user preferences, * or initializes values from the bean directly if they don't exist. * Sets the state of the view checkboxes to match. */ public void initState () { Preferences prefs; prefs = Preferences.userNodeForPackage (getClass ()); if (-1 == prefs.getInt (MRULENGTH, -1)) for (int i = 0; i < DEFAULTMRULIST.length; i++) updateMRU (DEFAULTMRULIST[i]); getThumbelina ().setStatusBarVisible ( prefs.getBoolean (STATUSBARSTATE, getThumbelina ().getStatusBarVisible ())); mStatusVisible.setSelected (getThumbelina ().getStatusBarVisible ()); getThumbelina ().setHistoryListVisible ( prefs.getBoolean (HISTORYLISTSTATE, getThumbelina ().getHistoryListVisible ())); mHistoryVisible.setSelected (getThumbelina ().getHistoryListVisible ()); getThumbelina ().setSequencerActive ( prefs.getBoolean (SEQUENCERACTIVE, getThumbelina ().getSequencerActive ())); getThumbelina ().setBackgroundThreadActive ( prefs.getBoolean (BACKGROUNDTHREADACTIVE, getThumbelina ().getBackgroundThreadActive ())); getThumbelina ().setSpeed ( prefs.getInt (DISPLAYSPEED, getThumbelina ().getSpeed ())); } /** * Saves the current settings in the user preferences. * By default this writes to the thumbelina subdirectory under * .java in the users home directory. */ public void saveState () { Preferences prefs; prefs = Preferences.userNodeForPackage (getClass ()); // don't save size unless we're in normal state if (NORMAL == getExtendedState ()) prefs.put (FRAMESIZE, toString (getBounds ())); prefs.putBoolean (STATUSBARSTATE, getThumbelina ().getStatusBarVisible ()); prefs.putBoolean (HISTORYLISTSTATE, getThumbelina ().getHistoryListVisible ()); prefs.putBoolean (SEQUENCERACTIVE, getThumbelina ().getSequencerActive ()); prefs.putBoolean (BACKGROUNDTHREADACTIVE, getThumbelina ().getBackgroundThreadActive ()); prefs.putInt (DISPLAYSPEED, getThumbelina ().getSpeed ()); try { prefs.flush (); } catch (BackingStoreException bse) { bse.printStackTrace (); } } /** * Sets the frame size if no previous preference has been stored. * It creates a window covering all but <code>BORDERPERCENT</code> * margins. */ public void initSize () { Toolkit tk; Dimension dim; int borderx;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -