Class CellContext<T extends javax.swing.JComponent>

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    ListCellContext, TableCellContext, TreeCellContext

    public class CellContext<T extends javax.swing.JComponent>
    extends java.lang.Object
    implements java.io.Serializable
    Encapsulates the display context passed into the getXXRendererComponent.

    Introduced to extract common state on which renderer configuration might rely. Similar to the view part of ComponentAdapter - difference is that the properties are not "live" dependent on the component but those passed-in are used.

    Additionally, provides lookup services to accessing state-dependent ui-specific default visual properties (like colors, borders, icons). Typically, they are taken from the UIManager or from the component, if supported in the component api.

    NOTE: the generic parameterization is useful to have a type-safe installContext. Reason enough?

    • PENDING: still incomplete? how about Font?
    • PENDING: protected methods? Probably need to open up - derived properties should be accessible in client code.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int column  
      protected T component  
      protected boolean expanded  
      protected boolean focused  
      protected boolean leaf  
      protected static javax.swing.border.Border noFocusBorder
      the default border for unfocused cells.
      protected int row  
      protected boolean selected  
      protected java.lang.Object value  
    • Constructor Summary

      Constructors 
      Constructor Description
      CellContext()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.awt.Color getBackground()
      Returns the background color of the renderered component or null if the component is null
      protected javax.swing.border.Border getBorder()
      Returns the default border of the renderered component depending on cell state.
      int getColumn()
      Returns the cell's column index in view coordinates as set in the install.
      T getComponent()
      Returns the component the cell resides on, may be null.
      protected java.awt.Color getFocusBackground()
      Returns the default focused background color of the renderered component.
      protected javax.swing.border.Border getFocusBorder()
      Returns the default focus border of the renderered component.
      protected java.awt.Color getFocusForeground()
      Returns the default focused foreground color of the renderered component.
      protected java.awt.Color getForeground()
      Returns the foreground color of the renderered component or null if the component is null
      javax.swing.Icon getIcon()
      Returns the icon.
      int getRow()
      Returns the cell's row index in view coordinates as set in the install.
      protected java.awt.Color getSelectionBackground()
      Returns the default selection background color of the renderered component.
      protected java.awt.Color getSelectionForeground()
      Returns the default selection foreground color of the renderered component.
      protected java.lang.String getUIKey​(java.lang.String key)
      Convenience method to build a component type specific lookup key for the UIManager.
      protected java.lang.String getUIPrefix()
      Returns the component type specific prefix of keys for lookup in the UIManager.
      java.lang.Object getValue()
      Returns the value of the cell as set in the install.
      void installContext​(T component, java.lang.Object value, int row, int column, boolean selected, boolean focused, boolean expanded, boolean leaf)
      Sets state of the cell's context.
      boolean isEditable()
      Returns the cell's editability.
      boolean isExpanded()
      Returns the expanded state as set in the install.
      boolean isFocused()
      Returns the focused state as set in the install.
      boolean isLeaf()
      Returns the leaf state as set in the install.
      boolean isSelected()
      Returns the selected state as set in the install.
      java.lang.Object replaceValue​(java.lang.Object value)  
      • 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 default border for unfocused cells.
      • component

        protected transient T extends javax.swing.JComponent component
      • value

        protected transient java.lang.Object value
      • row

        protected transient int row
      • column

        protected transient int column
      • selected

        protected transient boolean selected
      • focused

        protected transient boolean focused
      • expanded

        protected transient boolean expanded
      • leaf

        protected transient boolean leaf
    • Constructor Detail

      • CellContext

        public CellContext()
    • Method Detail

      • installContext

        public void installContext​(T component,
                                   java.lang.Object value,
                                   int row,
                                   int column,
                                   boolean selected,
                                   boolean focused,
                                   boolean expanded,
                                   boolean leaf)
        Sets state of the cell's context. Note that the component might be null to indicate a cell without a concrete context. All accessors must cope with.
        Parameters:
        component - the component the cell resides on, might be null
        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 java.lang.Object replaceValue​(java.lang.Object value)
      • getComponent

        public T getComponent()
        Returns the component the cell resides on, may be null.
        Returns:
        the component the cell resides on.
      • getValue

        public java.lang.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 javax.swing.Icon getIcon()
        Returns the icon. Subclasses should override to return a reasonable cell-related state.

        Here: null.

        Returns:
        the cell's icon.
      • getForeground

        protected java.awt.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 background color of the rendered component.
      • getBackground

        protected java.awt.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 java.awt.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 java.awt.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 javax.swing.border.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 javax.swing.border.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 java.awt.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 java.awt.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.
      • getUIKey

        protected java.lang.String getUIKey​(java.lang.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 java.lang.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.