public void generateGherkinRunIcons(Document rootDocument, Editor rootEditor) { for (int i = 0; i < rootDocument.getLineCount(); i++) { int startOffset = rootDocument.getLineStartOffset(i); int endOffset = rootDocument.getLineEndOffset(i); String lineText = rootDocument.getText(new TextRange(startOffset, endOffset)).trim(); Icon icon; if (lineText.matches(SCENARIO_REGEX)) { icon = GherkinIconRenderer.SCENARIO_ICON; } else if (lineText.matches(FEATURE_REGEX)) { icon = GherkinIconRenderer.FEATURE_ICON; } else { // System.out.println(); continue; } GherkinIconRenderer gherkinIconRenderer = new GherkinIconRenderer(rootEditor.getProject(), fileName); gherkinIconRenderer.setLine(i); gherkinIconRenderer.setIcon(icon); RangeHighlighter rangeHighlighter = createRangeHighlighter(rootDocument, rootEditor, i, i, new TextAttributes()); rangeHighlighter.setGutterIconRenderer(gherkinIconRenderer); } }
private void highlightLine(int index, NamedTextAttr namedTextAttr) { UIUtil.invokeAndWaitIfNeeded((Runnable) () -> { try { MarkupModelEx markupModel = myEditor.getMarkupModel(); final Document doc = markupModel.getDocument(); final int lineStartOffset = doc.getLineStartOffset(index); final int lineEndOffset = doc.getLineEndOffset(index); // IDEA-53203: add ERASE_MARKER for manually defined attributes markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset, HighlighterLayer.SELECTION - 1, TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE); RangeHighlighter rangeHighlight = markupModel.addRangeHighlighter(lineStartOffset, lineEndOffset, HighlighterLayer.SELECTION - 1, namedTextAttr, HighlighterTargetArea.EXACT_RANGE); rangeHighlight.setErrorStripeMarkColor(namedTextAttr.getErrorStripeColor()); rangeHighlight.setErrorStripeTooltip(namedTextAttr.getName()); } catch (Exception e) { throw new RuntimeException(e); } }); }
@Override public void reset(@NotNull TextAttributes ta) { myCbBold.setEnabled(true); myCbItalic.setEnabled(true); int fontType = ta.getFontType(); myCbBold.setSelected(BitUtil.isSet(fontType, Font.BOLD)); myCbItalic.setSelected(BitUtil.isSet(fontType, Font.ITALIC)); resetColorChooser(myCbForeground, myForegroundChooser, ta.getForegroundColor()); resetColorChooser(myCbBackground, myBackgroundChooser, ta.getBackgroundColor()); resetColorChooser(myCbErrorStripe, myErrorStripeColorChooser, ta.getErrorStripeColor()); Color effectColor = ta.getEffectColor(); resetColorChooser(myCbEffects, myEffectsColorChooser, effectColor); if (effectColor == null) { myEffectsCombo.setEnabled(false); } else { myEffectsCombo.setEnabled(true); myEffectsModel.setSelectedItem( ContainerUtil.reverseMap(myEffectsMap).get(ta.getEffectType())); } }
@Override public void actionPerformed(AnActionEvent e) { final Project project = e.getRequiredData(CommonDataKeys.PROJECT); final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR); final HighlightManager highlightManager = HighlightManager.getInstance(project); final RangeHighlighter[] highlighters = ((HighlightManagerImpl) highlightManager).getHighlighters(editor); for (RangeHighlighter highlighter : highlighters) { final TextAttributes ta = highlighter.getTextAttributes(); if (ta != null && ta instanceof NamedTextAttr && highlighter.getLayer() == HighlighterLayer.SELECTION - 1) { highlightManager.removeSegmentHighlighter(editor, highlighter); } } }
@Override protected Key create(List<TextAttributesKey> keys) { StringBuilder keyName = new StringBuilder("ConsoleViewUtil_"); for (TextAttributesKey key : keys) { keyName.append("_").append(key.getExternalName()); } final Key newKey = new Key(keyName.toString()); textAttributeKeys.put(newKey, keys); ConsoleViewContentType contentType = new ConsoleViewContentType(keyName.toString(), HighlighterColors.TEXT) { @Override public TextAttributes getAttributes() { return mergedTextAttributes.get(newKey); } }; registerNewConsoleViewType(newKey, contentType); return newKey; }
@Nullable @Override public TextAttributes getTextAttributes(@NotNull EditorColorsScheme scheme, @NotNull ArrangementSettingsToken token, boolean selected) { if (selected) { TextAttributes attributes = new TextAttributes(); attributes.setForegroundColor(scheme.getColor(EditorColors.SELECTION_FOREGROUND_COLOR)); attributes.setBackgroundColor(scheme.getColor(EditorColors.SELECTION_BACKGROUND_COLOR)); return attributes; } else if (SUPPORTED_TYPES.contains(token)) { return getAttributes(scheme, JavaHighlightingColors.KEYWORD); } else if (SUPPORTED_MODIFIERS.contains(token)) { getAttributes(scheme, JavaHighlightingColors.KEYWORD); } return null; }
public boolean isInherited(TextAttributesKey key) { TextAttributesKey fallbackKey = key.getFallbackAttributeKey(); if (fallbackKey != null) { if (myParentScheme instanceof AbstractColorsScheme) { TextAttributes ownAttrs = ((AbstractColorsScheme)myParentScheme).getDirectlyDefinedAttributes(key); if (ownAttrs != null) { return ownAttrs.isFallbackEnabled(); } } TextAttributes attributes = getAttributes(key); if (attributes != null) { TextAttributes fallbackAttributes = getAttributes(fallbackKey); return attributes == fallbackAttributes; } } return false; }
/** * @return List of highlighters */ public static List<RangeHighlighter> highlightAllOccurrences(Project project, PsiElement[] occurrences, Editor editor) { ArrayList<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); if (occurrences.length > 1) { for (PsiElement occurrence : occurrences) { final RangeMarker rangeMarker = occurrence.getUserData(ElementToWorkOn.TEXT_RANGE); if (rangeMarker != null && rangeMarker.isValid()) { highlightManager .addRangeHighlight(editor, rangeMarker.getStartOffset(), rangeMarker.getEndOffset(), attributes, true, highlighters); } else { final TextRange textRange = occurrence.getTextRange(); highlightManager.addRangeHighlight(editor, textRange.getStartOffset(), textRange.getEndOffset(), attributes, true, highlighters); } } } return highlighters; }
private static boolean equals(TextAttributes attributes1, TextAttributes attributes2) { if (attributes2 == null) { return attributes1 == null; } if(attributes1 == null) { return false; } if(!Comparing.equal(attributes1.getForegroundColor(), attributes2.getForegroundColor())) { return false; } if(attributes1.getFontType() != attributes2.getFontType()) { return false; } if(!Comparing.equal(attributes1.getBackgroundColor(), attributes2.getBackgroundColor())) { return false; } if(!Comparing.equal(attributes1.getEffectColor(), attributes2.getEffectColor())) { return false; } return true; }
public void testScopeBased() throws Exception { NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null)); NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject()); scopeManager.addScope(xScope); scopeManager.addScope(utilScope); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName()); TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC); scheme.setAttributes(xKey, xAttributes); TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName()); TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); scheme.setAttributes(utilKey, utilAttributes); try { testFile(BASE_PATH + "/scopeBased/x/X.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test(); } finally { scopeManager.removeAllSets(); } }
@Override public void update(PresentationData presentation) { String newName = getValue().getName(); int nameEndOffset = newName.length(); int todoItemCount = getTodoItemCount(getValue()); int fileCount = getFileCount(getValue()); newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount); myHighlightedRegions.clear(); TextAttributes textAttributes = new TextAttributes(); if (CopyPasteManager.getInstance().isCutElement(getValue())) { textAttributes.setForegroundColor(CopyPasteManager.CUT_COLOR); } myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes)); EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme(); myHighlightedRegions.add( new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES))); presentation.setIcon(ModuleType.get(getValue()).getIcon()); presentation.setPresentableText(newName); }
@Override public TextAttributes getAttributes(TextAttributesKey key) { if (key != null) { TextAttributesKey fallbackKey = key.getFallbackAttributeKey(); TextAttributes attributes = getDirectlyDefinedAttributes(key); if (fallbackKey == null) { if (containsValue(attributes)) return attributes; } else { if (containsValue(attributes) && !attributes.isFallbackEnabled()) return attributes; attributes = getFallbackAttributes(fallbackKey); if (containsValue(attributes)) return attributes; } } return myParentScheme.getAttributes(key); }
private static void flashUsageScriptaculously(@NotNull final Usage usage) { if (!(usage instanceof UsageInfo2UsageAdapter)) { return; } UsageInfo2UsageAdapter usageInfo = (UsageInfo2UsageAdapter)usage; Editor editor = usageInfo.openTextEditor(true); if (editor == null) return; TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); RangeBlinker rangeBlinker = new RangeBlinker(editor, attributes, 6); List<Segment> segments = new ArrayList<Segment>(); CommonProcessors.CollectProcessor<Segment> processor = new CommonProcessors.CollectProcessor<Segment>(segments); usageInfo.processRangeMarkers(processor); rangeBlinker.resetMarkers(segments); rangeBlinker.startBlinking(); }
public void renderElement(LookupElement element, LookupElementPresentation presentation) { Suggestion suggestion = (Suggestion) element.getObject(); if (suggestion.icon != null) { presentation.setIcon(suggestion.icon); } presentation.setStrikeout(suggestion.deprecationLevel != null); if (suggestion.deprecationLevel != null) { if (suggestion.deprecationLevel == SpringConfigurationMetadataDeprecationLevel.error) { presentation.setItemTextForeground(RED); } else { presentation.setItemTextForeground(YELLOW); } } String lookupString = element.getLookupString(); presentation.setItemText(lookupString); if (!lookupString.equals(suggestion.suggestion)) { presentation.setItemTextBold(true); } String shortDescription; if (suggestion.defaultValue != null) { shortDescription = shortenTextWithEllipsis(suggestion.defaultValue, 60, 0, true); TextAttributes attrs = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(SCALAR_TEXT); presentation.setTailText("=" + shortDescription, attrs.getForegroundColor()); } if (suggestion.description != null) { presentation.appendTailText( " (" + Util.getFirstSentenceWithoutDot(suggestion.description) + ")", true); } if (suggestion.shortType != null) { presentation.setTypeText(suggestion.shortType); } }
private static TextAttributes getNormalAttributes() { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(DebuggerColors.INLINED_VALUES); if (attributes == null || attributes.getForegroundColor() == null) { return new TextAttributes(new JBColor(Gray._135, new Color(0x3d8065)), null, null, null, Font.ITALIC); } return attributes; }
private RangeHighlighter createRangeHighlighter(Document document, Editor editor, int fromLine, int toLine, TextAttributes attributes) { int lineStartOffset = document.getLineStartOffset(Math.max(0, fromLine)); int lineEndOffset = document.getLineEndOffset(Math.max(0, toLine)); return editor.getMarkupModel().addRangeHighlighter( lineStartOffset, lineEndOffset, 3333, attributes, HighlighterTargetArea.LINES_IN_RANGE ); }
private static void clearHighlights(Editor editor, HighlightManager highlightManager, List<TextRange> toRemoves) { if (editor instanceof EditorWindow) { editor = ((EditorWindow) editor).getDelegate(); } RangeHighlighter[] highlighters = ((HighlightManagerImpl) highlightManager).getHighlighters(editor); Arrays.sort(highlighters, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset()); Collections.sort(toRemoves, (o1, o2) -> o1.getStartOffset() - o2.getStartOffset()); int i = 0; int j = 0; while (i < highlighters.length && j < toRemoves.size()) { RangeHighlighter highlighter = highlighters[i]; final TextAttributes ta = highlighter.getTextAttributes(); final TextRange textRange = TextRange.create(highlighter); final TextRange toRemove = toRemoves.get(j); if (ta != null && ta instanceof NamedTextAttr // wrap && highlighter.getLayer() == HighlighterLayer.SELECTION - 1 // wrap && toRemove.equals(textRange)) { highlightManager.removeSegmentHighlighter(editor, highlighter); i++; } else if (toRemove.getStartOffset() > textRange.getEndOffset()) { i++; } else if (toRemove.getEndOffset() < textRange.getStartOffset()) { j++; } else { i++; j++; } } }
private static void highlight(@NotNull HighlightManager highlightManager, @NotNull Collection<TextRange> textRanges, @NotNull Editor editor, @NotNull TextAttributes ta, @Nullable Collection<RangeHighlighter> holder, @Nullable Color scrollMarkColor) { for (TextRange range : textRanges) { highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), ta, 0, holder, scrollMarkColor); } }
private static void addLinesHighlighter(Project project, ArrayList<Integer> lines) { Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); //editor.getMarkupModel().removeAllHighlighters(); final TextAttributes attr = new TextAttributes(); attr.setBackgroundColor(JBColor.LIGHT_GRAY); // attr.setForegroundColor(JBColor.BLACK); // TODO: Check if line is illegal for (int line : lines){ log.info("line:" + line); if (line >= 1) { editor.getMarkupModel().addLineHighlighter(line - 1, flag++, attr); } } }
private static void removeHightlight(Project project, VirtualFile file, ArrayList<Integer> linesArrayList) { FileEditor fileEditor = FileEditorManager.getInstance(project).getSelectedEditor(file); Editor editor= fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null; editor.getMarkupModel().getDocument(); final TextAttributes attr = new TextAttributes(); attr.setBackgroundColor(JBColor.WHITE); // attr.setForegroundColor(JBColor.BLACK); for (int line : linesArrayList){ log.info("remove line:" + line); editor.getMarkupModel().addLineHighlighter(line - 1, flag++, attr); } }
@Override public void actionPerformed(AnActionEvent e) { DataContext dataContext = e.getDataContext(); Editor editor = CommonDataKeys.EDITOR.getData(dataContext); Project project = CommonDataKeys.PROJECT.getData(dataContext); List<PsiElement> elements = getElementsToCopy(editor, dataContext); if (!doCopy(elements, project, editor) && editor != null && project != null) { Document document = editor.getDocument(); PsiFile file = PsiDocumentManager.getInstance(project).getCachedPsiFile(document); if (file != null) { String toCopy = getFileFqn(file) + ":" + (editor.getCaretModel().getLogicalPosition().line + 1); CopyPasteManager.getInstance().setContents(new StringSelection(toCopy)); setStatusBarText(project, toCopy + " has been copied"); } return; } HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); if (elements.size() == 1 && editor != null && project != null) { PsiElement element = elements.get(0); PsiElement nameIdentifier = IdentifierUtil.getNameIdentifier(element); if (nameIdentifier != null) { highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{nameIdentifier}, attributes, true, null); } else { PsiReference reference = TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()); if (reference != null) { highlightManager.addOccurrenceHighlights(editor, new PsiReference[]{reference}, attributes, true, null); } else if (element != PsiDocumentManager.getInstance(project).getCachedPsiFile(editor.getDocument())) { highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{element}, attributes, true, null); } } } }
@Nullable private static Annotation createAnnotation(@NotNull AnnotationHolder holder, @NotNull HighlightSeverity severity, @Nullable TextAttributes forcedTextAttributes, @NotNull TextRange range, @NotNull String message) { if (forcedTextAttributes != null) { Annotation annotation = createAnnotation(holder, severity, range, message); annotation.setEnforcedTextAttributes(forcedTextAttributes); return annotation; } return createAnnotation(holder, severity, range, message); }
public void testYieldInNestedFunction() { // highlight func declaration first, lest we get an "Extra fragment highlighted" error. EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = TextAttributesKey.find("PY.FUNC_DEFINITION"); TextAttributes xAttributes = new TextAttributes(Color.red, Color.black, Color.white, EffectType.BOXED, Font.BOLD); scheme.setAttributes(xKey, xAttributes); doTest(); }
@Nullable @Override protected TextAttributes create(Key contentKey) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes result = scheme.getAttributes(HighlighterColors.TEXT); for (TextAttributesKey key : textAttributeKeys.get(contentKey)) { TextAttributes attributes = scheme.getAttributes(key); if (attributes != null) { result = TextAttributes.merge(result, attributes); } } return result; }
@Nullable static HighlightInfo highlightMethodName(@NotNull PsiMethod method, final PsiElement elementToHighlight, TextRange range, @NotNull TextAttributesScheme colorsScheme, final boolean isDeclaration) { boolean isInherited = false; if (!isDeclaration) { if (isCalledOnThis(elementToHighlight)) { final PsiClass containingClass = method.getContainingClass(); PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class); while (enclosingClass != null) { isInherited = enclosingClass.isInheritor(containingClass, true); if (isInherited) break; enclosingClass = PsiTreeUtil.getParentOfType(enclosingClass, PsiClass.class, true); } } } HighlightInfoType type = getMethodNameHighlightType(method, isDeclaration, isInherited); if (type != null && elementToHighlight != null) { TextAttributes attributes = mergeWithScopeAttributes(method, type, colorsScheme); HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range); if (attributes != null) { builder.textAttributes(attributes); } return builder.createUnconditionally(); } return null; }
@NotNull static HighlightInfo fromAnnotation(@NotNull Annotation annotation, @Nullable TextRange fixedRange, boolean batchMode) { final TextAttributes forcedAttributes = annotation.getEnforcedTextAttributes(); TextAttributesKey key = annotation.getTextAttributes(); final TextAttributesKey forcedAttributesKey = forcedAttributes == null ? (key == HighlighterColors.NO_HIGHLIGHTING ? null : key) : null; HighlightInfo info = new HighlightInfo(forcedAttributes, forcedAttributesKey, convertType(annotation), fixedRange != null? fixedRange.getStartOffset() : annotation.getStartOffset(), fixedRange != null? fixedRange.getEndOffset() : annotation.getEndOffset(), annotation.getMessage(), annotation.getTooltip(), annotation.getSeverity(), annotation.isAfterEndOfLine(), annotation.needsUpdateOnTyping(), annotation.isFileLevelAnnotation(), 0, annotation.getProblemGroup(), annotation.getGutterIconRenderer()); appendFixes(fixedRange, info, batchMode ? annotation.getBatchFixes() : annotation.getQuickFixes()); return info; }
HighlightInfo(@Nullable TextAttributes forcedTextAttributes, @Nullable TextAttributesKey forcedTextAttributesKey, @NotNull HighlightInfoType type, int startOffset, int endOffset, @Nullable String escapedDescription, @Nullable String escapedToolTip, @NotNull HighlightSeverity severity, boolean afterEndOfLine, @Nullable Boolean needsUpdateOnTyping, boolean isFileLevelAnnotation, int navigationShift, ProblemGroup problemGroup, GutterMark gutterIconRenderer) { if (startOffset < 0 || startOffset > endOffset) { LOG.error("Incorrect highlightInfo bounds. description="+escapedDescription+"; startOffset="+startOffset+"; endOffset="+endOffset+";type="+type); } this.forcedTextAttributes = forcedTextAttributes; this.forcedTextAttributesKey = forcedTextAttributesKey; this.type = type; this.startOffset = startOffset; this.endOffset = endOffset; fixStartOffset = startOffset; fixEndOffset = endOffset; description = escapedDescription; // optimisation: do not retain extra memory if can recompute toolTip = encodeTooltip(escapedToolTip, escapedDescription); this.severity = severity; setFlag(AFTER_END_OF_LINE_MASK, afterEndOfLine); setFlag(NEEDS_UPDATE_ON_TYPING_MASK, calcNeedUpdateOnTyping(needsUpdateOnTyping, type)); setFlag(FILE_LEVEL_ANNOTATION_MASK, isFileLevelAnnotation); this.navigationShift = navigationShift; myProblemGroup = problemGroup; this.gutterIconRenderer = gutterIconRenderer; }
public static void setupRenderer(SimpleColoredComponent renderer, Project project, Bookmark bookmark, boolean selected) { VirtualFile file = bookmark.getFile(); if (!file.isValid()) { return; } PsiManager psiManager = PsiManager.getInstance(project); PsiElement fileOrDir = file.isDirectory() ? psiManager.findDirectory(file) : psiManager.findFile(file); if (fileOrDir != null) { renderer.setIcon(fileOrDir.getIcon(0)); } String description = bookmark.getDescription(); if (description != null) { renderer.append(description + " ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES); } FileStatus fileStatus = FileStatusManager.getInstance(project).getStatus(file); TextAttributes attributes = new TextAttributes(fileStatus.getColor(), null, null, EffectType.LINE_UNDERSCORE, Font.PLAIN); renderer.append(file.getName(), SimpleTextAttributes.fromTextAttributes(attributes)); if (bookmark.getLine() >= 0) { renderer.append(":", SimpleTextAttributes.GRAYED_ATTRIBUTES); renderer.append(String.valueOf(bookmark.getLine() + 1), SimpleTextAttributes.GRAYED_ATTRIBUTES); } if (!selected) { FileColorManager colorManager = FileColorManager.getInstance(project); if (fileOrDir instanceof PsiFile) { Color color = colorManager.getRendererBackground((PsiFile)fileOrDir); if (color != null) { renderer.setBackground(color); } } } }
protected void addHighlights(@NotNull Map<TextRange, TextAttributes> ranges, @NotNull Editor editor, @NotNull Collection<RangeHighlighter> highlighters, @NotNull HighlightManager highlightManager) { for (Map.Entry<TextRange, TextAttributes> entry : ranges.entrySet()) { TextRange range = entry.getKey(); TextAttributes attributes = entry.getValue(); highlightManager.addOccurrenceHighlight(editor, range.getStartOffset(), range.getEndOffset(), attributes, 0, highlighters, null); } for (RangeHighlighter highlighter : highlighters) { highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); } }
public static void resizeColumns(final PackageEntryTable packageTable, JBTable result, boolean areStaticImportsEnabled) { ColoredTableCellRenderer packageRenderer = new ColoredTableCellRenderer() { @Override protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) { PackageEntry entry = packageTable.getEntryAt(row); if (entry == PackageEntry.BLANK_LINE_ENTRY) { append("<blank line>", SimpleTextAttributes.GRAYED_ATTRIBUTES); } else { TextAttributes attributes = JavaHighlightingColors.KEYWORD.getDefaultAttributes(); append("import", SimpleTextAttributes.fromTextAttributes(attributes)); if (entry.isStatic()) { append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES); append("static", SimpleTextAttributes.fromTextAttributes(attributes)); } append(" ", SimpleTextAttributes.REGULAR_ATTRIBUTES); if (entry == PackageEntry.ALL_OTHER_IMPORTS_ENTRY || entry == PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY) { append("all other imports", SimpleTextAttributes.REGULAR_ATTRIBUTES); } else { append(entry.getPackageName() + ".*", SimpleTextAttributes.REGULAR_ATTRIBUTES); } } } }; if (areStaticImportsEnabled) { fixColumnWidthToHeader(result, 0); fixColumnWidthToHeader(result, 2); result.getColumnModel().getColumn(1).setCellRenderer(packageRenderer); result.getColumnModel().getColumn(0).setCellRenderer(new BooleanTableCellRenderer()); result.getColumnModel().getColumn(2).setCellRenderer(new BooleanTableCellRenderer()); } else { fixColumnWidthToHeader(result, 1); result.getColumnModel().getColumn(0).setCellRenderer(packageRenderer); result.getColumnModel().getColumn(1).setCellRenderer(new BooleanTableCellRenderer()); } }
/** * Instructs current component that it should {@link #getUiComponent() draw} itself according to the given 'selected' state. * * @param selected flag that indicates if current component should be drawn as 'selected' */ @Override public void setSelected(boolean selected) { boolean notifyListener = selected != mySelected; mySelected = selected; TextAttributes attributes = updateComponentText(selected); myBorder.setColor(myColorsProvider.getBorderColor(selected)); myBackgroundColor = attributes.getBackgroundColor(); if (notifyListener && myListener != null) { myListener.stateChanged(); } }
@SuppressWarnings("deprecation") public ResultItem(final int highlightStartOffset, final int highlightEndOffset, @Nullable final HyperlinkInfo hyperlinkInfo, @Nullable final TextAttributes highlightAttributes) { this(highlightStartOffset, highlightEndOffset, hyperlinkInfo, highlightAttributes, null); }
public void testSharedScopeBased() throws Exception { NamedScope xScope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null)); NamedScope utilScope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); NamedScopesHolder scopeManager = DependencyValidationManager.getInstance(getProject()); scopeManager.addScope(xScope); scopeManager.addScope(utilScope); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributesKey xKey = ScopeAttributesUtil.getScopeTextAttributeKey(xScope.getName()); TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, null, Font.ITALIC); scheme.setAttributes(xKey, xAttributes); TextAttributesKey utilKey = ScopeAttributesUtil.getScopeTextAttributeKey(utilScope.getName()); TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); scheme.setAttributes(utilKey, utilAttributes); NamedScope projectScope = PackagesScopesProvider.getInstance(myProject).getProjectProductionScope(); TextAttributesKey projectKey = ScopeAttributesUtil.getScopeTextAttributeKey(projectScope.getName()); TextAttributes projectAttributes = new TextAttributes(null, null, Color.blue, EffectType.BOXED, Font.ITALIC); scheme.setAttributes(projectKey, projectAttributes); try { testFile(BASE_PATH + "/scopeBased/x/Shared.java").projectRoot(BASE_PATH + "/scopeBased").checkSymbolNames().test(); } finally { scopeManager.removeAllSets(); } }
public TextAttributes toTextAttributes() { Color effectColor; EffectType effectType; if (isWaved()) { effectColor = myWaveColor; effectType = EffectType.WAVE_UNDERSCORE; } else if (isStrikeout()) { effectColor = myWaveColor; effectType = EffectType.STRIKEOUT; } else if (isUnderline()) { effectColor = myWaveColor; effectType = EffectType.LINE_UNDERSCORE; } else if (isBoldDottedLine()) { effectColor = myWaveColor; effectType = EffectType.BOLD_DOTTED_LINE; } else if (isSearchMatch()) { effectColor = myWaveColor; effectType = EffectType.SEARCH_MATCH; } else { effectColor = null; effectType = null; } return new TextAttributes(myFgColor, null, effectColor, effectType, myStyle & FONT_MASK); }
private static void highlightInEditor(final Project project, final IncludeDuplicate pair, final Editor editor) { final HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final int startOffset = pair.getStart().getTextRange().getStartOffset(); final int endOffset = pair.getEnd().getTextRange().getEndOffset(); highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, null); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); }
@NotNull public TextAttributes getAttributes(@Nullable Editor editor) { if (editor == null) { return EditorColorsManager.getInstance().getGlobalScheme().getAttributes(myKey); } else { return editor.getColorsScheme().getAttributes(myKey); } }
public void addHighlToView(final Editor view, EditorColorsScheme scheme, final Map<TextAttributesKey,String> displayText) { // XXX: Hack if (HighlighterColors.BAD_CHARACTER.equals(myHighlightType)) { return; } final TextAttributes attr = scheme.getAttributes(myHighlightType); if (attr != null) { UIUtil.invokeAndWaitIfNeeded(new Runnable() { @Override public void run() { try { // IDEA-53203: add ERASE_MARKER for manually defined attributes view.getMarkupModel().addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, TextAttributes.ERASE_MARKER, HighlighterTargetArea.EXACT_RANGE); RangeHighlighter highlighter = view.getMarkupModel() .addRangeHighlighter(myStartOffset, myEndOffset, HighlighterLayer.ADDITIONAL_SYNTAX, attr, HighlighterTargetArea.EXACT_RANGE); final Color errorStripeColor = attr.getErrorStripeColor(); highlighter.setErrorStripeMarkColor(errorStripeColor); final String tooltip = displayText.get(myHighlightType); highlighter.setErrorStripeTooltip(tooltip); } catch (Exception e) { throw new RuntimeException(e); } } }); } }
private static TextAttributes createCompilationErrorAttr() { TextAttributes attr = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES).clone(); attr.setForegroundColor(JBColor.RED); attr.setEffectColor(JBColor.RED); attr.setEffectType(EffectType.LINE_UNDERSCORE); attr.setFontType(Font.PLAIN); return attr; }
public void invokeHint(Runnable hideRunnable) { myHideRunnable = hideRunnable; if (!canShowHint()) { hideHint(); return; } if (myType == ValueHintType.MOUSE_ALT_OVER_HINT) { EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme(); TextAttributes attributes = scheme.getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); attributes = NavigationUtil.patchAttributesColor(attributes, myCurrentRange, myEditor); myHighlighter = myEditor.getMarkupModel().addRangeHighlighter(myCurrentRange.getStartOffset(), myCurrentRange.getEndOffset(), HighlighterLayer.SELECTION + 1, attributes, HighlighterTargetArea.EXACT_RANGE); Component internalComponent = myEditor.getContentComponent(); myStoredCursor = internalComponent.getCursor(); internalComponent.addKeyListener(myEditorKeyListener); internalComponent.setCursor(hintCursor()); if (LOG.isDebugEnabled()) { LOG.debug("internalComponent.setCursor(hintCursor())"); } } else { evaluateAndShowHint(); } }
public ActionUsagePanel() { myEditor = (EditorEx)createEditor("", 10, 3, -1); setLayout(new BorderLayout()); add(myEditor.getComponent(), BorderLayout.CENTER); TextAttributes blinkAttributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(CodeInsightColors.BLINKING_HIGHLIGHTS_ATTRIBUTES); myRangeBlinker = new RangeBlinker(myEditor, blinkAttributes, Integer.MAX_VALUE); }