Search in sources :

Example 1 with ColoredItemPresentation

use of com.intellij.navigation.ColoredItemPresentation in project intellij-community by JetBrains.

the class PyStructureViewElement method getPresentation.

@NotNull
@Override
public ItemPresentation getPresentation() {
    final PyElement element = getValue();
    final ItemPresentation presentation = element != null ? element.getPresentation() : null;
    return new ColoredItemPresentation() {

        @Nullable
        @Override
        public String getPresentableText() {
            if (element instanceof PyFile) {
                return element.getName();
            }
            return presentation != null ? presentation.getPresentableText() : PyNames.UNNAMED_ELEMENT;
        }

        @Nullable
        @Override
        public TextAttributesKey getTextAttributesKey() {
            if (isInherited()) {
                return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
            }
            return null;
        }

        @Nullable
        @Override
        public String getLocationString() {
            return null;
        }

        @Nullable
        @Override
        public Icon getIcon(boolean open) {
            if (element == null) {
                return null;
            }
            Icon normal_icon = element.getIcon(0);
            // override normal
            if (myIcon != null)
                normal_icon = myIcon;
            if (myVisibility == Visibility.NORMAL) {
                return normal_icon;
            } else {
                LayeredIcon icon = new LayeredIcon(2);
                icon.setIcon(normal_icon, 0);
                Icon overlay = null;
                if (myVisibility == Visibility.PRIVATE || myVisibility == Visibility.PROTECTED) {
                    overlay = PythonIcons.Python.Nodes.Lock;
                } else if (myVisibility == Visibility.PREDEFINED) {
                    overlay = PythonIcons.Python.Nodes.Cyan_dot;
                } else if (myVisibility == Visibility.INVISIBLE) {
                    overlay = PythonIcons.Python.Nodes.Red_inv_triangle;
                }
                if (overlay != null) {
                    icon.setIcon(overlay, 1);
                }
                return icon;
            }
        }
    };
}
Also used : LayeredIcon(com.intellij.ui.LayeredIcon) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ItemPresentation(com.intellij.navigation.ItemPresentation) LayeredIcon(com.intellij.ui.LayeredIcon) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ColoredItemPresentation

use of com.intellij.navigation.ColoredItemPresentation in project intellij-community by JetBrains.

the class ClassPresentationProvider method getPresentation.

@Override
public ItemPresentation getPresentation(@NotNull final PsiClass psiClass) {
    return new ColoredItemPresentation() {

        @Override
        public String getPresentableText() {
            return ClassPresentationUtil.getNameForClass(psiClass, false);
        }

        @Override
        public String getLocationString() {
            PsiFile file = psiClass.getContainingFile();
            if (file instanceof PsiClassOwner) {
                PsiClassOwner classOwner = (PsiClassOwner) file;
                String packageName = classOwner.getPackageName();
                if (packageName.isEmpty())
                    return null;
                return "(" + packageName + ")";
            }
            return null;
        }

        @Override
        public TextAttributesKey getTextAttributesKey() {
            try {
                if (psiClass.isDeprecated()) {
                    return CodeInsightColors.DEPRECATED_ATTRIBUTES;
                }
            } catch (IndexNotReadyException ignore) {
            }
            return null;
        }

        @Override
        public Icon getIcon(boolean open) {
            return psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY | Iconable.ICON_FLAG_READ_STATUS);
        }
    };
}
Also used : PsiClassOwner(com.intellij.psi.PsiClassOwner) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) PsiFile(com.intellij.psi.PsiFile)

Example 3 with ColoredItemPresentation

use of com.intellij.navigation.ColoredItemPresentation in project intellij-community by JetBrains.

the class PsiElementListCellRenderer method getNavigationItemAttributes.

@Nullable
protected TextAttributes getNavigationItemAttributes(Object value) {
    TextAttributes attributes = null;
    if (value instanceof NavigationItem) {
        TextAttributesKey attributesKey = null;
        final ItemPresentation presentation = ((NavigationItem) value).getPresentation();
        if (presentation instanceof ColoredItemPresentation)
            attributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
        if (attributesKey != null) {
            attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
        }
    }
    return attributes;
}
Also used : NavigationItem(com.intellij.navigation.NavigationItem) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) ItemPresentation(com.intellij.navigation.ItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ColoredItemPresentation

use of com.intellij.navigation.ColoredItemPresentation in project intellij-community by JetBrains.

the class NodeRenderer method getSimpleTextAttributes.

public static SimpleTextAttributes getSimpleTextAttributes(@Nullable final ItemPresentation presentation, @NotNull EditorColorsScheme colorsScheme) {
    if (presentation instanceof ColoredItemPresentation) {
        final TextAttributesKey textAttributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
        if (textAttributesKey == null)
            return SimpleTextAttributes.REGULAR_ATTRIBUTES;
        final TextAttributes textAttributes = colorsScheme.getAttributes(textAttributesKey);
        return textAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.fromTextAttributes(textAttributes);
    }
    return SimpleTextAttributes.REGULAR_ATTRIBUTES;
}
Also used : ColoredItemPresentation(com.intellij.navigation.ColoredItemPresentation) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey)

Aggregations

ColoredItemPresentation (com.intellij.navigation.ColoredItemPresentation)4 ItemPresentation (com.intellij.navigation.ItemPresentation)2 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 NavigationItem (com.intellij.navigation.NavigationItem)1 IndexNotReadyException (com.intellij.openapi.project.IndexNotReadyException)1 PsiClassOwner (com.intellij.psi.PsiClassOwner)1 PsiFile (com.intellij.psi.PsiFile)1 LayeredIcon (com.intellij.ui.LayeredIcon)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1