Site hosted at byteslooser and Grasia! mirrors.


com.byteslooser.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 com.byteslooser.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 the JTable, or just below, using the same size -and resizing- as the table itself.

Each column can have a different type of editor associated, and there are four predefined editors:

Users can also provide customized editors, or modify the behaviour or appearance of the created ones

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

Author:
Luis M Pena - byteslooser@gmail.com
See Also:
Serialized Form

Nested Class Summary
static class TableFilterHeader.EditorMode
          Editor mode for the filter editors associated to each column
 
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
static float DEFAULT_FONT_PROPORTION
          Default proportion size related to 'normal' cell fonts.
 
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(TableFilterHeader.EditorMode mode)
          Constructor; the object is functional after a table is attached
 
Method Summary
 Color getErrorBackground()
          Returns the color set by default as background on each text editor when the user commits any error on the filter expression.
 Color getErrorForeground()
          Returns the color set by default as foreground on each text editor when the user commits any error on the filter expression.
 Color getFilterBackground()
          Returns the color set by default as background on each editor.
 ITableFilterEditor getFilterEditor(int modelColumn)
          Returns the filter editor for the given column.
 Color getFilterForeground()
          Returns the color set by default as foreground on each editor.
 TableFilterHeader.EditorMode getMode()
          Returns the mode currently associated to the TableHeader
 JTable getTable()
          Returns the table currently atached
 TableFilter getTableFilter()
          Returns the internal table filter.
 IFilterTextParser getTextParser()
          Returns the parser used on plain text filters.
 void resetFilters()
          Invokes resetFilter on all the editor filters.
 void resetMode(TableFilterHeader.EditorMode mode)
          Defines the type of filter editors associated by default to the columns, and recreates all the editors with the given type
 TextChoiceFilterEditor setBasicFilterEditor(int modelColumn)
          Sets a filter editor of type TextChoiceFilterEditor on the given column; this editor is a JComboBox which allows the user to enter complex filter expressions, with a historic of the last entries
 TableChoiceFilterEditor setChoiceFilterEditor(int modelColumn)
          Sets a filter editor of type TableChoiceFilterEditor on the given column; this editor is a JComboBox which only allows the user to enter predefined options.
 void setEnabled(boolean enabled)
          Enables/Disables programatically the filters
 void setErrorBackground(Color bg)
          Sets the background color used by the parsing text editors when there are error on the filter expressions.
 void setErrorForeground(Color fg)
          Sets the foreground color used by the parsing text editors when there are error on the filter expressions.
 void setFilterBackground(Color bg)
          Sets the background color used by the parsed-based editors.
 void setFilterEditor(int modelColumn, ITableFilterEditor editor)
          Sets a specific filter editor for a given column.
 void setFilterForeground(Color fg)
          Sets the foreground color used by the editors.
 void setFont(Font font)
          Sets the font used on all the editors.
 void setMode(TableFilterHeader.EditorMode mode)
          Defines the type of the filter editors associated by default to the columns.
 TextFilterEditor setSlimFilterEditor(int modelColumn)
          Sets a filter editor of type TextFilterEditor on the given column; this editor is a JTextField which allows the user to enter complex filter expressions, and includes a contextual menu to facilitate the input of older entries
 void setTable(JTable table)
          Attachs the table where the filtering will be applied.
 void setTableFilter(TableFilter filter)
          Sets a new table filter.
 void setTextParser(IFilterTextParser parser)
          Sets the parser to be used on text filter editors.
 void updateFilter()
          Invokes updateFilter on all the editor filters.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, 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, 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, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_FONT_PROPORTION

public static final float DEFAULT_FONT_PROPORTION
Default proportion size related to 'normal' cell fonts.

See Also:
Constant Field Values
Constructor Detail

TableFilterHeader

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

See Also:
setTable(JTable)

TableFilterHeader

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

See Also:
setMode(com.byteslooser.filters.gui.TableFilterHeader.EditorMode)
Method Detail

setTable

public void setTable(JTable table)

Attachs the table where the filtering will be applied.

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


getTable

public JTable getTable()
Returns the table currently atached


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.


setMode

public void setMode(TableFilterHeader.EditorMode mode)

Defines the type of the filter editors associated by default to the columns.

