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

📄 filterbuilder.java

📁 本程序用于对页面信息进行提取并分析
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public void setExpanded (        Filter[] filters,        boolean expanded,        boolean recursive)    {        SubFilterList list;        for (int i = 0; i < filters.length; i++)        {            if (recursive && (null != (list = getEnclosed (filters[i]))))                setExpanded (list.getFilters (), expanded, recursive);            filters[i].setExpanded (expanded);        }    }    /**     * Retrieve the top level filters in the main window.     * @return The top level filters.     */    public Filter[] getFilters ()    {        Component[] components;        Filter[] ret;        components = mMainPanel.getComponents ();        ret = new Filter[components.length];        System.arraycopy (components, 0, ret, 0, components.length);                return (ret);    }    /**     * Redo the layout.     */    public void relayout ()    {        mMainPanel.invalidate ();        mMainScroller.invalidate ();        mMainScroller.validate ();        mMainScroller.repaint ();    }    /**     * Read a workspace from file.     * The current contents are erased.     * @param name The name of the file to open.     */    public void open (String name)    {        LineNumberReader reader;        String line;        Filter[] filters;        Point point;        Dimension dimension;        try        {            reader = new LineNumberReader (new FileReader (name));            while (null != (line = reader.readLine ()))                if (line.startsWith ("// ["))                {                    line = line.substring (3);    	            try    	            {    	                filters = Filter.reconstitute (line, new Parser (mURLField.getText ()));    	                mMainPanel.removeAll ();    	                point = new Point ();    	                for (int i = 0; i < filters.length; i++)    	                {    	                    dimension = filters[i].getPreferredSize ();    	                    mMainPanel.add (filters[i]);    	                    filters[i].setLocation (point);    	                    point.y += dimension.height;    	                }    	                setupMouseListeners (filters);    	                setupDropTargets (filters);    	                relayout ();    	            }    	            catch (ParserException pe)    	            {    	                pe.printStackTrace ();    	            }                    break;                }            reader.close ();        }        catch (IOException ioe)        {            ioe.printStackTrace ();        }    }    /**     * Exit back to the operating system.     */    void exitApplication ()    {        this.setVisible (false);    // hide the Frame        this.dispose ();            // free the system resources        System.exit (0);            // close the application    }    /**     * Show a pop up context menu.     * Shows a context sensitive popup menu at the location of the     * mouse event.     * @param event The mouse event that initiates the popup.     */    public void showContextMenu (MouseEvent event)    {        JPopupMenu menu;        JMenuItem item;        menu = new JPopupMenu ();        menu.setName ("Popup");        item = new JMenuItem ("Expand");        item.setActionCommand ("expandAction");        item.addActionListener (this);        menu.add (item);        item = new JMenuItem ("Collapse");        item.setActionCommand ("collapseAction");        item.addActionListener (this);        menu.add (item);        menu.addSeparator ();        item = new JMenuItem ("Expand All");        item.setActionCommand ("expandAllAction");        item.addActionListener (this);        menu.add (item);        item = new JMenuItem ("CollapseAll");        item.setActionCommand ("collapseAllAction");        item.addActionListener (this);        menu.add (item);        menu.addSeparator ();        item = new JMenuItem ("Cut");        item.setActionCommand ("cutAction");        item.addActionListener (this);        menu.add (item);        item = new JMenuItem ("Copy");        item.setActionCommand ("copyAction");        item.addActionListener (this);        menu.add (item);        item = new JMenuItem ("Paste");        item.setActionCommand ("pasteAction");        item.addActionListener (this);        menu.add (item);        item = new JMenuItem ("Delete");        item.setActionCommand ("deleteAction");        item.addActionListener (this);        menu.add (item);        menu.addSeparator ();        item = new JMenuItem ("Execute Filter");        item.setActionCommand ("executeAction");        item.addActionListener (this);        menu.add (item);        menu.show (event.getComponent (), event.getX (), event.getY ());    }    //    // selection manipulation    //    /**     * Add a filter to the current selection set.     * @param filter The filter to add.     */    protected void addSelection (Filter filter)    {        if (!selectionContains (filter))            mSelection.addElement (filter);        filter.setSelected (true);        mMoved = false;    }    /**     * Remove a filter from the current selection set.     * @param filter The filter to remove.     */    protected void removeSelection (Filter filter)    {        mSelection.removeElement (filter); // no harm if not contained        filter.setSelected (false);    }    /**     * Select(highlight)/deselect the current selection set.     * @param select If <code>true</code> turn on highlighting,     * turn it off otherwise.     */    protected void selectSelection (boolean select)    {        int count;        Filter filter;                count = mSelection.size ();        for (int i = 0; i < count; i++)        {            filter = (Filter)mSelection.elementAt (i);            filter.setSelected (select);        }    }    /**     * Clear (empty) the current selection set.     */    protected void clearSelection ()    {        selectSelection (false);        mSelection.removeAllElements ();    }    /**     * Move the current selection set as a group.     * @param translation The displacement to move them all by.     */    protected void moveSelection (Point translation)    {        int count;        Filter filter;        Point point;                count = mSelection.size ();        for (int i = 0; i < count; i++)        {            filter = (Filter)mSelection.elementAt (i);            point = filter.getLocation ();            point.translate (translation.x, translation.y);            synchronized (filter.getTreeLock ())            {                filter.setLocation (point.x, point.y);            }        }        mMoved = true;    }    /**     * Check if the current selection set contains the given filter.     * @param filter The filter to check.     * @return <code>true</code> if the filter is a member,     * <code>false</code> otherwise.     */    protected boolean selectionContains (Filter filter)    {        return (mSelection.contains (filter));    }    /**     * Return the last filter added to the selection set.     * @return The last filter added or <code>null</code> if the current     * selection set is empty.     */    protected Filter lastSelected ()    {        Filter ret;                ret = null;        if (0 < mSelection.size ())            ret = (Filter)mSelection.lastElement ();                    return (ret);    }    /**     * Return the current selection set as an array.     * @return The array of selected filters.     */    protected Filter[] getSelection ()    {        Filter[] ret;        ret = new Filter[mSelection.size ()];        mSelection.copyInto (ret);        return (ret);    }    /**     * Serialize the current selection set.     * @return The serialized form of the set of filters.     */    public String serializeSelection ()    {        Filter[] filters;        StringWriter writer;        PrintWriter out;        filters = getSelection ();        writer = new StringWriter (200);        out = new PrintWriter (writer, false);        try        {            out.println (Filter.deconstitute (filters));        }        catch (IOException ioe)        {            ioe.printStackTrace ();        }        finally        {            out.close ();        }                return (writer.getBuffer ().toString ());    }    /**     * Delete the current selection set from the filters in the GUI.     */    public void deleteSelection ()    {        Filter[] filters;        SubFilterList list;        filters = getSelection ();        for (int i = 0; i < filters.length; i++)        {            list = getEnclosing (filters[i]);            if (null != list)                list.removeFilter (filters[i]);            else                mMainPanel.remove (filters[i]);        }        mSelection.clear ();    }        /**     * Check if there is more than one filter selected.     * @return <code>true</code> if only one filter is selected,     * <code>false</code> otherwise.     */    public boolean isSingleSelection ()    {        return (1 == mSelection.size());    }    //    // MouseListener interface    //    /**     * Invoked when the mouse has been clicked on a component.     * @param event The mouse clicked event.     */    public void mouseClicked (MouseEvent event)    {        Object component;        Filter filter;        SubFilterList list;        int modifiers;        boolean contained;        Filter[] filters;                component = event.getSource ();        if (component instanceof Filter)        {            filter = (Filter)component;            modifiers = event.getModifiers ();            contained = selectionContains (filter);                        if (0 != (modifiers & InputEvent.SHIFT_MASK))            {                // add everything from last selected to this command                list = getEnclosed (filter);                if (null != list)                    filters = list.getFilters ();                else                    filters = getFilters ();                Filter last = lastSelected ();                if (null == last)                    addSelection (filter);                else                {           

⌨️ 快捷键说明

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