Fixed settings pane selection
This commit is contained in:
parent
828673d00c
commit
f3ab609d97
@ -88,11 +88,11 @@ public class Settings {
|
|||||||
/**
|
/**
|
||||||
* Updates the preferences when the save button is clicked.
|
* Updates the preferences when the save button is clicked.
|
||||||
*
|
*
|
||||||
* @throws IOException if an error occurs while saving the themes to the theme
|
* @throws IOException if an error occurs while saving the themes
|
||||||
* file
|
|
||||||
* @since Envoy Client v0.2-alpha
|
* @since Envoy Client v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public void save() throws IOException {
|
public void save() throws IOException {
|
||||||
|
|
||||||
// Save settings to settings file
|
// Save settings to settings file
|
||||||
SerializationUtils.write(settingsFile, items);
|
SerializationUtils.write(settingsFile, items);
|
||||||
|
|
||||||
|
@ -2,14 +2,9 @@ package envoy.client.data;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
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
|
* Encapsulates a persistent value that is directly or indirectly mutable by the
|
||||||
* user.<br>
|
* user.<br>
|
||||||
@ -28,7 +23,6 @@ public class SettingsItem<T> implements Serializable {
|
|||||||
private String userFriendlyName, description;
|
private String userFriendlyName, description;
|
||||||
|
|
||||||
private transient Consumer<T> changeHandler;
|
private transient Consumer<T> changeHandler;
|
||||||
private transient Function<SettingsItem<?>, ? extends Node> nodeCreator;
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@ -46,8 +40,6 @@ public class SettingsItem<T> implements Serializable {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
this.userFriendlyName = userFriendlyName;
|
this.userFriendlyName = userFriendlyName;
|
||||||
this.description = description;
|
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;
|
this.changeHandler = changeHandler;
|
||||||
changeHandler.accept(value);
|
changeHandler.accept(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasNodeCreator() { return nodeCreator != null; }
|
|
||||||
|
|
||||||
public Node getNode() { return nodeCreator.apply(this); }
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package envoy.client.ui;
|
package envoy.client.ui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javafx.scene.layout.VBox;
|
import javafx.scene.layout.VBox;
|
||||||
|
|
||||||
import envoy.client.data.Settings;
|
import envoy.client.data.Settings;
|
||||||
|
import envoy.client.data.SettingsItem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Project: <strong>envoy-client</strong><br>
|
* Project: <strong>envoy-client</strong><br>
|
||||||
@ -22,8 +25,13 @@ public class GeneralSettingsPane extends SettingsPane {
|
|||||||
public GeneralSettingsPane() {
|
public GeneralSettingsPane() {
|
||||||
super("General");
|
super("General");
|
||||||
var vbox = new VBox();
|
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);
|
getChildren().add(vbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,17 +33,22 @@ public class SettingsSceneController {
|
|||||||
settingsList.setCellFactory(listView -> new ListCell<>() {
|
settingsList.setCellFactory(listView -> new ListCell<>() {
|
||||||
|
|
||||||
@Override
|
@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
|
@FXML
|
||||||
private void settingsListClicked() {
|
private void settingsListClicked() {
|
||||||
final var pane = settingsList.getSelectionModel().getSelectedItem();
|
final var pane = settingsList.getSelectionModel().getSelectedItem();
|
||||||
titledPane.setText(pane.getTitle());
|
if (pane != null) {
|
||||||
titledPane.setContent(pane);
|
titledPane.setText(pane.getTitle());
|
||||||
|
titledPane.setContent(pane);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
Reference in New Issue
Block a user