本文整理汇总了Java中org.reactfx.EventSource.push方法的典型用法代码示例。如果您正苦于以下问题:Java EventSource.push方法的具体用法?Java EventSource.push怎么用?Java EventSource.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.reactfx.EventSource
的用法示例。
在下文中一共展示了EventSource.push方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUndoInvertsTheChange
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testUndoInvertsTheChange() {
EventSource<Integer> changes = new EventSource<>();
Var<Integer> lastAction = Var.newSimpleVar(null);
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
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());
}
示例2: testMark
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testMark() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.fixedSizeHistoryUndoManager(
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());
}
示例3: testAtMarkedPositionRevalidation
import org.reactfx.EventSource; //导入方法依赖的package包/类
/**
* Tests that isAtMarkedPosition() forces atMarkedPositionProperty()
* become valid.
*/
@Test
public void testAtMarkedPositionRevalidation() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.zeroHistoryUndoManager(changes);
um.atMarkedPositionProperty().get(); // atMarkedPositionProperty is now valid
// we are going to expect two invalidations
CountDownLatch latch = new CountDownLatch(2);
um.atMarkedPositionProperty().addListener(observable -> latch.countDown());
changes.push(1); // atMarkedPositionProperty has been invalidated
assertEquals(1, latch.getCount());
um.isAtMarkedPosition(); // we want to test whether this caused revalidation of atMarkedPositionProperty
changes.push(2); // should have caused invalidation of atMarkedPositionProperty
assertEquals(0, latch.getCount());
}
示例4: testPushedNonIdentityChangeIsStored
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testPushedNonIdentityChangeIsStored() {
SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0);
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
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());
}
示例5: testPushedIdentityChangeIsNotStored
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testPushedIdentityChangeIsNotStored() {
SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0);
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
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());
}
示例6: testMergeResultingInNonIdentityChangeStoresMergeAndPreventsNextMerge
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testMergeResultingInNonIdentityChangeStoresMergeAndPreventsNextMerge() {
SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0);
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
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());
}
示例7: testPositionValidAfterAddingAChange
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testPositionValidAfterAddingAChange() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(changes, c -> c, changes::push);
changes.push(1);
UndoPosition pos = um.getCurrentPosition();
changes.push(1);
assertTrue(pos.isValid());
}
示例8: testPositionInvalidAfterMerge
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testPositionInvalidAfterMerge() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
changes, c -> -c, changes::push, (c1, c2) -> Optional.of(c1 + c2));
changes.push(1);
UndoPosition pos = um.getCurrentPosition();
changes.push(1);
assertFalse(pos.isValid());
}
示例9: testRedoUnavailableAfterAnnihilation
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testRedoUnavailableAfterAnnihilation() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
changes, c -> -c, changes::push, (c1, c2) -> Optional.of(c1 + c2), c -> c == 0);
changes.push(1);
changes.push(-1);
assertFalse(um.isRedoAvailable());
}
示例10: zeroHistoryUndoManagerMark
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void zeroHistoryUndoManagerMark() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.zeroHistoryUndoManager(changes);
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());
}
示例11: testFailFastWhenExpectedChangeNotReceived
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testFailFastWhenExpectedChangeNotReceived() {
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
changes, i -> -i, i -> {});
changes.push(1);
um.undo(); // should throw because the undone change is not received back
}
示例12: testMergeResultingInIdentityChangeAnnihilatesBothAndPreventsNextMerge
import org.reactfx.EventSource; //导入方法依赖的package包/类
@Test
public void testMergeResultingInIdentityChangeAnnihilatesBothAndPreventsNextMerge() {
SimpleIntegerProperty lastAppliedValue = new SimpleIntegerProperty(0);
EventSource<Integer> changes = new EventSource<>();
UndoManager<?> um = UndoManagerFactory.unlimitedHistoryUndoManager(
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());
}