本文整理汇总了Java中org.fxmisc.undo.UndoManager类的典型用法代码示例。如果您正苦于以下问题:Java UndoManager类的具体用法?Java UndoManager怎么用?Java UndoManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UndoManager类属于org.fxmisc.undo包,在下文中一共展示了UndoManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: reloadContent
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
/**
* Reload the content.
*
* @param content the content.
* @param clearHistory true if need to clear history.
*/
@FXThread
public void reloadContent(@NotNull final String content, final boolean clearHistory) {
final String currentContent = getText();
if (!StringUtils.equals(currentContent, content)) {
if (content.isEmpty()) {
try {
clear();
} catch (final IllegalStateException e) {
//FIXME it's a bug in the richfxeditor library
e.printStackTrace();
}
} else {
replaceText(0, currentContent.length(), content);
}
}
if (clearHistory) {
final UndoManager undoManager = getUndoManager();
undoManager.forgetHistory();
}
}
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:30,代码来源:BaseCodeArea.java
示例2: testUndoInvertsTheChange
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:24,代码来源:UndoManagerTest.java
示例3: testMark
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:25,代码来源:UndoManagerTest.java
示例4: testAtMarkedPositionRevalidation
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:24,代码来源:UndoManagerTest.java
示例5: testPushedNonIdentityChangeIsStored
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:18,代码来源:UndoManagerTest.java
示例6: testPushedIdentityChangeIsNotStored
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:21,代码来源:UndoManagerTest.java
示例7: testMergeResultingInNonIdentityChangeStoresMergeAndPreventsNextMerge
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:25,代码来源:UndoManagerTest.java
示例8: loadContent
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
/**
* Load the content.
*
* @param content the content.
*/
@FXThread
public void loadContent(@NotNull final String content) {
appendText(content);
final UndoManager undoManager = getUndoManager();
undoManager.forgetHistory();
}
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:13,代码来源:BaseCodeArea.java
示例9: callUndoManagers
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
protected void callUndoManagers(Consumer<UndoManager> umConsumer) {
umConsumer.accept(pageChangeUndoManager);
modelPageEditors.values().forEach(meps -> {
ModelPageEditorSupplier mepSupplier = (ModelPageEditorSupplier) meps;
if (mepSupplier.modelPageEditor != null) {
umConsumer.accept(mepSupplier.get().getUndoManager());
}
});
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:10,代码来源:AbstractPerspective.java
示例10: newPageChangeUndoManager
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
private UndoManager newPageChangeUndoManager() {
UndoManager result = UndoManagerFactory.unlimitedHistoryUndoManager(
pageChanges, // stream of changes to observe
c -> c.invert(), // function to invert a change
c -> c.apply(), // function to apply a change
(c1, c2) -> c1.mergeWith(c2));
return result;
}
开发者ID:aic-sri-international,项目名称:aic-praise,代码行数:9,代码来源:AbstractPerspective.java
示例11: testPositionValidAfterAddingAChange
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:11,代码来源:UndoManagerTest.java
示例12: testPositionInvalidAfterMerge
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:12,代码来源:UndoManagerTest.java
示例13: testRedoUnavailableAfterAnnihilation
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:11,代码来源:UndoManagerTest.java
示例14: zeroHistoryUndoManagerMark
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:16,代码来源:UndoManagerTest.java
示例15: testFailFastWhenExpectedChangeNotReceived
import org.fxmisc.undo.UndoManager; //导入依赖的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
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:11,代码来源:UndoManagerTest.java
示例16: testMergeResultingInIdentityChangeAnnihilatesBothAndPreventsNextMerge
import org.fxmisc.undo.UndoManager; //导入依赖的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());
}
开发者ID:FXMisc,项目名称:UndoFX,代码行数:34,代码来源:UndoManagerTest.java
示例17: richTextUndoManager
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
/**
* Returns an UndoManager that can undo/redo {@link RichTextChange}s. New changes
* emitted from the stream will not be merged with the previous change
* after {@code preventMergeDelay}
*/
public static <PS, SEG, S> UndoManager<RichTextChange<PS, SEG, S>> richTextUndoManager(GenericStyledArea<PS, SEG, S> area,
UndoManagerFactory factory,
Duration preventMergeDelay) {
return factory.create(area.richChanges(), TextChange::invert, applyRichTextChange(area),
TextChange::mergeWith, TextChange::isIdentity, preventMergeDelay);
}
开发者ID:FXMisc,项目名称:RichTextFX,代码行数:12,代码来源:UndoUtils.java
示例18: plainTextUndoManager
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
/**
* Returns an UndoManager that can undo/redo {@link PlainTextChange}s. New changes
* emitted from the stream will not be merged with the previous change
* after {@code preventMergeDelay}
*/
public static <PS, SEG, S> UndoManager<PlainTextChange> plainTextUndoManager(GenericStyledArea<PS, SEG, S> area,
UndoManagerFactory factory,
Duration preventMergeDelay) {
return factory.create(area.plainTextChanges(), TextChange::invert, applyPlainTextChange(area),
TextChange::mergeWith, TextChange::isIdentity, preventMergeDelay);
}
开发者ID:FXMisc,项目名称:RichTextFX,代码行数:12,代码来源:UndoUtils.java
示例19: JavaTextArea
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
public JavaTextArea(String content) {
codeArea = new CodeArea();
codeHelperDeligator = new JavaCodeAreaHelper(codeArea);
codeArea.setParagraphGraphicFactory(getLineFactory());
codeArea.richChanges().filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
.successionEnds(Duration.ofMillis(500)).supplyTask(this::computeHighlightingAsync).awaitLatest(codeArea.richChanges())
.filterMap(t -> {
if (t.isSuccess()) {
return Optional.of(t.get());
} else {
t.getFailure().printStackTrace();
return Optional.empty();
}
}).subscribe(this::applyHighlighting);
// 마우스 클릭이벤트 정의
codeArea.addEventHandler(KeyEvent.KEY_PRESSED, this::codeAreaKeyClick);
codeArea.setOnMouseClicked(defaultSelectionHandler);
codeArea.selectionProperty().addListener((oba, oldval, newval) -> {
int start = newval.getStart();
int end = newval.getEnd();
int caretColumn = codeArea.getCaretColumn();
String format = String.format(POSISION_FORMAT, codeArea.getCurrentParagraph() + 1, start + 1, end + 1, caretColumn + 1,
codeArea.getAnchor(), codeArea.getCaretPosition());
lblLineInfo.setText(format);
});
lblLineInfo.setPrefHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMinHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMaxHeight(USE_COMPUTED_SIZE);
this.setCenter(codeArea);
this.setBottom(lblLineInfo);
// this.getChildren().add(codeArea);
// this.getStylesheets().add(JavaKeywordsAsync.class.getResource("java-keywords.css").toExternalForm());
this.getStylesheets().add(JavaTextArea.class.getResource("java-keywords.css").toExternalForm());
this.codeArea.appendText(content);
UndoManager undoManager = codeArea.getUndoManager();
undoManager.forgetHistory();
undoManager.mark();
this.codeArea.selectRange(0, 0);
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:51,代码来源:JavaTextArea.java
示例20: BehaviorTextArea
import org.fxmisc.undo.UndoManager; //导入依赖的package包/类
public BehaviorTextArea(String content) {
codeArea = new CodeArea();
codeHelperDeligator = new BehaviorCodeAreaHelper(codeArea);
codeArea.setParagraphGraphicFactory(getLineFactory());
codeArea.richChanges().filter(ch -> !ch.getInserted().equals(ch.getRemoved())) // XXX
.successionEnds(Duration.ofMillis(500)).supplyTask(this::computeHighlightingAsync).awaitLatest(codeArea.richChanges())
.filterMap(t -> {
if (t.isSuccess()) {
return Optional.of(t.get());
} else {
t.getFailure().printStackTrace();
return Optional.empty();
}
}).subscribe(this::applyHighlighting);
// 마우스 클릭이벤트 정의
codeArea.addEventHandler(KeyEvent.KEY_PRESSED, this::codeAreaKeyClick);
codeArea.setOnMouseClicked(defaultSelectionHandler);
codeArea.selectionProperty().addListener((oba, oldval, newval) -> {
int start = newval.getStart();
int end = newval.getEnd();
int caretColumn = codeArea.getCaretColumn();
String format = String.format(POSISION_FORMAT, codeArea.getCurrentParagraph() + 1, start + 1, end + 1, caretColumn + 1,
codeArea.getAnchor(), codeArea.getCaretPosition());
lblLineInfo.setText(format);
});
lblLineInfo.setPrefHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMinHeight(USE_COMPUTED_SIZE);
lblLineInfo.setMaxHeight(USE_COMPUTED_SIZE);
this.setCenter(codeArea);
this.setBottom(lblLineInfo);
// this.getChildren().add(codeArea);
// this.getStylesheets().add(JavaKeywordsAsync.class.getResource("java-keywords.css").toExternalForm());
this.getStylesheets().add(BehaviorTextArea.class.getResource("behavior-keywords.css").toExternalForm());
this.codeArea.appendText(content);
UndoManager undoManager = codeArea.getUndoManager();
undoManager.forgetHistory();
undoManager.mark();
this.codeArea.selectRange(0, 0);
}
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:51,代码来源:BehaviorTextArea.java
注:本文中的org.fxmisc.undo.UndoManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论