use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class EventLogConsole method doPrintNotification.
void doPrintNotification(final Notification notification) {
Editor editor = getConsoleEditor();
if (editor.isDisposed()) {
return;
}
Document document = editor.getDocument();
boolean scroll = document.getTextLength() == editor.getCaretModel().getOffset() || !editor.getContentComponent().hasFocus();
if (document.getTextLength() > 0) {
append(document, "\n");
}
String lastDate = DateFormatUtil.formatDate(notification.getTimestamp());
if (document.getTextLength() == 0 || !lastDate.equals(myLastDate)) {
myLastDate = lastDate;
append(document, lastDate + "\n");
}
int startDateOffset = document.getTextLength();
String date = DateFormatUtil.formatTime(notification.getTimestamp()) + "\t";
append(document, date);
int tabs = calculateTabs(editor, startDateOffset);
int titleStartOffset = document.getTextLength();
int startLine = document.getLineCount() - 1;
EventLog.LogEntry pair = EventLog.formatForLog(notification, StringUtil.repeatSymbol('\t', tabs));
final NotificationType type = notification.getType();
TextAttributesKey key = type == NotificationType.ERROR ? ConsoleViewContentType.LOG_ERROR_OUTPUT_KEY : type == NotificationType.INFORMATION ? ConsoleViewContentType.NORMAL_OUTPUT_KEY : ConsoleViewContentType.LOG_WARNING_OUTPUT_KEY;
int msgStart = document.getTextLength();
append(document, pair.message);
TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(key);
int layer = HighlighterLayer.CARET_ROW + 1;
RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(msgStart, document.getTextLength(), layer, attributes, HighlighterTargetArea.EXACT_RANGE);
GROUP_ID.set(highlighter, notification.getGroupId());
NOTIFICATION_ID.set(highlighter, notification.id);
for (Pair<TextRange, HyperlinkInfo> link : pair.links) {
final RangeHighlighter rangeHighlighter = myHyperlinkSupport.getValue().createHyperlink(link.first.getStartOffset() + msgStart, link.first.getEndOffset() + msgStart, null, link.second);
if (link.second instanceof EventLog.ShowBalloon) {
((EventLog.ShowBalloon) link.second).setRangeHighlighter(rangeHighlighter);
}
}
append(document, "\n");
if (scroll) {
editor.getCaretModel().moveToOffset(document.getTextLength());
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
}
if (notification.isImportant()) {
highlightNotification(notification, pair.status, startLine, document.getLineCount() - 1, titleStartOffset, pair.titleLength);
}
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class PsiElementListCellRenderer method getNavigationItemAttributes.
@Nullable
protected TextAttributes getNavigationItemAttributes(Object value) {
TextAttributes attributes = null;
if (value instanceof NavigationItem) {
TextAttributesKey attributesKey = null;
final ItemPresentation presentation = ((NavigationItem) value).getPresentation();
if (presentation instanceof ColoredItemPresentation)
attributesKey = ((ColoredItemPresentation) presentation).getTextAttributesKey();
if (attributesKey != null) {
attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(attributesKey);
}
}
return attributes;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class HighlightNamesUtil method getScopeAttributes.
private static TextAttributes getScopeAttributes(@NotNull PsiElement element, @NotNull TextAttributesScheme colorsScheme) {
PsiFile file = element.getContainingFile();
if (file == null)
return null;
TextAttributes result = null;
DependencyValidationManagerImpl validationManager = (DependencyValidationManagerImpl) DependencyValidationManager.getInstance(file.getProject());
List<Pair<NamedScope, NamedScopesHolder>> scopes = validationManager.getScopeBasedHighlightingCachedScopes();
for (Pair<NamedScope, NamedScopesHolder> scope : scopes) {
final NamedScope namedScope = scope.getFirst();
final TextAttributesKey scopeKey = ScopeAttributesUtil.getScopeTextAttributeKey(namedScope.getName());
final TextAttributes attributes = colorsScheme.getAttributes(scopeKey);
if (attributes == null || attributes.isEmpty()) {
continue;
}
final PackageSet packageSet = namedScope.getValue();
if (packageSet != null && packageSet.contains(file, scope.getSecond())) {
result = TextAttributes.merge(attributes, result);
}
}
return result;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class JavaRearranger method getAttributes.
@Nullable
private static TextAttributes getAttributes(@NotNull EditorColorsScheme scheme, @NotNull TextAttributesKey... keys) {
TextAttributes result = null;
for (TextAttributesKey key : keys) {
TextAttributes attributes = scheme.getAttributes(key).clone();
if (attributes == null) {
continue;
}
if (result == null) {
result = attributes;
}
Color currentForegroundColor = result.getForegroundColor();
if (currentForegroundColor == null) {
result.setForegroundColor(attributes.getForegroundColor());
}
Color currentBackgroundColor = result.getBackgroundColor();
if (currentBackgroundColor == null) {
result.setBackgroundColor(attributes.getBackgroundColor());
}
if (result.getForegroundColor() != null && result.getBackgroundColor() != null) {
return result;
}
}
if (result != null && result.getForegroundColor() == null) {
return null;
}
if (result != null && result.getBackgroundColor() == null) {
result.setBackgroundColor(scheme.getDefaultBackground());
}
return result;
}
use of com.intellij.openapi.editor.colors.TextAttributesKey in project intellij-community by JetBrains.
the class ProblemDescriptorUtil method highlightTypeFromDescriptor.
@NotNull
public static HighlightInfoType highlightTypeFromDescriptor(@NotNull ProblemDescriptor problemDescriptor, @NotNull HighlightSeverity severity, @NotNull SeverityRegistrar severityRegistrar) {
final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
final HighlightInfoType highlightInfoType = getHighlightInfoType(highlightType, severity, severityRegistrar);
if (highlightInfoType == HighlightSeverity.INFORMATION) {
final TextAttributesKey attributes = ((ProblemDescriptorBase) problemDescriptor).getEnforcedTextAttributes();
if (attributes != null) {
return new HighlightInfoType.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, attributes);
}
}
return highlightInfoType;
}
Aggregations