public class TableFilterHeader extends JPanel implements PropertyChangeListener
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);
Modifier and Type | Class and Description |
---|---|
static class |
TableFilterHeader.Position
Location of the header in relation to the table
|
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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()
Returns 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.
|
Color |
getWarningForeground()
Returns the color set by default as foreground on each text editor
when the filter would produce no visible rows
|
boolean |
isAdaptiveChoices()
Returns the adaptive choices mode.
|
boolean |
isAllowedInstantVanishing()
Returns true if vanishing is enabled during instant filtering
|
boolean |
isAutoCompletion()
Returns true if auto completion is enabled.
|
boolean |
isAutoSelection()
Returns true if auto selection is enabled.
|
boolean |
isEnabled()
Returns the current enable status.
|
boolean |
isFilterOnUpdates()
Returns true if the filter is reapplied on updates.
|
boolean |
isHidePopupsOnTableUpdates()
Returns true if popups automatically hide during table updates.
|
boolean |
isInstantFiltering()
Returns true if instant filtering is enabled.
|
void |
propertyChange(PropertyChangeEvent evt)
Required to track model changes on the table
|
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 |
setAdaptiveChoices(boolean enable)
Sets the adaptive choices mode.
|
void |
setAllowedInstantVanishing(boolean enable)
Enables vanishing during instant filtering
If enabled, entering a filter expression that produces no rows will hide; otherwise, the filter is just marked with warning color. |
void |
setAutoChoices(AutoChoices set)
Sets the auto choices flag.
|
void |
setAutoCompletion(boolean enable)
Enables auto completion, as the user edits the filter's text.
|
void |
setAutoSelection(boolean enable)
Enables / Disables auto selection mode
|
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)
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
errors on the filter expressions.
|
void |
setFilterOnUpdates(boolean enable)
Sets the filter on updates flag.
It sets the sortOnUpdates flag on the underlying DefaultRowSorter
it is, in fact, just a helper to set this flag without accessing directly
the row sorter. |
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 |
setHidePopupsOnTableUpdates(boolean enable)
Enables / Disables automatic hiding of popups during table updates
|
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. |
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)
Sets the position of the header 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 |
setWarningForeground(Color fg)
Sets the foreground color used by the parsing text editors when the
associated filter would produce no visible rows.
|
void |
updateUI() |
getAccessibleContext, getUI, getUIClassID, paramString, setUI
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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
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, transferFocusDownCycle, validate, validateTree
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, 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, transferFocusBackward, transferFocusUpCycle
public TableFilterHeader()
public TableFilterHeader(JTable table)
IParserModel
.public TableFilterHeader(JTable table, AutoChoices mode)
AutoChoices
modepublic TableFilterHeader(JTable table, IParserModel parserModel)
public TableFilterHeader(JTable table, IParserModel parserModel, AutoChoices mode)
public IFilterEditor getFilterEditor(int modelColumn)
public void propertyChange(PropertyChangeEvent evt)
propertyChange
in interface PropertyChangeListener
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-.
public JTable getTable()
public void setParserModel(IParserModel parserModel)
IParserModel
, used to define the parsing of text on the
filter editors.public IParserModel getParserModel()
IParserModel
; The returned reference is
required to update properties like Format
or Comparator
instances associated to each class, or whether to ignore case.public void setAutoChoices(AutoChoices set)
public AutoChoices getAutoChoices()
public void setAdaptiveChoices(boolean enable)
public boolean isAdaptiveChoices()
public void setInstantFiltering(boolean enable)
IParser.parseInstantText(String)
public boolean isInstantFiltering()
public void setAllowedInstantVanishing(boolean enable)
public boolean isAllowedInstantVanishing()
public void setAutoCompletion(boolean enable)
public boolean isAutoCompletion()
public void setAutoSelection(boolean enable)
public boolean isAutoSelection()
public void setHidePopupsOnTableUpdates(boolean enable)
public boolean isHidePopupsOnTableUpdates()
public void setFilterOnUpdates(boolean enable)
DefaultRowSorter
it is, in fact, just a helper to set this flag without accessing directly
the row sorter.public boolean isFilterOnUpdates()
public void setVisible(boolean flag)
setVisible
in class JComponent
public void setEnabled(boolean enabled)
setEnabled
in class JComponent
public boolean isEnabled()
public void setPosition(TableFilterHeader.Position location)
public TableFilterHeader.Position getPosition()
public void setMaxVisibleRows(int maxVisibleRows)
public int getMaxVisibleRows()
public void setMaxHistory(int maxHistory)
public int getMaxHistory()
public void addFilter(IFilter... filter)
public void removeFilter(IFilter... filter)
public void addHeaderObserver(IFilterHeaderObserver observer)
public void removeHeaderObserver(IFilterHeaderObserver observer)
public void resetFilter()
Invokes resetFilter on all the editor filters.
IFilterEditor.resetFilter()
public void setBackground(Color bg)
setBackground
in class JComponent
public void setForeground(Color fg)
setForeground
in class JComponent
public void setDisabledForeground(Color dfg)
public Color getDisabledForeground()
public void setDisabledBackground(Color dbg)
public Color getDisabledBackground()
public void setSelectionForeground(Color fg)
public Color getSelectionForeground()
public void setSelectionBackground(Color bg)
public Color getSelectionBackground()
public void setTextSelectionColor(Color c)
public Color getTextSelectionColor()
public void setErrorForeground(Color fg)
public Color getErrorForeground()
public void setWarningForeground(Color fg)
public Color getWarningForeground()
Returns the color set by default as foreground on each text editor when the filter would produce no visible rows
public void setGridColor(Color c)
public Color getGridColor()
public void setFont(Font font)
setFont
in class JComponent
public void setRowHeightDelta(int filterRowHeightDelta)
public int getRowHeightDelta()
public void setCustomChoiceDecorator(CustomChoiceDecorator decorator)
CustomChoiceDecorator
instance.public CustomChoiceDecorator getCustomChoiceDecorator()
CustomChoiceDecorator
instance.public void addNotify()
addNotify
in class JComponent