List of usage examples for javax.swing.event UndoableEditEvent UndoableEditEvent
public UndoableEditEvent(Object source, UndoableEdit edit)
From source file:org.shaman.rpg.editor.dialog.DialogVisualElement.java
private void updatePersons() { if (isInsideSetupVisuals) { return;//from w w w. ja v a2 s . com } //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; } })); }