Fixed settings pane selection

This commit is contained in:
Kai S. K. Engelbart 2020-04-18 21:37:44 +02:00
parent 828673d00c
commit f3ab609d97
4 changed files with 21 additions and 20 deletions

View File

@ -88,11 +88,11 @@ public class Settings {
/**
* Updates the preferences when the save button is clicked.
*
* @throws IOException if an error occurs while saving the themes to the theme
* file
* @throws IOException if an error occurs while saving the themes
* @since Envoy Client v0.2-alpha
*/
public void save() throws IOException {
// Save settings to settings file
SerializationUtils.write(settingsFile, items);

View File

@ -2,14 +2,9 @@ package envoy.client.data;
import java.io.Serializable;
import java.util.function.Consumer;
import java.util.function.Function;
import javax.swing.JComponent;
import javafx.scene.Node;
import envoy.client.ui.SettingsToggleButton;
/**
* Encapsulates a persistent value that is directly or indirectly mutable by the
* user.<br>
@ -28,7 +23,6 @@ public class SettingsItem<T> implements Serializable {
private String userFriendlyName, description;
private transient Consumer<T> changeHandler;
private transient Function<SettingsItem<?>, ? extends Node> nodeCreator;
private static final long serialVersionUID = 1L;
@ -46,8 +40,6 @@ public class SettingsItem<T> implements Serializable {
this.value = value;
this.userFriendlyName = userFriendlyName;
this.description = description;
if (value.getClass() == Boolean.class) nodeCreator = s -> new SettingsToggleButton((SettingsItem<Boolean>) s);
}
/**
@ -104,8 +96,4 @@ public class SettingsItem<T> implements Serializable {
this.changeHandler = changeHandler;
changeHandler.accept(value);
}
public boolean hasNodeCreator() { return nodeCreator != null; }
public Node getNode() { return nodeCreator.apply(this); }
}

View File

@ -1,8 +1,11 @@
package envoy.client.ui;
import java.util.List;
import javafx.scene.layout.VBox;
import envoy.client.data.Settings;
import envoy.client.data.SettingsItem;
/**
* Project: <strong>envoy-client</strong><br>
@ -22,8 +25,13 @@ public class GeneralSettingsPane extends SettingsPane {
public GeneralSettingsPane() {
super("General");
var vbox = new VBox();
for (var name : new String[] { "onCloseMode", "enterToSend" })
vbox.getChildren().add(settings.getItems().get(name).getNode());
// TODO: Support other value types
List.of("onCloseMode", "enterToSend")
.stream()
.map(settings.getItems()::get)
.map(i -> new SettingsToggleButton((SettingsItem<Boolean>) i))
.forEach(vbox.getChildren()::add);
getChildren().add(vbox);
}
}

View File

@ -33,17 +33,22 @@ public class SettingsSceneController {
settingsList.setCellFactory(listView -> new ListCell<>() {
@Override
protected void updateItem(SettingsPane item, boolean empty) { if (!empty && item != null) setGraphic(new Label(item.getTitle())); }
protected void updateItem(SettingsPane item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null) setGraphic(new Label(item.getTitle()));
}
});
// settingsList.getItems().add(new GeneralSettingsPane());
settingsList.getItems().add(new GeneralSettingsPane());
}
@FXML
private void settingsListClicked() {
final var pane = settingsList.getSelectionModel().getSelectedItem();
titledPane.setText(pane.getTitle());
titledPane.setContent(pane);
if (pane != null) {
titledPane.setText(pane.getTitle());
titledPane.setContent(pane);
}
}
@FXML