Java 类org.eclipse.jface.text.ITextViewerExtension5 实例源码

项目:fluentmark    文件:FluentMkEditor.java   
/**
 * Computes and returns the source reference that includes the caret and serves as provider for the
 * outline pageModel selection and the editor range indication.
 *
 * @return the computed source reference
 */
public ISourceReference computeHighlightRange() {
    ISourceViewer sourceViewer = getSourceViewer();
    if (sourceViewer == null) return null;

    StyledText styledText = sourceViewer.getTextWidget();
    if (styledText == null) return null;

    int caret = 0;
    if (sourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
        caret = extension.widgetOffset2ModelOffset(styledText.getSelection().x);
    } else {
        int offset = sourceViewer.getVisibleRegion().getOffset();
        caret = offset + styledText.getSelection().x;
    }

    PagePart part = getPagePartAt(caret, false);
    return (ISourceReference) part;
}
项目:bts    文件:RenameRefactoringPopup.java   
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);
}
项目:velocity-edit    文件:VelocityEditor.java   
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;
    }
}
项目:APICloud-Studio    文件:WhitespaceCharacterPainter.java   
/**
 * Convert a document offset to the corresponding widget offset.
 * 
 * @param documentOffset
 * @return widget offset
 */
private int getWidgetOffset(int documentOffset)
{
    if (fTextViewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        return extension.modelOffset2WidgetOffset(documentOffset);
    }
    IRegion visible = fTextViewer.getVisibleRegion();
    int widgetOffset = documentOffset - visible.getOffset();
    if (widgetOffset > visible.getLength())
    {
        return -1;
    }
    return widgetOffset;
}
项目:APICloud-Studio    文件:QuickOutlinePopupDialog.java   
/**
 * {@inheritDoc}
 */
@Override
protected Control createDialogArea(Composite parent)
{
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().applyTo(composite);

    fPage.createControl(composite);

    // Try to select the current item we're on in editor in the outline
    ISourceViewer viewer = fEditor.getISourceViewer();
    int offset = viewer.getTextWidget().getCaretOffset();
    if (viewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 v5 = (ITextViewerExtension5) viewer;
        offset = v5.widgetOffset2ModelOffset(offset);
    }
    if (offset != -1)
    {
        fPage.revealPosition(offset);
    }
    GridDataFactory.fillDefaults().hint(320, 240).applyTo(composite);

    return composite;
}
项目:APICloud-Studio    文件:AbstractThemeableEditor.java   
public int getCaretOffset()
{
    ISourceViewer sourceViewer = getSourceViewer();
    if (sourceViewer == null)
    {
        return -1;
    }
    StyledText styledText = sourceViewer.getTextWidget();
    if (styledText == null)
    {
        return -1;
    }

    if (sourceViewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
        return extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
    }
    int offset = sourceViewer.getVisibleRegion().getOffset();
    return offset + styledText.getCaretOffset();
}
项目:tm4e    文件:TMPresentationReconciler.java   
/**
 * Translates the given text event into the corresponding range of the viewer's
 * document.
 * 
 * @param e
 *            the text event
 * @return the widget region corresponding the region of the given event or
 *         <code>null</code> if none
 * @since 2.1
 */
private IRegion widgetRegion2ModelRegion(TextEvent e) {

    String text = e.getText();
    int length = text == null ? 0 : text.length();

    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        return extension.widgetRange2ModelRange(new Region(e.getOffset(), length));
    }

    IRegion visible = viewer.getVisibleRegion();
    IRegion region = new Region(e.getOffset() + visible.getOffset(), length);
    return region;
}
项目:ftc    文件:TweakedLinkedModeUI.java   
private void select() {
    ITextViewer viewer = fCurrentTarget.getViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension5 = (ITextViewerExtension5) viewer;
        extension5.exposeModelRange(new Region(fFramePosition.offset, fFramePosition.length));
    } else if (!viewer.overlapsWithVisibleRegion(fFramePosition.offset, fFramePosition.length)) {
        viewer.resetVisibleRegion();
    }
    viewer.revealRange(fFramePosition.offset, fFramePosition.length);
    viewer.setSelectedRange(fFramePosition.offset, fFramePosition.length);
}
项目:typescript.java    文件:TypeScriptEditor.java   
@Override
public int getCursorOffset() {
    ISourceViewer sourceViewer = getSourceViewer();
    StyledText styledText = sourceViewer.getTextWidget();
    if (styledText == null) {
        return 0;
    }
    if (sourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
        return extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
    } else {
        int offset = sourceViewer.getVisibleRegion().getOffset();
        return offset + styledText.getCaretOffset();
    }
}
项目:bts    文件:TextViewerMoveLinesAction.java   
/**
 * Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>.
 * As a special case, a selection is considered contained even if it extends over the visible
 * region, but the extension stays on a partially contained line and contains only white space.
 *
 * @param selection the selection to be checked
 * @param viewer the viewer displaying a visible region of <code>selection</code>'s document.
 * @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise.
 */
