Site hosted at byteslooser and Grasia! mirrors.


com.byteslooser.filters.gui.editors
Class ChoiceFilterEditor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by com.byteslooser.filters.gui.editors.ChoiceFilterEditor
All Implemented Interfaces:
ITableFilterEditor, ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener
Direct Known Subclasses:
TableChoiceFilterEditor

public class ChoiceFilterEditor
extends JComboBox
implements ITableFilterEditor

Table filter editor based on selection of given expression choices, represented by a JComboBox.

Although it is initially less powerful than the editors based on text expressions, it is more customizable, in behaviour and appearance. It supports two specific ways to customize its appearance and contents:

An example of this second customization would be, in a column displaying people's ages, to setup several age ranges as choices, like 'ages below 25', '25 to 35', 'over 35'

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

Nested Class Summary
protected  class ChoiceFilterEditor.Filter
          Implementation of a RowFilter for the ChoiceFilterEditor
static interface ChoiceFilterEditor.IChoice
          Interface to delegate to the application how a selected option in the editor matches a RowFilter.Entry instance.
static interface ChoiceFilterEditor.IRenderer
          Renderer to display the different choices
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager
 
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
protected  Object[] choices
          The list of choices presented to the user
protected  Object currentChoice
          The last selected choice
protected  ChoiceFilterEditor.Filter filter
          The internal filter implementation
protected  int filterPosition
          This is the filter position requested to the RowFilter.Entry; it corresponds, in the case of a table, to the column to which this editor is associated.
static String NO_FILTER
          The object representing 'no filter', that is, it is the option to be selected for this editor to perform no filtering.
protected  Object otherChoices
          The object representing the notion of 'other choices'.
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
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
ChoiceFilterEditor()
          Default constructor.
ChoiceFilterEditor(int filterPosition, Object labelForOtherChoices, Object... choices)
          Full constructor
 
Method Summary
 Component getComponent()
          Provides the GUI component associated to the given editor
 IFilterObservable getFilterObservable()
          Provides the IFilterObservable associated to the given instance
 int getFilterPosition()
          Returns the filter position
 void resetFilter()
          Unselects any choice, removing, therefore, any filtering by this editor.
protected  void setChoiceModel(Object selected, Object otherChoices, Object[] choices)
          Sets the model for the combo box
 void setChoiceRenderer(ChoiceFilterEditor.IRenderer renderer)
          Sets the choice renderer, giving full access on how to render the contents of the component.
 void setChoices(ChoiceFilterEditor.IChoice... choices)
          Sets the choices to be displayed.
 void setChoices(Object otherChoices, Object... choices)
          Sets the elements to be used as choices, and the element to be used as 'other choices'.
 void setEnabled(boolean enabled)
           
 void setFilterPosition(int filterPosition)
          Sets the filter position requested to the RowFilter.Entry; it corresponds, in the case of a table, to the column to which this editor is associated.
 void updateFilter()
          It propagates the current filter to any listeners
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setRenderer, setSelectedIndex, setSelectedItem, setUI, showPopup, 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, 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, setFont, 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

NO_FILTER

public static final String NO_FILTER
The object representing 'no filter', that is, it is the option to be selected for this editor to perform no filtering.


filterPosition

protected int filterPosition

This is the filter position requested to the RowFilter.Entry; it corresponds, in the case of a table, to the column to which this editor is associated.


choices

protected Object[] choices
The list of choices presented to the user


otherChoices

protected Object otherChoices

The object representing the notion of 'other choices'.

If the user has multiple choices, but they do not cover all the possibilities, selection 'other choices', if present, will filter out all the choices not selected

This is, therefore, a special choice: selecting is equivalent to select any value not covered as the other provided choices.

It can be null, if the concept is not used or applicable.


currentChoice

protected Object currentChoice
The last selected choice


filter

protected ChoiceFilterEditor.Filter filter
The internal filter implementation

Constructor Detail

ChoiceFilterEditor

public ChoiceFilterEditor()
Default constructor. It is yet needed to set, at least, the choices to show to the user


ChoiceFilterEditor

public ChoiceFilterEditor(int filterPosition,
                          Object labelForOtherChoices,
                          Object... choices)
Full constructor

Parameters:
filterPosition - This is the filter position requested to the RowFilter.Entry; it corresponds, in the case of a table, to the column to which this editor is associated.
labelForOtherChoices - The object representing the notion of 'other choices'. This is a special choice: selecting is equivalent to select any value not covered in the current choices. It can be null, if the concept is not applicable.
choices - The choices to present to the user
See Also:
setFilterPosition(int), setChoices(Object, Object[])
Method Detail

setChoices

public void setChoices(ChoiceFilterEditor.IChoice... choices)

Sets the choices to be displayed.

Note that, in this case, there is no concept of 'other choices'; if needed, the invoker should provide a choice to cover that possible case.


setChoices

public void setChoices(Object otherChoices,
                       Object... choices)

Sets the elements to be used as choices, and the element to be used as 'other choices'.

If the user has multiple choices, but they do not cover all the possibilities, selection 'other choices', if present, will filter out all the choices not selected.


setChoiceRenderer

public void setChoiceRenderer(ChoiceFilterEditor.IRenderer renderer)

Sets the choice renderer, giving full access on how to render the contents of the component.

This is a wrapper method around JComboBox.setRenderer(ListCellRenderer)


setFilterPosition

public void setFilterPosition(int filterPosition)

Sets the filter position requested to the RowFilter.Entry; it corresponds, in the case of a table, to the column to which this editor is associated.


getFilterPosition

public int getFilterPosition()
Returns the filter position

See Also:
setFilterPosition(int)

getFilterObservable

public IFilterObservable getFilterObservable()
Description copied from interface: ITableFilterEditor
Provides the IFilterObservable associated to the given instance

Specified by:
getFilterObservable in interface ITableFilterEditor
See Also:
ITableFilterEditor.getFilterObservable()

updateFilter

public void updateFilter()
It propagates the current filter to any listeners

Specified by:
updateFilter in interface ITableFilterEditor
See Also:
ITableFilterEditor.updateFilter()

resetFilter

public void resetFilter()
Unselects any choice, removing, therefore, any filtering by this editor.

Specified by:
resetFilter in interface ITableFilterEditor
See Also:
ITableFilterEditor.resetFilter()

getComponent

public Component getComponent()
Description copied from interface: ITableFilterEditor
Provides the GUI component associated to the given editor

Specified by:
getComponent in interface ITableFilterEditor
See Also:
ITableFilterEditor.getComponent()

setChoiceModel

protected void setChoiceModel(Object selected,
                              Object otherChoices,
                              Object[] choices)
Sets the model for the combo box

Parameters:
selected - The elemenet to select in the combobox
otherChoices - The element defining the concept of 'other choices'. It will be displayed as the last option in the combobox
choices - All the values to show in the combo box, in the provided order

setEnabled

public void setEnabled(boolean enabled)
Overrides:
setEnabled in class JComboBox