Search in sources :

Example 1 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class IpnbEditorUtil method createPlainCodeEditor.

public static Editor createPlainCodeEditor(@NotNull final Project project, @NotNull final String text) {
    final EditorFactory editorFactory = EditorFactory.getInstance();
    assert editorFactory != null;
    final Document document = editorFactory.createDocument(text);
    EditorEx editor = (EditorEx) editorFactory.createEditor(document, project);
    setupEditor(editor);
    return editor;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document)

Example 2 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class StudyToolWindow method enterEditingMode.

public void enterEditingMode(VirtualFile taskFile, Project project) {
    final EditorFactory factory = EditorFactory.getInstance();
    Document document = FileDocumentManager.getInstance().getDocument(taskFile);
    if (document == null) {
        return;
    }
    WebBrowserManager.getInstance().setShowBrowserHover(false);
    final EditorEx createdEditor = (EditorEx) factory.createEditor(document, project, taskFile, false);
    Disposer.register(project, new Disposable() {

        public void dispose() {
            factory.releaseEditor(createdEditor);
        }
    });
    JComponent editorComponent = createdEditor.getComponent();
    editorComponent.setBorder(new EmptyBorder(10, 20, 0, 10));
    editorComponent.setBackground(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground());
    EditorSettings editorSettings = createdEditor.getSettings();
    editorSettings.setLineMarkerAreaShown(false);
    editorSettings.setLineNumbersShown(false);
    editorSettings.setFoldingOutlineShown(false);
    mySplitPane.setFirstComponent(editorComponent);
    mySplitPane.repaint();
    StudyTaskManager.getInstance(project).setToolWindowMode(StudyToolWindowMode.EDITING);
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorFactory(com.intellij.openapi.editor.EditorFactory) EditorSettings(com.intellij.openapi.editor.EditorSettings) EditorEx(com.intellij.openapi.editor.ex.EditorEx) Document(com.intellij.openapi.editor.Document) EmptyBorder(javax.swing.border.EmptyBorder)

Example 3 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class CCShowPreview method showPreviewDialog.

private static void showPreviewDialog(@NotNull Project project, @NotNull VirtualFile userFile, @NotNull TaskFile taskFile) {
    final FrameWrapper showPreviewFrame = new FrameWrapper(project);
    showPreviewFrame.setTitle(userFile.getName());
    LabeledEditor labeledEditor = new LabeledEditor(null);
    final EditorFactory factory = EditorFactory.getInstance();
    Document document = FileDocumentManager.getInstance().getDocument(userFile);
    if (document == null) {
        return;
    }
    final EditorEx createdEditor = (EditorEx) factory.createEditor(document, project, userFile, true);
    Disposer.register(project, new Disposable() {

        public void dispose() {
            factory.releaseEditor(createdEditor);
        }
    });
    for (AnswerPlaceholder answerPlaceholder : taskFile.getActivePlaceholders()) {
        if (answerPlaceholder.getActiveSubtaskInfo().isNeedInsertText()) {
            answerPlaceholder.setLength(answerPlaceholder.getTaskText().length());
        }
        Integer minIndex = Collections.min(answerPlaceholder.getSubtaskInfos().keySet());
        answerPlaceholder.setUseLength(minIndex >= answerPlaceholder.getActiveSubtaskIndex());
        EduAnswerPlaceholderPainter.drawAnswerPlaceholder(createdEditor, answerPlaceholder, JBColor.BLUE);
    }
    JPanel header = new JPanel();
    header.setLayout(new BoxLayout(header, BoxLayout.Y_AXIS));
    header.setBorder(new EmptyBorder(10, 10, 10, 10));
    header.add(new JLabel("Read-only preview."));
    String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
    header.add(new JLabel(String.format("Created %s.", timeStamp)));
    JComponent editorComponent = createdEditor.getComponent();
    labeledEditor.setComponent(editorComponent, header);
    createdEditor.setCaretVisible(false);
    createdEditor.setCaretEnabled(false);
    showPreviewFrame.setComponent(labeledEditor);
    showPreviewFrame.setSize(new Dimension(500, 500));
    if (!ApplicationManager.getApplication().isUnitTestMode()) {
        showPreviewFrame.show();
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) EditorFactory(com.intellij.openapi.editor.EditorFactory) AnswerPlaceholder(com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder) EditorEx(com.intellij.openapi.editor.ex.EditorEx) FrameWrapper(com.intellij.openapi.ui.FrameWrapper) Document(com.intellij.openapi.editor.Document) LabeledEditor(com.intellij.openapi.diff.impl.util.LabeledEditor) EmptyBorder(javax.swing.border.EmptyBorder) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class ReplacementPreviewDialog method createCenterPanel.

protected JComponent createCenterPanel() {
    JComponent centerPanel = new JPanel(new BorderLayout());
    PsiFile file = null;
    final StructuralSearchProfile profile = StructuralSearchUtil.getProfileByFileType(myFileType);
    if (profile != null) {
        file = profile.createCodeFragment(project, "", null);
    }
    if (file != null) {
        final Document document = PsiDocumentManager.getInstance(project).getDocument(file);
        replacement = UIUtil.createEditor(document, project, true, null);
        DaemonCodeAnalyzer.getInstance(project).setHighlightingEnabled(file, false);
    } else {
        final EditorFactory factory = EditorFactory.getInstance();
        final Document document = factory.createDocument("");
        replacement = factory.createEditor(document, project, myFileType, false);
    }
    centerPanel.add(BorderLayout.NORTH, new JLabel(SSRBundle.message("replacement.code")));
    centerPanel.add(BorderLayout.CENTER, replacement.getComponent());
    centerPanel.setMaximumSize(new Dimension(640, 480));
    return centerPanel;
}
Also used : EditorFactory(com.intellij.openapi.editor.EditorFactory) StructuralSearchProfile(com.intellij.structuralsearch.StructuralSearchProfile) PsiFile(com.intellij.psi.PsiFile) Document(com.intellij.openapi.editor.Document)

Example 5 with EditorFactory

use of com.intellij.openapi.editor.EditorFactory in project intellij-community by JetBrains.

the class ParsingTestCase method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    initApplication();
    ComponentAdapter component = getApplication().getPicoContainer().getComponentAdapter(ProgressManager.class.getName());
    if (component == null) {
        getApplication().getPicoContainer().registerComponent(new AbstractComponentAdapter(ProgressManager.class.getName(), Object.class) {

            @Override
            public Object getComponentInstance(PicoContainer container) throws PicoInitializationException, PicoIntrospectionException {
                return new ProgressManagerImpl();
            }

            @Override
            public void verify(PicoContainer container) throws PicoIntrospectionException {
            }
        });
    }
    Extensions.registerAreaClass("IDEA_PROJECT", null);
    myProject = new MockProjectEx(getTestRootDisposable());
    myPsiManager = new MockPsiManager(myProject);
    myFileFactory = new PsiFileFactoryImpl(myPsiManager);
    MutablePicoContainer appContainer = getApplication().getPicoContainer();
    registerComponentInstance(appContainer, MessageBus.class, getApplication().getMessageBus());
    registerComponentInstance(appContainer, SchemeManagerFactory.class, new MockSchemeManagerFactory());
    final MockEditorFactory editorFactory = new MockEditorFactory();
    registerComponentInstance(appContainer, EditorFactory.class, editorFactory);
    registerComponentInstance(appContainer, FileDocumentManager.class, new MockFileDocumentManagerImpl(charSequence -> editorFactory.createDocument(charSequence), FileDocumentManagerImpl.HARD_REF_TO_DOCUMENT_KEY));
    registerComponentInstance(appContainer, PsiDocumentManager.class, new MockPsiDocumentManager());
    registerApplicationService(PsiBuilderFactory.class, new PsiBuilderFactoryImpl());
    registerApplicationService(DefaultASTFactory.class, new DefaultASTFactoryImpl());
    registerApplicationService(ReferenceProvidersRegistry.class, new ReferenceProvidersRegistryImpl());
    myProject.registerService(CachedValuesManager.class, new CachedValuesManagerImpl(myProject, new PsiCachedValuesFactory(myPsiManager)));
    myProject.registerService(PsiManager.class, myPsiManager);
    myProject.registerService(StartupManager.class, new StartupManagerImpl(myProject));
    registerExtensionPoint(FileTypeFactory.FILE_TYPE_FACTORY_EP, FileTypeFactory.class);
    registerExtensionPoint(MetaLanguage.EP_NAME, MetaLanguage.class);
    for (ParserDefinition definition : myDefinitions) {
        addExplicitExtension(LanguageParserDefinitions.INSTANCE, definition.getFileNodeType().getLanguage(), definition);
    }
    if (myDefinitions.length > 0) {
        configureFromParserDefinition(myDefinitions[0], myFileExt);
    }
    // That's for reparse routines
    final PomModelImpl pomModel = new PomModelImpl(myProject);
    myProject.registerService(PomModel.class, pomModel);
    new TreeAspect(pomModel);
}
Also used : CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) NonNls(org.jetbrains.annotations.NonNls) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) org.picocontainer(org.picocontainer) BlockSupportImpl(com.intellij.psi.impl.source.text.BlockSupportImpl) PathManagerEx(com.intellij.openapi.application.ex.PathManagerEx) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) com.intellij.lang(com.intellij.lang) StartupManager(com.intellij.openapi.startup.StartupManager) PomModel(com.intellij.pom.PomModel) Disposer(com.intellij.openapi.util.Disposer) ReferenceProvidersRegistry(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry) FileUtil(com.intellij.openapi.util.io.FileUtil) TestCase(junit.framework.TestCase) DebugUtil(com.intellij.psi.impl.DebugUtil) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl) DiffLog(com.intellij.psi.impl.source.text.DiffLog) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) FileTypeManager(com.intellij.openapi.fileTypes.FileTypeManager) LoadTextUtil(com.intellij.openapi.fileEditor.impl.LoadTextUtil) FileTypeFactory(com.intellij.openapi.fileTypes.FileTypeFactory) SchemeManagerFactory(com.intellij.openapi.options.SchemeManagerFactory) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) Set(java.util.Set) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) TextRange(com.intellij.openapi.util.TextRange) FileDocumentManagerImpl(com.intellij.openapi.fileEditor.impl.FileDocumentManagerImpl) Disposable(com.intellij.openapi.Disposable) File(java.io.File) CachedValuesManager(com.intellij.psi.util.CachedValuesManager) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) EditorFactory(com.intellij.openapi.editor.EditorFactory) com.intellij.mock(com.intellij.mock) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) TreeAspect(com.intellij.pom.tree.TreeAspect) MessageBus(com.intellij.util.messages.MessageBus) StartupManagerImpl(com.intellij.ide.startup.impl.StartupManagerImpl) TreeAspect(com.intellij.pom.tree.TreeAspect) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ProgressManagerImpl(com.intellij.openapi.progress.impl.ProgressManagerImpl) CachedValuesManagerImpl(com.intellij.util.CachedValuesManagerImpl) PsiBuilderFactoryImpl(com.intellij.lang.impl.PsiBuilderFactoryImpl) PsiCachedValuesFactory(com.intellij.psi.impl.PsiCachedValuesFactory) PomModelImpl(com.intellij.pom.core.impl.PomModelImpl) AbstractComponentAdapter(org.picocontainer.defaults.AbstractComponentAdapter) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferenceProvidersRegistryImpl(com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistryImpl) PsiFileFactoryImpl(com.intellij.psi.impl.PsiFileFactoryImpl)

Aggregations

EditorFactory (com.intellij.openapi.editor.EditorFactory)22 Document (com.intellij.openapi.editor.Document)16 EditorEx (com.intellij.openapi.editor.ex.EditorEx)11 Editor (com.intellij.openapi.editor.Editor)10 Disposable (com.intellij.openapi.Disposable)5 EditorSettings (com.intellij.openapi.editor.EditorSettings)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NotNull (org.jetbrains.annotations.NotNull)4 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)2 EmptyBorder (javax.swing.border.EmptyBorder)2 CodeStyleFacade (com.intellij.codeStyle.CodeStyleFacade)1 CommanderPanel (com.intellij.ide.commander.CommanderPanel)1 XmlFileHighlighter (com.intellij.ide.highlighter.XmlFileHighlighter)1 StartupManagerImpl (com.intellij.ide.startup.impl.StartupManagerImpl)1 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)1 StructureViewModel (com.intellij.ide.structureView.StructureViewModel)1 TreeBasedStructureViewBuilder (com.intellij.ide.structureView.TreeBasedStructureViewBuilder)1 FileStructureDialog (com.intellij.ide.util.FileStructureDialog)1 com.intellij.lang (com.intellij.lang)1 Language (com.intellij.lang.Language)1