HTML Parser Home Page

org.htmlparser.parserapplications.filterbuilder
Class Filter

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.htmlparser.parserapplications.filterbuilder.Filter
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Cloneable, NodeFilter
Direct Known Subclasses:
AndFilterWrapper, HasAttributeFilterWrapper, HasChildFilterWrapper, HasParentFilterWrapper, HasSiblingFilterWrapper, NodeClassFilterWrapper, NotFilterWrapper, OrFilterWrapper, RegexFilterWrapper, StringFilterWrapper, TagNameFilterWrapper

public abstract class Filter
extends JComponent
implements NodeFilter

Base class for all filters. Provides common functionality applicable to all filters.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected static Hashtable mWrappers
          Map from cilter class to wrapper.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Filter()
          Create a filter.
 
Method Summary
static String deconstitute(Filter[] filters)
          Returns a string serialization of the filters.
static byte[] deserialize(String string)
          Convert a sequence of hexadecimal characters back into a byte array.
abstract  String getDescription()
          Get the name of the filter.
protected static SubFilterList getEnclosed(Component component)
          Get the enclosed sub filter list if any.
 Icon getIcon()
          Get the icon for the filter.
abstract  String getIconSpec()
          Get the resource name for the icon.
abstract  NodeFilter getNodeFilter()
          Get the underlying node filter object.
abstract  NodeFilter[] getSubNodeFilters()
          Get the underlying node filter's subordinate filters.
static Filter instantiate(String class_name)
          Create a new filter from the class name.
static void newline(StringBuffer out)
          Append a newline to the buffer.
static byte[] pickle(Object object)
          Serialize an object to a byte array.
static Filter[] reconstitute(String string, Parser context)
          Returns the filters represented by the string.
static String serialize(byte[] data)
          Serialize a byte array to a String.
 void setExpanded(boolean expanded)
          Set the expanded state for the component.
abstract  void setNodeFilter(NodeFilter filter, Parser context)
          Assign the underlying node filter for this wrapper.
 void setSelected(boolean selected)
          Set the 'selected look' for the component.
abstract  void setSubNodeFilters(NodeFilter[] filters)
          Assign the underlying node filter's subordinate filters.
static void spaces(StringBuffer out, int count)
          Append count spaces to the buffer.
abstract  String toJavaCode(StringBuffer out, int[] context)
          Convert this filter into Java code.
 String toString()
          Returns a string representation of this component and its values.
static Object unpickle(byte[] data)
          Reconstitute a serialized object.
static Filter wrap(NodeFilter filter, Parser context)
          Returns a wrapped filter.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.htmlparser.NodeFilter
accept
 

Field Detail

mWrappers

protected static Hashtable mWrappers
Map from cilter class to wrapper. Populated as part of each wrapper being loaded.

Constructor Detail

Filter

public Filter()
Create a filter. Set up the default display. Only a border with the label of the filter name, returned by getDescription(), and an icon, returned by getIcon().

Method Detail

instantiate

public static Filter instantiate(String class_name)
Create a new filter from the class name.

Parameters:
class_name - The class to instatiate.
Returns:
The constructed filter object.

getDescription

public abstract String getDescription()
Get the name of the filter.

Returns:
A descriptive name for the filter.

getNodeFilter

public abstract NodeFilter getNodeFilter()
Get the underlying node filter object.

Returns:
The node filter object suitable for serialization.

setNodeFilter

public abstract void setNodeFilter(NodeFilter filter,
                                   Parser context)
Assign the underlying node filter for this wrapper.

Parameters:
filter - The filter to wrap.
context - The parser to use for conditioning this filter. Some filters need contextual information to provide to the user, i.e. for tag names or attribute names or values, so the Parser context is provided.

getSubNodeFilters

public abstract NodeFilter[] getSubNodeFilters()
Get the underlying node filter's subordinate filters.

Returns:
The node filter object's contained filters.

setSubNodeFilters

public abstract void setSubNodeFilters(NodeFilter[] filters)
Assign the underlying node filter's subordinate filters.

Parameters:
filters - The filters to insert into the underlying node filter.

toJavaCode

