@Override public void run() { try { classDoc.remove(startReplacement, lengthReplacement); classDoc.insertString(startReplacement, ";", null); // NOI18N } catch (BadLocationException e) { // Can't update } } });
private static void generateFieldDoc(BaseDocument doc, int offset, int indent, ParserResult info, FieldsDeclaration decl) throws BadLocationException { StringBuilder toAdd = new StringBuilder(); generateDocEntry(doc, toAdd, "@var", indent, null, null); doc.insertString(offset - 1, toAdd.toString(), null); }
private static void generateGlobalVariableDoc(BaseDocument doc, int offset, int indent, String indexName, String type) throws BadLocationException { StringBuilder toAdd = new StringBuilder(); generateDocEntry(doc, toAdd, "@global", indent, "$GLOBALS['" + indexName + "']", type); toAdd.append("\n").append(IndentUtils.createIndentString(doc, indent)); toAdd.append(" * ").append("@name $").append(indexName); doc.insertString(offset - 1, toAdd.toString(), null); }
/** * Hook to insert the given string at the given position into * the given document in insert-mode, no selection, writeable * document. Designed to be overridden by subclasses that want * to intercept inserted characters. */ protected void insertString(BaseDocument doc, int dotPos, Caret caret, String str, boolean overwrite) throws BadLocationException { if (overwrite) doc.remove(dotPos, 1); doc.insertString(dotPos, str, null); }
@Override public void run() { try { String docText = src.getText(0, src.getLength()); dest.insertString(0, docText, null); } catch(BadLocationException ble) { Exceptions.printStackTrace(ble); retVal[0] = false; } } });
@Override public void run() { try { int insertOffset = openTag.from() + "<".length() + openTag.name().length(); int documentInsertOffset = snapshot.getOriginalOffset(insertOffset); document.insertString(documentInsertOffset, insertText.toString(), null); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } }
@Override public void run() { try { //TODO apply just changes via diff! document.remove(0, document.getLength()); document.insertString(0, newContent, null); } catch (BadLocationException ex) { bleRef.set(ex); } }
@Override public void run() { try { String pfx = doc.getText(anchor, caretOffset - anchor); doc.remove(caretOffset - pfx.length(), pfx.length()); doc.insertString(caretOffset - pfx.length(), value, null); component.setCaretPosition(component.getCaretPosition() - backOffset); } catch (BadLocationException e) { Exceptions.printStackTrace(e); } } });
@Override public void run() { try { Position position = doc.createPosition(offset); doc.remove(offset, len); doc.insertString(position.getOffset(), finalText.toString(), null); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } });
boolean replaceText( JTextComponent component, String text ) { BaseDocument doc = (BaseDocument)component.getDocument(); doc.atomicLock(); try { doc.remove( offset, length ); doc.insertString( offset, text, null); } catch( BadLocationException exc ) { return false; //not sucessfull } finally { doc.atomicUnlock(); } return true; }
boolean replaceText(JTextComponent component, String text) { BaseDocument doc = (BaseDocument) component.getDocument(); doc.atomicLock(); try { doc.remove(offset, length); doc.insertString(offset, text, null); } catch (BadLocationException exc) { return false; // not sucessfull } finally { doc.atomicUnlock(); } return true; }
/** Read from some reader and insert into document */ static void read(BaseDocument doc, Reader reader, int pos) throws BadLocationException, IOException { int readBufferSize = ((Integer)doc.getProperty( SettingsNames.READ_BUFFER_SIZE)).intValue(); LineSeparatorConversion.ToLineFeed toLF = new LineSeparatorConversion.ToLineFeed(reader, readBufferSize); Segment text = toLF.nextConverted(); while (text != null) { doc.insertString(pos, new String(text.array, text.offset, text.count), null); pos += text.count; text = toLF.nextConverted(); } }
private static void generateFunctionDoc(BaseDocument doc, int offset, int indent, ParserResult info, FunctionDeclaration decl) throws BadLocationException { StringBuilder toAdd = new StringBuilder(); ScannerImpl i = new ScannerImpl(info, decl); i.scan(decl); addVariables(doc, toAdd, "@global", indent, i.globals); addVariables(doc, toAdd, "@staticvar", indent, i.staticvars); addVariables(doc, toAdd, "@param", indent, i.params); if (i.hasReturn) { generateDocEntry(doc, toAdd, "@return", indent, null, i.returnType); } addVariables(doc, toAdd, "@throws", indent, i.throwsExceptions); doc.insertString(offset, toAdd.toString(), null); }
public boolean expandString(char typedChar, String expandStr, ActionEvent evt) throws BadLocationException { if (expandString(expandStr, evt)) { if (addTypedAcceptor.accept(typedChar)) { int dotPos = editorUI.getComponent().getCaret().getDot(); editorUI.getDocument().insertString(dotPos, String.valueOf(typedChar), null); } return true; } return false; }
public boolean expandString(char typedChar, String expandStr, ActionEvent evt) throws BadLocationException { if (expandString(expandStr, evt)) { if (addTypedAcceptor.accept(typedChar)) { int dotPos = editorUI.getComponent().getCaret().getDot(); editorUI.getDocument().insertString(dotPos, String.valueOf(typedChar), null); } return true; } return false; }
protected void transaction() throws BadLocationException { DocumentElement de = checkIntegrity(id); DocumentElement previousChild = getPreviousTagSibling(de); if (previousChild != null) { BaseDocument doc = getDoc(); int startOffset = de.getStartOffset(); int length = de.getEndOffset() - startOffset + 1; String elemText = getElemTextWithId(doc, de, id); int insertOffset = previousChild.getStartOffset(); assert startOffset > insertOffset : "Offset overlap #4" + insertOffset + "," + startOffset; //NOI18N doc.remove(startOffset, length); doc.insertString(insertOffset, elemText, null); } } });
public void run() { try { final BaseDocument doc = (BaseDocument)txt.getDocument(); final int s = Utilities.getRowStartFromLineOffset(doc, getSelectionStartLine(txt) - 1); final int e = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, getSelectionEndLine(txt) - 1)); doc.insertString(e, "\n//#enddebug", null); //NOI18N doc.insertString(s, "//#mdebug\n", null); //NOI18N txt.setSelectionEnd(txt.getSelectionStart()); } catch (BadLocationException ble) { ErrorManager.getDefault().notify(ble); } RecommentAction.actionPerformed(txt); } });
public void run() { try { final BaseDocument doc = (BaseDocument)txt.getDocument(); final int s = Utilities.getRowStartFromLineOffset(doc, getSelectionStartLine(txt) - 1); final int e = Utilities.getRowEnd(txt, Utilities.getRowStartFromLineOffset(doc, getSelectionEndLine(txt) - 1)); final String text = doc.getText(s, e-s); doc.insertString(e, "\n//#else\n" + text + "\n//#endif", null); //NOI18N doc.insertString(s, "//#if \n", null); //NOI18N txt.setSelectionStart(s + 6); txt.setSelectionEnd(s + 6); } catch (BadLocationException ble) { ErrorManager.getDefault().notify(ble); } RecommentAction.actionPerformed(txt); } });
protected void transaction() throws BadLocationException { DocumentElement de = checkIntegrity(id); DocumentElement firstChild = getFirstTagChild(de.getParentElement().getChildren()); if (de != firstChild) { BaseDocument doc = getDoc(); int startOffset = de.getStartOffset(); int length = de.getEndOffset() - startOffset + 1; String elemText = getElemTextWithId(doc, de, id); int insertOffset = firstChild.getStartOffset(); assert insertOffset < startOffset : "Offset overlap #1" + insertOffset + "," + startOffset; //NOI18N doc.remove(startOffset, length); doc.insertString(insertOffset, elemText, null); } } });
protected void transaction() throws BadLocationException { DocumentElement de = checkIntegrity(id); DocumentElement lastChild = getLastTagChild(de.getParentElement().getChildren()); if (de != lastChild) { BaseDocument doc = getDoc(); int startOffset = de.getStartOffset(); int length = de.getEndOffset() - startOffset + 1; String elemText = getElemTextWithId(doc, de, id); int insertOffset = lastChild.getEndOffset() + 1; assert startOffset < insertOffset : "Offset overlap #2" + insertOffset + "," + startOffset; //NOI18N doc.insertString(insertOffset, elemText, null); doc.remove(startOffset, length); } } });