Java Code Examples for com.intellij.openapi.editor.colors.EditorColorsManager#getInstance()
The following examples show how to use
com.intellij.openapi.editor.colors.EditorColorsManager#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HighlightingUtil.java From needsmoredojo with Apache License 2.0 | 6 votes |
public static void highlightElement(Editor editor, @NotNull com.intellij.openapi.project.Project project, @NotNull PsiElement[] elements) { final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme(); final TextAttributes textattributes = globalScheme.getAttributes( EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights( editor, elements, textattributes, true, null); final WindowManager windowManager = WindowManager.getInstance(); final StatusBar statusBar = windowManager.getStatusBar(project); statusBar.setInfo("Press Esc to remove highlighting"); }
Example 2
Source File: ColorAndFontOptions.java From consulo with Apache License 2.0 | 6 votes |
@Override public void apply() throws ConfigurationException { if (myApplyCompleted) { return; } try { EditorColorsManager myColorsManager = EditorColorsManager.getInstance(); myColorsManager.removeAllSchemes(); for (MyColorScheme scheme : mySchemes.values()) { if (!scheme.isDefault()) { scheme.apply(); myColorsManager.addColorsScheme(scheme.getOriginalScheme()); } } EditorColorsScheme originalScheme = mySelectedScheme.getOriginalScheme(); myColorsManager.setGlobalScheme(originalScheme); applyChangesToEditors(); reset(); } finally { myApplyCompleted = true; } }
Example 3
Source File: EditorTextField.java From consulo with Apache License 2.0 | 6 votes |
private void initOneLineMode(final EditorEx editor) { final boolean isOneLineMode = isOneLineMode(); // set mode in editor editor.setOneLineMode(isOneLineMode); EditorColorsManager colorsManager = EditorColorsManager.getInstance(); final EditorColorsScheme defaultScheme = UIUtil.isUnderDarcula() ? colorsManager.getGlobalScheme() : colorsManager.getScheme(EditorColorsManager.DEFAULT_SCHEME_NAME); EditorColorsScheme customGlobalScheme = isOneLineMode ? defaultScheme : null; editor.setColorsScheme(editor.createBoundColorSchemeDelegate(customGlobalScheme)); EditorColorsScheme colorsScheme = editor.getColorsScheme(); editor.getSettings().setCaretRowShown(false); // color scheme settings: setupEditorFont(editor); updateBorder(editor); editor.setBackgroundColor(getBackgroundColor(isEnabled())); }
Example 4
Source File: Browser.java From consulo with Apache License 2.0 | 6 votes |
private void setupStyle() { Document document = myHTMLViewer.getDocument(); if (!(document instanceof StyledDocument)) { return; } StyledDocument styledDocument = (StyledDocument)document; EditorColorsManager colorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = colorsManager.getGlobalScheme(); Style style = styledDocument.addStyle("active", null); StyleConstants.setFontFamily(style, scheme.getEditorFontName()); StyleConstants.setFontSize(style, scheme.getEditorFontSize()); styledDocument.setCharacterAttributes(0, document.getLength(), style, false); }
Example 5
Source File: ColorAndFontOptions.java From consulo with Apache License 2.0 | 6 votes |
public void saveSchemeAs(String name) { MyColorScheme scheme = mySelectedScheme; if (scheme == null) return; EditorColorsScheme clone = (EditorColorsScheme)scheme.getOriginalScheme().clone(); scheme.apply(clone); clone.setName(name); MyColorScheme newScheme = new MyColorScheme(clone, EditorColorsManager.getInstance()); initScheme(newScheme); newScheme.setIsNew(); mySchemes.put(name, newScheme); selectScheme(newScheme.getName()); resetSchemesCombo(null); }
Example 6
Source File: HighlightUsagesHandlerBase.java From consulo with Apache License 2.0 | 6 votes |
protected void performHighlighting() { boolean clearHighlights = HighlightUsagesHandler.isClearHighlights(myEditor); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); TextAttributes writeAttributes = manager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES); HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, attributes, clearHighlights, myReadUsages); HighlightUsagesHandler.highlightRanges(HighlightManager.getInstance(myEditor.getProject()), myEditor, writeAttributes, clearHighlights, myWriteUsages); if (!clearHighlights) { WindowManager.getInstance().getStatusBar(myEditor.getProject()).setInfo(myStatusText); HighlightHandlerBase.setupFindModel(myEditor.getProject()); // enable f3 navigation } if (myHintText != null) { HintManager.getInstance().showInformationHint(myEditor, myHintText); } }
Example 7
Source File: FlowInPlaceRenamer.java From mule-intellij-plugins with Apache License 2.0 | 6 votes |
private static void addHighlights(List<TextRange> ranges, Editor editor, ArrayList<RangeHighlighter> highlighters) { EditorColorsManager colorsManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES); HighlightManager highlightManager = HighlightManager.getInstance(editor.getProject()); Iterator iterator = ranges.iterator(); while (iterator.hasNext()) { TextRange range = (TextRange) iterator.next(); //highlightManager.addOccurrenceHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, 0, highlighters, (Color) null); highlightManager.addRangeHighlight(editor, range.getStartOffset() + 1, range.getEndOffset() - 1, attributes, false, highlighters); } iterator = highlighters.iterator(); while (iterator.hasNext()) { RangeHighlighter highlighter = (RangeHighlighter) iterator.next(); highlighter.setGreedyToLeft(true); highlighter.setGreedyToRight(true); } }
Example 8
Source File: HighlightUsagesHandler.java From consulo with Apache License 2.0 | 5 votes |
public static void highlightOtherOccurrences(final List<PsiElement> otherOccurrences, Editor editor, boolean clearHighlights) { EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); PsiElement[] elements = PsiUtilCore.toPsiElementArray(otherOccurrences); doHighlightElements(editor, elements, attributes, clearHighlights); }
Example 9
Source File: CallerChooserBase.java From consulo with Apache License 2.0 | 5 votes |
private void updateEditorTexts(final MethodNodeBase<M> node) { final MethodNodeBase<M> parentNode = (MethodNodeBase)node.getParent(); final String callerText = node != myRoot ? getText(node.getMethod()) : ""; final Document callerDocument = myCallerEditor.getDocument(); final String calleeText = node != myRoot ? getText(parentNode.getMethod()) : ""; final Document calleeDocument = myCalleeEditor.getDocument(); ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { callerDocument.setText(callerText); calleeDocument.setText(calleeText); } }); final M caller = node.getMethod(); final PsiElement callee = parentNode != null ? parentNode.getElementToSearch() : null; if (caller != null && caller.isPhysical() && callee != null) { HighlightManager highlighter = HighlightManager.getInstance(myProject); EditorColorsManager colorManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); int start = getStartOffset(caller); for (PsiElement element : findElementsToHighlight(caller, callee)) { highlighter.addRangeHighlight(myCallerEditor, element.getTextRange().getStartOffset() - start, element.getTextRange().getEndOffset() - start, attributes, false, null); } } }
Example 10
Source File: CopyReferenceAction.java From consulo with Apache License 2.0 | 5 votes |
@RequiredUIAccess @Override public void actionPerformed(@Nonnull AnActionEvent e) { DataContext dataContext = e.getDataContext(); Editor editor = dataContext.getData(CommonDataKeys.EDITOR); Project project = dataContext.getData(CommonDataKeys.PROJECT); 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); } } } }
Example 11
Source File: ColorAndFontOptions.java From consulo with Apache License 2.0 | 5 votes |
public void addImportedScheme(@Nonnull final EditorColorsScheme imported) { MyColorScheme newScheme = new MyColorScheme(imported, EditorColorsManager.getInstance()); initScheme(newScheme); mySchemes.put(imported.getName(), newScheme); selectScheme(newScheme.getName()); resetSchemesCombo(null); }
Example 12
Source File: ExtractMethodHelper.java From consulo with Apache License 2.0 | 5 votes |
private static void highlightInEditor(@Nonnull final Project project, @Nonnull final SimpleMatch match, @Nonnull final Editor editor, Map<SimpleMatch, RangeHighlighter> highlighterMap) { final List<RangeHighlighter> highlighters = new ArrayList<>(); final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager colorsManager = EditorColorsManager.getInstance(); final TextAttributes attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); final int startOffset = match.getStartElement().getTextRange().getStartOffset(); final int endOffset = match.getEndElement().getTextRange().getEndOffset(); highlightManager.addRangeHighlight(editor, startOffset, endOffset, attributes, true, highlighters); highlighterMap.put(match, highlighters.get(0)); final LogicalPosition logicalPosition = editor.offsetToLogicalPosition(startOffset); editor.getScrollingModel().scrollTo(logicalPosition, ScrollType.MAKE_VISIBLE); }
Example 13
Source File: ExtractIncludeFileBase.java From consulo with Apache License 2.0 | 5 votes |
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); }
Example 14
Source File: HippieWordCompletionHandler.java From consulo with Apache License 2.0 | 5 votes |
private static void highlightWord(final CompletionVariant variant, final Project project, CompletionData data) { int delta = data.startOffset < variant.offset ? variant.variant.length() - data.myWordUnderCursor.length() : 0; HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorManager = EditorColorsManager.getInstance(); TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlight(variant.editor, variant.offset + delta, variant.offset + variant.variant.length() + delta, attributes, HighlightManager.HIDE_BY_ANY_KEY, null, null); }
Example 15
Source File: CustomizeUIThemeStepPanel.java From consulo with Apache License 2.0 | 5 votes |
private void applyLaf(String lafName, Component component) { UIManager.LookAndFeelInfo info = getLookAndFeelInfo(lafName); if (info == null) return; try { UIManager.setLookAndFeel(info.getClassName()); if (!myInitial) { LafManager.getInstance().setCurrentLookAndFeel(info); if(info instanceof LafWithColorScheme) { EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = editorColorsManager.getScheme(((LafWithColorScheme)info).getColorSchemeName()); if(scheme != null) { editorColorsManager.setGlobalScheme(scheme); } } } Window window = SwingUtilities.getWindowAncestor(component); if (window != null) { window.setBackground(new Color(UIUtil.getPanelBackground().getRGB())); SwingUtilities.updateComponentTreeUI(window); } if (myColumnMode) { myPreviewLabel.setIcon(myLafNames.get(lafName)); myPreviewLabel.setBorder(BorderFactory.createLineBorder(UIManager.getColor("Label.foreground"))); } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { e.printStackTrace(); } }
Example 16
Source File: FragmentedEditorHighlighter.java From consulo with Apache License 2.0 | 5 votes |
private boolean isUsualAttributes(final TextAttributes ta) { if (myUsualAttributes == null) { final EditorColorsManager manager = EditorColorsManager.getInstance(); final EditorColorsScheme[] schemes = manager.getAllSchemes(); EditorColorsScheme defaultScheme = schemes[0]; for (EditorColorsScheme scheme : schemes) { if (manager.isDefaultScheme(scheme)) { defaultScheme = scheme; break; } } myUsualAttributes = defaultScheme.getAttributes(HighlighterColors.TEXT); } return myUsualAttributes.equals(ta); }
Example 17
Source File: HighlightDisplayLevel.java From consulo with Apache License 2.0 | 5 votes |
@Nullable public Color getColorInner() { final EditorColorsManager manager = EditorColorsManager.getInstance(); if (manager != null) { TextAttributes attributes = manager.getGlobalScheme().getAttributes(myKey); Color stripe = attributes.getErrorStripeColor(); if (stripe != null) return stripe; return attributes.getEffectColor(); } TextAttributes defaultAttributes = myKey.getDefaultAttributes(); if (defaultAttributes == null) defaultAttributes = TextAttributes.ERASE_MARKER; return defaultAttributes.getErrorStripeColor(); }
Example 18
Source File: AbstractBashSyntaxHighlighterTest.java From BashSupport with Apache License 2.0 | 5 votes |
protected void doLexerHighlightingTest(String fileContent, IElementType targetElementType) { BashSyntaxHighlighter syntaxHighlighter = new BashSyntaxHighlighter(); TextAttributesKey[] keys = syntaxHighlighter.getTokenHighlights(targetElementType); Assert.assertEquals("Expected one key", 1, keys.length); TextAttributesKey attributesKey = keys[0]; Assert.assertNotNull(attributesKey); EditorColorsManager manager = EditorColorsManager.getInstance(); EditorColorsScheme scheme = (EditorColorsScheme) manager.getGlobalScheme().clone(); manager.addColorsScheme(scheme); EditorColorsManager.getInstance().setGlobalScheme(scheme); TextAttributes targetAttributes = new TextAttributes(JBColor.RED, JBColor.BLUE, JBColor.GRAY, EffectType.BOXED, Font.BOLD); scheme.setAttributes(attributesKey, targetAttributes); myFixture.configureByText(BashFileType.BASH_FILE_TYPE, fileContent); TextAttributes actualAttributes = null; HighlighterIterator iterator = ((EditorImpl) myFixture.getEditor()).getHighlighter().createIterator(0); while (!iterator.atEnd()) { if (iterator.getTokenType() == targetElementType) { actualAttributes = iterator.getTextAttributes(); break; } iterator.advance(); } Assert.assertEquals("Expected text attributes for " + attributesKey, targetAttributes, actualAttributes); }
Example 19
Source File: ScopeHighlighter.java From consulo with Apache License 2.0 | 4 votes |
private static TextAttributes getTestAttributesForRemoval() { EditorColorsManager manager = EditorColorsManager.getInstance(); return manager.getGlobalScheme().getAttributes(EditorColors.DELETED_TEXT_ATTRIBUTES); }
Example 20
Source File: FindUtil.java From consulo with Apache License 2.0 | 4 votes |
@Nullable private static FindResult doSearch(@Nonnull Project project, @Nonnull final Editor editor, int offset, boolean toWarn, @Nonnull FindModel model, boolean adjustEditor) { FindManager findManager = FindManager.getInstance(project); Document document = editor.getDocument(); final FindResult result = findManager.findString(document.getCharsSequence(), offset, model, getVirtualFile(editor)); boolean isFound = result.isStringFound(); final SelectionModel selection = editor.getSelectionModel(); if (isFound && !model.isGlobal()) { if (!selectionMayContainRange(selection, result)) { isFound = false; } else if (!selectionStrictlyContainsRange(selection, result)) { final int[] starts = selection.getBlockSelectionStarts(); for (int newOffset : starts) { if (newOffset > result.getStartOffset()) { return doSearch(project, editor, newOffset, toWarn, model, adjustEditor); } } } } if (!isFound) { if (toWarn) { processNotFound(editor, model.getStringToFind(), model, project); } return null; } if (adjustEditor) { final CaretModel caretModel = editor.getCaretModel(); final ScrollingModel scrollingModel = editor.getScrollingModel(); int oldCaretOffset = caretModel.getOffset(); boolean forward = oldCaretOffset < result.getStartOffset(); final ScrollType scrollType = forward ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP; if (model.isGlobal()) { int targetCaretPosition = result.getEndOffset(); if (selection.getSelectionEnd() - selection.getSelectionStart() == result.getLength()) { // keeping caret's position relative to selection // use case: FindNext is used after SelectNextOccurrence action targetCaretPosition = caretModel.getOffset() - selection.getSelectionStart() + result.getStartOffset(); } if (caretModel.getCaretAt(editor.offsetToVisualPosition(targetCaretPosition)) != null) { // if there's a different caret at target position, don't move current caret/selection // use case: FindNext is used after SelectNextOccurrence action return result; } caretModel.moveToOffset(targetCaretPosition); selection.removeSelection(); scrollingModel.scrollToCaret(scrollType); scrollingModel.runActionOnScrollingFinished( () -> { scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getStartOffset()), scrollType); scrollingModel.scrollTo(editor.offsetToLogicalPosition(result.getEndOffset()), scrollType); } ); } else { moveCaretAndDontChangeSelection(editor, result.getStartOffset(), scrollType); moveCaretAndDontChangeSelection(editor, result.getEndOffset(), scrollType); } IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation(); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes selectionAttributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); if (!model.isGlobal()) { final RangeHighlighterEx segmentHighlighter = (RangeHighlighterEx)editor.getMarkupModel().addRangeHighlighter( result.getStartOffset(), result.getEndOffset(), HighlighterLayer.SELECTION + 1, selectionAttributes, HighlighterTargetArea.EXACT_RANGE); MyListener listener = new MyListener(editor, segmentHighlighter); caretModel.addCaretListener(listener); } else { selection.setSelection(result.getStartOffset(), result.getEndOffset()); } } return result; }