📄 thumbelina.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/Thumbelina.java,v $// $Author: derrickoswald $// $Date: 2005/02/13 20:36:00 $// $Revision: 1.7 $//// 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.Image;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.image.ImageObserver;import java.beans.PropertyChangeListener;import java.beans.PropertyChangeSupport;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import java.util.ArrayList;import java.util.HashMap;import javax.swing.BoxLayout;import javax.swing.DefaultListModel;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JList;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JProgressBar;import javax.swing.JScrollPane;import javax.swing.JSlider;import javax.swing.JSplitPane;import javax.swing.JTextField;import javax.swing.ListSelectionModel;import javax.swing.ScrollPaneConstants;import javax.swing.border.BevelBorder;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import org.htmlparser.Node;import org.htmlparser.Tag;import org.htmlparser.lexer.Lexer;import org.htmlparser.util.ParserException;/** * View images behind thumbnails. */public class Thumbelina extends JPanel // was: java.awt.Canvas implements Runnable, ItemListener, ChangeListener, ListSelectionListener{ /** * Property name for current URL binding. */ public static final String PROP_CURRENT_URL_PROPERTY = "currentURL"; /** * Property name for queue size binding. */ public static final String PROP_URL_QUEUE_PROPERTY = "queueSize"; /** * Property name for visited URL size binding. */ public static final String PROP_URL_VISITED_PROPERTY = "visitedSize"; /** * URL's to visit. */ private ArrayList mUrls; /** * URL's visited. */ protected HashMap mVisited; /** * Images requested. */ protected HashMap mRequested; /** * Images being tracked currently. */ protected HashMap mTracked; /** * Background thread. */ protected Thread mThread; /** * Activity state. * <code>true</code> means processing URLS, <code>false</code> not. */ protected boolean mActive; /** * The picture sequencer. */ protected Sequencer mSequencer; /** * The central area for pictures. */ protected PicturePanel mPicturePanel; /** * Value returned when no links are discovered. */ protected static final URL[][] NONE = { { }, { } }; /** * Bound property support. */ protected PropertyChangeSupport mPropertySupport; /** * The URL being currently being examined. */ protected String mCurrentURL; /** * If <code>true</code>, does not follow links containing cgi calls. */ protected boolean mDiscardCGI; /** * If <code>true</code>, does not follow links containing queries (?). */ protected boolean mDiscardQueries; /** * Background thread checkbox in status bar. */ protected JCheckBox mBackgroundToggle; /** * History list. */ protected JList mHistory; /** * Scroller for the picture panel. */ protected JScrollPane mPicturePanelScroller; /** * Scroller for the history list. */ protected JScrollPane mHistoryScroller; /** * Main panel in central area. */ protected JSplitPane mMainArea; /** * Status bar. */ protected JPanel mPowerBar; /** * Image request queue monitor in status bar. */ protected JProgressBar mQueueProgress; /** * Image ready queue monitor in status bar. */ protected JProgressBar mReadyProgress; /** * Sequencer thread toggle in status bar. */ protected JCheckBox mRunToggle; /** * Sequencer speed slider in status bar. */ protected JSlider mSpeedSlider; /** * URL report in status bar. */ protected JTextField mUrlText; /** * URL queue size display in status bar. */ protected JLabel mQueueSize; /** * URL visited count display in status bar. */ protected JLabel mVisitedSize; /** * Creates a new instance of Thumbelina. */ public Thumbelina () { this ((URL)null); } /** * Creates a new instance of Thumbelina. * @param url Single URL to enter into the 'to follow' list. * @exception MalformedURLException If the url is malformed. */ public Thumbelina (final String url) throws MalformedURLException { this (null == url ? null : new URL (url)); } /** * Creates a new instance of Thumbelina. * @param url URL to enter into the 'to follow' list. */ public Thumbelina (final URL url) { mUrls = new ArrayList (); mVisited = new HashMap (); mRequested = new HashMap (); mTracked = new HashMap (); mThread = null; mActive = true; mPicturePanel = new PicturePanel (this); mSequencer = new Sequencer (this); mPropertySupport = new PropertyChangeSupport (this); mCurrentURL = null; mDiscardCGI = true; mDiscardQueries = true; // JComponent specific setDoubleBuffered (false); setLayout (new java.awt.BorderLayout ()); mPicturePanel.setDoubleBuffered (false); mThread = new Thread (this); mThread.setName ("BackgroundThread"); mThread.start (); initComponents (); mRunToggle.addItemListener (this); mBackgroundToggle.addItemListener (this); mSpeedSlider.addChangeListener (this); mHistory.addListSelectionListener (this); memCheck (); if (null != url) append (url); } /** * Check for low memory situation. * Report to the user a bad situation. */ protected void memCheck () { Runtime runtime; long maximum; if (System.getProperty ("java.version").startsWith ("1.4")) { runtime = Runtime.getRuntime (); runtime.gc (); maximum = runtime.maxMemory (); if (maximum < 67108864L) // 64MB JOptionPane.showMessageDialog ( null, "Maximum available memory is low (" + maximum + " bytes).\n" + "\n" + "It is strongly suggested to increase the maximum memory\n" + "available by using the JVM command line switch -Xmx with\n" + "a suitable value, such as -Xmx256M for example.", "Thumbelina - Low memory", JOptionPane.WARNING_MESSAGE, null /*Icon*/); } } /** * Reset this Thumbelina. * Clears the sequencer of pending images, resets the picture panel, * emptiies the 'to be examined' list of URLs. */ public void reset () { int oldsize; synchronized (mUrls) { mSequencer.reset (); mPicturePanel.reset (); oldsize = mUrls.size (); mUrls.clear (); } updateQueueSize (oldsize, mUrls.size ()); } /** * Append the given URL to the queue. * Adds the url only if it isn't already in the queue, * and notifys listeners about the addition. * @param url The url to add. */ public void append (final URL url) { String href; boolean found; URL u; int oldsize; href = url.toExternalForm (); found = false; oldsize = -1; synchronized (mUrls) { for (int i = 0; !found && (i < mUrls.size ()); i++) { u = (URL)mUrls.get (i); if (href.equals (u.toExternalForm ())) found = true; } if (!found) { oldsize = mUrls.size (); mUrls.add (url); mUrls.notify (); } } if (-1 != oldsize) updateQueueSize (oldsize, mUrls.size ()); } /** * Append the given URLs to the queue. * @param list The list of URL objects to add. */ public void append (final ArrayList list) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -