Search in sources :

Example 46 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project android by JetBrains.

the class DetailsTreeNode method customizeRenderer.

@Override
public void customizeRenderer(@NotNull Renderer renderer, @Nullable JTree tree, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    SimpleTextAttributes attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    renderer.getTextRenderer().append(myModel.getTitle(), attributes);
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 47 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes 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)

Example 48 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project android by JetBrains.

the class StringsCellRenderer method customizeCellRenderer.

@Override
protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) {
    if (!(value instanceof String)) {
        return;
    }
    String s = (String) value;
    if (shouldClip(s)) {
        s = clip(s);
    }
    row = table.convertRowIndexToModel(row);
    column = table.convertColumnIndexToModel(column);
    String problem = ((StringResourceTableModel) table.getModel()).getCellProblem(row, column);
    SimpleTextAttributes attributes;
    if (problem == null) {
        attributes = SimpleTextAttributes.REGULAR_ATTRIBUTES;
    } else if (column == StringResourceTableModel.KEY_COLUMN) {
        attributes = SimpleTextAttributes.ERROR_ATTRIBUTES;
    } else {
        attributes = CELL_ERROR_ATTRIBUTES;
    }
    Font currentFont = table.getFont();
    Font f = FontUtil.getFontAbleToDisplay(s, currentFont);
    if (currentFont != f) {
        setFont(f);
    }
    setToolTipText(problem);
    append(s, attributes);
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Example 49 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project android by JetBrains.

the class ConnectedAndroidDevice method renderName.

@Override
public void renderName(@NotNull SimpleColoredComponent renderer, boolean isCompatible, @Nullable String searchPrefix) {
    if (myDeviceNameRenderer != null) {
        myDeviceNameRenderer.render(myDevice, renderer);
        return;
    }
    renderer.setIcon(myDevice.isEmulator() ? AndroidIcons.Ddms.EmulatorDevice : AndroidIcons.Ddms.RealDevice);
    IDevice.DeviceState state = myDevice.getState();
    if (state != IDevice.DeviceState.ONLINE) {
        String name = String.format("%1$s [%2$s", myDevice.getSerialNumber(), myDevice.getState());
        renderer.append(name, SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
        if (state == IDevice.DeviceState.UNAUTHORIZED) {
            renderer.append(" - Press 'OK' in the 'Allow USB Debugging' dialog on your device", SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
        }
        renderer.append("] ", SimpleTextAttributes.GRAYED_BOLD_ATTRIBUTES);
        return;
    }
    SimpleTextAttributes attr = isCompatible ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES;
    SearchUtil.appendFragments(searchPrefix, getName(), attr.getStyle(), attr.getFgColor(), attr.getBgColor(), renderer);
    String build = DevicePropertyUtil.getBuild(myDevice);
    if (!build.isEmpty()) {
        renderer.append(" (" + build + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
    }
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) IDevice(com.android.ddmlib.IDevice)

Example 50 with SimpleTextAttributes

use of com.intellij.ui.SimpleTextAttributes in project android by JetBrains.

the class LaunchableAndroidDevice method renderName.

@Override
public void renderName(@NotNull SimpleColoredComponent renderer, boolean isCompatible, @Nullable String searchPrefix) {
    renderer.setIcon(AndroidIcons.Ddms.EmulatorDevice);
    SimpleTextAttributes attr = isCompatible ? SimpleTextAttributes.REGULAR_ATTRIBUTES : SimpleTextAttributes.GRAY_ATTRIBUTES;
    SearchUtil.appendFragments(searchPrefix, getName(), attr.getStyle(), attr.getFgColor(), attr.getBgColor(), renderer);
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes)

Aggregations

SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)87 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)15 JBColor (com.intellij.ui.JBColor)11 NotNull (org.jetbrains.annotations.NotNull)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 SimpleColoredComponent (com.intellij.ui.SimpleColoredComponent)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)6 TextRange (com.intellij.openapi.util.TextRange)6 NodeDescriptor (com.intellij.ide.util.treeView.NodeDescriptor)5 ItemPresentation (com.intellij.navigation.ItemPresentation)4 FileStatus (com.intellij.openapi.vcs.FileStatus)4 PresentationData (com.intellij.ide.projectView.PresentationData)3 PsiElement (com.intellij.psi.PsiElement)3 SimpleColoredText (com.intellij.ui.SimpleColoredText)3 List (java.util.List)3 PsIssue (com.android.tools.idea.gradle.structure.model.PsIssue)2 PTableItem (com.android.tools.idea.uibuilder.property.ptable.PTableItem)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)2 RefEntity (com.intellij.codeInspection.reference.RefEntity)2