Package groovy.swing.impl
Class ClosureRenderer
java.lang.Object
groovy.swing.impl.ClosureRenderer
- All Implemented Interfaces:
ListCellRenderer,TableCellRenderer,TreeCellRenderer
public class ClosureRenderer
extends Object
implements ListCellRenderer, TableCellRenderer, TreeCellRenderer
Shared Swing renderer that delegates rendering customization to a Groovy closure.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a renderer with no update closure.Creates a renderer that delegates to the supplied closure. -
Method Summary
Modifier and TypeMethodDescriptionReturns the renderer children exposed to the update closure.intReturns the current column index.getList()Returns the current list being rendered.getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) Prepares list-rendering state and delegates component creation torender().intgetRow()Returns the current row index.getTable()Returns the current table being rendered.getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) Prepares table-rendering state and delegates component creation torender().getTree()Returns the current tree being rendered.getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) Prepares tree-rendering state and delegates component creation torender().Returns the update closure invoked during rendering.getValue()Returns the current cell value.booleanReturns whether the default renderer was used as the base renderer.booleanReturns whether the current tree node is expanded.booleanReturns whether the current cell has focus.booleanisLeaf()Returns whether the current tree node is a leaf.booleanReturns whether the current cell is selected.booleanReturns whether table rendering uses the table-header renderer.voidsetTableHeader(boolean tableHeader) Configures whether table rendering should use the table-header renderer.voidSets the update closure invoked during rendering.
-
Constructor Details
-
ClosureRenderer
public ClosureRenderer()Creates a renderer with no update closure. -
ClosureRenderer
Creates a renderer that delegates to the supplied closure.- Parameters:
c- the update closure
-
-
Method Details
-
getListCellRendererComponent
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) Prepares list-rendering state and delegates component creation torender().- Specified by:
getListCellRendererComponentin interfaceListCellRenderer- Parameters:
list- the list being renderedvalue- the current cell valueindex- the list index being renderedisSelected- whether the cell is selectedcellHasFocus- whether the cell has focus- Returns:
- the renderer component
-
getTableCellRendererComponent
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) Prepares table-rendering state and delegates component creation torender().- Specified by:
getTableCellRendererComponentin interfaceTableCellRenderer- Parameters:
table- the table being renderedvalue- the current cell valueisSelected- whether the cell is selectedhasFocus- whether the cell has focusrow- the model row being renderedcolumn- the model column being rendered- Returns:
- the renderer component
-
getTreeCellRendererComponent
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) Prepares tree-rendering state and delegates component creation torender().- Specified by:
getTreeCellRendererComponentin interfaceTreeCellRenderer- Parameters:
tree- the tree being renderedvalue- the current node valueselected- whether the row is selectedexpanded- whether the node is expandedleaf- whether the node is a leafrow- the tree row being renderedhasFocus- whether the row has focus- Returns:
- the renderer component
-
getUpdate
Returns the update closure invoked during rendering.- Returns:
- the update closure
-
setUpdate
Sets the update closure invoked during rendering.- Parameters:
update- the update closure
-
setTableHeader
public void setTableHeader(boolean tableHeader) Configures whether table rendering should use the table-header renderer.- Parameters:
tableHeader-trueto render using the table-header renderer
-
isTableHeader
public boolean isTableHeader()Returns whether table rendering uses the table-header renderer.- Returns:
truewhen header rendering is enabled
-
getChildren
Returns the renderer children exposed to the update closure.- Returns:
- the renderer children
-
getList
Returns the current list being rendered.- Returns:
- the current list, or
null
-
getTable
Returns the current table being rendered.- Returns:
- the current table, or
null
-
getValue
Returns the current cell value.- Returns:
- the current value
-
isSelected
public boolean isSelected()Returns whether the current cell is selected.- Returns:
truewhen the current cell is selected
-
isFocused
public boolean isFocused()Returns whether the current cell has focus.- Returns:
truewhen the current cell has focus
-
getRow
public int getRow()Returns the current row index.- Returns:
- the current row index
-
getColumn
public int getColumn()Returns the current column index.- Returns:
- the current column index, or
-1
-
getTree
Returns the current tree being rendered.- Returns:
- the current tree, or
null
-
isLeaf
public boolean isLeaf()Returns whether the current tree node is a leaf.- Returns:
truewhen the current node is a leaf
-
isExpanded
public boolean isExpanded()Returns whether the current tree node is expanded.- Returns:
truewhen the current node is expanded
-
isDefaultRenderer
public boolean isDefaultRenderer()Returns whether the default renderer was used as the base renderer.- Returns:
truewhen the default renderer provided the base component
-