com.jstatcom.component
Class CheckBoxList

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JList
                  extended by com.jstatcom.component.CheckBoxList
All Implemented Interfaces:
SymbolListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable

public final class CheckBoxList
extends javax.swing.JList
implements SymbolListener

This class provides a special JList that renders its items as selectable JCheckBox components. Ctrl-A selects all items, Ctrl-X deselects all.

It can be used to provide the user with a selection mechanism for a set of keys. The objects to select can be set via a JSCSArray object or a general Object array. If new data is set that contains elements that have been set before, the current selection is preserved. This behaviour can be turned off by invoking clear before setting new data. It is possible to provide a titled border for this list via setBorderTitle.

The contents of this list can be specified by a symbol. In the same way, the selection state can be stored to another symbol. However, it is not possible to change the selection state by changing the symbol contents.

Whenever there is a change in the selection status by either clicking on the list checkboxes or by invoking clearSelectionStatus, a "selectionChanged" property change event is fired. This does not happen if the selection status changed due to changes in the data model.

Author:
Markus Kraetzig
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JList
javax.swing.JList.DropLocation
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JList
HORIZONTAL_WRAP, VERTICAL, VERTICAL_WRAP
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
CheckBoxList()
          CheckBoxList default constructor.
 
Method Summary
 void addNotify()
          Overrides addNotify to retrieve data objects as soon as the component hierarchy is established.
 void clear()
          Removes all data from the list model and wipes out all selection information.
 void clearSelectionStatus()
          Deselects all checkboxes in this list and fires a property change event.
 boolean[] getBoolSelectionStatus()
          Gets the array indicating the selection status of all keys by setting the corresponding elements to true or false.
 java.lang.String getBorderTitle()
          Gets the title of the border displayed arround this list.
 int[] getIntSelectionStatus()
          Gets the array indicating the selection status of all keys by setting the corresponding elements to 1 or 0.
 java.lang.Object[] getSelectedObjects()
          Gets all elements of this list that are selected.
 java.lang.String getSymbolName()
          Gets the symbol identifier for the data object of the data displayed.
 java.lang.String getSymbolNameSelected()
          Gets the symbol identifier for the current selection state.
 Scope getSymbolScope()
          Gets the current symbol scope.
 void setBorderTitle(java.lang.String borderTitle)
          Sets the border title of this list.
 void setJSCSArray(JSCSArray dataKeys)
          Sets the data that should be displayed in the list.
 void setObjArray(java.lang.Object[] values)
          Sets the data that should be displayed in the list.
 void setSelectionChanged()
          This method is called, whenever the mouse was clicked over an item in the list and the selection changed.
 void setSelectionStatus(int[] selIndizes)
          Sets the selection of the checkboxes in this list according to an array indicating the selection status.
 void setSymbolName(java.lang.String newSymbolName)
          Sets the symbol name to retrieve data from.
 void setSymbolNameSelected(java.lang.String newSymbolNameSelected)
          Sets the symbol name to store the selection state to.
 void setSymbolScope(Scope scope)
          Sets the symbol scope.
 void valueChanged(SymbolEvent evt)
          Updates list if symbol changed.
 
Methods inherited from class javax.swing.JList
addListSelectionListener, addSelectionInterval, clearSelection, ensureIndexIsVisible, getAccessibleContext, getAnchorSelectionIndex, getCellBounds, getCellRenderer, getDragEnabled, getDropLocation, getDropMode, getFirstVisibleIndex, getFixedCellHeight, getFixedCellWidth, getLastVisibleIndex, getLayoutOrientation, getLeadSelectionIndex, getListSelectionListeners, getMaxSelectionIndex, getMinSelectionIndex, getModel, getNextMatch, getPreferredScrollableViewportSize, getPrototypeCellValue, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedIndex, getSelectedIndices, getSelectedValue, getSelectedValues, getSelectionBackground, getSelectionForeground, getSelectionMode, getSelectionModel, getToolTipText, getUI, getUIClassID, getValueIsAdjusting, getVisibleRowCount, indexToLocation, isSelectedIndex, isSelectionEmpty, locationToIndex, removeListSelectionListener, removeSelectionInterval, setCellRenderer, setDragEnabled, setDropMode, setFixedCellHeight, setFixedCellWidth, setLayoutOrientation, setListData, setListData, setModel, setPrototypeCellValue, setSelectedIndex, setSelectedIndices, setSelectedValue, setSelectionBackground, setSelectionForeground, setSelectionInterval, setSelectionMode, setSelectionModel, setUI, setValueIsAdjusting, setVisibleRowCount, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CheckBoxList

