client

Clone or download

Modified Files

package com.stream_pi.client.controller;
package com.stream_pi.client.controller;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.client.connection.Client;
import com.stream_pi.client.connection.Client;
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.profile.ClientProfiles;
import com.stream_pi.client.profile.ClientProfiles;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionGridPaneListener;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionGridPaneListener;
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.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.geometry.Orientation;
import javafx.geometry.Orientation;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ExecutorService;
public interface ClientListener
public interface ClientListener
{
{
void onActionFailed(String profileID, String actionID);
void onActionFailed(String profileID, String actionID);
void onActionClicked(String profileID, String actionID, boolean toggleState);
void onActionClicked(String profileID, String actionID, boolean toggleState);
ClientProfiles getClientProfiles();
ClientProfiles getClientProfiles();
Themes getThemes();
Themes getThemes();
String getDefaultThemeFullName();
String getDefaultThemeFullName();
Client getClient();
Client getClient();
void renderRootDefaultProfile();
void renderRootDefaultProfile();
void setConnected(boolean isConnected);
void setConnected(boolean isConnected);
boolean isConnected();
boolean isConnected();
void renderProfile(ClientProfile clientProfile, boolean freshRender);
void renderProfile(ClientProfile clientProfile, boolean freshRender);
void clearActionBox(int col, int row);
void clearActionBox(int col, int row);
void addBlankActionBox(int col, int row);
void addBlankActionBox(int col, int row);
void renderAction(String currentProfileID, Action action);
void renderAction(String currentProfileID, Action action);
void refreshGridIfCurrentProfile(String currentProfileID);
void refreshGridIfCurrentProfile(String currentProfileID);
ActionBox getActionBox(int col, int row);
ActionBox getActionBox(int col, int row);
ClientProfile getCurrentProfile();
ClientProfile getCurrentProfile();
String getCurrentParent();
String getCurrentParent();
Theme getCurrentTheme();
Theme getCurrentTheme();
void initLogger() throws SevereException;
void initLogger() throws SevereException;
void init();
void init();
void disconnect(String message) throws SevereException;
void disconnect(String message) throws SevereException;
void setupClientConnection();
void setupClientConnection();
void setupClientConnection(Runnable onConnect);
void setupClientConnection(Runnable onConnect);
void updateSettingsConnectDisconnectButton();
void updateSettingsConnectDisconnectButton();
void onCloseRequest();
void onCloseRequest();
void loadSettings();
void loadSettings();
double getStageWidth();
double getStageWidth();
double getStageHeight();
double getStageHeight();
void onDisconnect();
void onDisconnect();
boolean getToggleStatus(String profileID, String actionID);
boolean getToggleStatus(String profileID, String actionID);
ActionBox getActionBoxByProfileAndID(String profileID, String actionID);
ActionBox getActionBoxByProfileAndID(String profileID, String actionID);
void openURL(String URL);
void openURL(String URL);
void factoryReset();
void factoryReset();
void exitApp();
void exitApp();
ExecutorService getExecutor();
ExecutorService getExecutor();
Orientation getCurrentOrientation();
Orientation getCurrentOrientation();
void setFirstRun(boolean firstRun);
void setFirstRun(boolean firstRun);
ScreenSaver getScreenSaver();
}
}
package com.stream_pi.client.controller;
package com.stream_pi.client.controller;
import com.gluonhq.attach.browser.BrowserService;
import com.gluonhq.attach.browser.BrowserService;
import com.gluonhq.attach.orientation.OrientationService;
import com.gluonhq.attach.orientation.OrientationService;
import com.gluonhq.attach.vibration.VibrationService;
import com.gluonhq.attach.vibration.VibrationService;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.client.connection.Client;
import com.stream_pi.client.connection.Client;
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 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.Base;
import com.stream_pi.client.window.Base;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionGridPaneListener;
import com.stream_pi.client.window.dashboard.actiongridpane.ActionGridPaneListener;
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.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.gluonhq.attach.lifecycle.LifecycleService;
import com.gluonhq.attach.lifecycle.LifecycleService;
import com.gluonhq.attach.util.Services;
import com.gluonhq.attach.util.Services;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.iohelper.IOHelper;
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 javafx.animation.Interpolator;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Orientation;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Screen;
import javafx.stage.Screen;
import javafx.util.Duration;
import javafx.util.Duration;
import java.io.*;
import java.io.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Level;
public class Controller extends Base
public class Controller extends Base
{
{
private Client client;
private Client client;
public Controller()
public Controller()
{
{
client = null;
client = null;
}
}
private boolean firstRun = true;
private boolean firstRun = true;
private ScreenSaver screenSaver = null;
private ScreenSaver screenSaver = null;
@Override
public ScreenSaver getScreenSaver()
{
return screenSaver;
}
@Override
@Override
public void init()
public void init()
{
{
try
try
{
{
if(firstRun)
if(firstRun)
initBase();
initBase();
if (screenSaver != null)
if (screenSaver != null)
{
{
screenSaver.stop();
screenSaver.stop();
getChildren().remove(screenSaver);
getChildren().remove(screenSaver);
}
}
screenSaver = new ScreenSaver(getConfig().isScreenSaverEnabled(), this, getConfig().getScreenSaverTimeout());
screenSaver = new ScreenSaver(getConfig().isScreenSaverEnabled(), this, getConfig().getScreenSaverTimeout());
getChildren().add(screenSaver);
getChildren().add(screenSaver);
screenSaver.toBack();
screenSaver.toBack();
if(getClientInfo().getPlatform() != com.stream_pi.util.platform.Platform.ANDROID)
if(getClientInfo().getPlatform() != com.stream_pi.util.platform.Platform.ANDROID)
{
{
if(getConfig().isStartOnBoot())
if(getConfig().isStartOnBoot())
{
{
if(StartupFlags.IS_X_MODE != getConfig().isStartupXMode())
if(StartupFlags.IS_X_MODE != getConfig().isStartupXMode())
{
{
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
boolean result = startAtBoot.delete();
boolean result = startAtBoot.delete();
if(!result)
if(!result)
new StreamPiAlert("Uh Oh!", "Unable to delete the previous starter file.\n" +
new StreamPiAlert("Uh Oh!", "Unable to delete the previous starter file.\n" +
"This was probably because you ran Stream-Pi as root before. Restart stream pi as root, " +
"This was probably because you ran Stream-Pi as root before. Restart stream pi as root, " +
"delete the old starter file, then exit and restart Stream-Pi as normal user.", StreamPiAlertType.ERROR).show();
"delete the old starter file, then exit and restart Stream-Pi as normal user.", StreamPiAlertType.ERROR).show();
else
else
{
{
if(StartupFlags.RUNNER_FILE_NAME == null)
try
{
new StreamPiAlert("Uh Oh!",
"It looks like the runner file name for startup isn't specified in " +
"startup arguments. The start on boot functionality will be turned off.").show();
getConfig().setStartOnBoot(false);
}
else
{
{
startAtBoot.create(new File(StartupFlags.RUNNER_FILE_NAME),
startAtBoot.create(StartupFlags.RUNNER_FILE_NAME,
StartupFlags.IS_X_MODE);
StartupFlags.IS_X_MODE);
getConfig().setStartupIsXMode(StartupFlags.IS_X_MODE);
getConfig().setStartupIsXMode(StartupFlags.IS_X_MODE);
}
}
catch (MinorException e)
{
getConfig().setStartOnBoot(false);
handleMinorException(e);
}
}
}
}
}
}
}
setupFlags();
setupFlags();
if(!getConfig().getIsFullScreenMode())
if(!getConfig().getIsFullScreenMode())
{
{
getStage().setWidth(getConfig().getStartupWindowWidth());
getStage().setWidth(getConfig().getStartupWindowWidth());
getStage().setHeight(getConfig().getStartupWindowHeight());
getStage().setHeight(getConfig().getStartupWindowHeight());
}
}
}
}
applyDefaultTheme();
applyDefaultTheme();
setupDashWindow();
setupDashWindow();
getStage().show();
getStage().show();
requestFocus();
requestFocus();
if(Config.getInstance().isFirstTimeUse())
if(Config.getInstance().isFirstTimeUse())
return;
return;
setupSettingsWindowsAnimations();
setupSettingsWindowsAnimations();
getDashboardPane().getSettingsButton().setOnAction(event -> {
getDashboardPane().getSettingsButton().setOnAction(event -> {
openSettingsTimeLine.play();
openSettingsTimeLine.play();
});
});
getSettingsPane().getCloseButton().setOnAction(event -> {
getSettingsPane().getCloseButton().setOnAction(event -> {
closeSettingsTimeLine.play();
closeSettingsTimeLine.play();
});
});
setClientProfiles(new ClientProfiles(new File(getConfig().getProfilesPath()), getConfig().getStartupProfileID()));
setClientProfiles(new ClientProfiles(new File(getConfig().getProfilesPath()), getConfig().getStartupProfileID()));
if(getClientProfiles().getLoadingErrors().size() > 0)
if(getClientProfiles().getLoadingErrors().size() > 0)
{
{
StringBuilder errors = new StringBuilder("Please rectify the following errors and try again");
StringBuilder errors = new StringBuilder("Please rectify the following errors and try again");
for(MinorException exception : getClientProfiles().getLoadingErrors())
for(MinorException exception : getClientProfiles().getLoadingErrors())
{
{
errors.append("\n * ")
errors.append("\n * ")
.append(exception.getMessage());
.append(exception.getMessage());
}
}
throw new MinorException("Profiles", errors.toString());
throw new MinorException("Profiles", errors.toString());
}
}
if(getClientInfo().isPhone() && getConfig().isInvertRowsColsOnDeviceRotate())
if(getClientInfo().isPhone() && getConfig().isInvertRowsColsOnDeviceRotate())
{
{
OrientationService.create().ifPresent(orientationService -> {
OrientationService.create().ifPresent(orientationService -> {
if(orientationService.getOrientation().isPresent())
if(orientationService.getOrientation().isPresent())
{
{
setCurrentOrientation(orientationService.getOrientation().get());
setCurrentOrientation(orientationService.getOrientation().get());
orientationService.orientationProperty().addListener((observableValue, oldOrientation, newOrientation) -> {
orientationService.orientationProperty().addListener((observableValue, oldOrientation, newOrientation) -> {
setCurrentOrientation(newOrientation);
setCurrentOrientation(newOrientation);
getDashboardPane().renderProfile(
getDashboardPane().renderProfile(
getCurrentProfile(),
getCurrentProfile(),
getCurrentParent(),
getCurrentParent(),
true
true
);
);
getExecutor().submit(()->{
getExecutor().submit(()->{
try
try
{
{
if(isConnected())
if(isConnected())
{
{
getClient().updateOrientationOnClient(getCurrentOrientation());
getClient().updateOrientationOnClient(getCurrentOrientation());
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
});
});
});
});
}
}
});
});
}
}
renderRootDefaultProfile();
renderRootDefaultProfile();
loadSettings();
loadSettings();
if(firstRun)
if(firstRun)
{
{
if(getConfig().isConnectOnStartup())
if(getConfig().isConnectOnStartup())
{
{
setupClientConnection();
setupClientConnection();
}
}
firstRun = false;
firstRun = false;
}
}
if(!getClientInfo().isPhone())
if(!getClientInfo().isPhone())
{
{
getStage().widthProperty().addListener((observableValue, orientation, t1) -> syncClientSizeDetailsWithServer());
getStage().widthProperty().addListener((observableValue, orientation, t1) -> syncClientSizeDetailsWithServer());
getStage().heightProperty().addListener((observableValue, orientation, t1) -> syncClientSizeDetailsWithServer());
getStage().heightProperty().addListener((observableValue, orientation, t1) -> syncClientSizeDetailsWithServer());
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
}
}
private Orientation currentOrientation = null;
private Orientation currentOrientation = null;
@Override
@Override
public Orientation getCurrentOrientation()
public Orientation getCurrentOrientation()
{
{
return currentOrientation;
return currentOrientation;
}
}
private void setCurrentOrientation(Orientation currentOrientation)
private void setCurrentOrientation(Orientation currentOrientation)
{
{
this.currentOrientation = currentOrientation;
this.currentOrientation = currentOrientation;
}
}
public void syncClientSizeDetailsWithServer()
public void syncClientSizeDetailsWithServer()
{
{
if(isConnected())
if(isConnected())
{
{
try {
try {
client.sendClientScreenDetails();
client.sendClientScreenDetails();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
@Override
@Override
public void setupClientConnection()
public void setupClientConnection()
{
{
setupClientConnection(null);
setupClientConnection(null);
}
}
@Override
@Override
public void setupClientConnection(Runnable onConnect)
public void setupClientConnection(Runnable onConnect)
{
{
if(getSettingsPane().getGeneralTab().getConnectDisconnectButton().isDisabled()) //probably already connecting
if(getSettingsPane().getGeneralTab().getConnectDisconnectButton().isDisabled()) //probably already connecting
return;
return;
Platform.runLater(()->getSettingsPane().getGeneralTab().setDisableStatus(true));
Platform.runLater(()->getSettingsPane().getGeneralTab().setDisableStatus(true));
client = new Client(getConfig().getSavedServerHostNameOrIP(), getConfig().getSavedServerPort(), this, this, onConnect);
client = new Client(getConfig().getSavedServerHostNameOrIP(), getConfig().getSavedServerPort(), this, this, onConnect);
}
}
@Override
@Override
public void updateSettingsConnectDisconnectButton() {
public void updateSettingsConnectDisconnectButton() {
getSettingsPane().getGeneralTab().setConnectDisconnectButtonStatus();
getSettingsPane().getGeneralTab().setConnectDisconnectButtonStatus();
}
}
@Override
@Override
public void disconnect(String message) throws SevereException {
public void disconnect(String message) throws SevereException {
client.disconnect(message);
client.disconnect(message);
}
}
public void setupDashWindow()
public void setupDashWindow()
{
{
getStage().setTitle("Stream-Pi Client");
getStage().setTitle("Stream-Pi Client");
getStage().setOnCloseRequest(e->{
getStage().setOnCloseRequest(e->{
onCloseRequest();
onCloseRequest();
exitApp();
exitApp();
});
});
}
}
@Override
@Override
public void onCloseRequest()
public void onCloseRequest()
{
{
try
try
{
{
if(isConnected())
if(isConnected())
client.exit();
client.exit();
screenSaver.stop();
screenSaver.stop();
if(!getClientInfo().isPhone() && !getConfig().getIsFullScreenMode())
if(!getClientInfo().isPhone() && !getConfig().getIsFullScreenMode())
{
{
getConfig().setStartupWindowSize(getStageWidth(), getStageHeight());
getConfig().setStartupWindowSize(getStageWidth(), getStageHeight());
getConfig().save();
getConfig().save();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
finally
finally
{
{
getLogger().info("Shut down");
getLogger().info("Shut down");
closeLogger();
closeLogger();
Config.nullify();
Config.nullify();
}
}
}
}
@Override
@Override
public void exitApp()
public void exitApp()
{
{
getExecutor().shutdown();
getExecutor().shutdown();
if (ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.ANDROID)
if (ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.ANDROID)
{
{
Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);
Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);
}
}
else
else
{
{
Platform.exit();
Platform.exit();
}
}
}
}
@Override
@Override
public void loadSettings() {
public void loadSettings() {
try {
try {
getSettingsPane().getGeneralTab().loadData();
getSettingsPane().getGeneralTab().loadData();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@Override
@Override
public Client getClient() {
public Client getClient() {
return client;
return client;
}
}
@Override
@Override
public void onDisconnect() {
public void onDisconnect() {
Platform.runLater(()->getDashboardPane().getActionGridPane().toggleOffAllToggleActions());
Platform.runLater(()->getDashboardPane().getActionGridPane().toggleOffAllToggleActions());
}
}
@Override
@Override
public boolean getToggleStatus(String profileID, String actionID)
public boolean getToggleStatus(String profileID, String actionID)
{
{
return getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID).getCurrentToggleStatus();
return getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID).getCurrentToggleStatus();
}
}
private Timeline openSettingsTimeLine;
private Timeline openSettingsTimeLine;
private Timeline closeSettingsTimeLine;
private Timeline closeSettingsTimeLine;
private void setupSettingsWindowsAnimations()
private void setupSettingsWindowsAnimations()
{
{
Node settingsNode = getSettingsPane();
Node settingsNode = getSettingsPane();
Node dashboardNode = getDashboardPane();
Node dashboardNode = getDashboardPane();
openSettingsTimeLine = new Timeline();
openSettingsTimeLine = new Timeline();
openSettingsTimeLine.setCycleCount(1);
openSettingsTimeLine.setCycleCount(1);
openSettingsTimeLine.getKeyFrames().addAll(
openSettingsTimeLine.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
0.0D, Interpolator.EASE_IN)),
0.0D, Interpolator.EASE_IN)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
0.0D, Interpolator.LINEAR))
0.0D, Interpolator.LINEAR))
);
);
openSettingsTimeLine.setOnFinished(event1 -> settingsNode.toFront());
openSettingsTimeLine.setOnFinished(event1 -> settingsNode.toFront());
closeSettingsTimeLine = new Timeline();
closeSettingsTimeLine = new Timeline();
closeSettingsTimeLine.setCycleCount(1);
closeSettingsTimeLine.setCycleCount(1);
closeSettingsTimeLine.getKeyFrames().addAll(
closeSettingsTimeLine.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
0.0D, Interpolator.LINEAR)),
0.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
0.0D, Interpolator.LINEAR)),
0.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
1.0D, Interpolator.LINEAR))
1.0D, Interpolator.LINEAR))
);
);
closeSettingsTimeLine.setOnFinished(event1 -> {
closeSettingsTimeLine.setOnFinished(event1 -> {
dashboardNode.toFront();
dashboardNode.toFront();
Platform.runLater(()-> {
Platform.runLater(()-> {
try {
try {
getSettingsPane().getGeneralTab().loadData();
getSettingsPane().getGeneralTab().loadData();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
handleSevereException(e);
handleSevereException(e);
}
}
});
});
});
});
}
}
@Override
@Override
public void handleMinorException(MinorException e)
public void handleMinorException(MinorException e)
{
{
getLogger().log(Level.SEVERE, e.getMessage(), e);
getLogger().log(Level.SEVERE, e.getMessage(), e);
e.printStackTrace();
e.printStackTrace();
Platform.runLater(()-> genNewAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show());
Platform.runLater(()-> genNewAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show());
}
}
@Override
@Override
public void handleSevereException(SevereException e)
public void handleSevereException(SevereException e)
{
{
getLogger().log(Level.SEVERE, e.getMessage(), e);
getLogger().log(Level.SEVERE, e.getMessage(), e);
e.printStackTrace();
e.printStackTrace();
Platform.runLater(()->
Platform.runLater(()->
{
{
StreamPiAlert alert = genNewAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
StreamPiAlert alert = genNewAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
alert.setOnClicked(new StreamPiAlertListener()
alert.setOnClicked(new StreamPiAlertListener()
{
{
@Override
@Override
public void onClick(String txt)
public void onClick(String txt)
{
{
onCloseRequest();
onCloseRequest();
exitApp();
exitApp();
}
}
});
});
alert.show();
alert.show();
});
});
}
}
@Override
@Override
public void onAlert(String title, String body, StreamPiAlertType alertType) {
public void onAlert(String title, String body, StreamPiAlertType alertType) {
Platform.runLater(()-> genNewAlert(title, body, alertType).show());
Platform.runLater(()-> genNewAlert(title, body, alertType).show());
}
}
public StreamPiAlert genNewAlert(String title, String message, StreamPiAlertType alertType)
public StreamPiAlert genNewAlert(String title, String message, StreamPiAlertType alertType)
{
{
return new StreamPiAlert(title, message, alertType);
return new StreamPiAlert(title, message, alertType);
}
}
private boolean isConnected = false;
private boolean isConnected = false;
@Override
@Override
public void onActionFailed(String profileID, String actionID) {
public void onActionFailed(String profileID, String actionID) {
Platform.runLater(()-> getDashboardPane().getActionGridPane().actionFailed(profileID, actionID));
Platform.runLater(()-> getDashboardPane().getActionGridPane().actionFailed(profileID, actionID));
}
}
@Override
@Override
public void onActionClicked(String profileID, String actionID, boolean toggleState)
public void onActionClicked(String profileID, String actionID, boolean toggleState)
{
{
try {
try {
vibratePhone();
vibratePhone();
client.onActionClicked(profileID, actionID, toggleState);
client.onActionClicked(profileID, actionID, toggleState);
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
handleSevereException(e);
handleSevereException(e);
}
}
}
}
public void vibratePhone()
public void vibratePhone()
{
{
if(getConfig().isVibrateOnActionClicked())
if(getConfig().isVibrateOnActionClicked())
{
{
VibrationService.create().ifPresent(VibrationService::vibrate);
VibrationService.create().ifPresent(VibrationService::vibrate);
}
}
}
}
@Override
@Override
public void setConnected(boolean isConnected) {
public void setConnected(boolean isConnected) {
this.isConnected = isConnected;
this.isConnected = isConnected;
}
}
@Override
@Override
public ActionBox getActionBox(int col, int row)
public ActionBox getActionBox(int col, int row)
{
{
return getDashboardPane().getActionGridPane().getActionBox(col, row);
return getDashboardPane().getActionGridPane().getActionBox(col, row);
}
}
@Override
@Override
public boolean isConnected()
public boolean isConnected()
{
{
return isConnected;
return isConnected;
}
}
@Override
@Override
public void renderProfile(ClientProfile clientProfile, boolean freshRender)
public void renderProfile(ClientProfile clientProfile, boolean freshRender)
{
{
getDashboardPane().renderProfile(clientProfile, freshRender);
getDashboardPane().renderProfile(clientProfile, freshRender);
}
}
@Override
@Override
public void clearActionBox(int col, int row)
public void clearActionBox(int col, int row)
{
{
Platform.runLater(()->getDashboardPane().getActionGridPane().clearActionBox(col, row));
Platform.runLater(()->getDashboardPane().getActionGridPane().clearActionBox(col, row));
}
}
@Override
@Override
public void addBlankActionBox(int col, int row)
public void addBlankActionBox(int col, int row)
{
{
Platform.runLater(()->getDashboardPane().getActionGridPane().addBlankActionBox(col, row));
Platform.runLater(()->getDashboardPane().getActionGridPane().addBlankActionBox(col, row));
}
}
@Override
@Override
public void renderAction(String currentProfileID, Action action)
public void renderAction(String currentProfileID, Action action)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
try {
try {
if(getDashboardPane().getActionGridPane().getCurrentParent().equals(action.getParent()) &&
if(getDashboardPane().getActionGridPane().getCurrentParent().equals(action.getParent()) &&
getCurrentProfile().getID().equals(currentProfileID))
getCurrentProfile().getID().equals(currentProfileID))
{
{
getDashboardPane().getActionGridPane().renderAction(action);
getDashboardPane().getActionGridPane().renderAction(action);
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
}
}
@Override
@Override
public void refreshGridIfCurrentProfile(String profileID) {
public void refreshGridIfCurrentProfile(String profileID) {
if(getCurrentProfile().getID().equals(profileID))
if(getCurrentProfile().getID().equals(profileID))
{
{
Platform.runLater(()-> getDashboardPane().renderProfile(getClientProfiles().getProfileFromID(profileID), true));
Platform.runLater(()-> getDashboardPane().renderProfile(getClientProfiles().getProfileFromID(profileID), true));
}
}
}
}
@Override
@Override
public ClientProfile getCurrentProfile() {
public ClientProfile getCurrentProfile() {
return getDashboardPane().getActionGridPane().getClientProfile();
return getDashboardPane().getActionGridPane().getClientProfile();
}
}
@Override
@Override
public String getCurrentParent()
public String getCurrentParent()
{
{
return getDashboardPane().getActionGridPane().getCurrentParent();
return getDashboardPane().getActionGridPane().getCurrentParent();
}
}
@Override
@Override
public ActionBox getActionBoxByProfileAndID(String profileID, String actionID)
public ActionBox getActionBoxByProfileAndID(String profileID, String actionID)
{
{
Action action = getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID);
Action action = getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID);
if(!getCurrentProfile().getID().equals(profileID) && !getCurrentParent().equals(action.getParent()))
if(!getCurrentProfile().getID().equals(profileID) && !getCurrentParent().equals(action.getParent()))
return null;
return null;
return getDashboardPane().getActionGridPane().getActionBoxByLocation(action.getLocation());
return getDashboardPane().getActionGridPane().getActionBoxByLocation(action.getLocation());
}
}
@Override
@Override
public void openURL(String url)
public void openURL(String url)
{
{
if(ClientInfo.getInstance().isPhone())
if(ClientInfo.getInstance().isPhone())
{
{
BrowserService.create().ifPresentOrElse(s->
BrowserService.create().ifPresentOrElse(s->
{
{
try
try
{
{
s.launchExternalBrowser(url);
s.launchExternalBrowser(url);
}
}
catch (Exception e )
catch (Exception e )
{
{
handleMinorException(
handleMinorException(
new MinorException("Cant start browser! You can go to Server Settings > About > Contact " +
new MinorException("Cant start browser! You can go to Server Settings > About > Contact " +
"and open the links from there.")
"and open the links from there.")
);
);
}
}
},()-> handleMinorException(
},()-> handleMinorException(
new MinorException("Sorry!","No browser detected. You can go to Server Settings > About > Contact " +
new MinorException("Sorry!","No browser detected. You can go to Server Settings > About > Contact " +
"and open the links from there.")
"and open the links from there.")
));
));
}
}
else
else
{
{
if(getClientInfo().getPlatform() == com.stream_pi.util.platform.Platform.LINUX &&
if(getClientInfo().getPlatform() == com.stream_pi.util.platform.Platform.LINUX &&
!StartupFlags.IS_X_MODE)
!StartupFlags.IS_X_MODE)
{
{
handleMinorException(new MinorException("Sorry!","Your system is running directly on framebuffer and " +
handleMinorException(new MinorException("Sorry!","Your system is running directly on framebuffer and " +
"does not support opening a browser. You can go to Server Settings > About > Contact " +
"does not support opening a browser. You can go to Server Settings > About > Contact " +
"and open the links from there."));
"and open the links from there."));
}
}
else
else
{
{
getHostServices().showDocument(url);
getHostServices().showDocument(url);
}
}
}
}
}
}
@Override
@Override
public void factoryReset()
public void factoryReset()
{
{
getLogger().info("Reset to factory ...");
getLogger().info("Reset to factory ...");
onCloseRequest();
onCloseRequest();
boolean result = IOHelper.deleteFile(getClientInfo().getPrePath());
boolean result = IOHelper.deleteFile(getClientInfo().getPrePath());
if(result)
if(result)
{
{
setFirstRun(true);
setFirstRun(true);
init();
init();
}
}
else
else
{
{
handleSevereException(new SevereException("Unable to delete all files successfully. Installation corrupt. Re-install."));
handleSevereException(new SevereException("Unable to delete all files successfully. Installation corrupt. Re-install."));
}
}
}
}
@Override
@Override
public void setFirstRun(boolean firstRun)
public void setFirstRun(boolean firstRun)
{
{
this.firstRun = firstRun;
this.firstRun = firstRun;
}
}
}
}
package com.stream_pi.client.controller;
package com.stream_pi.client.controller;
import com.stream_pi.client.window.Base;
import com.stream_pi.client.window.Base;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.animation.*;
import javafx.animation.*;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import javafx.util.Duration;
import java.util.Timer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TimerTask;
public class ScreenSaver extends StackPane
public class ScreenSaver extends StackPane
{
{
private boolean isEnabled = false;
private boolean isEnabled = false;
private Timer timer;
private Timer timer;
private Timeline showScreenSaverTimeline;
private Timeline showScreenSaverTimeline;
private long timeout;
private long timeout;
public ScreenSaver(boolean isEnabled, Base base, int timeout)
public ScreenSaver(boolean isEnabled, Base base, int timeout)
{
{
this.isEnabled = isEnabled;
this.isEnabled = isEnabled;
this.timeout = timeout* 1000L;
this.timeout = timeout* 1000L;
setOpacity(0);
setOpacity(0);
getStyleClass().add("screensaver");
getStyleClass().add("screensaver");
if(isEnabled)
if(isEnabled)
{
{
showScreenSaverTimeline = new Timeline();
showScreenSaverTimeline = new Timeline();
showScreenSaverTimeline.setCycleCount(1);
showScreenSaverTimeline.setCycleCount(1);
showScreenSaverTimeline.getKeyFrames().addAll(
showScreenSaverTimeline.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(opacityProperty(),
new KeyValue(opacityProperty(),
0.0D, Interpolator.EASE_IN)),
0.0D, Interpolator.EASE_IN)),
new KeyFrame(Duration.seconds(15D),
new KeyFrame(Duration.seconds(15D),
new KeyValue(opacityProperty(),
new KeyValue(opacityProperty(),
1.0D, Interpolator.LINEAR))
1.0D, Interpolator.LINEAR))
);
);
startTimer();
startTimer();
base.setOnMouseClicked(mouseEvent -> {
base.setOnMouseClicked(mouseEvent -> {
close();
close();
restartTimer();
restartTimer();
});
});
}
}
}
}
public void stop()
public void stop()
{
{
stopTimer();
stopTimer();
setOpacity(0);
setOpacity(0);
toBack();
toBack();
}
}
public boolean isEnabled() {
public boolean isEnabled() {
return isEnabled;
return isEnabled;
}
}
private void show()
private void show()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
setOpacity(0);
setOpacity(0);
toFront();
toFront();
showScreenSaverTimeline.play();
showScreenSaverTimeline.play();
});
});
}
}
private void close()
private void close()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
if(showScreenSaverTimeline.getStatus() == Animation.Status.RUNNING)
if(showScreenSaverTimeline.getStatus() == Animation.Status.RUNNING)
{
{
showScreenSaverTimeline.stop();
showScreenSaverTimeline.stop();
}
}
setOpacity(0.0);
setOpacity(0.0);
toBack();
toBack();
});
});
restartTimer();
restartTimer();
}
}
private void restartTimer()
public void setTimeout(long timeout)
{
this.timeout = timeout;
}
public void restartTimer()
{
{
stopTimer();
stopTimer();
startTimer();
startTimer();
}
}
private void stopTimer()
private void stopTimer()
{
{
if(timer != null)
if(timer != null)
{
{
timer.cancel();
timer.cancel();
timer.purge();
timer.purge();
}
}
}
}
private void startTimer()
private void startTimer()
{
{
timer = new Timer();
timer = new Timer();
timer.schedule(new TimerTask() {
timer.schedule(new TimerTask() {
@Override
@Override
public void run() {
public void run() {
show();
show();
}
}
},timeout);
},timeout);
}
}
}
}
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 HBoxWithSpaceBetween invertRowsColsHBox;
private HBoxWithSpaceBetween invertRowsColsHBox;
private ToggleSwitch invertRowsColsToggleSwitch;
private ToggleSwitch invertRowsColsToggleSwitch;
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());
invertRowsColsToggleSwitch = new ToggleSwitch();
invertRowsColsToggleSwitch = new ToggleSwitch();
invertRowsColsHBox = new HBoxWithSpaceBetween("Invert Grid on Rotate", invertRowsColsToggleSwitch);
invertRowsColsHBox = new HBoxWithSpaceBetween("Invert Grid on Rotate", invertRowsColsToggleSwitch);
invertRowsColsHBox.managedProperty().bind(invertRowsColsHBox.visibleProperty());
invertRowsColsHBox.managedProperty().bind(invertRowsColsHBox.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");
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 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,
invertRowsColsHBox,
invertRowsColsHBox,
screenSaverHBox,
screenSaverHBox,
tryConnectingToServerIfActionClickedHBox,
tryConnectingToServerIfActionClickedHBox,
fullScreenModeHBox,
fullScreenModeHBox,
connectOnStartupHBox,
connectOnStartupHBox,
vibrateOnActionPressHBox,
vibrateOnActionPressHBox,
startOnBootHBox,
startOnBootHBox,
showCursorHBox,
showCursorHBox,
checkForUpdatesButton,
checkForUpdatesButton,
shutdownButton,
shutdownButton,
factoryResetButton
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(30));
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(30));
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
{
{
shutdownButton.setVisible(StartupFlags.IS_SHOW_SHUT_DOWN_BUTTON);
shutdownButton.setVisible(StartupFlags.IS_SHOW_SHUT_DOWN_BUTTON);
vibrateOnActionPressHBox.setVisible(false);
vibrateOnActionPressHBox.setVisible(false);
invertRowsColsHBox.setVisible(false);
invertRowsColsHBox.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());
invertRowsColsToggleSwitch.setSelected(config.isInvertRowsColsOnDeviceRotate());
invertRowsColsToggleSwitch.setSelected(config.isInvertRowsColsOnDeviceRotate());
}
}
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
else
{
{
if(nickNameTextField.getText().equals("about maker"))
if(nickNameTextField.getText().equals("about maker"))
{
{
new StreamPiAlert("किसने बनाया ? / কে বানিয়েছে ?","ZGViYXlhbiAtIGluZGlh\n" +
new StreamPiAlert("किसने बनाया ? / কে বানিয়েছে ?","ZGViYXlhbiAtIGluZGlh\n" +
"boka XD").show();
"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)
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
if(startOnBoot)
{
{
new StreamPiAlert("Uh Oh", "No Runner File Name Specified as startup arguments. Cant set run at boot.", StreamPiAlertType.ERROR).show();
try
startOnBoot = false;
}
else
{
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
if(startOnBoot)
{
{
startAtBoot.create(new File(StartupFlags.RUNNER_FILE_NAME),
startAtBoot.create(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
catch (MinorException e)
{
{
boolean result = startAtBoot.delete();
exceptionAndAlertHandler.handleMinorException(e);
if(!result)
startOnBoot = false;
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
}
else
{
boolean result = startAtBoot.delete();
if(!result)
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()) && config.isScreenSaverEnabled())
toBeReloaded = true;
{
config.setScreenSaverTimeout(screenTimeoutTextField.getText());
clientListener.getScreenSaver().setTimeout(config.getScreenSaverTimeout());
clientListener.getScreenSaver().restartTimer();
}
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.setInvertRowsColsOnDeviceRotate(invertRowsColsToggleSwitch.isSelected());
config.setInvertRowsColsOnDeviceRotate(invertRowsColsToggleSwitch.isSelected());
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)
{
{
if(!ClientInfo.getInstance().isPhone() && !config.getIsFullScreenMode())
{
config.setStartupWindowSize(clientListener.getStageWidth(), clientListener.getStageHeight());
config.save();
}
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);
}
}
}
}
}
}