Search in sources :

Example 1 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project groovy by apache.

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 2 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project groovy by apache.

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 3 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project jdk8u_jdk by JetBrains.

the class DefaultStyledDocument method removeElementImpl.

private void removeElementImpl(Element elem) {
    if (elem.getDocument() != this) {
        throw new IllegalArgumentException("element doesn't belong to document");
    }
    BranchElement parent = (BranchElement) elem.getParentElement();
    if (parent == null) {
        throw new IllegalArgumentException("can't remove the root element");
    }
    int startOffset = elem.getStartOffset();
    int removeFrom = startOffset;
    int endOffset = elem.getEndOffset();
    int removeTo = endOffset;
    int lastEndOffset = getLength() + 1;
    Content content = getContent();
    boolean atEnd = false;
    boolean isComposedText = Utilities.isComposedTextElement(elem);
    if (endOffset >= lastEndOffset) {
        // element includes the last "\n" character, needs special handling
        if (startOffset <= 0) {
            throw new IllegalArgumentException("can't remove the whole content");
        }
        // last "\n" must not be removed
        removeTo = lastEndOffset - 1;
        try {
            if (content.getString(startOffset - 1, 1).charAt(0) == '\n') {
                // preceding leaf ends with "\n", remove it
                removeFrom--;
            }
        } catch (BadLocationException ble) {
            // can't happen
            throw new IllegalStateException(ble);
        }
        atEnd = true;
    }
    int length = removeTo - removeFrom;
    DefaultDocumentEvent dde = new DefaultDocumentEvent(removeFrom, length, DefaultDocumentEvent.EventType.REMOVE);
    UndoableEdit ue = null;
    // do not leave empty branch elements
    while (parent.getElementCount() == 1) {
        elem = parent;
        parent = (BranchElement) parent.getParentElement();
        if (parent == null) {
            // shouldn't happen
            throw new IllegalStateException("invalid element structure");
        }
    }
    Element[] removed = { elem };
    Element[] added = {};
    int index = parent.getElementIndex(startOffset);
    parent.replace(index, 1, added);
    dde.addEdit(new ElementEdit(parent, index, removed, added));
    if (length > 0) {
        try {
            ue = content.remove(removeFrom, length);
            if (ue != null) {
                dde.addEdit(ue);
            }
        } catch (BadLocationException ble) {
            // can only happen if the element structure is severely broken
            throw new IllegalStateException(ble);
        }
        lastEndOffset -= length;
    }
    if (atEnd) {
        // preceding leaf element should be extended to cover orphaned "\n"
        Element prevLeaf = parent.getElement(parent.getElementCount() - 1);
        while ((prevLeaf != null) && !prevLeaf.isLeaf()) {
            prevLeaf = prevLeaf.getElement(prevLeaf.getElementCount() - 1);
        }
        if (prevLeaf == null) {
            // shouldn't happen
            throw new IllegalStateException("invalid element structure");
        }
        int prevStartOffset = prevLeaf.getStartOffset();
        BranchElement prevParent = (BranchElement) prevLeaf.getParentElement();
        int prevIndex = prevParent.getElementIndex(prevStartOffset);
        Element newElem;
        newElem = createLeafElement(prevParent, prevLeaf.getAttributes(), prevStartOffset, lastEndOffset);
        Element[] prevRemoved = { prevLeaf };
        Element[] prevAdded = { newElem };
        prevParent.replace(prevIndex, 1, prevAdded);
        dde.addEdit(new ElementEdit(prevParent, prevIndex, prevRemoved, prevAdded));
    }
    postRemoveUpdate(dde);
    dde.end();
    fireRemoveUpdate(dde);
    if (!(isComposedText && (ue != null))) {
        // do not fire UndoabeEdit event for composed text edit (unsupported)
        fireUndoableEditUpdate(new UndoableEditEvent(this, dde));
    }
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit) AbstractUndoableEdit(javax.swing.undo.AbstractUndoableEdit)

Example 4 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project cayenne by apache.

the class CayenneUndoManager method redo.

@Override
public void redo() throws CannotRedoException {
    UndoableEdit e = editToBeRedone();
    if (e instanceof TextCompoundEdit) {
        TextCompoundEdit edit = (TextCompoundEdit) e;
        edit.watchCaretPosition();
        super.redo();
        edit.stopWatchingCaretPosition();
    } else {
        super.redo();
    }
    updateUI();
}
Also used : UndoableEdit(javax.swing.undo.UndoableEdit)

Example 5 with UndoableEdit

use of javax.swing.undo.UndoableEdit in project cayenne by apache.

the class CayenneUndoManager method undo.

@Override
public void undo() throws CannotUndoException {
    UndoableEdit e = editToBeUndone();
    if (e instanceof TextCompoundEdit) {
        TextCompoundEdit edit = (TextCompoundEdit) e;
        edit.watchCaretPosition();
        super.undo();
        edit.stopWatchingCaretPosition();
    } else {
        super.undo();
    }
    updateUI();
}
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