Search in sources :

Example 1 with PresentationData

use of com.intellij.ide.projectView.PresentationData in project intellij-plugins by StepicOrg.

the class NavBarModelExtensionUtils method getPresentableText.

@Nullable
public static String getPresentableText(@Nullable final Object object) {
    if (object instanceof Project) {
        Project project = (Project) object;
        StudyNode root = StepikProjectManager.getProjectRoot(project);
        if (root == null) {
            return null;
        }
        return root.getName();
    }
    if (object instanceof PsiDirectory) {
        PsiDirectory psiDirectory = (PsiDirectory) object;
        PresentationData data = new PresentationData();
        updatePresentationData(data, psiDirectory);
        String text = data.getPresentableText();
        if (text != null)
            return text;
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) PresentationData(com.intellij.ide.projectView.PresentationData) PresentationDataUtils.updatePresentationData(org.stepik.plugin.utils.PresentationDataUtils.updatePresentationData) PsiDirectory(com.intellij.psi.PsiDirectory) StudyNode(org.stepik.core.courseFormat.StudyNode) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PresentationData

use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.

the class NodeRenderer method customizeCellRenderer.

@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    Color color = null;
    NodeDescriptor descriptor = null;
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        Object userObject = node.getUserObject();
        if (userObject instanceof NodeDescriptor) {
            descriptor = (NodeDescriptor) userObject;
            color = descriptor.getColor();
            setIcon(descriptor.getIcon());
        }
    }
    if (descriptor instanceof PresentableNodeDescriptor) {
        final PresentableNodeDescriptor node = (PresentableNodeDescriptor) descriptor;
        final PresentationData presentation = node.getPresentation();
        final List<PresentableNodeDescriptor.ColoredFragment> coloredText = presentation.getColoredText();
        if (coloredText.isEmpty()) {
            String text = tree.convertValueToText(value.toString(), selected, expanded, leaf, row, hasFocus);
            SimpleTextAttributes simpleTextAttributes = getSimpleTextAttributes(node, presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
            append(text, simpleTextAttributes);
            String location = presentation.getLocationString();
            if (!StringUtil.isEmpty(location)) {
                SimpleTextAttributes attributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.GRAYED_ATTRIBUTES);
                append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), attributes, false);
            }
        } else {
            boolean first = true;
            for (PresentableNodeDescriptor.ColoredFragment each : coloredText) {
                SimpleTextAttributes simpleTextAttributes = each.getAttributes();
                if (each.getAttributes().getFgColor() == null && presentation.getForcedTextForeground() != null) {
                    simpleTextAttributes = addColorToSimpleTextAttributes(each.getAttributes(), presentation.getForcedTextForeground() != null ? presentation.getForcedTextForeground() : color);
                }
                if (first) {
                    final TextAttributesKey textAttributesKey = presentation.getTextAttributesKey();
                    if (textAttributesKey != null) {
                        final TextAttributes forcedAttributes = getColorsScheme().getAttributes(textAttributesKey);
                        if (forcedAttributes != null) {
                            simpleTextAttributes = SimpleTextAttributes.merge(simpleTextAttributes, SimpleTextAttributes.fromTextAttributes(forcedAttributes));
                        }
                    }
                    first = false;
                }
                // treat grayed text as non-main
                boolean isMain = simpleTextAttributes != SimpleTextAttributes.GRAYED_ATTRIBUTES;
                append(each.getText(), simpleTextAttributes, isMain);
            }
            String location = presentation.getLocationString();
            if (!StringUtil.isEmpty(location)) {
                append(presentation.getLocationPrefix() + location + presentation.getLocationSuffix(), SimpleTextAttributes.GRAY_ATTRIBUTES, false);
            }
        }
        setToolTipText(presentation.getTooltip());
    } else if (value != null) {
        String text = value.toString();
        if (descriptor != null) {
            text = descriptor.myName;
        }
        text = tree.convertValueToText(text, selected, expanded, leaf, row, hasFocus);
        if (text == null) {
            text = "";
        }
        append(text);
        setToolTipText(null);
    }
    if (!AbstractTreeUi.isLoadingNode(value)) {
        SpeedSearchUtil.applySpeedSearchHighlighting(tree, this, true, selected);
    }
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TextAttributesKey(com.intellij.openapi.editor.colors.TextAttributesKey) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 3 with PresentationData

use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.

the class PresentableNodeDescriptor method getUpdatedPresentation.

private PresentationData getUpdatedPresentation() {
    PresentationData presentation = myUpdatedPresentation != null ? myUpdatedPresentation : createPresentation();
    myUpdatedPresentation = presentation;
    presentation.clear();
    update(presentation);
    if (shouldPostprocess()) {
        postprocess(presentation);
    }
    return presentation;
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData)

Example 4 with PresentationData

