client
Clone or download
Modified Files
package com.stream_pi.client.window;
package com.stream_pi.client.window;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.controller.ScreenSaver;
import com.stream_pi.client.controller.ScreenSaver;
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.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import java.io.File;
import java.io.File;
import java.util.Objects;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Executors;
import java.util.logging.Logger;
import java.util.logging.Logger;
import com.stream_pi.client.Main;
import com.stream_pi.client.Main;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.profile.ClientProfiles;
import com.stream_pi.client.profile.ClientProfiles;
import com.stream_pi.client.window.dashboard.DashboardBase;
import com.stream_pi.client.window.dashboard.DashboardBase;
import com.stream_pi.client.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.client.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.client.window.settings.SettingsBase;
import com.stream_pi.client.window.settings.SettingsBase;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Themes;
import com.stream_pi.theme_api.Themes;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.combobox.StreamPiComboBox;
import com.stream_pi.util.combobox.StreamPiComboBox;
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.loggerhelper.StreamPiLogFallbackHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFallbackHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFileHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFileHandler;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.Cursor;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.Font;
import javafx.stage.Screen;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.Stage;
public abstract class Base extends StackPane implements ExceptionAndAlertHandler, ClientListener
public abstract class Base extends StackPane implements ExceptionAndAlertHandler, ClientListener
{
{
private final ExecutorService executor = Executors.newCachedThreadPool();
private final ExecutorService executor = Executors.newCachedThreadPool();
private Config config;
private Config config;
private ClientProfiles clientProfiles;
private ClientProfiles clientProfiles;
private ClientInfo clientInfo;
private ClientInfo clientInfo;
private Stage stage;
private Stage stage;
public Stage getStage()
public Stage getStage()
{
{
return stage;
return stage;
}
}
public Logger getLogger()
public Logger getLogger()
{
{
return logger;
return logger;
}
}
private DashboardBase dashboardBase;
private DashboardBase dashboardBase;
private SettingsBase settingsBase;
private SettingsBase settingsBase;
private FirstTimeUse firstTimeUse;
private FirstTimeUse firstTimeUse;
private StackPane alertStackPane;
private StackPane alertStackPane;
@Override
@Override
public ClientProfiles getClientProfiles() {
public ClientProfiles getClientProfiles() {
return clientProfiles;
return clientProfiles;
}
}
public void setClientProfiles(ClientProfiles clientProfiles) {
public void setClientProfiles(ClientProfiles clientProfiles) {
this.clientProfiles = clientProfiles;
this.clientProfiles = clientProfiles;
}
}
private Logger logger = null;
private Logger logger = null;
private StreamPiLogFileHandler logFileHandler = null;
private StreamPiLogFileHandler logFileHandler = null;
private StreamPiLogFallbackHandler logFallbackHandler = null;
private StreamPiLogFallbackHandler logFallbackHandler = null;
@Override
@Override
public void initLogger()
public void initLogger()
{
{
try
try
{
{
if(logFileHandler != null)
if(logFileHandler != null)
return;
return;
closeLogger();
closeLogger();
logger = Logger.getLogger("");
logger = Logger.getLogger("");
if(new File(ClientInfo.getInstance().getPrePath()).getAbsoluteFile().getParentFile().canWrite())
if(new File(ClientInfo.getInstance().getPrePath()).getAbsoluteFile().getParentFile().canWrite())
{
{
String path = ClientInfo.getInstance().getPrePath()+"../stream-pi-client.log";
String path = ClientInfo.getInstance().getPrePath()+"../stream-pi-client.log";
Platform platform = getClientInfo().getPlatform();
Platform platform = getClientInfo().getPlatform();
if(platform == Platform.ANDROID ||
if(platform == Platform.ANDROID ||
platform == Platform.IOS)
platform == Platform.IOS)
path = ClientInfo.getInstance().getPrePath()+"stream-pi-client.log";
path = ClientInfo.getInstance().getPrePath()+"stream-pi-client.log";
logFileHandler = new StreamPiLogFileHandler(path);
logFileHandler = new StreamPiLogFileHandler(path);
logger.addHandler(logFileHandler);
logger.addHandler(logFileHandler);
}
}
else
else
{
{
logFallbackHandler = new StreamPiLogFallbackHandler();
logFallbackHandler = new StreamPiLogFallbackHandler();
logger.addHandler(logFallbackHandler);
logger.addHandler(logFallbackHandler);
}
}
}
}
catch(Exception e)
catch(Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
logFallbackHandler = new StreamPiLogFallbackHandler();
logFallbackHandler = new StreamPiLogFallbackHandler();
logger.addHandler(logFallbackHandler);
logger.addHandler(logFallbackHandler);
}
}
}
}
public void closeLogger()
public void closeLogger()
{
{
if(logFileHandler != null)
if(logFileHandler != null)
logFileHandler.close();
logFileHandler.close();
else if(logFallbackHandler != null)
else if(logFallbackHandler != null)
logFallbackHandler.close();
logFallbackHandler.close();
}
}
private HostServices hostServices;
private HostServices hostServices;
public void setHostServices(HostServices hostServices)
public void setHostServices(HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
}
}
public HostServices getHostServices()
public HostServices getHostServices()
{
{
return hostServices;
return hostServices;
}
}
public void initBase() throws SevereException
public void initBase() throws SevereException
{
{
stage = (Stage) getScene().getWindow();
stage = (Stage) getScene().getWindow();
getStage().getIcons().add(new Image(Objects.requireNonNull(Main.class.getResourceAsStream("app_icon.png"))));
getStage().getIcons().add(new Image(Objects.requireNonNull(Main.class.getResourceAsStream("app_icon.png"))));
clientInfo = ClientInfo.getInstance();
clientInfo = ClientInfo.getInstance();
dashboardBase = new DashboardBase(this, this);
dashboardBase = new DashboardBase(this, this);
dashboardBase.prefWidthProperty().bind(widthProperty());
dashboardBase.prefWidthProperty().bind(widthProperty());
dashboardBase.prefHeightProperty().bind(heightProperty());
dashboardBase.prefHeightProperty().bind(heightProperty());
settingsBase = new SettingsBase(getHostServices(), this, this);
settingsBase = new SettingsBase(getHostServices(), this, this);
alertStackPane = new StackPane();
alertStackPane = new StackPane();
alertStackPane.setPadding(new Insets(10));
alertStackPane.setPadding(new Insets(10));
alertStackPane.setVisible(false);
alertStackPane.setVisible(false);
StreamPiAlert.setParent(alertStackPane);
StreamPiAlert.setParent(alertStackPane);
StreamPiComboBox.setParent(alertStackPane);
StreamPiComboBox.setParent(alertStackPane);
getChildren().clear();
getChildren().clear();
getChildren().addAll(alertStackPane);
getChildren().addAll(alertStackPane);
if(getClientInfo().isPhone())
if(getClientInfo().isPhone())
{
{
dashboardBase.setPadding(new Insets(10));
dashboardBase.setPadding(new Insets(10));
settingsBase.setPadding(new Insets(10));
settingsBase.setPadding(new Insets(10));
}
}
initLogger();
initLogger();
checkPrePathDirectory();
checkPrePathDirectory();
getChildren().addAll(settingsBase, dashboardBase);
getChildren().addAll(settingsBase, dashboardBase);
setStyle(null);
setStyle(null);
config = Config.getInstance();
config = Config.getInstance();
initThemes();
initThemes();
if(config.isFirstTimeUse())
if(config.isFirstTimeUse())
{
{
firstTimeUse = new FirstTimeUse(this, this);
firstTimeUse = new FirstTimeUse(this, this);
getChildren().add(firstTimeUse);
getChildren().add(firstTimeUse);
if(getClientInfo().isPhone())
if(getClientInfo().isPhone())
{
{
firstTimeUse.setPadding(new Insets(10));
firstTimeUse.setPadding(new Insets(10));
}
}
firstTimeUse.toFront();
firstTimeUse.toFront();
//resolution check
//resolution check
resizeAccordingToResolution();
resizeAccordingToResolution();
}
}
else
else
{
{
dashboardBase.toFront();
dashboardBase.toFront();
}
}
}
}
private void resizeAccordingToResolution()
private void resizeAccordingToResolution()
{
{
if(!getClientInfo().isPhone())
if(!getClientInfo().isPhone())
{
{
double height = getScreenHeight();
double height = getScreenHeight();
double width = getScreenWidth();
double width = getScreenWidth();
if(height < 500)
if(height < 500)
setPrefHeight(320);
setPrefHeight(320);
if(width < 500)
if(width < 500)
setPrefWidth(240);
setPrefWidth(240);
}
}
}
}
@Override
@Override
public ExecutorService getExecutor()
public ExecutorService getExecutor()
{
{
return executor;
return executor;
}
}
@Override
@Override
public double getStageWidth()
public double getStageWidth()
{
{
if(getClientInfo().isPhone())
if(getClientInfo().isPhone())
{
{
return getScreenWidth();
return getScreenWidth();
}
}
else
else
{
{
return getStage().getWidth();
return getStage().getWidth();
}
}
}
}
public double getScreenWidth()
public double getScreenWidth()
{
{
return Screen.getPrimary().getBounds().getWidth();
return Screen.getPrimary().getBounds().getWidth();
}
}
@Override
@Override
public double getStageHeight()
public double getStageHeight()
{
{
if(ClientInfo.getInstance().getPlatform() == Platform.ANDROID)
if(ClientInfo.getInstance().getPlatform() == Platform.ANDROID)
{
{
return getScreenHeight();
return getScreenHeight();
}
}
else
else
{
{
return getStage().getHeight();
return getStage().getHeight();
}
}
}
}
public double getScreenHeight()
public double getScreenHeight()
{
{
return Screen.getPrimary().getBounds().getHeight();
return Screen.getPrimary().getBounds().getHeight();
}
}
private void checkPrePathDirectory() throws SevereException
private void checkPrePathDirectory() throws SevereException
{
{
try
try
{
{
String path = getClientInfo().getPrePath();
String path = getClientInfo().getPrePath();
if(path == null)
if(path == null)
{
{
throwStoragePermErrorAlert("Unable to access file system!");
throwStoragePermErrorAlert("Unable to access file system!");
return;
return;
}
}
File file = new File(path);
File file = new File(path);
if(!file.exists())
if(!file.exists())
{
{
boolean result = file.mkdirs();
boolean result = file.mkdirs();
if(result)
if(result)
{
{
Config.unzipToDefaultPrePath();
Config.unzipToDefaultPrePath();
ClientProfile clientProfile = new ClientProfile(new File(Config.getInstance().getProfilesPath()+"/"+
ClientProfile clientProfile = new ClientProfile(new File(Config.getInstance().getProfilesPath()+"/"+
Config.getInstance().getStartupProfileID()+".xml"), Config.getInstance().getIconsPath());
Config.getInstance().getStartupProfileID()+".xml"), Config.getInstance().getIconsPath());
int pre = clientProfile.getActionSize()+(clientProfile.getActionGap()*4);
int pre = clientProfile.getActionSize()+(clientProfile.getActionGap()*4);
int rows,cols;
int rows,cols;
if (StartupFlags.IS_X_MODE || StartupFlags.DEFAULT_FULLSCREEN_MODE)
if (StartupFlags.IS_X_MODE || StartupFlags.DEFAULT_FULLSCREEN_MODE)
{
{
setupFlags();
setupFlags();
getStage().show();
getStage().show();
rows = (int) (getStageHeight()/pre);
rows = (int) (getStageHeight()/pre);
cols = (int) (getStageWidth()/pre);
cols = (int) (getStageWidth()/pre);
//set rows/cols to 1 if stream-pi fails to determine rows/cols
if(rows==0 || cols == 0)
{
rows = 1;
cols = 1;
}
}
}
else
else
{
{
rows = (int) (Config.getInstance().getStartupWindowHeight()/pre);
rows = (int) (Config.getInstance().getStartupWindowHeight()/pre);
cols = (int) (Config.getInstance().getStartupWindowWidth()/pre);
cols = (int) (Config.getInstance().getStartupWindowWidth()/pre);
}
}
clientProfile.setCols(cols);
clientProfile.setCols(cols);
clientProfile.setRows(rows);
clientProfile.setRows(rows);
clientProfile.saveProfileDetails();
clientProfile.saveProfileDetails();
initLogger();
initLogger();
}
}
else
else
{
{
throwStoragePermErrorAlert("No storage permission. Give it!");
throwStoragePermErrorAlert("No storage permission. Give it!");
}
}
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
private void throwStoragePermErrorAlert(String msg) throws SevereException
private void throwStoragePermErrorAlert(String msg) throws SevereException
{
{
resizeAccordingToResolution();
resizeAccordingToResolution();
clearStylesheets();
clearStylesheets();
applyDefaultStylesheet();
applyDefaultStylesheet();
applyDefaultIconsStylesheet();
applyDefaultIconsStylesheet();
getStage().show();
getStage().show();
throw new SevereException(msg);
throw new SevereException(msg);
}
}
public void setupFlags() throws SevereException
public void setupFlags() throws SevereException
{
{
//Full Screen
//Full Screen
if(Config.getInstance().getIsFullScreenMode())
if(Config.getInstance().getIsFullScreenMode())
{
{
getStage().setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
getStage().setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
getStage().setFullScreen(true);
getStage().setFullScreen(true);
}
}
else
else
{
{
getStage().setFullScreenExitKeyCombination(KeyCombination.keyCombination("ESC"));
getStage().setFullScreenExitKeyCombination(KeyCombination.keyCombination("ESC"));
getStage().setFullScreen(false);
getStage().setFullScreen(false);
}
}
//Cursor
//Cursor
if(Config.getInstance().isShowCursor())
if(Config.getInstance().isShowCursor())
{
{
setCursor(Cursor.DEFAULT);
setCursor(Cursor.DEFAULT);
}
}
else
else
{
{
setCursor(Cursor.NONE);
setCursor(Cursor.NONE);
}
}
}
}
public SettingsBase getSettingsPane() {
public SettingsBase getSettingsPane() {
return settingsBase;
return settingsBase;
}
}
public DashboardBase getDashboardPane() {
public DashboardBase getDashboardPane() {
return dashboardBase;
return dashboardBase;
}
}
public void renderRootDefaultProfile()
public void renderRootDefaultProfile()
{
{
getDashboardPane().renderProfile(getClientProfiles().getProfileFromID(
getDashboardPane().renderProfile(getClientProfiles().getProfileFromID(
getConfig().getStartupProfileID()
getConfig().getStartupProfileID()
), true);
), true);
}
}
public void clearStylesheets()
public void clearStylesheets()
{
{
getStylesheets().clear();
getStylesheets().clear();
}
}
public void applyDefaultStylesheet()
public void applyDefaultStylesheet()
{
{
if(clientInfo.getPlatform() != Platform.IOS)
if(clientInfo.getPlatform() != Platform.IOS)
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
}
}
public void applyDefaultIconsStylesheet()
public void applyDefaultIconsStylesheet()
{
{
getStylesheets().add(Main.class.getResource("default_icons.css").toExternalForm());
getStylesheets().add(Main.class.getResource("default_icons.css").toExternalForm());
}
}
public Config getConfig()
public Config getConfig()
{
{
return config;
return config;
}
}
public ClientInfo getClientInfo()
public ClientInfo getClientInfo()
{
{
return clientInfo;
return clientInfo;
}
}
private Theme currentTheme;
private Theme currentTheme;
@Override
@Override
public Theme getCurrentTheme()
public Theme getCurrentTheme()
{
{
return currentTheme;
return currentTheme;
}
}
public void applyTheme(Theme t)
public void applyTheme(Theme t)
{
{
logger.info("Applying theme '"+t.getFullName()+"' ...");
logger.info("Applying theme '"+t.getFullName()+"' ...");
if(t.getFonts() != null)
if(t.getFonts() != null)
{
{
for(String fontFile : t.getFonts())
for(String fontFile : t.getFonts())
{
{
Font.loadFont(fontFile.replace("%20",""), 13);
Font.loadFont(fontFile.replace("%20",""), 13);
}
}
}
}
currentTheme = t;
currentTheme = t;
clearStylesheets();
clearStylesheets();
applyDefaultStylesheet();
applyDefaultStylesheet();
getStylesheets().addAll(t.getStylesheets());
getStylesheets().addAll(t.getStylesheets());
applyDefaultIconsStylesheet();
applyDefaultIconsStylesheet();
logger.info("... Done!");
logger.info("... Done!");
}
}
Themes themes;
Themes themes;
public void initThemes() throws SevereException
public void initThemes() throws SevereException
{
{
logger.info("Loading themes ...");
logger.info("Loading themes ...");
themes = new Themes(getConfig().getDefaultThemesPath(), getConfig().getThemesPath(), getConfig().getCurrentThemeFullName(), clientInfo.getMinThemeSupportVersion());
themes = new Themes(getConfig().getDefaultThemesPath(), getConfig().getThemesPath(), getConfig().getCurrentThemeFullName(), clientInfo.getMinThemeSupportVersion());
if(themes.getErrors().size()>0)
if(themes.getErrors().size()>0)
{
{
StringBuilder themeErrors = new StringBuilder();
StringBuilder themeErrors = new StringBuilder();
for(MinorException eachException : themes.getErrors())
for(MinorException eachException : themes.getErrors())
{
{
themeErrors.append("\n * ").append(eachException.getShortMessage());
themeErrors.append("\n * ").append(eachException.getShortMessage());
}
}
if(themes.getIsBadThemeTheCurrentOne())
if(themes.getIsBadThemeTheCurrentOne())
{
{
themeErrors.append("\n\nReverted to default theme! (").append(getConfig().getDefaultCurrentThemeFullName()).append(")");
themeErrors.append("\n\nReverted to default theme! (").append(getConfig().getDefaultCurrentThemeFullName()).append(")");
getConfig().setCurrentThemeFullName(getConfig().getDefaultCurrentThemeFullName());
getConfig().setCurrentThemeFullName(getConfig().getDefaultCurrentThemeFullName());
getConfig().save();
getConfig().save();
}
}
handleMinorException(new MinorException("Theme Loading issues", themeErrors.toString()));
handleMinorException(new MinorException("Theme Loading issues", themeErrors.toString()));
}
}
logger.info("... Done!");
logger.info("... Done!");
}
}
@Override
@Override
public Themes getThemes() {
public Themes getThemes() {
return themes;
return themes;
}
}
public void applyDefaultTheme()
public void applyDefaultTheme()
{
{
logger.info("Applying default theme ...");
logger.info("Applying default theme ...");
boolean foundTheme = false;
boolean foundTheme = false;
for(Theme t: themes.getThemeList())
for(Theme t: themes.getThemeList())
{
{
if(t.getFullName().equals(config.getCurrentThemeFullName()))
if(t.getFullName().equals(config.getCurrentThemeFullName()))
{
{
foundTheme = true;
foundTheme = true;
applyTheme(t);
applyTheme(t);
break;
break;
}
}
}
}
if(foundTheme)
if(foundTheme)
{
{
logger.info("... Done!");
logger.info("... Done!");
}
}
else
else
{
{
logger.info("Theme not found. reverting to light theme ...");
logger.info("Theme not found. reverting to light theme ...");
try {
try {
Config.getInstance().setCurrentThemeFullName("com.StreamPi.DefaultLight");
Config.getInstance().setCurrentThemeFullName("com.StreamPi.DefaultLight");
Config.getInstance().save();
Config.getInstance().save();
applyDefaultTheme();
applyDefaultTheme();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
}
}
@Override
@Override
public String getDefaultThemeFullName()
public String getDefaultThemeFullName()
{
{
return config.getCurrentThemeFullName();
return config.getCurrentThemeFullName();
}
}
}
}
package com.stream_pi.client.window.firsttimeuse;
package com.stream_pi.client.window.firsttimeuse;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
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.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class FinalConfigPane extends VBox
public class FinalConfigPane extends VBox
{
{
private TextField clientNicknameTextField;
private TextField clientNicknameTextField;
private TextField serverIPHostNameTextField;
private TextField serverIPHostNameTextField;
private TextField serverPortTextField;
private TextField serverPortTextField;
private Button nextButton;
private Button nextButton;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ClientListener clientListener;
private ClientListener clientListener;
public FinalConfigPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ClientListener clientListener,
public FinalConfigPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ClientListener clientListener,
Button nextButton)
Button nextButton)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.clientListener = clientListener;
this.clientListener = clientListener;
this.nextButton = nextButton;
this.nextButton = nextButton;
getStyleClass().add("first_time_use_pane_final_config");
getStyleClass().add("first_time_use_pane_final_config");
Label label = new Label("Thats it. Now just a little bit and then you're set!");
Label label = new Label("Thats it. Now just a little bit and then you're set!");
label.setWrapText(true);
label.setWrapText(true);
VBox.setVgrow(label, Priority.ALWAYS);
VBox.setVgrow(label, Priority.ALWAYS);
label.getStyleClass().add("first_time_use_pane_final_config_label");
label.getStyleClass().add("first_time_use_pane_final_config_label");
clientNicknameTextField = new TextField();
clientNicknameTextField = new TextField();
serverIPHostNameTextField = new TextField();
serverIPHostNameTextField = new TextField();
serverPortTextField = new TextField();
serverPortTextField = new TextField();
HBoxInputBox clientNickNameInputBox = new HBoxInputBox("Nickname", clientNicknameTextField);
HBoxInputBox clientNickNameInputBox = new HBoxInputBox("Nickname", clientNicknameTextField, 150);
HBoxInputBox serverIPHostNameInputBox = new HBoxInputBox("Server IP", serverIPHostNameTextField);
HBoxInputBox serverIPHostNameInputBox = new HBoxInputBox("Server IP", serverIPHostNameTextField, 150);
HBoxInputBox serverIPPortInputBox = new HBoxInputBox("Server Port", serverPortTextField);
HBoxInputBox serverIPPortInputBox = new HBoxInputBox("Server Port", serverPortTextField, 150);
getChildren().addAll(label, clientNickNameInputBox, serverIPHostNameInputBox, serverIPPortInputBox);
getChildren().addAll(label, clientNickNameInputBox, serverIPHostNameInputBox, serverIPPortInputBox);
setSpacing(10.0);
setSpacing(10.0);
setVisible(false);
setVisible(false);
}
}
public void makeChangesToNextButton()
public void makeChangesToNextButton()
{
{
nextButton.setText("Confirm");
nextButton.setText("Confirm");
nextButton.setOnAction(event -> onConfirmButtonClicked());
nextButton.setOnAction(event -> onConfirmButtonClicked());
}
}
private void onConfirmButtonClicked()
private void onConfirmButtonClicked()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(clientNicknameTextField.getText().isBlank())
if(clientNicknameTextField.getText().isBlank())
{
{
errors.append("* Nick name cannot be blank.\n");
errors.append("* Nick name cannot be blank.\n");
}
}
if(serverIPHostNameTextField.getText().isBlank())
if(serverIPHostNameTextField.getText().isBlank())
{
{
errors.append("* Server IP cannot be empty.\n");
errors.append("* Server IP cannot be empty.\n");
}
}
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");
}
}
if(errors.toString().isEmpty())
if(errors.toString().isEmpty())
{
{
try
try
{
{
Config.getInstance().setNickName(clientNicknameTextField.getText());
Config.getInstance().setNickName(clientNicknameTextField.getText());
Config.getInstance().setServerHostNameOrIP(serverIPHostNameTextField.getText());
Config.getInstance().setServerHostNameOrIP(serverIPHostNameTextField.getText());
Config.getInstance().setServerPort(port);
Config.getInstance().setServerPort(port);
Config.getInstance().setFirstTimeUse(false);
Config.getInstance().setFirstTimeUse(false);
Config.getInstance().save();
Config.getInstance().save();
clientListener.init();
clientListener.init();
clientListener.setupClientConnection();
clientListener.setupClientConnection();
}
}
catch(SevereException e)
catch(SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
else
else
{
{
new StreamPiAlert("Uh Oh", "Please rectify the following errors and try again:\n"+errors.toString(), StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh", "Please rectify the following errors and try again:\n"+errors.toString(), StreamPiAlertType.ERROR).show();
}
}
}
}
}
}
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());
screenTimeoutTextField.disableProperty().bind(screenSaverToggleSwitch.selectedProperty().not());
Label settingsLabel = new Label("Settings");
settingsLabel.setPadding(new Insets(5,0,0,5));
settingsLabel.getStyleClass().add("settings_heading_label");
saveButton = new Button("Save");
saveButton.setOnAction(event->onSaveButtonClicked());
connectDisconnectButton = new Button("Connect");
connectDisconnectButton.setOnAction(event -> onConnectDisconnectButtonClicked());
Button exitButton = new Button("Exit");
exitButton.setOnAction(event -> onExitButtonClicked());
HBox buttonBar = new HBox(connectDisconnectButton, saveButton);
shutdownButton = new Button("Shutdown");
shutdownButton.managedProperty().bind(shutdownButton.visibleProperty());
shutdownButton.setOnAction(event -> onShutdownButtonClicked());
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,
screenSaverHBox,
tryConnectingToServerIfActionClickedHBox,
fullScreenModeHBox,
connectOnStartupHBox,
vibrateOnActionPressHBox,
startOnBootHBox,
showCursorHBox,
checkForUpdatesButton,
shutdownButton,
factoryResetButton
);
);
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");
settingsLabel.setPadding(new Insets(5,0,0,5));
settingsLabel.getStyleClass().add("settings_heading_label");
saveButton = new Button("Save");
saveButton.setOnAction(event->onSaveButtonClicked());
connectDisconnectButton = new Button("Connect");
connectDisconnectButton.setOnAction(event -> onConnectDisconnectButtonClicked());
Button exitButton = new Button("Exit");
exitButton.setOnAction(event -> onExitButtonClicked());
HBox buttonBar = new HBox(connectDisconnectButton, saveButton);
shutdownButton = new Button("Shutdown");
shutdownButton.managedProperty().bind(shutdownButton.visibleProperty());
shutdownButton.setOnAction(event -> onShutdownButtonClicked());
vBox.getChildren().addAll(
tryConnectingToServerIfActionClickedHBox,
fullScreenModeHBox,
connectOnStartupHBox,
vibrateOnActionPressHBox,
screenSaverHBox,
startOnBootHBox,
showCursorHBox,
checkForUpdatesButton,
shutdownButton,
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);
}
}
screenSaverHBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenSaverHBox.setVisible(StartupFlags.SCREEN_SAVER_FEATURE);
screenTimeoutSecondsHBoxInputBox.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());
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");
}
}
else
{
if(nickNameTextField.getText().equals("about maker"))
{
new StreamPiAlert("किसने बनाया ? / কে বানিয়েছে ?","ZGViYXlhbiAtIGluZGlh\n" +
"boka XD").show();
}
}
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);
}
}
}
}
}
}