net.coderazzi.filters.gui
Class TableFilterHeader

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by net.coderazzi.filters.gui.TableFilterHeader
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class TableFilterHeader
extends JPanel

Implementation of a table filter that displays a set of editors associated to each table's column. This is the main Gui component in this library.

These editors are moved and resized as the table's columns are resized, so this Swing component is better suited to be displayed atop, inline the JTable, or just below, using the same size -and resizing- as the table itself. The position can be automatically handled by the header itself -that is the default behavior-

The editor associated to each column has the type FilterEditor, and can be manipulated separately.

The implementation relies on the TableFilter class, please read its documentation to understand the requirements on the table and its model, and how it is affected by this filter

The default settings can be modified by using system properties or by setting values on the singleton FilterSettings instance

Providing a filter header to an existing table is as easy as doing:

TableFilterHeader filter = new TableFilterHeader(table);

Author:
Luis M Pena - lu@coderazzi.net
See Also:
Serialized Form

Nested Class Summary
static class TableFilterHeader.Position
          Location of the header in relation to the table
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
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.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
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
TableFilterHeader()
          Constructor; the object is functional after a table is attached
TableFilterHeader(JTable table)
          Constructor, using the default location
TableFilterHeader(JTable table, TableFilterHeader.Position location)
          Full constructor
 
Method Summary
 void addHeaderObserver(IFilterHeaderObserver observer)
          Adds a new observer to the header
 void addNotify()
          Method automatically invoked when the class ancestor changes
protected  void customizeEditor(FilterEditor editor)
          Customizes the editor, can be overridden for custom appearance
 Color getDisabledForeground()
          Sets the color used for disabled fields
 Color getErrorForeground()
          Returns the color set by default as foreground on each text editor when the user commits any error on the filter expression.
 FilterEditor getFilterEditor(int modelColumn)
          Returns the filter editor for the given column in the table model
 int getMaxVisibleRows()
          Returns the maximum number of visible rows in the popup menu
 TableFilterHeader.Position getPosition()
          Returns the mode currently associated to the TableHeader
 JTable getTable()
          Returns the table currently attached
 TableFilter getTableFilter()
          Returns the internal table filter.
 IFilterTextParser getTextParser()
          Returns the parser used on plain text filters.
 boolean isAutoOptions()
          Returns the auto options flag
 boolean isEnabled()
          Returns the current enable status
 void removeHeaderObserver(IFilterHeaderObserver observer)
          Removes an existing observer from the header
 void resetFilter()
          Invokes resetFilter on all the editor filters.
 void setAutoOptions(boolean set)
          Sets the auto options flag.
 void setBackground(Color bg)
          Sets the background color used by the parsed-based editors.
 void setDisabledForeground(Color dfg)
          Sets the color used for disabled fields
 void setEnabled(boolean enabled)
          Enables/Disables the filters
 void setErrorForeground(Color fg)
          Sets the foreground color used by the parsing text editors when there are error on the filter expressions.
 void setFont(Font font)
          Sets the font used on all the editors.
 void setForeground(Color fg)
          Sets the foreground color used by the editors.
 void setMaxVisibleRows(int maxVisibleRows)
          Sets the maximum number of visible rows in the popup menu (a minimum is always enforced)
 void setPosition(TableFilterHeader.Position location)
          Defines the behaviour of the header concerning its position related to the table.
 void setTable(JTable table)
          Attaches the table where the filtering will be applied.
 void setTableCellRenderer(int modelColumn, TableCellRenderer renderer)
          Sets as renderer for the editor a generic TableCellRenderer, as used by the JTable
 void setTableFilter(TableFilter filter)
          Sets a new table filter.
 void setTextParser(IFilterTextParser parser)
          Sets the parser to be used on text filter editors.
 void setVisible(boolean flag)
          Hides / makes visible the header
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
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, 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, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TableFilterHeader

public TableFilterHeader()
Constructor; the object is functional after a table is attached

See Also:
setTable(JTable)

TableFilterHeader

public TableFilterHeader(JTable table)
Constructor, using the default location

See Also:
setPosition(net.coderazzi.filters.gui.TableFilterHeader.Position)

TableFilterHeader

public TableFilterHeader(JTable table,
                         TableFilterHeader.Position location)