private boolean containedByVisibleRegion(ITextSelection selection, ITextViewer viewer) {
    int min= selection.getOffset();
    int max= min + selection.getLength();
    IDocument document= viewer.getDocument();

    IRegion visible;
    if (viewer instanceof ITextViewerExtension5)
        visible= ((ITextViewerExtension5) viewer).getModelCoverage();
    else
        visible= viewer.getVisibleRegion();

    int visOffset= visible.getOffset();
    try {
        if (visOffset > min) {
            if (document.getLineOfOffset(visOffset) != selection.getStartLine())
                return false;
            if (!isWhitespace(document.get(min, visOffset - min))) {
                return false;
            }
        }
        int visEnd= visOffset + visible.getLength();
        if (visEnd < max) {
            if (document.getLineOfOffset(visEnd) != selection.getEndLine())
                return false;
            if (!isWhitespace(document.get(visEnd, max - visEnd))) {
                return false;
            }
        }
        return true;
    } catch (BadLocationException e) {
    }
    return false;
}
项目:bts    文件:MarkRegionTargetWithoutStatusline.java   
/**
 * Tells whether the given offset is visible in the given text viewer.
 * 
 * @param viewer
 *            the text viewer
 * @param offset
 *            the offset to check
 * @return <code>true</code> if the given offset is visible in the given text viewer
 */
protected boolean isVisible(ITextViewer viewer, int offset) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        return extension.modelOffset2WidgetOffset(offset) >= 0;
    }
    IRegion region = viewer.getVisibleRegion();
    int vOffset = region.getOffset();
    return (vOffset <= offset && offset <= vOffset + region.getLength());
}
项目:bts    文件:TextViewerJoinLinesAction.java   
/**
 * Adjusts the highlight range so that at least the specified range
 * is highlighted.
 * <p>
 * Subclasses may re-implement this method.</p>
 * @param viewer 
 *
 * @param offset the offset of the range which at least should be highlighted
 * @param length the length of the range which at least should be highlighted
 */
protected void adjustHighlightRange(ITextViewer viewer, int offset, int length) {
    if (viewer == null)
        return;

    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
        extension.exposeModelRange(new Region(offset, length));
    } else if (!isVisible(viewer, offset, length)) {
        viewer.resetVisibleRegion();
    }
}
项目:bts    文件:TextViewerJoinLinesAction.java   
protected boolean isVisible(ITextViewer viewer, int offset, int length) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
        IRegion overlap= extension.modelRange2WidgetRange(new Region(offset, length));
        return overlap != null;
    }
    return viewer.overlapsWithVisibleRegion(offset, length);
}
项目:velocity-edit    文件:VelocityEditor.java   
private void repairRepresentation(boolean redrawAll)
{
    if (fActiveRegion == null) { return; }
    ISourceViewer viewer = getSourceViewer();
    if (viewer != null)
    {
        resetCursor(viewer);
        int offset = fActiveRegion.getOffset();
        int length = fActiveRegion.getLength();
        // remove style
        if (!redrawAll && viewer instanceof ITextViewerExtension2)
        {
            ((ITextViewerExtension2) viewer).invalidateTextPresentation(offset, length);
        } else
        {
            viewer.invalidateTextPresentation();
        }
        // remove underline
        if (viewer instanceof ITextViewerExtension5)
        {
            ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
            offset = extension.modelOffset2WidgetOffset(offset);
        } else
        {
            offset -= viewer.getVisibleRegion().getOffset();
        }
        StyledText text = viewer.getTextWidget();
        try
        {
            text.redrawRange(offset, length, true);
        }
        catch (IllegalArgumentException x)
        {
        }
    }
    fActiveRegion = null;
}
项目:velocity-edit    文件:VelocityEditor.java   
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;
}
项目:velocity-edit    文件:VelocityEditor.java   
public void paintControl(PaintEvent event)
{
    if (fActiveRegion == null) { return; }
    ISourceViewer viewer = getSourceViewer();
    if (viewer == null) { return; }
    StyledText text = viewer.getTextWidget();
    if ((text == null) || text.isDisposed()) { return; }
    int offset = 0;
    int length = 0;
    if (viewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        IRegion widgetRange = extension.modelRange2WidgetRange(new Region(offset, length));
        if (widgetRange == null) { return; }
        offset = widgetRange.getOffset();
        length = widgetRange.getLength();
    } else
    {
        IRegion region = viewer.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);
}
项目:APICloud-Studio    文件:WhitespaceCharacterPainter.java   
/**
 * Check if the given widget line is a folded line.
 * 
 * @param widgetLine
 *            the widget line number
 * @return <code>true</code> if the line is folded
 */
