Search in sources :

Example 81 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class VerticalRuler method doPaint1.

/**
 * Draws the vertical ruler w/o drawing the Canvas background. Uses
 * <code>ITextViewerExtension5</code> for its implementation. Will replace
 * <code>doPaint(GC)</code>.
 *
 * @param gc  the GC to draw into
 */
protected void doPaint1(GC gc) {
    if (fModel == null || fTextViewer == null)
        return;
    IAnnotationAccessExtension annotationAccessExtension = null;
    if (fAnnotationAccess instanceof IAnnotationAccessExtension)
        annotationAccessExtension = (IAnnotationAccessExtension) fAnnotationAccess;
    ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
    StyledText textWidget = fTextViewer.getTextWidget();
    fScrollPos = textWidget.getTopPixel();
    Point dimension = fCanvas.getSize();
    // draw Annotations
    Rectangle r = new Rectangle(0, 0, 0, 0);
    // loop at least once through layers.
    int maxLayer = 1;
    for (int layer = 0; layer < maxLayer; layer++) {
        Iterator<Annotation> iter = fModel.getAnnotationIterator();
        while (iter.hasNext()) {
            IAnnotationPresentation annotationPresentation = null;
            Annotation annotation = iter.next();
            int lay = IAnnotationAccessExtension.DEFAULT_LAYER;
            if (annotationAccessExtension != null)
                lay = annotationAccessExtension.getLayer(annotation);
            else if (annotation instanceof IAnnotationPresentation) {
                annotationPresentation = (IAnnotationPresentation) annotation;
                lay = annotationPresentation.getLayer();
            }
            // dynamically update layer maximum
            maxLayer = Math.max(maxLayer, lay + 1);
            if (// wrong layer: skip annotation
            lay != layer)
                continue;
            Position position = fModel.getPosition(annotation);
            if (position == null)
                continue;
            IRegion widgetRegion = extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength()));
            if (widgetRegion == null)
                continue;
            int startLine = extension.widgetLineOfWidgetOffset(widgetRegion.getOffset());
            if (startLine == -1)
                continue;
            int endLine = extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() - 1, 0));
            if (endLine == -1)
                continue;
            r.x = 0;
            r.y = JFaceTextUtil.computeLineHeight(textWidget, 0, startLine, startLine) - fScrollPos;
            r.width = dimension.x;
            int lines = endLine - startLine;
            r.height = JFaceTextUtil.computeLineHeight(textWidget, startLine, endLine + 1, lines + 1);
            if (// annotation within visible area
            r.y < dimension.y && annotationAccessExtension != null)
                annotationAccessExtension.paint(annotation, gc, fCanvas, r);
            else if (annotationPresentation != null)
                annotationPresentation.paint(gc, fCanvas, r);
        }
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Position(org.eclipse.jface.text.Position) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Rectangle(org.eclipse.swt.graphics.Rectangle) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 82 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class VisibleLinesTracker method track.

/**
 * Track the line height change of the {@link StyledText} of the given handler an call the given
 * handler.
 *
 * @param viewer the viewer to track
 * @param handler the handler to call when line height change.
 */
static void track(ITextViewer viewer, Consumer<StyledText> handler) {
    StyledText textWidget = viewer != null ? viewer.getTextWidget() : null;
    if (textWidget == null) {
        return;
    }
    VisibleLinesTracker tracker = (VisibleLinesTracker) textWidget.getData(DATA_KEY);
    if (tracker == null) {
        tracker = new VisibleLinesTracker(viewer);
        textWidget.setData(DATA_KEY, tracker);
    }
    tracker.addHandler(handler);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText)

Example 83 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class VisibleLinesTracker method paintControl.

@Override
public void paintControl(PaintEvent e) {
    StyledText textWidget = viewer.getTextWidget();
    // track if bottom line index or bottom line pixel changed.
    if (oldBottom == -1) {
        oldBottom = JFaceTextUtil.getPartialBottomIndex(viewer);
        oldBottomPixel = JFaceTextUtil.getLinePixel(textWidget, oldBottom);
        return;
    }
    int newBottom = JFaceTextUtil.getPartialBottomIndex(viewer);
    if (newBottom != oldBottom) {
        oldBottom = newBottom;
        oldBottomPixel = JFaceTextUtil.getLinePixel(textWidget, oldBottom);
        handlers.forEach(handler -> handler.accept(textWidget));
        return;
    }
    int newBottomPixel = JFaceTextUtil.getLinePixel(textWidget, newBottom);
    if (newBottomPixel != oldBottomPixel) {
        oldBottomPixel = newBottomPixel;
        handlers.forEach(handler -> handler.accept(textWidget));
        return;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText)

Example 84 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractInlinedAnnotation method redraw.

/**
 * Redraw the inlined annotation.
 */
public void redraw() {
    StyledText text = getTextWidget();
    InlinedAnnotationSupport.runInUIThread(text, (t) -> {
        Position pos = getPosition();
        int offset = pos.getOffset();
        ISourceViewer viewer = getViewer();
        if (viewer instanceof ITextViewerExtension5) {
            // adjust offset according folded content
            offset = ((ITextViewerExtension5) viewer).modelOffset2WidgetOffset(offset);
        }
        InlinedAnnotationDrawingStrategy.draw(this, null, t, offset, pos.getLength(), null);
    });
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Position(org.eclipse.jface.text.Position) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Example 85 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractInlinedAnnotation method onMouseOut.

/**
 * Called when mouse out the inlined annotation.
 *
 * @param e the mouse event
 */
public void onMouseOut(MouseEvent e) {
    StyledText styledText = (StyledText) e.widget;
    styledText.setCursor(null);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)329 Point (org.eclipse.swt.graphics.Point)102 GridData (org.eclipse.swt.layout.GridData)68 Composite (org.eclipse.swt.widgets.Composite)63 GridLayout (org.eclipse.swt.layout.GridLayout)62 Control (org.eclipse.swt.widgets.Control)46 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Label (org.eclipse.swt.widgets.Label)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Display (org.eclipse.swt.widgets.Display)30 Shell (org.eclipse.swt.widgets.Shell)30 Rectangle (org.eclipse.swt.graphics.Rectangle)27 Color (org.eclipse.swt.graphics.Color)25 FillLayout (org.eclipse.swt.layout.FillLayout)25 Button (org.eclipse.swt.widgets.Button)23 Text (org.eclipse.swt.widgets.Text)21 StyleRange (org.eclipse.swt.custom.StyleRange)20 Font (org.eclipse.swt.graphics.Font)20 Event (org.eclipse.swt.widgets.Event)20 Test (org.junit.Test)20