Class CheckBoxList
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JList
-
- 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 specialJListthat renders its items as selectableJCheckBoxcomponents. 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
JSCSArrayobject or a generalObjectarray. 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 invokingclearbefore setting new data. It is possible to provide a titled border for this list viasetBorderTitle.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.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor and Description CheckBoxList()CheckBoxListdefault constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidaddNotify()OverridesaddNotifyto retrieve data objects as soon as the component hierarchy is established.voidclear()Removes all data from the list model and wipes out all selection information.voidclearSelectionStatus()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 totrueorfalse.java.lang.StringgetBorderTitle()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 to1or0.java.lang.Object[]getSelectedObjects()Gets all elements of this list that are selected.java.lang.StringgetSymbolName()Gets the symbol identifier for the data object of the data displayed.java.lang.StringgetSymbolNameSelected()Gets the symbol identifier for the current selection state.ScopegetSymbolScope()Gets the current symbol scope.voidsetBorderTitle(java.lang.String borderTitle)Sets the border title of this list.voidsetJSCSArray(JSCSArray dataKeys)Sets the data that should be displayed in the list.voidsetObjArray(java.lang.Object[] values)Sets the data that should be displayed in the list.voidsetSelectionChanged()This method is called, whenever the mouse was clicked over an item in the list and the selection changed.voidsetSelectionStatus(int[] selIndizes)Sets the selection of the checkboxes in this list according to an array indicating the selection status.voidsetSymbolName(java.lang.String newSymbolName)Sets the symbol name to retrieve data from.voidsetSymbolNameSelected(java.lang.String newSymbolNameSelected)Sets the symbol name to store the selection state to.voidsetSymbolScope(Scope scope)Sets the symbol scope.voidvalueChanged(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, getSelectedValuesList, 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, hide, 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, 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, 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, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Method Detail
-
valueChanged
public void valueChanged(SymbolEvent evt)
Updates list if symbol changed.- Specified by:
valueChangedin interfaceSymbolListener- Parameters:
evt- the data event with all relevant information about the change
-
addNotify
public void addNotify()
OverridesaddNotifyto retrieve data objects as soon as the component hierarchy is established.- Overrides:
addNotifyin classjavax.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 standardsetSelectionmethods 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 totrueorfalse. Selection here means not list selection, but whether theJCheckBoxfor 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 to1or0. Selection here means not list selection, but whether theJCheckBoxfor 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 theJCheckBoxfor 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 anintarray, 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, anEtchedBorderwith the title defined inborderTitleis wrapped around this list. The title is displayedtop left.- Parameters:
borderTitle- the title to be displayed,if ( borderTitle == null || borderTitle.length() == 0 )then a simpleEtchedBorderis 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. ThetoStringmethod is queried for the label of the repective item to display.- Parameters:
values- the object array with the elements to add, it must not benull- 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. ThetoStringmethod is queried for the label of the repective item to display.- Parameters:
dataKeys- the data object with the elements to add, it must not benull- 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)
-
-
DMelt 3.0 © DataMelt by jWork.ORG