com.sciapp.filter
Class FilterTablePanel

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.sciapp.filter.FilterTablePanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class FilterTablePanel
extends JPanel

FilterTablePanel is a panel through which filter events are propagated to a FilterTableModel. FilterTablePanel uses a box layout with horizontal orientation to layout the different gui components. You can customize its appearance by overriding makePanel, in which you must supply code to add these gui components to the panel. FilterTablePanel provides filters for the fields passed as arguments in the constructor. Additionally, it defines two more filtering options: no filter and filter on all columns.


Nested Class Summary
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JCheckBox caseSensitive
          a checkbox used by stringfilters to denote case(in)sensitivity.
protected  HashMap defaultFiltersByColumnClass
          A table of objects that filter data, indexed by class.
protected  JTextField expression
          a textfield used to input the filter pattern.
protected  JComboBox fieldBox
          a combobox that contains the fields that we are able to filter.
protected  JComboBox fieldBoxOptions
          a combobox that presents the different options of the current filter to the user.
protected  JButton filterButton
          a button that when clicked, fires the filter event.
protected  JCheckBox filterOn
          a checkbox that shows if the filter displayed is active or not.
 
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
FilterTablePanel(String[] fields)
          Constructs a FilterTablePanel with fields as the fields that we are able to filter.
FilterTablePanel(String[] fields, Class[] classes)
          Constructs a FilterTablePanel with fields as the fields that we are able to filter and classes as the corresponding classes of each field.
FilterTablePanel(TableModel tableModel)
          Constructs a FilterTablePanel by quering tableModel for the filtering fields and the corresponding classes.
 
Method Summary
 void addTableFilterListener(TableFilterListener l)
          Adds a TableFilterListener that is notified each time a filter event is generated.
protected  void createDefaultFilters()
          Creates default filters for objects, strings, numbers and boolean values.
 Filter getDefaultFilter(Class columnClass)
          Returns the filter to use for the class defined by columnClass.
 boolean getFilterOnKey()
          Returns a boolean value that if true, filter events are fired whenever a key press is detected on a text field, otherwise the user must press the Enter key for this to happen.
protected  void makePanel()
          Adds the gui components to the FilterTablePanel using a box layout with horizontal orientation.
 void removeTableFilterListener(TableFilterListener l)
          Removes a TableFilterListener from the list of listeners that is notified each time a filter event is generated.
 void setDefaultFilter(Class columnClass, Filter filter)
          Sets the default filter for columnClass.
 void setFilterOnKey(boolean key)
          Set key to true for filter events to be fired upon key detection.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

defaultFiltersByColumnClass

protected HashMap defaultFiltersByColumnClass
A table of objects that filter data, indexed by class.


expression

protected JTextField expression
a textfield used to input the filter pattern.


filterButton

protected JButton filterButton
a button that when clicked, fires the filter event.


filterOn

protected JCheckBox filterOn
a checkbox that shows if the filter displayed is active or not.


fieldBox

protected JComboBox fieldBox
a combobox that contains the fields that we are able to filter.


fieldBoxOptions

protected JComboBox fieldBoxOptions
a combobox that presents the different options of the current filter to the user.


caseSensitive

protected JCheckBox caseSensitive
a checkbox used by stringfilters to denote case(in)sensitivity.

Constructor Detail

FilterTablePanel

public FilterTablePanel(String[] fields)
Constructs a FilterTablePanel with fields as the fields that we are able to filter. The corresponing filter for each field is initialized to a StringFilter.

Parameters:
fields - the fields, which ususally are the columns of a table.

FilterTablePanel

public FilterTablePanel(String[] fields,
                        Class[] classes)
Constructs a FilterTablePanel with fields as the fields that we are able to filter and classes as the corresponding classes of each field. An IllegalArgumentException is thrown if fields and classes are not of the same length.

Parameters:
fields - the fields, which ususally are the columns of a table.
classes - the associated classes to fields.

FilterTablePanel

public FilterTablePanel(TableModel tableModel)
Constructs a FilterTablePanel by quering tableModel for the filtering fields and the corresponding classes. The filter columns and classes are constructed by calling the getColumnName and getColumnClass methods of TableModel respectively. Therefore, these methods should not return null.

Parameters:
tableModel - the tablemodel to query
Method Detail

addTableFilterListener

public void addTableFilterListener(TableFilterListener l)
Adds a TableFilterListener that is notified each time a filter event is generated.

Parameters:
l - the TableFilterListener

createDefaultFilters

protected void createDefaultFilters()
Creates default filters for objects, strings, numbers and boolean values.


getDefaultFilter

public Filter getDefaultFilter(Class columnClass)
Returns the filter to use for the class defined by columnClass.

Returns:
the filter that corresponds to columnClass.

getFilterOnKey

public boolean getFilterOnKey()
Returns a boolean value that if true, filter events are fired whenever a key press is detected on a text field, otherwise the user must press the Enter key for this to happen.

Returns:
true for filter events to be fired upon key detection

makePanel

protected void makePanel()
Adds the gui components to the FilterTablePanel using a box layout with horizontal orientation. If you override this method, you only need to supply code to add the components to the panel, since an instance of those has already been created.


removeTableFilterListener

public void removeTableFilterListener(TableFilterListener l)
Removes a TableFilterListener from the list of listeners that is notified each time a filter event is generated.

Parameters:
l - the TableFilterListener

setDefaultFilter

public void setDefaultFilter(Class columnClass,
                             Filter filter)
Sets the default filter for columnClass.

Parameters:
columnClass - the Class with which a filter we want to associate
filter - the filter to set

setFilterOnKey

public void setFilterOnKey(boolean key)
Set key to true for filter events to be fired upon key detection.

Parameters:
key - true if filter events are to be fired upon key detection