PreferencesFX
PreferencesFX copied to clipboard
Save Ui Properties
Not an issue, but I want to know if there is a way to save for example a Splitpane Divider Position using PreferencesFX, is there a way? Thank you.
Hi @aang7 I see what you mean - currently we don't have support to persist and load settings without having them shown in the GUI as well, is that what you meant? I could imagine a splitpane divider position would be something you wouldn't want to show a user in the settings, but would still like to save it.
I think this would make a great addition to PreferencesFX, it makes sense, since you already specify your way of persisting the settings (or keep the default Preferences API) to also save other settings that way. Here I could imagine an API like:
PreferencesFx.of(...).globalSettings(
Setting.of("Splitpane Divider Position 1", dividerPositionProperty1),
Setting.of("Splitpane Divider Position 2", dividerPositionProperty2)
);
Those would then be persisted and loaded, but not shown in the GUI.
Feel free to submit a PR!
@martinfrancois I would like to try :) How can I start?
Oh taking advantage of the moment, I just get the next exception trying to get the view and using another stage/scene and for some reason I get a NullPointerException while setting the scene:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException at com.dlsc.preferencesfx.view.PreferencesFxPresenter.lambda$setupEventHandlers$1(PreferencesFxPresenter.java:53) at com.sun.javafx.binding.ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182) at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81) at javafx.beans.property.ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74) at javafx.beans.property.ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102) at javafx.scene.Node$ReadOnlyObjectWrapperManualFire.fireSuperValueChangedEvent(Node.java:831) at javafx.scene.Node.invalidatedScenes(Node.java:881) at javafx.scene.Node.setScenes(Node.java:919) at javafx.scene.Parent.scenesChanged(Parent.java:667) at javafx.scene.Node.invalidatedScenes(Node.java:853) at javafx.scene.Node.setScenes(Node.java:919) at javafx.scene.Parent.scenesChanged(Parent.java:667) at javafx.scene.Node.invalidatedScenes(Node.java:853) at javafx.scene.Node.setScenes(Node.java:919) at javafx.scene.Scene$9.invalidated(Scene.java:1119) at javafx.beans.property.ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:111) at javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:146) at javafx.scene.Scene.setRoot(Scene.java:1072) at javafx.scene.Scene.<init>(Scene.java:347) at javafx.scene.Scene.<init>(Scene.java:194) at Nodes.Management.SettingsManager.showGeneralPreferencesWindow(SettingsManager.java:140) at Ui.MainUiController.lambda$controlSetup$29(MainUiController.java:490)
This is the code I use:
`static Stage preferencesStage;
static StackPane rootPaneOfPreferences;
static Scene preferencesScene;
public static void showGeneralPreferencesWindow(boolean show) {
if (preferencesStage == null) {
preferencesStage = new Stage();
rootPaneOfPreferences = new StackPane();
PreferencesFxView preferencesFxView = SettingsManager.getPreferencesFx().getView();
BorderPane borderPane = new BorderPane(preferencesFxView);
HBox hBox = new HBox();
Button saveButton = new Button("Guardar");
Button cancelButton = new Button("Cancelar");
saveButton.setOnAction(event -> getPreferencesFx().saveSettings());
cancelButton.setOnAction(event -> getPreferencesFx().discardChanges());
hBox.getChildren().addAll(saveButton, cancelButton);
borderPane.setBottom(hBox);
rootPaneOfPreferences.getChildren().add(borderPane);
try {
preferencesScene = new Scene(rootPaneOfPreferences);
}catch (Exception e){ }
preferencesStage.setScene(preferencesScene);
}
if (show)
preferencesStage.show();
else
preferencesStage.close();
}`
The line where preferencesScene is being instantiated is where the exception message marks. The try-catch is not catching anything, so I guess is related to other scope. It's really weird because I'm instantiating the scene, I guess something happens inside PreferencesFx but I'm not sure.. any idea?
@aang7 Concerning your first comment on how to start:
As mentioned above, I would first add a method to PreferencesFx
where you can pass global settings to be saved. Then, have a look in the PreferencesFxModel
class at the methods loadSettingValues
and saveSettings
in their current implementation, you would need to extend them to also load and save the global settings as well. If you need further info, just ask what is not clear!
Concerning the second thing you mentioned: We didn't foresee people wanting to use PreferencesFX as a node in a new window, which is why an exception gets thrown in this case, since in PreferencesFxPresenter
the call to newScene.getWindow().addEventHandler(...)
results in a NullPointerException
, because newScene.getWindow()
is null
, since the Scene
is created before the Stage
is effectively shown.
Thanks for reporting this! It will be fixed in the next release.