update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / refactoring / ui / ClassCellRenderer.java
blobc8e0fbaee4f8e35b8abac34f509d35d593437144
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.
18 * Created by IntelliJ IDEA.
19 * User: dsl
20 * Date: 18.06.2002
21 * Time: 13:47:11
22 * To change template for new class use
23 * Code Style | Class Templates options (Tools | IDE Options).
25 package com.intellij.refactoring.ui;
27 import com.intellij.openapi.util.Iconable;
28 import com.intellij.psi.PsiClass;
29 import com.intellij.refactoring.RefactoringBundle;
31 import javax.swing.*;
32 import java.awt.*;
34 /**
35 * Renders a list cell which contains a class
37 public class ClassCellRenderer extends DefaultListCellRenderer {
38 private final boolean myShowReadOnly;
39 public ClassCellRenderer() {
40 setOpaque(true);
41 myShowReadOnly = true;
44 public ClassCellRenderer(boolean showReadOnly) {
45 setOpaque(true);
46 myShowReadOnly = showReadOnly;
49 public Component getListCellRendererComponent(
50 JList list,
51 Object value,
52 int index,
53 boolean isSelected,
54 boolean cellHasFocus) {
55 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
57 return customizeRenderer(this, value, myShowReadOnly);
60 public static JLabel customizeRenderer(final JLabel cellRendererComponent, final Object value, final boolean showReadOnly) {
61 PsiClass aClass = (PsiClass) value;
62 cellRendererComponent.setText(getClassText(aClass));
64 int flags = Iconable.ICON_FLAG_VISIBILITY;
65 if (showReadOnly) {
66 flags |= Iconable.ICON_FLAG_READ_STATUS;
68 Icon icon = aClass.getIcon(flags);
69 if(icon != null) {
70 cellRendererComponent.setIcon(icon);
72 return cellRendererComponent;
75 private static String getClassText(PsiClass aClass) {
76 String qualifiedName = aClass.getQualifiedName();
77 if (qualifiedName != null) {
78 return qualifiedName;
81 String name = aClass.getName();
82 if (name != null) {
83 return name;
86 return RefactoringBundle.message("anonymous.class.text");