client
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>client</artifactId>
<artifactId>client</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<url>https://stream-pi.com/</url>
<url>https://stream-pi.com/</url>
<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>16-ea+7</javafx.version>
<javafx.version>16-ea+7</javafx.version>
<client.plugin.version>0.1.36</client.plugin.version>
<client.plugin.version>0.1.36</client.plugin.version>
<ikonli.version>11.5.0</ikonli.version>
<ikonli.version>11.5.0</ikonli.version>
<action.api.version>1.0.0-SNAPSHOT</action.api.version>
<action.api.version>1.0.0-SNAPSHOT</action.api.version>
<util.version>1.0.0-SNAPSHOT</util.version>
<util.version>1.0.0-SNAPSHOT</util.version>
<theme.api.version>1.0.0-SNAPSHOT</theme.api.version>
<theme.api.version>1.0.0-SNAPSHOT</theme.api.version>
<main.class.name>com.stream_pi.client.Main</main.class.name>
<main.class.name>com.stream_pi.client.Main</main.class.name>
<source.plugin.version>2.2.1</source.plugin.version>
<source.plugin.version>2.2.1</source.plugin.version>
<javadoc.plugin.version>3.1.0</javadoc.plugin.version>
<javadoc.plugin.version>3.1.0</javadoc.plugin.version>
<gpg.plugin.version>1.6</gpg.plugin.version>
<gpg.plugin.version>1.6</gpg.plugin.version>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
<version>${javafx.version}</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>${ikonli.version}</version>
<version>${ikonli.version}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<artifactId>ikonli-javafx</artifactId>
<version>${ikonli.version}</version>
<version>${ikonli.version}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>action-api</artifactId>
<artifactId>action-api</artifactId>
<version>${action.api.version}</version>
<version>${action.api.version}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>theme-api</artifactId>
<artifactId>theme-api</artifactId>
<version>${theme.api.version}</version>
<version>${theme.api.version}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream-pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>${util.version}</version>
<version>${util.version}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<groupId>com.gluonhq.attach</groupId>
<artifactId>lifecycle</artifactId>
<artifactId>lifecycle</artifactId>
<version>4.0.10</version>
<version>4.0.10</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<groupId>com.gluonhq.attach</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>4.0.10</version>
<version>4.0.10</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<groupId>com.gluonhq.attach</groupId>
<artifactId>storage</artifactId>
<artifactId>storage</artifactId>
<version>4.0.10</version>
<version>4.0.10</version>
</dependency>
</dependency>
<dependency>
<groupId>com.gluonhq.attach</groupId>
<artifactId>browser</artifactId>
<version>4.0.10</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>
</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>
<stripDebug>true</stripDebug>
<stripDebug>true</stripDebug>
<compress>2</compress>
<compress>2</compress>
<noHeaderFiles>true</noHeaderFiles>
<noHeaderFiles>true</noHeaderFiles>
<noManPages>true</noManPages>
<noManPages>true</noManPages>
<mainClass>${main.class.name}</mainClass>
<mainClass>${main.class.name}</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>
<target>android</target>
<target>${clientTarget}</target>
<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>{additionalArgs}</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>
<attachList>
<attachList>
<list>lifecycle</list>
<list>lifecycle</list>
<list>storage</list>
<list>storage</list>
<list>browser</list>
</attachList>
</attachList>
<reflectionList>
<reflectionList>
<list>java.util.logging.FileHandler</list>
<list>java.util.logging.FileHandler</list>
</reflectionList>
</reflectionList>
<mainClass>${main.class.name}</mainClass>
<mainClass>${main.class.name}</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>
<!--profiles>
<profile>
<id>android</id>
<properties>
<clientTarget>android</clientTarget>
<additionalArgs>-Dsvm.targetName=android</additionalArgs>
</properties>
</profile>
<profile>
<id>rpi</id>
<properties>
<clientTarget>linux-aarch64</clientTarget>
<additionalArgs>-Dsvm.targetName=linux_raspberrypi</additionalArgs>
</properties>
</profile>
</profiles-->
<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>
<profiles>
<profiles>
<profile>
<id>android</id>
<properties>
<clientTarget>android</clientTarget>
<additionalArgs>-Dsvm.targetName=android</additionalArgs>
</properties>
</profile>
<profile>
<id>ios</id>
<properties>
<clientTarget>ios</clientTarget>
<additionalArgs>-Dsvm.targetName=ios</additionalArgs>
</properties>
</profile>
<profile>
<profile>
<id>release</id>
<id>release</id>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<version>2.2.1</version>
<executions>
<executions>
<execution>
<execution>
<id>attach-sources</id>
<id>attach-sources</id>
<goals>
<goals>
<goal>jar-no-fork</goal>
<goal>jar-no-fork</goal>
</goals>
</goals>
</execution>
</execution>
</executions>
</executions>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${javadoc.plugin.version}</version>
<version>${javadoc.plugin.version}</version>
<executions>
<executions>
<execution>
<execution>
<id>attach-javadocs</id>
<id>attach-javadocs</id>
<goals>
<goals>
<goal>jar</goal>
<goal>jar</goal>
</goals>
</goals>
</execution>
</execution>
</executions>
</executions>
<configuration>
<configuration>
<source>8</source>
<source>8</source>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<artifactId>maven-gpg-plugin</artifactId>
<version>${gpg.plugin.version}</version>
<version>${gpg.plugin.version}</version>
<executions>
<executions>
<execution>
<execution>
<id>sign-artifacts</id>
<id>sign-artifacts</id>
<phase>verify</phase>
<phase>verify</phase>
<goals>
<goals>
<goal>sign</goal>
<goal>sign</goal>
</goals>
</goals>
<configuration>
<configuration>
<gpgArguments>
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
<arg>loopback</arg>
</gpgArguments>
</gpgArguments>
</configuration>
</configuration>
</execution>
</execution>
</executions>
</executions>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
</profile>
</profile>
</profiles>
</profiles>
<organization>
<organization>
<name>Stream Pi</name>
<name>Stream Pi</name>
<url>https://www.stream-pi.com</url>
<url>https://www.stream-pi.com</url>
</organization>
</organization>
<issueManagement>
<issueManagement>
<system>GitHub</system>
<system>GitHub</system>
<url>https://github.com/Stream-Pi/client/issues</url>
<url>https://github.com/Stream-Pi/client/issues</url>
</issueManagement>
</issueManagement>
<licenses>
<licenses>
<license>
<license>
<name>GPL-3.0 License</name>
<name>GPL-3.0 License</name>
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
<url>https://www.gnu.org/licenses/gpl-3.0.en.html</url>
<distribution>repo</distribution>
<distribution>repo</distribution>
</license>
</license>
</licenses>
</licenses>
<developers>
<developers>
<developer>
<developer>
<name>Debayan Sutradhar</name>
<name>Debayan Sutradhar</name>
<email>debayansutradhar3@gmail.com</email>
<email>debayansutradhar3@gmail.com</email>
<organization>Stream-Pi</organization>
<organization>Stream-Pi</organization>
<organizationUrl>https://www.stream-pi.com</organizationUrl>
<organizationUrl>https://www.stream-pi.com</organizationUrl>
</developer>
</developer>
<developer>
<developer>
<name>Abhinay Agarwal</name>
<name>Abhinay Agarwal</name>
<email>abhinay_agarwal@live.com</email>
<email>abhinay_agarwal@live.com</email>
<organization>Stream-Pi</organization>
<organization>Stream-Pi</organization>
<organizationUrl>https://www.stream-pi.com</organizationUrl>
<organizationUrl>https://www.stream-pi.com</organizationUrl>
</developer>
</developer>
</developers>
</developers>
<scm>
<scm>
<url>https://github.com/stream-pi/client</url>
<url>https://github.com/stream-pi/client</url>
<connection>scm:git:git://github.com/stream-pi/client.git</connection>
<connection>scm:git:git://github.com/stream-pi/client.git</connection>
<developerConnection>scm:git:ssh://git@github.com:stream-pi/client.git</developerConnection>
<developerConnection>scm:git:ssh://git@github.com:stream-pi/client.git</developerConnection>
</scm>
</scm>
<distributionManagement>
<distributionManagement>
<snapshotRepository>
<snapshotRepository>
<id>ossrh</id>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</snapshotRepository>
<repository>
<repository>
<id>ossrh</id>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</repository>
</distributionManagement>
</distributionManagement>
</project>
</project>
package com.stream_pi.client.connection;
package com.stream_pi.client.connection;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
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.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.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.comms.Message;
import com.stream_pi.util.comms.Message;
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.version.Version;
import com.stream_pi.util.version.Version;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import java.io.*;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class Client extends Thread{
public class Client extends Thread{
private Socket socket;
private Socket socket;
private ObjectOutputStream oos;
private ObjectOutputStream oos;
private ObjectInputStream ois;
private ObjectInputStream ois;
private final AtomicBoolean stop = new AtomicBoolean(false);
private final AtomicBoolean stop = new AtomicBoolean(false);
private final ClientListener clientListener;
private final ClientListener clientListener;
private final ExceptionAndAlertHandler exceptionAndAlertHandler;
private final ExceptionAndAlertHandler exceptionAndAlertHandler;
private final ClientInfo clientInfo;
private final ClientInfo clientInfo;
private final String serverIP;
private final String serverIP;
private final int serverPort;
private final int serverPort;
private final Logger logger;
private final Logger logger;
public Client(String serverIP, int serverPort, ClientListener clientListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
public Client(String serverIP, int serverPort, ClientListener clientListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
this.serverIP = serverIP;
this.serverIP = serverIP;
this.serverPort = serverPort;
this.serverPort = serverPort;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.clientInfo = ClientInfo.getInstance();
this.clientInfo = ClientInfo.getInstance();
this.clientListener = clientListener;
this.clientListener = clientListener;
logger = Logger.getLogger(Client.class.getName());
logger = Logger.getLogger(Client.class.getName());
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
try
try
{
{
logger.info("Trying to connect to server at "+serverIP+":"+serverPort);
logger.info("Trying to connect to server at "+serverIP+":"+serverPort);
socket = new Socket();
socket = new Socket();
socket.connect(new InetSocketAddress(serverIP, serverPort), 5000);
socket.connect(new InetSocketAddress(serverIP, serverPort), 5000);
clientListener.setConnected(true);
clientListener.setConnected(true);
clientListener.updateSettingsConnectDisconnectButton();
clientListener.updateSettingsConnectDisconnectButton();
logger.info("Connected to "+socket.getRemoteSocketAddress()+" !");
logger.info("Connected to "+socket.getRemoteSocketAddress()+" !");
}
}
catch (IOException e)
catch (IOException e)
{
{
e.printStackTrace();
e.printStackTrace();
clientListener.setConnected(false);
clientListener.setConnected(false);
clientListener.updateSettingsConnectDisconnectButton();
clientListener.updateSettingsConnectDisconnectButton();
throw new MinorException("Connection Error", "Unable to connect to server. Please check settings and connection and try again.");
throw new MinorException("Connection Error", "Unable to connect to server. Please check settings and connection and try again.");
}
}
try
try
{
{
oos = new ObjectOutputStream(socket.getOutputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());
ois = new ObjectInputStream(socket.getInputStream());
}
}
catch (IOException e)
catch (IOException e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
e.printStackTrace();
e.printStackTrace();
throw new MinorException("Unable to set up io Streams to server. Check connection and try again.");
throw new MinorException("Unable to set up io Streams to server. Check connection and try again.");
}
}
start();
start();
} catch (MinorException e)
} catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
public synchronized void exit()
public synchronized void exit()
{
{
if(stop.get())
if(stop.get())
return;
return;
logger.info("Stopping ...");
logger.info("Stopping ...");
try
try
{
{
if(socket!=null)
if(socket!=null)
{
{
disconnect();
disconnect();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public synchronized void sendMessage(Message message) throws SevereException
public synchronized void sendMessage(Message message) throws SevereException
{
{
try
try
{
{
oos.writeObject(message);
oos.writeObject(message);
oos.flush();
oos.flush();
}
}
catch (IOException e)
catch (IOException e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException("Unable to write to io Stream!");
throw new SevereException("Unable to write to io Stream!");
}
}
}
}
@Override
@Override
public void run() {
public void run() {
try
try
{
{
while(!stop.get())
while(!stop.get())
{
{
try
try
{
{
Message message = (Message) ois.readObject();
Message message = (Message) ois.readObject();
String header = message.getHeader();
String header = message.getHeader();
logger.info("Message Received. Heading : "+header);
logger.info("Message Received. Heading : "+header);
switch (header)
switch (header)
{
{
case "action_icon" : onActionIconReceived(message);
case "action_icon" : onActionIconReceived(message);
break;
break;
case "disconnect" : serverDisconnected(message);
case "disconnect" : serverDisconnected(message);
break;
break;
case "get_client_details" : sendClientDetails();
case "get_client_details" : sendClientDetails();
break;
break;
case "get_profiles" : sendProfileNamesToServer();
case "get_profiles" : sendProfileNamesToServer();
break;
break;
case "get_profile_details": sendProfileDetailsToServer(message);
case "get_profile_details": sendProfileDetailsToServer(message);
break;
break;
case "save_action_details": saveActionDetails(message);
case "save_action_details": saveActionDetails(message);
break;
break;
case "delete_action": deleteAction(message);
case "delete_action": deleteAction(message);
break;
break;
case "get_themes": sendThemesToServer();
case "get_themes": sendThemesToServer();
break;
break;
case "save_client_details": saveClientDetails(message);
case "save_client_details": saveClientDetails(message);
break;
break;
case "save_client_profile": saveProfileDetails(message);
case "save_client_profile": saveProfileDetails(message);
break;
break;
case "delete_profile": deleteProfile(message);
case "delete_profile": deleteProfile(message);
break;
break;
case "action_failed": actionFailed(message);
case "action_failed": actionFailed(message);
break;
break;
default: logger.warning("Command '"+header+"' does not match records. Make sure client and server versions are equal.");
default: logger.warning("Command '"+header+"' does not match records. Make sure client and server versions are equal.");
}
}
}
}
catch (IOException | ClassNotFoundException e)
catch (IOException | ClassNotFoundException e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
e.printStackTrace();
e.printStackTrace();
clientListener.setConnected(false);
clientListener.setConnected(false);
clientListener.updateSettingsConnectDisconnectButton();
clientListener.updateSettingsConnectDisconnectButton();
if(!stop.get())
if(!stop.get())
{
{
//isDisconnect.set(true); //Prevent running disconnect
//isDisconnect.set(true); //Prevent running disconnect
throw new MinorException("Accidentally disconnected from Server! (Failed at readUTF)");
throw new MinorException("Accidentally disconnected from Server! (Failed at readUTF)");
}
}
exit();
exit();
return;
return;
}
}
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
private void onActionIconReceived(Message message)
private void onActionIconReceived(Message message)
{
{
String profileID = message.getStringArrValue()[0];
String profileID = message.getStringArrValue()[0];
String actionID = message.getStringArrValue()[1];
String actionID = message.getStringArrValue()[1];
clientListener.getClientProfiles().getProfileFromID(profileID).saveActionIcon(
clientListener.getClientProfiles().getProfileFromID(profileID).saveActionIcon(
actionID,
actionID,
message.getByteArrValue()
message.getByteArrValue()
);
);
Action a = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID);
Action a = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID);
clientListener.renderAction(profileID, a);
clientListener.renderAction(profileID, a);
}
}
//commands
//commands
public synchronized void sendIcon(String profileID, String actionID, byte[] icon) throws SevereException
public synchronized void sendIcon(String profileID, String actionID, byte[] icon) throws SevereException
{
{
try
try
{
{
Thread.sleep(50);
Thread.sleep(50);
}
}
catch (InterruptedException e)
catch (InterruptedException e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
Message message = new Message("action_icon");
Message message = new Message("action_icon");
message.setStringArrValue(profileID, actionID);
message.setStringArrValue(profileID, actionID);
message.setByteArrValue(icon);
message.setByteArrValue(icon);
sendMessage(message);
sendMessage(message);
}
}
public void disconnect() throws SevereException
public void disconnect() throws SevereException
{
{
disconnect("");
disconnect("");
}
}
public void disconnect(String message) throws SevereException
public void disconnect(String message) throws SevereException
{
{
if(stop.get())
if(stop.get())
return;
return;
stop.set(true);
stop.set(true);
logger.info("Sending server disconnect message ...");
logger.info("Sending server disconnect message ...");
Message m = new Message("disconnect");
Message m = new Message("disconnect");
m.setStringValue(message);
m.setStringValue(message);
sendMessage(m);
sendMessage(m);
try
try
{
{
if(!socket.isClosed())
if(!socket.isClosed())
socket.close();
socket.close();
clientListener.setConnected(false);
clientListener.setConnected(false);
clientListener.updateSettingsConnectDisconnectButton();
clientListener.updateSettingsConnectDisconnectButton();
}
}
catch (IOException e)
catch (IOException e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException("Unable to close socket");
throw new SevereException("Unable to close socket");
}
}
}
}
public void sendThemesToServer() throws SevereException
public void sendThemesToServer() throws SevereException
{
{
Message message = new Message("themes");
Message message = new Message("themes");
String[] arr = new String[clientListener.getThemes().getThemeList().size()*4];
String[] arr = new String[clientListener.getThemes().getThemeList().size()*4];
int x = 0;
int x = 0;
for(int i = 0;i<clientListener.getThemes().getThemeList().size();i++)
for(int i = 0;i<clientListener.getThemes().getThemeList().size();i++)
{
{
Theme theme = clientListener.getThemes().getThemeList().get(i);
Theme theme = clientListener.getThemes().getThemeList().get(i);
arr[x] = theme.getFullName();
arr[x] = theme.getFullName();
arr[x+1] = theme.getShortName();
arr[x+1] = theme.getShortName();
arr[x+2] = theme.getAuthor();
arr[x+2] = theme.getAuthor();
arr[x+3] = theme.getVersion().getText();
arr[x+3] = theme.getVersion().getText();
x+=4;
x+=4;
}
}
message.setStringArrValue(arr);
message.setStringArrValue(arr);
sendMessage(message);
sendMessage(message);
}
}
public void sendActionIcon(String clientProfileID, String actionID) throws SevereException
public void sendActionIcon(String clientProfileID, String actionID) throws SevereException
{
{
System.out.println("sending action icon "+clientProfileID+", "+actionID);
System.out.println("sending action icon "+clientProfileID+", "+actionID);
sendIcon(clientProfileID, actionID, clientListener.getClientProfiles().getProfileFromID(clientProfileID).getActionFromID(actionID).getIconAsByteArray());
sendIcon(clientProfileID, actionID, clientListener.getClientProfiles().getProfileFromID(clientProfileID).getActionFromID(actionID).getIconAsByteArray());
}
}
public void serverDisconnected(Message message)
public void serverDisconnected(Message message)
{
{
stop.set(true);
stop.set(true);
String txt = "Disconnected!";
String txt = "Disconnected!";
String m = message.getStringValue();
String m = message.getStringValue();
if(!m.isBlank())
if(!m.isBlank())
txt = "Message : "+m;
txt = "Message : "+m;
exceptionAndAlertHandler.onAlert("Disconnected from Server", txt, StreamPiAlertType.WARNING);
exceptionAndAlertHandler.onAlert("Disconnected from Server", txt, StreamPiAlertType.WARNING);
if(!socket.isClosed()) {
if(!socket.isClosed()) {
try {
try {
socket.close();
socket.close();
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
clientListener.setConnected(false);
clientListener.setConnected(false);
clientListener.updateSettingsConnectDisconnectButton();
clientListener.updateSettingsConnectDisconnectButton();
}
}
public void sendClientDetails() throws SevereException
public void sendClientDetails() throws SevereException
{
{
String clientVersion = clientInfo.getVersion().getText();
String clientVersion = clientInfo.getVersion().getText();
String releaseStatus = clientInfo.getReleaseStatus().toString();
String releaseStatus = clientInfo.getReleaseStatus().toString();
String clientCommStandard = clientInfo.getCommStandardVersion().getText();
String clientCommStandard = clientInfo.getCommStandardVersion().getText();
String clientMinThemeStandard = clientInfo.getMinThemeSupportVersion().getText();
String clientMinThemeStandard = clientInfo.getMinThemeSupportVersion().getText();
String clientNickname = Config.getInstance().getClientNickName();
String clientNickname = Config.getInstance().getClientNickName();
String screenWidth = clientListener.getStageWidth()+"";
String screenWidth = clientListener.getStageWidth()+"";
String screenHeight = clientListener.getStageHeight()+"";
String screenHeight = clientListener.getStageHeight()+"";
String OS = clientInfo.getPlatformType()+"";
String OS = clientInfo.getPlatform()+"";
String defaultProfileID = Config.getInstance().getStartupProfileID();
String defaultProfileID = Config.getInstance().getStartupProfileID();
Message toBeSent = new Message("client_details");
Message toBeSent = new Message("client_details");
toBeSent.setStringArrValue(
toBeSent.setStringArrValue(
clientVersion,
clientVersion,
releaseStatus,
releaseStatus,
clientCommStandard,
clientCommStandard,
clientMinThemeStandard,
clientMinThemeStandard,
clientNickname,
clientNickname,
screenWidth,
screenWidth,
screenHeight,
screenHeight,
OS,
OS,
defaultProfileID,
defaultProfileID,
clientListener.getDefaultThemeFullName()
clientListener.getDefaultThemeFullName()
);
);
sendMessage(toBeSent);
sendMessage(toBeSent);
}
}
public void sendProfileNamesToServer() throws SevereException
public void sendProfileNamesToServer() throws SevereException
{
{
Message message = new Message("profiles");
Message message = new Message("profiles");
String[] arr = new String[clientListener.getClientProfiles().getClientProfiles().size()];
String[] arr = new String[clientListener.getClientProfiles().getClientProfiles().size()];
for(int i = 0;i<arr.length;i++)
for(int i = 0;i<arr.length;i++)
{
{
ClientProfile clientProfile = clientListener.getClientProfiles().getClientProfiles().get(i);
ClientProfile clientProfile = clientListener.getClientProfiles().getClientProfiles().get(i);
arr[i] = clientProfile.getID();
arr[i] = clientProfile.getID();
}
}
message.setStringArrValue(arr);
message.setStringArrValue(arr);
sendMessage(message);
sendMessage(message);
}
}
public void sendProfileDetailsToServer(Message message) throws SevereException
public void sendProfileDetailsToServer(Message message) throws SevereException
{
{
String ID = message.getStringValue();
String ID = message.getStringValue();
Message tbs1 = new Message("profile_details");
Message tbs1 = new Message("profile_details");
ClientProfile clientProfile = clientListener.getClientProfiles().getProfileFromID(ID);
ClientProfile clientProfile = clientListener.getClientProfiles().getProfileFromID(ID);
String[] arr = new String[]{
String[] arr = new String[]{
ID,
ID,
clientProfile.getName(),
clientProfile.getName(),
clientProfile.getRows()+"",
clientProfile.getRows()+"",
clientProfile.getCols()+"",
clientProfile.getCols()+"",
clientProfile.getActionSize()+"",
clientProfile.getActionSize()+"",
clientProfile.getActionGap()+""
clientProfile.getActionGap()+""
};
};
tbs1.setStringArrValue(arr);
tbs1.setStringArrValue(arr);
sendMessage(tbs1);
sendMessage(tbs1);
for(Action action : clientProfile.getActions())
for(Action action : clientProfile.getActions())
{
{
sendActionDetails(clientProfile.getID(), action);
sendActionDetails(clientProfile.getID(), action);
}
}
for(Action action : clientProfile.getActions())
for(Action action : clientProfile.getActions())
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
sendActionIcon(clientProfile.getID(), action.getID());
sendActionIcon(clientProfile.getID(), action.getID());
}
}
}
}
}
}
public void sendActionDetails(String profileID, Action action) throws SevereException {
public void sendActionDetails(String profileID, Action action) throws SevereException {
if(action == null)
if(action == null)
{
{
logger.info("NO SUCH ACTION");
logger.info("NO SUCH ACTION");
return;
return;
}
}
ArrayList<String> a = new ArrayList<>();
ArrayList<String> a = new ArrayList<>();
a.add(profileID);
a.add(profileID);
a.add(action.getID());
a.add(action.getID());
a.add(action.getActionType()+"");
a.add(action.getActionType()+"");
if(action.getActionType() == ActionType.NORMAL) {
if(action.getActionType() == ActionType.NORMAL) {
a.add(action.getVersion().getText());
a.add(action.getVersion().getText());
}
}
else
else
{
{
a.add("no");
a.add("no");
}
}
if(action.getActionType() ==ActionType.NORMAL)
if(action.getActionType() ==ActionType.NORMAL)
{
{
a.add(action.getModuleName());
a.add(action.getModuleName());
}
}
else
else
{
{
a.add("nut");
a.add("nut");
}
}
//display
//display
a.add(action.getBgColourHex());
a.add(action.getBgColourHex());
//icon
//icon
a.add(action.isHasIcon()+"");
a.add(action.isHasIcon()+"");
a.add(action.isShowIcon()+"");
a.add(action.isShowIcon()+"");
//text
//text
a.add(action.isShowDisplayText()+"");
a.add(action.isShowDisplayText()+"");
a.add(action.getDisplayTextFontColourHex());
a.add(action.getDisplayTextFontColourHex());
a.add(action.getDisplayText());
a.add(action.getDisplayText());
a.add(action.getDisplayTextAlignment()+"");
a.add(action.getDisplayTextAlignment()+"");
//location
//location
if(action.getLocation() == null)
if(action.getLocation() == null)
{
{
a.add("-1");
a.add("-1");
a.add("-1");
a.add("-1");
}
}
else
else
{
{
a.add(action.getLocation().getRow()+"");
a.add(action.getLocation().getRow()+"");
a.add(action.getLocation().getCol()+"");
a.add(action.getLocation().getCol()+"");
}
}
a.add(action.getParent());
a.add(action.getParent());
//client properties
//client properties
ClientProperties clientProperties = action.getClientProperties();
ClientProperties clientProperties = action.getClientProperties();
a.add(clientProperties.getSize()+"");
a.add(clientProperties.getSize()+"");
for(Property property : clientProperties.get())
for(Property property : clientProperties.get())
{
{
a.add(property.getName());
a.add(property.getName());
a.add(property.getRawValue());
a.add(property.getRawValue());
}
}
Message message = new Message("action_details");
Message message = new Message("action_details");
String[] x = new String[a.size()];
String[] x = new String[a.size()];
x = a.toArray(x);
x = a.toArray(x);
message.setStringArrValue(x);
message.setStringArrValue(x);
sendMessage(message);
sendMessage(message);
}
}
public void saveActionDetails(Message message)
public void saveActionDetails(Message message)
{
{
String[] r = message.getStringArrValue();
String[] r = message.getStringArrValue();
String profileID = r[0];
String profileID = r[0];
String actionID = r[1];
String actionID = r[1];
ActionType actionType = ActionType.valueOf(r[2]);
ActionType actionType = ActionType.valueOf(r[2]);
//3 - Version
//3 - Version
//4 - ModuleName
//4 - ModuleName
//display
//display
String bgColorHex = r[5];
String bgColorHex = r[5];
//icon
//icon
boolean isHasIcon = r[6].equals("true");
boolean isHasIcon = r[6].equals("true");
boolean isShowIcon = r[7].equals("true");
boolean isShowIcon = r[7].equals("true");
//text
//text
boolean isShowDisplayText = r[8].equals("true");
boolean isShowDisplayText = r[8].equals("true");
String displayFontColor = r[9];
String displayFontColor = r[9];
String displayText = r[10];
String displayText = r[10];
DisplayTextAlignment displayTextAlignment = DisplayTextAlignment.valueOf(r[11]);
DisplayTextAlignment displayTextAlignment = DisplayTextAlignment.valueOf(r[11]);
//location
//location
String row = r[12];
String row = r[12];
String col = r[13];
String col = r[13];
Location location = new Location(Integer.parseInt(row), Integer.parseInt(col));
Location location = new Location(Integer.parseInt(row), Integer.parseInt(col));
Action action = new Action(actionID, actionType);
Action action = new Action(actionID, actionType);
if(actionType == ActionType.NORMAL)
if(actionType == ActionType.NORMAL)
{
{
try
try
{
{
action.setVersion(new Version(r[3]));
action.setVersion(new Version(r[3]));
action.setModuleName(r[4]);
action.setModuleName(r[4]);
}
}
catch (Exception e)
catch (Exception e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
e.printStackTrace();
e.printStackTrace();
}
}
}
}
action.setBgColourHex(bgColorHex);
action.setBgColourHex(bgColorHex);
action.setShowIcon(isShowIcon);
action.setShowIcon(isShowIcon);
action.setHasIcon(isHasIcon);
action.setHasIcon(isHasIcon);
System.out.println("IS HAS ICON : "+isHasIcon+", IS SHOW ICON :"+isShowIcon);
System.out.println("IS HAS ICON : "+isHasIcon+", IS SHOW ICON :"+isShowIcon);
action.setShowDisplayText(isShowDisplayText);
action.setShowDisplayText(isShowDisplayText);
action.setDisplayTextFontColourHex(displayFontColor);
action.setDisplayTextFontColourHex(displayFontColor);
action.setDisplayText(displayText);
action.setDisplayText(displayText);
action.setDisplayTextAlignment(displayTextAlignment);
action.setDisplayTextAlignment(displayTextAlignment);
action.setLocation(location);
action.setLocation(location);
String parent = r[14];
String parent = r[14];
action.setParent(parent);
action.setParent(parent);
//client properties
//client properties
int clientPropertiesSize = Integer.parseInt(r[15]);
int clientPropertiesSize = Integer.parseInt(r[15]);
ClientProperties clientProperties = new ClientProperties();
ClientProperties clientProperties = new ClientProperties();
if(actionType == ActionType.FOLDER)
if(actionType == ActionType.FOLDER)
clientProperties.setDuplicatePropertyAllowed(true);
clientProperties.setDuplicatePropertyAllowed(true);
for(int i = 16;i<((clientPropertiesSize*2) + 16); i+=2)
for(int i = 16;i<((clientPropertiesSize*2) + 16); i+=2)
{
{
Property property = new Property(r[i], Type.STRING);
Property property = new Property(r[i], Type.STRING);
property.setRawValue(r[i+1]);
property.setRawValue(r[i+1]);
clientProperties.addProperty(property);
clientProperties.addProperty(property);
}
}
action.setClientProperties(clientProperties);
action.setClientProperties(clientProperties);
try
try
{
{
Action old = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(action.getID());
Action old = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(action.getID());
if(old != null)
if(old != null)
{
{
if(isHasIcon)
if(isHasIcon)
action.setIcon(clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(action.getID()).getIconAsByteArray());
action.setIcon(clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(action.getID()).getIconAsByteArray());
else
else
{
{
if(old.isHasIcon())
if(old.isHasIcon())
{
{
new File(Config.getInstance().getIconsPath()+"/"+actionID).delete();
new File(Config.getInstance().getIconsPath()+"/"+actionID).delete();
}
}
}
}
}
}
clientListener.getClientProfiles().getProfileFromID(profileID).addAction(action);
clientListener.getClientProfiles().getProfileFromID(profileID).addAction(action);
clientListener.getClientProfiles().getProfileFromID(profileID).saveAction(action);
clientListener.getClientProfiles().getProfileFromID(profileID).saveAction(action);
clientListener.renderAction(profileID, action);
clientListener.renderAction(profileID, action);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
}
}
public void deleteAction(Message message)
public void deleteAction(Message message)
{
{
try
try
{
{
String[] arr = message.getStringArrValue();
String[] arr = message.getStringArrValue();
String profileID = arr[0];
String profileID = arr[0];
String actionID = arr[1];
String actionID = arr[1];
Action acc = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID);
Action acc = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID);
if(acc.getActionType() == ActionType.FOLDER)
if(acc.getActionType() == ActionType.FOLDER)
{
{
ArrayList<String> idsToBeRemoved = new ArrayList<>();
ArrayList<String> idsToBeRemoved = new ArrayList<>();
ArrayList<String> folders = new ArrayList<>();
ArrayList<String> folders = new ArrayList<>();
String folderToBeDeletedID = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID).getID();
String folderToBeDeletedID = clientListener.getClientProfiles().getProfileFromID(profileID).getActionFromID(actionID).getID();
folders.add(folderToBeDeletedID);
folders.add(folderToBeDeletedID);
boolean startOver = true;
boolean startOver = true;
while(startOver)
while(startOver)
{
{
startOver = false;
startOver = false;
for(Action action : clientListener.getClientProfiles().getProfileFromID(profileID).getActions())
for(Action action : clientListener.getClientProfiles().getProfileFromID(profileID).getActions())
{
{
if(folders.contains(action.getParent()))
if(folders.contains(action.getParent()))
{
{
if(!idsToBeRemoved.contains(action.getID()))
if(!idsToBeRemoved.contains(action.getID()))
{
{
idsToBeRemoved.add(action.getID());
idsToBeRemoved.add(action.getID());
if(action.getActionType() == ActionType.FOLDER)
if(action.getActionType() == ActionType.FOLDER)
{
{
folders.add(action.getID());
folders.add(action.getID());
startOver = true;
startOver = true;
}
}
}
}
}
}
}
}
}
}
for(String ids : idsToBeRemoved)
for(String ids : idsToBeRemoved)
{
{
clientListener.getClientProfiles().getProfileFromID(profileID).removeAction(ids);
clientListener.getClientProfiles().getProfileFromID(profileID).removeAction(ids);
}
}
}
}
else if (acc.getActionType() == ActionType.COMBINE)
else if (acc.getActionType() == ActionType.COMBINE)
{
{
for(Property property : acc.getClientProperties().get())
for(Property property : acc.getClientProperties().get())
{
{
clientListener.getClientProfiles().getProfileFromID(profileID).removeAction(property.getRawValue());
clientListener.getClientProfiles().getProfileFromID(profileID).removeAction(property.getRawValue());
}
}
}
}
clientListener.getClientProfiles().getProfileFromID(profileID).removeAction(acc.getID());
clientListener.getClientProfiles().getProfileFromID(profileID).removeAction(acc.getID());
clientListener.getClientProfiles().getProfileFromID(profileID).saveActions();
clientListener.getClientProfiles().getProfileFromID(profileID).saveActions();
if(acc.getLocation().getCol()!=-1)
if(acc.getLocation().getCol()!=-1)
{
{
Platform.runLater(()-> {
Platform.runLater(()-> {
if (clientListener.getCurrentProfile().getID().equals(profileID)
if (clientListener.getCurrentProfile().getID().equals(profileID)
&& clientListener.getCurrentParent().equals(acc.getParent()))
&& clientListener.getCurrentParent().equals(acc.getParent()))
{
{
clientListener.clearActionBox(
clientListener.clearActionBox(
acc.getLocation().getCol(),
acc.getLocation().getCol(),
acc.getLocation().getRow()
acc.getLocation().getRow()
);
);
}
}
});
});
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
}
}
public void saveClientDetails(Message message)
public void saveClientDetails(Message message)
{
{
try
try
{
{
String[] sep = message.getStringArrValue();
String[] sep = message.getStringArrValue();
Config.getInstance().setNickName(sep[0]);
Config.getInstance().setNickName(sep[0]);
String oldWidth = Config.getInstance().getStartupWindowWidth()+"";
String oldWidth = Config.getInstance().getStartupWindowWidth()+"";
String oldHeight = Config.getInstance().getStartupWindowHeight()+"";
String oldHeight = Config.getInstance().getStartupWindowHeight()+"";
Config.getInstance().setStartupWindowSize(
Config.getInstance().setStartupWindowSize(
Double.parseDouble(sep[1]),
Double.parseDouble(sep[1]),
Double.parseDouble(sep[2])
Double.parseDouble(sep[2])
);
);
Config.getInstance().setStartupProfileID(sep[3]);
Config.getInstance().setStartupProfileID(sep[3]);
String oldThemeFullName = Config.getInstance().getCurrentThemeFullName();
String oldThemeFullName = Config.getInstance().getCurrentThemeFullName();
Config.getInstance().setCurrentThemeFullName(sep[4]);
Config.getInstance().setCurrentThemeFullName(sep[4]);
if(!oldHeight.equals(sep[2]) || !oldWidth.equals(sep[1]) || !oldThemeFullName.equals(sep[4]))
if(!oldHeight.equals(sep[2]) || !oldWidth.equals(sep[1]) || !oldThemeFullName.equals(sep[4]))
Platform.runLater(clientListener::init);
Platform.runLater(clientListener::init);
Config.getInstance().save();
Config.getInstance().save();
Platform.runLater(clientListener::loadSettings);
Platform.runLater(clientListener::loadSettings);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
public void saveProfileDetails(Message message) throws SevereException, MinorException
public void saveProfileDetails(Message message) throws SevereException, MinorException
{
{
String[] sep = message.getStringArrValue();
String[] sep = message.getStringArrValue();
ClientProfile clientProfile = clientListener.getClientProfiles().getProfileFromID(sep[0]);
ClientProfile clientProfile = clientListener.getClientProfiles().getProfileFromID(sep[0]);
if(clientProfile == null)
if(clientProfile == null)
{
{
clientProfile = new ClientProfile(new File(Config.getInstance().getProfilesPath()+"/"+sep[0]+".xml"),
clientProfile = new ClientProfile(new File(Config.getInstance().getProfilesPath()+"/"+sep[0]+".xml"),
Config.getInstance().getIconsPath());
Config.getInstance().getIconsPath());
}
}
clientProfile.setName(sep[1]);
clientProfile.setName(sep[1]);
clientProfile.setRows(Integer.parseInt(sep[2]));
clientProfile.setRows(Integer.parseInt(sep[2]));
clientProfile.setCols(Integer.parseInt(sep[3]));
clientProfile.setCols(Integer.parseInt(sep[3]));
clientProfile.setActionSize(Integer.parseInt(sep[4]));
clientProfile.setActionSize(Integer.parseInt(sep[4]));
clientProfile.setActionGap(Integer.parseInt(sep[5]));
clientProfile.setActionGap(Integer.parseInt(sep[5]));
try
try
{
{
clientListener.getClientProfiles().addProfile(clientProfile);
clientListener.getClientProfiles().addProfile(clientProfile);
clientProfile.saveProfileDetails();
clientProfile.saveProfileDetails();
clientListener.refreshGridIfCurrentProfile(sep[0]);
clientListener.refreshGridIfCurrentProfile(sep[0]);
Platform.runLater(clientListener::loadSettings);
Platform.runLater(clientListener::loadSettings);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
public void deleteProfile(Message message)
public void deleteProfile(Message message)
{
{
clientListener.getClientProfiles().deleteProfile(clientListener.getClientProfiles().getProfileFromID(
clientListener.getClientProfiles().deleteProfile(clientListener.getClientProfiles().getProfileFromID(
message.getStringValue()
message.getStringValue()
));
));
if(clientListener.getCurrentProfile().getID().equals(message.getStringValue()))
if(clientListener.getCurrentProfile().getID().equals(message.getStringValue()))
{
{
Platform.runLater(clientListener::renderRootDefaultProfile);
Platform.runLater(clientListener::renderRootDefaultProfile);
}
}
}
}
public void onActionClicked(String profileID, String actionID) throws SevereException
public void onActionClicked(String profileID, String actionID) throws SevereException
{
{
Message m = new Message("action_clicked");
Message m = new Message("action_clicked");
m.setStringArrValue(profileID, actionID);
m.setStringArrValue(profileID, actionID);
sendMessage(m);
sendMessage(m);
}
}
public void actionFailed(Message message)
public void actionFailed(Message message)
{
{
String[] r = message.getStringArrValue();
String[] r = message.getStringArrValue();
String profileID = r[0];
String profileID = r[0];
String actionID = r[1];
String actionID = r[1];
clientListener.onActionFailed(profileID, actionID);
clientListener.onActionFailed(profileID, actionID);
}
}
}
}
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.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.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 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.scene.Node;
import javafx.scene.Node;
import javafx.util.Duration;
import javafx.util.Duration;
import java.io.*;
import java.io.*;
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;
@Override
@Override
public void init()
public void init()
{
{
try
try
{
{
if(firstRun)
if(firstRun)
initBase();
initBase();
if(getClientInfo().getPlatformType()!= com.stream_pi.util.platform.Platform.ANDROID)
if(getClientInfo().getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID)
{
{
getStage().setWidth(getConfig().getStartupWindowWidth());
getStage().setWidth(getConfig().getStartupWindowWidth());
getStage().setHeight(getConfig().getStartupWindowHeight());
getStage().setHeight(getConfig().getStartupWindowHeight());
getStage().centerOnScreen();
getStage().centerOnScreen();
setupFlags();
setupFlags();
}
}
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());
}
}
renderRootDefaultProfile();
renderRootDefaultProfile();
loadSettings();
loadSettings();
if(firstRun)
if(firstRun)
{
{
setupClientConnection();
setupClientConnection();
firstRun = false;
firstRun = false;
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
return;
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
return;
}
}
}
}
@Override
@Override
public void setupClientConnection()
public void setupClientConnection()
{
{
Platform.runLater(()->getSettingsPane().setDisableStatus(true));
Platform.runLater(()->getSettingsPane().setDisableStatus(true));
client = new Client(getConfig().getSavedServerHostNameOrIP(), getConfig().getSavedServerPort(), this, this);
client = new Client(getConfig().getSavedServerHostNameOrIP(), getConfig().getSavedServerPort(), this, this);
}
}
@Override
@Override
public void updateSettingsConnectDisconnectButton() {
public void updateSettingsConnectDisconnectButton() {
getSettingsPane().setConnectDisconnectButtonStatus();
getSettingsPane().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->onCloseRequest());
getStage().setOnCloseRequest(e->onCloseRequest());
}
}
@Override
@Override
public void onCloseRequest()
public void onCloseRequest()
{
{
if(isConnected())
if(isConnected())
client.exit();
client.exit();
getLogger().info("Shut down");
getLogger().info("Shut down");
closeLogger();
closeLogger();
if (ClientInfo.getInstance().getPlatformType() == 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);
}
}
@Override
@Override
public void loadSettings() {
public void loadSettings() {
try {
try {
getSettingsPane().loadData();
getSettingsPane().loadData();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
handleSevereException(e);
handleSevereException(e);
}
}
}
}
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().loadData();
getSettingsPane().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);
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);
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();
Platform.exit();
Platform.exit();
}
}
});
});
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)
{
{
StreamPiAlert alert = new StreamPiAlert(title, message, alertType);
StreamPiAlert alert = new StreamPiAlert(title, message, alertType);
return alert;
return alert;
}
}
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 onNormalActionClicked(String profileID, String actionID) {
public void onNormalActionClicked(String profileID, String actionID) {
try {
try {
client.onActionClicked(profileID, actionID);
client.onActionClicked(profileID, actionID);
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@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();
}
}
}
}
/*
/*
ServerInfo.java
ServerInfo.java
Stores basic information about the server - name, platform type
Stores basic information about the server - name, platform type
Contributors: Debayan Sutradhar (@dubbadhar)
Contributors: Debayan Sutradhar (@dubbadhar)
*/
*/
package com.stream_pi.client.info;
package com.stream_pi.client.info;
import com.gluonhq.attach.storage.StorageService;
import com.gluonhq.attach.storage.StorageService;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import java.io.File;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.util.Optional;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Function;
public class ClientInfo {
public class ClientInfo {
private Version version;
private Version version;
private final ReleaseStatus releaseStatus;
private final ReleaseStatus releaseStatus;
private Platform platformType;
private Platform platform;
private String prePath;
private String prePath;
private Version minThemeSupportVersion;
private Version minThemeSupportVersion;
private Version minPluginSupportVersion;
private Version minPluginSupportVersion;
private Version commStandardVersion;
private Version commStandardVersion;
private String runnerFileName;
private String runnerFileName;
private static ClientInfo instance = null;
private static ClientInfo instance = null;
private ClientInfo()
private ClientInfo()
{
{
version = new Version(1,0,0);
version = new Version(0,0,0);
minThemeSupportVersion = new Version(1,0,0);
minThemeSupportVersion = new Version(1,0,0);
minPluginSupportVersion = new Version(1,0,0);
minPluginSupportVersion = new Version(1,0,0);
commStandardVersion = new Version(1,0,0);
commStandardVersion = new Version(1,0,0);
releaseStatus = ReleaseStatus.EA;
releaseStatus = ReleaseStatus.EA;
String osName = System.getProperty("os.name").toLowerCase();
String osName = System.getProperty("os.name").toLowerCase();
prePath = System.getProperty("user.home")+"/Stream-Pi/Client/";
prePath = System.getProperty("user.home")+"/Stream-Pi/Client/";
if(osName.contains("windows"))
if(osName.contains("windows"))
{
{
platformType = Platform.WINDOWS;
platform = Platform.WINDOWS;
}
}
else if (osName.contains("linux"))
else if (osName.contains("linux"))
{
{
platformType = Platform.LINUX;
platform = Platform.LINUX;
}
}
else if(osName.contains("android")) // SPECIFY -Dsvm.targetName=android WHILE BUILDING ANDROID NATIVE IMAGE
else if(osName.contains("android")) // SPECIFY -Dsvm.targetName=android WHILE BUILDING ANDROID NATIVE IMAGE
{
{
StorageService.create().ifPresent(s->{
StorageService.create().ifPresent(s->{
s.getPublicStorage("Documents").ifPresentOrElse(sp->{
s.getPublicStorage("Documents").ifPresentOrElse(sp->{
prePath = sp.getAbsolutePath()+"/Stream-Pi/Client/";
prePath = sp.getAbsolutePath()+"/Stream-Pi/Client/";
}, ()->
}, ()->
{
{
prePath = null;
prePath = null;
});
});
});
});
platformType = Platform.ANDROID;
platform = Platform.ANDROID;
}
}
else if(osName.contains("ios")) // SPECIFY -Dsvm.targetName=ios WHILE BUILDING ANDROID NATIVE IMAGE
else if(osName.contains("ios")) // SPECIFY -Dsvm.targetName=ios WHILE BUILDING ANDROID NATIVE IMAGE
{
{
StorageService.create().ifPresent(s->{
StorageService.create().ifPresent(s->{
s.getPrivateStorage().ifPresentOrElse(sp->{
s.getPrivateStorage().ifPresentOrElse(sp->{
prePath = sp.getAbsolutePath()+"/Stream-Pi/Client/";
prePath = sp.getAbsolutePath()+"/Stream-Pi/Client/";
}, ()->
}, ()->
{
{
prePath = null;
prePath = null;
});
});
});
});
platformType = Platform.IOS;
platform = Platform.IOS;
}
}
else if (osName.contains("mac"))
else if (osName.contains("mac"))
{
{
platformType = Platform.MAC;
platform = Platform.MAC;
}
}
else
else
{
{
platformType = Platform.UNKNOWN;
platform = Platform.UNKNOWN;
}
}
}
}
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 ClientInfo getInstance(){
public static synchronized ClientInfo getInstance(){
if(instance == null)
if(instance == null)
{
{
instance = new ClientInfo();
instance = new ClientInfo();
}
}
return instance;
return instance;
}
}
private boolean isShowShutDownButton = false;
private boolean isShowShutDownButton = false;
public void setShowShutDownButton(boolean showShutDownButton) {
public void setShowShutDownButton(boolean showShutDownButton) {
isShowShutDownButton = showShutDownButton;
isShowShutDownButton = showShutDownButton;
}
}
private boolean isXMode = false;
private boolean isXMode = false;
public void setXMode(boolean isXMode)
public void setXMode(boolean isXMode)
{
{
this.isXMode = isXMode;
this.isXMode = isXMode;
}
}
public boolean isXMode() {
public boolean isXMode() {
return isXMode;
return isXMode;
}
}
public boolean isShowShutDownButton() {
public boolean isShowShutDownButton() {
return isShowShutDownButton;
return isShowShutDownButton;
}
}
public String getPrePath()
public String getPrePath()
{
{
return prePath;
return prePath;
}
}
public Platform getPlatformType()
public Platform getPlatform()
{
{
return platformType;
return platform;
}
}
public Version getVersion() {
public Version getVersion() {
return version;
return version;
}
}
public ReleaseStatus getReleaseStatus()
public ReleaseStatus getReleaseStatus()
{
{
return releaseStatus;
return releaseStatus;
}
}
public Version getMinThemeSupportVersion()
public Version getMinThemeSupportVersion()
{
{
return minThemeSupportVersion;
return minThemeSupportVersion;
}
}
public Version getMinPluginSupportVersion()
public Version getMinPluginSupportVersion()
{
{
return minPluginSupportVersion;
return minPluginSupportVersion;
}
}
public Version getCommStandardVersion()
public Version getCommStandardVersion()
{
{
return commStandardVersion;
return commStandardVersion;
}
}
}
}
/*
/*
Config.java
Config.java
Contributor(s) : Debayan Sutradhar (@rnayabed)
Contributor(s) : Debayan Sutradhar (@rnayabed)
handler for config.xml
handler for config.xml
*/
*/
package com.stream_pi.client.io;
package com.stream_pi.client.io;
import java.io.File;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamResult;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
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.xmlconfighelper.XMLConfigHelper;
import com.stream_pi.util.xmlconfighelper.XMLConfigHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Element;
public class Config {
public class Config {
private static Config instance = null;
private static Config instance = null;
private final File configFile;
private final File configFile;
private Document document;
private Document document;
private Config() throws SevereException
private Config() throws SevereException
{
{
try
try
{
{
configFile = new File(ClientInfo.getInstance().getPrePath()+"config.xml");
configFile = new File(ClientInfo.getInstance().getPrePath()+"config.xml");
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
document = docBuilder.parse(configFile);
document = docBuilder.parse(configFile);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException("Config", "unable to read config.xml");
throw new SevereException("Config", "unable to read config.xml");
}
}
}
}
public static synchronized Config getInstance() throws SevereException
public static synchronized Config getInstance() throws SevereException
{
{
if(instance == null)
if(instance == null)
instance = new Config();
instance = new Config();
return instance;
return instance;
}
}
public void save() throws SevereException
public void save() throws SevereException
{
{
try
try
{
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(configFile);
Result output = new StreamResult(configFile);
Source input = new DOMSource(document);
Source input = new DOMSource(document);
transformer.transform(input, output);
transformer.transform(input, output);
}
}
catch (Exception e)
catch (Exception e)
{
{
throw new SevereException("Config", "unable to save config.xml");
throw new SevereException("Config", "unable to save config.xml");
}
}
}
}
//Client Element
//Client Element
public Element getClientElement()
public Element getClientElement()
{
{
return (Element) document.getElementsByTagName("client").item(0);
return (Element) document.getElementsByTagName("client").item(0);
}
}
//Default Values
//Default Values
public String getDefaultClientNickName()
public String getDefaultClientNickName()
{
{
return "Stream-Pi Client";
return "Stream-Pi Client";
}
}
public String getDefaultStartupProfileID()
public String getDefaultStartupProfileID()
{
{
return "default";
return "default";
}
}
public String getDefaultCurrentThemeFullName()
public String getDefaultCurrentThemeFullName()
{
{
return "com.stream_pi.defaultlight";
return "com.stream_pi.defaultlight";
}
}
public String getDefaultThemesPath()
public String getDefaultThemesPath()
{
{
return ClientInfo.getInstance().getPrePath()+"Themes/";
return ClientInfo.getInstance().getPrePath()+"Themes/";
}
}
public String getDefaultProfilesPath()
public String getDefaultProfilesPath()
{
{
return ClientInfo.getInstance().getPrePath()+"Profiles/";
return ClientInfo.getInstance().getPrePath()+"Profiles/";
}
}
public String getDefaultIconsPath()
public String getDefaultIconsPath()
{
{
return ClientInfo.getInstance().getPrePath()+"Icons/";
return ClientInfo.getInstance().getPrePath()+"Icons/";
}
}
public int getDefaultStartupWindowWidth()
public int getDefaultStartupWindowWidth()
{
{
return 800;
return 800;
}
}
public int getDefaultStartupWindowHeight()
public int getDefaultStartupWindowHeight()
{
{
return 400;
return 400;
}
}
//Getters
//Getters
public String getClientNickName()
public String getClientNickName()
{
{
return XMLConfigHelper.getStringProperty(getClientElement(), "nickname", getDefaultClientNickName(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getClientElement(), "nickname", getDefaultClientNickName(), false, true, document, configFile);
}
}
public String getStartupProfileID()
public String getStartupProfileID()
{
{
return XMLConfigHelper.getStringProperty(getClientElement(), "startup-profile", getDefaultStartupProfileID(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getClientElement(), "startup-profile", getDefaultStartupProfileID(), false, true, document, configFile);
}
}
public String getCurrentThemeFullName()
public String getCurrentThemeFullName()
{
{
return XMLConfigHelper.getStringProperty(getClientElement(), "current-theme-full-name", getDefaultCurrentThemeFullName(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getClientElement(), "current-theme-full-name", getDefaultCurrentThemeFullName(), false, true, document, configFile);
}
}
public String getThemesPath()
public String getThemesPath()
{
{
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
Platform platform = ClientInfo.getInstance().getPlatform();
if(platform != Platform.ANDROID &&
platform != Platform.IOS)
return ClientInfo.getInstance().getPrePath() + "Themes/";
return ClientInfo.getInstance().getPrePath() + "Themes/";
return XMLConfigHelper.getStringProperty(getClientElement(), "themes-path", getDefaultThemesPath(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getClientElement(), "themes-path", getDefaultThemesPath(), false, true, document, configFile);
}
}
public String getProfilesPath()
public String getProfilesPath()
{
{
Platform platform = ClientInfo.getInstance().getPlatform();
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
if(platform != Platform.ANDROID &&
platform != Platform.IOS)
return ClientInfo.getInstance().getPrePath() + "Profiles/";
return ClientInfo.getInstance().getPrePath() + "Profiles/";
return XMLConfigHelper.getStringProperty(getClientElement(), "profiles-path", getDefaultProfilesPath(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getClientElement(), "profiles-path", getDefaultProfilesPath(), false, true, document, configFile);
}
}
public String getIconsPath()
public String getIconsPath()
{
{
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
Platform platform = ClientInfo.getInstance().getPlatform();
if(platform != Platform.ANDROID &&
platform != Platform.IOS)
return ClientInfo.getInstance().getPrePath() + "Icons/";
return ClientInfo.getInstance().getPrePath() + "Icons/";
return XMLConfigHelper.getStringProperty(getClientElement(), "icons-path", getDefaultIconsPath(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getClientElement(), "icons-path", getDefaultIconsPath(), false, true, document, configFile);
}
}
public double getStartupWindowWidth()
public double getStartupWindowWidth()
{
{
return XMLConfigHelper.getDoubleProperty((Element) getClientElement().getElementsByTagName("startup-window-size").item(0), "width", getDefaultStartupWindowWidth(), false, true, document, configFile);
return XMLConfigHelper.getDoubleProperty((Element) getClientElement().getElementsByTagName("startup-window-size").item(0), "width", getDefaultStartupWindowWidth(), false, true, document, configFile);
}
}
public double getStartupWindowHeight()
public double getStartupWindowHeight()
{
{
return XMLConfigHelper.getDoubleProperty((Element) getClientElement().getElementsByTagName("startup-window-size").item(0), "height", getDefaultStartupWindowHeight(), false, true, document, configFile);
return XMLConfigHelper.getDoubleProperty((Element) getClientElement().getElementsByTagName("startup-window-size").item(0), "height", getDefaultStartupWindowHeight(), false, true, document, configFile);
}
}
//Setters
//Setters
public void setNickName(String nickName)
public void setNickName(String nickName)
{
{
getClientElement().getElementsByTagName("nickname").item(0).setTextContent(nickName);
getClientElement().getElementsByTagName("nickname").item(0).setTextContent(nickName);
}
}
public void setStartupProfileID(String id)
public void setStartupProfileID(String id)
{
{
getClientElement().getElementsByTagName("startup-profile").item(0).setTextContent(id);
getClientElement().getElementsByTagName("startup-profile").item(0).setTextContent(id);
}
}
public void setCurrentThemeFullName(String name)
public void setCurrentThemeFullName(String name)
{
{
getClientElement().getElementsByTagName("current-theme-full-name").item(0).setTextContent(name);
getClientElement().getElementsByTagName("current-theme-full-name").item(0).setTextContent(name);
}
}
public void setProfilesPath(String profilesPath)
public void setProfilesPath(String profilesPath)
{
{
getClientElement().getElementsByTagName("profiles-path").item(0).setTextContent(profilesPath);
getClientElement().getElementsByTagName("profiles-path").item(0).setTextContent(profilesPath);
}
}
public void setIconsPath(String iconsPath)
public void setIconsPath(String iconsPath)
{
{
getClientElement().getElementsByTagName("icons-path").item(0).setTextContent(iconsPath);
getClientElement().getElementsByTagName("icons-path").item(0).setTextContent(iconsPath);
}
}
public void setThemesPath(String themesPath)
public void setThemesPath(String themesPath)
{
{
getClientElement().getElementsByTagName("themes-path").item(0).setTextContent(themesPath);
getClientElement().getElementsByTagName("themes-path").item(0).setTextContent(themesPath);
}
}
//client > startup-window-size
//client > startup-window-size
public void setStartupWindowSize(double width, double height)
public void setStartupWindowSize(double width, double height)
{
{
setStartupWindowWidth(width);
setStartupWindowWidth(width);
setStartupWindowHeight(height);
setStartupWindowHeight(height);
}
}
public void setStartupWindowWidth(double width)
public void setStartupWindowWidth(double width)
{
{
((Element) getClientElement().getElementsByTagName("startup-window-size").item(0))
((Element) getClientElement().getElementsByTagName("startup-window-size").item(0))
.getElementsByTagName("width").item(0).setTextContent(width+"");
.getElementsByTagName("width").item(0).setTextContent(width+"");
}
}
public void setStartupWindowHeight(double height)
public void setStartupWindowHeight(double height)
{
{
((Element) getClientElement().getElementsByTagName("startup-window-size").item(0))
((Element) getClientElement().getElementsByTagName("startup-window-size").item(0))
.getElementsByTagName("height").item(0).setTextContent(height+"");
.getElementsByTagName("height").item(0).setTextContent(height+"");
}
}
//comms-server
//comms-server
public Element getCommsServerElement()
public Element getCommsServerElement()
{
{
return (Element) document.getElementsByTagName("comms-server").item(0);
return (Element) document.getElementsByTagName("comms-server").item(0);
}
}
public String getDefaultSavedServerHostNameOrIP()
public String getDefaultSavedServerHostNameOrIP()
{
{
return "127.0.0.1";
return "127.0.0.1";
}
}
public int getDefaultSavedServerPort()
public int getDefaultSavedServerPort()
{
{
return -1;
return -1;
}
}
public String getSavedServerHostNameOrIP()
public String getSavedServerHostNameOrIP()
{
{
return XMLConfigHelper.getStringProperty(getCommsServerElement(), "hostname-ip", getDefaultSavedServerHostNameOrIP(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getCommsServerElement(), "hostname-ip", getDefaultSavedServerHostNameOrIP(), false, true, document, configFile);
}
}
public int getSavedServerPort()
public int getSavedServerPort()
{
{
return XMLConfigHelper.getIntProperty(getCommsServerElement(), "port", getDefaultSavedServerPort(), false, true, document, configFile);
return XMLConfigHelper.getIntProperty(getCommsServerElement(), "port", getDefaultSavedServerPort(), false, true, document, configFile);
}
}
public void setServerHostNameOrIP(String hostNameOrIP)
public void setServerHostNameOrIP(String hostNameOrIP)
{
{
getCommsServerElement().getElementsByTagName("hostname-ip").item(0).setTextContent(hostNameOrIP);
getCommsServerElement().getElementsByTagName("hostname-ip").item(0).setTextContent(hostNameOrIP);
}
}
public void setServerPort(int port)
public void setServerPort(int port)
{
{
getCommsServerElement().getElementsByTagName("port").item(0).setTextContent(port+"");
getCommsServerElement().getElementsByTagName("port").item(0).setTextContent(port+"");
}
}
//others
//others
public Element getOthersElement()
public Element getOthersElement()
{
{
return (Element) document.getElementsByTagName("others").item(0);
return (Element) document.getElementsByTagName("others").item(0);
}
}
//others-default
//others-default
public boolean getDefaultStartOnBoot()
public boolean getDefaultStartOnBoot()
{
{
return false;
return false;
}
}
public boolean getDefaultFullscreen()
public boolean getDefaultFullscreen()
{
{
return true;
return true;
}
}
public boolean getDefaultIsShowCursor()
public boolean getDefaultIsShowCursor()
{
{
return true;
return true;
}
}
public boolean getDefaultFirstTimeUse()
public boolean getDefaultFirstTimeUse()
{
{
return true;
return true;
}
}
public boolean isShowCursor()
public boolean isShowCursor()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "show-cursor", getDefaultIsShowCursor(), false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "show-cursor", getDefaultIsShowCursor(), false, true, document, configFile);
}
}
public boolean isStartOnBoot()
public boolean isStartOnBoot()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "start-on-boot", getDefaultStartOnBoot(), false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "start-on-boot", getDefaultStartOnBoot(), false, true, document, configFile);
}
}
public boolean isFullscreen()
public boolean isFullscreen()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "fullscreen", getDefaultFullscreen(), false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "fullscreen", getDefaultFullscreen(), false, true, document, configFile);
}
}
public boolean isFirstTimeUse()
public boolean isFirstTimeUse()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "first-time-use", true, false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "first-time-use", true, false, true, document, configFile);
}
}
public void setStartOnBoot(boolean value)
public void setStartOnBoot(boolean value)
{
{
getOthersElement().getElementsByTagName("start-on-boot").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("start-on-boot").item(0).setTextContent(value+"");
}
}
public void setShowCursor(boolean value)
public void setShowCursor(boolean value)
{
{
getOthersElement().getElementsByTagName("show-cursor").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("show-cursor").item(0).setTextContent(value+"");
}
}
public void setFullscreen(boolean value)
public void setFullscreen(boolean value)
{
{
getOthersElement().getElementsByTagName("fullscreen").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("fullscreen").item(0).setTextContent(value+"");
}
}
public void setFirstTimeUse(boolean value)
public void setFirstTimeUse(boolean value)
{
{
getOthersElement().getElementsByTagName("first-time-use").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("first-time-use").item(0).setTextContent(value+"");
}
}
}
}
package com.stream_pi.client.window;
package com.stream_pi.client.window;
import com.stream_pi.client.connection.ClientListener;
import com.stream_pi.client.connection.ClientListener;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
import com.stream_pi.client.Main;
import com.stream_pi.client.Main;
import com.stream_pi.client.profile.ClientProfiles;
import com.stream_pi.client.profile.ClientProfiles;
import com.stream_pi.client.window.dashboard.DashboardBase;
import com.stream_pi.client.window.dashboard.DashboardBase;
import com.stream_pi.client.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.client.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.client.window.settings.SettingsBase;
import com.stream_pi.client.window.settings.SettingsBase;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Themes;
import com.stream_pi.theme_api.Themes;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.combobox.StreamPiComboBox;
import com.stream_pi.util.combobox.StreamPiComboBox;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.loggerhelper.StreamPiLogFallbackHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFallbackHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFileHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFileHandler;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.Cursor;
import javafx.scene.Cursor;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.Font;
import javafx.stage.Screen;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.Stage;
public abstract class Base extends StackPane implements ExceptionAndAlertHandler, ClientListener {
public abstract class Base extends StackPane implements ExceptionAndAlertHandler, ClientListener {
private Config config;
private Config config;
private ClientProfiles clientProfiles;
private ClientProfiles clientProfiles;
private ClientInfo clientInfo;
private ClientInfo clientInfo;
private Stage stage;
private Stage stage;
public Stage getStage()
public Stage getStage()
{
{
return stage;
return stage;
}
}
public Logger getLogger()
public Logger getLogger()
{
{
return logger;
return logger;
}
}
private DashboardBase dashboardBase;
private DashboardBase dashboardBase;
private SettingsBase settingsBase;
private SettingsBase settingsBase;
private FirstTimeUse firstTimeUse;
private FirstTimeUse firstTimeUse;
public FirstTimeUse getFirstTimeUse() {
public FirstTimeUse getFirstTimeUse() {
return firstTimeUse;
return firstTimeUse;
}
}
private StackPane alertStackPane;
private StackPane alertStackPane;
@Override
@Override
public ClientProfiles getClientProfiles() {
public ClientProfiles getClientProfiles() {
return clientProfiles;
return clientProfiles;
}
}
public void setClientProfiles(ClientProfiles clientProfiles) {
public void setClientProfiles(ClientProfiles clientProfiles) {
this.clientProfiles = clientProfiles;
this.clientProfiles = clientProfiles;
}
}
private Logger logger = null;
private Logger logger = null;
private StreamPiLogFileHandler logFileHandler = null;
private StreamPiLogFileHandler logFileHandler = null;
private StreamPiLogFallbackHandler logFallbackHandler = null;
private StreamPiLogFallbackHandler logFallbackHandler = null;
@Override
@Override
public void initLogger()
public void initLogger()
{
{
try
try
{
{
if(logFileHandler != null)
if(logFileHandler != null)
return;
return;
closeLogger();
closeLogger();
logger = Logger.getLogger("");
logger = Logger.getLogger("");
if(new File(ClientInfo.getInstance().getPrePath()).getAbsoluteFile().getParentFile().canWrite())
if(new File(ClientInfo.getInstance().getPrePath()).getAbsoluteFile().getParentFile().canWrite())
{
{
String path = ClientInfo.getInstance().getPrePath()+"../stream-pi-client.log";
String path = ClientInfo.getInstance().getPrePath()+"../stream-pi-client.log";
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
Platform platform = getClientInfo().getPlatform();
if(platform == Platform.ANDROID ||
platform == Platform.IOS)
path = ClientInfo.getInstance().getPrePath()+"stream-pi-client.log";
path = ClientInfo.getInstance().getPrePath()+"stream-pi-client.log";
logFileHandler = new StreamPiLogFileHandler(path);
logFileHandler = new StreamPiLogFileHandler(path);
logger.addHandler(logFileHandler);
logger.addHandler(logFileHandler);
}
}
else
else
{
{
logFallbackHandler = new StreamPiLogFallbackHandler();
logFallbackHandler = new StreamPiLogFallbackHandler();
logger.addHandler(logFallbackHandler);
logger.addHandler(logFallbackHandler);
}
}
}
}
catch(Exception e)
catch(Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
logFallbackHandler = new StreamPiLogFallbackHandler();
logFallbackHandler = new StreamPiLogFallbackHandler();
logger.addHandler(logFallbackHandler);
logger.addHandler(logFallbackHandler);
}
}
}
}
public void closeLogger()
public void closeLogger()
{
{
if(logFileHandler != null)
if(logFileHandler != null)
logFileHandler.close();
logFileHandler.close();
else if(logFallbackHandler != null)
else if(logFallbackHandler != null)
logFallbackHandler.close();
logFallbackHandler.close();
}
}
private HostServices hostServices;
private HostServices hostServices;
public void setHostServices(HostServices hostServices)
public void setHostServices(HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
}
}
public HostServices getHostServices()
public HostServices getHostServices()
{
{
return hostServices;
return hostServices;
}
}
public void initBase() throws SevereException
public void initBase() throws SevereException
{
{
stage = (Stage) getScene().getWindow();
stage = (Stage) getScene().getWindow();
getStage().getIcons().add(new Image(Main.class.getResourceAsStream("app_icon.png")));
getStage().getIcons().add(new Image(Main.class.getResourceAsStream("app_icon.png")));
clientInfo = ClientInfo.getInstance();
clientInfo = ClientInfo.getInstance();
dashboardBase = new DashboardBase(this, this);
dashboardBase = new DashboardBase(this, this);
dashboardBase.prefWidthProperty().bind(widthProperty());
dashboardBase.prefWidthProperty().bind(widthProperty());
dashboardBase.prefHeightProperty().bind(heightProperty());
dashboardBase.prefHeightProperty().bind(heightProperty());
settingsBase = new SettingsBase(this, this, getHostServices());
settingsBase = new SettingsBase(this, this, getHostServices());
alertStackPane = new StackPane();
alertStackPane = new StackPane();
alertStackPane.setPadding(new Insets(10));
alertStackPane.setPadding(new Insets(10));
alertStackPane.setVisible(false);
alertStackPane.setVisible(false);
StreamPiAlert.setParent(alertStackPane);
StreamPiAlert.setParent(alertStackPane);
StreamPiComboBox.setParent(alertStackPane);
StreamPiComboBox.setParent(alertStackPane);
firstTimeUse = new FirstTimeUse(this, this);
firstTimeUse = new FirstTimeUse(this, this);
getChildren().clear();
getChildren().clear();
getChildren().addAll(alertStackPane);
getChildren().addAll(alertStackPane);
initLogger();
initLogger();
checkPrePathDirectory();
checkPrePathDirectory();
getChildren().addAll(settingsBase, dashboardBase);
getChildren().addAll(settingsBase, dashboardBase);
setStyle(null);
setStyle(null);
config = Config.getInstance();
config = Config.getInstance();
if(config.isFirstTimeUse())
if(config.isFirstTimeUse())
{
{
clearStylesheets();
clearStylesheets();
applyDefaultStylesheet();
applyDefaultStylesheet();
applyDefaultIconsStylesheet();
applyDefaultIconsStylesheet();
getChildren().add(firstTimeUse);
getChildren().add(firstTimeUse);
firstTimeUse.toFront();
firstTimeUse.toFront();
//resolution check
//resolution check
resizeAccordingToResolution();
resizeAccordingToResolution();
}
}
else
else
{
{
dashboardBase.toFront();
dashboardBase.toFront();
}
}
initThemes();
initThemes();
}
}
private void resizeAccordingToResolution()
private void resizeAccordingToResolution()
{
{
if(ClientInfo.getInstance().getPlatformType() != Platform.ANDROID)
if(ClientInfo.getInstance().getPlatform() != Platform.ANDROID)
{
{
double height = getScreenHeight();
double height = getScreenHeight();
double width = getScreenWidth();
double width = getScreenWidth();
logger.info("HEIGHT: "+height+", WIDTH: "+width);
logger.info("HEIGHT: "+height+", WIDTH: "+width);
if(height < 500)
if(height < 500)
setPrefHeight(320);
setPrefHeight(320);
if(width < 500)
if(width < 500)
setPrefWidth(240);
setPrefWidth(240);
}
}
}
}
@Override
@Override
public double getStageWidth()
public double getStageWidth()
{
{
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
if(ClientInfo.getInstance().getPlatform() == Platform.ANDROID)
{
{
return getScreenWidth();
return getScreenWidth();
}
}
else
else
{
{
return getStage().getWidth();
return getStage().getWidth();
}
}
}
}
public double getScreenWidth()
public double getScreenWidth()
{
{
return Screen.getPrimary().getBounds().getWidth();
return Screen.getPrimary().getBounds().getWidth();
}
}
@Override
@Override
public double getStageHeight()
public double getStageHeight()
{
{
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
if(ClientInfo.getInstance().getPlatform() == Platform.ANDROID)
{
{
return getScreenHeight();
return getScreenHeight();
}
}
else
else
{
{
return getStage().getHeight();
return getStage().getHeight();
}
}
}
}
public double getScreenHeight()
public double getScreenHeight()
{
{
return Screen.getPrimary().getBounds().getHeight();
return Screen.getPrimary().getBounds().getHeight();
}
}
private void checkPrePathDirectory() throws SevereException
private void checkPrePathDirectory() throws SevereException
{
{
try
try
{
{
File filex = new File(getClientInfo().getPrePath());
String path = getClientInfo().getPrePath();
System.out.println("PAAAAAAAAAAAATH : '"+path+"'");
if(path == null)
{
throwStoragePermErrorAlert("Unable to access file system!");
return;
}
File file = new File(path);
if(!filex.exists())
if(!file.canWrite() || !file.canRead())
{
{
boolean result = filex.mkdirs();
throwStoragePermErrorAlert("No read/write storage permission. Give it!");
return;
}
if(!file.exists())
{
boolean result = file.mkdirs();
if(result)
if(result)
{
{
IOHelper.unzip(Main.class.getResourceAsStream("Default.zip"), ClientInfo.getInstance().getPrePath());
IOHelper.unzip(Main.class.getResourceAsStream("Default.zip"), ClientInfo.getInstance().getPrePath());
Config.getInstance().setThemesPath(ClientInfo.getInstance().getPrePath()+"Themes/");
Config.getInstance().setThemesPath(ClientInfo.getInstance().getPrePath()+"Themes/");
Config.getInstance().setIconsPath(ClientInfo.getInstance().getPrePath()+"Icons/");
Config.getInstance().setIconsPath(ClientInfo.getInstance().getPrePath()+"Icons/");
Config.getInstance().setProfilesPath(ClientInfo.getInstance().getPrePath()+"Profiles/");
Config.getInstance().setProfilesPath(ClientInfo.getInstance().getPrePath()+"Profiles/");
Config.getInstance().save();
Config.getInstance().save();
initLogger();
initLogger();
}
}
else
else
{
{
resizeAccordingToResolution();
throwStoragePermErrorAlert("No storage permission. Give it!");
clearStylesheets();
applyDefaultStylesheet();
applyDefaultIconsStylesheet();
getStage().show();
throw new SevereException("No storage permission. Give it!");
}
}
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
private void throwStoragePermErrorAlert(String msg) throws SevereException
{
resizeAccordingToResolution();
clearStylesheets();
applyDefaultStylesheet();
applyDefaultIconsStylesheet();
getStage().show();
throw new SevereException(msg);
}
public void setupFlags()
public void setupFlags()
{
{
//Full Screen
//Full Screen
if(getConfig().isFullscreen())
if(getConfig().isFullscreen())
{
{
getStage().setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
getStage().setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
getStage().setFullScreen(true);
getStage().setFullScreen(true);
}
}
else
else
{
{
getStage().setFullScreenExitKeyCombination(KeyCombination.keyCombination("Esc"));
getStage().setFullScreenExitKeyCombination(KeyCombination.keyCombination("Esc"));
getStage().setFullScreen(false);
getStage().setFullScreen(false);
}
}
//Cursor
//Cursor
if(getConfig().isShowCursor())
if(getConfig().isShowCursor())
{
{
setCursor(Cursor.DEFAULT);
setCursor(Cursor.DEFAULT);
}
}
else
else
{
{
setCursor(Cursor.NONE);
setCursor(Cursor.NONE);
}
}
}
}
public SettingsBase getSettingsPane() {
public SettingsBase getSettingsPane() {
return settingsBase;
return settingsBase;
}
}
public DashboardBase getDashboardPane() {
public DashboardBase getDashboardPane() {
return dashboardBase;
return dashboardBase;
}
}
public void renderRootDefaultProfile()
public void renderRootDefaultProfile()
{
{
getDashboardPane().renderProfile(getClientProfiles().getProfileFromID(
getDashboardPane().renderProfile(getClientProfiles().getProfileFromID(
getConfig().getStartupProfileID()
getConfig().getStartupProfileID()
), true);
), true);
}
}
public void clearStylesheets()
public void clearStylesheets()
{
{
getStylesheets().clear();
getStylesheets().clear();
}
}
public void applyDefaultStylesheet()
public void applyDefaultStylesheet()
{
{
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
}
}
public void applyDefaultIconsStylesheet()
public void applyDefaultIconsStylesheet()
{
{
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
getStylesheets().add(Main.class.getResource("default_icons.css").toExternalForm());
getStylesheets().add(Main.class.getResource("default_icons.css").toExternalForm());
}
}
public Config getConfig()
public Config getConfig()
{
{
return config;
return config;
}
}
public ClientInfo getClientInfo()
public ClientInfo getClientInfo()
{
{
return clientInfo;
return clientInfo;
}
}
private Theme currentTheme;
private Theme currentTheme;
@Override
@Override
public Theme getCurrentTheme()
public Theme getCurrentTheme()
{
{
return currentTheme;
return currentTheme;
}
}
public void applyTheme(Theme t)
public void applyTheme(Theme t)
{
{
logger.info("Applying theme '"+t.getFullName()+"' ...");
logger.info("Applying theme '"+t.getFullName()+"' ...");
if(t.getFonts() != null)
if(t.getFonts() != null)
{
{
for(String fontFile : t.getFonts())
for(String fontFile : t.getFonts())
{
{
Font.loadFont(fontFile.replace("%20",""), 13);
Font.loadFont(fontFile.replace("%20",""), 13);
}
}
}
}
currentTheme = t;
currentTheme = t;
clearStylesheets();
clearStylesheets();
applyDefaultStylesheet();
applyDefaultStylesheet();
getStylesheets().addAll(t.getStylesheets());
getStylesheets().addAll(t.getStylesheets());
applyDefaultIconsStylesheet();
applyDefaultIconsStylesheet();
logger.info("... Done!");
logger.info("... Done!");
}
}
Themes themes;
Themes themes;
public void initThemes() throws SevereException
public void initThemes() throws SevereException
{
{
logger.info("Loading themes ...");
logger.info("Loading themes ...");
themes = new Themes(getConfig().getThemesPath(), getConfig().getCurrentThemeFullName(), clientInfo.getMinThemeSupportVersion());
themes = new Themes(getConfig().getThemesPath(), getConfig().getCurrentThemeFullName(), clientInfo.getMinThemeSupportVersion());
if(themes.getErrors().size()>0)
if(themes.getErrors().size()>0)
{
{
StringBuilder themeErrors = new StringBuilder();
StringBuilder themeErrors = new StringBuilder();
for(MinorException eachException : themes.getErrors())
for(MinorException eachException : themes.getErrors())
{
{
themeErrors.append("\n * ").append(eachException.getShortMessage());
themeErrors.append("\n * ").append(eachException.getShortMessage());
}
}
if(themes.getIsBadThemeTheCurrentOne())
if(themes.getIsBadThemeTheCurrentOne())
{
{
themeErrors.append("\n\nReverted to default theme! (").append(getConfig().getDefaultCurrentThemeFullName()).append(")");
themeErrors.append("\n\nReverted to default theme! (").append(getConfig().getDefaultCurrentThemeFullName()).append(")");
getConfig().setCurrentThemeFullName(getConfig().getDefaultCurrentThemeFullName());
getConfig().setCurrentThemeFullName(getConfig().getDefaultCurrentThemeFullName());
getConfig().save();
getConfig().save();
}
}
handleMinorException(new MinorException("Theme Loading issues", themeErrors.toString()));
handleMinorException(new MinorException("Theme Loading issues", themeErrors.toString()));
}
}
logger.info("... Done!");
logger.info("... Done!");
}
}
@Override
@Override
public Themes getThemes() {
public Themes getThemes() {
return themes;
return themes;
}
}
public void applyDefaultTheme()
public void applyDefaultTheme()
{
{
logger.info("Applying default theme ...");
logger.info("Applying default theme ...");
boolean foundTheme = false;
boolean foundTheme = false;
for(Theme t: themes.getThemeList())
for(Theme t: themes.getThemeList())
{
{
if(t.getFullName().equals(config.getCurrentThemeFullName()))
if(t.getFullName().equals(config.getCurrentThemeFullName()))
{
{
foundTheme = true;
foundTheme = true;
applyTheme(t);
applyTheme(t);
break;
break;
}
}
}
}
if(foundTheme)
if(foundTheme)
{
{
logger.info("... Done!");
logger.info("... Done!");
}
}
else
else
{
{
logger.info("Theme not found. reverting to light theme ...");
logger.info("Theme not found. reverting to light theme ...");
try {
try {
Config.getInstance().setCurrentThemeFullName("com.StreamPi.DefaultLight");
Config.getInstance().setCurrentThemeFullName("com.StreamPi.DefaultLight");
Config.getInstance().save();
Config.getInstance().save();
applyDefaultTheme();
applyDefaultTheme();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
}
}
@Override
@Override
public String getDefaultThemeFullName()
public String getDefaultThemeFullName()
{
{
return config.getCurrentThemeFullName();
return config.getCurrentThemeFullName();
}
}
}
}
package com.stream_pi.client.window.firsttimeuse;
package com.stream_pi.client.window.firsttimeuse;
import com.stream_pi.client.connection.ClientListener;
import com.stream_pi.client.connection.ClientListener;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
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.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;
public class FinalConfigPane extends VBox
public class FinalConfigPane extends VBox
{
{
private TextField clientNicknameTextField;
private TextField clientNicknameTextField;
private TextField serverIPHostNameTextField;
private TextField serverIPHostNameTextField;
private TextField serverPortTextField;
private TextField serverPortTextField;
private TextField displayWidthTextField;
private TextField displayWidthTextField;
private TextField displayHeightTextField;
private TextField displayHeightTextField;
private Button nextButton;
private Button nextButton;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ClientListener clientListener;
private ClientListener clientListener;
public FinalConfigPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ClientListener clientListener,
public FinalConfigPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ClientListener clientListener,
Button nextButton)
Button nextButton)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.clientListener = clientListener;
this.clientListener = clientListener;
this.nextButton = nextButton;
this.nextButton = nextButton;
getStyleClass().add("first_time_use_pane_final_config");
getStyleClass().add("first_time_use_pane_final_config");
Label label = new Label("Thats it. Now just a little bit and then you're set!");
Label label = new Label("Thats it. Now just a little bit and then you're set!");
label.setWrapText(true);
label.setWrapText(true);
VBox.setVgrow(label, Priority.ALWAYS);
VBox.setVgrow(label, Priority.ALWAYS);
label.getStyleClass().add("first_time_use_pane_final_config_label");
label.getStyleClass().add("first_time_use_pane_final_config_label");
clientNicknameTextField = new TextField();
clientNicknameTextField = new TextField();
serverIPHostNameTextField = new TextField();
serverIPHostNameTextField = new TextField();
serverPortTextField = new TextField();
serverPortTextField = new TextField();
displayWidthTextField = new TextField();
displayWidthTextField = new TextField();
displayHeightTextField = new TextField();
displayHeightTextField = new TextField();
HBoxInputBox clientNickNameInputBox = new HBoxInputBox("Nickname", clientNicknameTextField);
HBoxInputBox clientNickNameInputBox = new HBoxInputBox("Nickname", clientNicknameTextField);
HBoxInputBox serverIPHostNameInputBox = new HBoxInputBox("Server IP", serverIPHostNameTextField);
HBoxInputBox serverIPHostNameInputBox = new HBoxInputBox("Server IP", serverIPHostNameTextField);
HBoxInputBox serverIPPortInputBox = new HBoxInputBox("Server Port", serverPortTextField);
HBoxInputBox serverIPPortInputBox = new HBoxInputBox("Server Port", serverPortTextField);
HBoxInputBox displayWidthInputBox = new HBoxInputBox("Display Width", displayWidthTextField);
HBoxInputBox displayWidthInputBox = new HBoxInputBox("Display Width", displayWidthTextField);
HBoxInputBox displayHeightInputBox = new HBoxInputBox("Display Height", displayHeightTextField);
HBoxInputBox displayHeightInputBox = new HBoxInputBox("Display Height", displayHeightTextField);
if(ClientInfo.getInstance().getPlatformType() == Platform.ANDROID)
Platform platform = ClientInfo.getInstance().getPlatform();
if(platform == Platform.ANDROID ||
platform == Platform.IOS)
{
{
displayWidthInputBox.setVisible(false);
displayWidthInputBox.setVisible(false);
displayHeightInputBox.setVisible(false);
displayHeightInputBox.setVisible(false);
}
}
VBox v = new VBox(clientNickNameInputBox, serverIPHostNameInputBox, serverIPPortInputBox,
VBox v = new VBox(clientNickNameInputBox, serverIPHostNameInputBox, serverIPPortInputBox,
displayWidthInputBox, displayHeightInputBox);
displayWidthInputBox, displayHeightInputBox);
v.setSpacing(10.0);
v.setSpacing(10.0);
ScrollPane scrollPane = new ScrollPane(v);
ScrollPane scrollPane = new ScrollPane(v);
scrollPane.getStyleClass().add("first_time_use_final_config_pane_scroll_pane");
scrollPane.getStyleClass().add("first_time_use_final_config_pane_scroll_pane");
v.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
v.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
getChildren().addAll(label, scrollPane);
getChildren().addAll(label, scrollPane);
setSpacing(10.0);
setSpacing(10.0);
setVisible(false);
setVisible(false);
}
}
public void makeChangesToNextButton()
public void makeChangesToNextButton()
{
{
nextButton.setText("Confirm");
nextButton.setText("Confirm");
nextButton.setOnAction(event -> onConfirmButtonClicked());
nextButton.setOnAction(event -> onConfirmButtonClicked());
}
}
private void onConfirmButtonClicked()
private void onConfirmButtonClicked()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(clientNicknameTextField.getText().isBlank())
if(clientNicknameTextField.getText().isBlank())
{
{
errors.append("* Nick name cannot be blank.\n");
errors.append("* Nick name cannot be blank.\n");
}
}
if(serverIPHostNameTextField.getText().isBlank())
if(serverIPHostNameTextField.getText().isBlank())
{
{
errors.append("* Server IP cannot be empty.\n");
errors.append("* Server IP cannot be empty.\n");
}
}
int port = -1;
int port = -1;
try
try
{
{
port = Integer.parseInt(serverPortTextField.getText());
port = Integer.parseInt(serverPortTextField.getText());
if(port < 1024)
if(port < 1024)
errors.append("* Server IP should be above 1024.\n");
errors.append("* Server IP should be above 1024.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Server IP should be a number.\n");
errors.append("* Server IP should be a number.\n");
}
}
double width=-1,height=-1;
double width=-1,height=-1;
if(ClientInfo.getInstance().getPlatformType() != Platform.ANDROID)
if(ClientInfo.getInstance().getPlatform() != Platform.ANDROID)
{
{
try
try
{
{
width = Double.parseDouble(displayWidthTextField.getText());
width = Double.parseDouble(displayWidthTextField.getText());
if(width < 0)
if(width < 0)
errors.append("* Display Width should be above 0.\n");
errors.append("* Display Width should be above 0.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Display Width should be a number.\n");
errors.append("* Display Width should be a number.\n");
}
}
try
try
{
{
height = Double.parseDouble(displayHeightTextField.getText());
height = Double.parseDouble(displayHeightTextField.getText());
if(height < 0)
if(height < 0)
errors.append("* Display Height should be above 0.\n");
errors.append("* Display Height should be above 0.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Display Height should be a number.\n");
errors.append("* Display Height should be a number.\n");
}
}
}
}
if(errors.toString().isEmpty())
if(errors.toString().isEmpty())
{
{
try
try
{
{
Config.getInstance().setNickName(clientNicknameTextField.getText());
Config.getInstance().setNickName(clientNicknameTextField.getText());
Config.getInstance().setServerHostNameOrIP(serverIPHostNameTextField.getText());
Config.getInstance().setServerHostNameOrIP(serverIPHostNameTextField.getText());
Config.getInstance().setServerPort(port);
Config.getInstance().setServerPort(port);
Config.getInstance().setFirstTimeUse(false);
Config.getInstance().setFirstTimeUse(false);
if(ClientInfo.getInstance().getPlatformType() != Platform.ANDROID)
Platform platform = ClientInfo.getInstance().getPlatform();
if(platform != Platform.ANDROID &&
platform != Platform.IOS)
{
{
Config.getInstance().setStartupWindowSize(
Config.getInstance().setStartupWindowSize(
width, height
width, height
);
);
}
}
Config.getInstance().save();
Config.getInstance().save();
clientListener.init();
clientListener.init();
}
}
catch(SevereException e)
catch(SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
else
else
{
{
new StreamPiAlert("Uh Oh", "Please rectify the following errors and try again:\n"+errors.toString(), StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh", "Please rectify the following errors and try again:\n"+errors.toString(), StreamPiAlertType.ERROR).show();
}
}
}
}
}
}
package com.stream_pi.client.window.settings;
package com.stream_pi.client.window.settings;
import java.io.File;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import com.gluonhq.attach.browser.BrowserService;
import com.stream_pi.client.connection.ClientListener;
import com.stream_pi.client.connection.ClientListener;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
import com.stream_pi.util.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.PlatformType;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.startatboot.StartAtBoot;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.concurrent.Task;
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;
public class SettingsBase extends VBox {
public class SettingsBase extends VBox {
private TextField serverPortTextField;
private TextField serverPortTextField;
private TextField serverHostNameOrIPTextField;
private TextField serverHostNameOrIPTextField;
private StreamPiComboBox<ClientProfile> clientProfileComboBox;
private StreamPiComboBox<ClientProfile> clientProfileComboBox;
private StreamPiComboBox<Theme> themeComboBox;
private StreamPiComboBox<Theme> themeComboBox;
private TextField displayWidthTextField;
private TextField displayWidthTextField;
private TextField displayHeightTextField;
private TextField displayHeightTextField;
private TextField nickNameTextField;
private TextField nickNameTextField;
private Button closeButton;
private Button closeButton;
private Button saveButton;
private Button saveButton;
private Button connectDisconnectButton;
private Button connectDisconnectButton;
private Button shutdownButton;
private Button shutdownButton;
private ToggleButton startOnBootToggleButton;
private ToggleButton startOnBootToggleButton;
private ToggleButton showCursorToggleButton;
private ToggleButton showCursorToggleButton;
private ToggleButton fullScreenToggleButton;
private ToggleButton fullScreenToggleButton;
private ClientListener clientListener;
private ClientListener clientListener;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private TextField themesPathTextField;
private TextField themesPathTextField;
private TextField iconsPathTextField;
private TextField iconsPathTextField;
private TextField profilesPathTextField;
private TextField profilesPathTextField;
private final Button checkForUpdatesButton;
private final Button checkForUpdatesButton;
private HostServices hostServices;
private HostServices hostServices;
public SettingsBase(ExceptionAndAlertHandler exceptionAndAlertHandler,
public SettingsBase(ExceptionAndAlertHandler exceptionAndAlertHandler,
ClientListener clientListener, HostServices hostServices)
ClientListener clientListener, HostServices hostServices)
{
{
getStyleClass().add("settings_base");
getStyleClass().add("settings_base");
this.hostServices = hostServices;
this.hostServices = hostServices;
this.clientListener = clientListener;
this.clientListener = clientListener;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
serverPortTextField = new TextField();
serverPortTextField = 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();
}
}
});
});
displayHeightTextField = new TextField();
displayHeightTextField = new TextField();
displayWidthTextField = new TextField();
displayWidthTextField = new TextField();
themesPathTextField = new TextField();
themesPathTextField = new TextField();
iconsPathTextField = new TextField();
iconsPathTextField = new TextField();
profilesPathTextField = new TextField();
profilesPathTextField = new TextField();
startOnBootToggleButton = new ToggleButton("Start On Boot");
startOnBootToggleButton = new ToggleButton("Start On Boot");
startOnBootToggleButton.managedProperty().bind(startOnBootToggleButton.visibleProperty());
startOnBootToggleButton.managedProperty().bind(startOnBootToggleButton.visibleProperty());
showCursorToggleButton = new ToggleButton("Show Cursor");
showCursorToggleButton = new ToggleButton("Show Cursor");
showCursorToggleButton.managedProperty().bind(showCursorToggleButton.visibleProperty());
showCursorToggleButton.managedProperty().bind(showCursorToggleButton.visibleProperty());
fullScreenToggleButton = new ToggleButton("Full Screen");
fullScreenToggleButton = new ToggleButton("Full Screen");
fullScreenToggleButton.managedProperty().bind(fullScreenToggleButton.visibleProperty());
fullScreenToggleButton.managedProperty().bind(fullScreenToggleButton.visibleProperty());
int prefWidth = 200;
int prefWidth = 200;
Label licenseLabel = new Label("This software is licensed to GNU GPLv3. Check StreamPi Server > settings > About to see full License Statement.");
Label licenseLabel = new Label("This software is licensed to GNU GPLv3. Check StreamPi Server > settings > About to see full License Statement.");
licenseLabel.setWrapText(true);
licenseLabel.setWrapText(true);
Label versionLabel = new Label(ClientInfo.getInstance().getReleaseStatus().getUIName() +" "+ClientInfo.getInstance().getVersion().getText());
Label versionLabel = new Label(ClientInfo.getInstance().getReleaseStatus().getUIName() +" "+ClientInfo.getInstance().getVersion().getText());
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());
HBoxInputBox screenHeightInputBox = new HBoxInputBox("Screen Height", displayHeightTextField, prefWidth);
HBoxInputBox screenHeightInputBox = new HBoxInputBox("Screen Height", displayHeightTextField, prefWidth);
screenHeightInputBox.managedProperty().bind(screenHeightInputBox.visibleProperty());
screenHeightInputBox.managedProperty().bind(screenHeightInputBox.visibleProperty());
HBoxInputBox screenWidthInputBox = new HBoxInputBox("Screen Width", displayWidthTextField, prefWidth);
HBoxInputBox screenWidthInputBox = new HBoxInputBox("Screen Width", displayWidthTextField, prefWidth);
screenWidthInputBox.managedProperty().bind(screenWidthInputBox.visibleProperty());
screenWidthInputBox.managedProperty().bind(screenWidthInputBox.visibleProperty());
if(ClientInfo.getInstance().getPlatformType() == com.stream_pi.util.platform.Platform.ANDROID)
com.stream_pi.util.platform.Platform platform = ClientInfo.getInstance().getPlatform();
if(platform == Platform.ANDROID ||
platform == Platform.IOS)
{
{
themesPathInputBox.setVisible(false);
themesPathInputBox.setVisible(false);
iconsPathInputBox.setVisible(false);
iconsPathInputBox.setVisible(false);
profilesPathInputBox.setVisible(false);
profilesPathInputBox.setVisible(false);
startOnBootToggleButton.setVisible(false);
startOnBootToggleButton.setVisible(false);
showCursorToggleButton.setVisible(false);
showCursorToggleButton.setVisible(false);
fullScreenToggleButton.setVisible(false);
fullScreenToggleButton.setVisible(false);
screenHeightInputBox.setVisible(false);
screenHeightInputBox.setVisible(false);
screenWidthInputBox.setVisible(false);
screenWidthInputBox.setVisible(false);
}
}
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
checkForUpdatesButton.setOnAction(event->checkForUpdates());
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
),
),
screenHeightInputBox,
screenHeightInputBox,
screenWidthInputBox,
screenWidthInputBox,
themesPathInputBox,
themesPathInputBox,
iconsPathInputBox,
iconsPathInputBox,
profilesPathInputBox
profilesPathInputBox
);
);
if(ClientInfo.getInstance().getPlatformType() == com.stream_pi.util.platform.Platform.LINUX &&
if(ClientInfo.getInstance().getPlatform() == com.stream_pi.util.platform.Platform.LINUX &&
ClientInfo.getInstance().isShowShutDownButton())
ClientInfo.getInstance().isShowShutDownButton())
{
{
shutdownButton = new Button("Shutdown");
shutdownButton = new Button("Shutdown");
shutdownButton.setOnAction(event -> onShutdownButtonClicked());
shutdownButton.setOnAction(event -> onShutdownButtonClicked());
vBox.getChildren().add(shutdownButton);
vBox.getChildren().add(shutdownButton);
}
}
vBox.getChildren().addAll(
vBox.getChildren().addAll(
checkForUpdatesButton,
checkForUpdatesButton,
startOnBootToggleButton,
startOnBootToggleButton,
showCursorToggleButton,
showCursorToggleButton,
fullScreenToggleButton,
fullScreenToggleButton,
licenseLabel,
licenseLabel,
versionLabel
versionLabel
);
);
vBox.getStyleClass().add("settings_base_vbox");
vBox.getStyleClass().add("settings_base_vbox");
vBox.setSpacing(5.0);
vBox.setSpacing(5.0);
vBox.setPadding(new Insets(5));
vBox.setPadding(new Insets(5));
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.getStyleClass().add("settings_base_scroll_pane");
scrollPane.getStyleClass().add("settings_base_scroll_pane");
scrollPane.setContent(vBox);
scrollPane.setContent(vBox);
vBox.setMinWidth(300);
vBox.setMinWidth(300);
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
Label settingsLabel = new Label("Settings");
Label settingsLabel = new Label("Settings");
settingsLabel.setPadding(new Insets(5,0,0,5));
settingsLabel.setPadding(new Insets(5,0,0,5));
settingsLabel.getStyleClass().add("settings_heading_label");
settingsLabel.getStyleClass().add("settings_heading_label");
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event->onSaveButtonClicked());
saveButton.setOnAction(event->onSaveButtonClicked());
closeButton = new Button("Close");
closeButton = new Button("Close");
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, exitButton, closeButton);
HBox buttonBar = new HBox(connectDisconnectButton, saveButton, exitButton, closeButton);
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(5.0);
setSpacing(5.0);
getChildren().addAll(
getChildren().addAll(
settingsLabel,
settingsLabel,
scrollPane,
scrollPane,
buttonBar
buttonBar
);
);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
private void checkForUpdates()
private void checkForUpdates()
{
{
new CheckForUpdates(checkForUpdatesButton, hostServices,
new CheckForUpdates(checkForUpdatesButton,
PlatformType.CLIENT, ClientInfo.getInstance().getVersion());
PlatformType.CLIENT, ClientInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
@Override
public void handle(ActionEvent actionEvent) {
Platform platform = ClientInfo.getInstance().getPlatform();
if(platform == Platform.ANDROID || platform == Platform.IOS)
{
BrowserService.create().ifPresentOrElse(s->
{
try
{
s.launchExternalBrowser(getURL());
}
catch (Exception e )
{
exceptionAndAlertHandler.handleMinorException(
new MinorException("Cant start browser!")
);
}
},()-> exceptionAndAlertHandler.handleMinorException(
new MinorException("Sorry!","No browser detected.")
));
}
else
{
hostServices.showDocument(getURL());
}
}
});
}
}
public void onExitButtonClicked()
public void onExitButtonClicked()
{
{
clientListener.onCloseRequest();
clientListener.onCloseRequest();
Platform.exit();
javafx.application.Platform.exit();
}
}
public void setDisableStatus(boolean status)
public void setDisableStatus(boolean status)
{
{
saveButton.setDisable(status);
saveButton.setDisable(status);
connectDisconnectButton.setDisable(status);
connectDisconnectButton.setDisable(status);
}
}
public 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()
{
{
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 Button getCloseButton() {
public Button getCloseButton() {
return closeButton;
return closeButton;
}
}
public void loadData() throws SevereException
public void loadData() throws SevereException
{
{
nickNameTextField.setText(Config.getInstance().getClientNickName());
nickNameTextField.setText(Config.getInstance().getClientNickName());
serverHostNameOrIPTextField.setText(Config.getInstance().getSavedServerHostNameOrIP());
serverHostNameOrIPTextField.setText(Config.getInstance().getSavedServerHostNameOrIP());
serverPortTextField.setText(Config.getInstance().getSavedServerPort()+"");
serverPortTextField.setText(Config.getInstance().getSavedServerPort()+"");
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);
displayWidthTextField.setText(Config.getInstance().getStartupWindowWidth()+"");
displayWidthTextField.setText(Config.getInstance().getStartupWindowWidth()+"");
displayHeightTextField.setText(Config.getInstance().getStartupWindowHeight()+"");
displayHeightTextField.setText(Config.getInstance().getStartupWindowHeight()+"");
themesPathTextField.setText(Config.getInstance().getThemesPath());
themesPathTextField.setText(Config.getInstance().getThemesPath());
iconsPathTextField.setText(Config.getInstance().getIconsPath());
iconsPathTextField.setText(Config.getInstance().getIconsPath());
profilesPathTextField.setText(Config.getInstance().getProfilesPath());
profilesPathTextField.setText(Config.getInstance().getProfilesPath());
startOnBootToggleButton.setSelected(Config.getInstance().isStartOnBoot());
startOnBootToggleButton.setSelected(Config.getInstance().isStartOnBoot());
fullScreenToggleButton.setSelected(Config.getInstance().isFullscreen());
fullScreenToggleButton.setSelected(Config.getInstance().isFullscreen());
showCursorToggleButton.setSelected(Config.getInstance().isShowCursor());
showCursorToggleButton.setSelected(Config.getInstance().isShowCursor());
}
}
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 IP should be above 1024.\n");
errors.append("* Server IP should be above 1024.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Server IP should be a number.\n");
errors.append("* Server IP should be a number.\n");
}
}
double width = -1;
double width = -1;
try
try
{
{
width = Double.parseDouble(displayWidthTextField.getText());
width = Double.parseDouble(displayWidthTextField.getText());
if(width < 0)
if(width < 0)
errors.append("* Display Width should be above 0.\n");
errors.append("* Display Width should be above 0.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Display Width should be a number.\n");
errors.append("* Display Width should be a number.\n");
}
}
double height = -1;
double height = -1;
try
try
{
{
height = Double.parseDouble(displayHeightTextField.getText());
height = Double.parseDouble(displayHeightTextField.getText());
if(height < 0)
if(height < 0)
errors.append("* Display Height should be above 0.\n");
errors.append("* Display Height should be above 0.\n");
}
}
catch (NumberFormatException exception)
catch (NumberFormatException exception)
{
{
errors.append("* Display Height should be a number.\n");
errors.append("* Display Height should be a number.\n");
}
}
if(serverHostNameOrIPTextField.getText().isBlank())
if(serverHostNameOrIPTextField.getText().isBlank())
{
{
errors.append("* Server IP cannot be empty.\n");
errors.append("* Server IP cannot be empty.\n");
}
}
if(nickNameTextField.getText().isBlank())
if(nickNameTextField.getText().isBlank())
{
{
errors.append("* Nick name cannot be blank.\n");
errors.append("* Nick name cannot be blank.\n");
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException(
exceptionAndAlertHandler.handleMinorException(new MinorException(
"You made mistakes",
"You made mistakes",
"Please fix the errors and try again :\n"+errors.toString()
"Please fix the errors and try again :\n"+errors.toString()
));
));
return;
return;
}
}
try {
try {
boolean toBeReloaded = false;
boolean toBeReloaded = false;
boolean breakConnection = false;
boolean breakConnection = false;
if(!Config.getInstance().getCurrentThemeFullName().equals(themeComboBox.getCurrentSelectedItem().getFullName()))
if(!Config.getInstance().getCurrentThemeFullName().equals(themeComboBox.getCurrentSelectedItem().getFullName()))
{
{
breakConnection = true;
breakConnection = true;
toBeReloaded = true;
toBeReloaded = true;
}
}
Config.getInstance().setCurrentThemeFullName(themeComboBox.getCurrentSelectedItem().getFullName());
Config.getInstance().setCurrentThemeFullName(themeComboBox.getCurrentSelectedItem().getFullName());
if(width != Config.getInstance().getStartupWindowWidth() || height != Config.getInstance().getStartupWindowHeight())
if(width != Config.getInstance().getStartupWindowWidth() || height != Config.getInstance().getStartupWindowHeight())
toBeReloaded = true;
toBeReloaded = true;
Config.getInstance().setStartupWindowSize(width, height);
Config.getInstance().setStartupWindowSize(width, height);
if(!Config.getInstance().getClientNickName().equals(nickNameTextField.getText()))
if(!Config.getInstance().getClientNickName().equals(nickNameTextField.getText()))
breakConnection = true;
breakConnection = true;
Config.getInstance().setNickName(nickNameTextField.getText());
Config.getInstance().setNickName(nickNameTextField.getText());
if(port != Config.getInstance().getSavedServerPort() || !serverHostNameOrIPTextField.getText().equals(Config.getInstance().getSavedServerHostNameOrIP()))
if(port != Config.getInstance().getSavedServerPort() || !serverHostNameOrIPTextField.getText().equals(Config.getInstance().getSavedServerHostNameOrIP()))
breakConnection = true;
breakConnection = true;
Config.getInstance().setServerPort(port);
Config.getInstance().setServerPort(port);
Config.getInstance().setServerHostNameOrIP(serverHostNameOrIPTextField.getText());
Config.getInstance().setServerHostNameOrIP(serverHostNameOrIPTextField.getText());
boolean startOnBoot = startOnBootToggleButton.isSelected();
boolean startOnBoot = startOnBootToggleButton.isSelected();
if(Config.getInstance().isStartOnBoot() != startOnBoot)
if(Config.getInstance().isStartOnBoot() != startOnBoot)
{
{
if(ClientInfo.getInstance().getRunnerFileName() == null)
if(ClientInfo.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(PlatformType.CLIENT, ClientInfo.getInstance().getPlatformType());
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.CLIENT, ClientInfo.getInstance().getPlatform());
if(startOnBoot)
if(startOnBoot)
{
{
startAtBoot.create(new File(ClientInfo.getInstance().getRunnerFileName()),
startAtBoot.create(new File(ClientInfo.getInstance().getRunnerFileName()),
ClientInfo.getInstance().isXMode());
ClientInfo.getInstance().isXMode());
}
}
else
else
{
{
boolean result = startAtBoot.delete();
boolean result = startAtBoot.delete();
if(!result)
if(!result)
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
}
}
}
Config.getInstance().setStartOnBoot(startOnBoot);
Config.getInstance().setStartOnBoot(startOnBoot);
if(Config.getInstance().isFullscreen() != fullScreenToggleButton.isSelected() ||
if(Config.getInstance().isFullscreen() != fullScreenToggleButton.isSelected() ||
Config.getInstance().isShowCursor() != showCursorToggleButton.isSelected())
Config.getInstance().isShowCursor() != showCursorToggleButton.isSelected())
toBeReloaded = true;
toBeReloaded = true;
Config.getInstance().setFullscreen(fullScreenToggleButton.isSelected());
Config.getInstance().setFullscreen(fullScreenToggleButton.isSelected());
Config.getInstance().setShowCursor(showCursorToggleButton.isSelected());
Config.getInstance().setShowCursor(showCursorToggleButton.isSelected());
if(!Config.getInstance().getThemesPath().equals(themesPathTextField.getText()))
if(!Config.getInstance().getThemesPath().equals(themesPathTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
Config.getInstance().setThemesPath(themesPathTextField.getText());
Config.getInstance().setThemesPath(themesPathTextField.getText());
if(!Config.getInstance().getIconsPath().equals(iconsPathTextField.getText()))
if(!Config.getInstance().getIconsPath().equals(iconsPathTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
Config.getInstance().setIconsPath(iconsPathTextField.getText());
Config.getInstance().setIconsPath(iconsPathTextField.getText());
if(!Config.getInstance().getProfilesPath().equals(profilesPathTextField.getText()))
if(!Config.getInstance().getProfilesPath().equals(profilesPathTextField.getText()))
toBeReloaded = true;
toBeReloaded = true;
Config.getInstance().setProfilesPath(profilesPathTextField.getText());
Config.getInstance().setProfilesPath(profilesPathTextField.getText());
Config.getInstance().save();
Config.getInstance().save();
loadData();
loadData();
if(breakConnection)
if(breakConnection)
{
{
if(clientListener.isConnected())
if(clientListener.isConnected())
{
{
clientListener.disconnect("Client connection settings were changed. Client will reconnect again.");
clientListener.disconnect("Client connection settings were changed. Client will reconnect again.");
clientListener.setupClientConnection();
clientListener.setupClientConnection();
}
}
}
}
if(toBeReloaded)
if(toBeReloaded)
{
{
clientListener.init();
clientListener.init();
clientListener.renderRootDefaultProfile();
clientListener.renderRootDefaultProfile();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
}
}
module com.stream_pi.client {
module com.stream_pi.client {
requires javafx.base;
requires javafx.base;
requires javafx.graphics;
requires javafx.graphics;
requires javafx.controls;
requires javafx.controls;
requires org.kordamp.iconli.core;
requires org.kordamp.iconli.core;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.javafx;
requires com.gluonhq.attach.lifecycle;
requires com.gluonhq.attach.lifecycle;
requires com.gluonhq.attach.util;
requires com.gluonhq.attach.util;
requires com.gluonhq.attach.storage;
requires com.gluonhq.attach.storage;
requires com.gluonhq.attach.browser;
requires java.xml;
requires java.xml;
requires com.stream_pi.util;
requires com.stream_pi.util;
requires com.stream_pi.theme_api;
requires com.stream_pi.theme_api;
requires com.stream_pi.action_api;
requires com.stream_pi.action_api;
requires org.kordamp.ikonli.fontawesome5;
requires org.kordamp.ikonli.fontawesome5;
exports com.stream_pi.client;
exports com.stream_pi.client;
}
}