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));
}
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;
}
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;
}
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;
}
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));
}
Aggregations