|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
net.wotonomy.ui.swing.components.IconCellRenderer
public class IconCellRenderer
A cell renderer that displays icons in addition to text,
and additionally is an editor in case you want to click
the icon to trigger some kind of action.
You probably should override both getStringForContext and
getIconForContext to achieve your desired results.
To receive mouse clicks, set the same instance of the
renderer as the editor for the same component.
One notable addition is that this class is an action event
broadcaster. ActionEvents are broadcast when the mouse is
clicked on the button with an action event containing a
user-configurable string that defaults to CLICKED.
The renderer itself can be used as a JComponent if
you need something like a JLabel that allows you to click
on the icon. You will want to call setIcon and setText
to configure the component since the renderer method would
not be called. (If you add an instance of the renderer
to a container, you cannnot use the same instance as an
editor in a table, tree, or list.)
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
javax.swing.JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
static java.lang.String |
CLICKED
|
protected javax.swing.JButton |
editorButton
|
protected javax.swing.JLabel |
editorLabel
|
protected javax.swing.JPanel |
editorPanel
The panel that is used to receive mouse clicks. |
protected javax.swing.JButton |
rendererButton
|
protected javax.swing.JLabel |
rendererLabel
|
protected javax.swing.JPanel |
rendererPanel
The panel that is re-used to render everything. |
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 | |
---|---|
IconCellRenderer()
Default constructor. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent evt)
Puts ourself on the end of the event queue for firing our action event to all listeners. |
void |
addActionListener(java.awt.event.ActionListener aListener)
Adds the specified listener to the list of listeners to be notified when the button receives a click. |
void |
addCellEditorListener(javax.swing.event.CellEditorListener aListener)
Adds the specified listener to the list of listeners to be notified when the table receives a double click. |
void |
cancelCellEditing()
Fires an editing cancelled event and returns true. |
protected void |
configureComponentForContext(javax.swing.JPanel component,
javax.swing.JButton iconButton,
javax.swing.JLabel label,
javax.swing.JComponent container,
java.lang.Object value,
int row,
int column,
boolean isSelected,
boolean hasFocus,
boolean isExpanded,
boolean isLeaf)
Called to configure components |
protected void |
fireActionEvent(java.awt.event.ActionEvent anActionEvent)
Broadcasts the specified action event to all listeners. |
java.lang.String |
getActionCommand()
Returns the action command broadcast when this icon receives a click. |
java.lang.Object |
getCellEditorValue()
Returns lastKnownValue, although this should not be called. |
java.awt.Component |
getEditorForContext(javax.swing.JComponent container,
java.lang.Object value,
int row,
int column,
boolean isSelected,
boolean hasFocus,
boolean isExpanded,
boolean isLeaf)
This method returns a separate component that should be visually identical to the renderer component. |
javax.swing.Icon |
getIcon()
Returns the icon currently displayed in the editor component. |
javax.swing.Icon |
getIconForContext(javax.swing.JComponent container,
java.lang.Object value,
int row,
int column,
boolean isSelected,
boolean hasFocus,
boolean isExpanded,
boolean isLeaf)
Override this method to provide an icon for the renderer. |
java.awt.Component |
getListCellRendererComponent(javax.swing.JList list,
java.lang.Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
Returns the component from getRendererForContext. |
java.awt.Component |
getRendererForContext(javax.swing.JComponent container,
java.lang.Object value,
int row,
int column,
boolean isSelected,
boolean hasFocus,
boolean isExpanded,
boolean isLeaf)
This default implementation returns a JPanel that is configured by calling configureComponentForContext. |
java.lang.String |
getStringForContext(javax.swing.JComponent container,
java.lang.Object value,
int row,
int column,
boolean isSelected,
boolean hasFocus,
boolean isExpanded,
boolean isLeaf)
Override this method to provide a string for the renderer. |
java.awt.Component |
getTableCellEditorComponent(javax.swing.JTable table,
java.lang.Object value,
boolean isSelected,
int row,
int column)
Returns getEditorForContext with the same parameters with hasFocus true. |
java.awt.Component |
getTableCellRendererComponent(javax.swing.JTable table,
java.lang.Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
Returns the component from getRendererForContext. |
java.lang.String |
getText()
Returns the text string currently displayed in the editor component. |
java.awt.Component |
getTreeCellEditorComponent(javax.swing.JTree tree,
java.lang.Object value,
boolean isSelected,
boolean expanded,
boolean leaf,
int row)
Returns the component from getEditorForContext with hasFocus true. |
java.awt.Component |
getTreeCellRendererComponent(javax.swing.JTree tree,
java.lang.Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus)
Returns the component from getRendererForContext. |
boolean |
isCellEditable(java.util.EventObject anEvent)
Returns true. |
boolean |
isClickable()
Returns whether the editor component's icon is clickable. |
boolean |
isEditable()
Returns whether the editor component's label text is editable. |
void |
mouseClicked(java.awt.event.MouseEvent e)
Passes through editor mouse clicks to last known component. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Does nothing. |
void |
mouseExited(java.awt.event.MouseEvent e)
Cancels cell editing. |
void |
mousePressed(java.awt.event.MouseEvent e)
Passes through editor right-mouse (popup trigger) mouse events to last known component. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Does nothing. |
void |
removeActionListener(java.awt.event.ActionListener aListener)
Removes the specified listener from the list of listeners to be notified when the button receives a click. |
void |
removeCellEditorListener(javax.swing.event.CellEditorListener aListener)
Removes the specified listener from the list of listeners to be notified when the table receives a double click. |
void |
run()
Fires the action event to all listeners. |
void |
setActionCommand(java.lang.String anActionCommand)
Sets the action command broadcast when this table receives a double click. |
void |
setClickable(boolean isClickable)
Sets whether the editor component's icon is clickable. |
void |
setEditable(boolean isEditable)
Sets whether the editor component's label text is editable. |
void |
setIcon(javax.swing.Icon anIcon)
Sets the icon currently displayed in the editor component. |
void |
setText(java.lang.String aString)
Sets the text string displayed in the editor component. |
boolean |
shouldSelectCell(java.util.EventObject anEvent)
Returns true. |
boolean |
stopCellEditing()
Fires an editing stopped event and returns true. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, 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, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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 |
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 |
---|
public static final java.lang.String CLICKED
protected javax.swing.JPanel rendererPanel
protected javax.swing.JLabel rendererLabel
protected javax.swing.JButton rendererButton
protected javax.swing.JPanel editorPanel
protected javax.swing.JLabel editorLabel
protected javax.swing.JButton editorButton
Constructor Detail |
---|
public IconCellRenderer()
Method Detail |
---|
public java.lang.String getText()
public void setText(java.lang.String aString)
public javax.swing.Icon getIcon()
public void setIcon(javax.swing.Icon anIcon)
public boolean isEditable()
public void setEditable(boolean isEditable)
public boolean isClickable()
public void setClickable(boolean isClickable)
public java.awt.Component getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
getListCellRendererComponent
in interface javax.swing.ListCellRenderer
public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, boolean hasFocus, int row, int column)
getTableCellRendererComponent
in interface javax.swing.table.TableCellRenderer
public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
getTreeCellRendererComponent
in interface javax.swing.tree.TreeCellRenderer
public java.awt.Component getTableCellEditorComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected, int row, int column)
getTableCellEditorComponent
in interface javax.swing.table.TableCellEditor
public java.awt.Component getTreeCellEditorComponent(javax.swing.JTree tree, java.lang.Object value, boolean isSelected, boolean expanded, boolean leaf, int row)
getTreeCellEditorComponent
in interface javax.swing.tree.TreeCellEditor
public java.awt.Component getRendererForContext(javax.swing.JComponent container, java.lang.Object value, int row, int column, boolean isSelected, boolean hasFocus, boolean isExpanded, boolean isLeaf)
public java.awt.Component getEditorForContext(javax.swing.JComponent container, java.lang.Object value, int row, int column, boolean isSelected, boolean hasFocus, boolean isExpanded, boolean isLeaf)
protected void configureComponentForContext(javax.swing.JPanel component, javax.swing.JButton iconButton, javax.swing.JLabel label, javax.swing.JComponent container, java.lang.Object value, int row, int column, boolean isSelected, boolean hasFocus, boolean isExpanded, boolean isLeaf)
public javax.swing.Icon getIconForContext(javax.swing.JComponent container, java.lang.Object value, int row, int column, boolean isSelected, boolean hasFocus, boolean isExpanded, boolean isLeaf)
public java.lang.String getStringForContext(javax.swing.JComponent container, java.lang.Object value, int row, int column, boolean isSelected, boolean hasFocus, boolean isExpanded, boolean isLeaf)
public void addActionListener(java.awt.event.ActionListener aListener)
public void removeActionListener(java.awt.event.ActionListener aListener)
protected void fireActionEvent(java.awt.event.ActionEvent anActionEvent)
public java.lang.String getActionCommand()
public void setActionCommand(java.lang.String anActionCommand)
public java.lang.Object getCellEditorValue()
getCellEditorValue
in interface javax.swing.CellEditor
public boolean isCellEditable(java.util.EventObject anEvent)
isCellEditable
in interface javax.swing.CellEditor
public boolean shouldSelectCell(java.util.EventObject anEvent)
shouldSelectCell
in interface javax.swing.CellEditor
public boolean stopCellEditing()
stopCellEditing
in interface javax.swing.CellEditor
public void cancelCellEditing()
cancelCellEditing
in interface javax.swing.CellEditor
public void addCellEditorListener(javax.swing.event.CellEditorListener aListener)
addCellEditorListener
in interface javax.swing.CellEditor
public void removeCellEditorListener(javax.swing.event.CellEditorListener aListener)
removeCellEditorListener
in interface javax.swing.CellEditor
public void actionPerformed(java.awt.event.ActionEvent evt)
actionPerformed
in interface java.awt.event.ActionListener
public void run()
run
in interface java.lang.Runnable
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |