Java Code Examples for com.intellij.openapi.editor.EditorFactory

The following examples show how to use com.intellij.openapi.editor.EditorFactory. These examples are extracted from open source projects. 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 Project: lsp4intellij   Source File: IntellijLanguageClient.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initComponent() {
    try {
        // Adds project listener.
        ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC,
                new LSPProjectManagerListener());
        // Adds editor listener.
        EditorFactory.getInstance().addEditorFactoryListener(new LSPEditorListener(), this);
        // Adds VFS listener.
        VirtualFileManager.getInstance().addVirtualFileListener(new VFSListener());
        // Adds document event listener.
        ApplicationManager.getApplication().getMessageBus().connect().subscribe(AppTopics.FILE_DOCUMENT_SYNC,
                new LSPFileDocumentManagerListener());

        // in case if JVM forcefully exit.
        Runtime.getRuntime().addShutdownHook(new Thread(() -> projectToLanguageWrappers.values().stream()
                .flatMap(Collection::stream).filter(RUNNING).forEach(s -> s.stop(true))));

        LOG.info("Intellij Language Client initialized successfully");
    } catch (Exception e) {
        LOG.warn("Fatal error occurred when initializing Intellij language client.", e);
    }
}
 
Example 2
Source Project: reasonml-idea-plugin   Source File: PromptConsole.java    License: 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 3
Source Project: consulo   Source File: ParameterNameHintsConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
private static EditorTextField createEditorField(@Nonnull String text, @Nullable TextRange rangeToSelect) {
  Document document = EditorFactory.getInstance().createDocument(text);
  EditorTextField field = new EditorTextField(document, null, PlainTextFileType.INSTANCE, false, false);
  field.setPreferredSize(new Dimension(200, 350));
  field.addSettingsProvider(editor -> {
    editor.setVerticalScrollbarVisible(true);
    editor.setHorizontalScrollbarVisible(true);
    editor.getSettings().setAdditionalLinesCount(2);
    if (rangeToSelect != null) {
      editor.getCaretModel().moveToOffset(rangeToSelect.getStartOffset());
      editor.getScrollingModel().scrollVertically(document.getTextLength() - 1);
      editor.getSelectionModel().setSelection(rangeToSelect.getStartOffset(), rangeToSelect.getEndOffset());
    }
  });
  return field;
}
 
Example 4
Source Project: consulo   Source File: TemplateEditorUtil.java    License: 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 5
Source Project: json2java4idea   Source File: NewClassDialog.java    License: 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 6
public EditorPositionService(Project project) {
  super(project);

  eventMulticaster = EditorFactory.getInstance().getEventMulticaster();

  visibleAreaListener = (VisibleAreaEvent event) -> {
    invokeAll(listener -> listener.updateVisibleArea(event.getNewRectangle()), event.getEditor());
  };
  eventMulticaster.addVisibleAreaListener(visibleAreaListener);

  eventMulticaster.addCaretListener(new CaretListener() {
    @Override
    public void caretPositionChanged(@NotNull CaretEvent e) {
      invokeAll(listener -> listener.updateSelected(e.getCaret()), e.getEditor());
    }
  }, this);
  // TODO(jacobr): listen for when editors are disposed?
}
 
Example 7
Source Project: neovim-intellij-complete   Source File: Inspect.java    License: MIT License 6 votes vote down vote up
/**
 * Invokes action in intentionActionDescriptor on file found in path and writes the file to disk.
 *
 * @param path
 * @param fileContent
 * @param intentionActionDescriptor
 * @return
 */
public static String doFix(String path, @Nullable String fileContent, HighlightInfo.IntentionActionDescriptor intentionActionDescriptor) {
    UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
        PsiFile psiFile = EmbeditorUtil.findTargetFile(path);
        Project project = psiFile.getProject();

        PsiFile fileCopy = fileContent != null
                ? EmbeditorUtil.createDummyPsiFile(project, fileContent, psiFile)
                : EmbeditorUtil.createDummyPsiFile(project, psiFile.getText(), psiFile);

        VirtualFile targetVirtualFile =  psiFile.getVirtualFile();
        Document document = fileCopy.getViewProvider().getDocument();

        Editor editor = EditorFactory.getInstance().createEditor(document, project, targetVirtualFile, false);

        intentionActionDescriptor.getAction().invoke(project, editor, fileCopy);

        FileDocumentManager.getInstance().saveDocument(psiFile.getViewProvider().getDocument());
    });
    return null;
}
 
Example 8
Source Project: consulo   Source File: CodeFoldingManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void initFolding(@Nonnull final Editor editor) {
  final Document document = editor.getDocument();
  editor.getFoldingModel().runBatchFoldingOperation(() -> {
    DocumentFoldingInfo documentFoldingInfo = getDocumentFoldingInfo(document);
    Editor[] editors = EditorFactory.getInstance().getEditors(document, myProject);
    for (Editor otherEditor : editors) {
      if (otherEditor == editor || !isFoldingsInitializedInEditor(otherEditor)) continue;
      documentFoldingInfo.loadFromEditor(otherEditor);
      break;
    }
    documentFoldingInfo.setToEditor(editor);
    documentFoldingInfo.clear();

    editor.putUserData(FOLDING_STATE_KEY, Boolean.TRUE);
  });
}
 
Example 9
Source Project: power-mode-intellij-plugin   Source File: PowerMode.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void initComponent() {

    final EditorActionManager editorActionManager = EditorActionManager.getInstance();
    final EditorFactory editorFactory = EditorFactory.getInstance();
    particleContainerManager = new ParticleContainerManager();
    editorFactory.addEditorFactoryListener(particleContainerManager, new Disposable() {
        @Override
        public void dispose() {

        }
    });
    final TypedAction typedAction = editorActionManager.getTypedAction();
    final TypedActionHandler rawHandler = typedAction.getRawHandler();
    typedAction.setupRawHandler(new TypedActionHandler() {
        @Override
        public void execute(@NotNull final Editor editor, final char c, @NotNull final DataContext dataContext) {
            updateEditor(editor);
            rawHandler.execute(editor, c, dataContext);
        }
    });
}
 
Example 10
Source Project: consulo   Source File: ExportToFileUtil.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected JComponent createCenterPanel() {
  final Document document = ((EditorFactoryImpl)EditorFactory.getInstance()).createDocument(true);
  ((DocumentImpl)document).setAcceptSlashR(true);

  myTextArea = EditorFactory.getInstance().createEditor(document, myProject, PlainTextFileType.INSTANCE, true);
  final EditorSettings settings = myTextArea.getSettings();
  settings.setLineNumbersShown(false);
  settings.setLineMarkerAreaShown(false);
  settings.setFoldingOutlineShown(false);
  settings.setRightMarginShown(false);
  settings.setAdditionalLinesCount(0);
  settings.setAdditionalColumnsCount(0);
  settings.setAdditionalPageAtBottom(false);
  ((EditorEx)myTextArea).setBackgroundColor(UIUtil.getInactiveTextFieldBackgroundColor());
  return myTextArea.getComponent();
}
 
Example 11
Source Project: consulo   Source File: TogglePresentationModeAction.java    License: Apache License 2.0 6 votes vote down vote up
private static void tweakEditorAndFireUpdateUI(UISettings settings, boolean inPresentation) {
  EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
  int fontSize = inPresentation ? settings.PRESENTATION_MODE_FONT_SIZE : globalScheme.getEditorFontSize();
  if (inPresentation) {
    ourSavedConsoleFontSize = globalScheme.getConsoleFontSize();
    globalScheme.setConsoleFontSize(fontSize);
  }
  else {
    globalScheme.setConsoleFontSize(ourSavedConsoleFontSize);
  }
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    if (editor instanceof EditorEx) {
      ((EditorEx)editor).setFontSize(fontSize);
    }
  }
  UISettings.getInstance().fireUISettingsChanged();
  LafManager.getInstance().updateUI();
  EditorUtil.reinitSettings();
}
 
Example 12
private void setupEventListeners() {
    ApplicationManager.getApplication().invokeLater(new Runnable(){
        public void run() {

            // save file
            MessageBus bus = ApplicationManager.getApplication().getMessageBus();
            connection = bus.connect();
            connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener());

            // edit document
            EditorFactory.getInstance().getEventMulticaster().addDocumentListener(new CustomDocumentListener());

            // mouse press
            EditorFactory.getInstance().getEventMulticaster().addEditorMouseListener(new CustomEditorMouseListener());

            // scroll document
            EditorFactory.getInstance().getEventMulticaster().addVisibleAreaListener(new CustomVisibleAreaListener());
        }
    });
}
 
Example 13
Source Project: consulo   Source File: LineStatusTrackerManager.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void projectOpened() {
  StartupManager.getInstance(myProject).registerPreStartupActivity(new Runnable() {
    @Override
    public void run() {
      final MyFileStatusListener fileStatusListener = new MyFileStatusListener();
      final EditorFactoryListener editorFactoryListener = new MyEditorFactoryListener();
      final MyVirtualFileListener virtualFileListener = new MyVirtualFileListener();

      final FileStatusManager fsManager = FileStatusManager.getInstance(myProject);
      fsManager.addFileStatusListener(fileStatusListener, myDisposable);

      final EditorFactory editorFactory = EditorFactory.getInstance();
      editorFactory.addEditorFactoryListener(editorFactoryListener, myDisposable);

      final VirtualFileManager virtualFileManager = VirtualFileManager.getInstance();
      virtualFileManager.addVirtualFileListener(virtualFileListener, myDisposable);
    }
  });
}
 
Example 14
Source Project: consulo   Source File: LafManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
private static void fireUpdate() {

    UISettings.getInstance().fireUISettingsChanged();
    EditorFactory.getInstance().refreshAllEditors();

    Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
    for (Project openProject : openProjects) {
      FileStatusManager.getInstance(openProject).fileStatusesChanged();
      DaemonCodeAnalyzer.getInstance(openProject).restart();
    }
    for (IdeFrame frame : WindowManagerEx.getInstanceEx().getAllProjectFrames()) {
      if (frame instanceof IdeFrameEx) {
        ((IdeFrameEx)frame).updateView();
      }
    }
    ActionToolbarImpl.updateAllToolbarsImmediately();
  }
 
Example 15
Source Project: idea-gitignore   Source File: CreateUserTemplateAction.java    License: MIT License 6 votes vote down vote up
/**
 * Handles an action of adding new template.
 * Ignores action if selected file is not a {@link IgnoreFile} instance, otherwise shows GeneratorDialog.
 *
 * @param e action event
 */
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    final PsiFile file = e.getData(CommonDataKeys.PSI_FILE);

    if (project == null || !(file instanceof IgnoreFile)) {
        return;
    }

    String content = file.getText();
    Document document = file.getViewProvider().getDocument();
    if (document != null) {
        Editor[] editors = EditorFactory.getInstance().getEditors(document);
        if (editors.length > 0) {
            String selectedText = editors[0].getSelectionModel().getSelectedText();
            if (!StringUtil.isEmpty(selectedText)) {
                content = selectedText;
            }
        }
    }

    new UserTemplateDialog(project, content).show();
}
 
Example 16
Source Project: consulo   Source File: DocumentWindowImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public int injectedToHost(int offset) {
  int offsetInLeftFragment = injectedToHost(offset, true, false);
  int offsetInRightFragment = injectedToHost(offset, false, false);
  if (offsetInLeftFragment == offsetInRightFragment) return offsetInLeftFragment;

  // heuristics: return offset closest to the caret
  Editor[] editors = EditorFactory.getInstance().getEditors(getDelegate());
  Editor editor = editors.length == 0 ? null : editors[0];
  if (editor != null) {
    if (editor instanceof EditorWindow) editor = ((EditorWindow)editor).getDelegate();
    int caret = editor.getCaretModel().getOffset();
    return Math.abs(caret - offsetInLeftFragment) < Math.abs(caret - offsetInRightFragment) ? offsetInLeftFragment : offsetInRightFragment;
  }
  return offsetInLeftFragment;
}
 
Example 17
Source Project: consulo   Source File: TestEditorManagerImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void closeFile(@Nonnull final VirtualFile file) {
  Editor editor = myVirtualFile2Editor.remove(file);
  if (editor != null){
    TextEditorProvider editorProvider = TextEditorProvider.getInstance();
    editorProvider.disposeEditor(editorProvider.getTextEditor(editor));
    EditorFactory.getInstance().releaseEditor(editor);
  }
  if (Comparing.equal(file, myActiveFile)) {
    myActiveFile = null;
  }

  modifyTabWell(new Runnable() {
    @Override
    public void run() {
      myTestEditorSplitter.closeFile(file);
    }
  });
}
 
