2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import java
.awt
.Color
;
20 import java
.awt
.Component
;
21 import java
.util
.ArrayList
;
22 import java
.util
.List
;
24 import javax
.swing
.JTree
;
25 import javax
.swing
.tree
.DefaultTreeCellRenderer
;
26 import javax
.swing
.tree
.TreePath
;
29 public class AccessibleTreeCellRenderer
30 extends DefaultTreeCellRenderer
35 protected ArrayList
<Boolean
>
40 public AccessibleTreeCellRenderer ()
42 maDefaultColor
= Color
.black
;
43 maChangedColor
= Color
.red
;
44 maChangedLines
= new ArrayList
<Boolean
> ();
47 public Component
getTreeCellRendererComponent (
56 super.getTreeCellRendererComponent(
61 if (maChangedLines
.size()<=row
|| maChangedLines
.get (row
) == null)
62 setTextNonSelectionColor (maDefaultColor
);
64 setTextNonSelectionColor (maChangedColor
);
69 /** Tell the cell renderer that no changes shall be displayed anymore.
71 public void clearAllChanges ()
73 maChangedLines
.clear();
76 /** Inform the cell renderer of a new changed line which to paint
77 highlighted when asked to paint it the next time.
79 public void addChangedLine (int nRow
)
81 while (maChangedLines
.size() <= nRow
)
82 maChangedLines
.add(null);
83 nRow
-= 1; // row index is one to large for some reason.
84 maChangedLines
.set (nRow
, true);
87 /** Inform the cell renderer of a set of changed line which to paint
88 highlighted when asked to paint them the next time.
90 The set of changed nodes. Each entry is a TreePath.
92 The JTree that is used to transform the given TreePath objects
95 public void addChangedNodes (List
<TreePath
> aChangedNodes
, JTree aTree
)
97 for (int i
=0; i
<aChangedNodes
.size(); i
++)
99 TreePath aPath
= aChangedNodes
.get (i
);
100 int nRow
= aTree
.getRowForPath (aPath
);
101 addChangedLine (nRow
);