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();
}
});
}
}
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;
}
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);
}
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;
}
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();
}
});
}
}
Aggregations