use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ChunkExtractor method createTextChunks.
@NotNull
public TextChunk[] createTextChunks(@NotNull UsageInfo2UsageAdapter usageInfo2UsageAdapter, @NotNull CharSequence chars, int start, int end, boolean selectUsageWithBold, @NotNull List<TextChunk> result) {
final Lexer lexer = myHighlighter.getHighlightingLexer();
final SyntaxHighlighterOverEditorHighlighter highlighter = myHighlighter;
LOG.assertTrue(start <= end);
int i = StringUtil.indexOf(chars, '\n', start, end);
if (i != -1)
end = i;
if (myDocumentStamp != myDocument.getModificationStamp()) {
highlighter.restart(chars);
myDocumentStamp = myDocument.getModificationStamp();
} else if (lexer.getTokenType() == null || lexer.getTokenStart() > start) {
// todo restart from nearest position with initial state
highlighter.resetPosition(0);
}
boolean isBeginning = true;
for (; lexer.getTokenType() != null; lexer.advance()) {
int hiStart = lexer.getTokenStart();
int hiEnd = lexer.getTokenEnd();
if (hiStart >= end)
break;
hiStart = Math.max(hiStart, start);
hiEnd = Math.min(hiEnd, end);
if (hiStart >= hiEnd) {
continue;
}
if (isBeginning) {
String text = chars.subSequence(hiStart, hiEnd).toString();
if (text.trim().isEmpty())
continue;
}
isBeginning = false;
IElementType tokenType = lexer.getTokenType();
TextAttributesKey[] tokenHighlights = highlighter.getTokenHighlights(tokenType);
processIntersectingRange(usageInfo2UsageAdapter, chars, hiStart, hiEnd, tokenHighlights, selectUsageWithBold, result);
}
return result.toArray(new TextChunk[result.size()]);
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ResourceBundlePropertyStructureViewElement method getPresentation.
@Override
@NotNull
public ItemPresentation getPresentation() {
return new ResourceBundleEditorRenderer.TextAttributesPresentation() {
@Override
public String getPresentableText() {
return myPresentableName == null ? getProperty().getName() : myPresentableName.isEmpty() ? PROPERTY_GROUP_KEY_TEXT : myPresentableName;
}
@Override
public String getLocationString() {
return null;
}
@Override
public Icon getIcon(boolean open) {
return PlatformIcons.PROPERTY_ICON;
}
@Override
public TextAttributes getTextAttributes(EditorColorsScheme colorsScheme) {
final TextAttributesKey baseAttrKey = (myPresentableName != null && myPresentableName.isEmpty()) ? GROUP_KEY : PropertiesHighlighter.PROPERTY_KEY;
final TextAttributes baseAttrs = colorsScheme.getAttributes(baseAttrKey);
if (getProperty().getPsiElement().isValid()) {
if (myInspectedPropertyProblems != null) {
TextAttributes highlightingAttributes = myInspectedPropertyProblems.getTextAttributes(colorsScheme);
if (highlightingAttributes != null) {
return TextAttributes.merge(baseAttrs, highlightingAttributes);
}
}
}
return baseAttrs;
}
};
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ComponentTree method getAttribute.
private SimpleTextAttributes getAttribute(@NotNull final SimpleTextAttributes attrs, @Nullable HighlightDisplayLevel level) {
if (level == null) {
return attrs;
}
Map<SimpleTextAttributes, SimpleTextAttributes> highlightMap = myHighlightAttributes.get(level.getSeverity());
if (highlightMap == null) {
highlightMap = new HashMap<>();
myHighlightAttributes.put(level.getSeverity(), highlightMap);
}
SimpleTextAttributes result = highlightMap.get(attrs);
if (result == null) {
final TextAttributesKey attrKey = SeverityRegistrar.getSeverityRegistrar(myProject).getHighlightInfoTypeBySeverity(level.getSeverity()).getAttributesKey();
TextAttributes textAttrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attrKey);
textAttrs = TextAttributes.merge(attrs.toTextAttributes(), textAttrs);
result = SimpleTextAttributes.fromTextAttributes(textAttrs);
highlightMap.put(attrs, result);
}
return result;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ColoredCommanderRenderer method customizeCellRenderer.
@Override
protected void customizeCellRenderer(@NotNull final JList list, final Object value, final int index, final boolean selected, final boolean hasFocus) {
// Fix GTK background
if (UIUtil.isUnderGTKLookAndFeel()) {
final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
UIUtil.changeBackGround(this, background);
}
Color color = UIUtil.getListForeground();
SimpleTextAttributes attributes = null;
String locationString = null;
// for separator, see below
setBorder(BorderFactory.createEmptyBorder(1, 0, 1, 0));
if (value instanceof NodeDescriptor) {
final NodeDescriptor descriptor = (NodeDescriptor) value;
setIcon(descriptor.getIcon());
final Color elementColor = descriptor.getColor();
if (elementColor != null) {
color = elementColor;
}
if (descriptor instanceof AbstractTreeNode) {
final AbstractTreeNode treeNode = (AbstractTreeNode) descriptor;
final TextAttributesKey attributesKey = treeNode.getAttributesKey();
if (attributesKey != null) {
final TextAttributes textAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
if (textAttributes != null)
attributes = SimpleTextAttributes.fromTextAttributes(textAttributes);
}
locationString = treeNode.getLocationString();
final PresentationData presentation = treeNode.getPresentation();
if (presentation.hasSeparatorAbove() && !selected) {
setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, GroupedElementsRenderer.POPUP_SEPARATOR_FOREGROUND), BorderFactory.createEmptyBorder(0, 0, 1, 0)));
}
}
}
if (attributes == null)
attributes = new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, color);
final String text = value.toString();
if (myCommanderPanel.isEnableSearchHighlighting()) {
JList list1 = myCommanderPanel.getList();
if (list1 != null) {
SpeedSearchUtil.appendFragmentsForSpeedSearch(list1, text, attributes, selected, this);
}
} else {
append(text != null ? text : "", attributes);
}
if (locationString != null && locationString.length() > 0) {
append(" (" + locationString + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class InjectedGeneralHighlightingPass method highlightInjectedSyntax.
private void highlightInjectedSyntax(@NotNull PsiFile injectedPsi, @NotNull HighlightInfoHolder holder) {
List<Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange>> tokens = InjectedLanguageUtil.getHighlightTokens(injectedPsi);
if (tokens == null)
return;
final Language injectedLanguage = injectedPsi.getLanguage();
Project project = injectedPsi.getProject();
SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(injectedLanguage, project, injectedPsi.getVirtualFile());
final TextAttributes defaultAttrs = myGlobalScheme.getAttributes(HighlighterColors.TEXT);
for (Trinity<IElementType, SmartPsiElementPointer<PsiLanguageInjectionHost>, TextRange> token : tokens) {
ProgressManager.checkCanceled();
IElementType tokenType = token.getFirst();
PsiLanguageInjectionHost injectionHost = token.getSecond().getElement();
if (injectionHost == null)
continue;
TextRange textRange = token.getThird();
TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(tokenType);
if (textRange.getLength() == 0)
continue;
TextRange annRange = textRange.shiftRight(injectionHost.getTextRange().getStartOffset());
// force attribute colors to override host' ones
TextAttributes attributes = null;
for (TextAttributesKey key : keys) {
TextAttributes attrs2 = myGlobalScheme.getAttributes(key);
if (attrs2 != null) {
attributes = attributes == null ? attrs2 : TextAttributes.merge(attributes, attrs2);
}
}
TextAttributes forcedAttributes;
if (attributes == null || attributes.isEmpty() || attributes.equals(defaultAttrs)) {
forcedAttributes = TextAttributes.ERASE_MARKER;
} else {
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(annRange).textAttributes(TextAttributes.ERASE_MARKER).createUnconditionally();
holder.add(info);
forcedAttributes = new TextAttributes(attributes.getForegroundColor(), attributes.getBackgroundColor(), attributes.getEffectColor(), attributes.getEffectType(), attributes.getFontType());
}
HighlightInfo info = HighlightInfo.newHighlightInfo(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT).range(annRange).textAttributes(forcedAttributes).createUnconditionally();
holder.add(info);
}
}
Aggregations