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;
}
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);
}
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();
}
}
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;
}
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);
}
Aggregations