diff --git a/pdfsam-core/pom.xml b/pdfsam-core/pom.xml
index 53bc5dc8..79072689 100644
--- a/pdfsam-core/pom.xml
+++ b/pdfsam-core/pom.xml
@@ -54,9 +54,12 @@
org.pdfsam
pdfsam-injector
+
- io.reactivex.rxjava3
- rxjava
+ org.pdfsam
+ pdfsam-test
+ ${project.version}
+ test
diff --git a/pdfsam-core/src/main/java/module-info.java b/pdfsam-core/src/main/java/module-info.java
index 44994abe..7d21cb56 100644
--- a/pdfsam-core/src/main/java/module-info.java
+++ b/pdfsam-core/src/main/java/module-info.java
@@ -23,7 +23,6 @@
requires org.sejda.commons;
requires org.slf4j;
- requires transitive io.reactivex.rxjava3;
requires transitive java.xml;
requires transitive javafx.graphics;
requires transitive org.apache.commons.lang3;
diff --git a/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationContext.java b/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationContext.java
index 19b43088..715f7414 100644
--- a/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationContext.java
+++ b/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationContext.java
@@ -18,7 +18,6 @@
*/
package org.pdfsam.core.context;
-import io.reactivex.rxjava3.disposables.CompositeDisposable;
import javafx.application.ConditionalFeature;
import javafx.application.Platform;
import javafx.scene.Scene;
@@ -47,7 +46,6 @@ public class ApplicationContext implements Closeable {
private final ApplicationPersistentSettings persistentSettings;
private ApplicationRuntimeState runtimeState;
private Optional injector = Optional.empty();
- private CompositeDisposable disposable = new CompositeDisposable();
private ApplicationContext() {
this(new ApplicationPersistentSettings(new PreferencesRepository("/org/pdfsam/user/conf")), null);
@@ -84,11 +82,11 @@ public ApplicationRuntimeState runtimeState() {
if (Objects.isNull(this.runtimeState)) {
this.runtimeState = new ApplicationRuntimeState();
//listen for changes in the working path
- disposable.add(this.persistentSettings().settingsChanges(WORKING_PATH).subscribe(path -> {
+ this.persistentSettings().settingsChanges(WORKING_PATH).subscribe(path -> {
this.runtimeState.defaultWorkingPath(
path.filter(StringUtils::isNotBlank).map(Paths::get).filter(Files::isDirectory)
.orElse(null));
- }));
+ });
var workingPath = persistentSettings().get(WORKING_PATH).filter(StringUtils::isNotBlank).map(Paths::get)
.filter(Files::isDirectory).orElse(null);
@@ -104,18 +102,20 @@ public ApplicationRuntimeState runtimeState() {
* @param scene
*/
public void registerScene(Scene scene) {
- disposable.add(this.runtimeState().theme().subscribe(t -> {
- Platform.runLater(() -> {
- scene.getStylesheets().setAll(t.stylesheets());
- if (!Platform.isSupported(ConditionalFeature.TRANSPARENT_WINDOW)) {
- scene.getStylesheets().addAll(t.transparentIncapableStylesheets());
- }
- });
- }));
- disposable.add(this.persistentSettings().settingsChanges(FONT_SIZE).subscribe(size -> {
+ this.runtimeState().theme().subscribe(t -> {
+ if (Objects.nonNull(t)) {
+ Platform.runLater(() -> {
+ scene.getStylesheets().setAll(t.stylesheets());
+ if (!Platform.isSupported(ConditionalFeature.TRANSPARENT_WINDOW)) {
+ scene.getStylesheets().addAll(t.transparentIncapableStylesheets());
+ }
+ });
+ }
+ });
+ this.persistentSettings().settingsChanges(FONT_SIZE).subscribe(size -> {
size.filter(StringUtils::isNotBlank).map(s -> String.format("-fx-font-size: %s;", s))
.ifPresentOrElse(scene.getRoot()::setStyle, () -> scene.getRoot().setStyle(""));
- }));
+ });
this.persistentSettings().get(FONT_SIZE).filter(not(String::isBlank))
.ifPresent(size -> scene.getRoot().setStyle(String.format("-fx-font-size: %s;", size)));
@@ -148,9 +148,6 @@ public void clean() {
@Override
public void close() {
injector.ifPresent(Injector::close);
- runtimeState().close();
- persistentSettings.close();
- disposable.dispose();
}
}
diff --git a/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationPersistentSettings.java b/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationPersistentSettings.java
index 22c66cb4..46201c4a 100644
--- a/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationPersistentSettings.java
+++ b/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationPersistentSettings.java
@@ -18,9 +18,8 @@
*/
package org.pdfsam.core.context;
-import io.reactivex.rxjava3.core.Observable;
-import io.reactivex.rxjava3.subjects.PublishSubject;
-import io.reactivex.rxjava3.subjects.Subject;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ObservableValue;
import org.pdfsam.persistence.PersistenceException;
import org.pdfsam.persistence.PreferencesRepository;
import org.slf4j.Logger;
@@ -30,6 +29,7 @@
import java.util.Optional;
import static java.util.Objects.nonNull;
+import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.sejda.commons.util.RequireUtils.requireNotNullArg;
@@ -39,14 +39,14 @@
*
* @author Andrea Vacondio
*/
-public class ApplicationPersistentSettings implements AutoCloseable {
+public class ApplicationPersistentSettings {
private static final Logger LOG = LoggerFactory.getLogger(ApplicationPersistentSettings.class);
private final PreferencesRepository repo;
- private final Subject> stringSettingsChanges = PublishSubject.create();
- private final Subject> intSettingsChanges = PublishSubject.create();
- private final Subject> boolSettingsChanges = PublishSubject.create();
+ private final SimpleObjectProperty> stringSettingsChanges = new SimpleObjectProperty<>();
+ private final SimpleObjectProperty> intSettingsChanges = new SimpleObjectProperty<>();
+ private final SimpleObjectProperty> boolSettingsChanges = new SimpleObjectProperty<>();
ApplicationPersistentSettings(PreferencesRepository repo) {
this.repo = repo;
@@ -101,7 +101,7 @@ public void set(StringPersistentProperty prop, String value) {
requireNotNullArg(prop, "Cannot set value for a null property");
try {
this.repo.saveString(prop.key(), value);
- stringSettingsChanges.onNext(new PersistentPropertyChange<>(prop, ofNullable(value)));
+ stringSettingsChanges.set(new PersistentPropertyChange<>(prop, ofNullable(value)));
} catch (PersistenceException e) {
LOG.error("Unable to save persistent property", e);
}
@@ -115,7 +115,7 @@ public void set(IntegerPersistentProperty prop, int value) {
requireNotNullArg(prop, "Cannot set value for a null property");
try {
this.repo.saveInt(prop.key(), value);
- intSettingsChanges.onNext(new PersistentPropertyChange<>(prop, of(value)));
+ intSettingsChanges.set(new PersistentPropertyChange<>(prop, of(value)));
} catch (PersistenceException e) {
LOG.error("Unable to save persistent property", e);
}
@@ -128,7 +128,7 @@ public void set(BooleanPersistentProperty prop, boolean value) {
requireNotNullArg(prop, "Cannot set value for a null property");
try {
this.repo.saveBoolean(prop.key(), value);
- boolSettingsChanges.onNext(new PersistentPropertyChange<>(prop, of(value)));
+ boolSettingsChanges.set(new PersistentPropertyChange<>(prop, of(value)));
} catch (PersistenceException e) {
LOG.error("Unable to save persistent property", e);
}
@@ -159,22 +159,40 @@ public void delete(PersistentProperty> property) {
/**
* @return an observable for changes to the given property
*/
- public Observable> settingsChanges(StringPersistentProperty prop) {
- return stringSettingsChanges.hide().filter(c -> c.property().equals(prop)).map(PersistentPropertyChange::value);
+ public ObservableValue> settingsChanges(StringPersistentProperty prop) {
+ var value = new SimpleObjectProperty>(empty());
+ stringSettingsChanges.subscribe((old, c) -> {
+ if (c.property().equals(prop)) {
+ value.set(c.value());
+ }
+ });
+ return value;
}
/**
* @return an observable for changes to the given property
*/
- public Observable> settingsChanges(IntegerPersistentProperty prop) {
- return intSettingsChanges.hide().filter(c -> c.property().equals(prop)).map(PersistentPropertyChange::value);
+ public ObservableValue> settingsChanges(IntegerPersistentProperty prop) {
+ var value = new SimpleObjectProperty>(empty());
+ intSettingsChanges.subscribe((old, c) -> {
+ if (c.property().equals(prop)) {
+ value.set(c.value());
+ }
+ });
+ return value;
}
/**
* @return an observable for changes to the given property
*/
- public Observable> settingsChanges(BooleanPersistentProperty prop) {
- return boolSettingsChanges.hide().filter(c -> c.property().equals(prop)).map(PersistentPropertyChange::value);
+ public ObservableValue> settingsChanges(BooleanPersistentProperty prop) {
+ var value = new SimpleObjectProperty>(empty());
+ boolSettingsChanges.subscribe((old, c) -> {
+ if (c.property().equals(prop)) {
+ value.set(c.value());
+ }
+ });
+ return value;
}
/**
@@ -189,10 +207,4 @@ public void clean() {
}
}
- @Override
- public void close() {
- stringSettingsChanges.onComplete();
- intSettingsChanges.onComplete();
- boolSettingsChanges.onComplete();
- }
}
diff --git a/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationRuntimeState.java b/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationRuntimeState.java
index 93249df1..4c58cc3f 100644
--- a/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationRuntimeState.java
+++ b/pdfsam-core/src/main/java/org/pdfsam/core/context/ApplicationRuntimeState.java
@@ -18,9 +18,8 @@
*/
package org.pdfsam.core.context;
-import io.reactivex.rxjava3.core.Observable;
-import io.reactivex.rxjava3.subjects.BehaviorSubject;
-import io.reactivex.rxjava3.subjects.ReplaySubject;
+import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ObservableValue;
import org.apache.commons.lang3.StringUtils;
import org.pdfsam.model.tool.Tool;
import org.pdfsam.theme.Theme;
@@ -49,14 +48,14 @@
*
* @author Andrea Vacondio
*/
-public class ApplicationRuntimeState implements AutoCloseable {
+public class ApplicationRuntimeState {
private static final Logger LOG = LoggerFactory.getLogger(ApplicationRuntimeState.class);
private Path defaultWorkingPath;
- private final BehaviorSubject> workingPath = BehaviorSubject.createDefault(empty());
- private final BehaviorSubject> activeTool = BehaviorSubject.createDefault(empty());
- private final ReplaySubject theme = ReplaySubject.create(1);
+ private final SimpleObjectProperty> workingPath = new SimpleObjectProperty<>(empty());
+ private final SimpleObjectProperty> activeTool = new SimpleObjectProperty<>(empty());
+ private final SimpleObjectProperty theme = new SimpleObjectProperty<>();
private final Future