Search in sources :

Example 1 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project smali by JesusFreke.

the class SmaliCodeFragmentFactoryTest method createEditor.

protected Editor createEditor(@NotNull VirtualFile file) {
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    Editor editor = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file, 0), false);
    DaemonCodeAnalyzer.getInstance(getProject()).restart();
    ((EditorImpl) editor).setCaretActive();
    return editor;
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) Editor(com.intellij.openapi.editor.Editor)

Example 2 with EditorImpl

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

the class EditorFragmentComponent method doInit.

private void doInit(Component anchorComponent, EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
    Document doc = editor.getDocument();
    final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength();
    boolean newRendering = editor instanceof EditorImpl;
    int widthAdjustment = newRendering ? EditorUtil.getSpaceWidth(Font.PLAIN, editor) : 0;
    final int textImageWidth = Math.min(editor.getMaxWidthInRange(doc.getLineStartOffset(startLine), endOffset) + widthAdjustment, getWidthLimit(editor));
    FoldingModelEx foldingModel = editor.getFoldingModel();
    boolean isFoldingEnabled = foldingModel.isFoldingEnabled();
    if (!showFolding) {
        foldingModel.setFoldingEnabled(false);
    }
    Point p1 = editor.logicalPositionToXY(new LogicalPosition(startLine, 0));
    Point p2 = editor.logicalPositionToXY(new LogicalPosition(Math.max(endLine, startLine + 1), 0));
    int y1 = p1.y;
    int y2 = p2.y;
    final int textImageHeight = y2 - y1 == 0 ? editor.getLineHeight() : y2 - y1;
    LOG.assertTrue(textImageHeight > 0, "Height: " + textImageHeight + "; startLine:" + startLine + "; endLine:" + endLine + "; p1:" + p1 + "; p2:" + p2);
    int savedScrollOffset = newRendering ? 0 : editor.getScrollingModel().getHorizontalScrollOffset();
    if (savedScrollOffset > 0) {
        editor.getScrollingModel().scrollHorizontally(0);
    }
    final BufferedImage textImage = UIUtil.createImage(anchorComponent == null ? editor.getContentComponent() : anchorComponent, textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
    Graphics textGraphics = textImage.getGraphics();
    EditorUIUtil.setupAntialiasing(textGraphics);
    final JComponent rowHeader;
    final BufferedImage markersImage;
    final int markersImageWidth;
    if (showGutter) {
        rowHeader = editor.getGutterComponentEx();
        markersImageWidth = Math.max(1, rowHeader.getWidth());
        markersImage = UIUtil.createImage(editor.getComponent(), markersImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
        Graphics markerGraphics = markersImage.getGraphics();
        EditorUIUtil.setupAntialiasing(markerGraphics);
        markerGraphics.translate(0, -y1);
        markerGraphics.setClip(0, y1, rowHeader.getWidth(), textImageHeight);
        markerGraphics.setColor(getBackgroundColor(editor));
        markerGraphics.fillRect(0, y1, rowHeader.getWidth(), textImageHeight);
        rowHeader.paint(markerGraphics);
    } else {
        markersImageWidth = 0;
        rowHeader = null;
        markersImage = null;
    }
    textGraphics.translate(0, -y1);
    textGraphics.setClip(0, y1, textImageWidth, textImageHeight);
    final boolean wasVisible = editor.setCaretVisible(false);
    editor.getContentComponent().paint(textGraphics);
    if (wasVisible) {
        editor.setCaretVisible(true);
    }
    if (!showFolding) {
        foldingModel.setFoldingEnabled(isFoldingEnabled);
    }
    if (savedScrollOffset > 0) {
        editor.getScrollingModel().scrollHorizontally(savedScrollOffset);
    }
    JComponent component = new JComponent() {

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(textImageWidth + markersImageWidth, textImageHeight);
        }

        @Override
        protected void paintComponent(Graphics graphics) {
            if (markersImage != null) {
                UIUtil.drawImage(graphics, markersImage, 0, 0, null);
                UIUtil.drawImage(graphics, textImage, rowHeader.getWidth(), 0, null);
            } else {
                UIUtil.drawImage(graphics, textImage, 0, 0, null);
            }
        }
    };
    setLayout(new BorderLayout());
    add(component);
    final Color borderColor = editor.getColorsScheme().getColor(EditorColors.SELECTED_TEARLINE_COLOR);
    Border outsideBorder = JBUI.Borders.customLine(borderColor, LINE_BORDER_THICKNESS);
    Border insideBorder = JBUI.Borders.empty(EMPTY_BORDER_THICKNESS, EMPTY_BORDER_THICKNESS);
    setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) Document(com.intellij.openapi.editor.Document) FoldingModelEx(com.intellij.openapi.editor.ex.FoldingModelEx) HintHint(com.intellij.ui.HintHint) LightweightHint(com.intellij.ui.LightweightHint) BufferedImage(java.awt.image.BufferedImage) Border(javax.swing.border.Border)

Example 3 with EditorImpl

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

the class SoftWrapHelper method isCaretAfterSoftWrap.

/**
   * Every soft wrap implies that multiple visual positions correspond to the same document offset. We can classify
   * such positions by the following criteria:
   * <pre>
   * <ul>
   *   <li>positions from visual line with soft wrap start;</li>
   *   <li>positions from visual line with soft wrap end;</li>
   * </ul>
   * </pre>
   * <p/>
   * This method allows to answer if caret offset of the given editor points to soft wrap and visual caret position
   * belongs to the visual line where soft wrap end is located.
   *
   * @return          <code>true</code> if caret offset of the given editor points to visual position that belongs to
   *                  visual line where soft wrap end is located
   */
public static boolean isCaretAfterSoftWrap(CaretImpl caret) {
    if (!caret.isUpToDate()) {
        return false;
    }
    EditorImpl editor = caret.getEditor();
    SoftWrapModel softWrapModel = editor.getSoftWrapModel();
    int offset = caret.getOffset();
    SoftWrap softWrap = softWrapModel.getSoftWrap(offset);
    if (softWrap == null) {
        return false;
    }
    VisualPosition afterWrapPosition = editor.offsetToVisualPosition(offset, false, false);
    VisualPosition caretPosition = caret.getVisualPosition();
    return caretPosition.line == afterWrapPosition.line && caretPosition.column <= afterWrapPosition.column;
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) SoftWrapModel(com.intellij.openapi.editor.SoftWrapModel) SoftWrap(com.intellij.openapi.editor.SoftWrap) VisualPosition(com.intellij.openapi.editor.VisualPosition)

Example 4 with EditorImpl

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

the class EditorTextField method createEditor.

protected EditorEx createEditor() {
    LOG.assertTrue(myDocument != null);
    final EditorFactory factory = EditorFactory.getInstance();
    EditorEx editor = (EditorEx) (myIsViewer ? factory.createViewer(myDocument, myProject) : factory.createEditor(myDocument, myProject));
    final EditorSettings settings = editor.getSettings();
    settings.setAdditionalLinesCount(0);
    settings.setAdditionalColumnsCount(1);
    settings.setRightMarginShown(false);
    settings.setRightMargin(-1);
    settings.setFoldingOutlineShown(false);
    settings.setLineNumbersShown(false);
    settings.setLineMarkerAreaShown(false);
    settings.setIndentGuidesShown(false);
    settings.setVirtualSpace(false);
    settings.setWheelFontChangeEnabled(false);
    settings.setAdditionalPageAtBottom(false);
    editor.setHorizontalScrollbarVisible(false);
    editor.setVerticalScrollbarVisible(false);
    editor.setCaretEnabled(!myIsViewer);
    settings.setLineCursorWidth(1);
    if (myProject != null) {
        PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(editor.getDocument());
        if (psiFile != null) {
            DaemonCodeAnalyzer.getInstance(myProject).setHighlightingEnabled(psiFile, !myIsViewer);
        }
    }
    if (myProject != null && myFileType != null) {
        editor.setHighlighter(EditorHighlighterFactory.getInstance().createEditorHighlighter(myProject, myFileType));
    }
    editor.getSettings().setCaretRowShown(false);
    editor.setOneLineMode(myOneLineMode);
    editor.getCaretModel().moveToOffset(myDocument.getTextLength());
    if (!shouldHaveBorder()) {
        editor.setBorder(null);
    }
    if (myIsViewer) {
        editor.getSelectionModel().removeSelection();
    } else if (myWholeTextSelected) {
        doSelectAll(editor);
        myWholeTextSelected = false;
    }
    editor.putUserData(SUPPLEMENTARY_KEY, myIsSupplementary);
    editor.getContentComponent().setFocusCycleRoot(false);
    editor.getContentComponent().addFocusListener(this);
    editor.setPlaceholder(myHintText);
    initOneLineMode(editor);
    if (myIsRendererWithSelection) {
        ((EditorImpl) editor).setPaintSelection(true);
        editor.getColorsScheme().setColor(EditorColors.SELECTION_BACKGROUND_COLOR, myRendererBg);
        editor.getColorsScheme().setColor(EditorColors.SELECTION_FOREGROUND_COLOR, myRendererFg);
        editor.getSelectionModel().setSelection(0, myDocument.getTextLength());
        editor.setBackgroundColor(myRendererBg);
    }
    for (EditorSettingsProvider provider : mySettingsProviders) {
        provider.customizeSettings(editor);
    }
    return editor;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) PsiFile(com.intellij.psi.PsiFile)

Example 5 with EditorImpl

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

the class EditorTextField method setupEditorFont.

private void setupEditorFont(final EditorEx editor) {
    if (myInheritSwingFont) {
        ((EditorImpl) editor).setUseEditorAntialiasing(false);
        editor.getColorsScheme().setEditorFontName(getFont().getFontName());
        editor.getColorsScheme().setEditorFontSize(getFont().getSize());
        return;
    }
    UISettings settings = UISettings.getInstance();
    if (settings.getPresentationMode())
        editor.setFontSize(settings.getPresentationModeFontSize());
}
Also used : UISettings(com.intellij.ide.ui.UISettings) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl)

Aggregations

EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)34 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)8 Editor (com.intellij.openapi.editor.Editor)7 LightweightHint (com.intellij.ui.LightweightHint)6 Document (com.intellij.openapi.editor.Document)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 EditorMouseFixture (com.intellij.testFramework.fixtures.EditorMouseFixture)3 NotNull (org.jetbrains.annotations.NotNull)3 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)2 SoftWrapModelImpl (com.intellij.openapi.editor.impl.SoftWrapModelImpl)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Project (com.intellij.openapi.project.Project)2 HintHint (com.intellij.ui.HintHint)2 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1