private boolean isFoldedLine(int widgetLine)
{
    if (fTextViewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        int modelLine = extension.widgetLine2ModelLine(widgetLine);
        int widgetLine2 = extension.modelLine2WidgetLine(modelLine + 1);
        return widgetLine2 == -1;
    }
    return false;
}
项目:APICloud-Studio    文件:WhitespaceCharacterPainter.java   
/**
 * Convert a widget offset to the corresponding document offset.
 * 
 * @param widgetOffset
 * @return document offset
 */
private int getDocumentOffset(int widgetOffset)
{
    if (fTextViewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        return extension.widgetOffset2ModelOffset(widgetOffset);
    }
    IRegion visible = fTextViewer.getVisibleRegion();
    if (widgetOffset > visible.getLength())
    {
        return -1;
    }
    return widgetOffset + visible.getOffset();
}
项目:APICloud-Studio    文件:CommandExecutionUtils.java   
private static void setCaretOffset(ITextViewer textViewer, int docOffset)
{
    if (textViewer instanceof ITextViewerExtension5)
    {
        docOffset = ((ITextViewerExtension5) textViewer).modelOffset2WidgetOffset(docOffset);
    }
    textViewer.getTextWidget().setCaretOffset(docOffset);
}
项目:APICloud-Studio    文件:CommandExecutionUtils.java   
private static int getCaretOffset(ITextViewer textViewer)
{
    StyledText textWidget = textViewer.getTextWidget();
    int caretOffset = textWidget.getCaretOffset();
    if (textViewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) textViewer;
        return extension.widgetOffset2ModelOffset(caretOffset);
    }
    return caretOffset;
}
项目:APICloud-Studio    文件:LineBackgroundPainter.java   
/**
 * Returns the location of the caret as offset in the source viewer's input document.
 * 
 * @return the caret location
 */
private int getModelCaret()
{
    int widgetCaret = fViewer.getTextWidget().getCaretOffset();
    if (fViewer instanceof ITextViewerExtension5)
    {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
        return extension.widgetOffset2ModelOffset(widgetCaret);
    }
    IRegion visible = fViewer.getVisibleRegion();
    return widgetCaret + visible.getOffset();
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaMoveLinesAction.java   
/**
 * Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>.
 * As a special case, a selection is considered contained even if it extends over the visible
 * region, but the extension stays on a partially contained line and contains only white space.
 *
 * @param selection the selection to be checked
 * @param viewer the viewer displaying a visible region of <code>selection</code>'s document.
 * @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise.
 */
private boolean containedByVisibleRegion(ITextSelection selection, ISourceViewer viewer) {
    int min= selection.getOffset();
    int max= min + selection.getLength();
    IDocument document= viewer.getDocument();

    IRegion visible;
    if (viewer instanceof ITextViewerExtension5)
        visible= ((ITextViewerExtension5) viewer).getModelCoverage();
    else
        visible= viewer.getVisibleRegion();

    int visOffset= visible.getOffset();
    try {
        if (visOffset > min) {
            if (document.getLineOfOffset(visOffset) != selection.getStartLine())
                return false;
            if (!isWhitespace(document.get(min, visOffset - min))) {
                showStatus();
                return false;
            }
        }
        int visEnd= visOffset + visible.getLength();
        if (visEnd < max) {
            if (document.getLineOfOffset(visEnd) != selection.getEndLine())
                return false;
            if (!isWhitespace(document.get(visEnd, max - visEnd))) {
                showStatus();
                return false;
            }
        }
        return true;
    } catch (BadLocationException e) {
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:JDTQuickMenuCreator.java   
private IRegion modelRange2WidgetRange(IRegion region) {
    ISourceViewer viewer= fEditor.getViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5)viewer;
        return extension.modelRange2WidgetRange(region);
    }

    IRegion visibleRegion= viewer.getVisibleRegion();
    int start= region.getOffset() - visibleRegion.getOffset();
    int end= start + region.getLength();
    if (end > visibleRegion.getLength())
        end= visibleRegion.getLength();

    return new Region(start, end - start);
}
项目:Eclipse-Postfix-Code-Completion    文件:AbstractJavaCompletionProposal.java   
/**
 * Convert a document offset to the corresponding widget offset.
 * 
 * @param viewer the text viewer
 * @param documentOffset the document offset
 * @return widget offset
 * @since 3.6
 */
private int getWidgetOffset(ITextViewer viewer, int documentOffset) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5)viewer;
        return extension.modelOffset2WidgetOffset(documentOffset);
    }
    IRegion visible= viewer.getVisibleRegion();
    int widgetOffset= documentOffset - visible.getOffset();
    if (widgetOffset > visible.getLength()) {
        return -1;
    }
    return widgetOffset;
}
项目:Eclipse-Postfix-Code-Completion    文件:AbstractJavaCompletionProposal.java   
/**
 * Creates a style range for the text viewer.
 * 
 * @param viewer the text viewer
 * @return the new style range for the text viewer or <code>null</code>
 * @since 3.6
 */
private StyleRange createStyleRange(ITextViewer viewer) {
    StyledText text= viewer.getTextWidget();
    if (text == null || text.isDisposed())
        return null;

    int widgetCaret= text.getCaretOffset();

    int modelCaret= 0;
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
        modelCaret= extension.widgetOffset2ModelOffset(widgetCaret);
    } else {
        IRegion visibleRegion= viewer.getVisibleRegion();
        modelCaret= widgetCaret + visibleRegion.getOffset();
    }

    if (modelCaret >= getReplacementOffset() + getReplacementLength())
        return null;

    int length= getReplacementOffset() + getReplacementLength() - modelCaret;

    Color foreground= getForegroundColor();
    Color background= getBackgroundColor();

    return new StyleRange(modelCaret, length, foreground, background);
}
项目:idecore    文件:ApexCodeEditor.java   
@Override
protected void adjustHighlightRange(int offset, int length) {
    ISourceViewer viewer = getSourceViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        extension.exposeModelRange(new Region(offset, length));
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaMoveLinesAction.java   
/**
 * Checks if <code>selection</code> is contained by the visible region of <code>viewer</code>.
 * As a special case, a selection is considered contained even if it extends over the visible
 * region, but the extension stays on a partially contained line and contains only white space.
 *
 * @param selection the selection to be checked
 * @param viewer the viewer displaying a visible region of <code>selection</code>'s document.
 * @return <code>true</code>, if <code>selection</code> is contained, <code>false</code> otherwise.
 */
private boolean containedByVisibleRegion(ITextSelection selection, ISourceViewer viewer) {
    int min= selection.getOffset();
    int max= min + selection.getLength();
    IDocument document= viewer.getDocument();

    IRegion visible;
    if (viewer instanceof ITextViewerExtension5)
        visible= ((ITextViewerExtension5) viewer).getModelCoverage();
    else
        visible= viewer.getVisibleRegion();

    int visOffset= visible.getOffset();
    try {
        if (visOffset > min) {
            if (document.getLineOfOffset(visOffset) != selection.getStartLine())
                return false;
            if (!isWhitespace(document.get(min, visOffset - min))) {
                showStatus();
                return false;
            }
        }
        int visEnd= visOffset + visible.getLength();
        if (visEnd < max) {
            if (document.getLineOfOffset(visEnd) != selection.getEndLine())
                return false;
            if (!isWhitespace(document.get(visEnd, max - visEnd))) {
                showStatus();
                return false;
            }
        }
        return true;
    } catch (BadLocationException e) {
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JDTQuickMenuCreator.java   
private IRegion modelRange2WidgetRange(IRegion region) {
    ISourceViewer viewer= fEditor.getViewer();
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5)viewer;
        return extension.modelRange2WidgetRange(region);
    }

    IRegion visibleRegion= viewer.getVisibleRegion();
    int start= region.getOffset() - visibleRegion.getOffset();
    int end= start + region.getLength();
    if (end > visibleRegion.getLength())
        end= visibleRegion.getLength();

    return new Region(start, end - start);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AbstractJavaCompletionProposal.java   
/**
 * Convert a document offset to the corresponding widget offset.
 * 
 * @param viewer the text viewer
 * @param documentOffset the document offset
 * @return widget offset
 * @since 3.6
 */
private int getWidgetOffset(ITextViewer viewer, int documentOffset) {
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5)viewer;
        return extension.modelOffset2WidgetOffset(documentOffset);
    }
    IRegion visible= viewer.getVisibleRegion();
    int widgetOffset= documentOffset - visible.getOffset();
    if (widgetOffset > visible.getLength()) {
        return -1;
    }
    return widgetOffset;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:AbstractJavaCompletionProposal.java   
/**
 * Creates a style range for the text viewer.
 * 
 * @param viewer the text viewer
 * @return the new style range for the text viewer or <code>null</code>
 * @since 3.6
 */
private StyleRange createStyleRange(ITextViewer viewer) {
    StyledText text= viewer.getTextWidget();
    if (text == null || text.isDisposed())
        return null;

    int widgetCaret= text.getCaretOffset();

    int modelCaret= 0;
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
        modelCaret= extension.widgetOffset2ModelOffset(widgetCaret);
    } else {
        IRegion visibleRegion= viewer.getVisibleRegion();
        modelCaret= widgetCaret + visibleRegion.getOffset();
    }

    if (modelCaret >= getReplacementOffset() + getReplacementLength())
        return null;

    int length= getReplacementOffset() + getReplacementLength() - modelCaret;

    Color foreground= getForegroundColor();
    Color background= getBackgroundColor();

    return new StyleRange(modelCaret, length, foreground, background);
}
项目:e4macs    文件:MarkUtils.java   
public static int widget2ModelOffset(ISourceViewer viewer, int widgetOffset) {
    int result = widgetOffset;
    try {
        if (viewer instanceof ITextViewerExtension5) {
            result = ((ITextViewerExtension5) viewer).widgetOffset2ModelOffset(result);
        }
    } catch (Exception e) {
    }
    return result;
}
项目:e4macs    文件:MarkUtils.java   
public static int model2WidgetOffset(ISourceViewer viewer, int modelOffset) {
    int result = modelOffset;
    try {
        if (viewer instanceof ITextViewerExtension5) {
            result = ((ITextViewerExtension5) viewer).modelOffset2WidgetOffset(result);
        }
    } catch (Exception e) {
    }
    return result;
}
项目:Pydev    文件:PyCompletionPresentationUpdater.java   
private StyleRange createStyleRange(ITextViewer viewer, int initialOffset, int len) {
    StyledText text = viewer.getTextWidget();
    if (text == null || text.isDisposed()) {
        return null;
    }

    int widgetCaret = text.getCaretOffset();

    int modelCaret = 0;
    if (viewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
        modelCaret = extension.widgetOffset2ModelOffset(widgetCaret);
    } else {
        IRegion visibleRegion = viewer.getVisibleRegion();
        modelCaret = widgetCaret + visibleRegion.getOffset();
    }

    if (modelCaret >= initialOffset + len) {
        return null;
    }

    int length = initialOffset + len - modelCaret;

    Color foreground = getForegroundColor();
    Color background = getBackgroundColor();

    return new StyleRange(modelCaret, length, foreground, background);
}
项目:IndentGuide    文件:IndentGuidePainter.java   
/**
 * Check if the given widget line is a folded line.
 * 
 * @param widgetLine
 *            the widget line number
 * @return <code>true</code> if the line is folded
 */
private boolean isFoldedLine(int widgetLine) {
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        int modelLine = extension.widgetLine2ModelLine(widgetLine);
        int widgetLine2 = extension.modelLine2WidgetLine(modelLine + 1);
        return widgetLine2 == -1;
    }
    return false;
}
项目:IndentGuide    文件:IndentGuidePainter.java   
/**
 * Convert a document offset to the corresponding widget offset.
 * 
 * @param documentOffset
 *            the document offset
 * @return widget offset
 */
private int getWidgetOffset(int documentOffset) {
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        return extension.modelOffset2WidgetOffset(documentOffset);
    }
    IRegion visible = fTextViewer.getVisibleRegion();
    int widgetOffset = documentOffset - visible.getOffset();
    if (widgetOffset > visible.getLength()) {
        return -1;
    }
    return widgetOffset;
}
项目:IndentGuide    文件:IndentGuidePainter.java   
/**
 * Convert a widget offset to the corresponding document offset.
 * 
 * @param widgetOffset
 *            the widget offset
 * @return document offset
 */
private int getDocumentOffset(int widgetOffset) {
    if (fTextViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) fTextViewer;
        return extension.widgetOffset2ModelOffset(widgetOffset);
    }
    IRegion visible = fTextViewer.getVisibleRegion();
    if (widgetOffset > visible.getLength()) {
        return -1;
    }
    return widgetOffset + visible.getOffset();
}
项目:typescript.java    文件:JavaScriptLightWeightEditor.java   
/**
 * Jumps to the matching bracket.
 */
public void gotoMatchingBracket() {

    ISourceViewer sourceViewer = getSourceViewer();
    IDocument document = sourceViewer.getDocument();
    if (document == null)
        return;

    IRegion selection = getSignedSelection(sourceViewer);

    int selectionLength = Math.abs(selection.getLength());
    if (selectionLength > 1) {
        setStatusLineErrorMessage(JSDTTypeScriptUIMessages.GotoMatchingBracket_error_invalidSelection);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    // #26314
    int sourceCaretOffset = selection.getOffset() + selection.getLength();
    if (isSurroundedByBrackets(document, sourceCaretOffset))
        sourceCaretOffset -= selection.getLength();

    IRegion region = fBracketMatcher.match(document, sourceCaretOffset);
    if (region == null) {
        setStatusLineErrorMessage(JSDTTypeScriptUIMessages.GotoMatchingBracket_error_noMatchingBracket);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset = region.getOffset();
    int length = region.getLength();

    if (length < 1)
        return;

    int anchor = fBracketMatcher.getAnchor();
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
    int targetOffset = (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length;

    boolean visible = false;
    if (sourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension = (ITextViewerExtension5) sourceViewer;
        visible = (extension.modelOffset2WidgetOffset(targetOffset) > -1);
    } else {
        IRegion visibleRegion = sourceViewer.getVisibleRegion();
        // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
        visible = (targetOffset >= visibleRegion.getOffset()
                && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength());
    }

    if (!visible) {
        setStatusLineErrorMessage(JSDTTypeScriptUIMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    if (selection.getLength() < 0)
        targetOffset -= selection.getLength();

    sourceViewer.setSelectedRange(targetOffset, selection.getLength());
    sourceViewer.revealRange(targetOffset, selection.getLength());
}
项目:APICloud-Studio    文件:LineBackgroundPainter.java   
private Rectangle getLineRectangle(Position position)
{
    if (position == null)
    {
        return null;
    }

    // if the position that is about to be drawn was deleted then we can't
    if (position.isDeleted())
    {
        return null;
    }

    int widgetOffset = 0;
    if (fViewer instanceof ITextViewerExtension5)
    {

        ITextViewerExtension5 extension = (ITextViewerExtension5) fViewer;
        widgetOffset = extension.modelOffset2WidgetOffset(position.getOffset());
        if (widgetOffset == -1)
        {
            return null;
        }
    }
    else
    {

        IRegion visible = fViewer.getVisibleRegion();
        widgetOffset = position.getOffset() - visible.getOffset();
        if (widgetOffset < 0 || visible.getLength() < widgetOffset)
        {
            return null;
        }
    }

    StyledText textWidget = fViewer.getTextWidget();
    // check for https://bugs.eclipse.org/bugs/show_bug.cgi?id=64898
    // this is a guard against the symptoms but not the actual solution
    if (0 <= widgetOffset && widgetOffset <= textWidget.getCharCount())
    {
        Point upperLeft = textWidget.getLocationAtOffset(widgetOffset);
        int width = textWidget.getClientArea().width + textWidget.getHorizontalPixel();
        int height = textWidget.getLineHeight(widgetOffset);
        return new Rectangle(0, upperLeft.y, width, height);
    }

    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditor.java   
/**
 * Jumps to the matching bracket.
 */
public void gotoMatchingBracket() {

    ISourceViewer sourceViewer= getSourceViewer();
    IDocument document= sourceViewer.getDocument();
    if (document == null)
        return;

    IRegion selection= getSignedSelection(sourceViewer);
    if (fPreviousSelections == null)
        initializePreviousSelectionList();

    IRegion region= fBracketMatcher.match(document, selection.getOffset(), selection.getLength());
    if (region == null) {
        region= fBracketMatcher.findEnclosingPeerCharacters(document, selection.getOffset(), selection.getLength());
        initializePreviousSelectionList();
        fPreviousSelections.add(selection);
    } else {
        if (fPreviousSelections.size() == 2) {
            if (!selection.equals(fPreviousSelections.get(1))) {
                initializePreviousSelectionList();
            }
        } else if (fPreviousSelections.size() == 3) {
            if (selection.equals(fPreviousSelections.get(2)) && !selection.equals(fPreviousSelections.get(0))) {
                IRegion originalSelection= fPreviousSelections.get(0);
                sourceViewer.setSelectedRange(originalSelection.getOffset(), originalSelection.getLength());
                sourceViewer.revealRange(originalSelection.getOffset(), originalSelection.getLength());
                initializePreviousSelectionList();
                return;
            }
            initializePreviousSelectionList();
        }
    }

    if (region == null) {
        setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_noMatchingBracket);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int offset= region.getOffset();
    int length= region.getLength();

    if (length < 1)
        return;

    int anchor= fBracketMatcher.getAnchor();
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
    int targetOffset= (ICharacterPairMatcher.RIGHT == anchor) ? offset + 1 : offset + length - 1;

    boolean visible= false;
    if (sourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5) sourceViewer;
        visible= (extension.modelOffset2WidgetOffset(targetOffset) > -1);
    } else {
        IRegion visibleRegion= sourceViewer.getVisibleRegion();
        // http://dev.eclipse.org/bugs/show_bug.cgi?id=34195
        visible= (targetOffset >= visibleRegion.getOffset() && targetOffset <= visibleRegion.getOffset() + visibleRegion.getLength());
    }

    if (!visible) {
        setStatusLineErrorMessage(JavaEditorMessages.GotoMatchingBracket_error_bracketOutsideSelectedElement);
        sourceViewer.getTextWidget().getDisplay().beep();
        return;
    }

    int adjustment= getOffsetAdjustment(document, selection.getOffset() + selection.getLength(), selection.getLength());
    targetOffset+= adjustment;
    int direction= (selection.getLength() == 0) ? 0 : ((selection.getLength() > 0) ? 1 : -1);
    if (fPreviousSelections.size() == 1 && direction < 0) {
        targetOffset++;
    }

    if (fPreviousSelections.size() > 0) {
        fPreviousSelections.add(new Region(targetOffset, direction));
    }
    sourceViewer.setSelectedRange(targetOffset, direction);
    sourceViewer.revealRange(targetOffset, direction);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaEditor.java   
/**
 * Computes and returns the source reference that includes the caret and
 * serves as provider for the outline page selection and the editor range
 * indication.
 *
 * @return the computed source reference
 * @since 3.0
 */
protected ISourceReference computeHighlightRangeSourceReference() {
    ISourceViewer sourceViewer= getSourceViewer();
    if (sourceViewer == null)
        return null;

    StyledText styledText= sourceViewer.getTextWidget();
    if (styledText == null)
        return null;

    int caret= 0;
    if (sourceViewer instanceof ITextViewerExtension5) {
        ITextViewerExtension5 extension= (ITextViewerExtension5)sourceViewer;
        caret= extension.widgetOffset2ModelOffset(styledText.getCaretOffset());
    } else {
        int offset= sourceViewer.getVisibleRegion().getOffset();
        caret= offset + styledText.getCaretOffset();
    }

    IJavaElement element= getElementAt(caret, false);

    if ( !(element instanceof ISourceReference))
        return null;

    if (element.getElementType() == IJavaElement.IMPORT_DECLARATION) {

        IImportDeclaration declaration= (IImportDeclaration) element;
        IImportContainer container= (IImportContainer) declaration.getParent();
        ISourceRange srcRange= null;

        try {
            srcRange= container.getSourceRange();
        } catch (JavaModelException e) {
        }

        if (srcRange != null && srcRange.getOffset() == caret)
            return container;
    }

    return (ISourceReference) element;
}