Class CellContext

java.lang.Object
org.jdesktop.swingx.renderer.CellContext
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
ListCellContext, TableCellContext, TreeCellContext

public class CellContext extends Object implements Serializable
Encapsulates a snapshop of cell content and default display context for usage by a ComponentProvider.

One part is the super-set of properties that's traditionally passed into the core renderers' (Table-, List-, Tree-) getXXCellRendererComponent. Raw properties which define the context are

  • selected
  • focused
  • expanded
  • leaf
Similarl to a ComponentAdapter, the properties are a super-set of those for a concrete component type. It's up to sub-classes (once the generics will be removed, until then the DefaultXXRenderers - PENDING JW: undecided - even after the generics removal, the param list in the subclasses are the same) fill any reasonable defaults for those not applicable to the specific component context. With those raw properties given, a CellContext looks up and returns dependent visual properties as appropriate for the concrete component. Typically, they are taken from the component if supported, or requested from the UIManager. Dependent properties are
  • foreground and background color
  • border
  • icon (relevant for trees only)
  • editable
For a backdoor, the cell location (in horizontal and vertical view coordinates) and the originating component is accessible as well. Note that they are not necessarily valid for the "life" component. It's not recommended to actually use them. If needed, that's probably a sign the api is lacking :-)
  • PENDING: still incomplete? how about Font?
  • PENDING: protected methods? Probably need to open up - derived properties should be accessible in client code.
