Skip to content
Snippets Groups Projects
Commit cda10c54 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

#174 - Add settings section for remote playwall instances

parent ba7bf978
No related branches found
No related tags found
No related merge requests found
Showing
with 262 additions and 32 deletions
...@@ -15,6 +15,4 @@ public class PseudoClasses { ...@@ -15,6 +15,4 @@ public class PseudoClasses {
public static final PseudoClass DRAG_CLASS = PseudoClass.getPseudoClass("drag"); public static final PseudoClass DRAG_CLASS = PseudoClass.getPseudoClass("drag");
public static final PseudoClass DEACTIVATED_CLASS = PseudoClass.getPseudoClass("deactivated"); public static final PseudoClass DEACTIVATED_CLASS = PseudoClass.getPseudoClass("deactivated");
} }
...@@ -34,7 +34,7 @@ public class GlobalSettings { ...@@ -34,7 +34,7 @@ public class GlobalSettings {
private Path savePath; private Path savePath;
// Key Binding // Key Binding
private KeyCollection keyCollection = new KeyCollection(); private final KeyCollection keyCollection = new KeyCollection();
// Update // Update
private boolean autoUpdate = true; private boolean autoUpdate = true;
...@@ -114,13 +114,11 @@ public class GlobalSettings { ...@@ -114,13 +114,11 @@ public class GlobalSettings {
return openLastDocument; return openLastDocument;
} }
public boolean isEnableAutosave() public boolean isEnableAutosave() {
{
return enableAutosave; return enableAutosave;
} }
public int getAutosaveIntervalInMinutes() public int getAutosaveIntervalInMinutes() {
{
return autosaveIntervalInMinutes; return autosaveIntervalInMinutes;
} }
...@@ -169,13 +167,11 @@ public class GlobalSettings { ...@@ -169,13 +167,11 @@ public class GlobalSettings {
this.openLastDocument = openLastDocument; this.openLastDocument = openLastDocument;
} }
public void setEnableAutosave(boolean enableAutosave) public void setEnableAutosave(boolean enableAutosave) {
{
this.enableAutosave = enableAutosave; this.enableAutosave = enableAutosave;
} }
public void setAutosaveIntervalInMinutes(int autosaveIntervalInMinutes) public void setAutosaveIntervalInMinutes(int autosaveIntervalInMinutes) {
{
this.autosaveIntervalInMinutes = autosaveIntervalInMinutes; this.autosaveIntervalInMinutes = autosaveIntervalInMinutes;
} }
......
package de.tobias.playpad.plugin.api.settings;
import de.thecodelabs.storage.settings.annotation.Key;
import de.tobias.playpad.Displayable;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class WebApiRemoteSettings implements Displayable {
@Key
private String name;
@Key
private String serverAddress;
@Key
private int port;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
displayProperty.set(name);
}
public String getServerAddress() {
return serverAddress;
}
public void setServerAddress(String serverAddress) {
this.serverAddress = serverAddress;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
private final StringProperty displayProperty = new SimpleStringProperty();
@Override
public StringProperty displayProperty() {
displayProperty.set(name);
return displayProperty;
}
}
package de.tobias.playpad.plugin.api.websocket.settings; package de.tobias.playpad.plugin.api.settings;
import de.thecodelabs.storage.settings.annotation.FilePath; import de.thecodelabs.storage.settings.annotation.FilePath;
import de.thecodelabs.storage.settings.annotation.Key; import de.thecodelabs.storage.settings.annotation.Key;
import java.util.ArrayList;
import java.util.List;
@FilePath("webapi.json") @FilePath("webapi.json")
public class WebApiSettings { public class WebApiSettings {
@Key @Key
private boolean enabled = false; private boolean enabled = false;
@Key @Key
private int port = 9876; private int port = 9876;
@Key
private List<WebApiRemoteSettings> remoteSettings = new ArrayList<>();
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
...@@ -25,4 +30,12 @@ public class WebApiSettings { ...@@ -25,4 +30,12 @@ public class WebApiSettings {
public void setPort(int port) { public void setPort(int port) {
this.port = port; this.port = port;
} }
public List<WebApiRemoteSettings> getRemoteSettings() {
return remoteSettings;
}
public void setRemoteSettings(List<WebApiRemoteSettings> remoteSettings) {
this.remoteSettings = remoteSettings;
}
} }
webapi.settings=WebAPI webapi.settings=WebAPI
webapi.settings.enable=WebAPI webapi-settings.server=Fernsteuerung
webapi.settings.enabled=Aktiv webapi.settings.server.enable=WebAPI
webapi.settings.port=Port webapi.settings.server.enabled=Aktiv
webapi.settings.restart=\u00C4nderungen an den Einstellungen werden erst mit einem Neustart von PlayWall wirksam. webapi.settings.server.port=Port
\ No newline at end of file webapi.settings.server.restart=\u00C4nderungen an den Einstellungen werden erst mit einem Neustart von PlayWall wirksam.
webapi-settings.remote=PlayWall Instanzen fernsteuern
webapi-settings.remote.name=Name
webapi-settings.remote.address=IP-Address/Host
webapi-settings.remote.port=Port
webapi-settings.remote.add=Hinzuf\u00FCgen
webapi-settings.remote.remove=L\u00F6schen
...@@ -2,30 +2,67 @@ ...@@ -2,30 +2,67 @@
<?import de.thecodelabs.utils.ui.scene.input.NumberTextField?> <?import de.thecodelabs.utils.ui.scene.input.NumberTextField?>
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.CheckBox?> <?import javafx.scene.control.*?>
<?import javafx.scene.control.Label?> <?import javafx.scene.layout.*?>
<?import javafx.scene.layout.HBox?> <VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1">
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="14.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children> <children>
<Label text="%webapi-settings.server" underline="true" />
<HBox alignment="CENTER_LEFT" spacing="14.0"> <HBox alignment="CENTER_LEFT" spacing="14.0">
<children> <children>
<Label alignment="CENTER_RIGHT" prefWidth="150.0" text="%webapi.settings.enable"/> <Label alignment="CENTER_RIGHT" prefWidth="150.0" text="%webapi.settings.server.enable" />
<CheckBox fx:id="activeCheckbox" mnemonicParsing="false" text="%webapi.settings.enabled"/> <CheckBox fx:id="activeCheckbox" mnemonicParsing="false" text="%webapi.settings.server.enabled" />
</children> </children>
</HBox> </HBox>
<HBox alignment="CENTER_LEFT" spacing="14.0"> <HBox alignment="CENTER_LEFT" spacing="14.0">
<children> <children>
<Label alignment="CENTER_RIGHT" prefWidth="150.0" text="%webapi.settings.port"/> <Label alignment="CENTER_RIGHT" prefWidth="150.0" text="%webapi.settings.server.port" />
<NumberTextField fx:id="portTextField" /> <NumberTextField fx:id="portTextField" />
</children> </children>
</HBox> </HBox>
<Label text="%webapi.settings.restart"> <Label text="%webapi.settings.server.restart">
<padding> <padding>
<Insets left="164.0" /> <Insets left="164.0" />
</padding> </padding>
</Label> </Label>
<Separator prefWidth="200.0" />
<Label text="%webapi-settings.remote" underline="true" />
<HBox spacing="14.0" VBox.vgrow="ALWAYS">
<children>
<VBox spacing="14.0">
<children>
<ListView fx:id="remoteListView" VBox.vgrow="ALWAYS" />
<HBox spacing="14.0">
<children>
<Button fx:id="remoteAddButton" onAction="#onRemoteAddButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="%webapi-settings.remote.add" HBox.hgrow="ALWAYS" />
<Button fx:id="remoteDeleteButton" onAction="#onRemoteDeleteButton" maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="%webapi-settings.remote.remove" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</children>
</VBox>
<VBox spacing="14.0">
<children>
<HBox alignment="CENTER_LEFT" spacing="14.0">
<children>
<Label alignment="CENTER_RIGHT" prefWidth="100.0" text="%webapi-settings.remote.name" />
<TextField fx:id="remoteNameTextField" />
</children>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="14.0">
<children>
<Label alignment="CENTER_RIGHT" prefWidth="100.0" text="%webapi-settings.remote.address" />
<TextField fx:id="remoteAddressTextField" />
</children>
</HBox>
<HBox alignment="CENTER_LEFT" spacing="14.0">
<children>
<Label alignment="CENTER_RIGHT" prefWidth="100.0" text="%webapi-settings.remote.port" />
<NumberTextField fx:id="remotePortTextField" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</children> </children>
<padding> <padding>
<Insets bottom="14.0" left="14.0" right="14.0" top="14.0" /> <Insets bottom="14.0" left="14.0" right="14.0" top="14.0" />
......
package de.tobias.playpad.plugin.api package de.tobias.playpad.plugin.api
import java.nio.file.{Files, Path}
import de.thecodelabs.logger.Logger import de.thecodelabs.logger.Logger
import de.thecodelabs.plugins.PluginDescriptor import de.thecodelabs.plugins.PluginDescriptor
import de.thecodelabs.plugins.versionizer.PluginArtifact import de.thecodelabs.plugins.versionizer.PluginArtifact
...@@ -10,12 +8,14 @@ import de.thecodelabs.utils.application.ApplicationUtils ...@@ -10,12 +8,14 @@ import de.thecodelabs.utils.application.ApplicationUtils
import de.thecodelabs.utils.application.container.PathType import de.thecodelabs.utils.application.container.PathType
import de.thecodelabs.utils.util.Localization import de.thecodelabs.utils.util.Localization
import de.tobias.playpad.PlayPadPlugin import de.tobias.playpad.PlayPadPlugin
import de.tobias.playpad.plugin.api.settings.{WebApiSettings, WebApiSettingsViewController}
import de.tobias.playpad.plugin.api.websocket.WebSocketHandler import de.tobias.playpad.plugin.api.websocket.WebSocketHandler
import de.tobias.playpad.plugin.api.websocket.listener.{PadStatusListener, ProjectListener} import de.tobias.playpad.plugin.api.websocket.listener.{PadStatusListener, ProjectListener}
import de.tobias.playpad.plugin.api.websocket.settings.{WebApiSettings, WebApiSettingsViewController}
import de.tobias.playpad.plugin.{Module, PlayPadPluginStub} import de.tobias.playpad.plugin.{Module, PlayPadPluginStub}
import spark.{Request, Response, Spark} import spark.{Request, Response, Spark}
import java.nio.file.{Files, Path}
class WebApiPlugin extends PlayPadPluginStub with PluginArtifact { class WebApiPlugin extends PlayPadPluginStub with PluginArtifact {
private var module: Module = _ private var module: Module = _
......
package de.tobias.playpad.plugin.api.websocket.settings package de.tobias.playpad.plugin.api.settings
import java.nio.file.Files
import de.thecodelabs.logger.Logger import de.thecodelabs.logger.Logger
import de.thecodelabs.storage.settings.{Storage, StorageTypes} import de.thecodelabs.storage.settings.{Storage, StorageTypes}
...@@ -9,8 +7,11 @@ import de.thecodelabs.utils.util.Localization ...@@ -9,8 +7,11 @@ import de.thecodelabs.utils.util.Localization
import de.tobias.playpad.plugin.api.WebApiPlugin import de.tobias.playpad.plugin.api.WebApiPlugin
import de.tobias.playpad.settings.GlobalSettings import de.tobias.playpad.settings.GlobalSettings
import de.tobias.playpad.viewcontroller.option.GlobalSettingsTabViewController import de.tobias.playpad.viewcontroller.option.GlobalSettingsTabViewController
import javafx.event.ActionEvent
import javafx.fxml.FXML import javafx.fxml.FXML
import javafx.scene.control.CheckBox import javafx.scene.control._
import java.nio.file.Files
class WebApiSettingsViewController(val webApiSettings: WebApiSettings) extends GlobalSettingsTabViewController { class WebApiSettingsViewController(val webApiSettings: WebApiSettings) extends GlobalSettingsTabViewController {
...@@ -22,52 +23,100 @@ class WebApiSettingsViewController(val webApiSettings: WebApiSettings) extends G ...@@ -22,52 +23,100 @@ class WebApiSettingsViewController(val webApiSettings: WebApiSettings) extends G
@FXML @FXML
var portTextField: NumberTextField = _ var portTextField: NumberTextField = _
/** @FXML var remoteListView: ListView[WebApiRemoteSettings] = _
* Lädt alle Einstellungen vom Model in die GUI. @FXML var remoteAddButton: Button = _
* @FXML var remoteDeleteButton: Button = _
* @param settings Aktuelles GlobalSettings @FXML var remoteNameTextField: TextField = _
*/ @FXML var remoteAddressTextField: TextField = _
@FXML var remotePortTextField: NumberTextField = _
override def init(): Unit = {
remoteListView.getItems.setAll(webApiSettings.getRemoteSettings)
remoteDeleteButton.disableProperty().bind(remoteListView.getSelectionModel.selectedItemProperty().isNull)
remoteListView.setCellFactory((_: ListView[WebApiRemoteSettings]) => new ListCell[WebApiRemoteSettings] {
override def updateItem(item: WebApiRemoteSettings, empty: Boolean): Unit = {
super.updateItem(item, empty)
if (!empty) {
textProperty().bind(item.displayProperty())
} else {
textProperty().unbind()
setText("")
}
}
})
remoteListView.getSelectionModel.selectedItemProperty().addListener((_, oldValue, newValue) => {
if (oldValue != null) {
saveSettingsToRemoteList(oldValue)
}
if (newValue != null) {
showRemoteConfiguration(newValue)
} else {
clearTextFields()
}
})
}
private def saveSettingsToRemoteList(remote: WebApiRemoteSettings): Unit = {
remote.setName(remoteNameTextField.getText)
remote.setServerAddress(remoteAddressTextField.getText)
remote.setPort(remotePortTextField.getText.toInt)
}
private def showRemoteConfiguration(remote: WebApiRemoteSettings): Unit = {
remoteNameTextField.setText(remote.getName)
remoteAddressTextField.setText(remote.getServerAddress)
remotePortTextField.setText(remote.getPort.toString)
}
private def clearTextFields(): Unit = {
remoteNameTextField.setText("")
remoteAddressTextField.setText("")
remotePortTextField.setText("")
}
@FXML def onRemoteAddButton(event: ActionEvent): Unit = {
val remoteSettings = new WebApiRemoteSettings()
remoteSettings.setName("Default")
webApiSettings.getRemoteSettings.add(remoteSettings)
remoteListView.getItems.add(remoteSettings)
}
@FXML def onRemoteDeleteButton(event: ActionEvent): Unit = {
val selectedItem = remoteListView.getSelectionModel.getSelectedItem
if (selectedItem != null) {
remoteListView.getItems.remove(selectedItem)
webApiSettings.getRemoteSettings.remove(selectedItem)
}
}
override def loadSettings(settings: GlobalSettings): Unit = { override def loadSettings(settings: GlobalSettings): Unit = {
activeCheckbox.setSelected(webApiSettings.isEnabled) activeCheckbox.setSelected(webApiSettings.isEnabled)
portTextField.setText(webApiSettings.getPort.toString) portTextField.setText(webApiSettings.getPort.toString)
} }
/**
* Speichert alle Änderungen in das Model.
*
* @param settings Aktuelles GlobalSettings
*/
override def saveSettings(settings: GlobalSettings): Unit = { override def saveSettings(settings: GlobalSettings): Unit = {
webApiSettings.setEnabled(activeCheckbox.isSelected) webApiSettings.setEnabled(activeCheckbox.isSelected)
webApiSettings.setPort(portTextField.getText.toInt) webApiSettings.setPort(portTextField.getText.toInt)
val selectedItem = remoteListView.getSelectionModel.getSelectedItem
if (selectedItem != null) {
saveSettingsToRemoteList(selectedItem)
}
saveToFile() saveToFile()
} }
/**
* Gibt <code>true</code> zurück, wenn im Hauptprogramm etwas neu geladen werden muss.
*
* @return <code>true</code> Benötigt Reload
*/
override def needReload(): Boolean = { override def needReload(): Boolean = {
false false
} }
/**
* Prüft ob die eingetragen Einstellungen erlaubt sind. Bei falschen Eingaben können die Einstellungen nicht
* geschlossen werden.
*
* @return <code>true</code> Einstellungen erlaubt. <code>false</code> Einstellungen fehlerhaft.
*/
override def validSettings(): Boolean = { override def validSettings(): Boolean = {
true true
} }
/**
* Gibt den Namen für den Tab zurück.
*
* @return Display Name des Tabs.
*/
override def name(): String = Localization.getString("webapi.settings") override def name(): String = Localization.getString("webapi.settings")
private def saveToFile(): Unit = { private def saveToFile(): Unit = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment