Search in sources :

Example 11 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx 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 12 with EditorEx

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

the class EditorFragmentComponent method showEditorFragmentHint.

@Nullable
public static LightweightHint showEditorFragmentHint(Editor editor, TextRange range, boolean showFolding, boolean hideByAnyKey) {
    if (!(editor instanceof EditorEx))
        return null;
    JRootPane rootPane = editor.getComponent().getRootPane();
    if (rootPane == null)
        return null;
    JLayeredPane layeredPane = rootPane.getLayeredPane();
    int lineHeight = editor.getLineHeight();
    int overhang = editor.getScrollingModel().getVisibleArea().y - editor.logicalPositionToXY(editor.offsetToLogicalPosition(range.getEndOffset())).y;
    int yRelative = overhang > 0 && overhang < lineHeight ? lineHeight - overhang + JBUI.scale(LINE_BORDER_THICKNESS + EMPTY_BORDER_THICKNESS) : 0;
    Point point = SwingUtilities.convertPoint(((EditorEx) editor).getScrollPane().getViewport(), -2, yRelative, layeredPane);
    return showEditorFragmentHintAt(editor, range, point.y, true, showFolding, hideByAnyKey, true, false);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with EditorEx

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

the class TogglePresentationModeAction method tweakEditorAndFireUpdateUI.

private static void tweakEditorAndFireUpdateUI(UISettings settings, boolean inPresentation) {
    EditorColorsScheme globalScheme = EditorColorsManager.getInstance().getGlobalScheme();
    int fontSize = inPresentation ? settings.getPresentationModeFontSize() : 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();
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) Editor(com.intellij.openapi.editor.Editor)

Example 14 with EditorEx

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

the class DiffLineMarkerRenderer method paint.

@Override
public void paint(Editor editor, Graphics g, Rectangle range) {
    Color color = myDiffType.getPolygonColor(editor);
    if (color == null) {
        return;
    }
    EditorGutterComponentEx gutter = ((EditorEx) editor).getGutterComponentEx();
    Graphics2D g2 = (Graphics2D) g;
    int x = 0;
    int y = range.y;
    int width = gutter.getWidth();
    int height = range.height;
    if (!myDiffType.isApplied()) {
        if (height > 2) {
            g.setColor(color);
            g.fillRect(x, y, width, height);
            DiffUtil.drawDoubleShadowedLine(g2, x, x + width, y - 1, color);
            DiffUtil.drawDoubleShadowedLine(g2, x, x + width, y + height - 1, color);
        } else {
            // insertion or deletion, when a range is null. matching the text highlighter which is a 2 pixel line
            DiffUtil.drawDoubleShadowedLine(g2, x, x + width, y - 1, color);
        }
    } else {
        DiffUtil.drawBoldDottedFramingLines(g2, x, x + width, y - 1, y + height - 1, color);
    }
}
Also used : EditorGutterComponentEx(com.intellij.openapi.editor.ex.EditorGutterComponentEx) EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 15 with EditorEx

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

the class DiffSideView method applyHighlighter.

private void applyHighlighter() {
    EditorEx editor = myEditorSource.getEditor();
    if (editor == null)
        return;
    EditorHighlighter highlighter = myHighlighterFactory.createHighlighter();
    if (highlighter != null)
        editor.setHighlighter(highlighter);
    editor.getSettings().setCaretRowShown(false);
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Aggregations

EditorEx (com.intellij.openapi.editor.ex.EditorEx)164 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)36 Editor (com.intellij.openapi.editor.Editor)35 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)33 Document (com.intellij.openapi.editor.Document)29 NotNull (org.jetbrains.annotations.NotNull)26 IElementType (com.intellij.psi.tree.IElementType)14 Nullable (org.jetbrains.annotations.Nullable)13 Project (com.intellij.openapi.project.Project)12 PsiFile (com.intellij.psi.PsiFile)12 EditorFactory (com.intellij.openapi.editor.EditorFactory)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 TextRange (com.intellij.openapi.util.TextRange)10 FileType (com.intellij.openapi.fileTypes.FileType)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)7 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)6 Language (com.intellij.lang.Language)6 CaretModel (com.intellij.openapi.editor.CaretModel)6 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)6