Example 18
Source Project: consulo   Source File: ContentChooser.java    License: Apache License 2.0 6 votes vote down vote up
private void updateViewerForSelection() {
  if (myAllContents.isEmpty()) return;
  String fullString = getSelectedText();

  if (myViewer != null) {
    EditorFactory.getInstance().releaseEditor(myViewer);
  }

  if (myUseIdeaEditor) {
    myViewer = createIdeaEditor(fullString);
    JComponent component = myViewer.getComponent();
    component.setPreferredSize(new Dimension(300, 500));
    mySplitter.setSecondComponent(component);
  } else {
    final JTextArea textArea = new JTextArea(fullString);
    textArea.setRows(3);
    textArea.setWrapStyleWord(true);
    textArea.setLineWrap(true);
    textArea.setSelectionStart(0);
    textArea.setSelectionEnd(textArea.getText().length());
    textArea.setEditable(false);
    mySplitter.setSecondComponent(ScrollPaneFactory.createScrollPane(textArea));
  }
  mySplitter.revalidate();
}
 
Example 19
Source Project: consulo   Source File: BinaryContent.java    License: Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings({"EmptyCatchBlock"})
@Nullable
public Document getDocument() {
  if (myDocument == null) {
    if (isBinary()) return null;

    String text = null;
    try {
      Charset charset = ObjectUtil
              .notNull(myCharset, EncodingProjectManager.getInstance(myProject).getDefaultCharset());
      text = CharsetToolkit.bytesToString(myBytes, charset);
    }
    catch (IllegalCharsetNameException e) {
    }

    //  Still NULL? only if not supported or an exception was thrown.
    //  Decode a string using the truly default encoding.
    if (text == null) text = new String(myBytes);
    text = LineTokenizer.correctLineSeparators(text);

    myDocument = EditorFactory.getInstance().createDocument(text);
    myDocument.setReadOnly(true);
  }
  return myDocument;
}
 
Example 20
Source Project: EasyCode   Source File: TemplateEditor.java    License: MIT License 5 votes vote down vote up
/**
 * 关闭回调方法
 */
public void onClose() {
    if (editor != null) {
        EditorFactory.getInstance().releaseEditor(editor);
    }
    editor = null;
}
 
Example 21
/**
 * Invoked when the application is started, then register the {@link HighlightBracketPairApplicationComponent}
 * component to the editor events,  and check if the plugin is updated.
 */
@Override
public void initComponent() {
    editorHighlightEditorComponentMap = new HashMap<>();
    EditorFactory.getInstance().
            addEditorFactoryListener(this, ApplicationManager.getApplication());

    final HighlightBracketPairSettings settings = HighlightBracketPairSettings.getInstance();
    updated = !getPlugin().getVersion().equals(settings.getVersion());
    if (updated) {
        settings.setVersion(getPlugin().getVersion());
    }
}
 
Example 22
Source Project: consulo   Source File: EditorLastActionTrackerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
EditorLastActionTrackerImpl(Application application, ActionManager actionManager, EditorFactory editorFactory) {
  myActionManager = actionManager;
  application.getMessageBus().connect(this).subscribe(AnActionListener.TOPIC, this);
  myEditorEventMulticaster = editorFactory.getEventMulticaster();
  myEditorEventMulticaster.addEditorMouseListener(this);
}
 
