Search in sources :

Example 11 with ITextViewerExtension5

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

the class AnnotationRulerColumn method doPaint1.

/**
 * Draws the vertical ruler w/o drawing the Canvas background. Implementation based
 * on <code>ITextViewerExtension5</code>. Will replace <code>doPaint(GC)</code>.
 *
 * @param gc the GC to draw into
 */
protected void doPaint1(GC gc) {
    if (fModel == null || fCachedTextViewer == null)
        return;
    ITextViewerExtension5 extension = (ITextViewerExtension5) fCachedTextViewer;
    fScrollPos = fCachedTextWidget.getTopPixel();
    Point dimension = fCanvas.getSize();
    int vOffset = getInclusiveTopIndexStartOffset();
    int vLength = getExclusiveBottomIndexEndOffset() - vOffset;
    // draw Annotations
    Rectangle r = new Rectangle(0, 0, 0, 0);
    ReusableRegion range = new ReusableRegion();
    boolean isWrapActive = fCachedTextWidget.getWordWrap();
    int minLayer = Integer.MAX_VALUE, maxLayer = Integer.MIN_VALUE;
    fCachedAnnotations.clear();
    Iterator<Annotation> iter;
    if (fModel instanceof IAnnotationModelExtension2)
        iter = ((IAnnotationModelExtension2) fModel).getAnnotationIterator(vOffset, vLength + 1, true, true);
    else
        iter = fModel.getAnnotationIterator();
    while (iter.hasNext()) {
        Annotation annotation = iter.next();
        if (skip(annotation))
            continue;
        Position position = fModel.getPosition(annotation);
        if (position == null)
            continue;
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=217710
        int extendedVLength = position.getLength() == 0 ? vLength + 1 : vLength;
        if (!position.overlapsWith(vOffset, extendedVLength))
            continue;
        int lay = IAnnotationAccessExtension.DEFAULT_LAYER;
        if (fAnnotationAccessExtension != null)
            lay = fAnnotationAccessExtension.getLayer(annotation);
        minLayer = Math.min(minLayer, lay);
        maxLayer = Math.max(maxLayer, lay);
        fCachedAnnotations.add(new Tuple(annotation, position));
    }
    Collections.sort(fCachedAnnotations, fTupleComparator);
    for (int layer = minLayer; layer <= maxLayer; layer++) {
        for (int i = 0, n = fCachedAnnotations.size(); i < n; i++) {
            Tuple tuple = fCachedAnnotations.get(i);
            Annotation annotation = tuple.annotation;
            Position position = tuple.position;
            int lay = IAnnotationAccessExtension.DEFAULT_LAYER;
            if (fAnnotationAccessExtension != null)
                lay = fAnnotationAccessExtension.getLayer(annotation);
            if (// wrong layer: skip annotation
            lay != layer)
                continue;
            range.setOffset(position.getOffset());
            range.setLength(position.getLength());
            IRegion widgetRegion = extension.modelRange2WidgetRange(range);
            if (widgetRegion == null)
                continue;
            int offset = widgetRegion.getOffset();
            int startLine = extension.widgetLineOfWidgetOffset(offset);
            if (startLine == -1)
                continue;
            int length = Math.max(widgetRegion.getLength() - 1, 0);
            int endLine = extension.widgetLineOfWidgetOffset(offset + length);
            if (endLine == -1)
                continue;
            r.x = 0;
            r.width = dimension.x;
            int lines = endLine - startLine;
            if (startLine != endLine || !isWrapActive || length <= 0) {
                // line height for different lines includes wrapped line info already,
                // end we show annotations without offset info at very first line anyway
                r.height = JFaceTextUtil.computeLineHeight(fCachedTextWidget, startLine, endLine + 1, lines + 1);
                r.y = JFaceTextUtil.computeLineHeight(fCachedTextWidget, 0, startLine, startLine) - fScrollPos;
            } else {
                // annotate only the part of the line related to the given offset
                Rectangle textBounds = fCachedTextWidget.getTextBounds(offset, offset + length);
                r.height = textBounds.height;
                r.y = textBounds.y;
            }
            if (// annotation within visible area
            r.y < dimension.y && fAnnotationAccessExtension != null)
                fAnnotationAccessExtension.paint(annotation, gc, fCanvas, r);
        }
    }
    fCachedAnnotations.clear();
}
Also used : Position(org.eclipse.jface.text.Position) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 12 with ITextViewerExtension5

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

