client

Clone or download

Update README.md, Refactored Settings Screen Timeout UI

Modified Files

M README.md
+2 −1
# Stream-Pi Client
# Stream-Pi Client
![version](https://img.shields.io/badge/Version-1.0.0-green)
![version](https://img.shields.io/badge/Version-1.0.0-green)
## Prerequisites
## Prerequisites
- Java >= 11
- Java >= 11
- Maven >= 3.6.3
- Maven >= 3.6.3
Note: If compiling the Android binary (apk) then Graalvm 21.x JDK should be used.
Note: If compiling the Android binary (apk) then GraalVM 21.1.0 (Java 11) should be used as JDK, or the path to it should be
set as value of environment variable `GRAALVM_HOME`.
## Quick Start
## Quick Start
This project depends on the following Stream-Pi modules:
This project depends on the following Stream-Pi modules:
- [Stream-Pi Action API](https://github.com/stream-pi/action-api)
- [Stream-Pi Action API](https://github.com/stream-pi/action-api)
- [Stream-Pi Theme API](https://github.com/stream-pi/theme-api)
- [Stream-Pi Theme API](https://github.com/stream-pi/theme-api)
- [Stream-Pi Utilities](https://github.com/stream-pi/util) - **This needs to be installed first**
- [Stream-Pi Utilities](https://github.com/stream-pi/util) - **This needs to be installed first**
## Download binaries
## Download binaries
Downloadable Binaries for available platforms are available [here](https://github.com/stream-pi/client/releases).
Downloadable Binaries for available platforms are available [here](https://github.com/stream-pi/client/releases).
## Compile and Run from source
## Compile and Run from source
Run `mvn clean javafx:run`
Run `mvn clean javafx:run`
package com.stream_pi.client.window.settings;
package com.stream_pi.client.window.settings;
import com.gluonhq.attach.vibration.VibrationService;
import com.gluonhq.attach.vibration.VibrationService;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.StartupFlags;
import com.stream_pi.client.info.StartupFlags;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
import com.stream_pi.util.combobox.StreamPiComboBox;
import com.stream_pi.util.combobox.StreamPiComboBox;
import com.stream_pi.util.combobox.StreamPiComboBoxFactory;
import com.stream_pi.util.combobox.StreamPiComboBoxFactory;
import com.stream_pi.util.combobox.StreamPiComboBoxListener;
import com.stream_pi.util.combobox.StreamPiComboBoxListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.event.ActionEvent;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import org.controlsfx.control.ToggleSwitch;
import org.controlsfx.control.ToggleSwitch;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class GeneralTab extends VBox
public class GeneralTab extends VBox
{
{
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ClientListener clientListener;
private ClientListener clientListener;
private HostServices hostServices;
private HostServices hostServices;
private TextField serverPortTextField;
private TextField serverPortTextField;
private TextField serverHostNameOrIPTextField;
private TextField serverHostNameOrIPTextField;
private TextField screenTimeoutTextField;
private TextField screenTimeoutTextField;
private StreamPiComboBox<ClientProfile> clientProfileComboBox;
private StreamPiComboBox<ClientProfile> clientProfileComboBox;
private StreamPiComboBox<Theme> themeComboBox;
private StreamPiComboBox<Theme> themeComboBox;
private TextField nickNameTextField;
private TextField nickNameTextField;
private Button saveButton;
private Button saveButton;
private Button connectDisconnectButton;
private Button connectDisconnectButton;
private Button shutdownButton;
private Button shutdownButton;
private HBoxWithSpaceBetween startOnBootHBox;
private HBoxWithSpaceBetween startOnBootHBox;
private ToggleSwitch startOnBootToggleSwitch;
private ToggleSwitch startOnBootToggleSwitch;
private HBoxWithSpaceBetween screenSaverHBox;
private HBoxWithSpaceBetween screenSaverHBox;
private ToggleSwitch screenSaverToggleSwitch;
private ToggleSwitch screenSaverToggleSwitch;
private HBoxWithSpaceBetween tryConnectingToServerIfActionClickedHBox;
private HBoxWithSpaceBetween tryConnectingToServerIfActionClickedHBox;
private ToggleSwitch tryConnectingToServerIfActionClickedToggleSwitch;
private ToggleSwitch tryConnectingToServerIfActionClickedToggleSwitch;
private HBoxWithSpaceBetween connectOnStartupHBox;
private HBoxWithSpaceBetween connectOnStartupHBox;
private ToggleSwitch connectOnStartupToggleSwitch;
private ToggleSwitch connectOnStartupToggleSwitch;
private HBoxWithSpaceBetween vibrateOnActionPressHBox;
private HBoxWithSpaceBetween vibrateOnActionPressHBox;
private ToggleSwitch vibrateOnActionPressToggleSwitch;
private ToggleSwitch vibrateOnActionPressToggleSwitch;
private HBoxWithSpaceBetween fullScreenModeHBox;
private HBoxWithSpaceBetween fullScreenModeHBox;
private ToggleSwitch fullScreenModeToggleSwitch;
private ToggleSwitch fullScreenModeToggleSwitch;
private HBoxWithSpaceBetween showCursorHBox;
private HBoxWithSpaceBetween showCursorHBox;
private ToggleSwitch showCursorToggleSwitch;
private ToggleSwitch showCursorToggleSwitch;
private TextField themesPathTextField;
private TextField themesPathTextField;
private TextField iconsPathTextField;
private TextField iconsPathTextField;
private TextField profilesPathTextField;
private TextField profilesPathTextField;
private final Button factoryResetButton;
private final Button factoryResetButton;
private Logger logger;
private Logger logger;
private final Button checkForUpdatesButton;
private final Button checkForUpdatesButton;
private HBoxInputBox screenTimeoutSecondsHBoxInputBox;
private HBoxInputBox screenTimeoutSecondsHBoxInputBox;
public GeneralTab(ExceptionAndAlertHandler exceptionAndAlertHandler,
public GeneralTab(ExceptionAndAlertHandler exceptionAndAlertHandler,
ClientListener clientListener, HostServices hostServices)
ClientListener clientListener, HostServices hostServices)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.clientListener = clientListener;
this.clientListener = clientListener;
this.hostServices = hostServices;
this.hostServices = hostServices;
logger = Logger.getLogger("");
logger = Logger.getLogger("");
serverPortTextField = new TextField();
serverPortTextField = new TextField();
screenTimeoutTextField = new TextField();
screenTimeoutTextField = new TextField();
serverHostNameOrIPTextField = new TextField();
serverHostNameOrIPTextField = new TextField();
nickNameTextField = new TextField();
nickNameTextField = new TextField();
clientProfileComboBox = new StreamPiComboBox<>();
clientProfileComboBox = new StreamPiComboBox<>();
clientProfileComboBox.setStreamPiComboBoxFactory(new StreamPiComboBoxFactory<ClientProfile>()
clientProfileComboBox.setStreamPiComboBoxFactory(new StreamPiComboBoxFactory<ClientProfile>()
{
{
@Override
@Override
public String getOptionDisplayText(ClientProfile object)
public String getOptionDisplayText(ClientProfile object)
{
{
return object.getName();
return object.getName();
}
}
});
});
clientProfileComboBox.setStreamPiComboBoxListener(new StreamPiComboBoxListener<ClientProfile>(){
clientProfileComboBox.setStreamPiComboBoxListener(new StreamPiComboBoxListener<ClientProfile>(){
@Override
@Override
public void onNewItemSelected(ClientProfile selectedItem)
public void onNewItemSelected(ClientProfile selectedItem)
{
{
clientListener.renderProfile(selectedItem, true);
clientListener.renderProfile(selectedItem, true);
}
}
});
});
themeComboBox = new StreamPiComboBox<>();
themeComboBox = new StreamPiComboBox<>();
themeComboBox.setStreamPiComboBoxFactory(new StreamPiComboBoxFactory<Theme>()
themeComboBox.setStreamPiComboBoxFactory(new StreamPiComboBoxFactory<Theme>()
{
{
@Override
@Override
public String getOptionDisplayText(Theme object)
public String getOptionDisplayText(Theme object)
{
{
return object.getShortName();
return object.getShortName();
}
}
});
});
themesPathTextField = new TextField();
themesPathTextField = new TextField();
iconsPathTextField = new TextField();
iconsPathTextField = new TextField();
profilesPathTextField = new TextField();
profilesPathTextField = new TextField();
startOnBootToggleSwitch = new ToggleSwitch();
startOnBootToggleSwitch = new ToggleSwitch();
startOnBootHBox = new HBoxWithSpaceBetween("Start On Boot", startOnBootToggleSwitch);
startOnBootHBox = new HBoxWithSpaceBetween("Start On Boot", startOnBootToggleSwitch);
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());
screenSaverToggleSwitch = new ToggleSwitch();
screenSaverToggleSwitch = new ToggleSwitch();
screenSaverHBox = new HBoxWithSpaceBetween("Screen Saver", screenSaverToggleSwitch);
screenSaverHBox = new HBoxWithSpaceBetween("Screen Saver", screenSaverToggleSwitch);
screenSaverHBox.managedProperty().bind(screenSaverHBox.visibleProperty());
screenSaverHBox.managedProperty().bind(screenSaverHBox.visibleProperty());
tryConnectingToServerIfActionClickedToggleSwitch = new ToggleSwitch();
tryConnectingToServerIfActionClickedToggleSwitch = new ToggleSwitch();
tryConnectingToServerIfActionClickedHBox = new HBoxWithSpaceBetween("Try connect to server on action click", tryConnectingToServerIfActionClickedToggleSwitch);
tryConnectingToServerIfActionClickedHBox = new HBoxWithSpaceBetween("Try connect to server on action click", tryConnectingToServerIfActionClickedToggleSwitch);
tryConnectingToServerIfActionClickedHBox.managedProperty().bind(tryConnectingToServerIfActionClickedHBox.visibleProperty());
tryConnectingToServerIfActionClickedHBox.managedProperty().bind(tryConnectingToServerIfActionClickedHBox.visibleProperty());
fullScreenModeToggleSwitch = new ToggleSwitch();
fullScreenModeToggleSwitch = new ToggleSwitch();
fullScreenModeHBox = new HBoxWithSpaceBetween("Full Screen", fullScreenModeToggleSwitch);
fullScreenModeHBox = new HBoxWithSpaceBetween("Full Screen", fullScreenModeToggleSwitch);
fullScreenModeHBox.managedProperty().bind(fullScreenModeHBox.visibleProperty());
fullScreenModeHBox.managedProperty().bind(fullScreenModeHBox.visibleProperty());
vibrateOnActionPressToggleSwitch = new ToggleSwitch();
vibrateOnActionPressToggleSwitch = new ToggleSwitch();
vibrateOnActionPressHBox = new HBoxWithSpaceBetween("Vibrate On Action Press", vibrateOnActionPressToggleSwitch);
vibrateOnActionPressHBox = new HBoxWithSpaceBetween("Vibrate On Action Press", vibrateOnActionPressToggleSwitch);
vibrateOnActionPressHBox.managedProperty().bind(vibrateOnActionPressHBox.visibleProperty());
vibrateOnActionPressHBox.managedProperty().bind(vibrateOnActionPressHBox.visibleProperty());
connectOnStartupToggleSwitch = new ToggleSwitch();
connectOnStartupToggleSwitch = new ToggleSwitch();
connectOnStartupHBox = new HBoxWithSpaceBetween("Connect On Startup", connectOnStartupToggleSwitch);
connectOnStartupHBox = new HBoxWithSpaceBetween("Connect On Startup", connectOnStartupToggleSwitch);
connectOnStartupHBox.managedProperty().bind(connectOnStartupHBox.visibleProperty());
connectOnStartupHBox.managedProperty().bind(connectOnStartupHBox.visibleProperty());
showCursorToggleSwitch = new ToggleSwitch();
showCursorToggleSwitch = new ToggleSwitch();
showCursorHBox = new HBoxWithSpaceBetween("Show Cursor", showCursorToggleSwitch);
showCursorHBox = new HBoxWithSpaceBetween("Show Cursor", showCursorToggleSwitch);
showCursorHBox.managedProperty().bind(showCursorHBox.visibleProperty());
showCursorHBox.managedProperty().bind(showCursorHBox.visibleProperty());
int prefWidth = 200;
int prefWidth = 200;
HBoxInputBox themesPathInputBox = new HBoxInputBox("Themes Path", themesPathTextField, prefWidth);
HBoxInputBox themesPathInputBox = new HBoxInputBox("Themes Path", themesPathTextField, prefWidth);
themesPathInputBox.managedProperty().bind(themesPathInputBox.visibleProperty());
themesPathInputBox.managedProperty().bind(themesPathInputBox.visibleProperty());
HBoxInputBox iconsPathInputBox = new HBoxInputBox("Icons Path", iconsPathTextField, prefWidth);
HBoxInputBox iconsPathInputBox = new HBoxInputBox("Icons Path", iconsPathTextField, prefWidth);
iconsPathInputBox.managedProperty().bind(iconsPathInputBox.visibleProperty());
iconsPathInputBox.managedProperty().bind(iconsPathInputBox.visibleProperty());
HBoxInputBox profilesPathInputBox = new HBoxInputBox("Profiles Path", profilesPathTextField, prefWidth);
HBoxInputBox profilesPathInputBox = new HBoxInputBox("Profiles Path", profilesPathTextField, prefWidth);
profilesPathInputBox.managedProperty().bind(profilesPathInputBox.visibleProperty());
profilesPathInputBox.managedProperty().bind(profilesPathInputBox.visibleProperty());
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
checkForUpdatesButton.setOnAction(event->checkForUpdates());
factoryResetButton = new Button("Factory Reset");
factoryResetButton = new Button("Factory Reset");
factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
screenTimeoutSecondsHBoxInputBox = new HBoxInputBox("Screen Timeout (seconds)", screenTimeoutTextField, prefWidth);
screenTimeoutSecondsHBoxInputBox = new HBoxInputBox("Screen Timeout (seconds)", screenTimeoutTextField, prefWidth);
screenTimeoutSecondsHBoxInputBox.managedProperty().bind(screenTimeoutSecondsHBoxInputBox.visibleProperty());
screenTimeoutSecondsHBoxInputBox.managedProperty().bind(screenTimeoutSecondsHBoxInputBox.visibleProperty());
screenTimeoutTextField.disableProperty().bind(screenSaverToggleSwitch.selectedProperty().not());
VBox vBox = new VBox(
VBox vBox = new VBox(
new HBoxInputBox("Device Name", nickNameTextField, prefWidth),
new HBoxInputBox("Device Name", nickNameTextField, prefWidth),
new HBoxInputBox("Host Name/IP", serverHostNameOrIPTextField, prefWidth),
new HBoxInputBox("Host Name/IP", serverHostNameOrIPTextField, prefWidth),
new HBoxInputBox("Port", serverPortTextField, prefWidth),
new HBoxInputBox("Port", serverPortTextField, prefWidth),
new HBox(
new HBox(
new Label("Current profile"),
new Label("Current profile"),
SpaceFiller.horizontal(),
SpaceFiller.horizontal(),
clientProfileComboBox
clientProfileComboBox
),
),
new HBox(
new HBox(
new Label("Theme"),
new Label("Theme"),
SpaceFiller.horizontal(),
SpaceFiller.horizontal(),
themeComboBox
themeComboBox
),
),
themesPathInputBox,
themesPathInputBox,
iconsPathInputBox,
iconsPathInputBox,
profilesPathInputBox,
profilesPathInputBox,
screenTimeoutSecondsHBoxInputBox
screenTimeoutSecondsHBoxInputBox
);
);
vBox.getStyleClass().add("settings_base_vbox");
vBox.getStyleClass().add("settings_base_vbox");
vBox.setSpacing(10.0);
vBox.setSpacing(10.0);
vBox.setPadding(new Insets(5));
vBox.setPadding(new Insets(5));
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.getStyleClass().add("settings_base_scroll_pane");
scrollPane.getStyleClass().add("settings_base_scroll_pane");
scrollPane.setContent(vBox);
scrollPane.setContent(vBox);
vBox.setMinWidth(300);
vBox.setMinWidth(300);
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
Label settingsLabel = new Label("Settings");
Label settingsLabel = new Label("Settings");
settingsLabel.setPadding(new Insets(5,0,0,5));
settingsLabel.setPadding(new Insets(5,0,0,5));
settingsLabel.getStyleClass().add("settings_heading_label");
settingsLabel.getStyleClass().add("settings_heading_label");
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event->onSaveButtonClicked());
saveButton.setOnAction(event->onSaveButtonClicked());
connectDisconnectButton = new Button("Connect");
connectDisconnectButton = new Button("Connect");
connectDisconnectButton.setOnAction(event -> onConnectDisconnectButtonClicked());
connectDisconnectButton.setOnAction(event -> onConnectDisconnectButtonClicked());
Button exitButton = new Button("Exit");
Button exitButton = new Button("Exit");
exitButton.setOnAction(event -> onExitButtonClicked());
exitButton.setOnAction(event -> onExitButtonClicked());
HBox buttonBar = new HBox(connectDisconnectButton, saveButton);
HBox buttonBar = new HBox(connectDisconnectButton, saveButton);
shutdownButton = new Button("Shutdown");
shutdownButton = new Button("Shutdown");
shutdownButton.managedProperty().bind(shutdownButton.visibleProperty());
shutdownButton.managedProperty().bind(shutdownButton.visibleProperty());
shutdownButton.setOnAction(event -> onShutdownButtonClicked());
shutdownButton.setOnAction(event -> onShutdownButtonClicked());
vBox.getChildren().addAll(
vBox.getChildren().addAll(
tryConnectingToServerIfActionClickedHBox,
tryConnectingToServerIfActionClickedHBox,
fullScreenModeHBox,
fullScreenModeHBox,
connectOnStartupHBox,
connectOnStartupHBox,
vibrateOnActionPressHBox,
vibrateOnActionPressHBox,
screenSaverHBox,
screenSaverHBox,
startOnBootHBox,
startOnBootHBox,
showCursorHBox,
showCursorHBox,
checkForUpdatesButton,
checkForUpdatesButton,
shutdownButton,
shutdownButton,
factoryResetButton
factoryResetButton
);
);
buttonBar.getStyleClass().add("settings_button_bar");
buttonBar.getStyleClass().add("settings_button_bar");
buttonBar.setPadding(new Insets(0,5,5,0));
buttonBar.setPadding(new Insets(0,5,5,0));
buttonBar.setSpacing(5.0);
buttonBar.setSpacing(5.0);
buttonBar.setAlignment(Pos.CENTER_RIGHT);
buttonBar.setAlignment(Pos.CENTER_RIGHT);
setSpacing(10.0);
setSpacing(10.0);
getChildren().addAll(
getChildren().addAll(
settingsLabel,
settingsLabel,
scrollPane,
scrollPane,
buttonBar
buttonBar
);
);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
//Perform platform checks
//Perform platform checks
Platform platform = ClientInfo.getInstance().getPlatform();
Platform platform = ClientInfo.getInstance().getPlatform();
if(platform == Platform.ANDROID ||
if(platform == Platform.ANDROID ||
platform == Platform.IOS)
platform == Platform.IOS)
{
{
themesPathInputBox.setVisible(false);
themesPathInputBox.setVisible(false);
iconsPathInputBox.setVisible(false);
iconsPathInputBox.setVisible(false);
profilesPathInputBox.setVisible(false);
profilesPathInputBox.setVisible(false);
startOnBootHBox.setVisible(false);
startOnBootHBox.setVisible(false);
showCursorHBox.setVisible(false);
showCursorHBox.setVisible(false);
fullScreenModeHBox.setVisible(false);
fullScreenModeHBox.setVisible(false);
shutdownButton.setVisible(false);
shutdownButton.setVisible(false);
}
}
else
else
{
{
if(!StartupFlags.IS_SHOW_SHUT_DOWN_BUTTON)
if(!StartupFlags.IS_SHOW_SHUT_DOWN_BUTTON)
{
{
shutdownButton.setVisible(false);
shutdownButton.setVisible(false);
}
}
vibrateOnActionPressHBox.setVisible(false);
vibrateOnActionPressHBox.setVisible(false);
fullScreenModeHBox.setVisible(StartupFlags.SHOW_FULLSCREEN_TOGGLE_BUTTON);
fullScreenModeHBox.setVisible(StartupFlags.SHOW_FULLSCREEN_TOGGLE_BUTTON);
buttonBar.getChildren().add(exitButton);
buttonBar.getChildren().add(exitButton);
}
}
screenTimeoutSecondsHBoxInputBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenSaverHBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenSaverHBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenTimeoutSecondsHBoxInputBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
}
}
private Logger getLogger()
private Logger getLogger()
{
{
return logger;
return logger;
}
}
private void checkForUpdates()
private void checkForUpdates()
{
{
new CheckForUpdates(checkForUpdatesButton,
new CheckForUpdates(checkForUpdatesButton,
PlatformType.CLIENT, ClientInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
PlatformType.CLIENT, ClientInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
@Override
@Override
public void handle(ActionEvent actionEvent) {
public void handle(ActionEvent actionEvent) {
if(ClientInfo.getInstance().isPhone())
if(ClientInfo.getInstance().isPhone())
{
{
clientListener.openURL(getURL());
clientListener.openURL(getURL());
}
}
else
else
{
{
hostServices.showDocument(getURL());
hostServices.showDocument(getURL());
}
}
}
}
});
});
}
}
private void onFactoryResetButtonClicked()
private void onFactoryResetButtonClicked()
{
{
StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
"This will erase everything.",StreamPiAlertType.WARNING);
"This will erase everything.",StreamPiAlertType.WARNING);
String yesButton = "Yes";
String yesButton = "Yes";
String noButton = "No";
String noButton = "No";
confirmation.setButtons(yesButton, noButton);
confirmation.setButtons(yesButton, noButton);
confirmation.setOnClicked(new StreamPiAlertListener() {
confirmation.setOnClicked(new StreamPiAlertListener() {
@Override
@Override
public void onClick(String s) {
public void onClick(String s) {
if(s.equals(yesButton))
if(s.equals(yesButton))
{
{
clientListener.factoryReset();
clientListener.factoryReset();
}
}
}
}
});
});
confirmation.show();
confirmation.show();
}
}
public void onExitButtonClicked()
public void onExitButtonClicked()
{
{
clientListener.onCloseRequest();
clientListener.onCloseRequest();
clientListener.exitApp();
clientListener.exitApp();
}
}
public void setDisableStatus(boolean status)
public void setDisableStatus(boolean status)
{
{
saveButton.setDisable(status);
saveButton.setDisable(status);
connectDisconnectButton.setDisable(status);
connectDisconnectButton.setDisable(status);
}
}
public Button getConnectDisconnectButton()
public Button getConnectDisconnectButton()
{
{
return connectDisconnectButton;
return connectDisconnectButton;
}
}
public void onShutdownButtonClicked()
public void onShutdownButtonClicked()
{
{
clientListener.onCloseRequest();
clientListener.onCloseRequest();
try
try
{
{
Runtime.getRuntime().exec("sudo halt");
Runtime.getRuntime().exec("sudo halt");
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void onConnectDisconnectButtonClicked()
public void onConnectDisconnectButtonClicked()
{
{
try
try
{
{
if(clientListener.isConnected())
if(clientListener.isConnected())
clientListener.disconnect("Client disconnected from settings");
clientListener.disconnect("Client disconnected from settings");
else
else
clientListener.setupClientConnection();
clientListener.setupClientConnection();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
public void setConnectDisconnectButtonStatus()
public void setConnectDisconnectButtonStatus()
{
{
javafx.application.Platform.runLater(()->{
javafx.application.Platform.runLater(()->{
setDisableStatus(false);
setDisableStatus(false);
if(clientListener.isConnected())
if(clientListener.isConnected())
connectDisconnectButton.setText("Disconnect");
connectDisconnectButton.setText("Disconnect");
else
else
connectDisconnectButton.setText("Connect");
connectDisconnectButton.setText("Connect");
});
});
}
}
public void loadData() throws SevereException
public void loadData() throws SevereException
{
{
Config config = Config.getInstance();
Config config = Config.getInstance();
nickNameTextField.setText(config.getClientNickName());
nickNameTextField.setText(config.getClientNickName());
serverHostNameOrIPTextField.setText(config.getSavedServerHostNameOrIP());
serverHostNameOrIPTextField.setText(config.getSavedServerHostNameOrIP());
serverPortTextField.setText(config.getSavedServerPort()+"");
serverPortTextField.setText(config.getSavedServerPort()+"");
screenTimeoutTextField.setText(config.getScreenSaverTimeout()+"");
screenTimeoutTextField.setText(config.getScreenSaverTimeout()+"");
screenSaverToggleSwitch.setSelected(config.isScreenSaverEnabled());
screenSaverToggleSwitch.setSelected(config.isScreenSaverEnabled());
screenTimeoutSecondsHBoxInputBox.setVisible(config.isScreenSaverEnabled());
clientProfileComboBox.setOptions(clientListener.getClientProfiles().getClientProfiles());
clientProfileComboBox.setOptions(clientListener.getClientProfiles().getClientProfiles());
int ind = 0;
int ind = 0;
for(int i = 0;i<clientProfileComboBox.getOptions().size();i++)
for(int i = 0;i<clientProfileComboBox.getOptions().size();i++)
{
{
if(clientProfileComboBox.getOptions().get(i).getID().equals(clientListener.getCurrentProfile().getID()))
if(clientProfileComboBox.getOptions().get(i).getID().equals(clientListener.getCurrentProfile().getID()))
{
{
ind = i;
ind = i;
break;
break;
}
}
}
}
clientProfileComboBox.setCurrentSelectedItemIndex(ind);
clientProfileComboBox.setCurrentSelectedItemIndex(ind);
themeComboBox.setOptions(clientListener.getThemes().getThemeList());
themeComboBox.setOptions(clientListener.getThemes().getThemeList());
int ind2 = 0;
int ind2 = 0;
for(int i = 0;i<themeComboBox.getOptions().size();i++)
for(int i = 0;i<themeComboBox.getOptions().size();i++)
{
{
if(themeComboBox.getOptions().get(i).getFullName().equals(clientListener.getCurrentTheme().getFullName()))
if(themeComboBox.getOptions().get(i).getFullName().equals(clientListener.getCurrentTheme().getFullName()))
{
{
ind2 = i;
ind2 = i;
break;
break;
}
}
}
}
themeComboBox.setCurrentSelectedItemIndex(ind2);
themeComboBox.setCurrentSelectedItemIndex(ind2);
themesPathTextField.setText(config.getThemesPath());
themesPathTextField.setText(config.getThemesPath());
iconsPathTextField.setText(config.getIconsPath());
iconsPathTextField.setText(config.getIconsPath());
profilesPathTextField.setText(config.getProfilesPath());
profilesPathTextField.setText(config.getProfilesPath());
startOnBootToggleSwitch.setSelected(config.isStartOnBoot());
startOnBootToggleSwitch.setSelected(config.isStartOnBoot());
fullScreenModeToggleSwitch.setSelected(config.getIsFullScreenMode());
fullScreenModeToggleSwitch.setSelected(config.getIsFullScreenMode());
showCursorToggleSwitch.setSelected(config.isShowCursor());
showCursorToggleSwitch.setSelected(config.isShowCursor());
connectOnStartupToggleSwitch.setSelected(config.isConnectOnStartup());
connectOnStartupToggleSwitch.setSelected(config.isConnectOnStartup());
vibrateOnActionPressToggleSwitch.setSelected(config.isVibrateOnActionClicked());
vibrateOnActionPressToggleSwitch.setSelected(config.isVibrateOnActionClicked());
tryConnectingToServerIfActionClickedToggleSwitch.setSelected(config.isTryConnectingWhenActionClicked());
tryConnectingToServerIfActionClickedToggleSwitch.setSelected(config.isTryConnectingWhenActionClicked());
}
}
public void onSaveButtonClicked()
public void onSaveButtonClicked()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
int port = -1;
int port = -1;
try
try
{
{
port = Integer.parseInt(serverPortTextField.getText());
port = Integer.parseInt(serverPortTextField.getText());
if(port < 1024)
if(port < 1024)
errors.append("* Server Port should be above 1024.\n");
errors.append("* Server Port should be above 1024.\n");
else if(port > 65535)
else if(port > 65535)
errors.append("* Server Port must be lesser than 65535\n");
errors.append("* Server Port must be lesser than 65535\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Server Port should be a number.\n");
errors.append("* Server Port should be a number.\n");
}
}
int screenSaverTimeout = -1;
int screenSaverTimeout = -1;
try
try
{
{
screenSaverTimeout = Integer.parseInt(serverPortTextField.getText());
screenSaverTimeout = Integer.parseInt(serverPortTextField.getText());
if(screenSaverTimeout < 15)
if(screenSaverTimeout < 15)
errors.append("* Screen Timeout cannot be below 15 seconds.\n");
errors.append("* Screen Timeout cannot be below 15 seconds.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Screen Timeout should be a number.\n");
errors.append("* Screen Timeout should be a number.\n");
}
}
if(serverHostNameOrIPTextField.getText().isBlank())
if(serverHostNameOrIPTextField.getText().isBlank())
{
{
errors.append("* Server IP cannot be empty.\n");
errors.append("* Server IP cannot be empty.\n");
}
}
if(nickNameTextField.getText().isBlank())
if(nickNameTextField.getText().isBlank())
{
{
errors.append("* Nick name cannot be blank.\n");
errors.append("* Nick name cannot be blank.\n");
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException(
exceptionAndAlertHandler.handleMinorException(new MinorException(
"You made mistakes",
"You made mistakes",
"Please fix the errors and try again :\n"+errors.toString()
"Please fix the errors and try again :\n"+errors.toString()
));
));
return;
return;
}
}
try
try
{
{
boolean toBeReloaded = false;
boolean toBeReloaded = false;
boolean syncWithServer = false;
boolean syncWithServer = false;
Config config = Config.getInstance();
Config config = Config.getInstance();
if(!config.getCurrentThemeFullName().equals(themeComboBox.getCurrentSelectedItem().getFullName()))
if(!config.getCurrentThemeFullName().equals(themeComboBox.getCurrentSelectedItem().getFullName()))
{
{
syncWithServer = true;
syncWithServer = true;
toBeReloaded = true;
toBeReloaded = true;
}
}
config.setCurrentThemeFullName(themeComboBox.getCurrentSelectedItem().getFullName());
config.setCurrentThemeFullName(themeComboBox.getCurrentSelectedItem().getFullName());
if(!config.getClientNickName().equals(nickNameTextField.getText()))
if(!config.getClientNickName().equals(nickNameTextField.getText()))
{
{
syncWithServer = true;
syncWithServer = true;
}
}
config.setNickName(nickNameTextField.getText());
config.setNickName(nickNameTextField.getText());
if(port != config.getSavedServerPort() || !serverHostNameOrIPTextField.getText().equals(config.getSavedServerHostNameOrIP()))
if(port != config.getSavedServerPort() || !serverHostNameOrIPTextField.getText().equals(config.getSavedServerHostNameOrIP()))
{
{
syncWithServer = true;
syncWithServer = true;
}
}
config.setServerPort(port);
config.setServerPort(port);
config.setServerHostNameOrIP(serverHostNameOrIPTextField.getText());
config.setServerHostNameOrIP(serverHostNameOrIPTextField.getText());
boolean isFullScreen = fullScreenModeToggleSwitch.isSelected();
boolean isFullScreen = fullScreenModeToggleSwitch.isSelected();
if(config.getIsFullScreenMode() != isFullScreen)
if(config.getIsFullScreenMode() != isFullScreen)
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
config.setIsFullScreenMode(isFullScreen);
config.setIsFullScreenMode(isFullScreen);
config.setTryConnectingWhenActionClicked(tryConnectingToServerIfActionClickedToggleSwitch.isSelected());
config.setTryConnectingWhenActionClicked(tryConnectingToServerIfActionClickedToggleSwitch.isSelected());
boolean startOnBoot = startOnBootToggleSwitch.isSelected();
boolean startOnBoot = startOnBootToggleSwitch.isSelected();
if(config.isStartOnBoot() != startOnBoot)
if(config.isStartOnBoot() != startOnBoot)
{
{
if(StartupFlags.RUNNER_FILE_NAME == null)
if(StartupFlags.RUNNER_FILE_NAME == null)
{
{
new StreamPiAlert("Uh Oh", "No Runner File Name Specified as startup arguments. Cant set run at boot.", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh", "No Runner File Name Specified as startup arguments. Cant set run at boot.", StreamPiAlertType.ERROR).show();
startOnBoot = false;
startOnBoot = false;
}
}
else
else
{
{
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
if(startOnBoot)
if(startOnBoot)
{
{
startAtBoot.create(new File(StartupFlags.RUNNER_FILE_NAME),
startAtBoot.create(new File(StartupFlags.RUNNER_FILE_NAME),
StartupFlags.IS_X_MODE);
StartupFlags.IS_X_MODE);
config.setStartupIsXMode(StartupFlags.IS_X_MODE);
config.setStartupIsXMode(StartupFlags.IS_X_MODE);
}
}
else
else
{
{
boolean result = startAtBoot.delete();
boolean result = startAtBoot.delete();
if(!result)
if(!result)
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
}
}
}
config.setStartOnBoot(startOnBoot);
config.setStartOnBoot(startOnBoot);
config.setShowCursor(showCursorToggleSwitch.isSelected());
config.setShowCursor(showCursorToggleSwitch.isSelected());
if(!config.getThemesPath().equals(themesPathTextField.getText()))
if(!config.getThemesPath().equals(themesPathTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
config.setThemesPath(themesPathTextField.getText());
config.setThemesPath(themesPathTextField.getText());
if(!config.getIconsPath().equals(iconsPathTextField.getText()))
if(!config.getIconsPath().equals(iconsPathTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
config.setIconsPath(iconsPathTextField.getText());
config.setIconsPath(iconsPathTextField.getText());
if(!config.getProfilesPath().equals(profilesPathTextField.getText()))
if(!config.getProfilesPath().equals(profilesPathTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
config.setProfilesPath(profilesPathTextField.getText());
config.setProfilesPath(profilesPathTextField.getText());
if(config.isScreenSaverEnabled() != screenSaverToggleSwitch.isSelected())
if(config.isScreenSaverEnabled() != screenSaverToggleSwitch.isSelected())
toBeReloaded = true;
toBeReloaded = true;
config.setScreenSaverEnabled(screenSaverToggleSwitch.isSelected());
config.setScreenSaverEnabled(screenSaverToggleSwitch.isSelected());
if(!(screenSaverTimeout+"").equals(screenTimeoutTextField.getText()))
if(!(screenSaverTimeout+"").equals(screenTimeoutTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
config.setScreenSaverTimeout(screenTimeoutTextField.getText());
config.setScreenSaverTimeout(screenTimeoutTextField.getText());
config.setConnectOnStartup(connectOnStartupToggleSwitch.isSelected());
config.setConnectOnStartup(connectOnStartupToggleSwitch.isSelected());
boolean isVibrateOnActionClicked = vibrateOnActionPressToggleSwitch.isSelected();
boolean isVibrateOnActionClicked = vibrateOnActionPressToggleSwitch.isSelected();
if(config.isVibrateOnActionClicked() != isVibrateOnActionClicked && isVibrateOnActionClicked)
if(config.isVibrateOnActionClicked() != isVibrateOnActionClicked && isVibrateOnActionClicked)
{
{
if(VibrationService.create().isEmpty())
if(VibrationService.create().isEmpty())
{
{
isVibrateOnActionClicked = false;
isVibrateOnActionClicked = false;
new StreamPiAlert("Uh Oh!", "Vibration not supported", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh!", "Vibration not supported", StreamPiAlertType.ERROR).show();
}
}
}
}
config.setVibrateOnActionClicked(isVibrateOnActionClicked);
config.setVibrateOnActionClicked(isVibrateOnActionClicked);
config.save();
config.save();
loadData();
loadData();
if(syncWithServer)
if(syncWithServer)
{
{
if(clientListener.isConnected())
if(clientListener.isConnected())
{
{
clientListener.getClient().updateClientDetails();
clientListener.getClient().updateClientDetails();
}
}
}
}
if(toBeReloaded)
if(toBeReloaded)
{
{
clientListener.init();
clientListener.init();
clientListener.renderRootDefaultProfile();
clientListener.renderRootDefaultProfile();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
}
}