Java Code Examples for com.intellij.openapi.editor.ex.EditorEx#setColorsScheme()

The following examples show how to use com.intellij.openapi.editor.ex.EditorEx#setColorsScheme() . 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: IdeUtils.java    From StringManipulation with Apache License 2.0 6 votes vote down vote up
public static EditorImpl createEditorPreview(String text, boolean editable) {
	EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
	ColorAndFontOptions options = new ColorAndFontOptions();
	options.reset();
	options.selectScheme(scheme.getName());

	EditorFactory editorFactory = EditorFactory.getInstance();
	Document editorDocument = editorFactory.createDocument(text);
	EditorEx editor = (EditorEx) (editable ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
	editor.setColorsScheme(scheme);
	EditorSettings settings = editor.getSettings();
	settings.setLineNumbersShown(true);
	settings.setWhitespacesShown(false);
	settings.setLineMarkerAreaShown(false);
	settings.setIndentGuidesShown(false);
	settings.setFoldingOutlineShown(false);
	settings.setAdditionalColumnsCount(0);
	settings.setAdditionalLinesCount(0);
	settings.setRightMarginShown(false);

	return (EditorImpl) editor;
}
 
Example 2
Source File: GoalEditor.java    From MavenHelper with Apache License 2.0 6 votes vote down vote up
@NotNull
private static Editor createEditor() {
	EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
	ColorAndFontOptions options = new ColorAndFontOptions();
	options.reset();
	options.selectScheme(scheme.getName());
	EditorFactory editorFactory = EditorFactory.getInstance();
	Document editorDocument = editorFactory.createDocument("");


	EditorEx editor = (EditorEx) (true ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
	editor.setColorsScheme(scheme);
	EditorSettings settings = editor.getSettings();
	settings.setLineNumbersShown(false);
	settings.setUseSoftWraps(true);
	settings.setWhitespacesShown(false);
	settings.setLineMarkerAreaShown(false);
	settings.setIndentGuidesShown(false);
	settings.setFoldingOutlineShown(false);
	settings.setAdditionalColumnsCount(0);
	settings.setAdditionalLinesCount(0);
	settings.setRightMarginShown(false);

	return editor;
}
 
Example 3
Source File: EditorTextField.java    From consulo with Apache License 2.0 6 votes vote down vote up
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: IntentionUsagePanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static Editor createEditor(String text, int column, int line, int selectedLine) {
  EditorFactory editorFactory = EditorFactory.getInstance();
  Document editorDocument = editorFactory.createDocument(text);
  EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument);
  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  editor.setColorsScheme(scheme);
  EditorSettings settings = editor.getSettings();
  settings.setWhitespacesShown(true);
  settings.setLineMarkerAreaShown(false);
  settings.setIndentGuidesShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalLinesCount(0);
  settings.setRightMarginShown(true);
  settings.setRightMargin(60);

  LogicalPosition pos = new LogicalPosition(line, column);
  editor.getCaretModel().moveToLogicalPosition(pos);
  if (selectedLine >= 0) {
    editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine),
                                            editorDocument.getLineEndOffset(selectedLine));
  }

  return editor;
}
 
Example 5
Source File: ActionUsagePanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected static Editor createEditor(String text, int column, int line, int selectedLine) {
  EditorFactory editorFactory = EditorFactory.getInstance();
  Document editorDocument = editorFactory.createDocument(text);
  EditorEx editor = (EditorEx)editorFactory.createViewer(editorDocument);
  EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
  editor.setColorsScheme(scheme);
  EditorSettings settings = editor.getSettings();
  settings.setWhitespacesShown(true);
  settings.setLineMarkerAreaShown(false);
  settings.setIndentGuidesShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalLinesCount(0);
  settings.setRightMarginShown(true);
  settings.setRightMargin(60);

  LogicalPosition pos = new LogicalPosition(line, column);
  editor.getCaretModel().moveToLogicalPosition(pos);
  if (selectedLine >= 0) {
    editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine),
                                            editorDocument.getLineEndOffset(selectedLine));
  }

  return editor;
}
 
Example 6
Source File: FontEditorPreview.java    From consulo with Apache License 2.0 6 votes vote down vote up
static Editor createPreviewEditor(String text, int column, int line, int selectedLine, ColorAndFontOptions options, boolean editable) {
  EditorFactory editorFactory = EditorFactory.getInstance();
  Document editorDocument = editorFactory.createDocument(text);
  EditorEx editor = (EditorEx) (editable ? editorFactory.createEditor(editorDocument) : editorFactory.createViewer(editorDocument));
  editor.setColorsScheme(options.getSelectedScheme());
  EditorSettings settings = editor.getSettings();
  settings.setLineNumbersShown(true);
  settings.setWhitespacesShown(true);
  settings.setLineMarkerAreaShown(false);
  settings.setIndentGuidesShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalLinesCount(0);
  settings.setRightMarginShown(true);
  settings.setRightMargin(60);

  LogicalPosition pos = new LogicalPosition(line, column);
  editor.getCaretModel().moveToLogicalPosition(pos);
  if (selectedLine >= 0) {
    editor.getSelectionModel().setSelection(editorDocument.getLineStartOffset(selectedLine),
                                            editorDocument.getLineEndOffset(selectedLine));
  }

  return editor;
}
 
Example 7
Source File: RightMarginEditorCustomization.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(@Nonnull EditorEx editor) {
  if (isEnabled()) {
    editor.getSettings().setRightMarginShown(true);
    editor.getSettings().setRightMargin(getRightMarginColumns());
    // ensure we've got a monospace font by loading up the global editor scheme
    editor.setColorsScheme(EditorColorsManager.getInstance().getGlobalScheme());
  } else {
    editor.getSettings().setRightMarginShown(false);
  }
}
 
Example 8
Source File: LineStatusMarkerPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private EditorFragmentComponent createEditorComponent(@Nullable FileType fileType, @javax.annotation.Nullable List<DiffFragment> wordDiff) {
  if (myRange.getType() == Range.INSERTED) return null;

  EditorEx uEditor = (EditorEx)EditorFactory.getInstance().createViewer(myTracker.getVcsDocument(), myTracker.getProject());
  uEditor.setColorsScheme(myEditor.getColorsScheme());

  DiffUtil.setEditorCodeStyle(myTracker.getProject(), uEditor, fileType);

  EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
  uEditor.setHighlighter(highlighterFactory.createEditorHighlighter(myTracker.getProject(), getFileName(myTracker.getDocument())));

  if (wordDiff != null) {
    int vcsStartShift = myTracker.getVcsTextRange(myRange).getStartOffset();
    for (DiffFragment fragment : wordDiff) {
      int vcsStart = vcsStartShift + fragment.getStartOffset1();
      int vcsEnd = vcsStartShift + fragment.getEndOffset1();
      TextDiffType type = getDiffType(fragment);

      DiffDrawUtil.createInlineHighlighter(uEditor, vcsStart, vcsEnd, type);
    }
  }

  EditorFragmentComponent fragmentComponent =
          EditorFragmentComponent.createEditorFragmentComponent(uEditor, myRange.getVcsLine1(), myRange.getVcsLine2(), false, false);

  EditorFactory.getInstance().releaseEditor(uEditor);

  return fragmentComponent;
}