1 import javax
.swing
.tree
.DefaultTreeCellRenderer
;
2 import javax
.swing
.tree
.TreePath
;
3 import javax
.swing
.JTree
;
5 import java
.awt
.Component
;
6 import java
.util
.Vector
;
9 public class AccessibleTreeCellRenderer
10 extends DefaultTreeCellRenderer
20 public AccessibleTreeCellRenderer ()
22 maDefaultColor
= Color
.black
;
23 maChangedColor
= Color
.red
;
24 maChangedLines
= new Vector ();
27 public Component
getTreeCellRendererComponent (
36 super.getTreeCellRendererComponent(
41 if (maChangedLines
.size()<=row
|| maChangedLines
.elementAt (row
) == null)
42 setTextNonSelectionColor (maDefaultColor
);
44 setTextNonSelectionColor (maChangedColor
);
49 /** Tell the cell renderer that no changes shall be displayed anymore.
51 public void clearAllChanges ()
53 maChangedLines
.clear();
56 /** Inform the cell renderer of a new changed line which to paint
57 highlighted when asked to paint it the next time.
59 public void addChangedLine (int nRow
)
61 if (maChangedLines
.size() <= nRow
)
62 maChangedLines
.setSize (nRow
+1);
63 nRow
-= 1; // row index is one to large for some reason.
64 maChangedLines
.set (nRow
, new Boolean (true));
67 /** Inform the cell renderer of a set of changed line which to paint
68 highlighted when asked to paint them the next time.
70 The set of changed nodes. Each entry is a TreePath.
72 The JTree that is used to transform the given TreePath objects
75 public void addChangedNodes (Vector aChangedNodes
, JTree aTree
)
77 for (int i
=0; i
<aChangedNodes
.size(); i
++)
79 TreePath aPath
= (TreePath
)aChangedNodes
.elementAt (i
);
80 int nRow
= aTree
.getRowForPath (aPath
);
81 addChangedLine (nRow
);