server
Clone or download
Modified Files
package com.StreamPi.Server.Connection;
package com.StreamPi.Server.Connection;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.Action.ActionType;
import com.StreamPi.ActionAPI.Action.ActionType;
import com.StreamPi.ActionAPI.Action.DisplayTextAlignment;
import com.StreamPi.ActionAPI.Action.DisplayTextAlignment;
import com.StreamPi.ActionAPI.Action.Location;
import com.StreamPi.ActionAPI.Action.Location;
import com.StreamPi.ActionAPI.ActionProperty.ClientProperties;
import com.StreamPi.ActionAPI.ActionProperty.ClientProperties;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.OtherActions.CombineAction;
import com.StreamPi.ActionAPI.OtherActions.CombineAction;
import com.StreamPi.ActionAPI.OtherActions.FolderAction;
import com.StreamPi.ActionAPI.OtherActions.FolderAction;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Client.Client;
import com.StreamPi.Server.Client.Client;
import com.StreamPi.Server.Client.ClientProfile;
import com.StreamPi.Server.Client.ClientProfile;
import com.StreamPi.Server.Client.ClientTheme;
import com.StreamPi.Server.Client.ClientTheme;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Util.Alert.StreamPiAlert;
import com.StreamPi.Util.Alert.StreamPiAlert;
import com.StreamPi.Util.Alert.StreamPiAlertType;
import com.StreamPi.Util.Alert.StreamPiAlertType;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.StreamPiException;
import com.StreamPi.Util.Exception.StreamPiException;
import com.StreamPi.Util.Platform.Platform;
import com.StreamPi.Util.Platform.Platform;
import com.StreamPi.Util.Platform.ReleaseStatus;
import com.StreamPi.Util.Platform.ReleaseStatus;
import com.StreamPi.Util.Version.Version;
import com.StreamPi.Util.Version.Version;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.Random;
import java.util.Random;
import java.util.UUID;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.Logger;
import java.util.stream.Stream;
import java.util.stream.Stream;
public class ClientConnection extends Thread{
public class ClientConnection extends Thread{
private Socket socket;
private Socket socket;
private ServerListener serverListener;
private ServerListener serverListener;
private AtomicBoolean stop = new AtomicBoolean(false);
private AtomicBoolean stop = new AtomicBoolean(false);
private DataInputStream dis;
private DataInputStream dis;
private DataOutputStream dos;
private DataOutputStream dos;
private Logger logger;
private Logger logger;
private Client client = null;
private Client client = null;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public ClientConnection(Socket socket, ServerListener serverListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
public ClientConnection(Socket socket, ServerListener serverListener, ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
//actionIconsToBeSent = new ArrayList__();
//actionIconsToBeSent = new ArrayList__();
this.socket = socket;
this.socket = socket;
this.serverListener = serverListener;
this.serverListener = serverListener;
logger = Logger.getLogger(ClientConnection.class.getName());
logger = Logger.getLogger(ClientConnection.class.getName());
try
try
{
{
dis = new DataInputStream(socket.getInputStream());
dis = new DataInputStream(socket.getInputStream());
dos = new DataOutputStream(socket.getOutputStream());
dos = new DataOutputStream(socket.getOutputStream());
} catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException("Unable to start socket streams"));
exceptionAndAlertHandler.handleMinorException(new MinorException("Unable to start socket streams"));
}
}
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)
{
{
logger.info("Stopping connection "+socket.getRemoteSocketAddress());
logger.info("Stopping connection "+socket.getRemoteSocketAddress());
disconnect();
disconnect();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
public synchronized void exitAndRemove()
public synchronized void exitAndRemove()
{
{
exit();
exit();
removeConnection();
removeConnection();
serverListener.clearTemp();
serverListener.clearTemp();
}
}
public void removeConnection()
public void removeConnection()
{
{
ClientConnections.getInstance().removeConnection(this);
ClientConnections.getInstance().removeConnection(this);
}
}
public void writeToStream(String text) throws SevereException
public void writeToStream(String text) throws SevereException
{
{
/*try
/*try
{
{
logger.debug(text);
logger.debug(text);
dos.writeUTF(text);
dos.writeUTF(text);
dos.flush();
dos.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!");
}*/
}*/
try
try
{
{
byte[] txtBytes = text.getBytes();
byte[] txtBytes = text.getBytes();
Thread.sleep(50);
Thread.sleep(50);
dos.writeUTF("string:: ::");
dos.writeUTF("string:: ::");
dos.flush();
dos.flush();
dos.writeInt(txtBytes.length);
dos.writeInt(txtBytes.length);
dos.flush();
dos.flush();
write(txtBytes);
write(txtBytes);
dos.flush();
dos.flush();
}
}
catch (IOException | InterruptedException e)
catch (IOException | InterruptedException e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException("Unable to write to IO Stream!");
throw new SevereException("Unable to write to IO Stream!");
}
}
}
}
public void sendIcon(String profileID, String actionID, byte[] icon) throws SevereException
public void sendIcon(String profileID, String actionID, byte[] icon) throws SevereException
{
{
try
try
{
{
logger.info("Sending action Icon...");
logger.info("Sending action Icon...");
//Thread.sleep(50);
//Thread.sleep(50);
System.out.println("1");
System.out.println("1");
dos.writeUTF("action_icon::"+profileID+"!!"+actionID+"!!::"+icon.length);
dos.writeUTF("action_icon::"+profileID+"!!"+actionID+"!!::"+icon.length);
System.out.println("2");
System.out.println("2");
dos.flush();
dos.flush();
System.out.println("3");
System.out.println("3");
dos.writeInt(icon.length);
dos.writeInt(icon.length);
System.out.println("4");
System.out.println("4");
dos.flush();
dos.flush();
System.out.println("5");
System.out.println("5");
write(icon);
write(icon);
System.out.println("6");
System.out.println("6");
dos.flush();
dos.flush();
System.out.println("7");
System.out.println("7");
}
}
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!");
}
}
}
}
public void write(byte[] array) throws SevereException
public void write(byte[] array) throws SevereException
{
{
try
try
{
{
dos.write(array);
dos.write(array);
}
}
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!");
}
}
}
}
public void initAfterConnectionQueryReceive(String[] arr) throws StreamPiException
public void initAfterConnectionQueryReceive(String[] arr) throws StreamPiException
{
{
logger.info("Setting up Client object ...");
logger.info("Setting up Client object ...");
Version clientVersion;
Version clientVersion;
Version commsStandard;
Version commsStandard;
Version themesStandard;
Version themesStandard;
ReleaseStatus releaseStatus;
ReleaseStatus releaseStatus;
try
try
{
{
clientVersion = new Version(arr[1]);
clientVersion = new Version(arr[1]);
releaseStatus = ReleaseStatus.valueOf(arr[2]);
releaseStatus = ReleaseStatus.valueOf(arr[2]);
commsStandard = new Version(arr[3]);
commsStandard = new Version(arr[3]);
themesStandard = new Version(arr[4]);
themesStandard = new Version(arr[4]);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exitAndRemove();
exitAndRemove();
throw new MinorException(e.getShortMessage()+" (Client '"+socket.getRemoteSocketAddress()+"' )");
throw new MinorException(e.getShortMessage()+" (Client '"+socket.getRemoteSocketAddress()+"' )");
}
}
if(!commsStandard.isEqual(ServerInfo.getInstance().getCommStandardVersion()))
if(!commsStandard.isEqual(ServerInfo.getInstance().getCommStandardVersion()))
{
{
String errTxt = "Server and Client Communication standards do not match. Make sure you are on the latest version of server and client.\n" +
String errTxt = "Server and Client Communication standards do not match. Make sure you are on the latest version of server and client.\n" +
"Server Comms. Standard : "+ServerInfo.getInstance().getCommStandardVersion().getText()+
"Server Comms. Standard : "+ServerInfo.getInstance().getCommStandardVersion().getText()+
"\nClient Comms. Standard : "+commsStandard.getText();
"\nClient Comms. Standard : "+commsStandard.getText();
disconnect(errTxt);
disconnect(errTxt);
throw new MinorException(errTxt);
throw new MinorException(errTxt);
}
}
client = new Client(clientVersion, releaseStatus, commsStandard, themesStandard, arr[5], Platform.valueOf(arr[8]), socket.getRemoteSocketAddress());
client = new Client(clientVersion, releaseStatus, commsStandard, themesStandard, arr[5], Platform.valueOf(arr[8]), socket.getRemoteSocketAddress());
client.setStartupDisplayWidth(Double.parseDouble(arr[6]));
client.setStartupDisplayWidth(Double.parseDouble(arr[6]));
client.setStartupDisplayHeight(Double.parseDouble(arr[7]));
client.setStartupDisplayHeight(Double.parseDouble(arr[7]));
client.setDefaultProfileID(arr[9]);
client.setDefaultProfileID(arr[9]);
client.setDefaultThemeFullName(arr[10]);
client.setDefaultThemeFullName(arr[10]);
//call get profiles command.
//call get profiles command.
serverListener.clearTemp();
serverListener.clearTemp();
}
}
public synchronized Client getClient()
public synchronized Client getClient()
{
{
return client;
return client;
}
}
@Override
@Override
public void run() {
public void run() {
try {
try {
initAfterConnectionQuerySend();
initAfterConnectionQuerySend();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
exitAndRemove();
exitAndRemove();
return;
return;
}
}
try
try
{
{
while(!stop.get())
while(!stop.get())
{
{
String msg = "";
String msg = "";
try
try
{
{
String raw = dis.readUTF();
String raw = dis.readUTF();
int length = dis.readInt();
int length = dis.readInt();
System.out.println("SIZE TO READ : "+length);
System.out.println("SIZE TO READ : "+length);
String[] precursor = raw.split("::");
String[] precursor = raw.split("::");
String inputType = precursor[0];
String inputType = precursor[0];
String secondArg = precursor[1];
String secondArg = precursor[1];
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
/*int count;
/*int count;
int chunkSize = 512;
int chunkSize = 512;
while (length>0)
while (length>0)
{
{
if(chunkSize > length)
if(chunkSize > length)
chunkSize = length;
chunkSize = length;
else
else
chunkSize = 512;
chunkSize = 512;
byte[] buffer = new byte[chunkSize];
byte[] buffer = new byte[chunkSize];
count = dis.read(buffer);
count = dis.read(buffer);
System.out.println(count);
System.out.println(count);
byteArrayOutputStream.write(buffer);
byteArrayOutputStream.write(buffer);
length-=count;
length-=count;
}*/
}*/
/*byte[] buffer = new byte[8192];
/*byte[] buffer = new byte[8192];
int read;
int read;
while((read = dis.read(buffer)) != -1){
while((read = dis.read(buffer)) != -1){
System.out.println("READ : "+read);
System.out.println("READ : "+read);
byteArrayOutputStream.write(buffer, 0, read);
byteArrayOutputStream.write(buffer, 0, read);
}
}
System.out.println("READ : "+byteArrayOutputStream.size());
System.out.println("READ : "+byteArrayOutputStream.size());
byteArrayOutputStream.close();
byteArrayOutputStream.close();
byte[] bArr = byteArrayOutputStream.toByteArray();*/
byte[] bArr = byteArrayOutputStream.toByteArray();*/
byte[] bArr = new byte[length];
byte[] bArr = new byte[length];
dis.readFully(bArr);
dis.readFully(bArr);
if(inputType.equals("string"))
if(inputType.equals("string"))
{
{
msg = new String(bArr);
msg = new String(bArr);
}
}
else if(inputType.equals("action_icon"))
else if(inputType.equals("action_icon"))
{
{
String[] secondArgSep = secondArg.split("!!");
String[] secondArgSep = secondArg.split("!!");
String profileID = secondArgSep[0];
String profileID = secondArgSep[0];
String actionID = secondArgSep[1];
String actionID = secondArgSep[1];
getClient().getProfileByID(profileID).getActionByID(actionID).setIcon(bArr);
getClient().getProfileByID(profileID).getActionByID(actionID).setIcon(bArr);
//serverListener.clearTemp();
//serverListener.clearTemp();
continue;
continue;
}
}
}
}
catch (IOException e)
catch (IOException e)
{
{
logger.log(Level.SEVERE, e.getMessage());
logger.log(Level.SEVERE, e.getMessage());
e.printStackTrace();
e.printStackTrace();
serverListener.clearTemp();
serverListener.clearTemp();
if(!stop.get())
if(!stop.get())
{
{
removeConnection();
removeConnection();
throw new MinorException("Accidentally disconnected from "+getClient().getNickName()+".");
throw new MinorException("Accidentally disconnected from "+getClient().getNickName()+".");
}
}
exitAndRemove();
exitAndRemove();
return;
return;
}
}
logger.info("Received text : '"+msg+"'");
logger.info("Received text : '"+msg+"'");
String[] sep = msg.split("::");
String[] sep = msg.split("::");
String command = sep[0];
String command = sep[0];
switch (command)
switch (command)
{
{
case "disconnect" : clientDisconnected(msg);
case "disconnect" : clientDisconnected(msg);
break;
break;
case "client_details" : initAfterConnectionQueryReceive(sep);
case "client_details" : initAfterConnectionQueryReceive(sep);
getProfilesFromClient();
getProfilesFromClient();
getThemesFromClient();
getThemesFromClient();
break;
break;
case "profiles" : registerProfilesFromClient(sep);
case "profiles" : registerProfilesFromClient(sep);
break;
break;
case "profile_details" : registerProfileDetailsFromClient(sep);
case "profile_details" : registerProfileDetailsFromClient(sep);
break;
break;
case "action_details" : registerActionToProfile(sep);
case "action_details" : registerActionToProfile(sep);
break;
break;
case "themes": registerThemes(sep);
case "themes": registerThemes(sep);
break;
break;
case "action_clicked": actionClicked(sep[1], sep[2]);
case "action_clicked": actionClicked(sep[1], sep[2]);
break;
break;
default: logger.warning("Command '"+command+"' does not match records. Make sure client and server versions are equal.");
default: logger.warning("Command '"+command+"' does not match records. Make sure client and server versions are equal.");
}
}
}
}
}
}
catch (StreamPiException e)
catch (StreamPiException e)
{
{
e.printStackTrace();
e.printStackTrace();
if(e instanceof MinorException)
if(e instanceof MinorException)
exceptionAndAlertHandler.handleMinorException((MinorException) e);
exceptionAndAlertHandler.handleMinorException((MinorException) e);
else if (e instanceof SevereException)
else if (e instanceof SevereException)
exceptionAndAlertHandler.handleSevereException((SevereException) e);
exceptionAndAlertHandler.handleSevereException((SevereException) e);
}
}
}
}
// commands
// commands
public void initAfterConnectionQuerySend() throws SevereException
public void initAfterConnectionQuerySend() throws SevereException
{
{
logger.info("Asking client details ...");
logger.info("Asking client details ...");
writeToStream("get_client_details::");
writeToStream("get_client_details::");
}
}
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 client disconnect message ...");
logger.info("Sending client disconnect message ...");
writeToStream("disconnect::"+message+"::");
writeToStream("disconnect::"+message+"::");
try
try
{
{
if(!socket.isClosed())
if(!socket.isClosed())
socket.close();
socket.close();
}
}
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 clientDisconnected(String message)
public void clientDisconnected(String message)
{
{
stop.set(true);
stop.set(true);
String txt = "Disconnected!";
String txt = "Disconnected!";
if(!message.equals("disconnect::::"))
if(!message.equals("disconnect::::"))
txt = "Message : "+message.split("::")[1];
txt = "Message : "+message.split("::")[1];
new StreamPiAlert("Disconnected from "+getClient().getNickName()+".", txt, StreamPiAlertType.WARNING).show();;
new StreamPiAlert("Disconnected from "+getClient().getNickName()+".", txt, StreamPiAlertType.WARNING).show();;
exitAndRemove();
exitAndRemove();
}
}
public void getProfilesFromClient() throws StreamPiException
public void getProfilesFromClient() throws StreamPiException
{
{
logger.info("Asking client to send profiles ...");
logger.info("Asking client to send profiles ...");
writeToStream("get_profiles::");
writeToStream("get_profiles::");
}
}
public void getThemesFromClient() throws StreamPiException
public void getThemesFromClient() throws StreamPiException
{
{
logger.info("Asking clients to send themes ...");
logger.info("Asking clients to send themes ...");
writeToStream("get_themes::");
writeToStream("get_themes::");
}
}
public void registerThemes(String[] sep)
public void registerThemes(String[] sep)
{
{
for(int i =1; i<sep.length;i++)
for(int i =1; i<sep.length;i++)
{
{
String[] internal = sep[i].split("__");
String[] internal = sep[i].split("__");
ClientTheme clientTheme = new ClientTheme(
ClientTheme clientTheme = new ClientTheme(
internal[0],
internal[0],
internal[1],
internal[1],
internal[2],
internal[2],
internal[3]
internal[3]
);
);
try
try
{
{
getClient().addTheme(clientTheme);
getClient().addTheme(clientTheme);
}
}
catch (CloneNotSupportedException e)
catch (CloneNotSupportedException e)
{
{
logger.log(Level.SEVERE, e.getMessage());
logger.log(Level.SEVERE, e.getMessage());
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
public void registerProfilesFromClient(String[] sep) throws StreamPiException
public void registerProfilesFromClient(String[] sep) throws StreamPiException
{
{
logger.info("Registering profiles ...");
logger.info("Registering profiles ...");
int noOfProfiles = Integer.parseInt(sep[1]);
int noOfProfiles = Integer.parseInt(sep[1]);
getClient().setTotalNoOfProfiles(noOfProfiles);
getClient().setTotalNoOfProfiles(noOfProfiles);
for(int i = 2; i<(noOfProfiles + 2); i++)
for(int i = 2; i<(noOfProfiles + 2); i++)
{
{
String profileID = sep[i];
String profileID = sep[i];
getProfileDetailsFromClient(profileID);
getProfileDetailsFromClient(profileID);
}
}
}
}
public void getProfileDetailsFromClient(String ID) throws StreamPiException
public void getProfileDetailsFromClient(String ID) throws StreamPiException
{
{
logger.info("Asking client to send details of profile : "+ID);
logger.info("Asking client to send details of profile : "+ID);
writeToStream("get_profile_details::"+ID+"::");
writeToStream("get_profile_details::"+ID+"::");
}
}
public void registerProfileDetailsFromClient(String[] sep)
public void registerProfileDetailsFromClient(String[] sep)
{
{
String ID = sep[1];
String ID = sep[1];
logger.info("Registering details for profile : "+ID);
logger.info("Registering details for profile : "+ID);
String name = sep[2];
String name = sep[2];
int rows = Integer.parseInt(sep[3]);
int rows = Integer.parseInt(sep[3]);
int cols = Integer.parseInt(sep[4]);
int cols = Integer.parseInt(sep[4]);
int actionSize = Integer.parseInt(sep[5]);
int actionSize = Integer.parseInt(sep[5]);
int actionGap = Integer.parseInt(sep[6]);
int actionGap = Integer.parseInt(sep[6]);
ClientProfile clientProfile = new ClientProfile(name, ID, rows, cols, actionSize, actionGap);
ClientProfile clientProfile = new ClientProfile(name, ID, rows, cols, actionSize, actionGap);
logger.info("Added client profile "+clientProfile.getName());
logger.info("Added client profile "+clientProfile.getName());
try
try
{
{
getClient().addProfile(clientProfile);
getClient().addProfile(clientProfile);
}
}
catch (CloneNotSupportedException e)
catch (CloneNotSupportedException e)
{
{
logger.severe(e.getMessage());
logger.severe(e.getMessage());
e.printStackTrace();
e.printStackTrace();
}
}
serverListener.clearTemp();
serverListener.clearTemp();
}
}
/*public void getActionIcon(String profileID, String actionID) throws StreamPiException
/*public void getActionIcon(String profileID, String actionID) throws StreamPiException
{
{
System.out.println("getting action icon from "+profileID+", "+actionID);
System.out.println("getting action icon from "+profileID+", "+actionID);
writeToStream("get_action_icon::"+profileID+"::"+actionID);
writeToStream("get_action_icon::"+profileID+"::"+actionID);
}*/
}*/
public synchronized void registerActionToProfile(String[] sep) throws StreamPiException
public synchronized void registerActionToProfile(String[] sep) throws StreamPiException
{
{
String profileID = sep[1];
String profileID = sep[1];
String ID = sep[2];
String ID = sep[2];
ActionType actionType = ActionType.valueOf(sep[3]);
ActionType actionType = ActionType.valueOf(sep[3]);
//4 - Version
//4 - Version
//5 - ModuleName
//5 - ModuleName
//display
//display
String bgColorHex = sep[6];
String bgColorHex = sep[6];
//icon
//icon
boolean isHasIcon = sep[7].equals("true");
boolean isHasIcon = sep[7].equals("true");
boolean isShowIcon = sep[8].equals("true");
boolean isShowIcon = sep[8].equals("true");
//text
//text
boolean isShowDisplayText = sep[9].equals("true");
boolean isShowDisplayText = sep[9].equals("true");
String displayFontColor = sep[10];
String displayFontColor = sep[10];
String displayText = sep[11];
String displayText = sep[11];
DisplayTextAlignment displayTextAlignment = DisplayTextAlignment.valueOf(sep[12]);
DisplayTextAlignment displayTextAlignment = DisplayTextAlignment.valueOf(sep[12]);
//location
//location
String row = sep[13];
String row = sep[13];
String col = sep[14];
String col = sep[14];
Location location = new Location(Integer.parseInt(row), Integer.parseInt(col));
Location location = new Location(Integer.parseInt(row), Integer.parseInt(col));
Action action = new Action(ID, actionType);
Action action = new Action(ID, actionType);
action.setBgColourHex(bgColorHex);
action.setBgColourHex(bgColorHex);
action.setShowIcon(isShowIcon);
action.setShowIcon(isShowIcon);
action.setHasIcon(isHasIcon);
action.setHasIcon(isHasIcon);
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);
//client properties
//client properties
int clientPropertiesSize = Integer.parseInt(sep[15]);
int clientPropertiesSize = Integer.parseInt(sep[15]);
String root = sep[17];
String root = sep[17];
action.setParent(root);
action.setParent(root);
String[] clientPropertiesRaw = sep[16].split("!!");
String[] clientPropertiesRaw = sep[16].split("!!");
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 = 0;i<clientPropertiesSize; i++)
for(int i = 0;i<clientPropertiesSize; i++)
{
{
String[] clientPraw = clientPropertiesRaw[i].split("__");
String[] clientPraw = clientPropertiesRaw[i].split("__");
Property property = new Property(clientPraw[0], Type.STRING);
Property property = new Property(clientPraw[0], Type.STRING);
if(clientPraw.length > 1)
if(clientPraw.length > 1)
property.setRawValue(clientPraw[1]);
property.setRawValue(clientPraw[1]);
clientProperties.addProperty(property);
clientProperties.addProperty(property);
}
}
action.setClientProperties(clientProperties);
action.setClientProperties(clientProperties);
action.setModuleName(sep[5]);
action.setModuleName(sep[5]);
//set up action
//set up action
//Action toBeAdded = null;
//Action toBeAdded = null;
if(actionType == ActionType.NORMAL)
if(actionType == ActionType.NORMAL)
{
{
NormalAction actionCopy = NormalActionPlugins.getInstance().getPluginByModuleName(sep[5]);
NormalAction actionCopy = NormalActionPlugins.getInstance().getPluginByModuleName(sep[5]);
if(actionCopy == null)
if(actionCopy == null)
{
{
action.setInvalid(true);
action.setInvalid(true);
}
}
else
else
{
{
action.setVersion(new Version(sep[4]));
action.setVersion(new Version(sep[4]));
action.setRepo(actionCopy.getRepo());
//action.setHelpLink(actionCopy.getHelpLink());
if(actionCopy.getVersion().getMajor() != action.getVersion().getMajor())
if(actionCopy.getVersion().getMajor() != action.getVersion().getMajor())
{
{
action.setInvalid(true);
action.setInvalid(true);
}
}
else
else
{
{
action.setName(actionCopy.getName());
action.setName(actionCopy.getName());
ClientProperties finalClientProperties = new ClientProperties();
ClientProperties finalClientProperties = new ClientProperties();
for(Property property : actionCopy.getClientProperties().get())
for(Property property : actionCopy.getClientProperties().get())
{
{
for(int i = 0;i<action.getClientProperties().getSize();i++)
for(int i = 0;i<action.getClientProperties().getSize();i++)
{
{
Property property1 = action.getClientProperties().get().get(i);
Property property1 = action.getClientProperties().get().get(i);
if (property.getName().equals(property1.getName()))
if (property.getName().equals(property1.getName()))
{
{
property.setRawValue(property1.getRawValue());
property.setRawValue(property1.getRawValue());
finalClientProperties.addProperty(property);
finalClientProperties.addProperty(property);
}
}
}
}
}
}
action.setClientProperties(finalClientProperties);
action.setClientProperties(finalClientProperties);
}
}
}
}
}
}
try
try
{
{
for(Property prop : action.getClientProperties().get())
for(Property prop : action.getClientProperties().get())
{
{
logger.info("G@@@@@ : "+prop.getRawValue());
logger.info("G@@@@@ : "+prop.getRawValue());
}
}
getClient().getProfileByID(profileID).addAction(action);
getClient().getProfileByID(profileID).addAction(action);
for(String action1x : getClient().getProfileByID(profileID).getActionsKeySet())
for(String action1x : getClient().getProfileByID(profileID).getActionsKeySet())
{
{
Action action1 = getClient().getProfileByID(profileID).getActionByID(action1x);
Action action1 = getClient().getProfileByID(profileID).getActionByID(action1x);
logger.info("231cc : "+action1.getID());
logger.info("231cc : "+action1.getID());
for(Property prop : action1.getClientProperties().get())
for(Property prop : action1.getClientProperties().get())
{
{
logger.info("G@VVVV@@@ : "+prop.getRawValue());
logger.info("G@VVVV@@@ : "+prop.getRawValue());
}
}
}
}
}
}
catch (CloneNotSupportedException e)
catch (CloneNotSupportedException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException("Action", "Unable to clone"));
exceptionAndAlertHandler.handleMinorException(new MinorException("Action", "Unable to clone"));
}
}
}
}
public void saveActionDetails(String profileID, Action action) throws SevereException
public void saveActionDetails(String profileID, Action action) throws SevereException
{
{
StringBuilder finalQuery = new StringBuilder("save_action_details::");
StringBuilder finalQuery = new StringBuilder("save_action_details::");
//failsafes
//failsafes
if(action.getDisplayText().endsWith(":"))
if(action.getDisplayText().endsWith(":"))
action.setDisplayText(action.getDisplayText()+" ");
action.setDisplayText(action.getDisplayText()+" ");
finalQuery.append(profileID)
finalQuery.append(profileID)
.append("::")
.append("::")
.append(action.getID())
.append(action.getID())
.append("::")
.append("::")
.append(action.getActionType())
.append(action.getActionType())
.append("::");
.append("::");
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
finalQuery.append(action.getVersion().getText());
finalQuery.append(action.getVersion().getText());
System.out.println("VERSION :sdd "+action.getVersion().getText());
System.out.println("VERSION :sdd "+action.getVersion().getText());
}
}
finalQuery.append("::");
finalQuery.append("::");
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
finalQuery.append(action.getModuleName());
finalQuery.append(action.getModuleName());
finalQuery.append("::");
finalQuery.append("::");
//display
//display
finalQuery.append(action.getBgColourHex())
finalQuery.append(action.getBgColourHex())
.append("::");
.append("::");
//icon
//icon
finalQuery.append(action.isHasIcon())
finalQuery.append(action.isHasIcon())
.append("::")
.append("::")
.append(action.isShowIcon())
.append(action.isShowIcon())
.append("::");
.append("::");
//text
//text
finalQuery.append(action.isShowDisplayText())
finalQuery.append(action.isShowDisplayText())
.append("::")
.append("::")
.append(action.getDisplayTextFontColourHex())
.append(action.getDisplayTextFontColourHex())
.append("::")
.append("::")
.append(action.getDisplayText())
.append(action.getDisplayText())
.append("::")
.append("::")
.append(action.getDisplayTextAlignment())
.append(action.getDisplayTextAlignment())
.append("::");
.append("::");
//location
//location
if(action.getLocation() == null)
if(action.getLocation() == null)
finalQuery.append("-1::-1::");
finalQuery.append("-1::-1::");
else
else
finalQuery.append(action.getLocation().getRow())
finalQuery.append(action.getLocation().getRow())
.append("::")
.append("::")
.append(action.getLocation().getCol())
.append(action.getLocation().getCol())
.append("::");
.append("::");
//client properties
//client properties
ClientProperties clientProperties = action.getClientProperties();
ClientProperties clientProperties = action.getClientProperties();
finalQuery.append(clientProperties.getSize())
finalQuery.append(clientProperties.getSize())
.append("::");
.append("::");
for(Property property : clientProperties.get())
for(Property property : clientProperties.get())
{
{
finalQuery.append(property.getName())
finalQuery.append(property.getName())
.append("__")
.append("__")
.append(property.getRawValue())
.append(property.getRawValue())
.append("__");
.append("__");
finalQuery.append("!!");
finalQuery.append("!!");
}
}
finalQuery.append("::")
finalQuery.append("::")
.append(action.getParent())
.append(action.getParent())
.append("::");
.append("::");
writeToStream(finalQuery.toString());
writeToStream(finalQuery.toString());
}
}
public void deleteAction(String profileID, String actionID) throws SevereException
public void deleteAction(String profileID, String actionID) throws SevereException
{
{
writeToStream("delete_action::"+profileID+"::"+actionID);
writeToStream("delete_action::"+profileID+"::"+actionID);
}
}
public void saveClientDetails(String clientNickname, String screenWidth, String screenHeight, String defaultProfileID,
public void saveClientDetails(String clientNickname, String screenWidth, String screenHeight, String defaultProfileID,
String defaultThemeFullName) throws SevereException
String defaultThemeFullName) throws SevereException
{
{
writeToStream("save_client_details::"+
writeToStream("save_client_details::"+
clientNickname+"::"+
clientNickname+"::"+
screenWidth+"::"+
screenWidth+"::"+
screenHeight+"::"+
screenHeight+"::"+
defaultProfileID+"::"+
defaultProfileID+"::"+
defaultThemeFullName+"::");
defaultThemeFullName+"::");
client.setNickName(clientNickname);
client.setNickName(clientNickname);
client.setStartupDisplayWidth(Double.parseDouble(screenWidth));
client.setStartupDisplayWidth(Double.parseDouble(screenWidth));
client.setStartupDisplayHeight(Double.parseDouble(screenHeight));
client.setStartupDisplayHeight(Double.parseDouble(screenHeight));
client.setDefaultProfileID(defaultProfileID);
client.setDefaultProfileID(defaultProfileID);
client.setDefaultThemeFullName(defaultThemeFullName);
client.setDefaultThemeFullName(defaultThemeFullName);
}
}
public void saveProfileDetails(ClientProfile clientProfile) throws SevereException, CloneNotSupportedException {
public void saveProfileDetails(ClientProfile clientProfile) throws SevereException, CloneNotSupportedException {
if(client.getProfileByID(clientProfile.getID()) !=null)
if(client.getProfileByID(clientProfile.getID()) !=null)
{
{
client.getProfileByID(clientProfile.getID()).setName(clientProfile.getName());
client.getProfileByID(clientProfile.getID()).setName(clientProfile.getName());
client.getProfileByID(clientProfile.getID()).setRows(clientProfile.getRows());
client.getProfileByID(clientProfile.getID()).setRows(clientProfile.getRows());
client.getProfileByID(clientProfile.getID()).setCols(clientProfile.getCols());
client.getProfileByID(clientProfile.getID()).setCols(clientProfile.getCols());
client.getProfileByID(clientProfile.getID()).setActionSize(clientProfile.getActionSize());
client.getProfileByID(clientProfile.getID()).setActionSize(clientProfile.getActionSize());
client.getProfileByID(clientProfile.getID()).setActionGap(clientProfile.getActionGap());
client.getProfileByID(clientProfile.getID()).setActionGap(clientProfile.getActionGap());
}
}
else
else
client.addProfile(clientProfile);
client.addProfile(clientProfile);
writeToStream("save_client_profile::"+
writeToStream("save_client_profile::"+
clientProfile.getID()+"::"+
clientProfile.getID()+"::"+
clientProfile.getName()+"::"+
clientProfile.getName()+"::"+
clientProfile.getRows()+"::"+
clientProfile.getRows()+"::"+
clientProfile.getCols()+"::"+
clientProfile.getCols()+"::"+
clientProfile.getActionSize()+"::"+
clientProfile.getActionSize()+"::"+
clientProfile.getActionGap()+"::");
clientProfile.getActionGap()+"::");
}
}
public void deleteProfile(String ID) throws SevereException
public void deleteProfile(String ID) throws SevereException
{
{
writeToStream("delete_profile::"+ID+"::");
writeToStream("delete_profile::"+ID+"::");
}
}
public void actionClicked(String profileID, String actionID) {
public void actionClicked(String profileID, String actionID) {
try
try
{
{
Action action = client.getProfileByID(profileID).getActionByID(actionID);
Action action = client.getProfileByID(profileID).getActionByID(actionID);
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
NormalAction original = NormalActionPlugins.getInstance().getPluginByModuleName(
NormalAction original = NormalActionPlugins.getInstance().getPluginByModuleName(
action.getModuleName()
action.getModuleName()
);
);
if(original == null)
if(original == null)
{
{
throw new MinorException(
throw new MinorException(
"The Action isn't installed on the server."
"The Action isn't installed on the server."
);
);
}
}
NormalAction normalAction = original.clone();
NormalAction normalAction = original.clone();
normalAction.setLocation(action.getLocation());
normalAction.setLocation(action.getLocation());
normalAction.setDisplayText(action.getDisplayText());
normalAction.setDisplayText(action.getDisplayText());
normalAction.setID(actionID);
normalAction.setID(actionID);
normalAction.setClientProperties(action.getClientProperties());
normalAction.setClientProperties(action.getClientProperties());
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
boolean result = serverListener.onNormalActionClicked(normalAction);
boolean result = serverListener.onNormalActionClicked(normalAction);
if(!result)
if(!result)
{
{
sendActionFailed(profileID, actionID);
sendActionFailed(profileID, actionID);
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
}
}
public void sendActionFailed(String profileID, String actionID) throws SevereException {
public void sendActionFailed(String profileID, String actionID) throws SevereException {
logger.info("Sending failed status ...");
logger.info("Sending failed status ...");
writeToStream("action_failed::"+
writeToStream("action_failed::"+
profileID+"::"+
profileID+"::"+
actionID+"::");
actionID+"::");
}
}
}
}
package com.StreamPi.Server.Controller;
package com.StreamPi.Server.Controller;
import com.StreamPi.ActionAPI.Action.ServerConnection;
import com.StreamPi.ActionAPI.Action.ServerConnection;
import com.StreamPi.ActionAPI.Action.PropertySaver;
import com.StreamPi.ActionAPI.Action.PropertySaver;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.Server.Main;
import com.StreamPi.Server.Main;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Connection.ClientConnections;
import com.StreamPi.Server.Connection.ClientConnections;
import com.StreamPi.Server.Connection.MainServer;
import com.StreamPi.Server.Connection.MainServer;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Window.Base;
import com.StreamPi.Server.Window.Base;
import com.StreamPi.Server.Window.Dashboard.DonatePopupContent;
import com.StreamPi.Server.Window.Dashboard.DonatePopupContent;
import com.StreamPi.Server.Window.FirstTimeUse.FirstTimeUse;
import com.StreamPi.Server.Window.FirstTimeUse.FirstTimeUse;
import com.StreamPi.Util.Alert.StreamPiAlert;
import com.StreamPi.Util.Alert.StreamPiAlert;
import com.StreamPi.Util.Alert.StreamPiAlertListener;
import com.StreamPi.Util.Alert.StreamPiAlertListener;
import com.StreamPi.Util.Alert.StreamPiAlertType;
import com.StreamPi.Util.Alert.StreamPiAlertType;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.IOHelper.IOHelper;
import com.StreamPi.Util.IOHelper.IOHelper;
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.concurrent.Task;
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.stage.WindowEvent;
import java.awt.SystemTray;
import java.awt.SystemTray;
import javafx.util.Duration;
import javafx.util.Duration;
import java.awt.Toolkit;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon;
import java.awt.PopupMenu;
import java.awt.PopupMenu;
import java.awt.MenuItem;
import java.awt.MenuItem;
import java.io.File;
import java.io.File;
import java.net.InetAddress;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
import java.util.Random;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Level;
public class Controller extends Base implements PropertySaver, ServerConnection
public class Controller extends Base implements PropertySaver, ServerConnection
{
{
MainServer mainServer;
MainServer mainServer;
final SystemTray systemTray;
final SystemTray systemTray;
public void setupDashWindow() throws SevereException
public void setupDashWindow() throws SevereException
{
{
try
try
{
{
getStage().setTitle("StreamPi Server - "+InetAddress.getLocalHost().getCanonicalHostName()+":"+Config.getInstance().getPort()); //Sets title
getStage().setTitle("Stream-Pi Server - "+InetAddress.getLocalHost().getCanonicalHostName()+":"+Config.getInstance().getPort()); //Sets title
getStage().setOnCloseRequest(this::onCloseRequest);
getStage().setOnCloseRequest(this::onCloseRequest);
}
}
catch (UnknownHostException e)
catch (UnknownHostException e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
private void checkPrePathDirectory() throws SevereException
private void checkPrePathDirectory() throws SevereException
{
{
try {
try {
File filex = new File(ServerInfo.getInstance().getPrePath());
File filex = new File(ServerInfo.getInstance().getPrePath());
System.out.println("SAX : "+filex.exists());
System.out.println("SAX : "+filex.exists());
if(!filex.exists())
if(!filex.exists())
{
{
filex.mkdirs();
filex.mkdirs();
IOHelper.unzip(Main.class.getResourceAsStream("Default.obj"), ServerInfo.getInstance().getPrePath());
IOHelper.unzip(Main.class.getResourceAsStream("Default.obj"), ServerInfo.getInstance().getPrePath());
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
@Override
@Override
public void init()
public void init()
{
{
try {
try {
checkPrePathDirectory();
checkPrePathDirectory();
initBase();
initBase();
setupDashWindow();
setupDashWindow();
setupSettingsWindowsAnimations();
setupSettingsWindowsAnimations();
NormalActionPlugins.getInstance().setPropertySaver(this);
NormalActionPlugins.getInstance().setPropertySaver(this);
NormalActionPlugins.getInstance().setServerConnection(this);
NormalActionPlugins.getInstance().setServerConnection(this);
getDashboardPane().getPluginsPane().getSettingsButton().setOnAction(event -> {
getDashboardPane().getPluginsPane().getSettingsButton().setOnAction(event -> {
openSettingsTimeLine.play();
openSettingsTimeLine.play();
});
});
getSettingsPane().getCloseButton().setOnAction(event -> {
getSettingsPane().getCloseButton().setOnAction(event -> {
closeSettingsTimeLine.play();
closeSettingsTimeLine.play();
});
});
getSettingsPane().getThemesSettings().setController(this);
getSettingsPane().getThemesSettings().setController(this);
mainServer = new MainServer(this, this);
mainServer = new MainServer(this, this);
if(getConfig().isFirstTimeUse())
if(getConfig().isFirstTimeUse())
{
{
Stage stage = new Stage();
Stage stage = new Stage();
Scene s = new Scene(new FirstTimeUse(this, this), 512, 300);
Scene s = new Scene(new FirstTimeUse(this, this), 512, 300);
stage.setResizable(false);
stage.setResizable(false);
stage.setScene(s);
stage.setScene(s);
stage.setTitle("StreamPi Server Setup");
stage.setTitle("Stream-Pi Server Setup");
stage.initModality(Modality.APPLICATION_MODAL);
stage.initModality(Modality.APPLICATION_MODAL);
stage.setOnCloseRequest(event->Platform.exit());
stage.setOnCloseRequest(event->Platform.exit());
stage.show();
stage.show();
}
}
else
else
{
{
if(getConfig().isAllowDonatePopup())
if(getConfig().isAllowDonatePopup())
{
{
if(new Random().nextInt(5) == 3)
if(new Random().nextInt(5) == 3)
new DonatePopupContent(getHostServices(), this).show();
new DonatePopupContent(getHostServices(), this).show();
}
}
othInit();
othInit();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@Override
@Override
public void othInit()
public void othInit()
{
{
try
try
{
{
if(ServerInfo.getInstance().isStartMinimised())
if(ServerInfo.getInstance().isStartMinimised())
minimiseApp();
minimiseApp();
else
else
getStage().show();
getStage().show();
}
}
catch(MinorException e)
catch(MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
getSettingsPane().getGeneralSettings().loadDataFromConfig();
getSettingsPane().getGeneralSettings().loadDataFromConfig();
//themes
//themes
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().loadThemes();
getSettingsPane().getThemesSettings().loadThemes();
//clients
//clients
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getClientsSettings().loadData();
try
try
{
{
//Plugins
//Plugins
Platform.runLater(()->{
Platform.runLater(()->{
getDashboardPane().getPluginsPane().clearData();
getDashboardPane().getPluginsPane().clearData();
getDashboardPane().getPluginsPane().loadOtherActions();
getDashboardPane().getPluginsPane().loadOtherActions();
});
});
NormalActionPlugins.setPluginsLocation(getConfig().getPluginsPath());
NormalActionPlugins.setPluginsLocation(getConfig().getPluginsPath());
NormalActionPlugins.getInstance().init();
NormalActionPlugins.getInstance().init();
Platform.runLater(()->getDashboardPane().getPluginsPane().loadData());
Platform.runLater(()->getDashboardPane().getPluginsPane().loadData());
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getPluginsSettings().loadPlugins();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
getSettingsPane().getPluginsSettings().showPluginInitError();
getSettingsPane().getPluginsSettings().showPluginInitError();
handleMinorException(e);
handleMinorException(e);
}
}
//Server
//Server
mainServer.setPort(getConfig().getPort());
mainServer.setPort(getConfig().getPort());
mainServer.start();
mainServer.start();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
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 KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.1D, Interpolator.EASE_IN),
1.1D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.1D, Interpolator.EASE_IN),
1.1D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.1D, Interpolator.EASE_IN)),
1.1D, 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 KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
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 KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
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),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
0.9D, Interpolator.LINEAR))
0.9D, Interpolator.LINEAR))
);
);
openSettingsTimeLine.setOnFinished(event1 -> {
openSettingsTimeLine.setOnFinished(event1 -> {
settingsNode.toFront();
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 KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
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 KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.1D, Interpolator.LINEAR),
1.1D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.1D, Interpolator.LINEAR),
1.1D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.1D, Interpolator.LINEAR)),
1.1D, 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 KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
0.9D, Interpolator.LINEAR)),
0.9D, 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),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
1.0D, Interpolator.LINEAR))
1.0D, Interpolator.LINEAR))
);
);
closeSettingsTimeLine.setOnFinished(event1 -> {
closeSettingsTimeLine.setOnFinished(event1 -> {
dashboardNode.toFront();
dashboardNode.toFront();
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call() {
protected Void call() {
try {
try {
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getGeneralSettings().loadDataFromConfig();
getSettingsPane().getGeneralSettings().loadDataFromConfig();
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().loadThemes();
getSettingsPane().getThemesSettings().loadThemes();
getSettingsPane().setDefaultTabToGeneral();
getSettingsPane().setDefaultTabToGeneral();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
});
});
}
}
private Timeline openSettingsTimeLine;
private Timeline openSettingsTimeLine;
private Timeline closeSettingsTimeLine;
private Timeline closeSettingsTimeLine;
public Controller(){
public Controller(){
systemTray = SystemTray.getSystemTray();
systemTray = SystemTray.getSystemTray();
mainServer = null;
mainServer = null;
}
}
public void onCloseRequest(WindowEvent event)
public void onCloseRequest(WindowEvent event)
{
{
try
try
{
{
if(Config.getInstance().getCloseOnX())
if(Config.getInstance().getCloseOnX())
{
{
getConfig().setStartupWindowSize(
getConfig().setStartupWindowSize(
getWidth(),
getWidth(),
getHeight()
getHeight()
);
);
getConfig().save();
getConfig().save();
onQuitApp();
onQuitApp();
NormalActionPlugins.getInstance().shutDownActions();
NormalActionPlugins.getInstance().shutDownActions();
Platform.exit();
Platform.exit();
}
}
else
else
{
{
minimiseApp();
minimiseApp();
event.consume();
event.consume();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
finally
finally
{
{
closeLogger();
closeLogger();
}
}
}
}
public void onQuitApp()
public void onQuitApp()
{
{
if(mainServer!=null)
if(mainServer!=null)
mainServer.stopListeningForConnections();
mainServer.stopListeningForConnections();
ClientConnections.getInstance().disconnectAll();
ClientConnections.getInstance().disconnectAll();
getLogger().info("Shutting down ...");
getLogger().info("Shutting down ...");
}
}
public void minimiseApp() throws MinorException
public void minimiseApp() throws MinorException
{
{
try
try
{
{
if(SystemTray.isSupported())
if(SystemTray.isSupported())
{
{
if(getTrayIcon() == null)
if(getTrayIcon() == null)
initIconTray();
initIconTray();
systemTray.add(getTrayIcon());
systemTray.add(getTrayIcon());
//getStage().setIconified(true);
//getStage().setIconified(true);
getStage().hide();
getStage().hide();
}
}
else
else
{
{
new StreamPiAlert("System Tray Error", "Your System does not support System Tray", StreamPiAlertType.ERROR).show();
new StreamPiAlert("System Tray Error", "Your System does not support System Tray", StreamPiAlertType.ERROR).show();
}
}
}
}
catch(Exception e)
catch(Exception e)
{
{
throw new MinorException(e.getMessage());
throw new MinorException(e.getMessage());
}
}
}
}
public void initIconTray()
public void initIconTray()
{
{
Platform.setImplicitExit(false);
Platform.setImplicitExit(false);
PopupMenu popup = new PopupMenu();
PopupMenu popup = new PopupMenu();
MenuItem showItem = new MenuItem("Show");
MenuItem showItem = new MenuItem("Show");
showItem.addActionListener(l->{
showItem.addActionListener(l->{
systemTray.remove(getTrayIcon());
systemTray.remove(getTrayIcon());
Platform.runLater(()->{
Platform.runLater(()->{
//getStage().setIconified(false);
//getStage().setIconified(false);
getStage().show();
getStage().show();
});
});
});
});
MenuItem exitItem = new MenuItem("Exit");
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(l->{
exitItem.addActionListener(l->{
systemTray.remove(getTrayIcon());
systemTray.remove(getTrayIcon());
onQuitApp();
onQuitApp();
Platform.exit();
Platform.exit();
});
});
popup.add(showItem);
popup.add(showItem);
popup.addSeparator();
popup.addSeparator();
popup.add(exitItem);
popup.add(exitItem);
TrayIcon trayIcon = new TrayIcon(
TrayIcon trayIcon = new TrayIcon(
Toolkit.getDefaultToolkit().getImage(Main.class.getResource("app_icon.png")),
Toolkit.getDefaultToolkit().getImage(Main.class.getResource("app_icon.png")),
"StreamPi Server",
"Stream-Pi Server",
popup
popup
);
);
trayIcon.setImageAutoSize(true);
trayIcon.setImageAutoSize(true);
this.trayIcon = trayIcon;
this.trayIcon = trayIcon;
}
}
private TrayIcon trayIcon = null;
private TrayIcon trayIcon = null;
public TrayIcon getTrayIcon()
public TrayIcon getTrayIcon()
{
{
return trayIcon;
return trayIcon;
}
}
@Override
@Override
public void handleMinorException(MinorException e) {
public void handleMinorException(MinorException e) {
getLogger().log(Level.SEVERE, e.getMessage());
getLogger().log(Level.SEVERE, e.getMessage());
e.printStackTrace();
e.printStackTrace();
Platform.runLater(()-> new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show());
Platform.runLater(()-> new StreamPiAlert(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());
getLogger().log(Level.SEVERE, e.getMessage());
e.printStackTrace();
e.printStackTrace();
Platform.runLater(()->{
Platform.runLater(()->{
StreamPiAlert alert = new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert(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)
{
{
onQuitApp();
onQuitApp();
Platform.exit();
Platform.exit();
}
}
});
});
alert.show();
alert.show();
});
});
}
}
@Override
@Override
public synchronized boolean onNormalActionClicked(NormalAction action) {
public synchronized boolean onNormalActionClicked(NormalAction action) {
try{
try{
getLogger().info("Action "+action.getID()+" clicked!");
getLogger().info("Action "+action.getID()+" clicked!");
action.onActionClicked();
action.onActionClicked();
return true;
return true;
}
}
catch (Exception e)
catch (Exception e)
{
{
handleMinorException(new MinorException(
handleMinorException(new MinorException(
"Action Execution Failed!",
"Action Execution Failed!",
"Error running Action at ["+action.getLocation().getRow()+","+action.getLocation().getCol()+"] ("+action.getDisplayText()+")\n"+
"Error running Action at ["+action.getLocation().getRow()+","+action.getLocation().getCol()+"] ("+action.getDisplayText()+")\n"+
"Check stacktrace/log to know what exactly happened\n\nMessage : \n"+e.getMessage() )
"Check stacktrace/log to know what exactly happened\n\nMessage : \n"+e.getMessage() )
);
);
return false;
return false;
}
}
}
}
@Override
@Override
public void clearTemp() {
public void clearTemp() {
Platform.runLater(() -> {
Platform.runLater(() -> {
getDashboardPane().getClientDetailsPane().refresh();
getDashboardPane().getClientDetailsPane().refresh();
getDashboardPane().getActionGridPane().clear();
getDashboardPane().getActionGridPane().clear();
getDashboardPane().getActionDetailsPane().clear();
getDashboardPane().getActionDetailsPane().clear();
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getClientsSettings().loadData();
});
});
}
}
@Override
@Override
public void saveServerProperties() {
public void saveServerProperties() {
try {
try {
NormalActionPlugins.getInstance().saveServerSettings();
NormalActionPlugins.getInstance().saveServerSettings();
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getPluginsSettings().loadPlugins();
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
handleMinorException(e);
handleMinorException(e);
}
}
}
}
@Override
@Override
public com.StreamPi.Util.Platform.Platform getPlatform() {
public com.StreamPi.Util.Platform.Platform getPlatform() {
return ServerInfo.getInstance().getPlatformType();
return ServerInfo.getInstance().getPlatformType();
}
}
}
}
package com.StreamPi.Server.Info;
package com.StreamPi.Server.Info;
public class License {
public class License {
public static String getLicense()
public static String getLicense()
{
{
return "StreamPi - Free & Opensource Modular Cross-Platform Programmable Macropad\n" +
return "Stream-Pi - Free & Opensource Modular Cross-Platform Programmable Macropad\n" +
"Copyright (C) 2020 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)\n" +
"Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)\n" +
"\n" +
"\n" +
"This program is free software: you can redistribute it and/or modify\n" +
"This program is free software: you can redistribute it and/or modify\n" +
"it under the terms of the GNU General Public License as published by\n" +
"it under the terms of the GNU General Public License as published by\n" +
"the Free Software Foundation, either version 3 of the License, or\n" +
"the Free Software Foundation, either version 3 of the License, or\n" +
"(at your option) any later version.\n" +
"(at your option) any later version.\n" +
"\n" +
"\n" +
"This program is distributed in the hope that it will be useful,\n" +
"This program is distributed in the hope that it will be useful,\n" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" +
"GNU General Public License for more details.\n" +
"GNU General Public License for more details.\n" +
"\n\n"+
"\n\n"+
"Opensource Libraries used :\n"+
"Opensource Libraries used :\n"+
"1. JavaFX - GNU General Public License with Classpath Exception\nhttp://openjdk.java.net/legal/gplv2+ce.html\n\n"+
"1. JavaFX - GNU General Public License with Classpath Exception\nhttp://openjdk.java.net/legal/gplv2+ce.html\n\n"+
"2. JSON - The JSON License\nhttps://www.json.org/license.html\n\n"+
"2. JSON - The JSON License\nhttps://www.json.org/license.html\n\n"+
"3. Ikonli - Apache License\nhttps://github.com/kordamp/ikonli/blob/master/LICENSE\n\n";
"3. Ikonli - Apache License\nhttps://github.com/kordamp/ikonli/blob/master/LICENSE\n\n";
}
}
}
}
package com.StreamPi.Server.Window.Dashboard;
package com.StreamPi.Server.Window.Dashboard;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.Action.ActionType;
import com.StreamPi.ActionAPI.Action.ActionType;
import com.StreamPi.ActionAPI.Action.DisplayTextAlignment;
import com.StreamPi.ActionAPI.Action.DisplayTextAlignment;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.OtherActions.CombineAction;
import com.StreamPi.ActionAPI.OtherActions.CombineAction;
import com.StreamPi.ActionAPI.OtherActions.FolderAction;
import com.StreamPi.ActionAPI.OtherActions.FolderAction;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Action.NormalActionPlugins;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.event.EventHandler;
import javafx.event.EventHandler;
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.Node;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import javafx.scene.paint.Paint;
import javafx.scene.paint.Paint;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
public class PluginsPane extends VBox {
public class PluginsPane extends VBox {
private Button settingsButton;
private Button settingsButton;
public PluginsPane(HostServices hostServices)
public PluginsPane(HostServices hostServices)
{
{
setMinWidth(250);
setMinWidth(250);
getStyleClass().add("plugins_pane");
getStyleClass().add("plugins_pane");
setPadding(new Insets(10));
setPadding(new Insets(10));
setSpacing(10.0);
setSpacing(10.0);
this.hostServices = hostServices;
this.hostServices = hostServices;
initUI();
initUI();
}
}
private Accordion pluginsAccordion;
private Accordion pluginsAccordion;
public void initUI()
public void initUI()
{
{
pluginsAccordion = new Accordion();
pluginsAccordion = new Accordion();
pluginsAccordion.setCache(true);
pluginsAccordion.setCache(true);
Region r = new Region();
Region r = new Region();
VBox.setVgrow(r, Priority.ALWAYS);
VBox.setVgrow(r, Priority.ALWAYS);
settingsButton = new Button();
settingsButton = new Button();
FontIcon cog = new FontIcon("fas-cog");
FontIcon cog = new FontIcon("fas-cog");
settingsButton.setGraphic(cog);
settingsButton.setGraphic(cog);
HBox settingsHBox = new HBox(settingsButton);
HBox settingsHBox = new HBox(settingsButton);
settingsHBox.setAlignment(Pos.CENTER_RIGHT);
settingsHBox.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(new Label("Plugins"), pluginsAccordion, r, settingsHBox);
getChildren().addAll(new Label("Plugins"), pluginsAccordion, r, settingsHBox);
}
}
public Button getSettingsButton()
public Button getSettingsButton()
{
{
return settingsButton;
return settingsButton;
}
}
public void clearData()
public void clearData()
{
{
pluginsAccordion.getPanes().clear();
pluginsAccordion.getPanes().clear();
}
}
public void loadData()
public void loadData()
{
{
HashMap<String, ArrayList<NormalAction>> sortedPlugins = NormalActionPlugins.getInstance().getSortedPlugins();
HashMap<String, ArrayList<NormalAction>> sortedPlugins = NormalActionPlugins.getInstance().getSortedPlugins();
for(String eachCategory : sortedPlugins.keySet())
for(String eachCategory : sortedPlugins.keySet())
{
{
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.setSpacing(5);
vBox.setSpacing(5);
TitledPane pane = new TitledPane(eachCategory, vBox);
TitledPane pane = new TitledPane(eachCategory, vBox);
for(NormalAction eachAction : sortedPlugins.get(eachCategory))
for(NormalAction eachAction : sortedPlugins.get(eachCategory))
{
{
if(!eachAction.isVisibleInPluginsPane())
if(!eachAction.isVisibleInPluginsPane())
continue;
continue;
Button eachNormalActionPluginButton = new Button();
Button eachNormalActionPluginButton = new Button();
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
eachNormalActionPluginButton.setMaxWidth(Double.MAX_VALUE);
eachNormalActionPluginButton.setMaxWidth(Double.MAX_VALUE);
eachNormalActionPluginButton.setAlignment(Pos.CENTER_LEFT);
eachNormalActionPluginButton.setAlignment(Pos.CENTER_LEFT);
Node graphic = eachAction.getServerButtonGraphic();
Node graphic = eachAction.getServerButtonGraphic();
if(graphic == null)
if(graphic == null)
{
{
FontIcon cogs = new FontIcon("fas-cogs");
FontIcon cogs = new FontIcon("fas-cogs");
cogs.getStyleClass().add("dashboard_plugins_pane_action_icon");
cogs.getStyleClass().add("dashboard_plugins_pane_action_icon");
eachNormalActionPluginButton.setGraphic(cogs);
eachNormalActionPluginButton.setGraphic(cogs);
}
}
else
else
{
{
if(graphic instanceof FontIcon)
if(graphic instanceof FontIcon)
{
{
FontIcon fi = (FontIcon) graphic;
FontIcon fi = (FontIcon) graphic;
eachNormalActionPluginButton.setGraphic(fi);
eachNormalActionPluginButton.setGraphic(fi);
}
}
else if(graphic instanceof ImageView)
else if(graphic instanceof ImageView)
{
{
ImageView iv = (ImageView) graphic;
ImageView iv = (ImageView) graphic;
iv.getStyleClass().add("dashboard_plugins_pane_action_icon_imageview");
iv.getStyleClass().add("dashboard_plugins_pane_action_icon_imageview");
iv.setPreserveRatio(false);
iv.setPreserveRatio(false);
eachNormalActionPluginButton.setGraphic(iv);
eachNormalActionPluginButton.setGraphic(iv);
}
}
}
}
eachNormalActionPluginButton.setText(eachAction.getName());
eachNormalActionPluginButton.setText(eachAction.getName());
eachNormalActionPluginButton.setOnDragDetected(mouseEvent -> {
eachNormalActionPluginButton.setOnDragDetected(mouseEvent -> {
Dragboard db = eachNormalActionPluginButton.startDragAndDrop(TransferMode.ANY);
Dragboard db = eachNormalActionPluginButton.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(Action.getDataFormat(), createFakeAction(eachAction, "Untitled Action"));
content.put(Action.getDataFormat(), createFakeAction(eachAction, "Untitled Action"));
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
});
});
HBox hBox = new HBox(eachNormalActionPluginButton);
HBox hBox = new HBox(eachNormalActionPluginButton);
hBox.setSpacing(5.0);
hBox.setSpacing(5.0);
hBox.setAlignment(Pos.TOP_LEFT);
hBox.setAlignment(Pos.TOP_LEFT);
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
if(eachAction.getRepo() != null) {
if(eachAction.getHelpLink() != null) {
Button helpButton = new Button();
Button helpButton = new Button();
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
questionIcon.getStyleClass().add("dashboard_plugins_pane_action_help_icon");
questionIcon.getStyleClass().add("dashboard_plugins_pane_action_help_icon");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> hostServices.showDocument(eachAction.getHelpLink()));
helpButton.setOnAction(event -> {
hostServices.showDocument(eachAction.getRepo());
});
hBox.getChildren().add(helpButton);
hBox.getChildren().add(helpButton);
}
}
vBox.getChildren().add(hBox);
vBox.getChildren().add(hBox);
}
}
if(vBox.getChildren().size() > 0)
if(vBox.getChildren().size() > 0)
pluginsAccordion.getPanes().add(pane);
pluginsAccordion.getPanes().add(pane);
}
}
}
}
private HostServices hostServices;
private HostServices hostServices;
public Action createFakeAction(Action action, String displayText)
public Action createFakeAction(Action action, String displayText)
{
{
Action newAction = new Action(action.getActionType());
Action newAction = new Action(action.getActionType());
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
newAction.setModuleName(action.getModuleName());
newAction.setModuleName(action.getModuleName());
newAction.setVersion(action.getVersion());
newAction.setVersion(action.getVersion());
newAction.setName(action.getName());
newAction.setName(action.getName());
}
}
newAction.setClientProperties(action.getClientProperties());
newAction.setClientProperties(action.getClientProperties());
for(Property property : newAction.getClientProperties().get())
for(Property property : newAction.getClientProperties().get())
{
{
if(property.getType() == Type.STRING || property.getType() == Type.INTEGER || property.getType() == Type.DOUBLE)
if(property.getType() == Type.STRING || property.getType() == Type.INTEGER || property.getType() == Type.DOUBLE)
property.setRawValue(property.getDefaultRawValue());
property.setRawValue(property.getDefaultRawValue());
}
}
// newAction.setLocation(location);
// newAction.setLocation(location);
newAction.setIDRandom();
newAction.setIDRandom();
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayText(displayText);
newAction.setDisplayText(displayText);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setShowIcon(false);
newAction.setShowIcon(false);
newAction.setHasIcon(false);
newAction.setHasIcon(false);
//action.setParent(root);
//action.setParent(root);
newAction.setBgColourHex("");
newAction.setBgColourHex("");
newAction.setDisplayTextFontColourHex("");
newAction.setDisplayTextFontColourHex("");
return newAction;
return newAction;
}
}
public void loadOtherActions()
public void loadOtherActions()
{
{
VBox vBox = new VBox();
VBox vBox = new VBox();
Button folderActionButton = new Button("Folder");
Button folderActionButton = new Button("Folder");
folderActionButton.setMaxWidth(Double.MAX_VALUE);
folderActionButton.setMaxWidth(Double.MAX_VALUE);
folderActionButton.setAlignment(Pos.CENTER_LEFT);
folderActionButton.setAlignment(Pos.CENTER_LEFT);
FontIcon folder = new FontIcon("fas-folder");
FontIcon folder = new FontIcon("fas-folder");
folderActionButton.setGraphic(folder);
folderActionButton.setGraphic(folder);
folderActionButton.setOnDragDetected(mouseEvent -> {
folderActionButton.setOnDragDetected(mouseEvent -> {
Dragboard db = folderActionButton.startDragAndDrop(TransferMode.ANY);
Dragboard db = folderActionButton.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(Action.getDataFormat(), createFakeAction(new FolderAction(), "Untitled Folder"));
content.put(Action.getDataFormat(), createFakeAction(new FolderAction(), "Untitled Folder"));
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
});
});
Button combineActionButton = new Button("Combine");
Button combineActionButton = new Button("Combine");
combineActionButton.setMaxWidth(Double.MAX_VALUE);
combineActionButton.setMaxWidth(Double.MAX_VALUE);
combineActionButton.setAlignment(Pos.CENTER_LEFT);
combineActionButton.setAlignment(Pos.CENTER_LEFT);
FontIcon list = new FontIcon("fas-list");
FontIcon list = new FontIcon("fas-list");
combineActionButton.setGraphic(list);
combineActionButton.setGraphic(list);
combineActionButton.setOnDragDetected(mouseEvent -> {
combineActionButton.setOnDragDetected(mouseEvent -> {
Dragboard db = combineActionButton.startDragAndDrop(TransferMode.ANY);
Dragboard db = combineActionButton.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(Action.getDataFormat(), createFakeAction(new CombineAction(), "Untitled Combine"));
content.put(Action.getDataFormat(), createFakeAction(new CombineAction(), "Untitled Combine"));
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
});
});
vBox.getChildren().addAll(folderActionButton, combineActionButton);
vBox.getChildren().addAll(folderActionButton, combineActionButton);
vBox.setSpacing(5);
vBox.setSpacing(5);
TitledPane pane = new TitledPane("StreamPi", vBox);
TitledPane pane = new TitledPane("StreamPi", vBox);
pluginsAccordion.getPanes().add(pane);
pluginsAccordion.getPanes().add(pane);
pluginsAccordion.setCache(true);
pluginsAccordion.setCache(true);
pluginsAccordion.setCacheHint(CacheHint.SPEED);
pluginsAccordion.setCacheHint(CacheHint.SPEED);
}
}
}
}
package com.StreamPi.Server.Window.Settings;
package com.StreamPi.Server.Window.Settings;
import com.StreamPi.Server.UIPropertyBox.UIPropertyBox;
import com.StreamPi.Server.UIPropertyBox.UIPropertyBox;
import com.StreamPi.ActionAPI.ActionProperty.Property.ControlType;
import com.StreamPi.ActionAPI.ActionProperty.Property.ControlType;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.ActionProperty.Property.Type;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Node;
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.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class PluginsSettings extends VBox {
public class PluginsSettings extends VBox {
private VBox pluginsSettingsVBox;
private VBox pluginsSettingsVBox;
private ServerListener serverListener;
private ServerListener serverListener;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private HostServices hostServices;
private HostServices hostServices;
public PluginsSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
public PluginsSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
{
{
getStyleClass().add("plugins_settings");
getStyleClass().add("plugins_settings");
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
pluginProperties = new ArrayList<>();
pluginProperties = new ArrayList<>();
logger = Logger.getLogger(PluginsSettings.class.getName());
logger = Logger.getLogger(PluginsSettings.class.getName());
setPadding(new Insets(10));
setPadding(new Insets(10));
pluginsSettingsVBox = new VBox();
pluginsSettingsVBox = new VBox();
pluginsSettingsVBox.setSpacing(10.0);
pluginsSettingsVBox.setSpacing(10.0);
pluginsSettingsVBox.setAlignment(Pos.TOP_CENTER);
pluginsSettingsVBox.setAlignment(Pos.TOP_CENTER);
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("plugins_settings_scroll_pane");
scrollPane.getStyleClass().add("plugins_settings_scroll_pane");
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
pluginsSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
pluginsSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
scrollPane.setContent(pluginsSettingsVBox);
scrollPane.setContent(pluginsSettingsVBox);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event -> onSaveButtonClicked());
saveButton.setOnAction(event -> onSaveButtonClicked());
HBox hBox = new HBox(saveButton);
HBox hBox = new HBox(saveButton);
hBox.setAlignment(Pos.CENTER_RIGHT);
hBox.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(scrollPane, hBox);
getChildren().addAll(scrollPane, hBox);
}
}
private Button saveButton;
private Button saveButton;
public void onSaveButtonClicked()
public void onSaveButtonClicked()
{
{
try {
try {
//form validation
//form validation
StringBuilder finalErrors = new StringBuilder();
StringBuilder finalErrors = new StringBuilder();
for (PluginProperties p : pluginProperties)
for (PluginProperties p : pluginProperties)
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(int j = 0; j < p.getServerPropertyUIBox().size(); j++)
for(int j = 0; j < p.getServerPropertyUIBox().size(); j++)
{
{
UIPropertyBox serverProperty = p.getServerPropertyUIBox().get(j);
UIPropertyBox serverProperty = p.getServerPropertyUIBox().get(j);
Node controlNode = serverProperty.getControlNode();
Node controlNode = serverProperty.getControlNode();
if (serverProperty.getControlType() == ControlType.TEXT_FIELD)
if (serverProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
String value = ((TextField) controlNode).getText();
String value = ((TextField) controlNode).getText();
if(serverProperty.getType() == Type.INTEGER)
if(serverProperty.getType() == Type.INTEGER)
{
{
try
try
{
{
Integer.parseInt(value);
Integer.parseInt(value);
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" must be integer.\n");
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" must be integer.\n");
}
}
}
}
else
else
{
{
if(value.isBlank() && !serverProperty.isCanBeBlank())
if(value.isBlank() && !serverProperty.isCanBeBlank())
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" cannot be blank.\n");
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" cannot be blank.\n");
}
}
}
}
}
}
if(!errors.toString().isBlank())
if(!errors.toString().isBlank())
{
{
finalErrors.append(" * ").append(p.getName()).append("\n").append(errors.toString()).append("\n");
finalErrors.append(" * ").append(p.getName()).append("\n").append(errors.toString()).append("\n");
}
}
}
}
if(!finalErrors.toString().isEmpty())
if(!finalErrors.toString().isEmpty())
{
{
throw new MinorException("Form Validation Errors",
throw new MinorException("Form Validation Errors",
"Please rectify the following errors and try again \n"+finalErrors.toString());
"Please rectify the following errors and try again \n"+finalErrors.toString());
}
}
//save
//save
for (PluginProperties pp : pluginProperties) {
for (PluginProperties pp : pluginProperties) {
for (int j = 0; j < pp.getServerPropertyUIBox().size(); j++) {
for (int j = 0; j < pp.getServerPropertyUIBox().size(); j++) {
UIPropertyBox serverProperty = pp.getServerPropertyUIBox().get(j);
UIPropertyBox serverProperty = pp.getServerPropertyUIBox().get(j);
String rawValue = serverProperty.getRawValue();
String rawValue = serverProperty.getRawValue();
NormalActionPlugins.getInstance().getActionFromIndex(pp.getIndex())
NormalActionPlugins.getInstance().getActionFromIndex(pp.getIndex())
.getServerProperties().get()
.getServerProperties().get()
.get(serverProperty.getIndex()).setRawValue(rawValue);
.get(serverProperty.getIndex()).setRawValue(rawValue);
}
}
}
}
NormalActionPlugins.getInstance().saveServerSettings();
NormalActionPlugins.getInstance().saveServerSettings();
NormalActionPlugins.getInstance().initPlugins();
NormalActionPlugins.getInstance().initPlugins();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
private ArrayList<PluginProperties> pluginProperties;
private ArrayList<PluginProperties> pluginProperties;
public void showPluginInitError()
public void showPluginInitError()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
pluginsSettingsVBox.getChildren().add(new Label("Plugin init error. Resolve issues and restart."));
pluginsSettingsVBox.getChildren().add(new Label("Plugin init error. Resolve issues and restart."));
saveButton.setVisible(false);
saveButton.setVisible(false);
});
});
}
}
public void loadPlugins() throws MinorException {
public void loadPlugins() throws MinorException {
pluginProperties.clear();
pluginProperties.clear();
List<NormalAction> actions = NormalActionPlugins.getInstance().getPlugins();
List<NormalAction> actions = NormalActionPlugins.getInstance().getPlugins();
System.out.println("asdasdasdasd"+actions.size());
System.out.println("asdasdasdasd"+actions.size());
Platform.runLater(()-> pluginsSettingsVBox.getChildren().clear());
Platform.runLater(()-> pluginsSettingsVBox.getChildren().clear());
if(actions.size() == 0)
if(actions.size() == 0)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
pluginsSettingsVBox.getChildren().add(new Label("No Plugins Installed."));
pluginsSettingsVBox.getChildren().add(new Label("No Plugins Installed."));
saveButton.setVisible(false);
saveButton.setVisible(false);
});
});
return;
return;
}
}
else
else
{
{
Platform.runLater(()->saveButton.setVisible(true));
Platform.runLater(()->saveButton.setVisible(true));
}
}
for(int i = 0; i<actions.size(); i++)
for(int i = 0; i<actions.size(); i++)
{
{
NormalAction action = actions.get(i);
NormalAction action = actions.get(i);
if(!action.isVisibleInServerSettingsPane())
if(!action.isVisibleInServerSettingsPane())
continue;
continue;
Label headingLabel = new Label(action.getName());
Label headingLabel = new Label(action.getName());
headingLabel.getStyleClass().add("settings_plugins_each_action_heading");
headingLabel.getStyleClass().add("settings_plugins_each_action_heading");
HBox headerHBox = new HBox(headingLabel, new SpaceFiller(FillerType.HBox));
HBox headerHBox = new HBox(headingLabel);
if (action.getRepo()!=null)
if (action.getHelpLink()!=null)
{
{
Button helpButton = new Button();
Button helpButton = new Button();
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
questionIcon.getStyleClass().add("dashboard_plugins_pane_action_help_icon");
questionIcon.getStyleClass().add("settings_plugins_plugin_help_icon");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> hostServices.showDocument(action.getHelpLink()));
headerHBox.getChildren().addAll(new SpaceFiller(FillerType.HBox),helpButton);
helpButton.setOnAction(event -> {
hostServices.showDocument(action.getRepo());
});
headerHBox.getChildren().add(helpButton);
}
}
Label authorLabel = new Label(action.getAuthor());
Label authorLabel = new Label(action.getAuthor());
Label moduleLabel = new Label(action.getModuleName());
Label moduleLabel = new Label(action.getModuleName());
Label versionLabel = new Label("Version : "+action.getVersion().getText());
Label versionLabel = new Label("Version : "+action.getVersion().getText());
VBox serverPropertiesVBox = new VBox();
VBox serverPropertiesVBox = new VBox();
serverPropertiesVBox.setSpacing(10.0);
serverPropertiesVBox.setSpacing(10.0);
List<Property> serverProperties = action.getServerProperties().get();
List<Property> serverProperties = action.getServerProperties().get();
ArrayList<UIPropertyBox> serverPropertyArrayList = new ArrayList<>();
ArrayList<UIPropertyBox> serverPropertyArrayList = new ArrayList<>();
for(int j =0; j<serverProperties.size(); j++)
for(int j =0; j<serverProperties.size(); j++)
{
{
Property eachProperty = serverProperties.get(j);
Property eachProperty = serverProperties.get(j);
if(!eachProperty.isVisible())
if(!eachProperty.isVisible())
continue;
continue;
Label label = new Label(eachProperty.getDisplayName());
Label label = new Label(eachProperty.getDisplayName());
Region region = new Region();
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HBox.setHgrow(region, Priority.ALWAYS);
HBox hBox = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox));
HBox hBox = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox));
//hBox.setId(j+"");
//hBox.setId(j+"");
Node controlNode = null;
Node controlNode = null;
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
{
{
ComboBox<String> comboBox = new ComboBox<>();
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
hBox.getChildren().add(comboBox);
hBox.getChildren().add(comboBox);
controlNode = comboBox;
controlNode = comboBox;
}
}
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
TextField textField = new TextField(eachProperty.getRawValue());
TextField textField = new TextField(eachProperty.getRawValue());
hBox.getChildren().add(textField);
hBox.getChildren().add(textField);
controlNode = textField;
controlNode = textField;
}
}
else if(eachProperty.getControlType() == ControlType.TOGGLE)
else if(eachProperty.getControlType() == ControlType.TOGGLE)
{
{
ToggleButton toggleButton = new ToggleButton();
ToggleButton toggleButton = new ToggleButton();
toggleButton.setSelected(eachProperty.getBoolValue());
toggleButton.setSelected(eachProperty.getBoolValue());
if(eachProperty.getBoolValue())
if(eachProperty.getBoolValue())
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
if(t1)
if(t1)
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
});
});
hBox.getChildren().add(toggleButton);
hBox.getChildren().add(toggleButton);
controlNode = toggleButton;
controlNode = toggleButton;
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getDoubleValue());
slider.setValue(eachProperty.getDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
hBox.getChildren().add(slider);
hBox.getChildren().add(slider);
controlNode = slider;
controlNode = slider;
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getIntValue());
slider.setValue(eachProperty.getIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setBlockIncrement(1.0);
slider.setBlockIncrement(1.0);
slider.setSnapToTicks(true);
slider.setSnapToTicks(true);
hBox.getChildren().add(slider);
hBox.getChildren().add(slider);
controlNode = slider;
controlNode = slider;
}
}
UIPropertyBox serverProperty = new UIPropertyBox(j, eachProperty.getDisplayName(), controlNode, eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
UIPropertyBox serverProperty = new UIPropertyBox(j, eachProperty.getDisplayName(), controlNode, eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
serverPropertyArrayList.add(serverProperty);
serverPropertyArrayList.add(serverProperty);
serverPropertiesVBox.getChildren().add(hBox);
serverPropertiesVBox.getChildren().add(hBox);
}
}
PluginProperties pp = new PluginProperties(i, serverPropertyArrayList, action.getName());
PluginProperties pp = new PluginProperties(i, serverPropertyArrayList, action.getName());
pluginProperties.add(pp);
pluginProperties.add(pp);
Region region1 = new Region();
Region region1 = new Region();
region1.setPrefHeight(5);
region1.setPrefHeight(5);
Platform.runLater(()->{
Platform.runLater(()->{
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.setSpacing(5.0);
vBox.setSpacing(5.0);
vBox.getChildren().addAll(headerHBox, authorLabel, moduleLabel, versionLabel, serverPropertiesVBox);
vBox.getChildren().addAll(headerHBox, authorLabel, moduleLabel, versionLabel, serverPropertiesVBox);
if(action.getButtonBar()!=null)
if(action.getButtonBar()!=null)
vBox.getChildren().add(new HBox(new SpaceFiller(SpaceFiller.FillerType.HBox), action.getButtonBar()));
vBox.getChildren().add(new HBox(new SpaceFiller(SpaceFiller.FillerType.HBox), action.getButtonBar()));
vBox.getChildren().add(region1);
vBox.getChildren().add(region1);
//vBox.setId(i+"");
//vBox.setId(i+"");
vBox.getStyleClass().add("settings_plugins_each_action");
vBox.getStyleClass().add("settings_plugins_each_action");
pluginsSettingsVBox.getChildren().add(vBox);
pluginsSettingsVBox.getChildren().add(vBox);
});
});
}
}
}
}
public class PluginProperties
public class PluginProperties
{
{
private int index;
private int index;
private ArrayList<UIPropertyBox> serverProperty;
private ArrayList<UIPropertyBox> serverProperty;
private String name;
private String name;
public PluginProperties(int index, ArrayList<UIPropertyBox> serverProperty, String name)
public PluginProperties(int index, ArrayList<UIPropertyBox> serverProperty, String name)
{
{
this.index = index;
this.index = index;
this.serverProperty = serverProperty;
this.serverProperty = serverProperty;
this.name = name;
this.name = name;
}
}
public String getName()
public String getName()
{
{
return name;
return name;
}
}
public int getIndex() {
public int getIndex() {
return index;
return index;
}
}
public ArrayList<UIPropertyBox> getServerPropertyUIBox() {
public ArrayList<UIPropertyBox> getServerPropertyUIBox() {
return serverProperty;
return serverProperty;
}
}
}
}
}
}
package com.StreamPi.Server.Window.Settings;
package com.StreamPi.Server.Window.Settings;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.ThemeAPI.Theme;
import com.StreamPi.ThemeAPI.Theme;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class SettingsBase extends VBox {
public class SettingsBase extends VBox {
private TabPane tabPane;
private TabPane tabPane;
private GeneralSettings generalSettings;
private GeneralSettings generalSettings;
private PluginsSettings pluginsSettings;
private PluginsSettings pluginsSettings;
private ThemesSettings themesSettings;
private ThemesSettings themesSettings;
private ClientsSettings clientsSettings;
private ClientsSettings clientsSettings;
private Button closeButton;
private Button closeButton;
private HostServices hostServices;
private HostServices hostServices;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public SettingsBase(HostServices hostServices, ExceptionAndAlertHandler exceptionAndAlertHandler,
public SettingsBase(HostServices hostServices, ExceptionAndAlertHandler exceptionAndAlertHandler,
ServerListener serverListener)
ServerListener serverListener)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.hostServices = hostServices;
this.hostServices = hostServices;
tabPane = new TabPane();
tabPane = new TabPane();
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
tabPane.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);
VBox.setVgrow(tabPane, Priority.ALWAYS);
VBox.setVgrow(tabPane, Priority.ALWAYS);
Tab generalSettingsTab = new Tab("General");
Tab generalSettingsTab = new Tab("General");
generalSettings = new GeneralSettings(exceptionAndAlertHandler, serverListener, hostServices);
generalSettings = new GeneralSettings(exceptionAndAlertHandler, serverListener, hostServices);
generalSettingsTab.setContent(generalSettings);
generalSettingsTab.setContent(generalSettings);
Tab pluginsSettingsTab = new Tab("Plugins");
Tab pluginsSettingsTab = new Tab("Plugins");
pluginsSettings = new PluginsSettings(exceptionAndAlertHandler, hostServices);
pluginsSettings = new PluginsSettings(exceptionAndAlertHandler, hostServices);
pluginsSettingsTab.setContent(pluginsSettings);
pluginsSettingsTab.setContent(pluginsSettings);
Tab themesSettingsTab = new Tab("Themes");
Tab themesSettingsTab = new Tab("Themes");
themesSettings = new ThemesSettings();
themesSettings = new ThemesSettings(hostServices);
themesSettingsTab.setContent(themesSettings);
themesSettingsTab.setContent(themesSettings);
Tab clientsSettingsTab = new Tab("Clients");
Tab clientsSettingsTab = new Tab("Clients");
clientsSettings = new ClientsSettings(exceptionAndAlertHandler, serverListener);
clientsSettings = new ClientsSettings(exceptionAndAlertHandler, serverListener);
clientsSettingsTab.setContent(clientsSettings);
clientsSettingsTab.setContent(clientsSettings);
Tab aboutTab = new Tab("About");
Tab aboutTab = new Tab("About");
aboutTab.setContent(new About(hostServices));
aboutTab.setContent(new About(hostServices));
tabPane.getTabs().addAll(generalSettingsTab, pluginsSettingsTab, themesSettingsTab, clientsSettingsTab, aboutTab);
tabPane.getTabs().addAll(generalSettingsTab, pluginsSettingsTab, themesSettingsTab, clientsSettingsTab, aboutTab);
setAlignment(Pos.TOP_RIGHT);
setAlignment(Pos.TOP_RIGHT);
closeButton = new Button("Close");
closeButton = new Button("Close");
VBox.setMargin(closeButton, new Insets(10.0));
VBox.setMargin(closeButton, new Insets(10.0));
getChildren().addAll(tabPane, closeButton);
getChildren().addAll(tabPane, closeButton);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
public void setDefaultTabToGeneral()
public void setDefaultTabToGeneral()
{
{
tabPane.getSelectionModel().selectFirst();
tabPane.getSelectionModel().selectFirst();
}
}
public Button getCloseButton()
public Button getCloseButton()
{
{
return closeButton;
return closeButton;
}
}
public GeneralSettings getGeneralSettings()
public GeneralSettings getGeneralSettings()
{
{
return generalSettings;
return generalSettings;
}
}
public PluginsSettings getPluginsSettings()
public PluginsSettings getPluginsSettings()
{
{
return pluginsSettings;
return pluginsSettings;
}
}
public ThemesSettings getThemesSettings()
public ThemesSettings getThemesSettings()
{
{
return themesSettings;
return themesSettings;
}
}
public ClientsSettings getClientsSettings()
public ClientsSettings getClientsSettings()
{
{
return clientsSettings;
return clientsSettings;
}
}
}
}
package com.StreamPi.Server.Window.Settings;
package com.StreamPi.Server.Window.Settings;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.Action.Action;
import com.StreamPi.ActionAPI.ActionProperty.Property.ControlType;
import com.StreamPi.ActionAPI.ActionProperty.Property.ControlType;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.ActionProperty.Property.Property;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.ActionAPI.NormalAction.NormalAction;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Action.NormalActionPlugins;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Controller.Controller;
import com.StreamPi.Server.Controller.Controller;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.ThemeAPI.Theme;
import com.StreamPi.ThemeAPI.Theme;
import com.StreamPi.ThemeAPI.Themes;
import com.StreamPi.ThemeAPI.Themes;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ThemesSettings extends VBox
public class ThemesSettings extends VBox
{
{
private VBox themesSettingsVBox;
private VBox themesSettingsVBox;
private Controller controller;
private Controller controller;
private Logger logger;
private Logger logger;
private HostServices hostServices;
public ThemesSettings()
public ThemesSettings(HostServices hostServices)
{
{
this.hostServices = hostServices;
getStyleClass().add("themes_settings");
getStyleClass().add("themes_settings");
logger = Logger.getLogger(ThemesSettings.class.getName());
logger = Logger.getLogger(ThemesSettings.class.getName());
setPadding(new Insets(10));
setPadding(new Insets(10));
themesSettingsVBox = new VBox();
themesSettingsVBox = new VBox();
themesSettingsVBox.setSpacing(10.0);
themesSettingsVBox.setSpacing(10.0);
themesSettingsVBox.setAlignment(Pos.TOP_CENTER);
themesSettingsVBox.setAlignment(Pos.TOP_CENTER);
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("themes_settings_scroll_pane");
scrollPane.getStyleClass().add("themes_settings_scroll_pane");
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
themesSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
themesSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setContent(themesSettingsVBox);
scrollPane.setContent(themesSettingsVBox);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
getChildren().addAll(scrollPane);
getChildren().addAll(scrollPane);
toggleButtons = new ArrayList<>();
toggleButtons = new ArrayList<>();
}
}
public void setController(Controller controller)
public void setController(Controller controller)
{
{
this.controller = controller;
this.controller = controller;
}
}
private Themes themes;
private Themes themes;
private String currentThemeFullName;
private String currentThemeFullName;
public void setThemes(Themes themes)
public void setThemes(Themes themes)
{
{
this.themes = themes;
this.themes = themes;
}
}
public void setCurrentThemeFullName(String currentThemeFullName)
public void setCurrentThemeFullName(String currentThemeFullName)
{
{
this.currentThemeFullName = currentThemeFullName;
this.currentThemeFullName = currentThemeFullName;
}
}
private ArrayList<ToggleButton> toggleButtons;
private ArrayList<ToggleButton> toggleButtons;
public void loadThemes()
public void loadThemes()
{
{
toggleButtons.clear();
toggleButtons.clear();
Platform.runLater(()-> themesSettingsVBox.getChildren().clear());
Platform.runLater(()-> themesSettingsVBox.getChildren().clear());
for(int i = 0; i<themes.getThemeList().size(); i++)
for(int i = 0; i<themes.getThemeList().size(); i++)
{
{
Theme theme = themes.getThemeList().get(i);
Theme theme = themes.getThemeList().get(i);
VBox vBox = new VBox();
vBox.setSpacing(5.0);
Label shortNameLabel = new Label(theme.getShortName());
Label shortNameLabel = new Label(theme.getShortName());
shortNameLabel.getStyleClass().add("settings_themes_each_theme_heading");
shortNameLabel.getStyleClass().add("settings_themes_each_theme_heading");
Label authorLabel = new Label(theme.getAuthor());
Label authorLabel = new Label(theme.getAuthor());
Label fullNameLabel = new Label(theme.getFullName());
Label fullNameLabel = new Label(theme.getFullName());
HBox topRowHBox = new HBox(shortNameLabel);
if(theme.getWebsite() != null)
{
Button helpButton = new Button();
FontIcon questionIcon = new FontIcon("fas-question");
questionIcon.getStyleClass().add("settings_themes_theme_help_icon");
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> hostServices.showDocument(theme.getWebsite()));
topRowHBox.getChildren().addAll(new SpaceFiller(SpaceFiller.FillerType.HBox), helpButton);
}
Label versionLabel = new Label("Version : "+theme.getVersion().getText());
Label versionLabel = new Label("Version : "+theme.getVersion().getText());
ToggleButton toggleButton = new ToggleButton();
ToggleButton toggleButton = new ToggleButton();
toggleButton.setSelected(theme.getFullName().equals(currentThemeFullName));
toggleButton.setSelected(theme.getFullName().equals(currentThemeFullName));
toggleButton.setId(theme.getFullName());
toggleButton.setId(theme.getFullName());
if(theme.getFullName().equals(currentThemeFullName))
if(theme.getFullName().equals(currentThemeFullName))
{
{
toggleButton.setText("ON");
toggleButton.setText("ON");
toggleButton.setSelected(true);
toggleButton.setSelected(true);
toggleButton.setDisable(true);
toggleButton.setDisable(true);
}
}
else
else
{
{
toggleButton.setText("OFF");
toggleButton.setText("OFF");
}
}
toggleButton.setOnAction(event -> {
toggleButton.setOnAction(event -> {
ToggleButton toggleButton1 = (ToggleButton) event.getSource();
ToggleButton toggleButton1 = (ToggleButton) event.getSource();
toggleButton.setText("ON");
toggleButton.setText("ON");
try {
try {
Config.getInstance().setCurrentThemeFullName(toggleButton1.getId());
Config.getInstance().setCurrentThemeFullName(toggleButton1.getId());
Config.getInstance().save();
Config.getInstance().save();
for(ToggleButton toggleButton2 : toggleButtons)
for(ToggleButton toggleButton2 : toggleButtons)
{
{
if(toggleButton2.getId().equals(Config.getInstance().getCurrentThemeFullName()))
if(toggleButton2.getId().equals(Config.getInstance().getCurrentThemeFullName()))
{
{
toggleButton2.setDisable(true);
toggleButton2.setDisable(true);
toggleButton2.setText("ON");
toggleButton2.setText("ON");
toggleButton2.setSelected(true);
toggleButton2.setSelected(true);
}
}
else
else
{
{
toggleButton2.setDisable(false);
toggleButton2.setDisable(false);
toggleButton2.setText("OFF");
toggleButton2.setText("OFF");
toggleButton2.setSelected(false);
toggleButton2.setSelected(false);
}
}
}
}
controller.initThemes();
controller.initThemes();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
controller.handleSevereException(e);
controller.handleSevereException(e);
}
}
});
});
HBox hBox = new HBox(toggleButton);
HBox hBox = new HBox(toggleButton);
Region region1 = new Region();
Region region1 = new Region();
region1.setPrefHeight(5);
region1.setPrefHeight(5);
hBox.setAlignment(Pos.TOP_RIGHT);
hBox.setAlignment(Pos.TOP_RIGHT);
vBox.getChildren().addAll(shortNameLabel, authorLabel, versionLabel, fullNameLabel, hBox, region1);
VBox vBox = new VBox(topRowHBox, authorLabel, versionLabel, fullNameLabel, hBox, region1);
vBox.setSpacing(5.0);
vBox.getStyleClass().add("settings_themes_each_theme");
vBox.getStyleClass().add("settings_themes_each_theme");
Platform.runLater(()->themesSettingsVBox.getChildren().add(vBox));
Platform.runLater(()->themesSettingsVBox.getChildren().add(vBox));
toggleButtons.add(toggleButton);
toggleButtons.add(toggleButton);
}
}
}
}
}
}