Java Code Examples for org.fxmisc.undo.UndoManager#undo()
The following examples show how to use
org.fxmisc.undo.UndoManager#undo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testSingleChangeUndoInvertsTheChange() { EventSource<Integer> changes = new EventSource<>(); Var<Integer> lastAction = Var.newSimpleVar(null); UndoManager<?> um = UndoManagerFactory.unlimitedHistorySingleChangeUM( changes, i -> -i, i -> { lastAction.setValue(i); changes.push(i); }); changes.push(3); changes.push(7); assertNull(lastAction.getValue()); um.undo(); assertEquals(-7, lastAction.getValue().intValue()); um.undo(); assertEquals(-3, lastAction.getValue().intValue()); um.redo(); assertEquals(3, lastAction.getValue().intValue()); um.redo(); assertEquals(7, lastAction.getValue().intValue()); }
Example 2
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMultiChangeUndoInvertsTheChangesAndReversesTheList() { EventSource<List<Integer>> changes = new EventSource<>(); Var<List<Integer>> lastChange = Var.newSimpleVar(null); UndoManager<?> um = UndoManagerFactory.unlimitedHistoryMultiChangeUM( changes, i -> -i, i -> { lastChange.setValue(i); changes.push(i); }); changes.push(list(3, 7)); assertNull(lastChange.getValue()); um.undo(); assertEquals(list(-7, -3), lastChange.getValue()); um.redo(); assertEquals(list(3, 7), lastChange.getValue()); }
Example 3
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMark() { EventSource<Integer> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.fixedSizeHistorySingleChangeUM( changes, c -> c, changes::push, 4); assertTrue(um.atMarkedPositionProperty().get()); changes.push(1); assertFalse(um.atMarkedPositionProperty().get()); changes.push(2); um.mark(); assertTrue(um.atMarkedPositionProperty().get()); changes.push(3); changes.push(4); assertFalse(um.atMarkedPositionProperty().get()); um.undo(); um.undo(); assertTrue(um.atMarkedPositionProperty().get()); changes.push(3); changes.push(4); changes.push(5); // overflow changes.push(6); assertFalse(um.atMarkedPositionProperty().get()); }
Example 4
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testPushedNonIdentitySingleChangeIsStored() { SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0); EventSource<Integer> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistorySingleChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply change and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 changes.push(4); assertTrue(um.isUndoAvailable()); um.undo(); assertEquals(-4, lastAppliedValue.get()); assertFalse(um.isUndoAvailable()); }
Example 5
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testPushedNonIdentityMultiChangeIsStored() { SimpleObjectProperty<List<Integer>> lastAppliedValue = new SimpleObjectProperty<>(); EventSource<List<Integer>> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistoryMultiChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply redo and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 changes.push(list(4, 5)); assertTrue(um.isUndoAvailable()); um.undo(); assertEquals(list(-5, -4), lastAppliedValue.get()); assertFalse(um.isUndoAvailable()); }
Example 6
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testPushedIdentitySingleChangeIsNotStored() { SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0); EventSource<Integer> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistorySingleChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply change and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 // force lastAppliedValue to store non-zero value changes.push(4); um.undo(); // test that pushed identity change is not stored changes.push(0); assertFalse(um.isUndoAvailable()); assertEquals(-4, lastAppliedValue.get()); }
Example 7
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testPushedIdentityMultiChangeIsNotStored() { SimpleObjectProperty<List<Integer>> lastAppliedValue = new SimpleObjectProperty<>(); EventSource<List<Integer>> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistoryMultiChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply redo and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 // force lastAppliedValue to store non-zero value changes.push(list(4, 8)); um.undo(); // test that pushed identity change is not stored changes.push(list(0, 0)); assertFalse(um.isUndoAvailable()); assertEquals(list(-8, -4), lastAppliedValue.get()); }
Example 8
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMergeResultingInNonIdentitySingleChangeStoresMergeAndPreventsNextMerge() { SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0); EventSource<Integer> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistorySingleChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply change and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 changes.push(1); changes.push(2); assertTrue(um.isUndoAvailable()); um.undo(); assertFalse(um.isUndoAvailable()); assertEquals(-3, lastAppliedValue.get()); um.redo(); // redo to test whether merge occurs on next push changes.push(5); assertTrue(um.isUndoAvailable()); um.undo(); assertEquals(-5, lastAppliedValue.get()); }
Example 9
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMergeResultingInNonIdentityMultiChangeStoresMergeAndPreventsNextMerge() { SimpleObjectProperty<List<Integer>> lastAppliedValue = new SimpleObjectProperty<>(); EventSource<List<Integer>> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistoryMultiChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply change and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 changes.push(list(1, 4)); changes.push(list(2, 5)); assertTrue(um.isUndoAvailable()); um.undo(); assertFalse(um.isUndoAvailable()); assertEquals(list(-9, -3), lastAppliedValue.get()); um.redo(); // redo to test whether merge occurs on next push changes.push(list(5, 8)); assertTrue(um.isUndoAvailable()); um.undo(); assertEquals(list(-8, -5), lastAppliedValue.get()); }
Example 10
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 5 votes |
@Test(expected = IllegalStateException.class) public void testFailFastWhenExpectedChangeNotReceived() { EventSource<Integer> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistorySingleChangeUM( changes, i -> -i, i -> {}); changes.push(1); um.undo(); // should throw because the undone change is not received back }
Example 11
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testMergeResultingInIdentitySingleChangeAnnihilatesBothAndPreventsNextMerge() { SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0); EventSource<Integer> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistorySingleChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply change and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 // have at least one change stored changes.push(6); // prevent next merge from occurring um.preventMerge(); // now push the identity-resulting merge changes changes.push(-3); // change A changes.push(3); // change B // changes should annihilate; neither are stored assertTrue(um.isUndoAvailable()); um.undo(); assertFalse(um.isUndoAvailable()); assertEquals(-6, lastAppliedValue.get()); um.redo(); // redo to test whether merge occurs on next push changes.push(3); assertTrue(um.isUndoAvailable()); um.undo(); assertTrue(um.isUndoAvailable()); assertEquals(-3, lastAppliedValue.get()); }
Example 12
Source File: UndoManagerTest.java From UndoFX with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testMergeResultingInIdentityMultiChangeAnnihilatesBothAndPreventsNextMerge() { SimpleObjectProperty<List<Integer>> lastAppliedValue = new SimpleObjectProperty<>(); EventSource<List<Integer>> changes = new EventSource<>(); UndoManager<?> um = UndoManagerFactory.unlimitedHistoryMultiChangeUM( changes, i -> -i, // invert i -> { lastAppliedValue.set(i); changes.push(i); }, // apply redo and re-emit value so expected change is received (a, b) -> Optional.of(a + b), // merge adds two changes together i -> i == 0); // identity change = 0 // have at least one change stored changes.push(list(6, 9)); // prevent next merge from occurring um.preventMerge(); // now push the identity-resulting merge changes changes.push(list(-3, -4)); // change A changes.push(list(3, 4)); // change B // changes should annihilate; neither are stored assertTrue(um.isUndoAvailable()); um.undo(); assertFalse(um.isUndoAvailable()); assertEquals(list(-9, -6), lastAppliedValue.get()); um.redo(); // redo to test whether merge occurs on next push changes.push(list(3, 4)); assertTrue(um.isUndoAvailable()); um.undo(); assertTrue(um.isUndoAvailable()); assertEquals(list(-4, -3), lastAppliedValue.get()); }