Author:
Jeanette Winzenburg
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
    TODO doc
    protected JComponent
    PENDING JW: maybe make this a WeakReference?
    protected boolean
    TODO doc
    protected boolean
    TODO doc
    protected boolean
    TODO doc
    protected boolean
    TODO doc
    protected static Border
    the default border for unfocused cells.
    protected int
    TODO doc
    protected boolean
    TODO doc
    protected Object
    PENDING JW: maybe make this a WeakReference?
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Color
    Returns the background color of the renderered component or null if the component is null
    protected Border
    Returns the default border of the renderered component depending on cell state.
    CellRendererName
    int
    Returns the cell's column index in view coordinates as set in the install.
    Returns the component the cell resides on, may be null.
    protected Color
    TODO doc
    protected Color
    TODO doc
    protected Color
    Returns the default focused background color of the renderered component.
    protected Border
    Returns the default focus border of the renderered component.
    protected Color
    Returns the default focused foreground color of the renderered component.
    protected Font
    Returns the Font of the target component or null if no component installed.
    protected Color
    Returns the foreground color of the renderered component or null if the component is null
    Returns the icon.
    int
    Returns the cell's row index in view coordinates as set in the install.
    protected Color
    Returns the default selection background color of the renderered component.
    protected Color
    Returns the default selection foreground color of the renderered component.
    protected String
    Convenience method to build a component type specific lookup key for the UIManager.
    protected String
    Returns the component type specific prefix of keys for lookup in the UIManager.
    Returns the value of the cell as set in the install.
    protected void
    installState(Object value, int row, int column, boolean selected, boolean focused, boolean expanded, boolean leaf)
    Sets the state of the cell's context.
    protected boolean
    Returns a boolean indicating if the cell is a drop location with any of the dropOn modes.
    boolean
    Returns the cell's editability.
    boolean
    Returns the expanded state as set in the install.
    boolean
    Returns the focused state as set in the install.
    boolean
    Returns the leaf state as set in the install.
    boolean
    Returns the selected state as set in the install.
    Replaces the value of this cell context with the given parameter and returns the replaced value.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • noFocusBorder

      protected static Border noFocusBorder
      the default border for unfocused cells.
    • component

      protected transient JComponent component
      PENDING JW: maybe make this a WeakReference? Would be a more robust fix for Issue #1040-swingx.
    • value

      protected transient Object value
      PENDING JW: maybe make this a WeakReference? Would be a more robust fix for Issue #1040-swingx.
    • row

      protected transient int row
      TODO doc
    • column

      protected transient int column
      TODO doc
    • selected

      protected transient boolean selected
      TODO doc
    • focused

      protected transient boolean focused
      TODO doc
    • expanded

      protected transient boolean expanded
      TODO doc
    • leaf

      protected transient boolean leaf
      TODO doc
    • dropOn

      protected transient boolean dropOn
      TODO doc
  • Constructor Details

    • CellContext

      public CellContext()
  • Method Details

    • installState

      protected void installState(Object value, int row, int column, boolean selected, boolean focused, boolean expanded, boolean leaf)
      Sets the state of the cell's context. Convenience method for subclasses.
      Parameters:
      value - the content value of the cell
      row - the cell's row index in view coordinates
      column - the cell's column index in view coordinates
      selected - the cell's selected state
      focused - the cell's focused state
      expanded - the cell's expanded state
      leaf - the cell's leaf state
    • replaceValue

      public Object replaceValue(Object value)
      Replaces the value of this cell context with the given parameter and returns the replaced value.
      Parameters:
      value - the new value of the cell context
      Returns:
      the replaced value of the cell context
    • getComponent

      public JComponent getComponent()
      Returns the component the cell resides on, may be null. Subclasses are expected to override and return the component type they are handling.
      Returns:
      the component the cell resides on, may be null.
    • getValue

      public Object getValue()
      Returns the value of the cell as set in the install.
      Returns:
      the content value of the cell.
    • getRow

      public int getRow()
      Returns the cell's row index in view coordinates as set in the install.
      Returns:
      the cell's row index.
    • getColumn

      public int getColumn()
      Returns the cell's column index in view coordinates as set in the install.
      Returns:
      the cell's column index.
    • isSelected

      public boolean isSelected()
      Returns the selected state as set in the install.
      Returns:
      the cell's selected state.
    • isFocused

      public boolean isFocused()
      Returns the focused state as set in the install.
      Returns:
      the cell's focused state.
    • isExpanded

      public boolean isExpanded()
      Returns the expanded state as set in the install.
      Returns:
      the cell's expanded state.
    • isLeaf

      public boolean isLeaf()
      Returns the leaf state as set in the install.
      Returns:
      the cell's leaf state.
    • isEditable

      public boolean isEditable()
      Returns the cell's editability. Subclasses should override to return a reasonable cell-related state.

      Here: false.

      Returns:
      the cell's editable property.
    • getIcon

      public Icon getIcon()
      Returns the icon. Subclasses should override to return a reasonable cell-related state.

      Here: null.

      Returns:
      the cell's icon.
    • isDropOn

      protected boolean isDropOn()
      Returns a boolean indicating if the cell is a drop location with any of the dropOn modes. It's up to subclasses to implement.

      Here: false.

      Returns:
      true if the current cell is a drop location with any of the dropOn modes, false otherwise
    • getForeground

      protected Color getForeground()
      Returns the foreground color of the renderered component or null if the component is null

      PENDING: fallback to UI properties if comp == null?

      Returns:
      the foreground color of the rendered component.
    • getBackground

      protected Color getBackground()
      Returns the background color of the renderered component or null if the component is null

      PENDING: fallback to UI properties if comp == null?

      Returns:
      the background color of the rendered component.
    • getSelectionBackground

      protected Color getSelectionBackground()
      Returns the default selection background color of the renderered component. Typically, the color is LF specific. It's up to subclasses to look it up. Here: returns null.

      PENDING: return UI properties here?

      Returns:
      the selection background color of the rendered component.
    • getSelectionForeground

      protected Color getSelectionForeground()
      Returns the default selection foreground color of the renderered component. Typically, the color is LF specific. It's up to subclasses to look it up. Here: returns null.

      PENDING: return UI properties here?

      Returns:
      the selection foreground color of the rendered component.
    • getFocusBorder

      protected Border getFocusBorder()
      Returns the default focus border of the renderered component. Typically, the border is LF specific.
      Returns:
      the focus border of the rendered component.
    • getBorder

      protected Border getBorder()
      Returns the default border of the renderered component depending on cell state. Typically, the border is LF specific.

      Here: returns the focus border if the cell is focused, the context defined no focus border otherwise.

      Returns:
      the default border of the rendered component.
    • getFocusForeground

      protected Color getFocusForeground()
      Returns the default focused foreground color of the renderered component. Typically, the color is LF specific.
      Returns:
      the focused foreground color of the rendered component.
    • getFocusBackground

      protected Color getFocusBackground()
      Returns the default focused background color of the renderered component. Typically, the color is LF specific.
      Returns:
      the focused background color of the rendered component.
    • getDropCellForeground

      protected Color getDropCellForeground()
      TODO doc
      Returns:
      Color
    • getDropCellBackground

      protected Color getDropCellBackground()
      TODO doc
      Returns:
      Color
    • getUIKey

      protected String getUIKey(String key)
      Convenience method to build a component type specific lookup key for the UIManager.
      Parameters:
      key - the general part of the key
      Returns:
      a composed key build of a component type prefix and the input.
    • getUIPrefix

      protected String getUIPrefix()
      Returns the component type specific prefix of keys for lookup in the UIManager. Subclasses must override, here: returns the empty String.
      Returns:
      the component type specific prefix.
    • getFont

      protected Font getFont()
      Returns the Font of the target component or null if no component installed.
      Returns:
      Font
    • getCellRendererName

      public String getCellRendererName()
      CellRendererName
      Returns:
      name