public abstract class NiceListRenderer<T>
extends javax.swing.JPanel
implements javax.swing.ListCellRenderer
checkbox
that can be selected or
deselected.title
that is rendered at the
top of the item in bold.description
that is rendered under
the title.secondary description
that is
optionally rendered under the description.hyperlink
that can send action
events when used in conjunction with NiceList
.indicator
icon.image
an image that is placed at the
right side of the title and description.NiceList
. Clients should provide a subclass of NiceListRenderer
that knows how to return the correct values for the above attributes for
a given item in the list model.This renderer is accessible. It returns the title and both descriptions as part of its accessible state. In addition, the accessible role of the renderer is a check item, allowing assistive technology to determine and interact with the state of the checkbox.
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
NiceListRenderer() |
Modifier and Type | Method and Description |
---|---|
javax.accessibility.AccessibleContext |
getAccessibleContext() |
protected java.awt.Color |
getBackgroundColor(T listItem)
Returns the background color for the specified item when it is not
selected.
|
protected abstract java.lang.String |
getDescription(T listItem)
Returns the description line for the specified item.
|
protected java.lang.String |
getHyperLinkText(T listItem)
Returns the text of the hyperlink for the specified list item.
|
protected java.awt.Image |
getImage(T listItem)
Returns the image for the specified list item.
|
protected javax.swing.Icon |
getIndicator(T listItem)
Returns the indicator for the specified list item.
|
java.awt.Component |
getListCellRendererComponent(javax.swing.JList list,
java.lang.Object value,
int index,
boolean isSelected,
boolean cellHasFocus) |
protected java.lang.String |
getSecondaryHyperLinkText(T listItem)
Returns the text of the secondary hyperlink for the specified list item.
|
protected java.lang.String |
getSecondDescription(T listItem)
Returns the second description line for the specified item.
|
java.lang.String |
getText() |
protected abstract java.lang.String |
getTitle(T listItem)
Returns the title (main text) for the specified item.
|
protected boolean |
isCheckable(T listItem)
Returns true if a checkbox is rendered for the specified item.
|
protected abstract boolean |
isItemSelected(T listItem)
Returns whether the specified item is selected (checked).
|
boolean |
isRadioButtonStyle()
Returns true if checkboxes are rendered as radio buttons.
|
void |
paintComponent(java.awt.Graphics g) |
void |
setGradientColor(java.awt.Color light,
java.awt.Color dark)
Sets the color to use for the selection gradient.
|
void |
setRadioButtonStyle(boolean radioButtonStyle)
Sets whether the checkboxes are rendered as radio buttons or checkboxes.
|
void |
setSelectedForeground(java.awt.Color color)
Set the foreground color for selected rows.
|
void |
setTwoLineDescription(boolean twoLine)
Set whether there are two description lines.
|
void |
setUnselectedForeground(java.awt.Color color)
Set the foreground color for non selected rows.
|
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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, 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, 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, transferFocusBackward, transferFocusUpCycle
public final void setRadioButtonStyle(boolean radioButtonStyle)
radioButtonStyle
- if true, the checkboxes are rendered
as radio buttons. If false, they are rendered as regular
checkboxes.public final boolean isRadioButtonStyle()
public final void setGradientColor(java.awt.Color light, java.awt.Color dark)
light
- the light color to use for the gradient. Must not be null.dark
- the dark color to use for the gradient. Must not be null.public final void setSelectedForeground(java.awt.Color color)
color
- the color to use for the foreground of selected rows. Must
not be null.public final void setUnselectedForeground(java.awt.Color color)
color
- the color to use for the foreground of non selected rows.
Must not be null.public final void setTwoLineDescription(boolean twoLine)
twoLine
- if true, two description lines will be displayed. If
false, only one will be displayed.public final void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
public final java.awt.Component getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
getListCellRendererComponent
in interface javax.swing.ListCellRenderer
protected java.awt.Color getBackgroundColor(T listItem)
This implementation returns a color which is almost white.
listItem
- an item in the list.public final java.lang.String getText()
protected abstract java.lang.String getTitle(T listItem)
listItem
- an item in the list.protected abstract java.lang.String getDescription(T listItem)
listItem
- an item in the list.protected java.lang.String getSecondDescription(T listItem)
setTwoLineDescription(boolean)
with an argument of true.listItem
- an item in the list.protected abstract boolean isItemSelected(T listItem)
listItem
- an item in the list.protected java.lang.String getHyperLinkText(T listItem)
This implementation returns an empty string.
listItem
- the list item to get a hyperlink for.protected java.lang.String getSecondaryHyperLinkText(T listItem)
This implementation returns an empty String.
listItem
- the list item to get a hyperlink for.protected javax.swing.Icon getIndicator(T listItem)
This implementation returns null.
listItem
- the item to get the indicator for.protected java.awt.Image getImage(T listItem)
This implementation returns null.
listItem
- the item to get the image for.protected boolean isCheckable(T listItem)
This implementation returns true.
listItem
- an item.public javax.accessibility.AccessibleContext getAccessibleContext()
getAccessibleContext
in interface javax.accessibility.Accessible
getAccessibleContext
in class javax.swing.JPanel