Search in sources :

Example 1 with FrameWrapper

use of com.intellij.openapi.ui.FrameWrapper 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 2 with FrameWrapper

use of com.intellij.openapi.ui.FrameWrapper in project intellij-community by JetBrains.

the class MergeTool method show.

public void show(DiffRequest data) {
    if (data instanceof MergeRequestImpl) {
        showDialog((MergeRequestImpl) data);
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(new Throwable("MergeTool - frame"));
    }
    FrameWrapper frameWrapper = new FrameWrapper(data.getProject(), data.getGroupKey());
    DiffViewer mergePanel = createMergeComponent(data, null, frameWrapper);
    frameWrapper.setComponent(mergePanel.getComponent());
    frameWrapper.setPreferredFocusedComponent(mergePanel.getPreferredFocusedComponent());
    frameWrapper.closeOnEsc();
    frameWrapper.setTitle(data.getWindowTitle());
    frameWrapper.setProject(data.getProject());
    frameWrapper.show();
}
Also used : DiffViewer(com.intellij.openapi.diff.DiffViewer) FrameWrapper(com.intellij.openapi.ui.FrameWrapper)

Example 3 with FrameWrapper

use of com.intellij.openapi.ui.FrameWrapper in project intellij-community by JetBrains.

the class FrameDiffTool method show.

public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = shouldOpenDialog(hints);
    if (shouldOpenDialog) {
        final DialogBuilder builder = new DialogBuilder(request.getProject());
        DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, builder.getWindow(), builder, true);
        if (diffPanel == null) {
            Disposer.dispose(builder);
            return;
        }
        final Runnable onOkRunnable = request.getOnOkRunnable();
        if (onOkRunnable != null) {
            builder.setOkOperation(() -> {
                builder.getDialogWrapper().close(0);
                onOkRunnable.run();
            });
        } else {
            builder.removeAllActions();
        }
        builder.setCenterPanel(diffPanel.getComponent());
        builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
        builder.setTitle(request.getWindowTitle());
        builder.setDimensionServiceKey(request.getGroupKey());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                builder.getDialogWrapper().close(0);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        showDiffDialog(builder, hints);
    } else {
        final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
        DiffPanelImpl diffPanel = createDiffPanelIfShouldShow(request, frameWrapper.getFrame(), frameWrapper, true);
        if (diffPanel == null) {
            Disposer.dispose(frameWrapper);
            return;
        }
        frameWrapper.setTitle(request.getWindowTitle());
        DiffUtil.initDiffFrame(diffPanel.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                frameWrapper.getFrame().dispose();
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        frameWrapper.show();
    }
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DiffPanelImpl(com.intellij.openapi.diff.impl.DiffPanelImpl) Collection(java.util.Collection) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) FrameWrapper(com.intellij.openapi.ui.FrameWrapper) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 4 with FrameWrapper

use of com.intellij.openapi.ui.FrameWrapper in project intellij-community by JetBrains.

the class MultiLevelDiffTool method show.

@Override
public void show(DiffRequest request) {
    Collection hints = request.getHints();
    boolean shouldOpenDialog = FrameDiffTool.shouldOpenDialog(hints);
    if (shouldOpenDialog) {
        final DialogBuilder builder = new DialogBuilder(request.getProject());
        final CompositeDiffPanel diffPanel = createPanel(request, builder.getWindow(), builder);
        if (diffPanel == null) {
            Disposer.dispose(builder);
            return;
        }
        final Runnable onOkRunnable = request.getOnOkRunnable();
        if (onOkRunnable != null) {
            builder.setOkOperation(() -> {
                builder.getDialogWrapper().close(0);
                onOkRunnable.run();
            });
        } else {
            builder.removeAllActions();
        }
        builder.setCenterPanel(diffPanel.getComponent());
        builder.setPreferredFocusComponent(diffPanel.getPreferredFocusedComponent());
        builder.setTitle(request.getWindowTitle());
        builder.setDimensionServiceKey(request.getGroupKey());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                builder.getDialogWrapper().close(0);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        diffPanel.setDiffRequest(request);
        FrameDiffTool.showDiffDialog(builder, hints);
    } else {
        final FrameWrapper frameWrapper = new FrameWrapper(request.getProject(), request.getGroupKey());
        final CompositeDiffPanel diffPanel = createPanel(request, frameWrapper.getFrame(), frameWrapper);
        if (diffPanel == null) {
            Disposer.dispose(frameWrapper);
            return;
        }
        frameWrapper.setTitle(request.getWindowTitle());
        diffPanel.setDiffRequest(request);
        DiffUtil.initDiffFrame(request.getProject(), frameWrapper, diffPanel, diffPanel.getComponent());
        new AnAction() {

            public void actionPerformed(final AnActionEvent e) {
                Disposer.dispose(frameWrapper);
            }
        }.registerCustomShortcutSet(new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts("CloseContent")), diffPanel.getComponent());
        frameWrapper.show();
    }
}
Also used : CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) FrameWrapper(com.intellij.openapi.ui.FrameWrapper) CompositeDiffPanel(com.intellij.openapi.diff.impl.CompositeDiffPanel) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

FrameWrapper (com.intellij.openapi.ui.FrameWrapper)4 AnAction (com.intellij.openapi.actionSystem.AnAction)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)2 DialogBuilder (com.intellij.openapi.ui.DialogBuilder)2 Disposable (com.intellij.openapi.Disposable)1 DiffViewer (com.intellij.openapi.diff.DiffViewer)1 CompositeDiffPanel (com.intellij.openapi.diff.impl.CompositeDiffPanel)1 DiffPanelImpl (com.intellij.openapi.diff.impl.DiffPanelImpl)1 LabeledEditor (com.intellij.openapi.diff.impl.util.LabeledEditor)1 Document (com.intellij.openapi.editor.Document)1 EditorFactory (com.intellij.openapi.editor.EditorFactory)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 AnswerPlaceholder (com.jetbrains.edu.learning.courseFormat.AnswerPlaceholder)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 EmptyBorder (javax.swing.border.EmptyBorder)1