org.jdesktop.swingx.decorator
Class ConditionalHighlighter

java.lang.Object
  extended by org.jdesktop.swingx.decorator.Highlighter
      extended by org.jdesktop.swingx.decorator.ConditionalHighlighter
Direct Known Subclasses:
PatternHighlighter, RolloverHighlighter

public abstract class ConditionalHighlighter
extends Highlighter

ConditionalHighlighter

Author:
Ramesh Gupta

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jdesktop.swingx.decorator.Highlighter
Highlighter.UIHighlighter
 
Field Summary
protected  int highlightColumn
           
protected  int mask
           
protected  int testColumn
           
 
Fields inherited from class org.jdesktop.swingx.decorator.Highlighter
changeEvent, immutable, ledgerBackground, listenerList, notePadBackground
 
Constructor Summary
ConditionalHighlighter()
           
ConditionalHighlighter(java.awt.Color cellBackground, java.awt.Color cellForeground, int testColumn, int highlightColumn)
          Constructs a ConditionalHighlighter instance with the specified background and foreground colors that will be used to highlight the renderer component for a cell in the specified highlightColumn of any row if and only if needsHighlight returns true for the adapter that identifies that cell.
 
Method Summary
protected  java.awt.Color computeBackground(java.awt.Component renderer, ComponentAdapter adapter)
          Computes a suitable background for the renderer component within the specified adapter and returns the computed color.
protected  java.awt.Color computeForeground(java.awt.Component renderer, ComponentAdapter adapter)
          Computes a suitable foreground for the renderer component within the specified adapter and returns the computed color.
protected  java.awt.Color computeSelectedForeground(java.awt.Color seed)
          Computes the selected foreground color.
protected  java.awt.Component doMask(java.awt.Component renderer, ComponentAdapter adapter)
           
 int getHighlightColumnIndex()
           
 int getMask()
           
 int getTestColumnIndex()
           
 java.awt.Component highlight(java.awt.Component renderer, ComponentAdapter adapter)
          Performs a conditional highlight.
protected  void maskBackground(java.awt.Component renderer, ComponentAdapter adapter)
           
protected  void maskForeground(java.awt.Component renderer, ComponentAdapter adapter)
           
protected  boolean needsHighlight(ComponentAdapter adapter)
          Checks if the cell identified by the specified adapter is a potential candidate for highlighting, and returns true if so; otherwise, it returns false.
 void setHighlightColumnIndex(int columnIndex)
           
 void setMask(int alpha)
           
 void setTestColumnIndex(int columnIndex)
           
protected abstract  boolean test(ComponentAdapter adapter)
          Tests if the cell identified by the specified adapter should actually be highlighted, and returns true if so; otherwise, it returns false.
 
Methods inherited from class org.jdesktop.swingx.decorator.Highlighter
addChangeListener, applyBackground, applyFont, applyForeground, computeSelectedBackground, doHighlight, fireStateChanged, getBackground, getChangeListeners, getForeground, getSelectedBackground, getSelectedForeground, isImmutable, removeChangeListener, setBackground, setForeground, setSelectedBackground, setSelectedForeground
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

testColumn

protected int testColumn

highlightColumn

protected int highlightColumn

mask

protected int mask
Constructor Detail

ConditionalHighlighter

public ConditionalHighlighter()

ConditionalHighlighter

public ConditionalHighlighter(java.awt.Color cellBackground,
                              java.awt.Color cellForeground,
                              int testColumn,
                              int highlightColumn)

Constructs a ConditionalHighlighter instance with the specified background and foreground colors that will be used to highlight the renderer component for a cell in the specified highlightColumn of any row if and only if needsHighlight returns true for the adapter that identifies that cell.

Parameters:
cellBackground - background color for highlighted cells, or null, if background should not be changed
cellForeground - foreground color for highlighted cells, or null, if foreground should not be changed
testColumn - column whose value is to be tested to determine if a cell should be highlighted
highlightColumn - column whose index is used to determine if a cell could be highlighted; may be a valid column index in model coordinates, or -1 to indicate all columns
Method Detail

