JavaFX Integration #4

Merged
kske merged 4 commits from f/javafx into develop 2021-12-16 12:05:50 +01:00
7 changed files with 56 additions and 20 deletions
Showing only changes of commit 0f1c3e06d8 - Show all commits

View File

@ -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.
* <p>
* 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 <C> the change type to store in this change manager
* @author Maximilian K&auml;fer

View File

@ -24,7 +24,7 @@ public final class UnlimitedChangeManager<C extends Change> implements ChangeMan
@Override
public Optional<C> getLastChange() {
return index == -1 ? Optional.empty() : Optional.of(changes.get(index));
return index < 0 ? Optional.empty() : Optional.of(changes.get(index));
}
@Override

View File

@ -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);

View File

@ -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.
kske marked this conversation as resolved
Review
<p>
The properties have exactly the same name as their corresponding `-property()` methods and can be called i.e. as binding under exactly that name. Alternatively, the names are available as constants.
```java <p> The properties have exactly the same name as their corresponding `-property()` methods and can be called i.e. as binding under exactly that name. Alternatively, the names are available as constants. ```
* <p>
* 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 <C> the change type to store in this change manager
* @param <M> the type of change manager to wrap
@ -18,18 +23,29 @@ import dev.kske.undoredo.core.*;
public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
implements ObservableChangeManager<C> {
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<C> 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;
}

View File

@ -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 <C> the change type to store in this change manager
* @author Kai S. K. Engelbart
* @since 0.0.1
* @see ChangeManagerWrapper
*/
public interface ObservableChangeManager<C extends Change> extends ChangeManager<C> {
ReadOnlyObjectProperty<C> lastChangeProperty();
@Override
default Optional<C> 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();

View File

@ -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;
}

10
pom.xml
View File

@ -48,6 +48,16 @@
</roles>
<timezone>Europe/Berlin</timezone>
</developer>
<developer>
<name>Leon Hofmeister</name>
<email>leon@kske.dev</email>
<url>https://git.kske.dev/delvh</url>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
<timezone>Europe/Berlin</timezone>
</developer>
</developers>
<scm>