Example usage for javax.swing.undo AbstractUndoableEdit AbstractUndoableEdit

List of usage examples for javax.swing.undo AbstractUndoableEdit AbstractUndoableEdit

Introduction

In this page you can find the example usage for javax.swing.undo AbstractUndoableEdit AbstractUndoableEdit.

Prototype

public AbstractUndoableEdit() 

Source Link

Document

Creates an AbstractUndoableEdit which defaults hasBeenDone and alive to true.

Usage

From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java

private void updatePersons() {
    if (isInsideSetupVisuals) {
        return;//from   w  w w . j a v a 2 s . c o m
    }
    //Extract persons
    @SuppressWarnings("unchecked")
    final DefaultListModel<String> listModel = (DefaultListModel<String>) personsList.getModel();
    final String[] newPersons = new String[listModel.size()];
    listModel.copyInto(newPersons);
    LOG.info("settings persons to " + Arrays.toString(newPersons));
    final String[] oldPersons = dialog.getPersonList();

    //send to dialog
    dialog.setPersonList(newPersons);
    updateDialogPersons();

    // undo/redo
    undoRedo.undoableEditHappened(new UndoableEditEvent(dialog, new AbstractUndoableEdit() {

        @Override
        public void undo() throws CannotUndoException {
            super.undo();
            isInsideSetupVisuals = true;
            listModel.clear();
            listModel.ensureCapacity(oldPersons.length);
            for (String s : oldPersons) {
                listModel.addElement(s);
            }
            LOG.info("settings persons to " + Arrays.toString(oldPersons));
            dialog.setPersonList(oldPersons);
            updateDialogPersons();
            isInsideSetupVisuals = false;
        }

        @Override
        public void redo() throws CannotRedoException {
            super.redo();
            isInsideSetupVisuals = true;
            listModel.clear();
            listModel.ensureCapacity(newPersons.length);
            for (String s : newPersons) {
                listModel.addElement(s);
            }
            LOG.info("settings persons to " + Arrays.toString(newPersons));
            dialog.setPersonList(newPersons);
            updateDialogPersons();
            isInsideSetupVisuals = false;
        }

    }));
}