public abstract String toJavaCode(StringBuffer out,
                                  int[] context)
Convert this filter into Java code. Output whatever text necessary and return the variable name.

Parameters:
out - The output buffer.
context - Three integers as follows:
  • indent level - the number of spaces to insert at the beginning of each line
  • filter number - the next available filter number
  • filter array number - the next available array of filters number
  • Returns:
    The variable name to use when referencing this filter (usually "filter" + context[1]++)

    getIcon

    public Icon getIcon()
    Get the icon for the filter. Loads the resource specified by getIconSpec() as an icon.

    Returns:
    The icon or null if it was not found.

    getIconSpec

    public abstract String getIconSpec()
    Get the resource name for the icon.

    Returns:
    The icon resource specification.

    toString

    public String toString()
    Returns a string representation of this component and its values.

    Overrides:
    toString in class Component
    Returns:
    A string representation of this component.

    pickle

    public static byte[] pickle(Object object)
                         throws IOException
    Serialize an object to a byte array.

    Parameters:
    object - The object to be pickled.
    Returns:
    The serialized object.
    Throws:
    IOException - If the output stream complains (unlikely).

    unpickle

    public static Object unpickle(byte[] data)
                           throws IOException,
                                  ClassNotFoundException
    Reconstitute a serialized object.

    Parameters:
    data - The pickled object.
    Returns:
    The reconstituted object.
    Throws:
    IOException - If the input stream complains.
    ClassNotFoundException - If the serialized object class cannot be located.

    serialize

    public static String serialize(byte[] data)
    Serialize a byte array to a String. Convert each byte from the serialized object into a couple of hexadecimal characters.

    Parameters:
    data - The serialized object as a byte array.
    Returns:
    The string representing the serialized object.

    deserialize

    public static byte[] deserialize(String string)
    Convert a sequence of hexadecimal characters back into a byte array.

    Parameters:
    string - The string to convert (must be correct hex characters).
    Returns:
    The bytes as an array.

    deconstitute

    public static String deconstitute(Filter[] filters)
                               throws IOException
    Returns a string serialization of the filters.

    Parameters:
    filters - The list of filters to serialize.
    Returns:
    A string representation of the filters.
    Throws:
    IOException - If serialization fails.

    reconstitute

    public static Filter[] reconstitute(String string,
                                        Parser context)
    Returns the filters represented by the string.

    Parameters:
    string - The string with serialized node filters.
    context - The context from which to extract meaningful values for GUI choices (which aren't serialized).
    Returns:
    The filters gleaned from the string.
    See Also:
    wrap(org.htmlparser.NodeFilter, org.htmlparser.Parser)

    getEnclosed

    protected static SubFilterList getEnclosed(Component component)
    Get the enclosed sub filter list if any. Todo: rationalize with FilterBuilder's method(s) of the same name.

    Parameters:
    component - The component that's supposedly enclosing the list.
    Returns:
    The enclosed component or null otherwise.

    wrap

    public static Filter wrap(NodeFilter filter,
                              Parser context)
    Returns a wrapped filter.

    Parameters:
    filter - A filter to be wrapped by GUI components.
    context - The context within which to wrap the object. Some wrappers need context to set up useful choices for the user.
    Returns:
    The filter to wrap.

    setSelected

    public void setSelected(boolean selected)
    Set the 'selected look' for the component.

    Parameters:
    selected - If true, 'select' this component, otherwise 'deselect' it.

    setExpanded

    public void setExpanded(boolean expanded)
    Set the expanded state for the component. This sets invisible all but the JLabel component in the comand component.

    Parameters:
    expanded - If true, 'expand' this component, otherwise 'collapse' it.

    spaces

    public static void spaces(StringBuffer out,
                              int count)
    Append count spaces to the buffer.

    Parameters:
    out - The buffer to append to.
    count - The number of spaces to append.

    newline

    public static void newline(StringBuffer out)
    Append a newline to the buffer.

    Parameters:
    out - The buffer to append to.

    © 2005 Derrick Oswald
    Jun 10, 2006

    HTML Parser is an open source library released under LGPL. SourceForge.net