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

The following examples show how to use com.intellij.openapi.editor.EditorFactory#createEditor() . 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: PromptConsole.java    From reasonml-idea-plugin with MIT License 6 votes vote down vote up
PromptConsole(@NotNull Project project, ConsoleViewImpl consoleView) {
    m_consoleView = consoleView;

    EditorFactory editorFactory = EditorFactory.getInstance();
    PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);

    Document outputDocument = ((EditorFactoryImpl) editorFactory).createDocument(true);
    UndoUtil.disableUndoFor(outputDocument);
    m_outputEditor = (EditorImpl) editorFactory.createViewer(outputDocument, project, CONSOLE);

    PsiFile file = fileFactory.createFileFromText("PromptConsoleDocument.ml", OclLanguage.INSTANCE, "");
    Document promptDocument = file.getViewProvider().getDocument();
    m_promptEditor = (EditorImpl) editorFactory.createEditor(promptDocument, project, CONSOLE);

    setupOutputEditor();
    setupPromptEditor();

    m_consoleView.print("(* ctrl+enter to send a command, ctrl+up/down to cycle through history *)\r\n", USER_INPUT);

    m_mainPanel.add(m_outputEditor.getComponent(), BorderLayout.CENTER);
    m_mainPanel.add(m_promptEditor.getComponent(), BorderLayout.SOUTH);
}
 
Example 2
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 3
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 4
Source File: TemplateConfigurable.java    From android-codegenerator-plugin-intellij with Apache License 2.0 6 votes vote down vote up
private Editor createEditorInPanel(String string) {
    EditorFactory editorFactory = EditorFactory.getInstance();
    Editor editor = editorFactory.createEditor(editorFactory.createDocument(string));

    EditorSettings editorSettings = editor.getSettings();
    editorSettings.setVirtualSpace(false);
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setIndentGuidesShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    editorSettings.setAdditionalColumnsCount(3);
    editorSettings.setAdditionalLinesCount(3);

    editor.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        public void documentChanged(DocumentEvent e) {
            onTextChanged();
        }
    });

    ((EditorEx) editor).setHighlighter(getEditorHighlighter());

    addEditorToPanel(editor);

    return editor;
}
 
Example 5
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 6
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 7
Source File: TemplateEditorUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 8
Source File: ConsoleExecutionEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
public ConsoleExecutionEditor(@Nonnull LanguageConsoleImpl.Helper helper) {
  myHelper = helper;
  EditorFactory editorFactory = EditorFactory.getInstance();
  myEditorDocument = helper.getDocument();
  myConsoleEditor = (EditorEx)editorFactory.createEditor(myEditorDocument, helper.project);
  myConsoleEditor.getScrollPane().getHorizontalScrollBar().setEnabled(false);
  myConsoleEditor.addFocusListener(myFocusListener);
  myConsoleEditor.getSettings().setVirtualSpace(false);
  myCurrentEditor = myConsoleEditor;
  myConsoleEditor.putUserData(SEARCH_DISABLED, true);

  myConsolePromptDecorator = new ConsolePromptDecorator(myConsoleEditor);
  myConsoleEditor.getGutter().registerTextAnnotation(myConsolePromptDecorator);

  myBusConnection = getProject().getMessageBus().connect();
  // action shortcuts are not yet registered
  ApplicationManager.getApplication().invokeLater(() -> installEditorFactoryListener(), getProject().getDisposed());
}
 
Example 9
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 10
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 11
Source File: Editors.java    From CodeMaker with Apache License 2.0 5 votes vote down vote up
public static Editor createSourceEditor(Project project, String language, String content, boolean readOnly) {
    final EditorFactory factory = EditorFactory.getInstance();
    final Editor editor = factory.createEditor(factory.createDocument(content), project, FileTypeManager.getInstance()
            .getFileTypeByExtension(language), readOnly);
    editor.getSettings().setRefrainFromScrolling(false);
    return editor;
}
 
Example 12
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 13
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 14
Source File: DiffUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static EditorEx createEditor(Document document, Project project, boolean isViewer, @Nullable FileType fileType) {
  EditorFactory factory = EditorFactory.getInstance();
  EditorEx editor = (EditorEx)(isViewer ? factory.createViewer(document, project) : factory.createEditor(document, project));
  editor.putUserData(DiffManagerImpl.EDITOR_IS_DIFF_KEY, Boolean.TRUE);
  editor.getGutterComponentEx().revalidateMarkup();

  if (fileType != null && project != null && !project.isDisposed()) {
    CodeStyleFacade codeStyleFacade = CodeStyleFacade.getInstance(project);
    editor.getSettings().setTabSize(codeStyleFacade.getTabSize(fileType));
    editor.getSettings().setUseTabCharacter(codeStyleFacade.useTabCharacter(fileType));
  }

  return editor;
}
 
Example 15
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);
  }
}