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
.ide
.util
;
18 import com
.intellij
.ide
.ui
.UISettings
;
19 import com
.intellij
.ide
.util
.treeView
.NodeRenderer
;
20 import com
.intellij
.navigation
.ItemPresentation
;
21 import com
.intellij
.navigation
.NavigationItem
;
22 import com
.intellij
.openapi
.actionSystem
.DataConstants
;
23 import com
.intellij
.openapi
.actionSystem
.DataProvider
;
24 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
25 import com
.intellij
.openapi
.editor
.colors
.EditorColorsManager
;
26 import com
.intellij
.openapi
.editor
.colors
.EditorColorsScheme
;
27 import com
.intellij
.openapi
.editor
.markup
.EffectType
;
28 import com
.intellij
.openapi
.editor
.markup
.TextAttributes
;
29 import com
.intellij
.openapi
.vcs
.FileStatus
;
30 import com
.intellij
.openapi
.vfs
.VirtualFile
;
31 import com
.intellij
.openapi
.project
.Project
;
32 import com
.intellij
.problems
.WolfTheProblemSolver
;
33 import com
.intellij
.psi
.PsiElement
;
34 import com
.intellij
.psi
.util
.PsiUtilBase
;
35 import com
.intellij
.ui
.ColoredListCellRenderer
;
36 import com
.intellij
.ui
.SimpleTextAttributes
;
37 import com
.intellij
.ui
.FileColorManager
;
38 import com
.intellij
.util
.IconUtil
;
39 import com
.intellij
.util
.ui
.UIUtil
;
44 public class NavigationItemListCellRenderer
extends JPanel
implements ListCellRenderer
{
45 public NavigationItemListCellRenderer() {
46 super(new BorderLayout());
49 public Component
getListCellRendererComponent(
54 boolean cellHasFocus
) {
55 EditorColorsScheme scheme
= EditorColorsManager
.getInstance().getGlobalScheme();
56 Font editorFont
= new Font(scheme
.getEditorFontName(), Font
.PLAIN
, scheme
.getEditorFontSize());
59 final Component leftCellRendererComponent
=
60 new LeftRenderer().getListCellRendererComponent(list
, value
, index
, isSelected
, cellHasFocus
);
61 final Color listBg
= leftCellRendererComponent
.getBackground();
62 add(leftCellRendererComponent
, BorderLayout
.WEST
);
63 if (UISettings
.getInstance().SHOW_ICONS_IN_QUICK_NAVIGATION
){
64 final DefaultListCellRenderer moduleRenderer
= ModuleRendererFactory
.getInstance().getModuleRenderer();
65 final Component rightCellRendererComponent
=
66 moduleRenderer
.getListCellRendererComponent(list
, value
, index
, isSelected
, cellHasFocus
);
67 rightCellRendererComponent
.setBackground(listBg
);
68 add(rightCellRendererComponent
, BorderLayout
.EAST
);
69 final JPanel spacer
= new JPanel();
70 final Dimension size
= rightCellRendererComponent
.getSize();
71 spacer
.setSize(new Dimension((int)(size
.width
* 0.015 + leftCellRendererComponent
.getSize().width
* 0.015), size
.height
));
72 spacer
.setBackground(isSelected ? UIUtil
.getListSelectionBackground() : listBg
);
73 add(spacer
, BorderLayout
.CENTER
);
75 setBackground(isSelected ? UIUtil
.getListSelectionBackground() : UIUtil
.getListBackground());
79 private static class LeftRenderer
extends ColoredListCellRenderer
{
80 protected void customizeCellRenderer(
87 Color bgColor
= UIUtil
.getListBackground();
89 if (value
instanceof NavigationItem
) {
90 NavigationItem element
= (NavigationItem
)value
;
91 ItemPresentation presentation
= element
.getPresentation();
92 assert presentation
!= null: "PSI elements displayed in choose by name lists must return a non-null value from getPresentation(): element " +
93 element
.toString() + ", class " + element
.getClass().getName();
94 String name
= presentation
.getPresentableText();
95 Color color
= list
.getForeground();
96 boolean isProblemFile
= element
instanceof PsiElement
97 && WolfTheProblemSolver
.getInstance(((PsiElement
)element
).getProject())
98 .isProblemFile(PsiUtilBase
.getVirtualFile((PsiElement
)element
));
100 if (element
instanceof PsiElement
|| element
instanceof DataProvider
) {
101 final PsiElement psiElement
= element
instanceof PsiElement ?
(PsiElement
)element
: (PsiElement
) ((DataProvider
)element
).getData(
102 DataConstants
.PSI_ELEMENT
);
103 if (psiElement
!= null) {
104 final Project project
= psiElement
.getProject();
106 final VirtualFile virtualFile
= PsiUtilBase
.getVirtualFile(psiElement
);
107 isProblemFile
= WolfTheProblemSolver
.getInstance(project
).isProblemFile(virtualFile
);
109 final FileColorManager fileColorManager
= FileColorManager
.getInstance(project
);
110 if (virtualFile
!= null && fileColorManager
.isEnabled()) {
111 final Color fileColor
= fileColorManager
.getFileColor(psiElement
.getContainingFile());
112 if (fileColor
!= null) {
119 FileStatus status
= element
.getFileStatus();
120 if (status
!= FileStatus
.NOT_CHANGED
) {
121 color
= status
.getColor();
124 final TextAttributes textAttributes
= NodeRenderer
.getSimpleTextAttributes(presentation
).toTextAttributes();
126 textAttributes
.setEffectType(EffectType
.WAVE_UNDERSCORE
);
127 textAttributes
.setEffectColor(Color
.red
);
129 textAttributes
.setForegroundColor(color
);
130 SimpleTextAttributes nameAttributes
= SimpleTextAttributes
.fromTextAttributes(textAttributes
);
131 append(name
, nameAttributes
);
132 setIcon(presentation
.getIcon(false));
134 String containerText
= presentation
.getLocationString();
136 if (containerText
!= null && containerText
.length() > 0) {
137 append(" " + containerText
, new SimpleTextAttributes(Font
.PLAIN
, Color
.GRAY
));
141 setIcon(IconUtil
.getEmptyIcon(false));
142 append(value
== null ?
"" : value
.toString(), new SimpleTextAttributes(Font
.PLAIN
, list
.getForeground()));
144 setPaintFocusBorder(false);
145 setBackground(selected ? UIUtil
.getListSelectionBackground() : bgColor
);