本文整理匯總了Java中org.eclipse.jface.text.ITextSelection.getEndLine方法的典型用法代碼示例。如果您正苦於以下問題:Java ITextSelection.getEndLine方法的具體用法?Java ITextSelection.getEndLine怎麽用?Java ITextSelection.getEndLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jface.text.ITextSelection
的用法示例。
在下文中一共展示了ITextSelection.getEndLine方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMovingSelection
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* Given a selection on a document, computes the lines fully or partially covered by
* <code>selection</code>. A line in the document is considered covered if
* <code>selection</code> comprises any characters on it, including the terminating delimiter.
* <p>Note that the last line in a selection is not considered covered if the selection only
* comprises the line delimiter at its beginning (that is considered part of the second last
* line).
* As a special case, if the selection is empty, a line is considered covered if the caret is
* at any position in the line, including between the delimiter and the start of the line. The
* line containing the delimiter is not considered covered in that case.
* </p>
*
* @param document the document <code>selection</code> refers to
* @param selection a selection on <code>document</code>
* @param viewer the <code>ISourceViewer</code> displaying <code>document</code>
* @return a selection describing the range of lines (partially) covered by
* <code>selection</code>, without any terminating line delimiters
* @throws BadLocationException if the selection is out of bounds (when the underlying document has changed during the call)
*/
private ITextSelection getMovingSelection(IDocument document, ITextSelection selection, ITextViewer viewer) throws BadLocationException {
int low= document.getLineOffset(selection.getStartLine());
int endLine= selection.getEndLine();
int high= document.getLineOffset(endLine) + document.getLineLength(endLine);
// get everything up to last line without its delimiter
String delim= document.getLineDelimiter(endLine);
if (delim != null)
high -= delim.length();
// the new selection will cover the entire lines being moved, except for the last line's
// delimiter. The exception to this rule is an empty last line, which will stay covered
// including its delimiter
if (delim != null && document.getLineLength(endLine) == delim.length())
fAddDelimiter= true;
else
fAddDelimiter= false;
return new TextSelection(document, low, high - low);
}
示例2: run
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
public void run()
{
ITextEditor editor = getTextEditor();
ISelection selection = editor.getSelectionProvider().getSelection();
if (selection instanceof ITextSelection)
{
ITextSelection textSelection = (ITextSelection) selection;
if (textSelection.getLength() != 0)
{
IAnnotationModel model = getAnnotationModel(editor);
if (model != null)
{
int start = textSelection.getStartLine();
int end = textSelection.getEndLine();
try
{
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
int offset = document.getLineOffset(start);
int endOffset = document.getLineOffset(end + 1);
Position position = new Position(offset, endOffset - offset);
model.addAnnotation(new ProjectionAnnotation(), position);
} catch (BadLocationException x)
{
// ignore
}
}
}
}
}
示例3: containedByVisibleRegion
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* 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;
}
示例4: getSkippedLine
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
/**
* Computes the region of the skipped line given the text block to be moved. If
* <code>fUpwards</code> is <code>true</code>, the line above <code>selection</code>
* is selected, otherwise the line below.
*
* @param document the document <code>selection</code> refers to
* @param selection the selection on <code>document</code> that will be moved.
* @return the region comprising the line that <code>selection</code> will be moved over, without its terminating delimiter.
*/
private ITextSelection getSkippedLine(IDocument document, ITextSelection selection) {
int skippedLineN= (fUpwards ? selection.getStartLine() - 1 : selection.getEndLine() + 1);
if (skippedLineN > document.getNumberOfLines() || (!fCopy && (skippedLineN < 0 || skippedLineN == document.getNumberOfLines())))
return null;
try {
if (fCopy && skippedLineN == -1)
skippedLineN= 0;
IRegion line= document.getLineInformation(skippedLineN);
return new TextSelection(document, line.getOffset(), line.getLength());
} catch (BadLocationException e) {
// only happens on concurrent modifications
return null;
}
}
示例5: run
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
@Override
public void run() {
ITextViewer viewer= getTextViewer();
if (viewer == null)
return;
if (!canModifyViewer())
return;
IDocument document= viewer.getDocument();
if (document == null)
return;
ITextSelection selection= getSelection(viewer);
if (selection == null)
return;
int startLine= selection.getStartLine();
int endLine= selection.getEndLine();
try {
int caretOffset= joinLines(document, startLine, endLine);
if (caretOffset > -1) {
StyledText widget= viewer.getTextWidget();
widget.setRedraw(false);
adjustHighlightRange(viewer, caretOffset, 0);
viewer.revealRange(caretOffset, 0);
viewer.setSelectedRange(caretOffset, 0);
widget.setRedraw(true);
}
} catch (BadLocationException e) {
// should not happen
}
}
示例6: convertRegion
import org.eclipse.jface.text.ITextSelection; //導入方法依賴的package包/類
private static IRegion convertRegion(int offset, int length, String text,
String originalDelimiter) {
try {
Document document = new Document(text);
String delimiter = document.getLineDelimiter(0);
// If the document's line delimiter is the same as that used to originally
// calculate this offset/length, then just return the original region.
if (delimiter == null || delimiter.equals(originalDelimiter)) {
return new Region(offset, length);
}
// If we're running a platform other than the one this offset/length was
// calculated on, we'll need to adjust the values. We start by creating
// a text selection containing the original region and the text with the
// original line endings.
String originalText = text.replaceAll(delimiter, originalDelimiter);
ITextSelection originalSelection = new TextSelection(new Document(
originalText), offset, length);
int delimiterLengthCorrection = originalDelimiter.length()
- delimiter.length();
// Adjust the offset by the delimiter length difference for each line
// that came before it.
int newOffset = originalSelection.getOffset()
- (delimiterLengthCorrection * originalSelection.getStartLine());
// Adjust the length by the delimiter length difference for each line
// between the start and the end of the original region
// TODO: account for case where the selection ends with a line break;
// currently this will not update the length since the selection starts
// and ends on the same line.
int regionLineBreaks = originalSelection.getEndLine()
- originalSelection.getStartLine();
int newLength = originalSelection.getLength()
- (delimiterLengthCorrection * regionLineBreaks);
return new Region(newOffset, newLength);
} catch (BadLocationException e) {
return null;
}
}