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 behaviour-

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

The implementation relies on the FiltersHandler 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()
          Basic constructor, requires an attached table.
TableFilterHeader(JTable table)
          Basic constructor, using default IParserModel.
TableFilterHeader(JTable table, AutoChoices mode)
          Advanced constructor, enabling setting the AutoChoices mode
TableFilterHeader(JTable table, IParserModel parserModel)
          Advanced constructor.
TableFilterHeader(JTable table, IParserModel parserModel, AutoChoices mode)
          Full constructor.
 
Method Summary
 void addFilter(IFilter... filter)
          Adds a filter -user specified- to the filter header.
 void addHeaderObserver(IFilterHeaderObserver observer)
          Adds a new observer to the header.
 void addNotify()
          Method automatically invoked when the class ancestor changes.
 AutoChoices getAutoChoices()
          Returns the auto choices flag.
 CustomChoiceDecorator getCustomChoiceDecorator()
          Returns the CustomChoiceDecorator instance.
 Color getDisabledBackground()
          Returns the background color used for disabled editors.
 Color getDisabledForeground()
          Sets the color used for disabled editors.
 Color getErrorForeground()
          Returns the color set by default as foreground on each text editor when the user commits any error on the filter expression.
 IFilterEditor getFilterEditor(int modelColumn)
          Returns the filter editor for the given column in the table model.
 Color getGridColor()
          Returns the color set by default for the header's grid.
 int getMaxHistory()
          Returns the maximum history size.
 int getMaxVisibleRows()
          Returns the maximum number of visible rows in the popup menu.
 IParserModel getParserModel()
          Retrieves the current IParserModel; The returned reference is required to update properties like Format or Comparator instances associated to each class, or whether to ignore case.
 TableFilterHeader.Position getPosition()
          Returns the mode currently associated to the TableHeader.
 int getRowHeightDelta()
          Returns the filter row's height delta.
 Color getSelectionBackground()
          Returns the background color on focused editors.
 Color getSelectionForeground()
          Returns the foreground color on focused editors.
 JTable getTable()
          Returns the table currently attached.
 Color getTextSelectionColor()
          Returns the color set by default as text selection on filters.
 boolean isAutoCompletion()
          Returns true if instant filtering is enabled.
 boolean isEnabled()
          Returns the current enable status.
 boolean isInstantFiltering()
          Returns true if instant filtering is enabled.
 void removeFilter(IFilter... filter)
          Adds a filter -user specified- to the filter header.
 void removeHeaderObserver(IFilterHeaderObserver observer)
          Removes an existing observer from the header.
 void resetFilter()
          Invokes resetFilter on all the editor filters.
 void setAutoChoices(AutoChoices set)
          Sets the auto choices flag.
 void setAutoCompletion(boolean enable)
          Enables instant filtering, as the user edits the filter's text.
 void setBackground(Color bg)
          Sets the background color used by the parsed-based editors.
 void setCustomChoiceDecorator(CustomChoiceDecorator decorator)
          Sets the CustomChoiceDecorator instance.
 void setDisabledBackground(Color dbg)
          Sets the background color used for disabled editors.
 void setDisabledForeground(Color dfg)
          Returns the color used for disabled editors.
 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 errors 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 setGridColor(Color c)
          Sets the color used to draw the header's grid.
 void setInstantFiltering(boolean enable)
          Enables instant filtering, as the user edits the filter's text
The exact way the instant filtering works depends on the associated IParser.parseInstantText(String) implementation.
 void setMaxHistory(int maxHistory)
          Sets the maximum history size, always lower than the max number of visible rows.
 void setMaxVisibleRows(int maxVisibleRows)
          Sets the maximum number of visible rows in the popup menu (a minimum is always enforced).
 void setParserModel(IParserModel parserModel)
          Sets the IParserModel, used to define the parsing of text on the filter editors.
 void setPosition(TableFilterHeader.Position location)
          Defines the behaviour of the header concerning its position related to the table.
 void setRowHeightDelta(int filterRowHeightDelta)
          Setting to add / decrease height to the filter row.
 void setSelectionBackground(Color bg)
          Sets the background color used to represent selected state.
 void setSelectionForeground(Color fg)
          Sets the foreground color used to represent selected state.
 void setTable(JTable table)
          Attaches the table where the filtering will be applied.
 void setTextSelectionColor(Color c)
          Sets the color set by default as text selection on filters.
 void setVisible(boolean flag)
          Hides / makes visible the header.
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
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()
Basic constructor, requires an attached table.