Example 23
Source Project: consulo   Source File: FileStatusManagerImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public FileStatusManagerImpl(Project project, StartupManager startupManager, @SuppressWarnings("UnusedParameters") DirectoryIndex makeSureIndexIsInitializedFirst) {
  myProject = project;

  project.getMessageBus().connect().subscribe(EditorColorsManager.TOPIC, new EditorColorsListener() {
    @Override
    public void globalSchemeChange(EditorColorsScheme scheme) {
      fileStatusesChanged();
    }
  });

  if (project.isDefault()) return;

  startupManager.registerPreStartupActivity(() -> {
    DocumentAdapter documentListener = new DocumentAdapter() {
      @Override
      public void documentChanged(DocumentEvent event) {
        if (event.getOldLength() == 0 && event.getNewLength() == 0) return;
        VirtualFile file = FileDocumentManager.getInstance().getFile(event.getDocument());
        if (file != null) {
          refreshFileStatusFromDocument(file, event.getDocument());
        }
      }
    };

    final EditorFactory factory = EditorFactory.getInstance();
    if (factory != null) {
      factory.getEventMulticaster().addDocumentListener(documentListener, myProject);
    }
  });
  startupManager.registerPostStartupActivity(new DumbAwareRunnable() {
    @Override
    public void run() {
      fileStatusesChanged();
    }
  });
}
 
Example 24
Source Project: json2java4idea   Source File: SettingsPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void dispose() {
    Collections.list(styleGroup.getElements()).forEach(button -> button.removeActionListener(this));
    classNamePrefixField.getDocument().removeDocumentListener(this);
    classNameSuffixField.getDocument().removeDocumentListener(this);
    generatedAnnotationCheckBox.removeActionListener(this);
    suppressWarningsAnnotationCheckBox.removeActionListener(this);

    if (previewEditor == null || previewEditor.isDisposed()) {
        return;
    }
    EditorFactory.getInstance().releaseEditor(previewEditor);
}
 
Example 25
Source Project: json2java4idea   Source File: NewClassDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void dispose() {
    if (jsonEditor != null && !jsonEditor.isDisposed()) {
        EditorFactory.getInstance().releaseEditor(jsonEditor);
    }
    super.dispose();
}
 
Example 26
Source Project: json2java4idea   Source File: SettingsPanelTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void disposeShouldReleaseEditor() throws Exception {
    // exercise
    application.invokeAndWait(() -> underTest.dispose());

    // verify
    final Editor[] actual = EditorFactory.getInstance().getAllEditors();
    assertThat(actual)
            .isEmpty();
}
 
Example 27
Source Project: consulo   Source File: EditorOptionDescription.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void fireUpdated() {
  Project[] projects = ProjectManager.getInstance().getOpenProjects();
  for (Project project : projects) {
    DaemonCodeAnalyzer.getInstance(project).settingsChanged();
  }

  EditorFactory.getInstance().refreshAllEditors();
}
 
Example 28
Source Project: consulo   Source File: ShowTextPopupHyperlinkInfo.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void navigate(Project project) {
  Application.get().invokeLater(() -> {
    Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(myText));
    EditorTextField textField = new EditorTextField(document, project, PlainTextFileType.INSTANCE, true, false) {
      @Override
      protected EditorEx createEditor() {
        EditorEx editor = super.createEditor();
        editor.getScrollPane().setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        editor.getScrollPane().setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        editor.getSettings().setUseSoftWraps(true);
        return editor;
      }
    };

    Window frame = TargetAWT.to(WindowManager.getInstance().getWindow(project));
    if(frame != null) {
      Dimension size = frame.getSize();
      if(size != null) {
        textField.setPreferredSize(new Dimension(size.width / 2, size.height / 2));
      }
    }

    JBPopupFactory.getInstance()
            .createComponentPopupBuilder(textField, textField)
            .setTitle(myTitle)
            .setResizable(true)
            .setMovable(true)
            .setRequestFocus(true)
            .createPopup()
            .showCenteredInCurrentWindow(project);
  });
}
 
Example 29
Source Project: consulo   Source File: VisibleEditorsTracker.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void commandStarted(CommandEvent event) {
  for (Editor editor : EditorFactory.getInstance().getAllEditors()) {
    if (editor.getComponent().isShowing()) {
      myEditorsVisibleOnCommandStart.add(editor);
    }

    ((ScrollingModelImpl)editor.getScrollingModel()).finishAnimation();
    myCurrentCommandStart = System.currentTimeMillis();
  }
}
 
Example 30
Source Project: consulo   Source File: TextViewer.java    License: Apache License 2.0 5 votes vote down vote up
private static Document createDocument(@Nonnull String initialText) {
  final Document document = EditorFactory.getInstance().createDocument(initialText);
  if (document instanceof DocumentImpl) {
    ((DocumentImpl)document).setAcceptSlashR(true);
  }
  return document;
}