If the filter editors have been already created, they are not removed, the mode will only be used on newly created editors (like when adding columns to the table)

See Also:
resetMode(com.byteslooser.filters.gui.TableFilterHeader.EditorMode)

getMode

public TableFilterHeader.EditorMode getMode()
Returns the mode currently associated to the TableHeader


resetMode

public void resetMode(TableFilterHeader.EditorMode mode)
Defines the type of filter editors associated by default to the columns, and recreates all the editors with the given type

See Also:
setMode(com.byteslooser.filters.gui.TableFilterHeader.EditorMode)

resetFilters

public void resetFilters()

Invokes resetFilter on all the editor filters.

Note that the exact semantics depend on the exact editor type.

See Also:
ITableFilterEditor.resetFilter()

updateFilter

public void updateFilter()

Invokes updateFilter on all the editor filters.

Note that the exact semantics depend on the exact editor type.

See Also:
ITableFilterEditor.updateFilter()

setFilterBackground

public void setFilterBackground(Color bg)

Sets the background color used by the parsed-based editors.


getFilterBackground

public Color getFilterBackground()

Returns the color set by default as background on each editor.

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


setFilterForeground

public void setFilterForeground(Color fg)

Sets the foreground color used by the editors.

This method is a helper, invoking JComponent.setForeground(Color) on each editor component, already created or not.


getFilterForeground

public Color getFilterForeground()

Returns the color set by default as foreground on each editor.

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


setErrorForeground

public void setErrorForeground(Color fg)

Sets the foreground color used by the parsing text editors when there are error on the filter expressions.

See Also:
ITableFilterTextBasedEditor.setErrorForeground(Color)

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


setErrorBackground

public void setErrorBackground(Color bg)

Sets the background color used by the parsing text editors when there are error on the filter expressions.

See Also:
ITableFilterTextBasedEditor.setErrorBackground(Color)

getErrorBackground

public Color getErrorBackground()

Returns the color set by default as background 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


getFilterEditor

public ITableFilterEditor getFilterEditor(int modelColumn)

Returns the filter editor for the given column.

By default, all FilterEditors are instances of TextChoiceFilterEditor

Parameters:
modelColumn - The column number in the table model

setFilterEditor

public void setFilterEditor(int modelColumn,
                            ITableFilterEditor editor)
Sets a specific filter editor for a given column.

Parameters:
modelColumn - The column number in the table model
editor - The filter editor, which can be null to place a TableFilterHeader.EditorMode NULL editor.

setChoiceFilterEditor

public TableChoiceFilterEditor setChoiceFilterEditor(int modelColumn)

Sets a filter editor of type TableChoiceFilterEditor on the given column; this editor is a JComboBox which only allows the user to enter predefined options. The initial options are the values in the table model for the given column.

If the given column already contains an editor of the given type, the existing editor is returned.

Parameters:
modelColumn - The column number in the table model
Returns:
the created TableChoiceFilterEditor editor, which can be then directly manipulated by the user

setSlimFilterEditor

public TextFilterEditor setSlimFilterEditor(int modelColumn)

Sets a filter editor of type TextFilterEditor on the given column; this editor is a JTextField which allows the user to enter complex filter expressions, and includes a contextual menu to facilitate the input of older entries

If the given column already contains an editor of the given type, the existing editor is returned.

Parameters:
modelColumn - The column number in the table model
Returns:
the created TextFilterEditor editor, which can be then directly manipulated by the user

setBasicFilterEditor

public TextChoiceFilterEditor setBasicFilterEditor(int modelColumn)

Sets a filter editor of type TextChoiceFilterEditor on the given column; this editor is a JComboBox which allows the user to enter complex filter expressions, with a historic of the last entries

If the given column already contains an editor of the given type, the existing editor is returned.

Parameters:
modelColumn - The column number in the table model
Returns:
the created TextChoiceFilterEditor editor, which can be then directly manipulated by the user

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.

By default, it is an instance of FilterTextParser

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.

See Also:
ITableFilterTextBasedEditor.setTextParser(IFilterTextParser)

setEnabled

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

Overrides:
setEnabled in class JComponent
See Also:
JComponent.setEnabled(boolean)

setFont

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

Overrides:
setFont in class JComponent
See Also:
JComponent.setFont(java.awt.Font)