Search in sources :

Example 11 with UndoableEdit

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());
    }
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit)

Example 12 with UndoableEdit

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());
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit)

Example 13 with UndoableEdit

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();
    }
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit) UndoableEditEvent(javax.swing.event.UndoableEditEvent)

Example 14 with UndoableEdit

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);
        }
    }
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit)

Example 15 with UndoableEdit

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;
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit)

Aggregations

UndoableEdit (javax.swing.undo.UndoableEdit)16 AbstractUndoableEdit (javax.swing.undo.AbstractUndoableEdit)4 DataMap (org.apache.cayenne.map.DataMap)2 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 List (java.util.List)1 UndoableEditEvent (javax.swing.event.UndoableEditEvent)1 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DataNodeDescriptor (org.apache.cayenne.configuration.DataNodeDescriptor)1 DbEntity (org.apache.cayenne.map.DbEntity)1 Embeddable (org.apache.cayenne.map.Embeddable)1 ObjEntity (org.apache.cayenne.map.ObjEntity)1 Procedure (org.apache.cayenne.map.Procedure)1 QueryDescriptor (org.apache.cayenne.map.QueryDescriptor)1 PasteCompoundUndoableEdit (org.apache.cayenne.modeler.undo.PasteCompoundUndoableEdit)1 PasteUndoableEdit (org.apache.cayenne.modeler.undo.PasteUndoableEdit)1 RemoveAttributeUndoableEdit (org.apache.cayenne.modeler.undo.RemoveAttributeUndoableEdit)1 RemoveCallbackMethodUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCallbackMethodUndoableEdit)1 RemoveCompoundUndoableEdit (org.apache.cayenne.modeler.undo.RemoveCompoundUndoableEdit)1 RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)1 RemoveUndoableEdit (org.apache.cayenne.modeler.undo.RemoveUndoableEdit)1