Java Code Examples for com.intellij.openapi.editor.EditorFactory#createDocument()

The following examples show how to use com.intellij.openapi.editor.EditorFactory#createDocument() . 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: SettingsPanel.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
private void createUIComponents() {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    previewDocument = editorFactory.createDocument(EMPTY_TEXT);
    previewEditor = editorFactory.createEditor(previewDocument, null, JavaFileType.INSTANCE, true);

    final EditorSettings settings = previewEditor.getSettings();
    settings.setWhitespacesShown(true);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setLineNumbersShown(false);
    settings.setFoldingOutlineShown(false);
    settings.setRightMarginShown(false);
    settings.setVirtualSpace(false);
    settings.setWheelFontChangeEnabled(false);
    settings.setUseSoftWraps(false);
    settings.setAdditionalColumnsCount(0);
    settings.setAdditionalLinesCount(1);

    previewPanel = (JPanel) previewEditor.getComponent();
    previewPanel.setName(PREVIEW_PANEL_NAME);
    previewPanel.setPreferredSize(new Dimension(PREFERRED_PREVIEW_WIDTH, PREFERRED_PREVIEW_HEIGHT));
}
 
Example 2
Source File: NewClassDialog.java    From json2java4idea with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example 3
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 4
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 5
Source File: AnalyzeStacktraceUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static StacktraceEditorPanel createEditorPanel(Project project, @Nonnull Disposable parentDisposable) {
  EditorFactory editorFactory = EditorFactory.getInstance();
  Document document = editorFactory.createDocument("");
  Editor editor = editorFactory.createEditor(document, project);
  EditorSettings settings = editor.getSettings();
  settings.setFoldingOutlineShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setIndentGuidesShown(false);
  settings.setLineNumbersShown(false);
  settings.setRightMarginShown(false);

  StacktraceEditorPanel editorPanel = new StacktraceEditorPanel(project, editor);
  editorPanel.setPreferredSize(new Dimension(600, 400));
  Disposer.register(parentDisposable, editorPanel);
  return editorPanel;
}
 
Example 6
Source File: TemplateEditForm.java    From code-generator with Apache License 2.0 5 votes vote down vote up
private void initEditor(String template) {
    EditorFactory factory = EditorFactory.getInstance();
    Document velocityTemplate = factory.createDocument(template);
    editor = factory.createEditor(velocityTemplate, null, FileTypeManager.getInstance()
        .getFileTypeByExtension("vm"), false);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.weightx = 1;
    constraints.weighty = 1;
    editPanel.add(editor.getComponent(), constraints);
}
 
Example 7
Source File: QueryPanel.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
protected Editor createEditor() {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Document editorDocument = editorFactory.createDocument("");
    Editor editor = editorFactory.createEditor(editorDocument, project);
    fillEditorSettings(editor.getSettings());
    EditorEx editorEx = (EditorEx) editor;
    attachHighlighter(editorEx);

    return editor;
}
 
Example 8
Source File: CoverageLineMarkerRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showHint(final Editor editor, final Point point, final int lineNumber) {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);

  final LineData lineData = getLineData(lineNumber);
  final Editor uEditor;
  if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
    final EditorFactory factory = EditorFactory.getInstance();
    final Document doc = factory.createDocument(getReport(editor, lineNumber));
    doc.setReadOnly(true);
    uEditor = factory.createEditor(doc, editor.getProject());
    panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
  } else {
    uEditor = null;
  }


  final LightweightHint hint = new LightweightHint(panel){
    @Override
    public void hide() {
      if (uEditor != null) EditorFactory.getInstance().releaseEditor(uEditor);
      super.hide();

    }
  };
  HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point,
                                                   HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
 
Example 9
Source File: SimpleContent.java    From consulo with Apache License 2.0 5 votes vote down vote up
public SimpleContent(@Nonnull String text, FileType type, EditorFactory f) {
  myOriginalBytes = text.getBytes();
  myOriginalText = myLineSeparators.correctText(text);
  myDocument = f.createDocument(myOriginalText);
  setReadOnly(true);
  myType = type;
}
 
Example 10
Source File: TemplateCommentPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void initEditor() {
  if (myEditor == null) {
    myPreviewEditorPanel.removeAll();
    EditorFactory editorFactory = EditorFactory.getInstance();
    myDocument = editorFactory.createDocument("");

    myEditor = editorFactory.createEditor(myDocument, myProject, ObjectUtil.notNull(myFileType, PlainTextFileType.INSTANCE), true);
    CopyrightConfigurable.setupEditor(myEditor);

    myPreviewEditorPanel.add(myEditor.getComponent(), BorderLayout.CENTER);
  }
}
 
Example 11
Source File: CallerChooserBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Editor createEditor() {
  final EditorFactory editorFactory = EditorFactory.getInstance();
  final Document document = editorFactory.createDocument("");
  final Editor editor = editorFactory.createViewer(document, myProject);
  ((EditorEx)editor).setHighlighter(HighlighterFactory.createHighlighter(myProject, myFileName));
  return editor;
}