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

📄 thumbelina.java

📁 html 解析处理代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    /**     * Handle checkbox events from the status bar.     * Based on the thread toggles, activates or deactivates the     * background thread processes.     * @param event The event describing the checkbox event.     */    public void itemStateChanged (final ItemEvent event)    {        Object source;        boolean checked;        source = event.getItemSelectable ();        checked = ItemEvent.SELECTED == event.getStateChange ();        if (source == mRunToggle)            setSequencerActive (checked);        else if (source == mBackgroundToggle)            setBackgroundThreadActive (checked);    }    //    // ChangeListener interface    //    /**     * Handles the speed slider events.     * @param event The event describing the slider activity.     */    public void stateChanged (final ChangeEvent event)    {        JSlider source;        source = (JSlider)event.getSource ();        if (!source.getValueIsAdjusting ())            setSpeed (source.getValue ());    }    //    // ListSelectionListener interface    //    /**     * Handles the history list events.     * @param event The event describing the list activity.     */    public void valueChanged (final ListSelectionEvent event)    {        JList source;        Object[] hrefs;        Picture picture;        URL url;        Image image;        Tracker tracker;        source = (JList)event.getSource ();        if (source == mHistory && !event.getValueIsAdjusting ())        {            hrefs = source.getSelectedValues ();            for (int i = 0; i < hrefs.length; i++)            {                picture = mPicturePanel.find ("http://" + (String)hrefs[i]);                if (null != picture)                    mPicturePanel.bringToTop (picture);                else                    try                    {                        url = new URL ("http://" + (String)hrefs[i]);                        image = getToolkit ().createImage (url);                        tracker = new Tracker (url);                        image.getWidth (tracker);                        System.out.println ("refetching " + hrefs[i]);                    }                    catch (MalformedURLException murle)                    {                        murle.printStackTrace ();                    }            }        }    }    /**     * Adds the given url to the history list.     * Also puts the URL in the url text of the status bar.     * @param url The URL to add to the history list.     */    public void addHistory (String url)    {        int index;        DefaultListModel model;        mUrlText.setText (url);        // chop off the protocol        index = url.indexOf ("http://");        if (-1 != index)            url = url.substring (index + 7);        else            System.out.println ("********* " + url + " ************");        model = (DefaultListModel)mHistory.getModel ();        model.addElement (url);        // this doesn't friggin work:        // mHistory.ensureIndexIsVisible (model.getSize ());    }    /**     * Open a URL.     * Resets the urls list and appends the given url as the only item.     * @param ref The URL to add.     */    public void open (String ref)    {        URL url;        try        {            if (!ref.startsWith ("http://"))                ref = "http://" + ref;            url = new URL (ref);            reset ();            append (url);        }        catch (Exception e)        {            System.out.println (e.getMessage ());        }    }    /**     * Provide command line help.     */    protected static void help ()    {        System.out.println ("Thumbelina - Scan and display the images behind thumbnails.");        System.out.println ("java -Xmx256M -jar thumbelina.jar [url]");        System.out.println ("It is highly recommended that the maximum heap "            + "size be increased with -Xmx switch.");        System.exit (0);    }    /**     * Mainline.     * @param args the command line arguments.     * Can be one or more forms of -help to get command line help,     * or a URL to prime the program with.     * Checks for JDK 1.4 and if not found runs in crippled mode     * (no ThumbelinaFrame).     */    public static void main (final String[] args)    {        URL url;        String version;        JFrame frame;        Thumbelina thumbelina;        System.setProperty ("sun.net.client.defaultReadTimeout", "7000");        System.setProperty ("sun.net.client.defaultConnectTimeout", "7000");        url = null;        if (0 != args.length)            try            {                if (args[0].equalsIgnoreCase ("help")                    || args[0].equalsIgnoreCase ("-help")                    || args[0].equalsIgnoreCase ("-h")                    || args[0].equalsIgnoreCase ("?")                    || args[0].equalsIgnoreCase ("-?"))                    help ();                else                    url = new URL (args[0]);            }            catch (MalformedURLException murle)            {                System.err.println (murle.getMessage ());                help ();            }        version = System.getProperty ("java.version");        if (version.startsWith ("1.4") || version.startsWith ("1.5"))            frame = new ThumbelinaFrame (url);        else        {            if (null == url)                help ();            System.out.println (                "Java version is only "                + version                + ", entering crippled mode");            frame = new JFrame ("Thumbelina");            thumbelina = new Thumbelina (url);            frame.getContentPane ().add (thumbelina, BorderLayout.CENTER);            frame.setBounds (10, 10, 640, 480);            frame.addWindowListener (new WindowAdapter ()            {                public void windowClosing (final WindowEvent event)                {                    System.exit (0);                }            });        }        frame.setVisible (true);    }    /**     * Getter for property queue.     * @return List of URLs that are to be visited.     */    public ArrayList getQueue ()    {        return (mUrls);    }    /**     * Getter for property queue.     * This is a bound property. Notifications are available via the     * <code>PROP_URL_QUEUE_PROPERTY</code> property.     * @return The size of the list of URLs that are to be visited.     */    public int getQueueSize ()    {        return (mUrls.size ());    }    /**     * Track incoming asynchronous image reception.     * On completion, adds the image to the pending list.     */    class Tracker implements ImageObserver    {        /**         * The url the image is comming from.         */        protected URL mSource;        /**         * Create an image tracker.         * @param source The URL the image is being fetched from.         */        public Tracker (final URL source)        {            mSource = source;        }        //        // ImageObserver interface        //        /**         * This method is called when information about an image which was         * previously requested using an asynchronous interface becomes         * available.  Asynchronous interfaces are method calls such as         * getWidth(ImageObserver) and drawImage(img, x, y, ImageObserver)         * which take an ImageObserver object as an argument.  Those methods         * register the caller as interested either in information about         * the overall image itself (in the case of getWidth(ImageObserver))         * or about an output version of an image (in the case of the         * drawImage(img, x, y, [w, h,] ImageObserver) call).         *         * <p>This method         * should return true if further updates are needed or false if the         * required information has been acquired.  The image which was being         * tracked is passed in using the img argument.  Various constants         * are combined to form the infoflags argument which indicates what         * information about the image is now available.  The interpretation         * of the x, y, width, and height arguments depends on the contents         * of the infoflags argument.         * <p>         * The <code>infoflags</code> argument should be the bitwise inclusive         * <b>OR</b> of the following flags: <code>WIDTH</code>,         * <code>HEIGHT</code>, <code>PROPERTIES</code>, <code>SOMEBITS</code>,         * <code>FRAMEBITS</code>, <code>ALLBITS</code>, <code>ERROR</code>,         * <code>ABORT</code>.         *         * @param     image   the image being observed.         * @param     infoflags   the bitwise inclusive OR of the following         *               flags:  <code>WIDTH</code>, <code>HEIGHT</code>,         *               <code>PROPERTIES</code>, <code>SOMEBITS</code>,         *               <code>FRAMEBITS</code>, <code>ALLBITS</code>,         *               <code>ERROR</code>, <code>ABORT</code>.         * @param     x   the <i>x</i> coordinate.         * @param     y   the <i>y</i> coordinate.         * @param     width    the width.         * @param     height   the height.         * @return    <code>false</code> if the infoflags indicate that the         *            image is completely loaded; <code>true</code> otherwise.         *         * @see #WIDTH         * @see #HEIGHT         * @see #PROPERTIES         * @see #SOMEBITS         * @see #FRAMEBITS         * @see #ALLBITS         * @see #ERROR         * @see #ABORT         * @see Image#getWidth         * @see Image#getHeight         * @see java.awt.Graphics#drawImage         */        public synchronized boolean imageUpdate (            final Image image,            final int infoflags,            final int x,            final int y,            final int width,            final int height)        {            boolean done;            boolean error;            boolean abort;            URL url;            done = (0 != (infoflags & ImageObserver.ALLBITS));            abort = (0 != (infoflags & ImageObserver.ABORT));            error = (0 != (infoflags & ImageObserver.ERROR));            if (done || abort || error)                synchronized (mTracked)                {                    url = (URL)mTracked.remove (mSource.toExternalForm ());                    mTracked.notify ();                    mQueueProgress.setValue (mTracked.size ());                    if (done)                        mSequencer.add (image, mSource, (null != url));                }            return (!done);        }    }}/* * Revision Control Modification History * * $Log: Thumbelina.java,v $ * Revision 1.7  2005/02/13 20:36:00  derrickoswald * FilterBuilder * * Revision 1.6  2004/07/31 16:42:30  derrickoswald * Remove unused variables and other fixes exposed by turning on compiler warnings. * * Revision 1.5  2004/05/24 16:18:17  derrickoswald * Part three of a multiphase refactoring. * The three node types are now fronted by interfaces (program to the interface paradigm) * with concrete implementations in the new htmlparser.nodes package. Classes from the * lexer.nodes package are moved to this package, and obvious references to the concrete * classes that got broken by this have been changed to use the interfaces where possible. * * Revision 1.4  2004/05/16 17:59:56  derrickoswald * Alter bound property name constants to agree with section * 8.8 Capitalization of inferred names. * in the JavaBeans API specification. * * Revision 1.3  2003/11/04 01:25:02  derrickoswald * Made visiting order the same order as on the page. * The 'shouldRecurseSelf' boolean of NodeVisitor could probably * be removed since it doesn't make much sense any more. * Fixed StringBean, which was still looking for end tags with names starting with * a slash, i.e. "/SCRIPT", silly beany. * Added some debugging support to the lexer, you can easily base a breakpoint on * line number. * * Revision 1.2  2003/10/26 16:44:01  derrickoswald * Get thumbelina working again. The tag.getName() method doesn't include the / of end tags. * * Revision 1.1  2003/09/21 18:20:56  derrickoswald * Thumbelina * Created a lexer GUI application to extract images behind thumbnails. * Added a task in the ant build script - thumbelina - to create the jar file. * You need JDK 1.4.x to build it.  It can be run on JDK 1.3.x in crippled mode. * Usage: java -Xmx256M thumbelina.jar [URL] * * */

⌨️ 快捷键说明

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