public class ColoredCellRenderer
extends javax.swing.JLabel
implements javax.swing.table.TableCellRenderer
javax.swing.JLabel.AccessibleJLabel
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
private static org.apache.log4j.Logger |
LOGGER
Logger
|
private java.util.Map<java.lang.String,java.awt.Color> |
mapcBGPatterns
Background colors mapped to keys
|
private java.util.Map<java.lang.String,java.awt.Color> |
mapcFGPatterns
Foreground colors mapped to keys
|
private java.util.List<java.awt.Color> |
objcAlternatingBGColors
The ordered set of foregound colors used for rows when displaying a table
|
private java.util.List<java.awt.Color> |
objcAlternatingFGColors
The ordered set of background colors used for rows when displaying a table
|
private javax.swing.JTable |
objcTable
A table to display
|
private static long |
serialVersionUID
Serial UID for this version of class
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Constructor and Description |
---|
ColoredCellRenderer()
Constructor a ColoredCellRenderer - when this function is called it
passes default parameters to the function
ColoredCellRenderer(int,int,int,int)
|
ColoredCellRenderer(int iaHorizontalAlignment)
Class Constructor - passes the parameter iaHorizontalAlignment to the
function ColoredCellRenderer(int,int,int,int)
|
ColoredCellRenderer(int iaHorizAlignment,
int iaVerticalAlignment)
Creates and Initializes the class ColoredCellRenderer
|
Modifier and Type | Method and Description |
---|---|
void |
addAlternatingRowColor(java.awt.Color objaTextColor,
java.awt.Color objaBGColor)
Add a foreground and background color pair for a row in the displayed
table.
|
void |
addPattern(java.lang.String saPattern,
java.awt.Color objaTextColor,
java.awt.Color objaBackgroundColor)
Associates the specified foreground (text) and background colors with the
specified string pattern
|
void |
clearColors()
Reset the renderer, removing all color definitions
|
private java.awt.Color |
findBGColor(java.lang.String saText,
int row)
Finds the background color object that is associated with the String
pattern
|
private java.awt.Color |
findFGColor(java.lang.String saText,
int row)
Finds the foreground color object that is associated with the String
pattern
|
java.awt.Component |
getTableCellRendererComponent(javax.swing.JTable table,
java.lang.Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
Returns the component used for drawing the cell.Used to configure the
renderer appropriately before drawing
|
private void |
setColor(javax.swing.JTable table,
boolean isSelected,
boolean hasFocus,
int row,
int col)
Sets the color for the object objlBackgroundColor
|
void |
setDefaultColors(java.awt.Color objaTextColor,
java.awt.Color objaBackgroundColor)
Sets the default foreground (text) and background colors for the object
|
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
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, isPaintingOrigin, 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
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, hide, 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
private static final long serialVersionUID
private static final org.apache.log4j.Logger LOGGER
private java.util.Map<java.lang.String,java.awt.Color> mapcFGPatterns
private java.util.Map<java.lang.String,java.awt.Color> mapcBGPatterns
private java.util.List<java.awt.Color> objcAlternatingBGColors
private java.util.List<java.awt.Color> objcAlternatingFGColors
private javax.swing.JTable objcTable
public ColoredCellRenderer()
public ColoredCellRenderer(int iaHorizontalAlignment)
iaHorizontalAlignment
- The Horizontal Alignment attributepublic ColoredCellRenderer(int iaHorizAlignment, int iaVerticalAlignment)
iaHorizAlignment
- The Horizontal Alignment attributeiaVerticalAlignment
- The Vertical Alignment attributepublic void addAlternatingRowColor(java.awt.Color objaTextColor, java.awt.Color objaBGColor)
objaTextColor
- The foreground text colorobjaBGColor
- The background cell colorpublic void setDefaultColors(java.awt.Color objaTextColor, java.awt.Color objaBackgroundColor)
objaTextColor
- The default foreground (text) color is set to this valueobjaBackgroundColor
- The default background color is set to this valuepublic void clearColors()
public void addPattern(java.lang.String saPattern, java.awt.Color objaTextColor, java.awt.Color objaBackgroundColor)
saPattern
- The key in this map is the stringobjaTextColor
- The value of the foreground (text) Color object associated with
the stringobjaBackgroundColor
- The value of the background Color object which
is associated with the stringprivate java.awt.Color findBGColor(java.lang.String saText, int row)
saText
- The string pattern which is the key for the
color objectrow
- The row being displayedprivate java.awt.Color findFGColor(java.lang.String saText, int row)
saText
- The string pattern which is the key for the
color objectrow
- The row being displayedpublic 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
table
- The JTable that is asking the renderer to drawvalue
- The value of the cell to be renderedisSelected
- A Boolean Value - true if the cell is to be rendered
with the selection highlightedhasFocus
- A Boolean Value - if true render cell appropriatelyrow
- The row index of the cell to be renderedcolumn
- The column index of the cell to be renderedprivate void setColor(javax.swing.JTable table, boolean isSelected, boolean hasFocus, int row, int col)
table
- The JTableisSelected
- Boolean valuehasFocus
- Whether the component has focusrow
- The row indexcol
- The column index