ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / lang-impl / src / com / intellij / ide / hierarchy / HierarchyNodeRenderer.java
blob2f92f23370af98d2b7cb68f4cf261083f5b3b60c
1 /*
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;
24 import javax.swing.*;
25 import javax.swing.tree.DefaultMutableTreeNode;
26 import java.awt.*;
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);
37 if (expanded){
38 setIcon(descriptor.getOpenIcon());
40 else{
41 setIcon(descriptor.getClosedIcon());
43 if (!selected) {
44 final Color color = getBackgroundColor(descriptor);
45 if (color != null) {
46 setBackground(color);
53 @Nullable
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);
60 return null;