public CheckBoxList()
CheckBoxList default constructor.

Method Detail

valueChanged

public void valueChanged(SymbolEvent evt)
Updates list if symbol changed.

Specified by:
valueChanged in interface SymbolListener
Parameters:
evt - the data event with all relevant information about the change

addNotify

public void addNotify()
Overrides addNotify to retrieve data objects as soon as the component hierarchy is established.

Overrides:
addNotify in class javax.swing.JComponent

clear

public void clear()
Removes all data from the list model and wipes out all selection information.


clearSelectionStatus

public void clearSelectionStatus()
Deselects all checkboxes in this list and fires a property change event.


setSelectionStatus

public void setSelectionStatus(int[] selIndizes)
Sets the selection of the checkboxes in this list according to an array indicating the selection status. The other standard setSelection methods take no effect.

Parameters:
selIndizes - array indicating whether the checkboxes should be selected or not (0: no selection, else: selection)
Throws:
java.lang.IllegalArgumentException - if (selIndizes == null || selIndizes.length != getModel().getSize())

getBoolSelectionStatus

public boolean[] getBoolSelectionStatus()
Gets the array indicating the selection status of all keys by setting the corresponding elements to true or false. Selection here means not list selection, but whether the JCheckBox for an item is selected.

Returns:
array with the selection states of the items

getBorderTitle

public java.lang.String getBorderTitle()
Gets the title of the border displayed arround this list.

Returns:
the title string
See Also:
setBorderTitle(java.lang.String)

getIntSelectionStatus

public int[] getIntSelectionStatus()
Gets the array indicating the selection status of all keys by setting the corresponding elements to 1 or 0. Selection here means not list selection, but whether the JCheckBox for an item is selected.

Returns:
array with the selection states of the items

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Gets all elements of this list that are selected. Selection here means not list selection, but whether the JCheckBox for an item is selected.

Returns:
the objects with selection state true

getSymbolName

public java.lang.String getSymbolName()
Gets the symbol identifier for the data object of the data displayed.

Returns:
the symbol name

getSymbolNameSelected

public java.lang.String getSymbolNameSelected()
Gets the symbol identifier for the current selection state. The state is stored as an int array, where 1 indicates a selection.

Returns:
the symbol name for the selection state

setBorderTitle

public void setBorderTitle(java.lang.String borderTitle)
Sets the border title of this list. If invoked, an EtchedBorder with the title defined in borderTitle is wrapped around this list. The title is displayed top left.

Parameters:
borderTitle - the title to be displayed, if ( borderTitle == null || borderTitle.length() == 0 ) then a simple EtchedBorder is displayed
See Also:
getBorderTitle()

setObjArray

public void setObjArray(java.lang.Object[] values)
Sets the data that should be displayed in the list. The argument is specified as an object array. The toString method is queried for the label of the repective item to display.

Parameters:
values - the object array with the elements to add, it must not be null
Throws:
java.lang.IllegalArgumentException - if (values == null)

setJSCSArray

public void setJSCSArray(JSCSArray dataKeys)
Sets the data that should be displayed in the list. The argument is specified as a data object that is queried for the number of rows. The first element in each row is then added. Typically it contains a representation of a 1-dimensional string array. The toString method is queried for the label of the repective item to display.

Parameters:
dataKeys - the data object with the elements to add, it must not be null
Throws:
java.lang.IllegalArgumentException - if (dataKeys == null)

setSelectionChanged

public void setSelectionChanged()
This method is called, whenever the mouse was clicked over an item in the list and the selection changed. It fires a property change event "selectionChanged" and can be used by graphical development tools to easily connect listeners.


setSymbolName

public void setSymbolName(java.lang.String newSymbolName)
Sets the symbol name to retrieve data from. The symbol data is never overwritten by the data that might have been set before to this list, but just read from the symbol.

Parameters:
newSymbolName - the symbol name
Throws:
java.lang.IllegalArgumentException - if (JSCConstants.isValidName(newSymbolName) != null)

setSymbolNameSelected

public void setSymbolNameSelected(java.lang.String newSymbolNameSelected)
Sets the symbol name to store the selection state to. The selection state is never retrieved from the symbol object.

Parameters:
newSymbolNameSelected - the symbol name for the selection state
Throws:
java.lang.IllegalArgumentException - if (JSCConstants.isValidName(newSymbolNameSelected) != null)

getSymbolScope

public Scope getSymbolScope()
Gets the current symbol scope.

Returns:
symbol scope

setSymbolScope

public void setSymbolScope(Scope scope)
Sets the symbol scope.

Parameters:
scope -
Throws:
java.lang.IllegalArgumentException - if (scope == null)