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();
}
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);
}
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);
}
}
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;
}
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);
}
}
Aggregations