Java Code Examples for org.netbeans.editor.Utilities#getRowCount()

The following examples show how to use org.netbeans.editor.Utilities#getRowCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: AnnotationView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
int[] getLinesSpan(int currentLine) {
    AbstractDocument adoc = doc;
    if (adoc != null)
        adoc.readLock();
    try {
        double componentHeight = getComponentHeight();
        double usableHeight = getUsableHeight();

        double position  = _modelToView(currentLine, componentHeight, usableHeight);

        if (position == (-1))
            return new int[] {currentLine, currentLine};

        int    startLine = currentLine;
        int    endLine   = currentLine;

        while (position == _modelToView(startLine - 1, componentHeight, usableHeight) && startLine > 0)
            startLine--;

        while ((endLine + 1) < Utilities.getRowCount(doc) && position == _modelToView(endLine + 1, componentHeight, usableHeight))
            endLine++;

        return new int[] {startLine, endLine};
    } finally {
        if (adoc != null)
            adoc.readUnlock();
    }
}
 
Example 3
Source File: EmbeddedSectionsHighlighting.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean moveNext() {
    synchronized (EmbeddedSectionsHighlighting.this) {
        if (checkVersion()) {
            if (sequence == null) {
                sequence = scanner.tokenSequence(GspLexerLanguage.getLanguage());

                if (sequence == null) {
                    sectionStart = -1;
                    sectionEnd = -1;
                    finished = true;

                    return false;
                }

                sequence.move(startOffset);
            }

            int delimiterSize = 0;
            while (sequence.moveNext() && sequence.offset() < endOffset) {
                if (sequence.token().id().isDelimiter()) {
                    // opening delimiters can have different lenght
                    delimiterSize = sequence.token().length();
                } else {
                    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;
    }
}
 
Example 4
Source File: EmbeddedSectionsHighlighting.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public boolean moveNext() {
    synchronized (EmbeddedSectionsHighlighting.this) {
        if (checkVersion()) {
            if (sequence == null) {
                if(!scanner.isActive()) {
                    return false; //token hierarchy inactive already
                }
                sequence = scanner.tokenSequence();
                sequence.move(startOffset);
            }

            while (sequence.moveNext() && sequence.offset() < endOffset) {
                if (javascripletBackground != null && sequence.token().id() == JspTokenId.SCRIPTLET) {
                    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 - 2 &&
                                isWhitespace(document, firstLineStartOffset, sectionStart - 2)) // always preceeded by '<%' hence -2
                            {
                                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();
                            }
                            
                            if (sectionEnd + 2 >= lastLineEndOffset || // unclosed section
                                isWhitespace(document, sectionEnd + 2, lastLineEndOffset)) // always succeeded by '%>' hence +2
                            {
                                sectionEnd = lastLineEndOffset;
                            }
                        }
                        
                        attributeSet = javascripletBackground;
                        return true;
                        
                    } catch (BadLocationException ble) {
                        LOG.log(Level.WARNING, null, ble);
                    }
                    
                    
                } else if (expressionLanguageBackground != null && sequence.token().id() == JspTokenId.EL) {
                    sectionStart = sequence.offset();
                    sectionEnd = sequence.offset() + sequence.token().length();
                    attributeSet = expressionLanguageBackground;
                    
                    return true;
                }
            }
        }
        
        sectionStart = -1;
        sectionEnd = -1;
        finished = true;

        return false;
    }
}
 
Example 5
Source File: GotoDialogSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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;
}
 
Example 6
Source File: EmbeddedSectionsHighlighting.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@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;
    }
}