com.zfqjava.swing.cell
Class AbstractCellRenderer

java.lang.Object
  |
  +--com.zfqjava.swing.cell.AbstractCellRenderer
All Implemented Interfaces:
javax.swing.ListCellRenderer, javax.swing.table.TableCellRenderer, javax.swing.tree.TreeCellRenderer
Direct Known Subclasses:
ObjectCellRenderer, StringCellRenderer

public abstract class AbstractCellRenderer
extends java.lang.Object
implements javax.swing.ListCellRenderer, javax.swing.table.TableCellRenderer, javax.swing.tree.TreeCellRenderer

AbstractCellRenderer provides a abstract cell renderer, can renderer JList, JTable, JTree.


Field Summary
protected static javax.swing.border.Border noFocusBorder
          The border used when the cell has no focus.
protected  boolean useFocusColor
          True use the focus color when the cell has focus.
 
Constructor Summary
AbstractCellRenderer()
           
 
Method Summary
 CellProvider getCellProvider()
          Returns the cell provider to add extra info for current renderer.
abstract  java.awt.Component getComponent()
          Returns the component for this renderer.
 java.awt.Component getListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)
          Return a component that has been configured to display the specified value.
 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.
 java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
          Sets the value of the current tree cell to value.
 void setCellProvider(CellProvider provider)
          Sets the cell provider to add extra info for current renderer.
protected abstract  void setValue(java.lang.Object value)
          Sets the value for current renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

noFocusBorder

protected static javax.swing.border.Border noFocusBorder
The border used when the cell has no focus. The default is new EmptyBorder(1, 1, 1, 1).

useFocusColor

protected boolean useFocusColor
True use the focus color when the cell has focus. This is important for TableCellRenderer. The default is true.
Constructor Detail

AbstractCellRenderer

public AbstractCellRenderer()
Method Detail

getListCellRendererComponent

public java.awt.Component getListCellRendererComponent(javax.swing.JList list,
                                                       java.lang.Object value,
                                                       int index,
                                                       boolean isSelected,
                                                       boolean cellHasFocus)
Return a component that has been configured to display the specified value. That component's paint method is then called to "render" the cell. If it is necessary to compute the dimensions of a list because the list cells do not have a fixed size, this method is called to generate a component on which getPreferredSize can be invoked.
Specified by:
getListCellRendererComponent in interface javax.swing.ListCellRenderer
Parameters:
list - The JList we're painting.
value - The value returned by list.getModel().getElementAt(index).
index - The cells index.
isSelected - True if the specified cell was selected.
cellHasFocus - True if the specified cell has the focus.
Returns:
A component whose paint() method will render the specified value.
See Also:
JList, ListSelectionModel, ListModel

getTableCellRendererComponent

public 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. This method is used to configure the renderer appropriately before drawing.
Specified by:
getTableCellRendererComponent in interface javax.swing.table.TableCellRenderer
Parameters:
table - the JTable that is asking the renderer to draw; can be null
value - the value of the cell to be rendered. It is up to the specific renderer to interpret and draw the value. For example, if value is the string "true", it could be rendered as a string or it could be rendered as a check box that is checked. null is a valid value
isSelected - true if the cell is to be rendered with the selection highlighted; otherwise false
hasFocus - if true, render cell appropriately. For example, put a special border on the cell, if the cell can be edited, render in the color used to indicate editing
row - the row index of the cell being drawn. When drawing the header, the value of row is -1
column - the column index of the cell being drawn

getTreeCellRendererComponent

public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree,
                                                       java.lang.Object value,
                                                       boolean selected,
                                                       boolean expanded,
                                                       boolean leaf,
                                                       int row,
                                                       boolean hasFocus)
Sets the value of the current tree cell to value. If selected is true, the cell will be drawn as if selected. If expanded is true the node is currently expanded and if leaf is true the node represets a leaf and if hasFocus is true the node currently has focus. tree is the JTree the receiver is being configured for. Returns the Component that the renderer uses to draw the value.
Specified by:
getTreeCellRendererComponent in interface javax.swing.tree.TreeCellRenderer
Returns:
the Component that the renderer uses to draw the value

setCellProvider

public void setCellProvider(CellProvider provider)
Sets the cell provider to add extra info for current renderer.
Parameters:
provider - the cell provider
See Also:
getCellProvider()

getCellProvider

public CellProvider getCellProvider()
Returns the cell provider to add extra info for current renderer.
Returns:
the cell provider to add extra info for current renderer
See Also:
setCellProvider(com.zfqjava.swing.cell.CellProvider)

getComponent

public abstract java.awt.Component getComponent()
Returns the component for this renderer.
Returns:
the component for this renderer

setValue

protected abstract void setValue(java.lang.Object value)
Sets the value for current renderer. This method aims to format the object in subclass.
Parameters:
value - the value to renderer


Copyright © 2001-2003 Extreme Component, Inc. All rights reserved.