client

Clone or download

cleanup, refactored

Modified Files

/*
/*
ServerInfo.java
ServerInfo.java
Stores basic information about the server - name, platform type
Stores basic information about the server - name, platform type
Contributors: Debayan Sutradhar (@dubbadhar)
Contributors: Debayan Sutradhar (@dubbadhar)
*/
*/
package com.stream_pi.client.info;
package com.stream_pi.client.info;
import com.gluonhq.attach.storage.StorageService;
import com.gluonhq.attach.storage.StorageService;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import java.io.File;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.util.Optional;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Function;
public class ClientInfo {
public class ClientInfo {
private Version version;
private Version version;
private final ReleaseStatus releaseStatus;
private final ReleaseStatus releaseStatus;
private Platform platform;
private Platform platform;
private String prePath;
private String prePath;
private Version minThemeSupportVersion;
private Version minThemeSupportVersion;
private Version minPluginSupportVersion;
private Version minPluginSupportVersion;
private Version commStandardVersion;
private Version commStandardVersion;
private static ClientInfo instance = null;
private static ClientInfo instance = null;
private ClientInfo()
private ClientInfo()
{
{
version = new Version(1,0,0);
version = new Version(1,0,0);
minThemeSupportVersion = new Version(1,0,0);
minThemeSupportVersion = new Version(1,0,0);
minPluginSupportVersion = new Version(1,0,0);
minPluginSupportVersion = new Version(1,0,0);
commStandardVersion = new Version(1,0,0);
commStandardVersion = new Version(1,0,0);
releaseStatus = ReleaseStatus.EA;
releaseStatus = ReleaseStatus.EA;
String osName = System.getProperty("os.name").toLowerCase();
String osName = System.getProperty("os.name").toLowerCase();
prePath = System.getProperty("user.home")+"/Stream-Pi/Client/";
prePath = System.getProperty("user.home")+"/Stream-Pi/Client/";
if(osName.contains("windows"))
if(osName.contains("windows"))
{
{
platform = Platform.WINDOWS;
platform = Platform.WINDOWS;
}
}
else if (osName.contains("linux"))
else if (osName.contains("linux"))
{
{
platform = Platform.LINUX;
platform = Platform.LINUX;
}
}
else if(osName.contains("android") || osName.contains("ios"))
else if(osName.contains("android") || osName.contains("ios"))
{
{
StorageService.create().ifPresent(s-> s.getPrivateStorage().ifPresentOrElse(sp-> prePath = sp.getAbsolutePath()+"/Stream-Pi/Client/",
StorageService.create().ifPresent(s-> s.getPrivateStorage().ifPresentOrElse(sp-> prePath = sp.getAbsolutePath()+"/Stream-Pi/Client/",
()-> prePath = null));
()-> prePath = null));
platform = Platform.valueOf(osName.toUpperCase());
platform = Platform.valueOf(osName.toUpperCase());
}
}
else if (osName.contains("mac"))
else if (osName.contains("mac"))
{
{
platform = Platform.MAC;
platform = Platform.MAC;
}
}
else
else
{
{
platform = Platform.UNKNOWN;
platform = Platform.UNKNOWN;
}
}
}
}
public static synchronized ClientInfo getInstance(){
public static synchronized ClientInfo getInstance(){
if(instance == null)
if(instance == null)
{
{
instance = new ClientInfo();
instance = new ClientInfo();
}
}
return instance;
return instance;
}
}
public String getPrePath()
public String getPrePath()
{
{
return prePath;
return prePath;
}
}
public Platform getPlatform()
public Platform getPlatform()
{
{
return platform;
return platform;
}
}
public Version getVersion() {
public Version getVersion() {
return version;
return version;
}
}
public ReleaseStatus getReleaseStatus()
public ReleaseStatus getReleaseStatus()
{
{
return releaseStatus;
return releaseStatus;
}
}
public Version getMinThemeSupportVersion()
public Version getMinThemeSupportVersion()
{
{
return minThemeSupportVersion;
return minThemeSupportVersion;
}
}
public Version getMinPluginSupportVersion()
public Version getMinPluginSupportVersion()
{
{
return minPluginSupportVersion;
return minPluginSupportVersion;
}
}
public Version getCommStandardVersion()
public Version getCommStandardVersion()
{
{
return commStandardVersion;
return commStandardVersion;
}
}
private boolean showFullScreenToggleButton = true;
public boolean isShowFullScreenToggleButton()
{
return showFullScreenToggleButton;
}
public void setShowFullScreenToggleButton(boolean showFullScreenToggleButton)
{
this.showFullScreenToggleButton = showFullScreenToggleButton;
}
public boolean isPhone()
public boolean isPhone()
{
{
return getPlatform() == Platform.ANDROID || getPlatform() == Platform.IOS;
return getPlatform() == Platform.ANDROID || getPlatform() == Platform.IOS;
}
}
private boolean defaultFullscreenMode = false;
private boolean defaultFullscreenMode = false;
public void setDefaultFullscreenMode(boolean defaultFullscreenMode)
public void setDefaultFullscreenMode(boolean defaultFullscreenMode)
{
{
this.defaultFullscreenMode = defaultFullscreenMode;
this.defaultFullscreenMode = defaultFullscreenMode;
}
}
public boolean getDefaultFullScreenMode()
public boolean getDefaultFullScreenMode()
{
{
return defaultFullscreenMode;
return defaultFullscreenMode;
}
}
}
}
package com.stream_pi.client.window.settings;
package com.stream_pi.client.window.settings;
import com.gluonhq.attach.browser.BrowserService;
import com.gluonhq.attach.browser.BrowserService;
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.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 org.w3c.dom.Text;
import org.w3c.dom.Text;
import java.io.File;
import java.io.File;
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 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;
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());
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());
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
);
);
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.LINUX)
{
fullScreenModeHBox.setVisible(StartupFlags.IS_X_MODE);
}
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(ClientInfo.getInstance().isShowFullScreenToggleButton());
fullScreenModeHBox.setVisible(StartupFlags.SHOW_FULLSCREEN_TOGGLE_BUTTON);
buttonBar.getChildren().add(exitButton);
buttonBar.getChildren().add(exitButton);
}
}
screenTimeoutSecondsHBoxInputBox.setVisible(ClientInfo.getInstance().isShowFullScreenToggleButton());
screenTimeoutSecondsHBoxInputBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenSaverHBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenSaverHBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
}
}
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());
}
}
}
}
});
});
}
}
public void onExitButtonClicked()
public void onExitButtonClicked()
{
{
clientListener.onCloseRequest();
clientListener.onCloseRequest();
javafx.application.Platform.exit();
javafx.application.Platform.exit();
}
}
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());
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);
}
}
}
}
}
}