Search in sources :

Example 1 with SimpleColoredComponent

use of com.intellij.ui.SimpleColoredComponent in project intellij-community by JetBrains.

the class ColorIcon method paintIcon.

@Override
public void paintIcon(Component component, Graphics g, final int left, final int top) {
    int iconWidth = getIconWidth();
    int iconHeight = getIconHeight();
    if (component instanceof SimpleColoredComponent) {
        SimpleColoredComponent coloredComponent = (SimpleColoredComponent) component;
        g.setColor(component.getBackground());
        g.fillRect(left - coloredComponent.getIpad().left, 0, iconWidth + coloredComponent.getIpad().left + coloredComponent.getIconTextGap(), component.getHeight());
    }
    int x = left + (iconWidth - scaleVal(myColorSize)) / 2;
    int y = top + (iconHeight - scaleVal(myColorSize)) / 2;
    g.setColor(myColor);
    g.fillRect(x, y, scaleVal(myColorSize), scaleVal(myColorSize));
    if (myShowRedLine) {
        Graphics2D g2d = (Graphics2D) g;
        Object hint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setColor(JBColor.red);
        g.drawLine(x, y + scaleVal(myColorSize), x + scaleVal(myColorSize), y);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
    }
    g.setColor(Color.BLACK);
    g.drawRect(x, y, scaleVal(myColorSize), scaleVal(myColorSize));
}
Also used : SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Example 2 with SimpleColoredComponent

use of com.intellij.ui.SimpleColoredComponent in project intellij-community by JetBrains.

the class QuickFixPreviewPanelFactory method getLabel.

@NotNull
private static SimpleColoredComponent getLabel(int problemsCount) {
    SimpleColoredComponent label = new SimpleColoredComponent();
    appendTextToLabel(label, problemsCount);
    label.setBorder(IdeBorderFactory.createEmptyBorder(0, 0, 0, 2));
    return label;
}
Also used : SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with SimpleColoredComponent

use of com.intellij.ui.SimpleColoredComponent in project intellij-community by JetBrains.

the class ShowUsagesTableCellRenderer method textComponentSpanningWholeRow.

@NotNull
private static Component textComponentSpanningWholeRow(@NotNull SimpleColoredComponent chunks, Color panelBackground, Color panelForeground, final int column, @NotNull final JTable table) {
    final SimpleColoredComponent component = new SimpleColoredComponent() {

        @Override
        protected void doPaint(Graphics2D g) {
            int offset = 0;
            int i = 0;
            final TableColumnModel columnModel = table.getColumnModel();
            while (i < column) {
                offset += columnModel.getColumn(i).getWidth();
                i++;
            }
            g.translate(-offset, 0);
            //if (column == columnModel.getColumnCount()-1) {
            //}
            // should increase the column width so that selection background will be visible even after offset translation
            setSize(getWidth() + offset, getHeight());
            super.doPaint(g);
            g.translate(+offset, 0);
        }

        @NotNull
        @Override
        public Dimension getPreferredSize() {
            //return super.getPreferredSize();
            return column == table.getColumnModel().getColumnCount() - 1 ? super.getPreferredSize() : new Dimension(0, 0);
        // it should span the whole row, so we can't return any specific value here,
        // because otherwise it would be used in the "max width" calculation in com.intellij.find.actions.ShowUsagesAction.calcMaxWidth
        }
    };
    component.setBackground(panelBackground);
    component.setForeground(panelForeground);
    for (SimpleColoredComponent.ColoredIterator iterator = chunks.iterator(); iterator.hasNext(); ) {
        iterator.next();
        String fragment = iterator.getFragment();
        SimpleTextAttributes attributes = iterator.getTextAttributes();
        attributes = attributes.derive(attributes.getStyle(), panelForeground, panelBackground, attributes.getWaveColor());
        component.append(fragment, attributes);
    }
    return component;
}
Also used : SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) TableColumnModel(javax.swing.table.TableColumnModel) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with SimpleColoredComponent

use of com.intellij.ui.SimpleColoredComponent in project intellij-community by JetBrains.

the class InspectionListCellRenderer method getListCellRendererComponent.