use of com.intellij.ide.projectView.PresentationData in project intellij-community by JetBrains.

the class PackageElementNode method getTestPresentation.

@Override
public String getTestPresentation() {
    final PresentationData presentation = new PresentationData();
    update(presentation);
    return "PsiPackage: " + presentation.getPresentableText();
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData)

Example 5 with PresentationData

use of com.intellij.ide.projectView.PresentationData in project android by JetBrains.

the class NodeHyperlinkSupport method addHyperlinkBehaviorToSupportedNodes.

private void addHyperlinkBehaviorToSupportedNodes() {
    myTree.setCellRenderer(new NodeRenderer() {

        @NotNull
        @Override
        protected SimpleTextAttributes getSimpleTextAttributes(@NotNull PresentationData presentation, Color color, @NotNull Object node) {
            List<PsIssue> issues = Collections.emptyList();
            if (myShowIssues && node instanceof AbstractPsModelNode) {
                AbstractPsModelNode<? extends PsModel> modelNode = (AbstractPsModelNode<? extends PsModel>) node;
                issues = findIssues(modelNode, IssuesByTypeAndTextComparator.INSTANCE);
                presentation.setTooltip(getTooltipText(issues, false));
            }
            if (myHoveredNode != null && myHoveredNode == node) {
                return LINK_ATTRIBUTES;
            }
            SimpleTextAttributes textAttributes = super.getSimpleTextAttributes(presentation, color, node);
            if (!issues.isEmpty()) {
                PsIssue issue = issues.get(0);
                Color waveColor = issue.getSeverity().getColor();
                textAttributes = textAttributes.derive(STYLE_WAVED, null, null, waveColor);
            }
            return textAttributes;
        }

        @Override
        public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (myShowIssues) {
                AbstractPsModelNode<? extends PsModel> modelNode = findModelNode(value);
                if (modelNode != null) {
                    List<PsIssue> issues = findIssues(modelNode, null);
                    if (!issues.isEmpty()) {
                        // Force color change of the node.
                        modelNode.getPresentation().clearText();
                    }
                }
            }
            super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
            Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
            if (userObject instanceof CellAppearanceEx) {
                ((CellAppearanceEx) userObject).customize(this);
            }
        }

        @Nullable
        private AbstractPsModelNode<? extends PsModel> findModelNode(@Nullable Object value) {
            if (value instanceof DefaultMutableTreeNode) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
                Object userObject = node.getUserObject();
                if (userObject instanceof AbstractPsModelNode) {
                    return (AbstractPsModelNode<? extends PsModel>) userObject;
                }
            }
            return null;
        }
    });
    MouseAdapter mouseListener = new MouseAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            Cursor cursor = getDefaultCursor();
            T node = getIfHyperlink(e);
            if (node != null) {
                cursor = getPredefinedCursor(HAND_CURSOR);
            }
            setHoveredNode(node);
            myTree.setCursor(cursor);
        }
    };
    myTree.addMouseMotionListener(mouseListener);
    // Make the cursor change to 'hand' if the mouse pointer is over a supported node and the user presses Ctrl or Cmd.
    myKeyEventDispatcher = e -> {
        T node = null;
        if (e.getID() == KEY_PRESSED) {
            Cursor cursor = getDefaultCursor();
            if (isMetaOrCtrlKeyPressed(e)) {
                node = getNodeUnderMousePointer();
                if (node != null) {
                    cursor = getPredefinedCursor(HAND_CURSOR);
                }
            }
            setHoveredNode(node);
            myTree.setCursor(cursor);
        } else if (e.getID() == KEY_RELEASED) {
            if (isMetaOrCtrlKeyPressed(e)) {
                setHoveredNode(null);
            }
            myTree.setCursor(getDefaultCursor());
        }
        return false;
    };
    KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(myKeyEventDispatcher);
}
Also used : PresentationData(com.intellij.ide.projectView.PresentationData) CellAppearanceEx(com.intellij.openapi.roots.ui.CellAppearanceEx) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsModel(com.android.tools.idea.gradle.structure.model.PsModel) MouseAdapter(java.awt.event.MouseAdapter) Cursor(java.awt.Cursor) NotNull(org.jetbrains.annotations.NotNull) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) List(java.util.List) PsIssue(com.android.tools.idea.gradle.structure.model.PsIssue) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PresentationData (com.intellij.ide.projectView.PresentationData)14 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)5 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)4 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)3 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)3 PresentableNodeDescriptor (com.intellij.ide.util.treeView.PresentableNodeDescriptor)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 PsIssue (com.android.tools.idea.gradle.structure.model.PsIssue)1 PsModel (com.android.tools.idea.gradle.structure.model.PsModel)1 ExporterToTextFile (com.intellij.ide.ExporterToTextFile)1 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)1 ProjectViewNode (com.intellij.ide.projectView.ProjectViewNode)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)1