Search in sources :

Example 36 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class AbstractTemplatesPage method getOffset.

/**
 * Returns the document relative offset from the text widget relative point
 *
 * @param document the document
 * @param textWidget the text widget
 * @param point the point for which to get the offset
 * @return the offset
 * @throws BadLocationException if the document is accessed with an invalid line
 */
private int getOffset(IDocument document, StyledText textWidget, Point point) throws BadLocationException {
    int widgetCaret = fViewer.getTextWidget().getCaretOffset();
    if (fViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 ext = (ITextViewerExtension5) fViewer;
        int widgetOffset = textWidget.getOffsetAtPoint(point);
        int offset = widgetOffset != -1 ? ext.widgetOffset2ModelOffset(textWidget.getOffsetAtPoint(point)) : -1;
        if (offset == -1) {
            int docLineIndex = ext.widgetLine2ModelLine(textWidget.getLineIndex(point.y));
            String lineDelimiter = document.getLineDelimiter(docLineIndex);
            int delimLength = lineDelimiter == null ? 0 : lineDelimiter.length();
            return document.getLineOffset(docLineIndex) + document.getLineLength(docLineIndex) - delimLength;
        }
        return offset;
    }
    IRegion visible = fViewer.getVisibleRegion();
    return widgetCaret + visible.getOffset();
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 37 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class OverviewRuler method handleMouseScrolled.

/**
 * Handles mouse scrolls.
 *
 * @param event the mouse scrolled event
 */
private void handleMouseScrolled(MouseEvent event) {
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        StyledText textWidget = fTextViewer.getTextWidget();
        int topIndex = textWidget.getTopIndex();
        int newTopIndex = Math.max(0, topIndex - event.count);
        fTextViewer.setTopIndex(extension.widgetLine2ModelLine(newTopIndex));
    } else if (fTextViewer != null) {
        int topIndex = fTextViewer.getTopIndex();
        int newTopIndex = Math.max(0, topIndex - event.count);
        fTextViewer.setTopIndex(newTopIndex);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point)

Example 38 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class VerticalRuler method doubleBufferPaint.

/**
 * Double buffer drawing.
 *
 * @param dest the GC to draw into
 */
private void doubleBufferPaint(GC dest) {
    Point size = fCanvas.getSize();
    if (size.x <= 0 || size.y <= 0)
        return;
    if (fBuffer != null) {
        Rectangle r = fBuffer.getBounds();
        if (r.width != size.x || r.height != size.y) {
            fBuffer.dispose();
            fBuffer = null;
        }
    }
    if (fBuffer == null)
        fBuffer = new Image(fCanvas.getDisplay(), size.x, size.y);
    GC gc = new GC(fBuffer);
    gc.setFont(fTextViewer.getTextWidget().getFont());
    try {
        gc.setBackground(fCanvas.getBackground());
        gc.fillRectangle(0, 0, size.x, size.y);
        if (fTextViewer instanceof ITextViewerExtension5)
            doPaint1(gc);
        else
            doPaint(gc);
    } finally {
        gc.dispose();
    }
    dest.drawImage(fBuffer, 0, 0);
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC)

Example 39 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class VerticalRuler method widgetLine2ModelLine.

/**
 * Returns the line of the viewer's document that corresponds to the given widget line.
 *
 * @param viewer the viewer
 * @param widgetLine the widget line
 * @return the corresponding line of the viewer's document
 * @since 2.1
 */
protected static final int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        return extension.widgetLine2ModelLine(widgetLine);
    }
    try {
        IRegion r = viewer.getVisibleRegion();
        IDocument d = viewer.getDocument();
        return widgetLine += d.getLineOfOffset(r.getOffset());
    } catch (BadLocationException x) {
    }
    return widgetLine;
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 40 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project eclipse.platform.text by eclipse.

the class InlinedAnnotationSupport method getInlinedAnnotationAtLine.

/**
 * Returns the {@link AbstractInlinedAnnotation} from the given line index and null otherwise.
 *
 * @param viewer the source viewer
 * @param lineIndex the line index.
 * @return the {@link AbstractInlinedAnnotation} from the given line index and null otherwise.
 */
private static AbstractInlinedAnnotation getInlinedAnnotationAtLine(ISourceViewer viewer, int lineIndex) {
    if (viewer == null) {
        return null;
    }
    IAnnotationModel annotationModel = viewer.getAnnotationModel();
    if (annotationModel == null) {
        return null;
    }
    IDocument document = viewer.getDocument();
    int lineNumber = lineIndex;
    if (lineNumber > document.getNumberOfLines()) {
        return null;
    }
    try {
        if (viewer instanceof ITextViewerExtension5) {
            lineNumber = ((ITextViewerExtension5) viewer).widgetLine2ModelLine(lineNumber);
        }
        IRegion line = document.getLineInformation(lineNumber);
        return getInlinedAnnotationAtOffset(viewer, line.getOffset(), line.getLength());
    } catch (BadLocationException e) {
        return null;
    }
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)58 Point (org.eclipse.swt.graphics.Point)39 IRegion (org.eclipse.jface.text.IRegion)38 StyledText (org.eclipse.swt.custom.StyledText)23 Region (org.eclipse.jface.text.Region)17 BadLocationException (org.eclipse.jface.text.BadLocationException)14 IDocument (org.eclipse.jface.text.IDocument)14 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)7 ITextViewer (org.eclipse.jface.text.ITextViewer)6 Rectangle (org.eclipse.swt.graphics.Rectangle)6 Position (org.eclipse.jface.text.Position)5 GC (org.eclipse.swt.graphics.GC)5 StyleRange (org.eclipse.swt.custom.StyleRange)4 ITextViewerExtension2 (org.eclipse.jface.text.ITextViewerExtension2)3 ITypedRegion (org.eclipse.jface.text.ITypedRegion)3 ITextSelection (org.eclipse.jface.text.ITextSelection)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2 Display (org.eclipse.swt.widgets.Display)2 Entry (java.util.Map.Entry)1