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


Java Utilities.getLineOffset方法代码示例

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


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

示例1: getLine

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** Get the line object from the given position.
* @param doc document for which the line is being retrieved
* @param offset position in the document
* @param original whether to retrieve the original line (true) before
*   the modifications were done or the current line (false)
* @return the line object
* @deprecated Replaced by more generic method having {@link javax.swing.text.Document} parameter.
*/
public static Line getLine(BaseDocument doc, int offset, boolean original) {
    DataObject dob = getDataObject(doc);
    if (dob != null) {
        LineCookie lc = (LineCookie)dob.getCookie(LineCookie.class);
        if (lc != null) {
            Line.Set lineSet = lc.getLineSet();
            if (lineSet != null) {
                try {
                    int lineOffset = Utilities.getLineOffset(doc, offset);
                    return original
                           ? lineSet.getOriginal(lineOffset)
                           : lineSet.getCurrent(lineOffset);
                } catch (BadLocationException e) {
                }

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

示例2: mouseClicked

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    if (e.isPopupTrigger()) {
        return;
    }
    e.consume();
    int position = editorPane.viewToModel(e.getPoint());
    if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON1) {
        if (position < 0) {
            return;
        }
        if (mousedIndex != -1) {
            selectedIndex = mousedIndex;
            releaseUI(true);
            return;
        }
    }
    try {
        int line = Utilities.getLineOffset((BaseDocument) doc, position) + 1;
        if (line < startLine || line > endLine) {
            releaseUI(false);
            return;
        }
    } catch (BadLocationException ex) {
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:MethodChooser.java

示例3: 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

示例4: getLine

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public int getLine() {
    try {
        return Utilities.getLineOffset(doc, getOffset());
    } catch (BadLocationException e) {
        IllegalStateException exc = new IllegalStateException();
        
        exc.initCause(e);
        
        throw exc;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:AnnotationTestUtilities.java

示例5: calculateLinePairs

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private List<LinePair> calculateLinePairs(List<JoinedTokenSequence.CodeBlock<T1>> blocks, int startOffset, int endOffset) throws BadLocationException {
    List<LinePair> lps = new ArrayList<LinePair>();
    LinePair lastOne = null;
    int startLine = Utilities.getLineOffset(getDocument(), startOffset);
    int endLine = Utilities.getLineOffset(getDocument(), endOffset);
    for (JoinedTokenSequence.CodeBlock<T1> block : blocks) {
        for (JoinedTokenSequence.TokenSequenceWrapper<T1> tsw : block.tss) {
            if (tsw.isVirtual()) {
                continue;
            }
            LinePair lp = new LinePair();
            lp.startingLine = Utilities.getLineOffset(getDocument(), LexUtilities.getTokenSequenceStartOffset(tsw.getTokenSequence()));
            lp.endingLine = Utilities.getLineOffset(getDocument(), LexUtilities.getTokenSequenceEndOffset(tsw.getTokenSequence()));
            if (lp.startingLine > endLine) {
                break;
            }
            if (lp.startingLine < startLine) {
                if (startLine <= lp.endingLine) {
                    lp.startingLine = startLine;
                } else {
                    continue;
                }
            }
            if (lp.endingLine > endLine) {
                lp.endingLine = endLine;
            }
            if (lastOne != null && lastOne.endingLine == lp.startingLine) {
                lastOne.endingLine = lp.endingLine;
            } else {
                lps.add(lp);
                lastOne = lp;
            }
        }
    }
    return lps;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:AbstractIndenter.java

示例6: debugIndentation

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private void debugIndentation(int lineOffset, List<IndentCommand> iis, String text, boolean indentable) throws BadLocationException {
    int index = Utilities.getLineOffset(getDocument(), lineOffset);
    char ch = ' ';
    if (indentable) {
        ch = '*';
    }
    System.err.println(String.format("%1c[%4d]", ch, index+1)+text);
    for (IndentCommand ii : iis) {
        System.err.println("      "+ii);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:AbstractIndenter.java

示例7: 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

示例8: getLineFromMouseEvent

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** GlyphGutter copy pasted utility method. */
private int getLineFromMouseEvent(MouseEvent e){
    int line = -1;
    if (editorUI != null) {
        try{
            JTextComponent component = editorUI.getComponent();
            BaseTextUI textUI = (BaseTextUI)component.getUI();
            int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
            line = Utilities.getLineOffset(doc, clickOffset);
        }catch (BadLocationException ble){
        }
    }
    return line;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:AnnotationBar.java

示例9: getLineFromMouseEvent

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
/** GlyphGutter copy pasted utility method. */
private int getLineFromMouseEvent(MouseEvent e){
    int line = -1;
    if (editorUI != null) {
        try {
            JTextComponent component = editorUI.getComponent();
            BaseTextUI textUI = (BaseTextUI)component.getUI();
            int clickOffset = textUI.viewToModel(component, new Point(0, e.getY()));
            line = Utilities.getLineOffset(doc, clickOffset);
        } catch (BadLocationException ble) {
            // there's not such line, return -1
        }
    }
    return line;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:AnnotationBar.java

示例10: process

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public void process(Context context) throws BadLocationException{
    if (context.isIndent()) {
        //
        // A temporary workaround for issue #178512
        BaseDocument doc = (BaseDocument)context.document();
        int firstLine = Utilities.getLineOffset(doc, context.startOffset());
        int lastLine = Utilities.getLineOffset(doc, context.endOffset());
        if (firstLine == lastLine) {
            enterPressed(context);
        } else {
            reformat(context);
        }
    } else {
        reformat(context);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:TagBasedLexerFormatter.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: calcIndents_processOpeningTag

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
private boolean calcIndents_processOpeningTag(final BaseDocument doc, final JoinedTokenSequence tokenSequence, final String tagName, final Collection<TagIndentationData> unprocessedOpeningTags, final int[] indentsWithinTags) throws BadLocationException {

        boolean thereAreMoreTokens = true;
        // format content of a tag that spans across multiple lines
        int firstTagLine = Utilities.getLineOffset(doc, tokenSequence.offset());
        int tagEndOffset = getTagEndOffset(tokenSequence, tokenSequence.offset());
        
        if (tagEndOffset == -1){
            return true; // unterminated tag, ignore
        }
        
        int lastTagLine = Utilities.getLineOffset(doc, tagEndOffset);

        TagIndentationData tagData = new TagIndentationData(tagName, lastTagLine);
        unprocessedOpeningTags.add(tagData);

        if (firstTagLine < lastTagLine) {
            // performance!
            int indentWithinTag = getIndentForTagParameter(doc, tokenSequence, tokenSequence.offset());

            for (int i = firstTagLine + 1; i <= lastTagLine; i++) {
                indentsWithinTags[i] = indentWithinTag;
            }
        }

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

示例13: invokeDefaultAction

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
boolean invokeDefaultAction(boolean onlyActive) {
    JTextComponent comp = getComponent();
    if (comp == null) {
        Logger.getLogger(HintsUI.class.getName()).log(Level.WARNING, "HintsUI.invokeDefaultAction called, but comp == null");
        return false;
    }

    Document doc = comp.getDocument();

    cancel.set(false);
    
    if (doc instanceof BaseDocument) {
        try {
            Rectangle carretRectangle = comp.modelToView(comp.getCaretPosition());
            int line = Utilities.getLineOffset((BaseDocument) doc, comp.getCaretPosition());
            FixData fixes;
            String description;

            if (!onlyActive) {
                refresh(doc, comp.getCaretPosition());
                AnnotationHolder holder = getAnnotationHolder(doc);
                Pair<FixData, String> fixData = holder != null ? holder.buildUpFixDataForLine(line) : null;

                if (fixData == null) return false;

                fixes = fixData.first();
                description = fixData.second();
            } else {
                AnnotationDesc activeAnnotation = ((BaseDocument) doc).getAnnotations().getActiveAnnotation(line);
                if (activeAnnotation == null) {
                    return false;
                }
                String type = activeAnnotation.getAnnotationType();
                if (!fixableAnnotations.contains(type) && onlyActive) {
                    return false;
                }
                if (onlyActive) {
                    refresh(doc, comp.getCaretPosition());
                }
                Annotations annotations = ((BaseDocument) doc).getAnnotations();
                AnnotationDesc desc = annotations.getAnnotation(line, type);
                ParseErrorAnnotation annotation = null;
                if (desc != null) {
                    annotations.frontAnnotation(desc);
                    annotation = findAnnotation(doc, desc, line);
                }

                if (annotation == null) {
                    return false;
                }
                
                fixes = annotation.getFixes();
                description = annotation.getDescription();
            }

            Point p = comp.modelToView(Utilities.getRowStartFromLineOffset((BaseDocument) doc, line)).getLocation();
            p.y += carretRectangle.height;
            if(comp.getParent() instanceof JViewport) {
                p.x += ((JViewport)comp.getParent()).getViewPosition().x;
            }
            if(comp.getParent() instanceof JLayeredPane &&
                    comp.getParent().getParent() instanceof JViewport) {
                p.x += ((JViewport)comp.getParent().getParent()).getViewPosition().x;
            }

            showPopup(fixes, description, comp, p);

            return true;
        } catch (BadLocationException ex) {
            ErrorManager.getDefault().notify(ex);
        }
    }

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

示例14: resolvePlaceholder

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@NbBundle.Messages({
    "# {0} - number of lines of folded code",
    "FMT_contentSummary={0} {0,choice,0#lines|1#line|1<lines}"
})
private String resolvePlaceholder(String text, int at) {
    if ((options & 3) == 0) {
        return text;
    }
    Document d = getDocument();
    if (!(d instanceof BaseDocument)) {
        return null;
    }
    BaseDocument bd = (BaseDocument)d;
    CharSequence contentSeq = ""; // NOI18N
    String summary = ""; // NOI18N
    
    int mask = options;
    try {
        if ((options & 1) > 0) {
                contentSeq = FoldContentReaders.get().readContent(
                       org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(textComponent),
                       d, 
                       fold, 
                       fold.getType().getTemplate());
                if (contentSeq == null) {
                    mask &= ~1;
                }
        }
        if ((options & 2) > 0) {
            int start = fold.getStartOffset();
            int end = fold.getEndOffset();
            int startLine = Utilities.getLineOffset(bd, start);
            int endLine = Utilities.getLineOffset(bd, end) + 1;
            
            if (endLine <= startLine + 1) {
                mask &= ~2;
            } else {
                summary = FMT_contentSummary((endLine - startLine));
            }
        }
    } catch (BadLocationException ex) {
    }
    if (mask == 0) {
        return text;
    }
    String replacement = NbBundle.getMessage(FoldView.class, "FMT_ContentPlaceholder_" + (mask & 3), contentSeq, summary); // NOI18N
    StringBuilder sb = new StringBuilder(text.length() + replacement.length());
    sb.append(text.subSequence(0, at));
    sb.append(replacement);
    sb.append(text.subSequence(at + FoldTemplate.CONTENT_PLACEHOLDER.length(), text.length()));
    return sb.toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:FoldView.java

示例15: getNumberOfLines

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
protected static int getNumberOfLines(BaseDocument doc) throws BadLocationException{
    return Utilities.getLineOffset(doc, doc.getLength() - 1) + 1;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:4,代码来源:TagBasedFormatter.java


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