private void createUIComponents() { final EditorFactory editorFactory = EditorFactory.getInstance(); jsonDocument = editorFactory.createDocument(EMPTY_TEXT); jsonEditor = editorFactory.createEditor(jsonDocument, project, JsonFileType.INSTANCE, false); final EditorSettings settings = jsonEditor.getSettings(); settings.setWhitespacesShown(true); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setLineNumbersShown(true); settings.setFoldingOutlineShown(false); settings.setRightMarginShown(false); settings.setVirtualSpace(false); settings.setWheelFontChangeEnabled(false); settings.setUseSoftWraps(false); settings.setAdditionalColumnsCount(0); settings.setAdditionalLinesCount(1); final EditorColorsScheme colorsScheme = jsonEditor.getColorsScheme(); colorsScheme.setColor(EditorColors.CARET_ROW_COLOR, null); jsonEditor.getContentComponent().setFocusable(true); jsonPanel = (JPanel) jsonEditor.getComponent(); }
public static void drawAllAnswerPlaceholders(Editor editor, TaskFile taskFile) { editor.getMarkupModel().removeAllHighlighters(); final Project project = editor.getProject(); if (project == null) return; final StudyTaskManager taskManager = StudyTaskManager.getInstance(project); for (AnswerPlaceholder answerPlaceholder : taskFile.getAnswerPlaceholders()) { final JBColor color = taskManager.getColor(answerPlaceholder); EduAnswerPlaceholderPainter.drawAnswerPlaceholder(editor, answerPlaceholder, color); } final Document document = editor.getDocument(); EditorActionManager.getInstance() .setReadonlyFragmentModificationHandler(document, new EduAnswerPlaceholderDeleteHandler(editor)); EduAnswerPlaceholderPainter.createGuardedBlocks(editor, taskFile); editor.getColorsScheme().setColor(EditorColors.READONLY_FRAGMENT_BACKGROUND_COLOR, null); }
@Nullable @Override public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) { if (!CCUtils.isCourseCreator(myProject)) { return null; } boolean isTestFile = CCUtils.isTestsFile(myProject, file); if (!isTestFile && StudyUtils.getTaskFile(myProject, file) == null) { return null; } Task task = StudyUtils.getTaskForFile(myProject, file); if (task instanceof TaskWithSubtasks) { final TaskWithSubtasks withSubtasks = (TaskWithSubtasks)task; EditorNotificationPanel panel = new EditorNotificationPanel(EditorColors.GUTTER_BACKGROUND); String header = (isTestFile ? "test" : "task") + " file"; int activeSubtaskIndex = withSubtasks.getActiveSubtaskIndex() + 1; int subtaskSize = withSubtasks.getLastSubtaskIndex() + 1; panel.setText("This is a " + header + " for " + EduNames.SUBTASK + " " + activeSubtaskIndex + "/" + subtaskSize); panel .createActionLabel(SWITCH_SUBTASK, () -> createPopup(withSubtasks, myProject).show(RelativePoint.getSouthEastOf(panel))); return panel; } return null; }
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); } }
public static RemoveUnusedVariableUtil.RemoveMode showSideEffectsWarning(List<PsiElement> sideEffects, PsiVariable variable, Editor editor, boolean canCopeWithSideEffects, @NonNls String beforeText, @NonNls String afterText) { if (sideEffects.isEmpty()) return RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL; if (ApplicationManager.getApplication().isUnitTestMode()) { return canCopeWithSideEffects ? RemoveUnusedVariableUtil.RemoveMode.MAKE_STATEMENT : RemoveUnusedVariableUtil.RemoveMode.DELETE_ALL; } Project project = editor.getProject(); HighlightManager highlightManager = HighlightManager.getInstance(project); PsiElement[] elements = PsiUtilCore.toPsiElementArray(sideEffects); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights(editor, elements, attributes, true, null); SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, variable, beforeText, afterText, canCopeWithSideEffects); dialog.show(); int code = dialog.getExitCode(); return RemoveUnusedVariableUtil.RemoveMode.values()[code]; }
private static void highlightOccurrences(String filter, Project project, Editor editor) { final HighlightManager highlightManager = HighlightManager.getInstance(project); EditorColorsManager colorManager = EditorColorsManager.getInstance(); final TextAttributes attributes = colorManager.getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); String documentText = editor.getDocument().getText(); int i = -1; while (true) { int nextOccurrence = StringUtil.indexOfIgnoreCase(documentText, filter, i + 1); if (nextOccurrence < 0) { break; } i = nextOccurrence; highlightManager.addOccurrenceHighlight(editor, i, i + filter.length(), attributes, HighlightManager.HIDE_BY_TEXT_CHANGE, null, null); } }
@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; }
/** * @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; }
@Override public void paint(Editor editor, Graphics g, Rectangle r) { if (!myCondition.get()) return; int y = r.y; int lineHeight = myEditor.getLineHeight(); EditorGutterComponentEx gutter = ((EditorEx)editor).getGutterComponentEx(); int annotationsOffset = gutter.getAnnotationsAreaOffset(); int annotationsWidth = gutter.getAnnotationsAreaWidth(); if (annotationsWidth != 0) { g.setColor(editor.getColorsScheme().getColor(EditorColors.GUTTER_BACKGROUND)); g.fillRect(annotationsOffset, y, annotationsWidth, lineHeight); } draw(g, 0, y, lineHeight, myEditor.getColorsScheme()); }
private void paintSelectionOnSecondSoftWrapLineIfNecessary(Graphics2D g, int columnEnd, float xEnd, int y) { VisualPosition selectionStartPosition = myEditor.getSelectionModel().getSelectionStartPosition(); VisualPosition selectionEndPosition = myEditor.getSelectionModel().getSelectionEndPosition(); int visualLine = myView.yToVisualLine(y); if (selectionStartPosition.equals(selectionEndPosition) || visualLine < selectionStartPosition.line || visualLine > selectionEndPosition.line || visualLine == selectionStartPosition.line && selectionStartPosition.column >= columnEnd) { return; } float startX = (selectionStartPosition.line == visualLine && selectionStartPosition.column > 0) ? myView.visualPositionToXY(selectionStartPosition).x : 0; float endX = (selectionEndPosition.line == visualLine && selectionEndPosition.column < columnEnd) ? myView.visualPositionToXY(selectionEndPosition).x : xEnd; paintBackground(g, myEditor.getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), startX, y, endX - startX); }
private void paintSelectionOnFirstSoftWrapLineIfNecessary(Graphics2D g, int columnStart, float xStart, float xEnd, int y) { VisualPosition selectionStartPosition = myEditor.getSelectionModel().getSelectionStartPosition(); VisualPosition selectionEndPosition = myEditor.getSelectionModel().getSelectionEndPosition(); int visualLine = myView.yToVisualLine(y); if (selectionStartPosition.equals(selectionEndPosition) || visualLine < selectionStartPosition.line || visualLine > selectionEndPosition.line || visualLine == selectionEndPosition.line && selectionEndPosition.column <= columnStart) { return; } float startX = selectionStartPosition.line == visualLine && selectionStartPosition.column > columnStart ? myView.visualPositionToXY(selectionStartPosition).x : xStart; float endX = selectionEndPosition.line == visualLine ? myView.visualPositionToXY(selectionEndPosition).x : xEnd; paintBackground(g, myEditor.getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), startX, y, endX - startX); }
private void paintLineMarkerSeparator(RangeHighlighter marker, Rectangle clip, Graphics g) { Color separatorColor = marker.getLineSeparatorColor(); LineSeparatorRenderer lineSeparatorRenderer = marker.getLineSeparatorRenderer(); if (separatorColor == null && lineSeparatorRenderer == null) { return; } int line = myDocument.getLineNumber(marker.getLineSeparatorPlacement() == SeparatorPlacement.TOP ? marker.getStartOffset() : marker.getEndOffset()); int visualLine = myView.logicalToVisualPosition(new LogicalPosition(line + (marker.getLineSeparatorPlacement() == SeparatorPlacement.TOP ? 0 : 1), 0), false).line; int y = myView.visualLineToY(visualLine) - 1; int endShift = clip.x + clip.width; EditorSettings settings = myEditor.getSettings(); if (settings.isRightMarginShown() && myEditor.getColorsScheme().getColor(EditorColors.RIGHT_MARGIN_COLOR) != null) { endShift = Math.min(endShift, settings.getRightMargin(myEditor.getProject()) * myView.getPlainSpaceWidth()); } g.setColor(separatorColor); if (lineSeparatorRenderer != null) { lineSeparatorRenderer.drawLine(g, 0, endShift, y); } else { UIUtil.drawLine(g, 0, y, endShift, y); } }
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean selected, boolean focused, int row, int column) { RendererComponent panel = getEditorPanel(table); EditorEx editor = panel.getEditor(); editor.getColorsScheme().setEditorFontSize(table.getFont().getSize()); editor.getColorsScheme().setColor(EditorColors.SELECTION_BACKGROUND_COLOR, table.getSelectionBackground()); editor.getColorsScheme().setColor(EditorColors.SELECTION_FOREGROUND_COLOR, table.getSelectionForeground()); editor.setBackgroundColor(selected ? table.getSelectionBackground() : table.getBackground()); panel.setSelected(!Comparing.equal(editor.getBackgroundColor(), table.getBackground())); panel.setBorder(null); // prevents double border painting when ExtendedItemRendererComponentWrapper is used customizeEditor(editor, table, value, selected, row, column); return panel; }
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); } }
@NotNull private HighlightersSet installHighlighterSet(@NotNull Info info, @NotNull Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); for (TextRange range : info.getRanges()) { TextAttributes attr = NavigationUtil.patchAttributesColor(attributes, range, editor); final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attr, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
private boolean addInjectedPsiHighlights(@NotNull final Set<PsiFile> injectedFiles, @NotNull final ProgressIndicator progress, @NotNull final Collection<HighlightInfo> outInfos) { if (injectedFiles.isEmpty()) return true; final InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(myProject); final TextAttributes injectedAttributes = myGlobalScheme.getAttributes(EditorColors.INJECTED_LANGUAGE_FRAGMENT); return JobLauncher.getInstance() .invokeConcurrentlyUnderProgress(new ArrayList<PsiFile>(injectedFiles), progress, isFailFastOnAcquireReadAction(), new Processor<PsiFile>() { @Override public boolean process(final PsiFile injectedPsi) { return addInjectedPsiHighlights(injectedPsi, injectedAttributes, outInfos, progress, injectedLanguageManager); } }); }
private void updateCursorHighlighting() { hideBalloon(); if (myCursorHighlighter != null) { HighlightManager.getInstance(mySearchResults.getProject()).removeSegmentHighlighter(mySearchResults.getEditor(), myCursorHighlighter); myCursorHighlighter = null; } final FindResult cursor = mySearchResults.getCursor(); Editor editor = mySearchResults.getEditor(); if (cursor != null && cursor.getEndOffset() <= editor.getDocument().getTextLength()) { Set<RangeHighlighter> dummy = new HashSet<RangeHighlighter>(); Color color = editor.getColorsScheme().getColor(EditorColors.CARET_COLOR); highlightRange(cursor, new TextAttributes(null, null, color, EffectType.ROUNDED_BOX, 0), dummy); if (!dummy.isEmpty()) { myCursorHighlighter = dummy.iterator().next(); } editor.getScrollingModel().runActionOnScrollingFinished(new Runnable() { @Override public void run() { showReplacementPreview(); } }); } }
private void highlightUsages() { if (mySearchResults.getEditor() == null) return; if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit()) return; for (FindResult range : mySearchResults.getOccurrences()) { if (range.getEndOffset() > mySearchResults.getEditor().getDocument().getTextLength()) continue; TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); if (range.getLength() == 0) { attributes = attributes.clone(); attributes.setEffectType(EffectType.BOXED); attributes.setEffectColor(attributes.getBackgroundColor()); } if (mySearchResults.isExcluded(range)) { highlightRange(range, strikeout(), myHighlighters); } else { highlightRange(range, attributes, myHighlighters); } } updateInSelectionHighlighters(); if (!myListeningSelection) { mySearchResults.getEditor().getSelectionModel().addSelectionListener(this); myListeningSelection = true; } }
private void highlightTemplateVariables(Template template, Editor topLevelEditor) { //add highlights if (myHighlighters != null) { // can be null if finish is called during testing Map<TextRange, TextAttributes> rangesToHighlight = new HashMap<TextRange, TextAttributes>(); final TemplateState templateState = TemplateManagerImpl.getTemplateState(topLevelEditor); if (templateState != null) { EditorColorsManager colorsManager = EditorColorsManager.getInstance(); for (int i = 0; i < templateState.getSegmentsCount(); i++) { final TextRange segmentOffset = templateState.getSegmentRange(i); final String name = template.getSegmentName(i); TextAttributes attributes = null; if (name.equals(PRIMARY_VARIABLE_NAME)) { attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.WRITE_SEARCH_RESULT_ATTRIBUTES); } else if (name.equals(OTHER_VARIABLE_NAME)) { attributes = colorsManager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); } if (attributes == null) continue; rangesToHighlight.put(segmentOffset, attributes); } } addHighlights(rangesToHighlight, topLevelEditor, myHighlighters, HighlightManager.getInstance(myProject)); } }
public RestEditorHighlighter(@NotNull EditorColorsScheme scheme, @Nullable Project project, @Nullable VirtualFile file) { super(SyntaxHighlighterFactory.getSyntaxHighlighter(RestLanguage.INSTANCE, project, file), scheme); registerLayer(RestTokenTypes.PYTHON_LINE, new LayerDescriptor( SyntaxHighlighterFactory.getSyntaxHighlighter(PythonFileType.INSTANCE, project, file), "", EditorColors.INJECTED_LANGUAGE_FRAGMENT)); FileType djangoTemplateFileType = FileTypeManager.getInstance().findFileTypeByName("DjangoTemplate"); if (djangoTemplateFileType != null) { registerLayer(RestTokenTypes.DJANGO_LINE, new LayerDescriptor( SyntaxHighlighterFactory.getSyntaxHighlighter(djangoTemplateFileType, project, file), "", EditorColors.INJECTED_LANGUAGE_FRAGMENT)); } registerLayer(RestTokenTypes.JAVASCRIPT_LINE, new LayerDescriptor( SyntaxHighlighterFactory.getSyntaxHighlighter(StdFileTypes.JS, project, file), "", EditorColors.INJECTED_LANGUAGE_FRAGMENT)); }
@Override public void itemHovered(@Nullable BreadcrumbsPsiItem item) { if (!Registry.is("editor.breadcrumbs.highlight.on.hover")) { return; } HighlightManager hm = HighlightManager.getInstance(myProject); if (myHighlighed != null) { for (RangeHighlighter highlighter : myHighlighed) { hm.removeSegmentHighlighter(myEditor, highlighter); } myHighlighed = null; } if (item != null) { final TextRange range = item.getPsiElement().getTextRange(); final TextAttributes attributes = new TextAttributes(); final CrumbPresentation p = item.getPresentation(); final Color color = p != null ? p.getBackgroundColor(false, false, false) : BreadcrumbsComponent.ButtonSettings.DEFAULT_BG_COLOR; final Color background = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.CARET_ROW_COLOR); attributes.setBackgroundColor(XmlTagTreeHighlightingUtil.makeTransparent(color, background != null ? background : Gray._200, 0.3)); myHighlighed = new ArrayList<RangeHighlighter>(1); int flags = HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_TEXT_CHANGE | HighlightManager.HIDE_BY_ANY_KEY; hm.addOccurrenceHighlight(myEditor, range.getStartOffset(), range.getEndOffset(), attributes, flags, myHighlighed, null); } }
private static void highlightElement(@NotNull PsiElement element) { final Project project = element.getProject(); final FileEditorManager editorManager = FileEditorManager.getInstance(project); final HighlightManager highlightManager = HighlightManager.getInstance(project); final EditorColorsManager editorColorsManager = EditorColorsManager.getInstance(); final Editor editor = editorManager.getSelectedTextEditor(); final EditorColorsScheme globalScheme = editorColorsManager.getGlobalScheme(); final TextAttributes textattributes = globalScheme.getAttributes( EditorColors.SEARCH_RESULT_ATTRIBUTES); final PsiElement[] elements = new PsiElement[]{element}; highlightManager.addOccurrenceHighlights(editor, elements, textattributes, true, null); StatusBar.Info.set(IntentionPowerPackBundle.message( "status.bar.escape.highlighting.message"), project); }
public static int showSideEffectsWarning(List<PsiElement> sideEffects, PsiVariable variable, Editor editor, boolean canCopeWithSideEffects, @NonNls String beforeText, @NonNls String afterText) { if (sideEffects.isEmpty()) return RemoveUnusedVariableUtil.DELETE_ALL; if (ApplicationManager.getApplication().isUnitTestMode()) { return canCopeWithSideEffects ? RemoveUnusedVariableUtil.MAKE_STATEMENT : RemoveUnusedVariableUtil.DELETE_ALL; } Project project = editor.getProject(); HighlightManager highlightManager = HighlightManager.getInstance(project); PsiElement[] elements = PsiUtilCore.toPsiElementArray(sideEffects); EditorColorsManager manager = EditorColorsManager.getInstance(); TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES); highlightManager.addOccurrenceHighlights(editor, elements, attributes, true, null); SideEffectWarningDialog dialog = new SideEffectWarningDialog(project, false, variable, beforeText, afterText, canCopeWithSideEffects); dialog.show(); return dialog.getExitCode(); }
public static void setupConsoleEditor(final EditorEx editor, final boolean foldingOutlineShown, final boolean lineMarkerAreaShown) { ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { editor.setSoftWrapAppliancePlace(SoftWrapAppliancePlaces.CONSOLE); final EditorSettings editorSettings = editor.getSettings(); editorSettings.setLineMarkerAreaShown(lineMarkerAreaShown); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(foldingOutlineShown); editorSettings.setAdditionalPageAtBottom(false); editorSettings.setAdditionalColumnsCount(0); editorSettings.setAdditionalLinesCount(0); editor.putUserData(EDITOR_IS_CONSOLE_VIEW, true); final DelegateColorScheme scheme = updateConsoleColorScheme(editor.getColorsScheme()); editor.setColorsScheme(scheme); scheme.setColor(EditorColors.CARET_ROW_COLOR, null); scheme.setColor(EditorColors.RIGHT_MARGIN_COLOR, null); } }); }
private HighlightersSet installHighlighterSet(Info info, Editor editor) { final JComponent internalComponent = editor.getContentComponent(); internalComponent.addKeyListener(myEditorKeyListener); editor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); final Cursor cursor = internalComponent.getCursor(); internalComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myFileEditorManager.addFileEditorManagerListener(myFileEditorManagerListener); List<RangeHighlighter> highlighters = new ArrayList<RangeHighlighter>(); TextAttributes attributes = myEditorColorsManager.getGlobalScheme().getAttributes(EditorColors.REFERENCE_HYPERLINK_COLOR); for (TextRange range : info.getRanges()) { final RangeHighlighter highlighter = editor.getMarkupModel().addRangeHighlighter(range.getStartOffset(), range.getEndOffset(), HighlighterLayer.SELECTION + 1, attributes, HighlighterTargetArea.EXACT_RANGE); highlighters.add(highlighter); } return new HighlightersSet(highlighters, editor, cursor, info); }
private static Editor createEditor(boolean isReadOnly, final Document document, final Project project) { EditorFactory editorFactory = EditorFactory.getInstance(); Editor editor = (isReadOnly ? editorFactory.createViewer(document, project) : editorFactory.createEditor(document, project)); EditorSettings editorSettings = editor.getSettings(); editorSettings.setVirtualSpace(false); editorSettings.setLineMarkerAreaShown(false); editorSettings.setIndentGuidesShown(false); editorSettings.setLineNumbersShown(false); editorSettings.setFoldingOutlineShown(false); EditorColorsScheme scheme = editor.getColorsScheme(); scheme.setColor(EditorColors.CARET_ROW_COLOR, null); VirtualFile file = FileDocumentManager.getInstance().getFile(document); if (file != null) { EditorHighlighter highlighter = EditorHighlighterFactory.getInstance().createEditorHighlighter(file, scheme, project); ((EditorEx) editor).setHighlighter(highlighter); } return editor; }
private static void duplicateHighlighters(MarkupModel to, MarkupModel from, int offset, TextRange textRange) { for (RangeHighlighter rangeHighlighter : from.getAllHighlighters()) { if (!rangeHighlighter.isValid()) continue; Object tooltip = rangeHighlighter.getErrorStripeTooltip(); HighlightInfo highlightInfo = tooltip instanceof HighlightInfo? (HighlightInfo)tooltip : null; if (highlightInfo != null) { if (highlightInfo.getSeverity() != HighlightSeverity.INFORMATION) continue; if (highlightInfo.type.getAttributesKey() == EditorColors.IDENTIFIER_UNDER_CARET_ATTRIBUTES) continue; } final int localOffset = textRange.getStartOffset(); final int start = Math.max(rangeHighlighter.getStartOffset(), localOffset) - localOffset; final int end = Math.min(rangeHighlighter.getEndOffset(), textRange.getEndOffset()) - localOffset; if (start > end) continue; final RangeHighlighter h = to.addRangeHighlighter( start + offset, end + offset, rangeHighlighter.getLayer(), rangeHighlighter.getTextAttributes(), rangeHighlighter.getTargetArea()); ((RangeHighlighterEx)h).setAfterEndOfLine(((RangeHighlighterEx)rangeHighlighter).isAfterEndOfLine()); } }
private void highlightUsages() { if (mySearchResults.getEditor() == null) return; if (mySearchResults.getMatchesCount() >= mySearchResults.getMatchesLimit()) return; for (FindResult range : mySearchResults.getOccurrences()) { TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.TEXT_SEARCH_RESULT_ATTRIBUTES); if (range.getLength() == 0) { attributes = attributes.clone(); attributes.setEffectType(EffectType.BOXED); attributes.setEffectColor(attributes.getBackgroundColor()); } if (mySearchResults.isExcluded(range)) { highlightRange(range, strikout(attributes), myHighlighters); } else { highlightRange(range, attributes, myHighlighters); } } updateInSelectionHighlighters(); if (!myListeningSelection) { mySearchResults.getEditor().getSelectionModel().addSelectionListener(this); myListeningSelection = true; } }
/** * Creates and configures template preview editor. * * @param document virtual editor document * @param project current project * @return editor */ @NotNull public static Editor createPreviewEditor(@NotNull Document document, @Nullable Project project, boolean isViewer) { EditorEx editor = (EditorEx) EditorFactory.getInstance().createEditor(document, project, IgnoreFileType.INSTANCE, isViewer); editor.setCaretEnabled(!isViewer); final EditorSettings settings = editor.getSettings(); settings.setLineNumbersShown(false); settings.setAdditionalColumnsCount(1); settings.setAdditionalLinesCount(0); settings.setRightMarginShown(false); settings.setFoldingOutlineShown(false); settings.setLineMarkerAreaShown(false); settings.setIndentGuidesShown(false); settings.setVirtualSpace(false); settings.setWheelFontChangeEnabled(false); EditorColorsScheme colorsScheme = editor.getColorsScheme(); colorsScheme.setColor(EditorColors.CARET_ROW_COLOR, null); return editor; }
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"); }
private void paintSelectionOnSecondSoftWrapLineIfNecessary(Graphics2D g, int visualLine, int columnEnd, float xEnd, int y, VisualPosition selectionStartPosition, VisualPosition selectionEndPosition) { if (selectionStartPosition.equals(selectionEndPosition) || visualLine < selectionStartPosition.line || visualLine > selectionEndPosition.line || visualLine == selectionStartPosition.line && selectionStartPosition.column >= columnEnd) { return; } float startX = (selectionStartPosition.line == visualLine && selectionStartPosition.column > 0) ? (float)myView.visualPositionToXY(selectionStartPosition).getX() : getMinX(); float endX = (selectionEndPosition.line == visualLine && selectionEndPosition.column < columnEnd) ? (float)myView.visualPositionToXY(selectionEndPosition).getX() : xEnd; paintBackground(g, myEditor.getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), startX, y, endX - startX); }
private void paintSelectionOnFirstSoftWrapLineIfNecessary(Graphics2D g, int visualLine, int columnStart, float xStart, float xEnd, int y, VisualPosition selectionStartPosition, VisualPosition selectionEndPosition) { if (selectionStartPosition.equals(selectionEndPosition) || visualLine < selectionStartPosition.line || visualLine > selectionEndPosition.line || visualLine == selectionEndPosition.line && selectionEndPosition.column <= columnStart) { return; } float startX = selectionStartPosition.line == visualLine && selectionStartPosition.column > columnStart ? (float)myView.visualPositionToXY(selectionStartPosition).getX() : xStart; float endX = selectionEndPosition.line == visualLine ? (float)myView.visualPositionToXY(selectionEndPosition).getX() : xEnd; paintBackground(g, myEditor.getColorsScheme().getColor(EditorColors.SELECTION_BACKGROUND_COLOR), startX, y, endX - startX); }