the class AnnotationRulerColumn 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(fCachedTextWidget.getFont());
    try {
        gc.setBackground(fCanvas.getBackground());
        gc.fillRectangle(0, 0, size.x, size.y);
        if (fCachedTextViewer 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 13 with ITextViewerExtension5

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

the class AnnotationRulerColumn method handleMouseScrolled.

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

Example 14 with ITextViewerExtension5

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

the class CompositeRuler method widgetLine2ModelLine.

/**
 * Returns the line in the given viewer's document that correspond to the given
 * line of the viewer's widget.
 *
 * @param viewer the viewer
 * @param widgetLine the widget line
 * @return the corresponding line 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 15 with ITextViewerExtension5

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

the class MatchingCharacterPainter method handleDrawRequest.

/**
 * Handles a redraw request.
 *
 * @param gc the GC to draw into or <code>null</code> to send a redraw request if necessary
 */
private void handleDrawRequest(GC gc) {
    if (fPairPosition.isDeleted)
        return;
    int offset = fPairPosition.getOffset();
    int length = fPairPosition.getLength();
    if (length < 1)
        return;
    if (fSourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fSourceViewer;
        IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
        if (widgetRange == null)
            return;
        try {
            // don't draw if the pair position is really hidden and widgetRange just
            // marks the coverage around it.
            IDocument doc = fSourceViewer.getDocument();
            int startLine = doc.getLineOfOffset(offset);
            int endLine = doc.getLineOfOffset(offset + length);
            if (extension.modelLine2WidgetLine(startLine) == -1 || extension.modelLine2WidgetLine(endLine) == -1)
                return;
        } catch (BadLocationException e) {
            return;
        }
        offset = widgetRange.getOffset();
        length = widgetRange.getLength();
    } else {
        IRegion region = fSourceViewer.getVisibleRegion();
        if (region.getOffset() > offset || region.getOffset() + region.getLength() < offset + length)
            return;
        offset -= region.getOffset();
    }
    if (fHighlightCharacterAtCaretLocation || (fHighlightEnclosingPeerCharacters && !fCharacterPresentAtCaretLocation)) {
        draw(gc, offset);
        draw(gc, offset + length - 1);
    } else {
        if (ICharacterPairMatcher.RIGHT == fAnchor)
            draw(gc, offset);
        else
            draw(gc, offset + length - 1);
    }
}
Also used : ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITextViewerExtension5 (org.eclipse.jface.text.ITextViewerExtension5)32 IRegion (org.eclipse.jface.text.IRegion)22 Point (org.eclipse.swt.graphics.Point)21 BadLocationException (org.eclipse.jface.text.BadLocationException)11 Region (org.eclipse.jface.text.Region)10 IDocument (org.eclipse.jface.text.IDocument)9 StyledText (org.eclipse.swt.custom.StyledText)9 Position (org.eclipse.jface.text.Position)5 Rectangle (org.eclipse.swt.graphics.Rectangle)5 ITextViewer (org.eclipse.jface.text.ITextViewer)2 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)2 GC (org.eclipse.swt.graphics.GC)2 Image (org.eclipse.swt.graphics.Image)2 Entry (java.util.Map.Entry)1 IFindReplaceTargetExtension (org.eclipse.jface.text.IFindReplaceTargetExtension)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ITextViewerExtension (org.eclipse.jface.text.ITextViewerExtension)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 ILineRange (org.eclipse.jface.text.source.ILineRange)1 LineRange (org.eclipse.jface.text.source.LineRange)1