2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.ui
;
19 import javax
.swing
.event
.TreeSelectionEvent
;
20 import javax
.swing
.event
.TreeSelectionListener
;
21 import javax
.swing
.tree
.TreeCellRenderer
;
22 import javax
.swing
.tree
.TreePath
;
25 public final class TreeToolTipHandler
extends AbstractToolTipHandler
<Integer
, JTree
>{
26 protected TreeToolTipHandler(JTree tree
) {
28 tree
.getSelectionModel().addTreeSelectionListener(
29 new TreeSelectionListener() {
30 public void valueChanged(TreeSelectionEvent e
) {
34 catch (Exception e1
) {
35 // Workaround for some race conditions in Swing, see
36 // http://www.intellij.net/tracker/idea/viewSCR?publicId=53961
43 public static void install(JTree tree
) {
44 new TreeToolTipHandler(tree
);
47 protected Integer
getCellKeyForPoint(Point point
) {
48 int rowIndex
= myComponent
.getRowForLocation(point
.x
, point
.y
);
49 return rowIndex
!= -1 ?
new Integer(rowIndex
) : null;
52 protected Rectangle
getCellBounds(Integer key
, Component rendererComponent
) {
53 int rowIndex
= key
.intValue();
54 TreePath path
= myComponent
.getPathForRow(rowIndex
);
55 Rectangle cellBounds
= myComponent
.getPathBounds(path
);
59 protected Component
getRendererComponent(Integer key
) {
60 int rowIndex
= key
.intValue();
62 TreeCellRenderer renderer
= myComponent
.getCellRenderer();
63 if (renderer
== null) {
66 TreePath path
= myComponent
.getPathForRow(rowIndex
);
70 Object node
= path
.getLastPathComponent();
71 rComponent
= renderer
.getTreeCellRendererComponent(
74 myComponent
.isRowSelected(rowIndex
),
75 myComponent
.isExpanded(rowIndex
),
76 myComponent
.getModel().isLeaf(node
),
78 myComponent
.hasFocus()