@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean sel, boolean focus) {
    final BorderLayout layout = new BorderLayout();
    layout.setHgap(5);
    final JPanel panel = new JPanel(layout);
    panel.setOpaque(true);
    final Color bg = sel ? UIUtil.getListSelectionBackground() : UIUtil.getListBackground();
    final Color fg = sel ? UIUtil.getListSelectionForeground() : UIUtil.getListForeground();
    panel.setBackground(bg);
    panel.setForeground(fg);
    if (value instanceof InspectionToolWrapper) {
        final InspectionToolWrapper toolWrapper = (InspectionToolWrapper) value;
        final String inspectionName = "  " + toolWrapper.getDisplayName();
        final String groupName = StringUtil.join(toolWrapper.getGroupPath(), " | ");
        final String matchingText = inspectionName + "|" + groupName;
        Matcher matcher = MatcherHolder.getAssociatedMatcher(list);
        List<TextRange> fragments = matcher == null ? null : ((MinusculeMatcher) matcher).matchingFragments(matchingText);
        List<TextRange> adjustedFragments = new ArrayList<>();
        if (fragments != null) {
            adjustedFragments.addAll(fragments);
        }
        final int splitPoint = adjustRanges(adjustedFragments, inspectionName.length() + 1);
        final SimpleColoredComponent c = new SimpleColoredComponent();
        final boolean matchHighlighting = Registry.is("ide.highlight.match.in.selected.only") && !sel;
        if (matchHighlighting) {
            c.append(inspectionName, myPlain);
        } else {
            final List<TextRange> ranges = adjustedFragments.subList(0, splitPoint);
            SpeedSearchUtil.appendColoredFragments(c, inspectionName, ranges, sel ? mySelected : myPlain, myHighlighted);
        }
        panel.add(c, BorderLayout.WEST);
        final SimpleColoredComponent group = new SimpleColoredComponent();
        if (matchHighlighting) {
            group.append(groupName, SimpleTextAttributes.GRAYED_ATTRIBUTES);
        } else {
            final SimpleTextAttributes attributes = sel ? mySelected : SimpleTextAttributes.GRAYED_ATTRIBUTES;
            final List<TextRange> ranges = adjustedFragments.subList(splitPoint, adjustedFragments.size());
            SpeedSearchUtil.appendColoredFragments(group, groupName, ranges, attributes, myHighlighted);
        }
        final JPanel right = new JPanel(new BorderLayout());
        right.setBackground(bg);
        right.setForeground(fg);
        right.add(group, BorderLayout.CENTER);
        final JLabel icon = new JLabel(getIcon(toolWrapper));
        icon.setBackground(bg);
        icon.setForeground(fg);
        right.add(icon, BorderLayout.EAST);
        panel.add(right, BorderLayout.EAST);
    } else {
        // E.g. "..." item
        return value == ChooseByNameBase.NON_PREFIX_SEPARATOR ? ChooseByNameBase.renderNonPrefixSeparatorComponent(UIUtil.getListBackground()) : super.getListCellRendererComponent(list, value, index, sel, focus);
    }
    return panel;
}
Also used : MinusculeMatcher(com.intellij.psi.codeStyle.MinusculeMatcher) Matcher(com.intellij.util.text.Matcher) JBColor(com.intellij.ui.JBColor) ArrayList(java.util.ArrayList) TextRange(com.intellij.openapi.util.TextRange) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) InspectionToolWrapper(com.intellij.codeInspection.ex.InspectionToolWrapper) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent)

Example 5 with SimpleColoredComponent

use of com.intellij.ui.SimpleColoredComponent in project intellij-community by JetBrains.

the class UnknownFileTypeDiffRequest method getComponent.

@NotNull
@Override
public JComponent getComponent(@NotNull final DiffContext context) {
    final SimpleColoredComponent label = new SimpleColoredComponent();
    label.setTextAlign(SwingConstants.CENTER);
    label.append("Can't show diff for unknown file type. ", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getInactiveTextColor()));
    if (myFileName != null) {
        label.append("Associate", SimpleTextAttributes.LINK_ATTRIBUTES, new Runnable() {

            @Override
            public void run() {
                FileType type = FileTypeChooser.associateFileType(myFileName);
                if (type != null)
                    onSuccess(context);
            }
        });
        LinkMouseListenerBase.installSingleTagOn(label);
    }
    return new DiffUtil.CenteredPanel(label, JBUI.Borders.empty(5));
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) UnknownFileType(com.intellij.openapi.fileTypes.UnknownFileType) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) SimpleColoredComponent(com.intellij.ui.SimpleColoredComponent) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SimpleColoredComponent (com.intellij.ui.SimpleColoredComponent)18 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)8 NotNull (org.jetbrains.annotations.NotNull)6 TextRange (com.intellij.openapi.util.TextRange)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 UiUtil.revalidateAndRepaint (com.android.tools.idea.gradle.structure.configurables.ui.UiUtil.revalidateAndRepaint)1 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 Descriptor (com.intellij.codeInspection.ex.Descriptor)1 InspectionToolWrapper (com.intellij.codeInspection.ex.InspectionToolWrapper)1 LanguageConsoleView (com.intellij.execution.console.LanguageConsoleView)1 ConsoleViewImpl (com.intellij.execution.impl.ConsoleViewImpl)1 ConsoleView (com.intellij.execution.ui.ConsoleView)1 DirDiffOperation (com.intellij.ide.diff.DirDiffOperation)1 AbstractTreeBuilder (com.intellij.ide.util.treeView.AbstractTreeBuilder)1 Disposable (com.intellij.openapi.Disposable)1 ActionManager (com.intellij.openapi.actionSystem.ActionManager)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ShortcutSet (com.intellij.openapi.actionSystem.ShortcutSet)1 Application (com.intellij.openapi.application.Application)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1