TableFilterHeader

public TableFilterHeader(JTable table)
Basic constructor, using default IParserModel.


TableFilterHeader

public TableFilterHeader(JTable table,
                         AutoChoices mode)
Advanced constructor, enabling setting the AutoChoices mode


TableFilterHeader

public TableFilterHeader(JTable table,
                         IParserModel parserModel)
Advanced constructor.


TableFilterHeader

public TableFilterHeader(JTable table,
                         IParserModel parserModel,
                         AutoChoices mode)
Full constructor.

Method Detail

getFilterEditor

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


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.

Setting the parameter to null effectively de-associates the TableFilterHeader from any previously associated table -which, unless the TableFilterHeader.Position is set to NONE, also implies removing the filter header from the GUI-.


getTable

public JTable getTable()
Returns the table currently attached.


setParserModel

public void setParserModel(IParserModel parserModel)
Sets the IParserModel, used to define the parsing of text on the filter editors.


getParserModel

public IParserModel getParserModel()
Retrieves the current IParserModel; The returned reference is required to update properties like Format or Comparator instances associated to each class, or whether to ignore case.


setAutoChoices

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


getAutoChoices

public AutoChoices getAutoChoices()
Returns the auto choices flag.


setInstantFiltering

public void setInstantFiltering(boolean enable)
Enables instant filtering, as the user edits the filter's text
The exact way the instant filtering works depends on the associated IParser.parseInstantText(String) implementation.


isInstantFiltering

public boolean isInstantFiltering()
Returns true if instant filtering is enabled.


setAutoCompletion

public void setAutoCompletion(boolean enable)
Enables instant filtering, as the user edits the filter's text.


isAutoCompletion

public boolean isAutoCompletion()
Returns true if instant filtering is enabled.


setVisible

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

Overrides:
setVisible in class JComponent

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

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.


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.


setMaxHistory

public void setMaxHistory(int maxHistory)
Sets the maximum history size, always lower than the max number of visible rows.


getMaxHistory

public int getMaxHistory()
Returns the maximum history size.


addFilter

public void addFilter(IFilter... filter)
Adds a filter -user specified- to the filter header.


removeFilter

public void removeFilter(IFilter... filter)
Adds a filter -user specified- to the filter header.


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.


resetFilter

public void resetFilter()

Invokes resetFilter on all the editor filters.

See Also:
IFilterEditor.resetFilter()

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)
Returns the color used for disabled editors.


getDisabledForeground

public Color getDisabledForeground()
Sets the color used for disabled editors.


setDisabledBackground

public void setDisabledBackground(Color dbg)
Sets the background color used for disabled editors.


getDisabledBackground

public Color getDisabledBackground()
Returns the background color used for disabled editors.


setSelectionForeground

public void setSelectionForeground(Color fg)
Sets the foreground color used to represent selected state.


getSelectionForeground

public Color getSelectionForeground()
Returns the foreground color on focused editors.


setSelectionBackground

public void setSelectionBackground(Color bg)
Sets the background color used to represent selected state.


getSelectionBackground

public Color getSelectionBackground()
Returns the background color on focused editors.


setTextSelectionColor

public void setTextSelectionColor(Color c)
Sets the color set by default as text selection on filters.


getTextSelectionColor

public Color getTextSelectionColor()
Returns the color set by default as text selection on filters.


setErrorForeground

public void setErrorForeground(Color fg)
Sets the foreground color used by the parsing text editors when there are errors 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.


setGridColor

public void setGridColor(Color c)
Sets the color used to draw the header's grid.


getGridColor

public Color getGridColor()
Returns the color set by default for the header's grid.


setFont

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

Overrides:
setFont in class JComponent

setRowHeightDelta

public void setRowHeightDelta(int filterRowHeightDelta)
Setting to add / decrease height to the filter row.


getRowHeightDelta

public int getRowHeightDelta()
Returns the filter row's height delta.


setCustomChoiceDecorator

public void setCustomChoiceDecorator(CustomChoiceDecorator decorator)
Sets the CustomChoiceDecorator instance.


getCustomChoiceDecorator

public CustomChoiceDecorator getCustomChoiceDecorator()
Returns the CustomChoiceDecorator instance.


addNotify

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

Overrides:
addNotify in class JComponent

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel