本文整理汇总了Java中org.netbeans.editor.Utilities.getRowStartFromLineOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getRowStartFromLineOffset方法的具体用法?Java Utilities.getRowStartFromLineOffset怎么用?Java Utilities.getRowStartFromLineOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.netbeans.editor.Utilities
的用法示例。
在下文中一共展示了Utilities.getRowStartFromLineOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getModelToViewImpl
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private synchronized int getModelToViewImpl(int line) throws BadLocationException {
int docLines = Utilities.getRowCount(doc);
if (modelToViewCache == null || height != pane.getHeight() || lines != docLines) {
modelToViewCache = new int[Utilities.getRowCount(doc) + 2];
lines = Utilities.getRowCount(doc);
height = pane.getHeight();
}
if (line >= docLines)
return -1;
int result = modelToViewCache[line + 1];
if (result == 0) {
int lineOffset = Utilities.getRowStartFromLineOffset((BaseDocument) pane.getDocument(), line);
modelToViewCache[line + 1] = result = getYFromPos(lineOffset);
}
if (result == (-1))
result = 0;
return result;
}
示例2: addLanguageEndLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void addLanguageEndLine(List<Line> lines) throws BadLocationException {
// check what last line of language suggests about next line:
if (lines.isEmpty()) {
return;
}
Line lastLine = lines.get(lines.size()-1);
if (lastLine.preliminaryNextLineIndent.isEmpty()) {
return;
}
int lineIndex = lastLine.index+1;
int offset = Utilities.getRowStartFromLineOffset(getDocument(), lineIndex);
if (offset == -1) {
return;
}
Line l = generateBasicLine(lineIndex);
l.indentThisLine = false;
l.lineIndent = new ArrayList<IndentCommand>(lastLine.preliminaryNextLineIndent);
lines.add(l);
}
示例3: generateBasicLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private Line generateBasicLine(int index) throws BadLocationException {
Line line = new Line();
line.index = index;
line.offset = Utilities.getRowStartFromLineOffset(getDocument(), index);
line.existingLineIndent = IndentUtils.lineIndent(getDocument(), line.offset);
int nonWS = Utilities.getRowFirstNonWhite(getDocument(), line.offset);
line.emptyLine = nonWS == -1;
// if (first-non-whitespace-offset - line-start-offset) is different from
// existingLineIndent then line starts with tab characters which will need
// to be replaced; if line is empty set tabIndentation to true just to make sure
// possible tabs get replaced:
line.tabIndentation = nonWS == -1 || line.existingLineIndent != (nonWS - line.offset);
line.lineStartOffset = line.offset;
line.lineEndOffset = Utilities.getRowEnd(getDocument(), line.offset);
line.lineIndent = new ArrayList<IndentCommand>();
line.lineIndent.add(new IndentCommand(IndentCommand.Type.NO_CHANGE, line.offset, getIndentationSize()));
line.preliminaryNextLineIndent = new ArrayList<IndentCommand>();
line.preliminaryNextLineIndent.add(new IndentCommand(IndentCommand.Type.NO_CHANGE, line.offset, getIndentationSize()));
return line;
}
示例4: getInitialIndentFromPreviousLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int line) throws BadLocationException {
// get initial indent from the previous line
int initialIndent = 0;
if (line > 0) {
int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
int previousNonWhiteLineEnd = Utilities.getFirstNonWhiteBwd(doc, lineStart);
if (previousNonWhiteLineEnd > 0) {
initialIndent = Utilities.getRowIndent(doc, previousNonWhiteLineEnd);
}
}
return initialIndent;
}
示例5: markCurrentLanguageLines
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void markCurrentLanguageLines(BaseDocument doc, TextBounds languageBounds, EmbeddingType[] embeddingType) throws BadLocationException {
if (languageBounds.getStartPos() == -1){
return; // only white spaces
}
int firstLineOfTheLanguageBlock = languageBounds.getStartLine();
int lineStart = Utilities.getRowStartFromLineOffset(doc, firstLineOfTheLanguageBlock);
if (Utilities.getFirstNonWhiteFwd(doc, lineStart) < languageBounds.getStartPos()) {
firstLineOfTheLanguageBlock++;
}
for (int i = firstLineOfTheLanguageBlock; i <= languageBounds.getEndLine(); i++) {
embeddingType[i] = EmbeddingType.CURRENT_LANG;
}
}
示例6: getInitialIndentFromPreviousLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected int getInitialIndentFromPreviousLine(final BaseDocument doc, final int line) throws BadLocationException {
// get initial indent from the previous line
int initialIndent = 0;
if (line > 0){
int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
int previousNonWhiteLineEnd = Utilities.getFirstNonWhiteBwd(doc, lineStart);
if (previousNonWhiteLineEnd > 0){
initialIndent = Utilities.getRowIndent(doc, previousNonWhiteLineEnd);
}
}
return initialIndent;
}
示例7: doesLineStartWithOurLanguage
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean doesLineStartWithOurLanguage(BaseDocument doc, int lineIndex, JoinedTokenSequence<T1> joinedTS) throws BadLocationException {
int rowStartOffset = Utilities.getRowStartFromLineOffset(doc, lineIndex);
int rowEndOffset = Utilities.getRowEnd(doc, rowStartOffset);
int firstNonWhite = Utilities.getRowFirstNonWhite(doc, rowStartOffset);
if (firstNonWhite != -1) {
// there is something on the line:
int newRowStartOffset = findLanguageOffset(joinedTS, rowStartOffset, rowEndOffset, true);
if (newRowStartOffset == -1) {
// but it is not our langauge
return false;
}
}
return true;
}
示例8: getInitialIndentFromNextLine
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private int getInitialIndentFromNextLine(final BaseDocument doc, final int line) throws BadLocationException {
// get initial indent from the next line
int initialIndent = 0;
int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
int lineEnd = Utilities.getRowEnd(doc, lineStart);
int nextNonWhiteLineStart = Utilities.getFirstNonWhiteFwd(doc, lineEnd);
if (nextNonWhiteLineStart > 0){
initialIndent = Utilities.getRowIndent(doc, nextNonWhiteLineStart, true);
}
return initialIndent;
}
示例9: computeDocumentOffset
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private int computeDocumentOffset(int lineOffset) {
int end = Utilities.getRowStartFromLineOffset(document, lineOffset);
if (end == -1) {
Element lineRoot = document.getParagraphElement(0).getParentElement();
for (end = lineRoot.getElement(lineOffset - 1).getEndOffset(); end > document.getLength(); end--) {
}
}
return end;
}
示例10: scrollToDifference
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private Point scrollToDifference(Difference diff) {
int lineStart = diff.getSecondStart() - 1;
int lineEnd = diff.getSecondEnd() - 1;
if (lineStart == -1) {
// the change was delete starting on the first line, show the diff on the next line
// since in this case the file cannot be empty, 0 index does not throw BLE
lineStart = 0;
}
if (diff.getType() == Difference.DELETE) {
lineEnd = lineStart;
}
try {
EditorUI editorUI = Utilities.getEditorUI(textComponent);
int visibleBorder = editorUI.getLineHeight() * 5;
int startOffset = Utilities.getRowStartFromLineOffset((BaseDocument) textComponent.getDocument(), lineStart);
int endOffset = Utilities.getRowStartFromLineOffset((BaseDocument) textComponent.getDocument(), lineEnd);
Rectangle startRect = textComponent.getUI().modelToView(textComponent, startOffset);
Rectangle endRect = textComponent.getUI().modelToView(textComponent, endOffset);
Rectangle visibleRect = new Rectangle(startRect.x - visibleBorder, startRect.y - visibleBorder,
startRect.x, endRect.y - startRect.y + endRect.height + visibleBorder * 2);
textComponent.scrollRectToVisible(visibleRect);
//make sure the y coordinate isn't outside the editor bounds otherwise the popup will 'float' beneath the editor
Rectangle extent = editorUI.getExtentBounds();
int maxVisibleY = extent.y + extent.height;
Point p = new Point(endRect.x, Math.min(maxVisibleY, endRect.y + endRect.height + 1));
//XXX: The resulting screen coordinates could still be outside the main screen
SwingUtilities.convertPointToScreen(p, textComponent);
return p;
} catch (BadLocationException e) {
LOG.log(Level.WARNING, "scrollToDifference", e); // NOI18N
}
return null;
}
示例11: getRowStartFromLineOffset
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
static int getRowStartFromLineOffset(Document doc, int lineIndex) {
if (doc instanceof BaseDocument) {
return Utilities.getRowStartFromLineOffset((BaseDocument) doc, lineIndex);
} else {
// TODO: find row start from line offet
Element element = doc.getDefaultRootElement();
Element line = element.getElement(lineIndex);
return line.getStartOffset();
}
}
示例12: canRollback
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean canRollback(Document doc, Difference diff) {
if (!(doc instanceof GuardedDocument)) return true;
GuardedDocument document = (GuardedDocument) doc;
int start, end;
if (diff.getType() == Difference.DELETE) {
start = end = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart());
} else {
start = Utilities.getRowStartFromLineOffset(document, diff.getSecondStart() > 0 ? diff.getSecondStart() - 1 : 0);
end = Utilities.getRowStartFromLineOffset(document, diff.getSecondEnd());
}
MarkBlockChain mbc = ((GuardedDocument) document).getGuardedBlockChain();
return (mbc.compareBlock(start, end) & MarkBlock.OVERLAP) == 0;
}
示例13: performGoto
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** Perform the goto operation.
* @return whether the dialog should be made invisible or not
*/
protected boolean performGoto() {
JTextComponent c = EditorRegistry.lastFocusedComponent();
if (c != null) {
try {
int line = Integer.parseInt(getGotoValueText());
//issue 188976
if (line==0)
line = 1;
//end of issue 188976
BaseDocument doc = Utilities.getDocument(c);
if (doc != null) {
int rowCount = Utilities.getRowCount(doc);
if (line > rowCount)
line = rowCount;
// Obtain the offset where to jump
int pos = Utilities.getRowStartFromLineOffset(doc, line - 1);
BaseKit kit = Utilities.getKit(c);
if (kit != null) {
Action a = kit.getActionByName(ExtKit.gotoAction);
if (a instanceof ExtKit.GotoAction) {
pos = ((ExtKit.GotoAction)a).getOffsetFromLine(doc, line - 1);
}
}
if (pos != -1) {
Caret caret = c.getCaret();
caret.setDot(pos);
} else {
c.getToolkit().beep();
return false;
}
}
} catch (NumberFormatException e) {
c.getToolkit().beep();
return false;
}
}
return true;
}
示例14: getExistingIndent
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected static int getExistingIndent(BaseDocument doc, int line) throws BadLocationException{
int lineStart = Utilities.getRowStartFromLineOffset(doc, line);
return IndentUtils.lineIndent(doc, lineStart);
}
示例15: moveNext
import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public boolean moveNext() {
synchronized (EmbeddedSectionsHighlighting.this) {
if (checkVersion()) {
if (sequence == null) {
sequence = scanner.tokenSequence();
if (sequence == null) {
return false;
} else {
sequence.move(startOffset);
}
}
int delimiterSize = 0;
while (sequence.moveNext() && sequence.offset() < endOffset) {
if (sequence.token().id() == YamlTokenId.DELIMITER) {
// opening delimiters can have different lenght
delimiterSize = sequence.token().length();
} else if (YamlTokenId.isRuby(sequence.token().id())) {
sectionStart = sequence.offset();
sectionEnd = sequence.offset() + sequence.token().length();
try {
int docLen = document.getLength();
int startLine = Utilities.getLineOffset((BaseDocument) document, Math.min(sectionStart, docLen));
int endLine = Utilities.getLineOffset((BaseDocument) document, Math.min(sectionEnd, docLen));
if (startLine != endLine) {
// multiline scriplet section
// adjust the sections start to the beginning of the firts line
int firstLineStartOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, startLine);
if (firstLineStartOffset < sectionStart - delimiterSize
&& isWhitespace(document, firstLineStartOffset, sectionStart - delimiterSize)) // always preceeded by the delimiter
{
sectionStart = firstLineStartOffset;
}
// adjust the sections end to the end of the last line
int lines = Utilities.getRowCount((BaseDocument) document);
int lastLineEndOffset;
if (endLine + 1 < lines) {
lastLineEndOffset = Utilities.getRowStartFromLineOffset((BaseDocument) document, endLine + 1);
} else {
lastLineEndOffset = document.getLength() + 1;
}
if (sectionEnd + 2 >= lastLineEndOffset || // unclosed section
isWhitespace(document, sectionEnd + 2, lastLineEndOffset)) // always succeeded by '%>' hence +2
{
sectionEnd = lastLineEndOffset;
}
}
} catch (BadLocationException ble) {
LOG.log(Level.WARNING, null, ble);
}
return true;
}
}
}
sectionStart = -1;
sectionEnd = -1;
finished = true;
return false;
}
}