1*cdf0e10cSrcweir import javax.swing.tree.DefaultTreeCellRenderer;
2*cdf0e10cSrcweir import javax.swing.tree.TreePath;
3*cdf0e10cSrcweir import javax.swing.JTree;
4*cdf0e10cSrcweir import java.awt.Color;
5*cdf0e10cSrcweir import java.awt.Component;
6*cdf0e10cSrcweir import java.util.Vector;
7*cdf0e10cSrcweir 
8*cdf0e10cSrcweir 
9*cdf0e10cSrcweir public class AccessibleTreeCellRenderer
10*cdf0e10cSrcweir     extends DefaultTreeCellRenderer
11*cdf0e10cSrcweir {
12*cdf0e10cSrcweir     public Color
13*cdf0e10cSrcweir         maDefaultColor,
14*cdf0e10cSrcweir         maChangedColor;
15*cdf0e10cSrcweir     protected Vector
16*cdf0e10cSrcweir         maChangedLines;
17*cdf0e10cSrcweir 
18*cdf0e10cSrcweir 
19*cdf0e10cSrcweir 
20*cdf0e10cSrcweir     public AccessibleTreeCellRenderer ()
21*cdf0e10cSrcweir     {
22*cdf0e10cSrcweir         maDefaultColor = Color.black;
23*cdf0e10cSrcweir         maChangedColor = Color.red;
24*cdf0e10cSrcweir         maChangedLines = new Vector ();
25*cdf0e10cSrcweir     }
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir     public Component getTreeCellRendererComponent (
28*cdf0e10cSrcweir         JTree tree,
29*cdf0e10cSrcweir         Object value,
30*cdf0e10cSrcweir         boolean sel,
31*cdf0e10cSrcweir         boolean expanded,
32*cdf0e10cSrcweir         boolean leaf,
33*cdf0e10cSrcweir         int row,
34*cdf0e10cSrcweir         boolean hasFocus)
35*cdf0e10cSrcweir     {
36*cdf0e10cSrcweir         super.getTreeCellRendererComponent(
37*cdf0e10cSrcweir             tree, value, sel,
38*cdf0e10cSrcweir             expanded, leaf, row,
39*cdf0e10cSrcweir             hasFocus);
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir         if (maChangedLines.size()<=row || maChangedLines.elementAt (row) == null)
42*cdf0e10cSrcweir             setTextNonSelectionColor (maDefaultColor);
43*cdf0e10cSrcweir         else
44*cdf0e10cSrcweir             setTextNonSelectionColor (maChangedColor);
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir         return this;
47*cdf0e10cSrcweir     }
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     /** Tell the cell renderer that no changes shall be displayed anymore.
50*cdf0e10cSrcweir     */
51*cdf0e10cSrcweir     public void clearAllChanges ()
52*cdf0e10cSrcweir     {
53*cdf0e10cSrcweir         maChangedLines.clear();
54*cdf0e10cSrcweir     }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir     /** Inform the cell renderer of a new changed line which to paint
57*cdf0e10cSrcweir         highlighted when asked to paint it the next time.
58*cdf0e10cSrcweir     */
59*cdf0e10cSrcweir     public void addChangedLine (int nRow)
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         if (maChangedLines.size() <= nRow)
62*cdf0e10cSrcweir             maChangedLines.setSize (nRow+1);
63*cdf0e10cSrcweir         nRow -= 1; // row index is one to large for some reason.
64*cdf0e10cSrcweir         maChangedLines.set (nRow, new Boolean (true));
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     /** Inform the cell renderer of a set of changed line which to paint
68*cdf0e10cSrcweir         highlighted when asked to paint them the next time.
69*cdf0e10cSrcweir         @param aChangedNodes
70*cdf0e10cSrcweir             The set of changed nodes.  Each entry is a TreePath.
71*cdf0e10cSrcweir         @param aTree
72*cdf0e10cSrcweir             The JTree that is used to transform the given TreePath objects
73*cdf0e10cSrcweir             into rows.
74*cdf0e10cSrcweir     */
75*cdf0e10cSrcweir     public void addChangedNodes (Vector aChangedNodes, JTree aTree)
76*cdf0e10cSrcweir     {
77*cdf0e10cSrcweir         for (int i=0; i<aChangedNodes.size(); i++)
78*cdf0e10cSrcweir         {
79*cdf0e10cSrcweir             TreePath aPath = (TreePath)aChangedNodes.elementAt (i);
80*cdf0e10cSrcweir             int nRow = aTree.getRowForPath (aPath);
81*cdf0e10cSrcweir             addChangedLine (nRow);
82*cdf0e10cSrcweir         }
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87