public void lock() throws IOException { if (!locked.getAndSet(true)) { document.atomicLock(); boolean success = false; try { doParse(fo, document, false); success = true; } finally { if (!success) { document.atomicUnlock(); } } } }
public void undo() throws CannotUndoException { atomicLock(); try { super.undo(); } finally { atomicUnlockImpl(true); } }
public void redo() throws CannotRedoException { atomicLock(); try { super.redo(); } finally { atomicUnlockImpl(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; }
/** * Runs the runnable under write lock. If there are any excpeptions thrown * during the processing of the runnable, all the document modifications are * rolled back automatically. */ public void runAtomicAsUser(Runnable r) { boolean completed = false; atomicLock(); try { r.run(); completed = true; } finally { try { if (!completed) { breakAtomicLock(); } } finally { atomicUnlock(); } } }
/** Runs the runnable under write lock. * If there are any excpeptions thrown during the processing of the runnable, * all the document modifications are rolled back automatically. */ public void runAtomicAsUser(Runnable r) { boolean completed = false; atomicLock(); try { r.run(); completed = true; } finally { try { if (!completed) { breakAtomicLock(); } } finally { atomicUnlock(); } } }
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; }
/** Generic implementation, behaves just as described in specification * in substituteCommonText() - removes <CODE>len</CODE> * characters at <CODE>offset</CODE> out of document and then inserts * <CODE>subLen<CODE> characters from the <CODE>text</CODE> */ public boolean substituteCommonText( JTextComponent c, int offset, int len, int subLen ) { BaseDocument doc = (BaseDocument)c.getDocument(); try { doc.atomicLock(); try { doc.remove( offset, len ); doc.insertString( offset, text.substring( 0, subLen ), null); } finally { doc.atomicUnlock(); } } catch( BadLocationException exc ) { return false; //not sucessfull } return true; }
/** Generic implementation, behaves just as described in specification * in substituteCommonText() - removes <CODE>len</CODE> * characters at <CODE>offset</CODE> out of document and then inserts * <CODE>subLen<CODE> characters from the <CODE>text</CODE> */ public boolean substituteCommonText( JTextComponent c, int offset, int len, int subLen ) { BaseDocument doc = (BaseDocument)c.getDocument(); try { doc.atomicLock(); try { doc.remove( offset, len ); doc.insertString( offset, text.substring( 0, subLen ), null); } finally { doc.atomicUnlock(); } } catch( BadLocationException exc ) { return false; //not sucessfull } return true; }
/** * Generic implementation, behaves just as described in specification in * substituteCommonText() - removes <CODE>len</CODE> characters at * <CODE>offset</CODE> out of document and then inserts <CODE>subLen<CODE> * characters from the <CODE>text</CODE> */ public boolean substituteCommonText(JTextComponent c, int offset, int len, int subLen) { BaseDocument doc = (BaseDocument) c.getDocument(); try { doc.atomicLock(); try { doc.remove(offset, len); doc.insertString(offset, text.substring(0, subLen), null); } finally { doc.atomicUnlock(); } } catch (BadLocationException exc) { return false; // not sucessfull } return true; }
/** Generic implementation, behaves just as described in specification * in substituteText() - removes <CODE>len</CODE> characters * at <CODE>offset</CODE> out of document and then inserts * whole <CODE>text</CODE>. Ignores <CODE>shift</CODE> argument. */ public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { BaseDocument doc = (BaseDocument)c.getDocument(); try { doc.atomicLock(); try { String textToReplace = doc.getText(offset, len); if (text.equals(textToReplace)) return false; doc.remove( offset, len ); doc.insertString( offset, text, null); } finally { doc.atomicUnlock(); } } catch( BadLocationException exc ) { return false; //not sucessfull } return true; }
/** * Generic implementation, behaves just as described in specification in * substituteText() - removes <CODE>len</CODE> characters at <CODE>offset</CODE> * out of document and then inserts whole <CODE>text</CODE>. Ignores * <CODE>shift</CODE> argument. */ public boolean substituteText(JTextComponent c, int offset, int len, boolean shift) { BaseDocument doc = (BaseDocument) c.getDocument(); try { doc.atomicLock(); try { doc.remove(offset, len); doc.insertString(offset, text, null); } finally { doc.atomicUnlock(); } } catch (BadLocationException exc) { return false; // not sucessfull } return true; }
protected void substituteText(JTextComponent c, int offset, int len, String toAdd) { BaseDocument doc = (BaseDocument) c.getDocument(); CharSequence prefix = getInsertPrefix(); String text = prefix.toString(); if (toAdd != null) { text += toAdd; } doc.atomicLock(); try { Position position = doc.createPosition(offset); doc.remove(offset, len); doc.insertString(position.getOffset(), text.toString(), null); } catch (BadLocationException ble) { // nothing can be done to update } finally { doc.atomicUnlock(); } }
public boolean substituteText(JTextComponent c, int offset, int len, boolean shift) { BaseDocument doc = (BaseDocument)c.getDocument(); String text = getReplaceText(); int selectionStartOffset = -1; int selectionEndOffset = -1; if (text != null) { // Update the text doc.atomicLock(); try { String textToReplace = doc.getText(offset, len); if (text.equals(textToReplace)) return false; doc.remove(offset, len); doc.insertString(offset, text, null); if (selectionStartOffset >= 0) { c.select(offset + selectionStartOffset, offset + selectionEndOffset); } } catch (BadLocationException e) { // Can't update } finally { doc.atomicUnlock(); } } return true; }
/** Generic implementation, behaves just as described in specification * in substituteText() - removes <CODE>len</CODE> characters * at <CODE>offset</CODE> out of document and then inserts * whole <CODE>text</CODE>. Ignores <CODE>shift</CODE> argument. */ public boolean substituteText( JTextComponent c, int offset, int len, boolean shift ) { BaseDocument doc = (BaseDocument)c.getDocument(); try { doc.atomicLock(); try { CharSequence textToReplace = DocumentUtilities.getText(doc, offset, len); if (CharSequenceUtilities.textEquals(text, textToReplace)) return false; doc.remove( offset, len ); doc.insertString( offset, text, null); } finally { doc.atomicUnlock(); } } catch( BadLocationException exc ) { return false; //not sucessfull } return true; }
/** * Update the text in response to pressing TAB key. * * @return whether the text was successfully updated */ public boolean substituteCommonText(int dataIndex) { BaseDocument doc = (BaseDocument) component.getDocument(); try { String prefix = doc.getText(substituteOffset, substituteLength); String commonText = getCommonText(prefix); if (commonText != null) { if (substituteExp != null) { if ((substituteExp.getExpID() == JCExpression.METHOD_OPEN) || (substituteExp.getExpID() == JCExpression.METHOD)) return true; } doc.atomicLock(); try { doc.remove(substituteOffset, substituteLength); doc.insertString(substituteOffset, commonText, null); } finally { doc.atomicUnlock(); } } } catch (BadLocationException e) { // no updating } return true; }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } BaseDocument doc = (BaseDocument)target.getDocument(); Caret caret = target.getCaret(); int dotPos = caret.getDot(); doc.atomicLock(); try{ target.replaceSelection(""); int newDotPos = dotPos; // dot stays where it was doc.getFormatter().indentNewLine(doc, dotPos); // newline caret.setDot(newDotPos); } finally { doc.atomicUnlock(); } } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { if (target != null) { if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } target.replaceSelection(""); Caret caret = target.getCaret(); BaseDocument doc = (BaseDocument)target.getDocument(); doc.atomicLock(); try{ Object cookie = beforeBreak(target, doc, caret); int dotPos = caret.getDot(); int newDotPos = doc.getFormatter().indentNewLine(doc, dotPos); caret.setDot(newDotPos); afterBreak(target, doc, caret, cookie); } finally { doc.atomicUnlock(); } } }
/** * Change the indent of the given row. Document is atomically locked during * this operation. */ public void changeRowIndent(BaseDocument doc, int pos, int newIndent) throws BadLocationException { doc.atomicLock(); try { if (newIndent < 0) { newIndent = 0; } int firstNW = Utilities.getRowFirstNonWhite(doc, pos); if (firstNW == -1) { // valid first non-blank firstNW = Utilities.getRowEnd(doc, pos); } int bolPos = Utilities.getRowStart(doc, pos); doc.remove(bolPos, firstNW - bolPos); // !!! indent by spaces/tabs doc.insertString(bolPos, getIndentString(doc, newIndent), null); } finally { doc.atomicUnlock(); } }
public void actionPerformed(ActionEvent evt, JTextComponent target) { // shift-enter while editing aka startNewLineAction if (!target.isEditable() || !target.isEnabled()) { target.getToolkit().beep(); return; } BaseDocument doc = (BaseDocument)target.getDocument(); doc.atomicLock(); try { target.replaceSelection(""); //NOI18N Caret caret = target.getCaret(); // insert and remove '-' to remember caret // position int dotpos = caret.getDot(); doc.insertString(dotpos,"-",null); //NOI18N doc.remove(dotpos,1); int eolDot = Utilities.getRowEnd(target, caret.getDot()); int newDotPos = doc.getFormatter().indentNewLine(doc,eolDot); caret.setDot(newDotPos); } catch (BadLocationException ex) { ex.printStackTrace(); } finally{ doc.atomicUnlock(); } } }