JComponentPack 3.5

com.zfqjava.swing.cell
Class AbstractCellRenderer

java.lang.Object
  extended by com.zfqjava.swing.cell.AbstractCellRenderer
All Implemented Interfaces:
ListCellRenderer, Renderer, TableCellRenderer, TreeCellRenderer
Direct Known Subclasses:
DefaultCellRenderer, ObjectCellRenderer

public abstract class AbstractCellRenderer
extends Object
implements ListCellRenderer, TableCellRenderer, TreeCellRenderer, Renderer

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


Field Summary
protected static 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
protected  CellArgs getCellArgs()
          Return the cell args contains more information about this renderer.
 CellProvider getCellProvider()
          Returns the cell provider to add extra info for current renderer.
 Component getCellRendererComponent(Container host, Object value, boolean isSelected, boolean cellHasFocus)
          Return a component that has been configured to display the specified value.
 CellRendererComponentType getCellRendererComponentType()
           
abstract  Component getComponent()
          Returns the component for this renderer.
 CellRendererComponentType getDefaultCellRendererComponentType()
          Returns the default cell renderer component type.
 Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
          Return a component that has been configured to display the specified value.
 Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
          Returns the component used for drawing the cell.
 Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus)
          Sets the value of the current tree cell to value.
 boolean isOpaque()
          Returns the opaque property.
 void setCellProvider(CellProvider provider)
          Sets the cell provider to add extra info for current renderer.
 void setCellRendererComponentType(CellRendererComponentType cellRendererComponentType)
           
 void setDefaultCellRendererComponentType(CellRendererComponentType defaultCellRendererComponentType)
          Sets the default cell renderer component type.
 void setOpaque(boolean opaque)
          Sets the opaque property.
protected abstract  void setValue(Object value)
          Sets the value for current renderer.
 void setValue(Object value, boolean isSelected)
          Sets the value.
 void updateUI()
          Updates UI.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

noFocusBorder

protected static 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

getCellArgs

protected CellArgs getCellArgs()
Return the cell args contains more information about this renderer.

Returns:
the cell args
Since:
JComponentPack 3.2

getCellRendererComponent

public Component getCellRendererComponent(Container host,
                                          Object value,
                                          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.

Parameters:
host - the renderer component container
value - the value
isSelected - True if the specified cell was selected
cellHasFocus - True if the specified cell has the focus.
Returns:
the component for render the specified value
Since:
JFlowChart 1.0

getListCellRendererComponent

public Component getListCellRendererComponent(JList list,
                                              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 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 Component getTableCellRendererComponent(JTable table,
                                               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 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 Component getTreeCellRendererComponent(JTree tree,
                                              Object value,
                                              boolean isSelected,
                                              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 TreeCellRenderer
Returns:
the Component that the renderer uses to draw the value

updateUI

public void updateUI()
Updates UI.


setOpaque

public void setOpaque(boolean opaque)
Sets the opaque property.

Parameters:
opaque - the opaque property

isOpaque

public boolean isOpaque()
Returns the opaque property.

Returns:
the opaque property

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)

setValue

public void setValue(Object value,
                     boolean isSelected)
Sets the value.

Specified by:
setValue in interface Renderer
Parameters:
value - the value
isSelected - the select state

getComponent

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

Specified by:
getComponent in interface Renderer
Returns:
the component for this renderer

setValue

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

Parameters:
value - the value to renderer

getCellRendererComponentType

public CellRendererComponentType getCellRendererComponentType()
Since:
JComponentPack 1.3

setCellRendererComponentType

public void setCellRendererComponentType(CellRendererComponentType cellRendererComponentType)
Since:
JComponentPack 1.3

getDefaultCellRendererComponentType

public CellRendererComponentType getDefaultCellRendererComponentType()
Returns the default cell renderer component type.

Returns:
the default cell renderer component type
Since:
JComponentPack 3.2
See Also:
setDefaultCellRendererComponentType(com.zfqjava.swing.cell.CellRendererComponentType)

setDefaultCellRendererComponentType

public void setDefaultCellRendererComponentType(CellRendererComponentType defaultCellRendererComponentType)
Sets the default cell renderer component type.

Parameters:
defaultCellRendererComponentType - the default cell renderer component type
Since:
JComponentPack 3.2
See Also:
getDefaultCellRendererComponentType()

JComponentPack 3.5

Send your Feedback
JComponentPack 3.5
Copyright © 2009 Extreme Component, Inc. All rights reserved.