@Override public void run() { try { doc.remove(expression.getStartOffset(), exprText.length()); doc.insertString(expression.getStartOffset(), aName, null); Position exprStart = NbDocument.createPosition(doc, expression.getStartOffset(), Position.Bias.Forward); Position exprEnd = NbDocument.createPosition(doc, expression.getStartOffset() + aName.length(), Position.Bias.Backward); doc.insertString(st.getStartOffset(), text, null); Position stmtStart = NbDocument.createPosition(doc, st.getStartOffset() + typeTextPrefix.length(), Position.Bias.Forward); Position stmtEnd = NbDocument.createPosition(doc, st.getStartOffset() + typeTextPrefix.length() +aName.length(), Position.Bias.Backward); changeInfo.add(fo, stmtStart, stmtEnd); changeInfo.add(fo, exprStart, exprEnd); Indent indent = Indent.get(doc); indent.lock(); try { indent.reindent(st.getStartOffset()+text.length()+1); } finally { indent.unlock(); } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } });
protected boolean overlapsGuardedBlocks(final JTextComponent c) { Document d = c.getDocument(); if (!(d instanceof StyledDocument)) return false; GuardedSectionManager man = GuardedSectionManager.getInstance((StyledDocument)d); if (man == null) return false; for (GuardedSection s : man.getGuardedSections()) try { if (s.contains(NbDocument.createPosition(d, c.getSelectionStart(), Bias.Backward), false) || s.contains(NbDocument.createPosition(d, c.getSelectionEnd(), Bias.Forward), false) || (s.getStartPosition().getOffset() >= c.getSelectionStart() && s.getEndPosition().getOffset() <= c.getSelectionEnd())) return true; } catch (BadLocationException ble) {} return false; } }
public void run() { if (isCanceled()) { return; } int len = doc.getLength(); if (startOffsetFinal > len || endOffsetFinal > len) { if (!isCanceled() && ERR.isLoggable(ErrorManager.WARNING)) { ERR.log(ErrorManager.WARNING, "document changed, but not canceled?" ); ERR.log(ErrorManager.WARNING, "len = " + len ); ERR.log(ErrorManager.WARNING, "startOffset = " + startOffsetFinal ); ERR.log(ErrorManager.WARNING, "endOffset = " + endOffsetFinal ); } cancel(); return; } try { result[0] = NbDocument.createPosition(doc, startOffsetFinal, Bias.Forward); result[1] = NbDocument.createPosition(doc, endOffsetFinal, Bias.Backward); } catch (BadLocationException e) { ERR.notify(ErrorManager.ERROR, e); } } });
Position start = NbDocument.createPosition(doc, h.getStart(), Bias.Backward); Position end = NbDocument.createPosition(doc, h.getEnd(), Bias.Forward); MutablePositionRegion current = new MutablePositionRegion(start, end);
Position start = NbDocument.createPosition(doc, h.getStartOffset(), Bias.Backward); Position end = NbDocument.createPosition(doc, h.getEndOffset(), Bias.Forward); MutablePositionRegion current = new MutablePositionRegion(start, end);
p = NbDocument.createPosition( mgr.getDoc(), offset, argInsertAfter ? Position.Bias.Backward : Position.Bias.Forward retObject = NbDocument.createPosition( mgr.getDoc(), NbDocument.findLineOffset(mgr.getDoc(), argLine) + argColumn, argInsertAfter ? Position.Bias.Backward : Position.Bias.Forward
p = NbDocument.createPosition (mgr.getDoc (), offset, argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); } catch (BadLocationException e) { retObject = NbDocument.createPosition (mgr.getDoc (), NbDocument.findLineOffset (mgr.getDoc (), argLine) + argColumn, argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward);
p = NbDocument.createPosition (mgr.getDoc (), offset, argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward); } catch (BadLocationException e) { retObject = NbDocument.createPosition (mgr.getDoc (), NbDocument.findLineOffset (mgr.getDoc (), argLine) + argColumn, argInsertAfter ? Position.Bias.Forward : Position.Bias.Backward);