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 Details

    • ClosureRenderer

      public ClosureRenderer()
      Creates a renderer with no update closure.
    • ClosureRenderer

      public ClosureRenderer(Closure c)
      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 to render().
      Specified by:
      getListCellRendererComponent in interface ListCellRenderer
      Parameters:
      list - the list being rendered
      value - the current cell value
      index - the list index being rendered
      isSelected - whether the cell is selected
      cellHasFocus - 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 to render().
      Specified by:
      getTableCellRendererComponent in interface TableCellRenderer
      Parameters:
      table - the table being rendered
      value - the current cell value
      isSelected - whether the cell is selected
      hasFocus - whether the cell has focus
      row - the model row being rendered
      column - 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 to render().
      Specified by:
      getTreeCellRendererComponent in interface TreeCellRenderer
      Parameters:
      tree - the tree being rendered
      value - the current node value
      selected - whether the row is selected
      expanded - whether the node is expanded
      leaf - whether the node is a leaf
      row - the tree row being rendered
      hasFocus - whether the row has focus
      Returns:
      the renderer component
    • getUpdate

      public Closure getUpdate()
      Returns the update closure invoked during rendering.
      Returns:
      the update closure
    • setUpdate

      public void setUpdate(Closure update)
      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 - true to render using the table-header renderer
    • isTableHeader

      public boolean isTableHeader()
      Returns whether table rendering uses the table-header renderer.
      Returns:
      true when header rendering is enabled
    • getChildren

      public List getChildren()
      Returns the renderer children exposed to the update closure.
      Returns:
      the renderer children
    • getList

      public JList getList()
      Returns the current list being rendered.
      Returns:
      the current list, or null
    • getTable

      public JTable getTable()
      Returns the current table being rendered.
      Returns:
      the current table, or null
    • getValue

      public Object getValue()
      Returns the current cell value.
      Returns:
      the current value
    • isSelected

      public boolean isSelected()
      Returns whether the current cell is selected.
      Returns:
      true when the current cell is selected
    • isFocused

      public boolean isFocused()
      Returns whether the current cell has focus.
      Returns:
      true when 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

      public JTree 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:
      true when the current node is a leaf
    • isExpanded

      public boolean isExpanded()
      Returns whether the current tree node is expanded.
      Returns:
      true when the current node is expanded
    • isDefaultRenderer

      public boolean isDefaultRenderer()
      Returns whether the default renderer was used as the base renderer.
      Returns:
      true when the default renderer provided the base component