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.
17 package com
.intellij
.ide
.hierarchy
;
19 import com
.intellij
.psi
.PsiFile
;
20 import com
.intellij
.ui
.ColoredTreeCellRenderer
;
21 import com
.intellij
.ui
.FileColorManager
;
22 import org
.jetbrains
.annotations
.Nullable
;
25 import javax
.swing
.tree
.DefaultMutableTreeNode
;
28 public final class HierarchyNodeRenderer
extends ColoredTreeCellRenderer
{
29 public void customizeCellRenderer(final JTree tree
, final Object value
, final boolean selected
, final boolean expanded
, final boolean leaf
,
30 final int row
, final boolean hasFocus
) {
31 if (value
instanceof DefaultMutableTreeNode
) {
32 final DefaultMutableTreeNode node
= (DefaultMutableTreeNode
)value
;
33 final Object object
= node
.getUserObject();
34 if (object
instanceof HierarchyNodeDescriptor
) {
35 final HierarchyNodeDescriptor descriptor
= (HierarchyNodeDescriptor
)object
;
36 descriptor
.getHighlightedText().customize(this);
38 setIcon(descriptor
.getOpenIcon());
41 setIcon(descriptor
.getClosedIcon());
44 final Color color
= getBackgroundColor(descriptor
);
54 private static Color
getBackgroundColor(final HierarchyNodeDescriptor descriptor
) {
55 final PsiFile psiFile
= descriptor
.getContainingFile();
56 if (psiFile
!= null && psiFile
.isValid()) {
57 final FileColorManager colorManager
= FileColorManager
.getInstance(descriptor
.getProject());
58 return colorManager
.getRendererBackground(psiFile
);