Search in sources :

Example 51 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project webtools.sourceediting by eclipse.

the class HighlighterHyperlinkPresenter method highlightRegion.

private void highlightRegion(IRegion region) {
    if (region.equals(fActiveRegion))
        return;
    repairRepresentation();
    StyledText text = fTextViewer.getTextWidget();
    if (text == null || text.isDisposed())
        return;
    // Underline
    int offset = 0;
    int length = 0;
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        IRegion widgetRange = extension.modelRange2WidgetRange(region);
        if (widgetRange == null)
            return;
        offset = widgetRange.getOffset();
        length = widgetRange.getLength();
    } else {
        offset = region.getOffset() - fTextViewer.getVisibleRegion().getOffset();
        length = region.getLength();
    }
    // needs to clean background due to StructuredTextEditor's highlighter
    text.redrawRange(offset, length, true);
    // Invalidate region ==> apply text presentation
    fActiveRegion = region;
    if (fTextViewer instanceof ITextViewerExtension2)
        ((ITextViewerExtension2) fTextViewer).invalidateTextPresentation(region.getOffset(), region.getLength());
    else
        fTextViewer.invalidateTextPresentation();
}
Also used : ITextViewerExtension2(org.eclipse.jface.text.ITextViewerExtension2) StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 52 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project tdq-studio-se by Talend.

the class MouseClickListener method highlightRegion.

private void highlightRegion(ISourceViewer viewer, IRegion region) {
    if (region.equals(fActiveRegion))
        return;
    repairRepresentation();
    StyledText text = viewer.getTextWidget();
    if (text == null || text.isDisposed())
        return;
    // highlight region
    int offset = 0;
    int length = 0;
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        IRegion widgetRange = extension.modelRange2WidgetRange(region);
        if (widgetRange == null)
            return;
        offset = widgetRange.getOffset();
        length = widgetRange.getLength();
    } else {
        offset = region.getOffset() - viewer.getVisibleRegion().getOffset();
        length = region.getLength();
    }
    StyleRange oldStyleRange = text.getStyleRangeAtOffset(offset);
    Color foregroundColor = fColor;
    Color backgroundColor = oldStyleRange == null ? text.getBackground() : oldStyleRange.background;
    StyleRange styleRange = new StyleRange(offset, length, foregroundColor, backgroundColor);
    text.setStyleRange(styleRange);
    // underline
    text.redrawRange(offset, length, true);
    fActiveRegion = region;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) StyleRange(org.eclipse.swt.custom.StyleRange) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 53 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project tdq-studio-se by Talend.

the class MouseClickListener method getCurrentTextOffset.

private int getCurrentTextOffset(ISourceViewer viewer) {
    try {
        StyledText text = viewer.getTextWidget();
        if (text == null || text.isDisposed())
            return -1;
        Display display = text.getDisplay();
        Point absolutePosition = display.getCursorLocation();
        Point relativePosition = text.toControl(absolutePosition);
        int widgetOffset = text.getOffsetAtLocation(relativePosition);
        if (viewer instanceof ITextViewerExtension5) {
            ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
            return extension.widgetOffset2ModelOffset(widgetOffset);
        } else {
            return widgetOffset + viewer.getVisibleRegion().getOffset();
        }
    } catch (IllegalArgumentException e) {
        return -1;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Display(org.eclipse.swt.widgets.Display)

Example 54 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project tdq-studio-se by Talend.

the class MouseClickListener method paintControl.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
	 */
public void paintControl(PaintEvent event) {
    if (fActiveRegion == null)
        return;
    if (sourceViewer == null)
        return;
    StyledText text = sourceViewer.getTextWidget();
    if (text == null || text.isDisposed())
        return;
    int offset = 0;
    int length = 0;
    if (sourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
        IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
        if (widgetRange == null)
            return;
        offset = widgetRange.getOffset();
        length = widgetRange.getLength();
    } else {
        IRegion region = sourceViewer.getVisibleRegion();
        if (!includes(region, fActiveRegion))
            return;
        offset = fActiveRegion.getOffset() - region.getOffset();
        length = fActiveRegion.getLength();
    }
    // support for bidi
    Point minLocation = getMinimumLocation(text, offset, length);
    Point maxLocation = getMaximumLocation(text, offset, length);
    int x1 = minLocation.x;
    int x2 = minLocation.x + maxLocation.x - minLocation.x - 1;
    int y = minLocation.y + text.getLineHeight() - 1;
    GC gc = event.gc;
    if (fColor != null && !fColor.isDisposed())
        gc.setForeground(fColor);
    gc.drawLine(x1, y, x2, y);
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) Point(org.eclipse.swt.graphics.Point) GC(org.eclipse.swt.graphics.GC) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Example 55 with ITextViewerExtension5

use of org.eclipse.jface.text.ITextViewerExtension5 in project xtext-eclipse by eclipse.

the class RenameRefactoringPopup method computePopupLocation.

protected Point computePopupLocation() {
    if (popup == null || popup.isDisposed())
        return null;
    LinkedPosition position = renameLinkedMode.getCurrentLinkedPosition();
    if (position == null)
        return null;
    ISourceViewer viewer = editor.getInternalSourceViewer();
    ITextViewerExtension5 viewer5 = (ITextViewerExtension5) viewer;
    int widgetOffset = viewer5.modelOffset2WidgetOffset(position.offset);
    StyledText textWidget = viewer.getTextWidget();
    Point pos = textWidget.getLocationAtOffset(widgetOffset);
    Point pSize = getExtent();
    pSize.y += HAH + 1;
    pos.x -= HAO;
    pos.y += textWidget.getLineHeight(widgetOffset);
    Point dPos = textWidget.toDisplay(pos);
    Rectangle displayBounds = textWidget.getDisplay().getClientArea();
    Rectangle dPopupRect = Geometry.createRectangle(dPos, pSize);
    Geometry.moveInside(dPopupRect, displayBounds);
    return new Point(dPopupRect.x, dPopupRect.y);
}
Also used : LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension5(org.eclipse.jface.text.ITextViewerExtension5) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Point(org.eclipse.swt.graphics.Point)

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