server
Clone or download
Modified Files
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>server</artifactId>
<artifactId>server</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.target>11</maven.compiler.target>
<client.plugin.version>0.1.36</client.plugin.version>
<client.plugin.version>0.1.36</client.plugin.version>
<JavaFXVersion>16-ea+7</JavaFXVersion>
<JavaFXVersion>16-ea+7</JavaFXVersion>
<CommonsBeanUtilsVersion>1.9.4</CommonsBeanUtilsVersion>
<CommonsBeanUtilsVersion>1.9.4</CommonsBeanUtilsVersion>
<CommonsConfigurationVersion>2.7</CommonsConfigurationVersion>
<CommonsConfigurationVersion>2.7</CommonsConfigurationVersion>
<ActionAPIVersion>1.0.0-SNAPSHOT</ActionAPIVersion>
<ActionAPIVersion>1.0.0-SNAPSHOT</ActionAPIVersion>
<ThemeAPIVersion>1.0.0-SNAPSHOT</ThemeAPIVersion>
<ThemeAPIVersion>1.0.0-SNAPSHOT</ThemeAPIVersion>
<UtilVersion>1.0.0-SNAPSHOT</UtilVersion>
<UtilVersion>1.0.0-SNAPSHOT</UtilVersion>
<Log4JVersion>2.14.0</Log4JVersion>
<Log4JVersion>2.14.0</Log4JVersion>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<MainClassName>com.stream_pi.server.Main</MainClassName>
<MainClassName>com.stream_pi.server.Main</MainClassName>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<artifactId>javafx-controls</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<artifactId>javafx-media</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${IkonliFA5PackVersion}</version>
<version>${IkonliFA5PackVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<artifactId>ikonli-javafx</artifactId>
<version>${IkonliVersion}</version>
<version>${IkonliVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<artifactId>javafx-base</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>action-api</artifactId>
<artifactId>action-api</artifactId>
<version>${ActionAPIVersion}</version>
<version>${ActionAPIVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>${UtilVersion}</version>
<version>${UtilVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>theme-api</artifactId>
<artifactId>theme-api</artifactId>
<version>${ThemeAPIVersion}</version>
<version>${ThemeAPIVersion}</version>
</dependency>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20201115</version>
</dependency>
</dependencies>
</dependencies>
<repositories>
<repositories>
<repository>
<repository>
<id>gluon-releases</id>
<id>gluon-releases</id>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
</repository>
</repository>
</repositories>
</repositories>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.8.1</version>
<configuration>
<configuration>
<release>11</release>
<release>11</release>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.5</version>
<version>0.0.5</version>
<configuration>
<configuration>
<commandlineArgs>-DStreamPi.startupRunnerFileName=run_min -DStreamPi.startupMode=maximise</commandlineArgs>
<commandlineArgs>-DStreamPi.startupRunnerFileName=run_min -DStreamPi.startupMode=maximise</commandlineArgs>
<options>
<options>
<option>-Dglass.gtk.uiScale=1.0</option>
<option>-Dglass.gtk.uiScale=1.0</option>
</options>
</options>
<mainClass>${MainClassName}</mainClass>
<mainClass>${MainClassName}</mainClass>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<artifactId>client-maven-plugin</artifactId>
<version>${client.plugin.version}</version>
<version>${client.plugin.version}</version>
<configuration>
<configuration>
<nativeImageArgs>
<nativeImageArgs>
<list>--initialize-at-build-time=com.sun.org.apache.xml.internal.serializer.ToXMLStream</list>
<list>--initialize-at-build-time=com.sun.org.apache.xml.internal.serializer.ToXMLStream</list>
<!--list>-Dsvm.targetName=android</list-->
<!--list>-Dsvm.targetName=android</list-->
</nativeImageArgs>
</nativeImageArgs>
<bundlesList>
<bundlesList>
<list>com.sun.org.apache.xerces.internal.impl.msg.XMLMessages</list>
<list>com.sun.org.apache.xerces.internal.impl.msg.XMLMessages</list>
</bundlesList>
</bundlesList>
<reflectionList>
<reflectionList>
<list>java.util.logging.FileHandler</list>
<list>java.util.logging.FileHandler</list>
</reflectionList>
</reflectionList>
<mainClass>${MainClassName}</mainClass>
<mainClass>${MainClassName}</mainClass>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.0</version>
<configuration>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
</configuration>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
<pluginRepositories>
<pluginRepositories>
<pluginRepository>
<pluginRepository>
<id>gluon-releases</id>
<id>gluon-releases</id>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
</pluginRepository>
</pluginRepository>
<pluginRepository>
<pluginRepository>
<id>gluon-snapshots</id>
<id>gluon-snapshots</id>
<url>https://nexus.gluonhq.com/nexus/content/repositories/public-snapshots</url>
<url>https://nexus.gluonhq.com/nexus/content/repositories/public-snapshots</url>
</pluginRepository>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
</project>
</project>
package com.stream_pi.server.connection;
package com.stream_pi.server.connection;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import java.io.IOException;
import java.io.IOException;
import java.net.BindException;
import java.net.BindException;
import java.net.ServerSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class MainServer extends Thread{
public class MainServer extends Thread{
private ServerListener serverListener;
private ServerListener serverListener;
private Logger logger = Logger.getLogger(MainServer.class.getName());
private Logger logger = Logger.getLogger(MainServer.class.getName());
private int port;
private int port;
private ServerSocket serverSocket = null;
private ServerSocket serverSocket = null;
//private Server server;
//private Server server;
private AtomicBoolean stop = new AtomicBoolean(false);
private AtomicBoolean stop = new AtomicBoolean(false);
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public MainServer(ServerListener serverListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
public MainServer(ServerListener serverListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.port = port;
this.port = port;
this.serverListener = serverListener;
this.serverListener = serverListener;
}
}
public void setPort(int port) {
public void setPort(int port) {
this.port = port;
this.port = port;
}
}
@Override
@Override
public synchronized void start() {
public synchronized void start() {
stop.set(false);
stop.set(false);
super.start();
super.start();
}
}
public void stopListeningForConnections()
public void stopListeningForConnections()
{
{
/*if(server !=null)
/*if(server !=null)
{
{
if(!server.isShutdown())
if(!server.isShutdown())
server.shutdown();
server.shutdown();
}*/
}*/
try
try
{
{
logger.info("Stopping listening for connections ...");
logger.info("Stopping listening for connections ...");
if(serverSocket!=null)
if(serverSocket!=null)
if(!serverSocket.isClosed())
if(!serverSocket.isClosed())
{
stop.set(true);
serverSocket.close();
serverSocket.close();
}
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
}
}
finally {
finally {
logger.info("... Done!");
logger.info("... Done!");
}
}
stop.set(true);
}
}
@Override
@Override
public void run() {
public void run() {
logger.warning("Starting main server on port "+port+" ...");
logger.warning("Starting main server on port "+port+" ...");
try {
try {
logger.info("Starting server on port "+port+" ...");
logger.info("Starting server on port "+port+" ...");
/*Server server = ServerBuilder.forPort(port)
.addService(new ConnectionService(serverListener))
.build();
server.start();
logger.info("... Done!");*/
serverSocket = new ServerSocket(port);
serverSocket = new ServerSocket(port);
while(!stop.get())
while(!stop.get())
{
{
Socket s = serverSocket.accept();
Socket s = serverSocket.accept();
ClientConnections.getInstance().addConnection(new ClientConnection(s, serverListener, exceptionAndAlertHandler));
ClientConnections.getInstance().addConnection(new ClientConnection(s, serverListener, exceptionAndAlertHandler));
logger.info("New client connected ("+s.getRemoteSocketAddress()+") !");
logger.info("New client connected ("+s.getRemoteSocketAddress()+") !");
}
}
}
}
catch (SocketException e)
catch (SocketException e)
{
{
logger.info("Main Server stopped accepting calls ...");
if(!e.getMessage().contains("Socket closed"))
exceptionAndAlertHandler.handleSevereException(new SevereException("Sorry","Unable to Start Server. Check logs, stacktrace. \n\n"+e.getMessage()));
{
e.printStackTrace();
logger.info("Main Server stopped accepting calls ...");
exceptionAndAlertHandler.handleSevereException(new SevereException("Sorry","Another Server Instance probably running. Unable to Start Server \n\n"+e.getMessage()));
e.printStackTrace();
}
}
}
catch (IOException e)
catch (IOException e)
{
{
exceptionAndAlertHandler.handleSevereException(new SevereException("MainServer io Exception occurred!"));
exceptionAndAlertHandler.handleSevereException(new SevereException("MainServer io Exception occurred!"));
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
/*
/*
ServerInfo.java
ServerInfo.java
Stores basic information about the server - name, platform type
Stores basic information about the server - name, platform type
Contributors: Debayan Sutradhar (@dubbadhar)
Contributors: Debayan Sutradhar (@dubbadhar)
*/
*/
package com.stream_pi.server.info;
package com.stream_pi.server.info;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
public class ServerInfo {
public class ServerInfo {
private Version version;
private Version version;
private final ReleaseStatus releaseStatus;
private final ReleaseStatus releaseStatus;
private final Platform platformType;
private final Platform platformType;
private String prePath;
private String prePath;
private Version minThemeSupportVersion;
private Version minThemeSupportVersion;
private Version minPluginSupportVersion;
private Version minPluginSupportVersion;
private Version commStandardVersion;
private Version commStandardVersion;
private static ServerInfo instance = null;
private static ServerInfo instance = null;
private String runnerFileName = null;
private String runnerFileName = null;
private boolean startMinimised = false;
private boolean startMinimised = false;
private ServerInfo(){
private ServerInfo()
{
version = new Version(1,0,0);
version = new Version(1,0,0);
minThemeSupportVersion = new Version(1,0,0);
minThemeSupportVersion = new Version(1,0,0);
minPluginSupportVersion = new Version(1,0,0);
minPluginSupportVersion = new Version(1,0,0);
commStandardVersion = new Version(1,0,0);
commStandardVersion = new Version(1,0,0);
releaseStatus = ReleaseStatus.EA;
releaseStatus = ReleaseStatus.EA;
prePath = "data/";
prePath = "data/";
String osName = System.getProperty("os.name").toLowerCase();
String osName = System.getProperty("os.name").toLowerCase();
if(osName.contains("windows"))
if(osName.contains("windows"))
platformType = Platform.WINDOWS;
platformType = Platform.WINDOWS;
else if (osName.contains("linux"))
else if (osName.contains("linux"))
platformType = Platform.LINUX;
platformType = Platform.LINUX;
else if (osName.contains("mac"))
else if (osName.contains("mac"))
platformType = Platform.MAC;
platformType = Platform.MAC;
else
else
platformType = Platform.UNKNOWN;
platformType = Platform.UNKNOWN;
}
}
public String getPrePath() {
public String getPrePath() {
return prePath;
return prePath;
}
}
public void setStartMinimised(boolean startMinimised)
public void setStartMinimised(boolean startMinimised)
{
{
this.startMinimised = startMinimised;
this.startMinimised = startMinimised;
}
}
public boolean isStartMinimised()
public boolean isStartMinimised()
{
{
return startMinimised;
return startMinimised;
}
}
public void setRunnerFileName(String runnerFileName)
public void setRunnerFileName(String runnerFileName)
{
{
this.runnerFileName = runnerFileName;
this.runnerFileName = runnerFileName;
}
}
public String getRunnerFileName()
public String getRunnerFileName()
{
{
return runnerFileName;
return runnerFileName;
}
}
public static synchronized ServerInfo getInstance(){
public static synchronized ServerInfo getInstance()
{
if(instance == null)
if(instance == null)
{
{
instance = new ServerInfo();
instance = new ServerInfo();
}
}
return instance;
return instance;
}
}
public Platform getPlatformType()
public Platform getPlatformType()
{
{
return platformType;
return platformType;
}
}
public Version getVersion() {
public Version getVersion() {
return version;
return version;
}
}
public ReleaseStatus getReleaseStatus()
public ReleaseStatus getReleaseStatus()
{
{
return releaseStatus;
return releaseStatus;
}
}
public Version getMinThemeSupportVersion()
public Version getMinThemeSupportVersion()
{
{
return minThemeSupportVersion;
return minThemeSupportVersion;
}
}
public Version getMinPluginSupportVersion()
public Version getMinPluginSupportVersion()
{
{
return minPluginSupportVersion;
return minPluginSupportVersion;
}
}
public Version getCommStandardVersion()
public Version getCommStandardVersion()
{
{
return commStandardVersion;
return commStandardVersion;
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
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 javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ActionDetailsPaneListener actionDetailsPaneListener;
private ActionDetailsPaneListener actionDetailsPaneListener;
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
logger = Logger.getLogger(ActionGridPane.class.getName());
logger = Logger.getLogger(ActionGridPane.class.getName());
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
getStyleClass().add("action_grid_pane_parent");
getStyleClass().add("action_grid_pane_parent");
VBox.setVgrow(this, Priority.ALWAYS);
VBox.setVgrow(this, Priority.ALWAYS);
actionsGridPane = new GridPane();
actionsGridPane = new GridPane();
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
setContent(actionsGridPane);
setContent(actionsGridPane);
setCache(true);
setCacheHint(CacheHint.SPEED);
}
}
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
}
}
private String currentParent;
private String currentParent;
@Override
@Override
public void setCurrentParent(String currentParent) {
public void setCurrentParent(String currentParent) {
this.currentParent = currentParent;
this.currentParent = currentParent;
}
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
private Client client;
private Client client;
public void setClient(Client client) {
public void setClient(Client client) {
this.client = client;
this.client = client;
}
}
public Client getClient() {
public Client getClient() {
return client;
return client;
}
}
private int rows, cols;
private int rows, cols;
private GridPane actionsGridPane;
private GridPane actionsGridPane;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClientProfile(ClientProfile clientProfile)
public void setClientProfile(ClientProfile clientProfile)
{
{
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
setCurrentParent("root");
setCurrentParent("root");
setRows(clientProfile.getRows());
setRows(clientProfile.getRows());
setCols(clientProfile.getCols());
setCols(clientProfile.getCols());
}
}
@Override
@Override
public String getCurrentParent() {
public String getCurrentParent() {
return currentParent;
return currentParent;
}
}
public StackPane getFolderBackButton() throws SevereException
public StackPane getFolderBackButton() throws SevereException
{
{
StackPane stackPane = new StackPane();
StackPane stackPane = new StackPane();
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box_valid");
stackPane.getStyleClass().add("action_box_valid");
stackPane.setPrefSize(
stackPane.setPrefSize(
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize()
Config.getInstance().getActionGridActionSize()
);
);
FontIcon fontIcon = new FontIcon("fas-chevron-left");
FontIcon fontIcon = new FontIcon("fas-chevron-left");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.setIconSize(Config.getInstance().getActionGridActionSize() - 30);
fontIcon.setIconSize(Config.getInstance().getActionGridActionSize() - 30);
stackPane.setAlignment(Pos.CENTER);
stackPane.setAlignment(Pos.CENTER);
stackPane.getChildren().add(fontIcon);
stackPane.getChildren().add(fontIcon);
stackPane.setOnMouseClicked(e->returnToPreviousParent());
stackPane.setOnMouseClicked(e->returnToPreviousParent());
return stackPane;
return stackPane;
}
}
private ActionBox[][] actionBoxes;
private ActionBox[][] actionBoxes;
private boolean isFreshRender = true;
private boolean isFreshRender = true;
private Node folderBackButton = null;
private Node folderBackButton = null;
public void renderGrid() throws SevereException
public void renderGrid() throws SevereException
{
{
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
if(isFreshRender)
if(isFreshRender)
{
{
clear();
clear();
actionBoxes = new ActionBox[cols][rows];
actionBoxes = new ActionBox[cols][rows];
}
}
boolean isFolder = false;
boolean isFolder = false;
if(getCurrentParent().equals("root"))
if(getCurrentParent().equals("root"))
{
{
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
actionBoxes[0][0] = addBlankActionBox(0,0);
actionBoxes[0][0] = addBlankActionBox(0,0);
}
}
}
}
else
else
{
{
isFolder = true;
isFolder = true;
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
}
}
else
else
{
{
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
}
}
folderBackButton = getFolderBackButton();
folderBackButton = getFolderBackButton();
actionsGridPane.add(folderBackButton, 0,0);
actionsGridPane.add(folderBackButton, 0,0);
}
}
for(int row = 0; row<rows; row++)
for(int row = 0; row<rows; row++)
{
{
for(int col = 0; col<cols; col++)
for(int col = 0; col<cols; col++)
{
{
if(row == 0 && col == 0 && isFolder)
if(row == 0 && col == 0 && isFolder)
continue;
continue;
if(isFreshRender)
if(isFreshRender)
{
{
actionBoxes[col][row] = addBlankActionBox(col, row);
actionBoxes[col][row] = addBlankActionBox(col, row);
}
}
else
else
{
{
if(actionBoxes[col][row].getAction() != null)
if(actionBoxes[col][row].getAction() != null)
{
{
actionBoxes[col][row].clear();
actionBoxes[col][row].clear();
}
}
}
}
}
}
}
}
isFreshRender = false;
isFreshRender = false;
}
}
public void setFreshRender(boolean freshRender)
public void setFreshRender(boolean freshRender)
{
{
isFreshRender = freshRender;
isFreshRender = freshRender;
}
}
public ActionBox addBlankActionBox(int col, int row) throws SevereException {
public ActionBox addBlankActionBox(int col, int row) throws SevereException {
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this,
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this,
col, row);
col, row);
actionsGridPane.add(actionBox, row, col);
actionsGridPane.add(actionBox, row, col);
return actionBox;
return actionBox;
}
}
public void renderActions()
public void renderActions()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(String action1x : getClientProfile().getActionsKeySet())
for(String action1x : getClientProfile().getActionsKeySet())
{
{
Action eachAction = getClientProfile().getActionByID(action1x);
Action eachAction = getClientProfile().getActionByID(action1x);
logger.info("action ID : "+eachAction.getID()+
logger.info("action ID : "+eachAction.getID()+
"\nInvalid : "+eachAction.isInvalid());
"\nInvalid : "+eachAction.isInvalid());
try {
try {
renderAction(eachAction);
renderAction(eachAction);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
errors.append("*").append(e.getShortMessage()).append("\n");
errors.append("*").append(e.getShortMessage()).append("\n");
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
}
}
}
}
public void clear()
public void clear()
{
{
actionsGridPane.getChildren().clear();
actionsGridPane.getChildren().clear();
}
}
private Logger logger;
private Logger logger;
public void renderAction(Action action) throws SevereException, MinorException
public void renderAction(Action action) throws SevereException, MinorException
{
{
if(!action.getParent().equals(currentParent))
if(!action.getParent().equals(currentParent))
{
{
logger.info("Skipping action "+action.getID()+", not current parent!");
logger.info("Skipping action "+action.getID()+", not current parent!");
return;
return;
}
}
if(action.getLocation().getRow()==-1)
if(action.getLocation().getRow()==-1)
{
{
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
return;
return;
}
}
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
{
{
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
" Consider increasing rows/cols from client settings and relocating/deleting it.");
" Consider increasing rows/cols from client settings and relocating/deleting it.");
}
}
Location location = action.getLocation();
Location location = action.getLocation();
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
actionBox.clear();
actionBox.clear();
actionBox.setAction(action);
actionBox.setAction(action);
actionBox.init();
actionBox.init();
/*ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
/*ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
Location location = action.getLocation();
Location location = action.getLocation();
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
actionBox.setRow(location.getRow());
actionBox.setRow(location.getRow());
actionBox.setCol(location.getCol());
actionBox.setCol(location.getCol());
for(Node node : actionsGridPane.getChildren())
for(Node node : actionsGridPane.getChildren())
{
{
if(GridPane.getColumnIndex(node) == location.getRow() &&
if(GridPane.getColumnIndex(node) == location.getRow() &&
GridPane.getRowIndex(node) == location.getCol())
GridPane.getRowIndex(node) == location.getCol())
{
{
actionsGridPane.getChildren().remove(node);
actionsGridPane.getChildren().remove(node);
break;
break;
}
}
}
}
System.out.println(location.getCol()+","+location.getRow());
System.out.println(location.getCol()+","+location.getRow());
actionsGridPane.add(actionBox, location.getRow(), location.getCol());*/
actionsGridPane.add(actionBox, location.getRow(), location.getCol());*/
}
}
public void setRows(int rows)
public void setRows(int rows)
{
{
this.rows = rows;
this.rows = rows;
}
}
public void setCols(int cols)
public void setCols(int cols)
{
{
this.cols = cols;
this.cols = cols;
}
}
public int getRows()
public int getRows()
{
{
return rows;
return rows;
}
}
public int getCols()
public int getCols()
{
{
return cols;
return cols;
}
}
@Override
@Override
public void addActionToCurrentClientProfile(Action newAction) {
public void addActionToCurrentClientProfile(Action newAction) {
try {
try {
getClientProfile().addAction(newAction);
getClientProfile().addAction(newAction);
} catch (CloneNotSupportedException e) {
} catch (CloneNotSupportedException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private String previousParent;
private String previousParent;
public void setPreviousParent(String previousParent) {
public void setPreviousParent(String previousParent) {
this.previousParent = previousParent;
this.previousParent = previousParent;
}
}
public String getPreviousParent() {
public String getPreviousParent() {
return previousParent;
return previousParent;
}
}
@Override
@Override
public void renderFolder(FolderAction action) {
public void renderFolder(FolderAction action) {
setCurrentParent(action.getID());
setCurrentParent(action.getID());
setPreviousParent(action.getParent());
setPreviousParent(action.getParent());
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void returnToPreviousParent()
public void returnToPreviousParent()
{
{
setCurrentParent(getPreviousParent());
setCurrentParent(getPreviousParent());
if(!getPreviousParent().equals("root"))
if(!getPreviousParent().equals("root"))
{
{
System.out.println("parent : "+getPreviousParent());
System.out.println("parent : "+getPreviousParent());
setPreviousParent(getClientProfile().getActionByID(
setPreviousParent(getClientProfile().getActionByID(
getPreviousParent()
getPreviousParent()
).getParent());
).getParent());
}
}
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.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.startatboot.SoftwareType;
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.version.Version;
import com.stream_pi.util.version.Version;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.control.*;
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.*;
import javafx.scene.layout.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.DirectoryChooser;
import org.json.JSONObject;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.awt.SystemTray;
import java.awt.SystemTray;
import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.File;
import java.io.InputStreamReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URL;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class GeneralSettings extends VBox {
public class GeneralSettings extends VBox {
private final TextField serverNameTextField;
private final TextField serverNameTextField;
private final TextField portTextField;
private final TextField portTextField;
private final TextField pluginsPathTextField;
private final TextField pluginsPathTextField;
private final TextField themesPathTextField;
private final TextField themesPathTextField;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxGap;
private final TextField actionGridPaneActionBoxGap;
private final ToggleButton startOnBootToggleButton;
private final ToggleButton startOnBootToggleButton;
private final ToggleButton closeOnXToggleButton;
private final ToggleButton closeOnXToggleButton;
private final Button saveButton;
private final Button saveButton;
private final Button checkForUpdatesButton;
private final Button checkForUpdatesButton;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ServerListener serverListener;
private ServerListener serverListener;
private HostServices hostServices;
private HostServices hostServices;
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.serverListener = serverListener;
this.serverListener = serverListener;
logger = Logger.getLogger(GeneralSettings.class.getName());
logger = Logger.getLogger(GeneralSettings.class.getName());
serverNameTextField = new TextField();
serverNameTextField = new TextField();
portTextField = new TextField();
portTextField = new TextField();
pluginsPathTextField = new TextField();
pluginsPathTextField = new TextField();
themesPathTextField = new TextField();
themesPathTextField = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxGap = new TextField();
actionGridPaneActionBoxGap = new TextField();
startOnBootToggleButton = new ToggleButton("Start on Boot");
startOnBootToggleButton = new ToggleButton("Start on Boot");
closeOnXToggleButton = new ToggleButton("Quit On window Close");
closeOnXToggleButton = new ToggleButton("Quit On window Close");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
checkForUpdatesButton.setOnAction(event->checkForUpdates());
getStyleClass().add("general_settings");
getStyleClass().add("general_settings");
prefWidthProperty().bind(widthProperty());
prefWidthProperty().bind(widthProperty());
setAlignment(Pos.CENTER);
setAlignment(Pos.CENTER);
setSpacing(5);
setSpacing(5);
getChildren().addAll(
getChildren().addAll(
getUIInputBox("Server Name", serverNameTextField),
getUIInputBox("Server Name", serverNameTextField),
getUIInputBox("Port", portTextField),
getUIInputBox("Port", portTextField),
getUIInputBox("Grid Pane - Box Size", actionGridPaneActionBoxSize),
getUIInputBox("Grid Pane - Box Size", actionGridPaneActionBoxSize),
getUIInputBox("Grid Pane - Box Gap", actionGridPaneActionBoxGap),
getUIInputBox("Grid Pane - Box Gap", actionGridPaneActionBoxGap),
getUIInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
getUIInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
getUIInputBoxWithDirectoryChooser("Themes Path", themesPathTextField)
getUIInputBoxWithDirectoryChooser("Themes Path", themesPathTextField)
);
);
serverNameTextField.setPrefWidth(200);
serverNameTextField.setPrefWidth(200);
HBox toggleButtons = new HBox(closeOnXToggleButton, startOnBootToggleButton);
HBox toggleButtons = new HBox(closeOnXToggleButton, startOnBootToggleButton);
toggleButtons.setSpacing(10.0);
toggleButtons.setSpacing(10.0);
VBox.setMargin(toggleButtons, new Insets(30, 0 , 0,0));
VBox.setMargin(toggleButtons, new Insets(30, 0 , 0,0));
toggleButtons.setAlignment(Pos.CENTER);
toggleButtons.setAlignment(Pos.CENTER);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event->save());
saveButton.setOnAction(event->save());
getChildren().addAll(toggleButtons, checkForUpdatesButton, saveButton);
getChildren().addAll(toggleButtons, checkForUpdatesButton, saveButton);
setPadding(new Insets(10));
setPadding(new Insets(10));
}
}
private void checkForUpdates()
{
new CheckForUpdates(checkForUpdatesButton, hostServices,
PlatformType.SERVER, ServerInfo.getInstance().getVersion());
}
private HBox getUIInputBoxWithDirectoryChooser(String labelText, TextField textField)
private HBox getUIInputBoxWithDirectoryChooser(String labelText, TextField textField)
{
{
HBox hBox = getUIInputBox(labelText, textField);
HBox hBox = getUIInputBox(labelText, textField);
hBox.setSpacing(5.0);
hBox.setSpacing(5.0);
TextField tf = (TextField) hBox.getChildren().get(2);
TextField tf = (TextField) hBox.getChildren().get(2);
tf.setPrefWidth(300);
tf.setPrefWidth(300);
tf.setDisable(true);
tf.setDisable(true);
Button button = new Button();
Button button = new Button();
FontIcon fontIcon = new FontIcon("far-folder");
FontIcon fontIcon = new FontIcon("far-folder");
button.setGraphic(fontIcon);
button.setGraphic(fontIcon);
button.setOnAction(event -> {
button.setOnAction(event -> {
DirectoryChooser directoryChooser = new DirectoryChooser();
DirectoryChooser directoryChooser = new DirectoryChooser();
try {
try {
File selectedDirectory = directoryChooser.showDialog(getScene().getWindow());
File selectedDirectory = directoryChooser.showDialog(getScene().getWindow());
textField.setText(selectedDirectory.getAbsolutePath());
textField.setText(selectedDirectory.getAbsolutePath());
}
}
catch (NullPointerException e)
catch (NullPointerException e)
{
{
logger.info("No folder selected");
logger.info("No folder selected");
}
}
});
});
hBox.getChildren().add(button);
hBox.getChildren().add(button);
return hBox;
return hBox;
}
}
private HBox getUIInputBox(String labelText, TextField textField)
private HBox getUIInputBox(String labelText, TextField textField)
{
{
textField.setPrefWidth(100);
textField.setPrefWidth(100);
Label label = new Label(labelText);
Label label = new Label(labelText);
Region region = new Region();
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HBox.setHgrow(region, Priority.ALWAYS);
return new HBox(label, region, textField);
return new HBox(label, region, textField);
}
}
public void loadDataFromConfig() throws SevereException {
public void loadDataFromConfig() throws SevereException {
Config config = Config.getInstance();
Config config = Config.getInstance();
Platform.runLater(()->
Platform.runLater(()->
{
{
serverNameTextField.setText(config.getServerName());
serverNameTextField.setText(config.getServerName());
portTextField.setText(config.getPort()+"");
portTextField.setText(config.getPort()+"");
pluginsPathTextField.setText(config.getPluginsPath());
pluginsPathTextField.setText(config.getPluginsPath());
themesPathTextField.setText(config.getThemesPath());
themesPathTextField.setText(config.getThemesPath());
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
closeOnXToggleButton.setSelected(config.getCloseOnX());
closeOnXToggleButton.setSelected(config.getCloseOnX());
startOnBootToggleButton.setSelected(config.getStartOnBoot());
startOnBootToggleButton.setSelected(config.getStartOnBoot());
});
});
}
}
public void save()
public void save()
{
{
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try {
try {
boolean toBeReloaded = false;
boolean toBeReloaded = false;
boolean dashToBeReRendered = false;
boolean dashToBeReRendered = false;
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(true);
saveButton.setDisable(true);
serverNameTextField.setDisable(true);
serverNameTextField.setDisable(true);
portTextField.setDisable(true);
portTextField.setDisable(true);
closeOnXToggleButton.setDisable(true);
closeOnXToggleButton.setDisable(true);
startOnBootToggleButton.setDisable(true);
startOnBootToggleButton.setDisable(true);
});
});
String serverNameStr = serverNameTextField.getText();
String serverNameStr = serverNameTextField.getText();
String serverPortStr = portTextField.getText();
String serverPortStr = portTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
boolean closeOnX = closeOnXToggleButton.isSelected();
boolean closeOnX = closeOnXToggleButton.isSelected();
boolean startOnBoot = startOnBootToggleButton.isSelected();
boolean startOnBoot = startOnBootToggleButton.isSelected();
Config config = Config.getInstance();
Config config = Config.getInstance();
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(serverNameStr.isBlank())
if(serverNameStr.isBlank())
{
{
errors.append("* Server Name cannot be blank.\n");
errors.append("* Server Name cannot be blank.\n");
}
}
else
else
{
{
if(!config.getServerName().equals(serverNameStr))
if(!config.getServerName().equals(serverNameStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
int serverPort=-1;
int serverPort=-1;
try {
try {
serverPort = Integer.parseInt(serverPortStr);
serverPort = Integer.parseInt(serverPortStr);
if (serverPort < 1024)
if (serverPort < 1024)
errors.append("* Server Port must be more than 1024");
errors.append("* Server Port must be more than 1024");
if(config.getPort()!=serverPort)
if(config.getPort()!=serverPort)
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* Server Port must be integer.\n");
errors.append("* Server Port must be integer.\n");
}
}
int actionSize=-1;
int actionSize=-1;
try {
try {
actionSize = Integer.parseInt(actionGridActionBoxSize);
actionSize = Integer.parseInt(actionGridActionBoxSize);
if(config.getActionGridActionSize() != actionSize)
if(config.getActionGridActionSize() != actionSize)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Size must be integer.\n");
errors.append("* action Size must be integer.\n");
}
}
int actionGap=-1;
int actionGap=-1;
try {
try {
actionGap = Integer.parseInt(actionGridActionBoxGap);
actionGap = Integer.parseInt(actionGridActionBoxGap);
if(config.getActionGridActionGap() != actionGap)
if(config.getActionGridActionGap() != actionGap)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Gap must be integer.\n");
errors.append("* action Gap must be integer.\n");
}
}
if(pluginsPathStr.isBlank())
if(pluginsPathStr.isBlank())
{
{
errors.append("* Plugins Path must not be blank.\n");
errors.append("* Plugins Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getPluginsPath().equals(pluginsPathStr))
if(!config.getPluginsPath().equals(pluginsPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(themesPathStr.isBlank())
if(themesPathStr.isBlank())
{
{
errors.append("* Themes Path must not be blank.\n");
errors.append("* Themes Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getThemesPath().equals(themesPathStr))
if(!config.getThemesPath().equals(themesPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
throw new MinorException("settings", "Please rectify the following errors and try again :\n"+errors.toString());
throw new MinorException("settings", "Please rectify the following errors and try again :\n"+errors.toString());
}
}
if(config.getStartOnBoot() != startOnBoot)
if(config.getStartOnBoot() != startOnBoot)
{
{
if(ServerInfo.getInstance().getRunnerFileName() == null)
if(ServerInfo.getInstance().getRunnerFileName() == 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(SoftwareType.SERVER, ServerInfo.getInstance().getPlatformType());
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.SERVER, ServerInfo.getInstance().getPlatformType());
if(startOnBoot)
if(startOnBoot)
{
{
startAtBoot.create(new File(ServerInfo.getInstance().getRunnerFileName()));
startAtBoot.create(new File(ServerInfo.getInstance().getRunnerFileName()));
}
}
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();
}
}
}
}
}
}
if(!closeOnX)
if(!closeOnX)
{
{
if(!SystemTray.isSupported())
if(!SystemTray.isSupported())
{
{
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
alert.show();
alert.show();
closeOnX = true;
closeOnX = true;
}
}
}
}
config.setServerName(serverNameStr);
config.setServerName(serverNameStr);
config.setServerPort(serverPort);
config.setServerPort(serverPort);
config.setActionGridGap(actionGap);
config.setActionGridGap(actionGap);
config.setActionGridSize(actionSize);
config.setActionGridSize(actionSize);
config.setPluginsPath(pluginsPathStr);
config.setPluginsPath(pluginsPathStr);
config.setThemesPath(themesPathStr);
config.setThemesPath(themesPathStr);
config.setCloseOnX(closeOnX);
config.setCloseOnX(closeOnX);
config.setStartupOnBoot(startOnBoot);
config.setStartupOnBoot(startOnBoot);
config.save();
config.save();
loadDataFromConfig();
loadDataFromConfig();
if(toBeReloaded)
if(toBeReloaded)
{
{
new StreamPiAlert("Restart","Restart to see changes", StreamPiAlertType.INFORMATION).show();
new StreamPiAlert("Restart","Restart to see changes", StreamPiAlertType.INFORMATION).show();
}
}
if(dashToBeReRendered)
if(dashToBeReRendered)
{
{
serverListener.clearTemp();
serverListener.clearTemp();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
finally {
finally {
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(false);
saveButton.setDisable(false);
serverNameTextField.setDisable(false);
serverNameTextField.setDisable(false);
portTextField.setDisable(false);
portTextField.setDisable(false);
closeOnXToggleButton.setDisable(false);
closeOnXToggleButton.setDisable(false);
startOnBootToggleButton.setDisable(false);
startOnBootToggleButton.setDisable(false);
});
});
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
public void checkForUpdates()
{
new Thread(new Task<Void>()
{
@Override
protected Void call() throws Exception {
try
{
Platform.runLater(()->checkForUpdatesButton.setDisable(true));
String jsonRaw = readUrl("https://stream-pi.com/API/get_latest.php?TYPE=SERVER");
JSONObject jsonObject = new JSONObject(jsonRaw);
String latestVersionRaw = jsonObject.getString("Version");
String releasePage = jsonObject.getString("Release Page");
Version latestVersion = new Version(latestVersionRaw);
Version currentVersion = ServerInfo.getInstance().getVersion();
if(latestVersion.isBiggerThan(currentVersion))
{
VBox vBox = new VBox();
Hyperlink urlLabel = new Hyperlink(releasePage);
urlLabel.setOnAction(event->hostServices.showDocument(releasePage));
Label label = new Label(
"New Version "+latestVersionRaw+" Available.\n" +
"Current Version "+currentVersion.getText()+".\n"+
"Changelog and install instructions are included in the release page.\n" +
"It is recommended to update to ensure maximum stability and least bugs.");
label.setWrapText(true);
vBox.setSpacing(5);
vBox.getChildren().addAll(
urlLabel,
label
);
new StreamPiAlert("New Update Available!", StreamPiAlertType.INFORMATION, vBox).show();;
}
else
{
new StreamPiAlert("Up to Date", "Server is upto date. ("+currentVersion.getText()+")", StreamPiAlertType.INFORMATION).show();;
}
}
catch (Exception e)
{
e.printStackTrace();
new StreamPiAlert("Uh Oh", "Update Check Failed. API Error/Network issue.", StreamPiAlertType.WARNING).show();;
}
finally
{
Platform.runLater(()->checkForUpdatesButton.setDisable(false));
}
return null;
}
}).start();;
}
private String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try {
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuffer buffer = new StringBuffer();
int read;
char[] chars = new char[1024];
while ((read = reader.read(chars)) != -1)
buffer.append(chars, 0, read);
return buffer.toString();
} finally {
if (reader != null)
reader.close();
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import javafx.application.HostServices;
import javafx.application.HostServices;
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.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class SettingsBase extends VBox {
public class SettingsBase extends VBox {
private TabPane tabPane;
private TabPane tabPane;
private GeneralSettings generalSettings;
private GeneralSettings generalSettings;
private PluginsSettings pluginsSettings;
private PluginsSettings pluginsSettings;
private ThemesSettings themesSettings;
private ThemesSettings themesSettings;
private ClientsSettings clientsSettings;
private ClientsSettings clientsSettings;
private Button closeButton;
private Button closeButton;
private HostServices hostServices;
private HostServices hostServices;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public SettingsBase(HostServices hostServices, ExceptionAndAlertHandler exceptionAndAlertHandler,
public SettingsBase(HostServices hostServices, ExceptionAndAlertHandler exceptionAndAlertHandler,
ServerListener serverListener)
ServerListener serverListener)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.hostServices = hostServices;
this.hostServices = hostServices;
tabPane = new TabPane();
tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
VBox.setVgrow(tabPane, Priority.ALWAYS);
VBox.setVgrow(tabPane, Priority.ALWAYS);
Tab generalSettingsTab = new Tab("General");
Tab generalSettingsTab = new Tab("General");
generalSettings = new GeneralSettings(exceptionAndAlertHandler, serverListener, hostServices);
generalSettings = new GeneralSettings(exceptionAndAlertHandler, serverListener, hostServices);
generalSettingsTab.setContent(generalSettings);
generalSettingsTab.setContent(generalSettings);
Tab pluginsSettingsTab = new Tab("Plugins");
Tab pluginsSettingsTab = new Tab("Plugins");
pluginsSettings = new PluginsSettings(exceptionAndAlertHandler, hostServices);
pluginsSettings = new PluginsSettings(exceptionAndAlertHandler, hostServices);
pluginsSettingsTab.setContent(pluginsSettings);
pluginsSettingsTab.setContent(pluginsSettings);
Tab themesSettingsTab = new Tab("Themes");
Tab themesSettingsTab = new Tab("Themes");
themesSettings = new ThemesSettings(hostServices);
themesSettings = new ThemesSettings(hostServices);
themesSettingsTab.setContent(themesSettings);
themesSettingsTab.setContent(themesSettings);
Tab clientsSettingsTab = new Tab("Clients");
Tab clientsSettingsTab = new Tab("Clients");
clientsSettings = new ClientsSettings(exceptionAndAlertHandler, serverListener);
clientsSettings = new ClientsSettings(exceptionAndAlertHandler, serverListener);
clientsSettingsTab.setContent(clientsSettings);
clientsSettingsTab.setContent(clientsSettings);
Tab aboutTab = new Tab("About");
Tab aboutTab = new Tab("About");
aboutTab.setContent(new About(hostServices));
aboutTab.setContent(new About(hostServices));
tabPane.getTabs().addAll(generalSettingsTab, pluginsSettingsTab, themesSettingsTab, clientsSettingsTab, aboutTab);
tabPane.getTabs().addAll(generalSettingsTab, pluginsSettingsTab, themesSettingsTab, clientsSettingsTab, aboutTab);
setAlignment(Pos.TOP_RIGHT);
setAlignment(Pos.TOP_RIGHT);
closeButton = new Button("Close");
closeButton = new Button("Close");
VBox.setMargin(closeButton, new Insets(10.0));
VBox.setMargin(closeButton, new Insets(10.0));
getChildren().addAll(tabPane, closeButton);
getChildren().addAll(tabPane, closeButton);
setCache(true);
setCache(true);
setCacheHint(CacheHint.QUALITY);
setCacheHint(CacheHint.SPEED);
}
}
public void setDefaultTabToGeneral()
public void setDefaultTabToGeneral()
{
{
tabPane.getSelectionModel().selectFirst();
tabPane.getSelectionModel().selectFirst();
}
}
public Button getCloseButton()
public Button getCloseButton()
{
{
return closeButton;
return closeButton;
}
}
public GeneralSettings getGeneralSettings()
public GeneralSettings getGeneralSettings()
{
{
return generalSettings;
return generalSettings;
}
}
public PluginsSettings getPluginsSettings()
public PluginsSettings getPluginsSettings()
{
{
return pluginsSettings;
return pluginsSettings;
}
}
public ThemesSettings getThemesSettings()
public ThemesSettings getThemesSettings()
{
{
return themesSettings;
return themesSettings;
}
}
public ClientsSettings getClientsSettings()
public ClientsSettings getClientsSettings()
{
{
return clientsSettings;
return clientsSettings;
}
}
}
}
module com.stream_pi.server {
module com.stream_pi.server {
uses com.stream_pi.action_api.action.Action;
uses com.stream_pi.action_api.action.Action;
uses com.stream_pi.action_api.normalaction.NormalAction;
uses com.stream_pi.action_api.normalaction.NormalAction;
requires com.stream_pi.action_api;
requires com.stream_pi.action_api;
requires com.stream_pi.util;
requires com.stream_pi.util;
requires com.stream_pi.theme_api;
requires com.stream_pi.theme_api;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.javafx;
requires java.xml;
requires java.xml;
requires org.json;
requires javafx.base;
requires javafx.base;
requires javafx.graphics;
requires javafx.graphics;
requires javafx.controls;
requires javafx.controls;
requires javafx.media;
requires javafx.media;
requires java.desktop;
requires java.desktop;
requires java.sql;
requires java.sql;
exports com.stream_pi.server;
exports com.stream_pi.server;
}
}