Java Code Examples for org.openide.cookies.EditorCookie#getLineSet()

The following examples show how to use org.openide.cookies.EditorCookie#getLineSet() . 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: BookmarkUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void openEditor(EditorCookie ec, int lineIndex) {
    Line.Set lineSet = ec.getLineSet();
    if (lineSet != null) {
        try {
            Line line = lineSet.getCurrent(lineIndex);
            if (line != null) {
                line.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
            }
        } catch (IndexOutOfBoundsException ex) {
            // attempt at least to open the editor
            ec.open();
            // expected, bookmark contains an invalid line
            StatusDisplayer.getDefault().setStatusText(
                    NbBundle.getMessage(BookmarkUtils.class, "MSG_InvalidLineNumnber", lineIndex));
        }
        JEditorPane[] panes = ec.getOpenedPanes();
        if (panes.length > 0) {
            panes[0].requestFocusInWindow();
        }
    }
}
 
Example 2
Source File: EditorContextDispatcher.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Get the line of the caret in the most recent editor.
 * This returns the current line in the current editor if there's one,
 * or a line of the caret in the editor, that was most recently active.
 * @return the line or <code>null</code> when there was no recent active editor.
 */
public Line getMostRecentLine() {
    EditorCookie e = getMostRecentEditorCookie ();
    if (e == null) return null;
    JEditorPane ep = getMostRecentEditor ();
    if (ep == null) return null;
    StyledDocument d = e.getDocument ();
    if (d == null) return null;
    Caret caret = ep.getCaret ();
    if (caret == null) return null;
    int lineNumber = NbDocument.findLineNumber(d, caret.getDot());
    Line.Set lineSet = e.getLineSet();
    try {
        return lineSet.getCurrent(lineNumber);
    } catch (IndexOutOfBoundsException ex) {
        return null;
    }
}