merge the formfield patch from ooo-build
[ooovba.git] / toolkit / test / accessibility / AccessibleTreeCellRenderer.java
blob8e8f26aa858a7106ef7431894598a9c569d4ab92
1 import javax.swing.tree.DefaultTreeCellRenderer;
2 import javax.swing.tree.TreePath;
3 import javax.swing.JTree;
4 import java.awt.Color;
5 import java.awt.Component;
6 import java.util.Vector;
9 public class AccessibleTreeCellRenderer
10 extends DefaultTreeCellRenderer
12 public Color
13 maDefaultColor,
14 maChangedColor;
15 protected Vector
16 maChangedLines;
20 public AccessibleTreeCellRenderer ()
22 maDefaultColor = Color.black;
23 maChangedColor = Color.red;
24 maChangedLines = new Vector ();
27 public Component getTreeCellRendererComponent (
28 JTree tree,
29 Object value,
30 boolean sel,
31 boolean expanded,
32 boolean leaf,
33 int row,
34 boolean hasFocus)
36 super.getTreeCellRendererComponent(
37 tree, value, sel,
38 expanded, leaf, row,
39 hasFocus);
41 if (maChangedLines.size()<=row || maChangedLines.elementAt (row) == null)
42 setTextNonSelectionColor (maDefaultColor);
43 else
44 setTextNonSelectionColor (maChangedColor);
46 return this;
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.
69 @param aChangedNodes
70 The set of changed nodes. Each entry is a TreePath.
71 @param aTree
72 The JTree that is used to transform the given TreePath objects
73 into rows.
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);