Search in sources :

Example 1 with BaseDocument

use of org.netbeans.editor.BaseDocument in project blue by kunstmusik.

the class RemoveSemiColonLineCommentAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }
        final Caret caret = target.getCaret();
        final BaseDocument doc = (BaseDocument) target.getDocument();
        doc.runAtomicAsUser(() -> {
            try {
                int startPos;
                int endPos;
                if (Utilities.isSelectionShowing(caret)) {
                    startPos = Utilities.getRowStart(doc, target.getSelectionStart());
                    endPos = target.getSelectionEnd();
                    if (endPos > 0 && Utilities.getRowStart(doc, endPos) == endPos) {
                        endPos--;
                    }
                    endPos = Utilities.getRowEnd(doc, endPos);
                } else {
                    // selection not visible
                    startPos = Utilities.getRowStart(doc, caret.getDot());
                    endPos = Utilities.getRowEnd(doc, caret.getDot());
                }
                int lineCount = Utilities.getRowCount(doc, startPos, endPos);
                uncomment(doc, startPos, lineCount);
            } catch (BadLocationException e) {
                target.getToolkit().beep();
            }
        });
    }
}
Also used : BaseDocument(org.netbeans.editor.BaseDocument) Caret(javax.swing.text.Caret) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with BaseDocument

use of org.netbeans.editor.BaseDocument in project blue by kunstmusik.

the class ClojureBracesMatcher method findOrigin.

@Override
public int[] findOrigin() throws InterruptedException, BadLocationException {
    int[] ret = null;
    ((AbstractDocument) context.getDocument()).readLock();
    try {
        BaseDocument doc = (BaseDocument) context.getDocument();
        int offset = context.getSearchOffset();
        TokenSequence<? extends ClojureTokenId> ts = ClojureLexUtilities.getClojureTokenSequence(doc, offset);
        if (ts != null) {
            ts.move(offset);
            if (ts.moveNext()) {
                Token<? extends ClojureTokenId> token = ts.token();
                if (token != null) {
                    TokenId id = token.id();
                    int ordinal = id.ordinal();
                    for (BracePair bp : bracePairs) {
                        if (ordinal == bp.open) {
                            ret = new int[] { ts.offset(), ts.offset() + token.length() };
                            break;
                        } else if (ordinal == bp.close) {
                            ret = new int[] { ts.offset(), ts.offset() + token.length() };
                            break;
                        }
                    }
                }
            }
        }
    } finally {
        ((AbstractDocument) context.getDocument()).readUnlock();
    }
    return ret;
}
Also used : AbstractDocument(javax.swing.text.AbstractDocument) BaseDocument(org.netbeans.editor.BaseDocument) TokenId(org.netbeans.api.lexer.TokenId)

Example 3 with BaseDocument

use of org.netbeans.editor.BaseDocument in project enclojure by EricThorsen.

the class ClojureFoldManager method initFolds.

public void initFolds(FoldHierarchyTransaction tran) {
    Document doc = getOperation().getHierarchy().getComponent().getDocument();
    if (doc instanceof BaseDocument) {
        this.document = (BaseDocument) doc;
    }
    updateFolds(document, tran);
}
Also used : BaseDocument(org.netbeans.editor.BaseDocument) BaseDocument(org.netbeans.editor.BaseDocument) Document(javax.swing.text.Document)

Example 4 with BaseDocument

use of org.netbeans.editor.BaseDocument in project blue by kunstmusik.

the class BlueNbUtilities method convertEditorForMimeType.

/**
 * Returns the original JEditorPane or the Netbeans Extended
 * Editor for the mimeType
 */
public static Component convertEditorForMimeType(JEditorPane editor, String mimeType) {
    Component retVal = editor;
    EditorKit kit = CloneableEditorSupport.getEditorKit(mimeType);
    editor.setEditorKit(kit);
    editor.setDocument(kit.createDefaultDocument());
    BaseDocument doc = Utilities.getDocument(editor);
    if (doc instanceof NbDocument.CustomEditor) {
        NbDocument.CustomEditor ce = (NbDocument.CustomEditor) doc;
        retVal = ce.createEditor(editor);
    } else {
        retVal = new JScrollPane(retVal);
    }
    return retVal;
}
Also used : EditorKit(javax.swing.text.EditorKit) JScrollPane(javax.swing.JScrollPane) BaseDocument(org.netbeans.editor.BaseDocument) NbDocument(org.openide.text.NbDocument) Component(java.awt.Component)

Example 5 with BaseDocument

use of org.netbeans.editor.BaseDocument in project blue by kunstmusik.

the class AddSemiColonLineCommentAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }
        final Caret caret = target.getCaret();
        final BaseDocument doc = (BaseDocument) target.getDocument();
        doc.runAtomicAsUser(() -> {
            try {
                int startPos;
                int endPos;
                if (org.netbeans.editor.Utilities.isSelectionShowing(caret)) {
                    startPos = org.netbeans.editor.Utilities.getRowStart(doc, target.getSelectionStart());
                    endPos = target.getSelectionEnd();
                    if (endPos > 0 && org.netbeans.editor.Utilities.getRowStart(doc, endPos) == endPos) {
                        endPos--;
                    }
                    endPos = org.netbeans.editor.Utilities.getRowEnd(doc, endPos);
                } else {
                    // selection not visible
                    startPos = org.netbeans.editor.Utilities.getRowStart(doc, caret.getDot());
                    endPos = org.netbeans.editor.Utilities.getRowEnd(doc, caret.getDot());
                }
                int lineCount = org.netbeans.editor.Utilities.getRowCount(doc, startPos, endPos);
                comment(doc, startPos, lineCount);
            } catch (BadLocationException e) {
                target.getToolkit().beep();
            }
        });
    }
}
Also used : BaseDocument(org.netbeans.editor.BaseDocument) Caret(javax.swing.text.Caret) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

BaseDocument (org.netbeans.editor.BaseDocument)6 AbstractDocument (javax.swing.text.AbstractDocument)2 BadLocationException (javax.swing.text.BadLocationException)2 Caret (javax.swing.text.Caret)2 TokenId (org.netbeans.api.lexer.TokenId)2 OffsetRange (blue.ui.editor.support.OffsetRange)1 Component (java.awt.Component)1 JScrollPane (javax.swing.JScrollPane)1 Document (javax.swing.text.Document)1 EditorKit (javax.swing.text.EditorKit)1 NbDocument (org.openide.text.NbDocument)1