use of com.intellij.ui.SimpleTextAttributes 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;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class SwitcherToolWindowsListRenderer method customizeCellRenderer.
protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
hide = false;
setPaintFocusBorder(false);
if (value instanceof ToolWindow) {
final ToolWindow tw = (ToolWindow) value;
setIcon(getIcon(tw));
final String name;
String stripeTitle = tw.getStripeTitle();
String shortcut = shortcuts.get(tw);
if (myPinned || shortcut == null) {
name = stripeTitle;
} else {
append(shortcut, new SimpleTextAttributes(SimpleTextAttributes.STYLE_UNDERLINE, null));
name = ": " + stripeTitle;
}
append(name);
if (mySpeedSearch != null && mySpeedSearch.isPopupActive()) {
hide = mySpeedSearch.matchingFragments(stripeTitle) == null && !StringUtil.isEmpty(mySpeedSearch.getEnteredPrefix());
}
}
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class IssueLinkRenderer method appendTextWithLinks.
public List<String> appendTextWithLinks(final String text, final SimpleTextAttributes baseStyle, final Consumer<String> consumer) {
final List<String> pieces = new ArrayList<>();
final List<IssueNavigationConfiguration.LinkMatch> list = myIssueNavigationConfiguration.findIssueLinks(text);
int pos = 0;
final SimpleTextAttributes linkAttributes = getLinkAttributes(baseStyle);
for (IssueNavigationConfiguration.LinkMatch match : list) {
final TextRange textRange = match.getRange();
if (textRange.getStartOffset() > pos) {
final String piece = text.substring(pos, textRange.getStartOffset());
pieces.add(piece);
consumer.consume(piece);
}
final String piece = textRange.substring(text);
pieces.add(piece);
append(piece, linkAttributes, match);
pos = textRange.getEndOffset();
}
if (pos < text.length()) {
final String piece = text.substring(pos);
pieces.add(piece);
consumer.consume(piece);
}
return pieces;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class InspectionsConfigTreeRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
final SimpleColoredComponent component = new SimpleColoredComponent();
if (!(value instanceof InspectionConfigTreeNode))
return component;
InspectionConfigTreeNode node = (InspectionConfigTreeNode) value;
Object object = node.getUserObject();
boolean reallyHasFocus = ((TreeTableTree) tree).getTreeTable().hasFocus();
final Color background = selected ? (reallyHasFocus ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeUnfocusedSelectionBackground()) : UIUtil.getTreeTextBackground();
UIUtil.changeBackGround(component, background);
Color foreground = selected ? UIUtil.getTreeSelectionForeground() : node.isProperSetting() ? PlatformColors.BLUE : UIUtil.getTreeTextForeground();
@NonNls String text;
int style = SimpleTextAttributes.STYLE_PLAIN;
String hint = null;
if (object instanceof String) {
text = (String) object;
style = SimpleTextAttributes.STYLE_BOLD;
} else {
final ToolDescriptors descriptors = node.getDescriptors();
assert descriptors != null;
final Descriptor defaultDescriptor = descriptors.getDefaultDescriptor();
text = defaultDescriptor.getText();
hint = getHint(defaultDescriptor);
}
if (text != null) {
SearchUtil.appendFragments(getFilter(), text, style, foreground, background, component);
}
if (hint != null) {
component.append(" " + hint, selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, foreground) : SimpleTextAttributes.GRAYED_ATTRIBUTES);
}
component.setForeground(foreground);
return component;
}
use of com.intellij.ui.SimpleTextAttributes in project intellij-community by JetBrains.
the class SpeedSearchUtil method applySpeedSearchHighlighting.
public static void applySpeedSearchHighlighting(@NotNull JComponent speedSearchEnabledComponent, @NotNull SimpleColoredComponent coloredComponent, boolean mainTextOnly, boolean selected) {
SpeedSearchSupply speedSearch = SpeedSearchSupply.getSupply(speedSearchEnabledComponent);
// The bad thing is that SpeedSearch model is decoupled from UI presentation so we don't know the real matched text.
// Our best guess is to get string from the ColoredComponent. We can only provide main-text-only option.
Iterable<TextRange> ranges = speedSearch == null ? null : speedSearch.matchingFragments(coloredComponent.getCharSequence(mainTextOnly).toString());
Iterator<TextRange> rangesIterator = ranges != null ? ranges.iterator() : null;
if (rangesIterator == null || !rangesIterator.hasNext())
return;
Color bg = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
SimpleColoredComponent.ColoredIterator coloredIterator = coloredComponent.iterator();
TextRange range = rangesIterator.next();
main: while (coloredIterator.hasNext()) {
coloredIterator.next();
int offset = coloredIterator.getOffset();
int endOffset = coloredIterator.getEndOffset();
if (!range.intersectsStrict(offset, endOffset))
continue;
SimpleTextAttributes attributes = coloredIterator.getTextAttributes();
SimpleTextAttributes highlighted = new SimpleTextAttributes(bg, attributes.getFgColor(), null, attributes.getStyle() | SimpleTextAttributes.STYLE_SEARCH_MATCH);
do {
if (range.getStartOffset() > offset) {
offset = coloredIterator.split(range.getStartOffset() - offset, attributes);
}
if (range.getEndOffset() <= endOffset) {
offset = coloredIterator.split(range.getEndOffset() - offset, highlighted);
if (rangesIterator.hasNext()) {
range = rangesIterator.next();
} else {
break main;
}
} else {
coloredIterator.split(endOffset - offset, highlighted);
continue main;
}
} while (range.intersectsStrict(offset, endOffset));
}
}
Aggregations