use of javax.swing.undo.UndoableEdit in project groovy-core by groovy.
the class TextUndoManager method undoableEditHappened.
public void undoableEditHappened(UndoableEditEvent uee) {
UndoableEdit edit = uee.getEdit();
boolean undoable = canUndo();
long editTime = System.currentTimeMillis();
if (firstModified == 0 || editTime - compoundEdit.editedTime() > 700) {
compoundEdit.end();
compoundEdit = new StructuredEdit();
}
compoundEdit.addEdit(edit);
firstModified = firstModified == 0 ? compoundEdit.editedTime() : firstModified;
if (lastEdit() != compoundEdit) {
boolean changed = hasChanged();
addEdit(compoundEdit);
firePropertyChangeEvent(UndoManager.UndoName, undoable, canUndo());
}
}
use of javax.swing.undo.UndoableEdit in project groovy-core by groovy.
the class TextUndoManager method undo.
public void undo() throws javax.swing.undo.CannotUndoException {
compoundEdit.end();
UndoableEdit edit = editToBeUndone();
if (((StructuredEdit) editToBeUndone()).editedTime() == firstModified) {
firstModified = 0;
} else if (firstModified == 0) {
firstModified = ((StructuredEdit) editToBeUndone()).editedTime();
}
boolean redoable = canRedo();
boolean changed = hasChanged();
super.undo();
firePropertyChangeEvent(UndoManager.RedoName, redoable, canRedo());
}
use of javax.swing.undo.UndoableEdit in project pcgen by PCGen.
the class ExtendedHTMLDocument method removeElements.
/**
* Removes elements. Used by Swing.
*
* @param e the element to remove
* @param index the element position
* @param count how many to remove
*
* @throws BadLocationException if there are not elements enough
*
* @see Content#remove(int, int)
*/
public void removeElements(Element e, int index, int count) throws BadLocationException {
writeLock();
int start = e.getElement(index).getStartOffset();
int end = e.getElement((index + count) - 1).getEndOffset();
try {
Element[] removed = new Element[count];
Element[] added = EMPTY_ELEMENT_ARRAY;
for (int counter = 0; counter < count; counter++) {
removed[counter] = e.getElement(counter + index);
}
DefaultDocumentEvent dde = new DefaultDocumentEvent(start, end - start, EventType.REMOVE);
((AbstractDocument.BranchElement) e).replace(index, removed.length, added);
dde.addEdit(new ElementEdit(e, index, removed, added));
UndoableEdit u = getContent().remove(start, end - start);
if (u != null) {
dde.addEdit(u);
}
postRemoveUpdate(dde);
dde.end();
fireRemoveUpdate(dde);
if (u != null) {
fireUndoableEditUpdate(new UndoableEditEvent(this, dde));
}
} finally {
writeUnlock();
}
}
use of javax.swing.undo.UndoableEdit in project n2a by frothga.
the class UndoManager method endCompoundEdit.
public synchronized void endCompoundEdit() {
UndoableEdit lastEdit = lastEdit();
if (lastEdit instanceof CompoundEdit) {
CompoundEdit compound = (CompoundEdit) lastEdit;
compound.end();
if (compound.isEmpty()) {
// Remove it. This is not strictly necessary, because an empty CompoundEdit will return false for isSignificant(), and thus not add a step for the user.
int lastIndex = edits.size() - 1;
trimEdits(lastIndex, lastIndex);
}
}
}
use of javax.swing.undo.UndoableEdit in project n2a by frothga.
the class UndoManager method add.
public synchronized boolean add(Undoable edit) {
// All descendants of Undoable are expected to carry out their operation once on creation. We do that here for convenience.
edit.redo();
if (!super.addEdit(edit))
return false;
// lastEdit could be a CompoundEdit, thus we have to check ...
UndoableEdit lastEdit = lastEdit();
if (lastEdit instanceof Undoable && ((Undoable) lastEdit).anihilate()) {
int lastIndex = edits.size() - 1;
// We have to do this indirectly because indexOfNextAdd is package private, so we can't maintain it.
trimEdits(lastIndex, lastIndex);
}
return true;
}
Aggregations