diff --git a/core/src/main/java/dev/kske/undoredo/core/ChangeManager.java b/core/src/main/java/dev/kske/undoredo/core/ChangeManager.java
index daffcfd..5410cfc 100644
--- a/core/src/main/java/dev/kske/undoredo/core/ChangeManager.java
+++ b/core/src/main/java/dev/kske/undoredo/core/ChangeManager.java
@@ -6,6 +6,10 @@ import java.util.*;
* A change manager keeps track of subsequent changes and allows un- and redoing them. A specific
* change can be marked using {@link #mark()} to keep track of a saved state in the application that
* uses the manager.
+ *
+ * If you intend to listen to the state of a change manager, consider writing a wrapper
+ * implementation for an existing change manager that adds the necessary hooks. If you use JavaFX,
+ * take a look at the {@code dev.kske.undoredo.javafx} module.
*
* @param the change type to store in this change manager
* @author Maximilian Käfer
diff --git a/core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java b/core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java
index 4e64120..4b0d13b 100644
--- a/core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java
+++ b/core/src/main/java/dev/kske/undoredo/core/UnlimitedChangeManager.java
@@ -24,7 +24,7 @@ public final class UnlimitedChangeManager implements ChangeMan
@Override
public Optional getLastChange() {
- return index == -1 ? Optional.empty() : Optional.of(changes.get(index));
+ return index < 0 ? Optional.empty() : Optional.of(changes.get(index));
}
@Override
diff --git a/core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java b/core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java
index 2508b56..51ac613 100644
--- a/core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java
+++ b/core/src/test/java/dev/kske/undoredo/core/ChangeManagerTest.java
@@ -27,7 +27,7 @@ class ChangeManagerTest {
* @since 0.0.1
*/
@Test
- @Order(1)
+ @Order(10)
void testAddChange() {
assertSame(0, wrapper.value);
manager.addChange(change);
@@ -40,7 +40,7 @@ class ChangeManagerTest {
* @since 0.0.1
*/
@Test
- @Order(2)
+ @Order(20)
void testLastChange() {
assertTrue(manager.getLastChange().isEmpty());
manager.addChange(change);
@@ -53,7 +53,7 @@ class ChangeManagerTest {
* @since 0.0.1
*/
@Test
- @Order(3)
+ @Order(30)
void testGetChanges() {
assertTrue(manager.getChanges().isEmpty());
manager.addChange(change);
@@ -67,7 +67,7 @@ class ChangeManagerTest {
* @since 0.0.1
*/
@Test
- @Order(4)
+ @Order(40)
void testUndo() {
assertFalse(manager.isUndoAvailable());
assertFalse(manager.undo());
@@ -85,7 +85,7 @@ class ChangeManagerTest {
* @since 0.0.1
*/
@Test
- @Order(5)
+ @Order(50)
void testRedo() {
assertFalse(manager.isRedoAvailable());
assertFalse(manager.redo());
@@ -106,7 +106,7 @@ class ChangeManagerTest {
* @since 0.0.1
*/
@Test
- @Order(6)
+ @Order(60)
void testMark() {
assertTrue(manager.isAtMarkedIndex());
manager.addChange(change);
diff --git a/javafx/src/main/java/dev/kske/undoredo/javafx/ChangeManagerWrapper.java b/javafx/src/main/java/dev/kske/undoredo/javafx/ChangeManagerWrapper.java
index 85029b5..0c16cb6 100644
--- a/javafx/src/main/java/dev/kske/undoredo/javafx/ChangeManagerWrapper.java
+++ b/javafx/src/main/java/dev/kske/undoredo/javafx/ChangeManagerWrapper.java
@@ -9,6 +9,11 @@ import dev.kske.undoredo.core.*;
/**
* Wraps an ordinary change manager into an observable change manager, providing the required
* properties for concrete implementations.
+ *
+ * The properties have the same name as their corresponding {@code -property()} methods and can be
+ * accessed reflectively from JavaFX, e.g. through
+ * {@link javafx.beans.binding.Bindings#select(Object, String...)}. Alternatively, the property
+ * names are available as constants.
*
* @param the change type to store in this change manager
* @param the type of change manager to wrap
@@ -18,18 +23,29 @@ import dev.kske.undoredo.core.*;
public class ChangeManagerWrapper>
implements ObservableChangeManager {
+ public static final String LAST_CHANGE = "lastChange";
+ public static final String AT_MARKED_INDEX = "atMarkedIndex";
+ public static final String UNDO_AVAILABLE = "undoAvailable";
+ public static final String REDO_AVAILABLE = "redoAvailable";
+
protected ReadOnlyObjectWrapper lastChange =
- new ReadOnlyObjectWrapper<>(this, "lastChange");
+ new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
protected ReadOnlyBooleanWrapper atMarkedIndex =
- new ReadOnlyBooleanWrapper(this, "atMarkedIndex");
+ new ReadOnlyBooleanWrapper(this, AT_MARKED_INDEX);
protected ReadOnlyBooleanWrapper undoAvailable =
- new ReadOnlyBooleanWrapper(this, "undoAvailable");
+ new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
protected ReadOnlyBooleanWrapper redoAvailable =
- new ReadOnlyBooleanWrapper(this, "redoAvailable");
+ new ReadOnlyBooleanWrapper(this, REDO_AVAILABLE);
protected final M manager;
- protected ChangeManagerWrapper(M manager) {
+ /**
+ * Initializes a change manager wrapper.
+ *
+ * @param manager the change manager to wrap
+ * @since 0.0.1
+ */
+ public ChangeManagerWrapper(M manager) {
this.manager = manager;
}
diff --git a/javafx/src/main/java/dev/kske/undoredo/javafx/ObservableChangeManager.java b/javafx/src/main/java/dev/kske/undoredo/javafx/ObservableChangeManager.java
index 09697af..4dad0e4 100644
--- a/javafx/src/main/java/dev/kske/undoredo/javafx/ObservableChangeManager.java
+++ b/javafx/src/main/java/dev/kske/undoredo/javafx/ObservableChangeManager.java
@@ -7,35 +7,39 @@ import javafx.beans.property.*;
import dev.kske.undoredo.core.*;
/**
+ * A change manager that exposes its state through JavaFX properties, thereby allowing a direct
+ * integration of Undo-Redo with JavaFX listeners and property bindings.
+ *
* @param the change type to store in this change manager
* @author Kai S. K. Engelbart
* @since 0.0.1
+ * @see ChangeManagerWrapper
*/
public interface ObservableChangeManager extends ChangeManager {
ReadOnlyObjectProperty lastChangeProperty();
-
+
@Override
default Optional getLastChange() {
return Optional.of(lastChangeProperty().get());
}
-
+
ReadOnlyBooleanProperty atMarkedIndexProperty();
-
+
@Override
default boolean isAtMarkedIndex() {
return atMarkedIndexProperty().get();
}
-
+
ReadOnlyBooleanProperty undoAvailableProperty();
-
+
@Override
default boolean isUndoAvailable() {
return undoAvailableProperty().get();
}
-
+
ReadOnlyBooleanProperty redoAvailableProperty();
-
+
@Override
default boolean isRedoAvailable() {
return redoAvailableProperty().get();
diff --git a/javafx/src/main/java/module-info.java b/javafx/src/main/java/module-info.java
index aa7f939..e296056 100644
--- a/javafx/src/main/java/module-info.java
+++ b/javafx/src/main/java/module-info.java
@@ -8,6 +8,8 @@ module dev.kske.undoredo.javafx {
exports dev.kske.undoredo.javafx;
- requires dev.kske.undoredo.core;
+ opens dev.kske.undoredo.javafx to javafx.base;
+
+ requires transitive dev.kske.undoredo.core;
requires transitive javafx.base;
}
diff --git a/pom.xml b/pom.xml
index c2ad885..4d3e67c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,6 +48,16 @@
Europe/Berlin
+
+ Leon Hofmeister
+ leon@kske.dev
+ https://git.kske.dev/delvh
+
+ architect
+ developer
+
+ Europe/Berlin
+