setMask

public void setMask(int alpha)

getMask

public int getMask()

highlight

public java.awt.Component highlight(java.awt.Component renderer,
                                    ComponentAdapter adapter)
Performs a conditional highlight. Calls doHighlight if and only if needsHighlight returns true.

Overrides:
highlight in class Highlighter
Parameters:
renderer -
adapter -
Returns:
the highlighted component

doMask

protected java.awt.Component doMask(java.awt.Component renderer,
                                    ComponentAdapter adapter)

maskBackground

protected void maskBackground(java.awt.Component renderer,
                              ComponentAdapter adapter)

maskForeground

protected void maskForeground(java.awt.Component renderer,
                              ComponentAdapter adapter)

computeBackground

protected java.awt.Color computeBackground(java.awt.Component renderer,
                                           ComponentAdapter adapter)
Description copied from class: Highlighter

Computes a suitable background for the renderer component within the specified adapter and returns the computed color. The computed color depends on two factors: (i) whether the background color for this Highlighter is null or not, and (ii) whether the cell identified by the specified adapter isSelected or not.

If the background color for this Highlighter is not null, this method starts with an initial value that is equal to that background color, and proceeds to check the selected state of the cell. Otherwise, it starts with the background color of the component whose cell is being rendererd (not the background color of the renderer component that was passed in), and proceeds to check the selected state of the cell.

If the cell identified by the specified adapter is selected, this method returns the value computed by computeSelectedBackground when passed the initial background color computed earlier. Otherwise, it simply returns the initial background color computed earlier.

Overrides:
computeBackground in class Highlighter
Parameters:
renderer -
adapter -
Returns:
null if the background is null; otherwise delegate to superclass

computeForeground

protected java.awt.Color computeForeground(java.awt.Component renderer,
                                           ComponentAdapter adapter)
Description copied from class: Highlighter

Computes a suitable foreground for the renderer component within the specified adapter and returns the computed color. The computed color depends on two factors: (i) whether the foreground color for this Highlighter is null or not, and (ii) whether the cell identified by the specified adapter isSelected or not.

If the foreground color for this Highlighter is not null, this method starts with an initial value that is equal to that foreground color, and proceeds to check the selected state of the cell. Otherwise, it starts with the foreground color of the component whose cell is being rendererd (not the foreground color of the renderer component that was passed in), and proceeds to check the selected state of the cell.

If the cell identified by the specified adapter is selected, this method returns the value computed by computeSelectedBackground when passed the initial foreground color computed earlier. Otherwise, it simply returns the initial foreground color computed earlier.

Overrides:
computeForeground in class Highlighter
Parameters:
renderer -
adapter -
Returns:
null if the foreground is null; otherwise delegate to superclass

computeSelectedForeground

protected java.awt.Color computeSelectedForeground(java.awt.Color seed)
Description copied from class: Highlighter
Computes the selected foreground color. If the selected foreground color of this Highlighter is not null, this method returns that color. Otherwise, it returns Color.white, ignoring the specified seed color.

Overrides:
computeSelectedForeground in class Highlighter
Parameters:
seed - initial foreground color; must cope with null!
Returns:
the foreground color for a selected cell

getTestColumnIndex

public int getTestColumnIndex()

setTestColumnIndex

public void setTestColumnIndex(int columnIndex)

getHighlightColumnIndex

public int getHighlightColumnIndex()

setHighlightColumnIndex

public void setHighlightColumnIndex(int columnIndex)

needsHighlight

protected boolean needsHighlight(ComponentAdapter adapter)
Checks if the cell identified by the specified adapter is a potential candidate for highlighting, and returns true if so; otherwise, it returns false.

Parameters:
adapter -
Returns:
true if the cell identified by the specified adapter needs highlight; false otherwise

test

protected abstract boolean test(ComponentAdapter adapter)
Tests if the cell identified by the specified adapter should actually be highlighted, and returns true if so; otherwise, it returns false.

Parameters:
adapter -
Returns:
true if the test succeeds; false otherwise


Copyright © 2005 Sun Microsystems All Rights Reserved.