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

📄 thumbelina.java

📁 html 解析处理代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        for (int i = 0; i < list.size (); i++)            append ((URL)list.get (i));    }    /**     * Filter URLs and add to queue.     * Removes already visited links and appends the rest (if any) to the     * visit pending list.     * @param urls The list of URL's to add to the 'to visit' list.     * @return Returns the filered list.     */    protected ArrayList filter (final URL[] urls)    {        ArrayList list;        URL url;        String ref;        list = new ArrayList ();        for (int i = 0; i < urls.length; i++)        {            url = urls[i];            ref = url.toExternalForm ();            // ignore cgi            if (!mDiscardCGI || (-1 == ref.indexOf ("/cgi-bin/")))                // ignore queries                if (!mDiscardQueries || (-1 == ref.indexOf ("?")))                    // ignore duplicates                    if (!mVisited.containsKey (ref))                    {                        try                        {                            url.openConnection ();                            list.add (url);                        }                        catch (IOException ioe)                        {                            // unknown host or some other problem... discard                        }                    }        }        return (list);    }    /**     * Initialize the GUI.     */    private void initComponents ()    {        mPowerBar = new JPanel ();        mUrlText = new JTextField ();        mRunToggle = new JCheckBox ();        mSpeedSlider = new JSlider ();        mReadyProgress = new JProgressBar ();        mQueueProgress = new JProgressBar ();        mBackgroundToggle = new JCheckBox ();        mMainArea = new JSplitPane ();        mPicturePanelScroller = new JScrollPane ();        mHistoryScroller = new JScrollPane ();        mHistory = new JList ();        mQueueSize = new JLabel ();        mVisitedSize = new JLabel ();        mPowerBar.setLayout (new BoxLayout (mPowerBar, BoxLayout.X_AXIS));        mPowerBar.setBorder (new BevelBorder (BevelBorder.LOWERED));        mPowerBar.add (mUrlText);        mRunToggle.setSelected (true);        mRunToggle.setText ("On/Off");        mRunToggle.setToolTipText ("Starts/stops the image presentation.");        mPowerBar.add (mRunToggle);        mSpeedSlider.setMajorTickSpacing (1000);        mSpeedSlider.setMaximum (5000);        mSpeedSlider.setPaintTicks (true);        mSpeedSlider.setToolTipText ("Set inter-image delay.");        mSpeedSlider.setValue (500);        mSpeedSlider.setInverted (true);        mPowerBar.add (mSpeedSlider);        mReadyProgress.setToolTipText ("Pending images..");        mReadyProgress.setStringPainted (true);        mPowerBar.add (mReadyProgress);        mQueueProgress.setToolTipText ("Outstanding image fetches..");        mQueueProgress.setStringPainted (true);        mPowerBar.add (mQueueProgress);        mBackgroundToggle.setSelected (true);        mBackgroundToggle.setText ("On/Off");        mBackgroundToggle.setToolTipText ("Starts/stops background fetching.");        mPowerBar.add (mBackgroundToggle);        mVisitedSize.setBorder (new BevelBorder (BevelBorder.LOWERED));        mVisitedSize.setText ("00000");        mVisitedSize.setToolTipText ("Number of URLs examined.");        mPowerBar.add (mVisitedSize);        mQueueSize.setBorder (new BevelBorder (BevelBorder.LOWERED));        mQueueSize.setText ("00000");        mQueueSize.setToolTipText ("Number of URLs in queue.");        mPowerBar.add (mQueueSize);        mHistory.setModel (new DefaultListModel ());        mHistory.setToolTipText ("History");        mHistory.setDoubleBuffered (false);        mHistory.setSelectionMode (            ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);        mHistoryScroller.setViewportView (mHistory);        mHistoryScroller.setDoubleBuffered (false);        mPicturePanelScroller.setViewportView (mPicturePanel);        mPicturePanelScroller.setDoubleBuffered (false);        mPicturePanelScroller.setHorizontalScrollBarPolicy (            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);        mPicturePanelScroller.setVerticalScrollBarPolicy (            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);        add (mMainArea, java.awt.BorderLayout.CENTER);        mMainArea.setLeftComponent (mHistoryScroller);        mMainArea.setRightComponent (mPicturePanelScroller);        add (mPowerBar, java.awt.BorderLayout.SOUTH);    }    /**     * Gets the state of status bar visibility.     * @return <code>true</code> if the status bar is visible.     */    public boolean getStatusBarVisible ()    {        boolean ret;        ret = false;        for (int i = 0; !ret && (i < getComponentCount ()); i++)            if (mPowerBar == getComponent (i))                ret = true;        return (ret);    }    /**     * Sets the status bar visibility.     * @param visible The new visibility state.     * If <code>true</code>, the status bar will be unhidden.     */    public void setStatusBarVisible (final boolean visible)    {        int index;        index = -1;        for (int i = 0; (-1 == index) && (i < getComponentCount ()); i++)            if (mPowerBar == getComponent (i))                index = i;        if (visible)        {            if (-1 == index)            {                add (mPowerBar, java.awt.BorderLayout.SOUTH);                invalidate ();                validate ();            }        }        else            if (-1 != index)            {                remove (index);                invalidate ();                validate ();            }    }    /**     * Gets the state of history list visibility.     * @return <code>true</code> if the history list is visible.     */    public boolean getHistoryListVisible ()    {        boolean ret;        ret = false;        for (int i = 0; !ret && (i < getComponentCount ()); i++)            // check indirectly because the history list is in a splitter            if (mMainArea == getComponent (i))                ret = true;        return (ret);    }    /**     * Sets the history list visibility.     * @param visible The new visibility state.     * If <code>true</code>, the history list will be unhidden.     */    public void setHistoryListVisible (final boolean visible)    {        int pictpanel;        int splitter;        Component component;        pictpanel = -1;        splitter = -1;        for (int i = 0; i < getComponentCount (); i++)        {            component = getComponent (i);            if (mPicturePanelScroller == component)                pictpanel = i;            else if (mMainArea == component)                splitter = i;        }        if (visible)        {            if (-1 != pictpanel)            {                remove (pictpanel);                add (mMainArea, java.awt.BorderLayout.CENTER);                mMainArea.setLeftComponent (mHistoryScroller);                //mPicturePanelScroller.setViewportView (mPicturePanel);                mMainArea.setRightComponent (mPicturePanelScroller);                invalidate ();                validate ();            }        }        else            if (-1 != splitter)            {                remove (splitter);                add (mPicturePanelScroller, java.awt.BorderLayout.CENTER);                invalidate ();                validate ();            }    }    /**     * Gets the state of the sequencer thread.     * @return <code>true</code> if the thread is pumping images.     */    public boolean getSequencerActive ()    {        return (mSequencer.mActive);    }    /**     * Sets the sequencer activity state.     * The sequencer is the thread that moves images from the pending list     * to the picture panel on a timed basis.     * @param active The new activity state.     * If <code>true</code>, the sequencer will be turned on.     * This may alter the speed setting if it is set to zero.     */    public void setSequencerActive (final boolean active)    {        // check the delay is not zero        if (0 == getSpeed ())            setSpeed (Sequencer.DEFAULT_DELAY);        mSequencer.mActive = active;        if (active)            synchronized (mSequencer.mPending)            {                mSequencer.mPending.notify ();            }        if (active != mRunToggle.isSelected ())            mRunToggle.setSelected (active);    }    /**     * Gets the state of the background thread.     * @return <code>true</code> if the thread is examining web pages.     */    public boolean getBackgroundThreadActive ()    {        return (mActive);    }    /**     * Sets the state of the background thread activity.     * The background thread is responsible for examining URLs that are on     * the queue for thumbnails, and starting the image fetch operation.     * @param active If <code>true</code>,     * the background thread will be turned on.     */    public void setBackgroundThreadActive (final boolean active)    {        mActive = active;        if (active)            synchronized (mUrls)            {                mUrls.notify ();            }        if (active != mBackgroundToggle.isSelected ())            mBackgroundToggle.setSelected (active);    }    /**     * Get the sequencer delay time.     * @return The number of milliseconds between image additions to the panel.     */    public int getSpeed ()    {        return (mSequencer.getDelay ());    }    /**     * Set the sequencer delay time.     * The sequencer is the thread that moves images from the pending list     * to the picture panel on a timed basis. This value sets the number of     * milliseconds it waits between pictures.     * Setting it to zero toggles the running state off.     * @param speed The sequencer delay in milliseconds.     */    public void setSpeed (final int speed)    {        if (0 == speed)            mRunToggle.setSelected (false);        else        {            mRunToggle.setSelected (true);            mSequencer.setDelay (speed);        }        if (speed != mSpeedSlider.getValue ())            mSpeedSlider.setValue (speed);    }    /**     * Getter for property discardCGI.     * @return Value of property discardCGI.     *     */    public boolean isDiscardCGI ()    {        return (mDiscardCGI);    }    /**     * Setter for property discardCGI.     * @param discard New value of property discardCGI.     *     */    public void setDiscardCGI (final boolean discard)    {        mDiscardCGI = discard;    }    /**     * Getter for property discardQueries.     * @return Value of property discardQueries.     *     */    public boolean isDiscardQueries ()    {        return (mDiscardQueries);    }    /**     * Setter for property discardQueries.     * @param discard New value of property discardQueries.     *     */    public void setDiscardQueries (final boolean discard)    {        mDiscardQueries = discard;    }    /**     * Check if the url looks like an image.     * @param url The usrl to check for image characteristics.     * @return <code>true</code> if the url ends in a recognized image     * extension.     */    protected boolean isImage (final String url)    {        String lower = url.toLowerCase ();        return (lower.endsWith (".jpg") || lower.endsWith (".gif")            || lower.endsWith (".png"));

⌨️ 快捷键说明

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