Full constructor

See Also:
setTable(JTable), setPosition(net.coderazzi.filters.gui.TableFilterHeader.Position)
Method Detail

setTable

public void setTable(JTable table)

Attaches the table where the filtering will be applied.

It will be created a row of editors, that follow the size and position of each of the columns in the table.


getTable

public JTable getTable()
Returns the table currently attached


getTableFilter

public TableFilter getTableFilter()
Returns the internal table filter. This can be used to attach additional filters.


setTableFilter

public void setTableFilter(TableFilter filter)

Sets a new table filter.

The filters associated to the initial TableFilter are transferred to the new one.


setPosition

public void setPosition(TableFilterHeader.Position location)

Defines the behaviour of the header concerning its position related to the table.


getPosition

public TableFilterHeader.Position getPosition()
Returns the mode currently associated to the TableHeader


resetFilter

public void resetFilter()

Invokes resetFilter on all the editor filters.

Invokes resetFilter on all the editors. This does not only implies invoking FilterEditor.resetFilter(), as it tries to reset the original editor options for enums and boolean types

See Also:
FilterEditor.resetFilter()

addNotify

public void addNotify()
Method automatically invoked when the class ancestor changes

Overrides:
addNotify in class JComponent

setBackground

public void setBackground(Color bg)
Sets the background color used by the parsed-based editors.

Overrides:
setBackground in class JComponent

setForeground

public void setForeground(Color fg)
Sets the foreground color used by the editors.

Overrides:
setForeground in class JComponent

setDisabledForeground

public void setDisabledForeground(Color dfg)
Sets the color used for disabled fields


getDisabledForeground

public Color getDisabledForeground()
Sets the color used for disabled fields


setErrorForeground

public void setErrorForeground(Color fg)
Sets the foreground color used by the parsing text editors when there are error on the filter expressions.


getErrorForeground

public Color getErrorForeground()

Returns the color set by default as foreground on each text editor when the user commits any error on the filter expression.

Note that the color of each specific editor can be different, if the user customizes it directly


setMaxVisibleRows

public void setMaxVisibleRows(int maxVisibleRows)
Sets the maximum number of visible rows in the popup menu (a minimum is always enforced)


getMaxVisibleRows

public int getMaxVisibleRows()
Returns the maximum number of visible rows in the popup menu


customizeEditor

protected void customizeEditor(FilterEditor editor)
Customizes the editor, can be overridden for custom appearance


getFilterEditor

public FilterEditor getFilterEditor(int modelColumn)
Returns the filter editor for the given column in the table model


setTableCellRenderer

public void setTableCellRenderer(int modelColumn,
                                 TableCellRenderer renderer)

Sets as renderer for the editor a generic TableCellRenderer, as used by the JTable

This method allows reusing a renderer already written for a table as the editor's renderer, but it has an important restriction: it only works if the renderer does not depend on the cell coordinates


setTextParser

public void setTextParser(IFilterTextParser parser)

Sets the parser to be used on text filter editors.

This parser overrides any parser already set on the separate columns filters.


getTextParser

public IFilterTextParser getTextParser()

Returns the parser used on plain text filters.

Each column can have its own Parser, if setTextParser is used on the associated filter. In that case, it is needed to access each filter to obtain the used parser.


setVisible

public void setVisible(boolean flag)
Hides / makes visible the header

Overrides:
setVisible in class JComponent

setAutoOptions

public void setAutoOptions(boolean set)
Sets the auto options flag. When set, all editors are automatically populated with options extracted from the table's content -and updated as the table is updated-.


isAutoOptions

public boolean isAutoOptions()
Returns the auto options flag


setEnabled

public void setEnabled(boolean enabled)
Enables/Disables the filters

Overrides:
setEnabled in class JComponent

isEnabled

public boolean isEnabled()
Returns the current enable status

Overrides:
isEnabled in class Component

setFont

public void setFont(Font font)
Sets the font used on all the editors.

Overrides:
setFont in class JComponent

addHeaderObserver

public void addHeaderObserver(IFilterHeaderObserver observer)
Adds a new observer to the header


removeHeaderObserver

public void removeHeaderObserver(IFilterHeaderObserver observer)
Removes an existing observer from the header