当前位置: 首页>>代码示例>>Java>>正文


Java Utilities.getRowStart方法代码示例

本文整理汇总了Java中org.netbeans.editor.Utilities.getRowStart方法的典型用法代码示例。如果您正苦于以下问题:Java Utilities.getRowStart方法的具体用法?Java Utilities.getRowStart怎么用?Java Utilities.getRowStart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.netbeans.editor.Utilities的用法示例。


在下文中一共展示了Utilities.getRowStart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLineIndent

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public static int getLineIndent(BaseDocument doc, int offset) {
    try {
        int start = Utilities.getRowStart(doc, offset);
        int end;

        if (Utilities.isRowWhite(doc, start)) {
            end = Utilities.getRowEnd(doc, offset);
        } else {
            end = Utilities.getRowFirstNonWhite(doc, start);
        }

        int indent = Utilities.getVisualColumn(doc, end);

        return indent;
    } catch (BadLocationException ble) {
        Exceptions.printStackTrace(ble);

        return 0;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:YamlKeystrokeHandler.java

示例2: insert

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void insert(MutableContext context) throws BadLocationException {
    int offset = context.getBreakInsertOffset();
    BaseDocument doc = (BaseDocument) context.getDocument();
    if (offset > 0 && offset < doc.getLength()) { //check corners
        String text = doc.getText(offset - 1, 2); //get char before and after
        if (TWO_CURLY_BRACES_IMAGE.equals(text)) { //NOI18N
            //context.setText("\n\n", 1, 1, 0, 2);
            //reformat workaround -- the preferred 
            //won't work as the reformatter will not reformat the line with the closing tag
            int from = Utilities.getRowStart(doc, offset);
            int to = Utilities.getRowEnd(doc, offset);
            reformat = new Position[]{doc.createPosition(from), doc.createPosition(to)};
            context.setText("\n\n", 1, 1);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:CssTypedBreakInterceptor.java

示例3: uncomment

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void uncomment(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
    for (int offset = startOffset; lineCount > 0; lineCount--) {
        // Get the first non-whitespace char on the current line
        int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);

        // If there is any, check wheter it's the line-comment-chars and remove them
        if (firstNonWhitePos != -1) {
            if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos >= lineCommentStringLen) {
                CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
                if (CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
                    doc.remove(firstNonWhitePos, lineCommentStringLen);
                }
            }
        }

        offset = Utilities.getRowStart(doc, offset, +1);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ExtKit.java

示例4: getHyperlinkSpan

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public int[] getHyperlinkSpan(Document doc, int offset, HyperlinkType type) {
    if (!(doc instanceof BaseDocument)) {
        return null;
    }
    
    try {
        BaseDocument bdoc = (BaseDocument) doc;
        int start = Utilities.getRowStart(bdoc, offset);
        int end = Utilities.getRowEnd(bdoc, offset);

        for (int[] span : Parser.recognizeURLs(DocumentUtilities.getText(doc, start, end - start))) {
            if (span[0] + start <= offset && offset <= span[1] + start) {
                return new int[] {
                    span[0] + start,
                    span[1] + start
                };
            }
        }
    } catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:HyperlinkImpl.java

示例5: allComments

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean allComments(BaseDocument doc, int startOffset, int lineCount, String lineCommentString) throws BadLocationException {
    final int lineCommentStringLen = lineCommentString.length();
    for (int offset = startOffset; lineCount > 0; lineCount--) {
        int firstNonWhitePos = Utilities.getRowFirstNonWhite(doc, offset);
        if (firstNonWhitePos == -1) {
            return false;
        }

        if (Utilities.getRowEnd(doc, firstNonWhitePos) - firstNonWhitePos < lineCommentStringLen) {
            return false;
        }

        CharSequence maybeLineComment = DocumentUtilities.getText(doc, firstNonWhitePos, lineCommentStringLen);
        if (!CharSequenceUtilities.textEquals(maybeLineComment, lineCommentString)) {
            return false;
        }

        offset = Utilities.getRowStart(doc, offset, +1);
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:ToggleBlockCommentAction.java

示例6: getIndentForTagParameter

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected int getIndentForTagParameter(BaseDocument doc, TokenItem tag) throws BadLocationException{
    int tagStartLine = Utilities.getLineOffset(doc, tag.getOffset());
    TokenItem currentToken = tag.getNext();
    
    /*
     * Find the offset of the first attribute if it is specified on the same line as the opening of the tag
     * e.g. <tag   |attr=
     * 
     */
    while (currentToken != null && isWSTag(currentToken) && tagStartLine == Utilities.getLineOffset(doc, currentToken.getOffset())){
        currentToken = currentToken.getNext();
    }
    
    if (tag != null && !isWSTag(currentToken) && tagStartLine == Utilities.getLineOffset(doc, currentToken.getOffset())){
        return currentToken.getOffset() - Utilities.getRowIndent(doc, currentToken.getOffset()) - Utilities.getRowStart(doc, currentToken.getOffset());
    }
    
    return getShiftWidth(); // default;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:TagBasedFormatter.java

示例7: adjustLimitPos

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public int adjustLimitPos(BaseDocument doc, int limitPos) {
    origLimitPos = limitPos;
    try {
        return Utilities.getRowStart(doc, limitPos);
    } catch (BadLocationException e) {
        return limitPos;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ExtFinderFactory.java

示例8: adjustStartPos

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public int adjustStartPos(BaseDocument doc, int startPos) {
    origStartPos = startPos;
    try {
        return Utilities.getRowStart(doc, startPos);
    } catch (BadLocationException e) {
        return startPos;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ExtFinderFactory.java

示例9: recalculateLineIndex

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void recalculateLineIndex(BaseDocument doc) throws BadLocationException {
    index = Utilities.getLineOffset(doc, offset);
    int rowStart = Utilities.getRowStart(doc, offset);

    // Java formatter is fiddling with lines it should not. This is a check
    // that if line start is different then issue a warning. See also
    // AbstractIndenter.recalculateLineIndexes() for more examples.
    if (rowStart != this.offset) {
       if (DEBUG) {
           System.err.println("WARNING: disabling line indentability because its start has changed: "+this);
       }
       this.indentThisLine = false;
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:AbstractIndenter.java

示例10: getErrorDescriptionsAt

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public List<ErrorDescription> getErrorDescriptionsAt(CompilationInfo info, Context context, Document doc) throws BadLocationException {
    int rowStart = Utilities.getRowStart((BaseDocument) doc, context.getPosition());
    int rowEnd = Utilities.getRowEnd((BaseDocument) doc, context.getPosition());

    return new HintsInvoker(HintsSettings.getSettingsFor(info.getFileObject()), rowStart, rowEnd, context.getCancel()).computeHints(info);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:HintsTask.java

示例11: getIndentForTagParameter

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected int getIndentForTagParameter(BaseDocument doc, JoinedTokenSequence tokenSequence, int tagOffset) throws BadLocationException {
    int originalOffset = tokenSequence.offset();
    int tagStartLine = Utilities.getLineOffset(doc, tagOffset);
    tokenSequence.move(tagOffset);
    Token<?> token;
    int tokenOffset;
    boolean thereWasWS = false;
    int shift = doc.getShiftWidth(); // default;

    /*
     * Find the offset of the first attribute if it is specified on the same line as the opening of the tag
     * e.g. <tag   |attr=
     *
     */
    while (tokenSequence.moveNext()) {
        token = tokenSequence.token();
        tokenOffset = tokenSequence.offset();
        boolean isWSToken = isWSToken(token);
        
        if (thereWasWS && (!isWSToken || tagStartLine != Utilities.getLineOffset(doc, tokenOffset))) {
            if (!isWSToken && tagStartLine == Utilities.getLineOffset(doc, tokenOffset)) {
                
                shift = tokenOffset - Utilities.getRowIndent(doc, tokenOffset)
                        - Utilities.getRowStart(doc, tokenOffset);
            }
            break;
        } else if (isWSToken){
            thereWasWS = true;
        }
    }

    tokenSequence.move(originalOffset);
    tokenSequence.moveNext();

    return shift;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:TagBasedLexerFormatter.java

示例12: setStartOffset

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public void setStartOffset (int offset) {
    currentWord = null;
    currentStartOffset = (-1);
    this.ignoreBefore = offset;
    try {
        this.nextSearchOffset = Utilities.getRowStart (doc, offset);
    } catch (BadLocationException ex) {
        Logger.getLogger (AbstractTokenList.class.getName ()).log (Level.FINE, null, ex);
        this.nextSearchOffset = offset;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:AbstractTokenList.java

示例13: performActionAt

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void performActionAt(Mark mark, int mouseY) throws BadLocationException {
    if (mark != null) {
        return;
    }
    BaseDocument bdoc = Utilities.getDocument(component);
    BaseTextUI textUI = (BaseTextUI)component.getUI();

    View rootView = Utilities.getDocumentView(component);
    if (rootView == null) return;
    
    bdoc.readLock();
    try {
        int yOffset = textUI.getPosFromY(mouseY);
        FoldHierarchy hierarchy = FoldHierarchy.get(component);
        hierarchy.lock();
        try {
            Fold f = FoldUtilities.findOffsetFold(hierarchy, yOffset);
            if (f == null) {
                return;
            }
            if (f.isCollapsed()) {
                LOG.log(Level.WARNING, "Clicked on a collapsed fold {0} at {1}", new Object[] { f, mouseY });
                return;
            }
            int startOffset = f.getStartOffset();
            int endOffset = f.getEndOffset();
            
            int startY = textUI.getYFromPos(startOffset);
            int nextLineOffset = Utilities.getRowStart(bdoc, startOffset, 1);
            int nextY = textUI.getYFromPos(nextLineOffset);

            if (mouseY >= startY && mouseY <= nextY) {
                LOG.log(Level.FINEST, "Starting line clicked, ignoring. MouseY={0}, startY={1}, nextY={2}",
                        new Object[] { mouseY, startY, nextY });
                return;
            }

            startY = textUI.getYFromPos(endOffset);
            nextLineOffset = Utilities.getRowStart(bdoc, endOffset, 1);
            nextY = textUI.getYFromPos(nextLineOffset);

            if (mouseY >= startY && mouseY <= nextY) {
                // the mouse can be positioned above the marker (the fold found above), or
                // below it; in that case, the immediate enclosing fold should be used - should be the fold
                // that corresponds to the nextLineOffset, if any
                int h2 = (startY + nextY) / 2;
                if (mouseY >= h2) {
                    Fold f2 = f;
                    
                    f = FoldUtilities.findOffsetFold(hierarchy, nextLineOffset);
                    if (f == null) {
                        // fold does not exist for the position below end-of-fold indicator
                        return;
                    }
                }
                
            }
            
            LOG.log(Level.FINEST, "Collapsing fold: {0}", f);
            hierarchy.collapse(f);
        } finally {
            hierarchy.unlock();
        }
    } finally {
        bdoc.readUnlock();
    }        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:68,代码来源:CodeFoldingSideBar.java

示例14: insert

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void insert(MutableContext context) throws BadLocationException {
    if (!(context.getDocument() instanceof BaseDocument)) {
        return;
    }
    BaseDocument doc = (BaseDocument)context.getDocument();

    int insertPos = context.getCaretOffset();
    int caretPos = context.getComponent().getCaretPosition();
    int lineStartPos = Utilities.getRowStart(doc, insertPos);

    TokenHierarchy h = TokenHierarchy.get(doc);
    TokenSequence seq = h.tokenSequence();
    // check the actual tokens
    seq.move(context.getCaretOffset());
    int openOffset = followsOpeningTag(seq);
    
    int nonWhiteBefore = Utilities.getFirstNonWhiteBwd(doc, insertPos, lineStartPos);

    int lineEndPos = Utilities.getRowEnd(doc, caretPos);
    int nonWhiteAfter = Utilities.getFirstNonWhiteFwd(doc, caretPos, lineEndPos);

    // there is a opening tag preceding on the line && something following the insertion point
    if (nonWhiteBefore != -1 && nonWhiteAfter != -1 && openOffset >= 0) {
        // check that the following token (after whitespace(s)) is a 
        // opening tag
        seq.move(nonWhiteAfter);
        // now we need to position the caret at the END of the line immediately 
        // preceding the closing tag. Assuming it's already indented
        if (precedesClosingTag(seq)) {
            int startClosingLine = Utilities.getRowStart(doc, nonWhiteAfter);
            int nextLineStart = Utilities.getRowStart(doc, insertPos, 1);
            if (nextLineStart >= startClosingLine - 1) {
                insertBlankBetweenTabs(context, openOffset);
            }
            return;
        }
    }
    // if the rest of the line is blank, we must insert newline + indent, so the cursor
    // appears at the correct place
    if (nonWhiteAfter != -1) {
        // will be handled by the formatter automatically
        return;
    }

    int desiredIndent;

    if (openOffset != Integer.MIN_VALUE) {
        desiredIndent = IndentUtils.lineIndent(doc, Utilities.getRowStart(doc, Math.abs(openOffset)));
        if (openOffset >= 0) {
            desiredIndent += IndentUtils.indentLevelSize(doc);
        }
    } else {
        // align with the current line
        desiredIndent = IndentUtils.lineIndent(doc, lineStartPos);
    }
    String blankLine = "\n" + 
        IndentUtils.createIndentString(doc, desiredIndent);
    context.setText(blankLine, -1, blankLine.length(), 1, blankLine.length());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:61,代码来源:LineBreakHook.java

示例15: comment

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void comment(BaseDocument doc, int startOffset, int lineCount) throws BadLocationException {
    for (int offset = startOffset; lineCount > 0; lineCount--) {
        doc.insertString(offset, lineCommentString, null); // NOI18N
        offset = Utilities.getRowStart(doc, offset, +1);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:ExtKit.java


注:本文中的org.netbeans.editor.Utilities.getRowStart方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。