server
Clone or download
Modified Files
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macropad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macropad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Written by : Debayan Sutradhar (rnayabed)
Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.server.client;
package com.stream_pi.server.client;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import javafx.geometry.Orientation;
import java.net.SocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
public class Client
public class Client
{
{
private String nickName;
private String nickName;
private final SocketAddress remoteSocketAddress;
private final SocketAddress remoteSocketAddress;
private final Platform platform;
private final Platform platform;
private final Version version;
private final Version version;
private final Version commStandardVersion;
private final Version commStandardVersion;
private final Version themeAPIVersion;
private final Version themeAPIVersion;
private final ReleaseStatus releaseStatus;
private final ReleaseStatus releaseStatus;
private double displayHeight, displayWidth;
private double displayHeight, displayWidth;
private final HashMap<String,ClientProfile> profiles;
private final HashMap<String,ClientProfile> profiles;
private final HashMap<String,ClientTheme> themes;
private final HashMap<String,ClientTheme> themes;
private String defaultProfileID;
private String defaultProfileID;
private String defaultThemeFullName;
private String defaultThemeFullName;
public Client(Version version, ReleaseStatus releaseStatus, Version commStandardVersion, Version themeAPIVersion, String nickName, Platform platform, SocketAddress remoteSocketAddress)
private Orientation orientation;
public Client(Version version, ReleaseStatus releaseStatus, Version commStandardVersion,
Version themeAPIVersion, String nickName, Platform platform, SocketAddress remoteSocketAddress,
Orientation orientation)
{
{
this.version = version;
this.version = version;
this.releaseStatus = releaseStatus;
this.releaseStatus = releaseStatus;
this.commStandardVersion = commStandardVersion;
this.commStandardVersion = commStandardVersion;
this.themeAPIVersion = themeAPIVersion;
this.themeAPIVersion = themeAPIVersion;
this.nickName = nickName;
this.nickName = nickName;
this.remoteSocketAddress = remoteSocketAddress;
this.remoteSocketAddress = remoteSocketAddress;
this.platform = platform;
this.platform = platform;
this.profiles = new HashMap<>();
this.profiles = new HashMap<>();
this.themes = new HashMap<>();
this.themes = new HashMap<>();
this.orientation = orientation;
}
}
public ReleaseStatus getReleaseStatus() {
public ReleaseStatus getReleaseStatus() {
return releaseStatus;
return releaseStatus;
}
}
public void setDefaultThemeFullName(String defaultThemeFullName) {
public void setDefaultThemeFullName(String defaultThemeFullName) {
this.defaultThemeFullName = defaultThemeFullName;
this.defaultThemeFullName = defaultThemeFullName;
}
}
public String getDefaultThemeFullName() {
public String getDefaultThemeFullName() {
return defaultThemeFullName;
return defaultThemeFullName;
}
}
public void setDefaultProfileID(String ID)
public void setDefaultProfileID(String ID)
{
{
defaultProfileID = ID;
defaultProfileID = ID;
}
}
public void addTheme(ClientTheme clientTheme) throws CloneNotSupportedException
public void addTheme(ClientTheme clientTheme) throws CloneNotSupportedException
{
{
themes.put(clientTheme.getThemeFullName(), (ClientTheme) clientTheme.clone());
themes.put(clientTheme.getThemeFullName(), (ClientTheme) clientTheme.clone());
}
}
public ArrayList<ClientTheme> getThemes()
public ArrayList<ClientTheme> getThemes()
{
{
ArrayList<ClientTheme> clientThemes = new ArrayList<>();
ArrayList<ClientTheme> clientThemes = new ArrayList<>();
for(String clientTheme : themes.keySet())
for(String clientTheme : themes.keySet())
{
{
clientThemes.add(themes.get(clientTheme));
clientThemes.add(themes.get(clientTheme));
}
}
return clientThemes;
return clientThemes;
}
}
public ClientTheme getThemeByFullName(String fullName)
public ClientTheme getThemeByFullName(String fullName)
{
{
return themes.getOrDefault(fullName, null);
return themes.getOrDefault(fullName, null);
}
}
public String getDefaultProfileID()
public String getDefaultProfileID()
{
{
return defaultProfileID;
return defaultProfileID;
}
}
//client Profiles
//client Profiles
public void setNickName(String nickName)
public void setNickName(String nickName)
{
{
this.nickName = nickName;
this.nickName = nickName;
}
}
public List<ClientProfile> getAllClientProfiles()
public List<ClientProfile> getAllClientProfiles()
{
{
ArrayList<ClientProfile> clientProfiles = new ArrayList<>();
ArrayList<ClientProfile> clientProfiles = new ArrayList<>();
for(String profile : profiles.keySet())
for(String profile : profiles.keySet())
clientProfiles.add(profiles.get(profile));
clientProfiles.add(profiles.get(profile));
return clientProfiles;
return clientProfiles;
}
}
public void removeProfileFromID(String ID)
public void removeProfileFromID(String ID)
{
{
profiles.remove(ID);
profiles.remove(ID);
}
}
public void addProfile(ClientProfile clientProfile) throws CloneNotSupportedException {
public void addProfile(ClientProfile clientProfile) throws CloneNotSupportedException {
profiles.put(clientProfile.getID(), (ClientProfile) clientProfile.clone());
profiles.put(clientProfile.getID(), (ClientProfile) clientProfile.clone());
}
}
public synchronized ClientProfile getProfileByID(String ID) {
public synchronized ClientProfile getProfileByID(String ID) {
return profiles.getOrDefault(ID, null);
return profiles.getOrDefault(ID, null);
}
}
public SocketAddress getRemoteSocketAddress()
public SocketAddress getRemoteSocketAddress()
{
{
return remoteSocketAddress;
return remoteSocketAddress;
}
}
public Platform getPlatform()
public Platform getPlatform()
{
{
return platform;
return platform;
}
}
public String getNickName()
public String getNickName()
{
{
return nickName;
return nickName;
}
}
public Version getVersion()
public Version getVersion()
{
{
return version;
return version;
}
}
public Version getCommStandardVersion()
public Version getCommStandardVersion()
{
{
return commStandardVersion;
return commStandardVersion;
}
}
public Version getThemeAPIVersion()
public Version getThemeAPIVersion()
{
{
return themeAPIVersion;
return themeAPIVersion;
}
}
public double getDisplayHeight()
public double getDisplayHeight()
{
{
return displayHeight;
return displayHeight;
}
}
public double getDisplayWidth()
public double getDisplayWidth()
{
{
return displayWidth;
return displayWidth;
}
}
public void setDisplayHeight(double height)
public void setDisplayHeight(double height)
{
{
displayHeight = height;
displayHeight = height;
}
}
public void setDisplayWidth(double width)
public void setDisplayWidth(double width)
{
{
displayWidth = width;
displayWidth = width;
}
}
private int getMaxRows(int eachActionSize)
private int getMaxRows(int eachActionSize)
{
{
return (int) (displayHeight / eachActionSize);
return (int) (displayHeight / eachActionSize);
}
}
public int getMaxCols(int eachActionSize)
public int getMaxCols(int eachActionSize)
{
{
return (int) (displayWidth / eachActionSize);
return (int) (displayWidth / eachActionSize);
}
}
public void setOrientation(Orientation orientation)
{
this.orientation = orientation;
}
public Orientation getOrientation()
{
return orientation;
}
}
}
package com.stream_pi.server.connection;
package com.stream_pi.server.connection;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientTheme;
import com.stream_pi.server.client.ClientTheme;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.comms.Message;
import com.stream_pi.util.comms.Message;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.StreamPiException;
import com.stream_pi.util.exception.StreamPiException;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Orientation;
import java.io.*;
import java.io.*;
import java.net.Socket;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
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;
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 ObjectOutputStream oos;
private ObjectOutputStream oos;
private ObjectInputStream ois;
private ObjectInputStream ois;
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;
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
{
{
oos = new ObjectOutputStream(socket.getOutputStream());
oos = new ObjectOutputStream(socket.getOutputStream());
ois = new ObjectInputStream(socket.getInputStream());
ois = new ObjectInputStream(socket.getInputStream());
} catch (IOException e) {
} catch (IOException e) {
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 "+getRemoteSocketAddress());
logger.info("Stopping connection "+getRemoteSocketAddress());
disconnect();
disconnect();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
public SocketAddress getRemoteSocketAddress()
public SocketAddress getRemoteSocketAddress()
{
{
return socket.getRemoteSocketAddress();
return socket.getRemoteSocketAddress();
}
}
public synchronized void exitAndRemove()
public synchronized void exitAndRemove()
{
{
exit();
exit();
callOnClientDisconnectOnAllActions();
callOnClientDisconnectOnAllActions();
removeConnection();
removeConnection();
serverListener.clearTemp();
serverListener.clearTemp();
}
}
public void callOnClientDisconnectOnAllActions()
public void callOnClientDisconnectOnAllActions()
{
{
for(ClientProfile profile : getClient().getAllClientProfiles())
for(ClientProfile profile : getClient().getAllClientProfiles())
{
{
for (String actionID : profile.getActionsKeySet())
for (String actionID : profile.getActionsKeySet())
{
{
Action action = profile.getActionByID(actionID);
Action action = profile.getActionByID(actionID);
if(action instanceof ExternalPlugin)
if(action instanceof ExternalPlugin)
{
{
try
try
{
{
((ExternalPlugin) action).onClientDisconnected();
((ExternalPlugin) action).onClientDisconnected();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.setTitle("Unable to run onClientDisconnected for "+action.getModuleName());
e.setTitle("Unable to run onClientDisconnected for "+action.getModuleName());
e.setShortMessage("Detailed message :\n\n"+e.getShortMessage());
e.setShortMessage("Detailed message :\n\n"+e.getShortMessage());
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
}
}
}
}
}
}
public void removeConnection()
public void removeConnection()
{
{
ClientConnections.getInstance().removeConnection(this);
ClientConnections.getInstance().removeConnection(this);
}
}
public Logger getLogger()
public Logger getLogger()
{
{
return logger;
return logger;
}
}
public void sendIcon(String profileID, String actionID, String state, byte[] icon) throws SevereException
public void sendIcon(String profileID, String actionID, String state, byte[] icon) throws SevereException
{
{
getLogger().info("Sending icon "+state+" len "+icon.length+"; profile:"+profileID+"; actionid:"+actionID+"\n\n\n\n");
getLogger().info("Sending icon "+state+" len "+icon.length+"; profile:"+profileID+"; actionid:"+actionID+"\n\n\n\n");
try
try
{
{
Thread.sleep(50);
Thread.sleep(50);
}
}
catch (InterruptedException e)
catch (InterruptedException e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
Message message = new Message("action_icon");
Message message = new Message("action_icon");
message.setStringArrValue(profileID, actionID, state);
message.setStringArrValue(profileID, actionID, state);
message.setByteArrValue(icon);
message.setByteArrValue(icon);
sendMessage(message);
sendMessage(message);
}
}
public void initAfterConnectionQueryReceive(Message message) throws StreamPiException
public void initAfterConnectionQueryReceive(Message message) throws StreamPiException
{
{
String[] ar = message.getStringArrValue();
String[] ar = message.getStringArrValue();
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(ar[0]);
clientVersion = new Version(ar[0]);
releaseStatus = ReleaseStatus.valueOf(ar[1]);
releaseStatus = ReleaseStatus.valueOf(ar[1]);
commsStandard = new Version(ar[2]);
commsStandard = new Version(ar[2]);
themesStandard = new Version(ar[3]);
themesStandard = new Version(ar[3]);
}
}
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, ar[4], Platform.valueOf(ar[7]), socket.getRemoteSocketAddress());
client = new Client(clientVersion, releaseStatus, commsStandard, themesStandard, ar[4],
Platform.valueOf(ar[7]), socket.getRemoteSocketAddress(), Orientation.valueOf(ar[10]));
client.setDisplayWidth(Double.parseDouble(ar[5]));
client.setDisplayWidth(Double.parseDouble(ar[5]));
client.setDisplayHeight(Double.parseDouble(ar[6]));
client.setDisplayHeight(Double.parseDouble(ar[6]));
client.setDefaultProfileID(ar[8]);
client.setDefaultProfileID(ar[8]);
client.setDefaultThemeFullName(ar[9]);
client.setDefaultThemeFullName(ar[9]);
//call get profiles command.
//call get profiles command.
serverListener.clearTemp();
serverListener.clearTemp();
}
}
public void updateClientDetails(Message message)
public void updateClientDetails(Message message)
{
{
String[] ar = message.getStringArrValue();
String[] ar = message.getStringArrValue();
logger.info("Setting up client object ...");
logger.info("Setting up client object ...");
client.setNickName(ar[4]);
client.setNickName(ar[4]);
client.setDisplayWidth(Double.parseDouble(ar[5]));
client.setDisplayWidth(Double.parseDouble(ar[5]));
client.setDisplayHeight(Double.parseDouble(ar[6]));
client.setDisplayHeight(Double.parseDouble(ar[6]));
client.setDefaultProfileID(ar[8]);
client.setDefaultProfileID(ar[8]);
client.setDefaultThemeFullName(ar[9]);
client.setDefaultThemeFullName(ar[9]);
serverListener.getSettingsBase().getClientsSettings().loadData();
serverListener.getSettingsBase().getClientsSettings().loadData();
}
}
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())
{
{
try
try
{
{
Message message = (Message) ois.readObject();
Message message = (Message) ois.readObject();
String header = message.getHeader();
String header = message.getHeader();
switch (header)
switch (header)
{
{
case "action_icon" : onActionIconReceived(message);
case "action_icon" : onActionIconReceived(message);
break;
break;
case "disconnect" : clientDisconnected(message);
case "disconnect" : clientDisconnected(message);
break;
break;
case "register_client_details" : initAfterConnectionQueryReceive(message);
case "register_client_details" : initAfterConnectionQueryReceive(message);
getProfilesFromClient();
getProfilesFromClient();
getThemesFromClient();
getThemesFromClient();
break;
break;
case "update_client_details" : updateClientDetails(message);
case "update_client_details" : updateClientDetails(message);
break;
break;
case "client_screen_details" : onClientScreenDetailsReceived(message);
case "client_screen_details" : onClientScreenDetailsReceived(message);
break;
break;
case "profiles" : registerProfilesFromClient(message);
case "profiles" : registerProfilesFromClient(message);
break;
break;
case "profile_details" : registerProfileDetailsFromClient(message);
case "profile_details" : registerProfileDetailsFromClient(message);
break;
break;
case "action_details" : registerActionToProfile(message);
case "action_details" : registerActionToProfile(message);
break;
break;
case "themes": registerThemes(message);
case "themes": registerThemes(message);
break;
break;
case "action_clicked": onActionClicked(message);
case "action_clicked": onActionClicked(message);
break;
break;
case "client_orientation": updateClientOrientation(message);
break;
default: logger.warning("Command '"+header+"' does not match records. Make sure client and server versions are equal.");
default: logger.warning("Command '"+header+"' does not match records. Make sure client and server versions are equal.");
}
}
}
}
catch (IOException | ClassNotFoundException e)
catch (IOException | ClassNotFoundException e)
{
{
logger.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;
}
}
}
}
}
}
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
private void updateClientOrientation(Message message) throws MinorException
{
getClient().setOrientation(Orientation.valueOf(message.getStringValue()));
javafx.application.Platform.runLater(()-> serverListener.getDashboardBase().reDrawProfile());
}
private void onActionIconReceived(Message message) throws MinorException
private void onActionIconReceived(Message message) throws MinorException
{
{
String[] s = message.getStringArrValue();
String[] s = message.getStringArrValue();
String profileID = s[0];
String profileID = s[0];
String actionID = s[1];
String actionID = s[1];
String iconState = s[2];
String iconState = s[2];
getClient()
getClient()
.getProfileByID(profileID)
.getProfileByID(profileID)
.getActionByID(actionID)
.getActionByID(actionID)
.addIcon(iconState,message.getByteArrValue());
.addIcon(iconState,message.getByteArrValue());
}
}
public void initAfterConnectionQuerySend() throws SevereException
public void initAfterConnectionQuerySend() throws SevereException
{
{
logger.info("Asking client details ...");
logger.info("Asking client details ...");
sendMessage(new Message("get_client_details"));
sendMessage(new Message("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 ...");
Message m = new Message("disconnect");
Message m = new Message("disconnect");
m.setStringValue(message);
m.setStringValue(message);
sendMessage(m);
sendMessage(m);
try
try
{
{
if(!socket.isClosed())
if(!socket.isClosed())
socket.close();
socket.close();
}
}
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 synchronized void sendMessage(Message message) throws SevereException
public synchronized void sendMessage(Message message) throws SevereException
{
{
try
try
{
{
logger.info("Sending message with heading "+message.getHeader()+" ...");
logger.info("Sending message with heading "+message.getHeader()+" ...");
oos.writeObject(message);
oos.writeObject(message);
oos.flush();
oos.flush();
logger.info("... Done!");
logger.info("... Done!");
}
}
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 clientDisconnected(Message message)
public void clientDisconnected(Message message)
{
{
stop.set(true);
stop.set(true);
String txt = "Disconnected!";
String txt = "Disconnected!";
String msg = message.getStringValue();
String msg = message.getStringValue();
if(!msg.isBlank())
if(!msg.isBlank())
txt = "Message : "+msg;
txt = "Message : "+msg;
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 ...");
sendMessage(new Message("get_profiles"));
sendMessage(new Message("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 ...");
sendMessage(new Message("get_themes"));
sendMessage(new Message("get_themes"));
}
}
public void registerThemes(Message message)
public void registerThemes(Message message)
{
{
String[] r = message.getStringArrValue();
String[] r = message.getStringArrValue();
for(int i =0; i<(r.length);i+=4)
for(int i =0; i<(r.length);i+=4)
{
{
ClientTheme clientTheme = new ClientTheme(
ClientTheme clientTheme = new ClientTheme(
r[i],
r[i],
r[i+1],
r[i+1],
r[i+2],
r[i+2],
r[i+3]
r[i+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();
}
}
}
}
}
}
private HashMap<String, Integer> temporaryProfilesCheck = null;
private HashMap<String, Integer> temporaryProfilesCheck = null;
public void registerProfilesFromClient(Message message) throws StreamPiException
public void registerProfilesFromClient(Message message) throws StreamPiException
{
{
logger.info("Registering profiles ...");
logger.info("Registering profiles ...");
String[] profileIds = message.getStringArrValue();
String[] profileIds = message.getStringArrValue();
int[] profilesActionIds = message.getIntArrValue();
int[] profilesActionIds = message.getIntArrValue();
temporaryProfilesCheck = new HashMap<>();
temporaryProfilesCheck = new HashMap<>();
for (int i = 0;i<profileIds.length;i++)
for (int i = 0;i<profileIds.length;i++)
{
{
temporaryProfilesCheck.put(profileIds[i], profilesActionIds[i]);
temporaryProfilesCheck.put(profileIds[i], profilesActionIds[i]);
getProfileDetailsFromClient(profileIds[i]);
getProfileDetailsFromClient(profileIds[i]);
}
}
}
}
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);
Message message = new Message("get_profile_details");
Message message = new Message("get_profile_details");
message.setStringValue(ID);
message.setStringValue(ID);
sendMessage(message);
sendMessage(message);
}
}
public void registerProfileDetailsFromClient(Message message)
public void registerProfileDetailsFromClient(Message message)
{
{
String[] r = message.getStringArrValue();
String[] r = message.getStringArrValue();
String ID = r[0];
String ID = r[0];
logger.info("Registering details for profile : "+ID);
logger.info("Registering details for profile : "+ID);
String name = r[1];
String name = r[1];
int rows = Integer.parseInt(r[2]);
int rows = Integer.parseInt(r[2]);
int cols = Integer.parseInt(r[3]);
int cols = Integer.parseInt(r[3]);
int actionSize = Integer.parseInt(r[4]);
int actionSize = Integer.parseInt(r[4]);
int actionGap = Integer.parseInt(r[5]);
int actionGap = Integer.parseInt(r[5]);
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 synchronized void registerActionToProfile(Message message) throws StreamPiException
public synchronized void registerActionToProfile(Message message) throws StreamPiException
{
{
String[] r = message.getStringArrValue();
String[] r = message.getStringArrValue();
String profileID = r[0];
String profileID = r[0];
String ID = r[1];
String ID = r[1];
ActionType actionType = ActionType.valueOf(r[2]);
ActionType actionType = ActionType.valueOf(r[2]);
//3 - Version
//3 - Version
//4 - ModuleName
//4 - ModuleName
//display
//display
String bgColorHex = r[5];
String bgColorHex = r[5];
//icon
//icon
String[] allIconStateNames = r[6].split("::");
String[] allIconStateNames = r[6].split("::");
String defaultIconState = r[7];
String defaultIconState = r[7];
//text
//text
boolean isShowDisplayText = r[8].equals("true");
boolean isShowDisplayText = r[8].equals("true");
String displayFontColor = r[9];
String displayFontColor = r[9];
String displayText = r[10];
String displayText = r[10];
DisplayTextAlignment displayTextAlignment = DisplayTextAlignment.valueOf(r[11]);
DisplayTextAlignment displayTextAlignment = DisplayTextAlignment.valueOf(r[11]);
//location
//location
String row = r[12];
String row = r[12];
String col = r[13];
String col = r[13];
Location location = new Location(Integer.parseInt(row), Integer.parseInt(col));
Location location = new Location(Integer.parseInt(row), Integer.parseInt(col));
String root = r[14];
String root = r[14];
int delayBeforeRunning = Integer.parseInt(r[15]);
int delayBeforeRunning = Integer.parseInt(r[15]);
//client properties
//client properties
int clientPropertiesSize = Integer.parseInt(r[16]);
int clientPropertiesSize = Integer.parseInt(r[16]);
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 = 17;i<((clientPropertiesSize*2) + 17); i+=2)
for(int i = 17;i<((clientPropertiesSize*2) + 17); i+=2)
{
{
Property property = new Property(r[i], Type.STRING);
Property property = new Property(r[i], Type.STRING);
property.setRawValue(r[i+1]);
property.setRawValue(r[i+1]);
clientProperties.addProperty(property);
clientProperties.addProperty(property);
}
}
//set up action
//set up action
temporaryProfilesCheck.replace(
temporaryProfilesCheck.replace(
profileID,
profileID,
(temporaryProfilesCheck.get(profileID) - 1)
(temporaryProfilesCheck.get(profileID) - 1)
);
);
if(temporaryProfilesCheck.get(profileID) == 0)
if(temporaryProfilesCheck.get(profileID) == 0)
{
{
temporaryProfilesCheck.remove(profileID);
temporaryProfilesCheck.remove(profileID);
}
}
//action toBeAdded = null;
//action toBeAdded = null;
boolean isInvalidAction = false;
boolean isInvalidAction = false;
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
{
{
String moduleName = r[4];
String moduleName = r[4];
Version version = new Version(r[3]);
Version version = new Version(r[3]);
ExternalPlugin originalAction = ExternalPlugins.getInstance().getPluginByModuleName(moduleName);
ExternalPlugin originalAction = ExternalPlugins.getInstance().getPluginByModuleName(moduleName);
if(originalAction == null)
if(originalAction == null)
{
{
isInvalidAction = true;
isInvalidAction = true;
}
}
else
else
{
{
if(originalAction.getVersion().getMajor() != version.getMajor())
if(originalAction.getVersion().getMajor() != version.getMajor())
{
{
isInvalidAction = true;
isInvalidAction = true;
}
}
else
else
{
{
try
try
{
{
ExternalPlugin newPlugin = originalAction.clone();
ExternalPlugin newPlugin = originalAction.clone();
newPlugin.setID(ID);
newPlugin.setID(ID);
newPlugin.setProfileID(profileID);
newPlugin.setProfileID(profileID);
newPlugin.setSocketAddressForClient(socket.getRemoteSocketAddress());
newPlugin.setSocketAddressForClient(socket.getRemoteSocketAddress());
newPlugin.setBgColourHex(bgColorHex);
newPlugin.setBgColourHex(bgColorHex);
newPlugin.setCurrentIconState(defaultIconState);
newPlugin.setCurrentIconState(defaultIconState);
newPlugin.setShowDisplayText(isShowDisplayText);
newPlugin.setShowDisplayText(isShowDisplayText);
newPlugin.setDisplayTextFontColourHex(displayFontColor);
newPlugin.setDisplayTextFontColourHex(displayFontColor);
newPlugin.setDisplayText(displayText);
newPlugin.setDisplayText(displayText);
newPlugin.setDisplayTextAlignment(displayTextAlignment);
newPlugin.setDisplayTextAlignment(displayTextAlignment);
newPlugin.setLocation(location);
newPlugin.setLocation(location);
newPlugin.setParent(root);
newPlugin.setParent(root);
newPlugin.setDelayBeforeExecuting(delayBeforeRunning);
newPlugin.setDelayBeforeExecuting(delayBeforeRunning);
ClientProperties finalClientProperties = new ClientProperties();
ClientProperties finalClientProperties = new ClientProperties();
for(Property property : originalAction.getClientProperties().get())
for(Property property : originalAction.getClientProperties().get())
{
{
for(int i = 0;i<clientProperties.getSize();i++)
for(int i = 0;i<clientProperties.getSize();i++)
{
{
Property property1 = clientProperties.get().get(i);
Property property1 = clientProperties.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);
}
}
}
}
}
}
newPlugin.setClientProperties(finalClientProperties);
newPlugin.setClientProperties(finalClientProperties);
getClient().getProfileByID(profileID).addAction(newPlugin);
getClient().getProfileByID(profileID).addAction(newPlugin);
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
newPlugin.onClientConnected();
newPlugin.onClientConnected();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.setTitle("Unable to run onClientConnected for "+moduleName);
e.setTitle("Unable to run onClientConnected for "+moduleName);
e.setShortMessage("Detailed message :\n\n"+e.getShortMessage());
e.setShortMessage("Detailed message :\n\n"+e.getShortMessage());
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
catch (CloneNotSupportedException e)
catch (CloneNotSupportedException e)
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("action", "Unable to clone"));
exceptionAndAlertHandler.handleMinorException(new MinorException("action", "Unable to clone"));
}
}
checkIfReady();
checkIfReady();
return;
return;
}
}
}
}
}
}
Action action = null;
Action action = null;
if(isInvalidAction)
if(isInvalidAction)
{
{
String moduleName = r[4];
String moduleName = r[4];
Version version = new Version(r[3]);
Version version = new Version(r[3]);
action = new Action();
action = new Action();
action.setInvalid(true);
action.setInvalid(true);
action.setVersion(version);
action.setVersion(version);
action.setModuleName(moduleName);
action.setModuleName(moduleName);
}
}
else
else
{
{
if(actionType == ActionType.COMBINE)
if(actionType == ActionType.COMBINE)
{
{
action = new CombineAction();
action = new CombineAction();
}
}
else if(actionType == ActionType.FOLDER)
else if(actionType == ActionType.FOLDER)
{
{
action = new FolderAction();
action = new FolderAction();
}
}
}
}
action.setID(ID);
action.setID(ID);
action.setProfileID(profileID);
action.setProfileID(profileID);
action.setSocketAddressForClient(socket.getRemoteSocketAddress());
action.setSocketAddressForClient(socket.getRemoteSocketAddress());
action.setBgColourHex(bgColorHex);
action.setBgColourHex(bgColorHex);
action.setCurrentIconState(defaultIconState);
action.setCurrentIconState(defaultIconState);
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);
action.setParent(root);
action.setParent(root);
action.setClientProperties(clientProperties);
action.setClientProperties(clientProperties);
try
try
{
{
getClient().getProfileByID(profileID).addAction(action);
getClient().getProfileByID(profileID).addAction(action);
}
}
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"));
}
}
checkIfReady();
checkIfReady();
}
}
public void checkIfReady() throws SevereException
public void checkIfReady() throws SevereException
{
{
if(temporaryProfilesCheck.size() == 0)
if(temporaryProfilesCheck.size() == 0)
{
{
temporaryProfilesCheck = null;
temporaryProfilesCheck = null;
sendMessage(new Message("ready"));
sendMessage(new Message("ready"));
}
}
}
}
public synchronized void saveActionDetails(String profileID, Action action) throws SevereException
public synchronized void saveActionDetails(String profileID, Action action) throws SevereException
{
{
ArrayList<String> a = new ArrayList<>();
ArrayList<String> a = new ArrayList<>();
a.add(profileID);
a.add(profileID);
a.add(action.getID());
a.add(action.getID());
a.add(action.getActionType()+"");
a.add(action.getActionType()+"");
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
{
{
a.add(action.getVersion().getText());
a.add(action.getVersion().getText());
System.out.println("VERSION :sdd "+action.getVersion().getText());
System.out.println("VERSION :sdd "+action.getVersion().getText());
}
}
else
else
{
{
a.add("no");
a.add("no");
}
}
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.NORMAL || action.getActionType() == ActionType.TOGGLE)
{
{
a.add(action.getModuleName());
a.add(action.getModuleName());
}
}
else
else
{
{
a.add("nut");
a.add("nut");
}
}
//display
//display
a.add(action.getBgColourHex());
a.add(action.getBgColourHex());
//icon
//icon
StringBuilder allIconStatesNames = new StringBuilder();
StringBuilder allIconStatesNames = new StringBuilder();
for(String eachState : action.getIcons().keySet())
for(String eachState : action.getIcons().keySet())
{
{
allIconStatesNames.append(eachState).append("::");
allIconStatesNames.append(eachState).append("::");
}
}
a.add(allIconStatesNames.toString());
a.add(allIconStatesNames.toString());
a.add(action.getCurrentIconState());
a.add(action.getCurrentIconState());
//text
//text
a.add(action.isShowDisplayText()+"");
a.add(action.isShowDisplayText()+"");
a.add(action.getDisplayTextFontColourHex());
a.add(action.getDisplayTextFontColourHex());
a.add(action.getDisplayText());
a.add(action.getDisplayText());
a.add(action.getDisplayTextAlignment()+"");
a.add(action.getDisplayTextAlignment()+"");
//location
//location
if(action.getLocation() == null)
if(action.getLocation() == null)
{
{
a.add("-1");
a.add("-1");
a.add("-1");
a.add("-1");
}
}
else
else
{
{
a.add(action.getLocation().getRow()+"");
a.add(action.getLocation().getRow()+"");
a.add(action.getLocation().getCol()+"");
a.add(action.getLocation().getCol()+"");
}
}
a.add(action.getParent());
a.add(action.getParent());
a.add(action.getDelayBeforeExecuting()+"");
a.add(action.getDelayBeforeExecuting()+"");
//client properties
//client properties
ClientProperties clientProperties = action.getClientProperties();
ClientProperties clientProperties = action.getClientProperties();
a.add(clientProperties.getSize()+"");
a.add(clientProperties.getSize()+"");
for(Property property : clientProperties.get())
for(Property property : clientProperties.get())
{
{
a.add(property.getName());
a.add(property.getName());
a.add(property.getRawValue());
a.add(property.getRawValue());
}
}
Message message = new Message("save_action_details");
Message message = new Message("save_action_details");
String[] x = new String[a.size()];
String[] x = new String[a.size()];
x = a.toArray(x);
x = a.toArray(x);
message.setStringArrValue(x);
message.setStringArrValue(x);
sendMessage(message);
sendMessage(message);
}
}
public void getClientScreenDetails() throws SevereException
public void getClientScreenDetails() throws SevereException
{
{
Message message = new Message("get_client_screen_details");
Message message = new Message("get_client_screen_details");
sendMessage(message);
sendMessage(message);
}
}
public void onClientScreenDetailsReceived(Message message)
public void onClientScreenDetailsReceived(Message message)
{
{
getClient().setDisplayWidth(message.getDoubleArrValue()[0]);
getClient().setDisplayWidth(message.getDoubleArrValue()[0]);
getClient().setDisplayHeight(message.getDoubleArrValue()[1]);
getClient().setDisplayHeight(message.getDoubleArrValue()[1]);
}
}
public void deleteAction(String profileID, String actionID) throws SevereException
public void deleteAction(String profileID, String actionID) throws SevereException
{
{
Message message = new Message("delete_action");
Message message = new Message("delete_action");
message.setStringArrValue(profileID, actionID);
message.setStringArrValue(profileID, actionID);
sendMessage(message);
sendMessage(message);
}
}
public void saveClientDetails(String clientNickname, String defaultProfileID,
public void saveClientDetails(String clientNickname, String defaultProfileID,
String defaultThemeFullName) throws SevereException
String defaultThemeFullName) throws SevereException
{
{
Message message = new Message("save_client_details");
Message message = new Message("save_client_details");
message.setStringArrValue(
message.setStringArrValue(
clientNickname,
clientNickname,
defaultProfileID,
defaultProfileID,
defaultThemeFullName
defaultThemeFullName
);
);
sendMessage(message);
sendMessage(message);
client.setNickName(clientNickname);
client.setNickName(clientNickname);
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);
Message message = new Message("save_client_profile");
Message message = new Message("save_client_profile");
message.setStringArrValue(
message.setStringArrValue(
clientProfile.getID(),
clientProfile.getID(),
clientProfile.getName(),
clientProfile.getName(),
clientProfile.getRows()+"",
clientProfile.getRows()+"",
clientProfile.getCols()+"",
clientProfile.getCols()+"",
clientProfile.getActionSize()+"",
clientProfile.getActionSize()+"",
clientProfile.getActionGap()+""
clientProfile.getActionGap()+""
);
);
sendMessage(message);
sendMessage(message);
}
}
public void deleteProfile(String ID) throws SevereException
public void deleteProfile(String ID) throws SevereException
{
{
Message message = new Message("delete_profile");
Message message = new Message("delete_profile");
message.setStringValue(ID);
message.setStringValue(ID);
sendMessage(message);
sendMessage(message);
}
}
public void onActionClicked(Message message)
public void onActionClicked(Message message)
{
{
String[] r = message.getStringArrValue();
String[] r = message.getStringArrValue();
String profileID = r[0];
String profileID = r[0];
String actionID = r[1];
String actionID = r[1];
boolean toggle = r[2].equals("true");
boolean toggle = r[2].equals("true");
serverListener.onActionClicked(getClient(), profileID, actionID, toggle);
serverListener.onActionClicked(getClient(), profileID, actionID, toggle);
}
}
public void setToggleStatus(boolean status, String profileID, String actionID) throws SevereException
public void setToggleStatus(boolean status, String profileID, String actionID) throws SevereException
{
{
Message message = new Message("set_toggle_status");
Message message = new Message("set_toggle_status");
message.setStringArrValue(profileID, actionID, status+"");
message.setStringArrValue(profileID, actionID, status+"");
sendMessage(message);
sendMessage(message);
}
}
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 ...");
Message message = new Message("action_failed");
Message message = new Message("action_failed");
message.setStringArrValue(profileID, actionID);
message.setStringArrValue(profileID, actionID);
sendMessage(message);
sendMessage(message);
}
}
}
}
/*
/*
Config.java
Config.java
Contributor(s) : Debayan Sutradhar (@rnayabed)
Contributor(s) : Debayan Sutradhar (@rnayabed)
handler for config.xml
handler for config.xml
*/
*/
package com.stream_pi.server.io;
package com.stream_pi.server.io;
import java.awt.*;
import java.awt.*;
import java.io.File;
import java.io.File;
import java.lang.reflect.Array;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Objects;
import java.util.Objects;
import java.util.logging.Logger;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamResult;
import com.stream_pi.server.Main;
import com.stream_pi.server.Main;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.xmlconfighelper.XMLConfigHelper;
import com.stream_pi.util.xmlconfighelper.XMLConfigHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Node;
public class Config
public class Config
{
{
private static Config instance = null;
private static Config instance = null;
private final File configFile;
private final File configFile;
private Document document;
private Document document;
private Config() throws SevereException {
private Config() throws SevereException
try {
{
try
{
configFile = new File(ServerInfo.getInstance().getPrePath()+"config.xml");
configFile = new File(ServerInfo.getInstance().getPrePath()+"config.xml");
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
document = docBuilder.parse(configFile);
document = docBuilder.parse(configFile);
} catch (Exception e) {
}
catch (Exception e)
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException("Config", "Unable to read config.xml\n"+e.getMessage());
throw new SevereException("Config", "Unable to read config.xml\n"+e.getMessage());
}
}
}
}
public static synchronized Config getInstance() throws SevereException
public static synchronized Config getInstance() throws SevereException
{
{
if(instance == null)
if(instance == null)
instance = new Config();
instance = new Config();
return instance;
return instance;
}
}
public static void nullify()
public static void nullify()
{
{
instance = null;
instance = null;
}
}
Logger logger = Logger.getLogger(Config.class.getName());
Logger logger = Logger.getLogger(Config.class.getName());
public void save() throws SevereException {
public void save() throws SevereException {
try {
try {
logger.info("Saving config ...");
logger.info("Saving config ...");
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(configFile);
Result output = new StreamResult(configFile);
Source input = new DOMSource(document);
Source input = new DOMSource(document);
transformer.transform(input, output);
transformer.transform(input, output);
logger.info("... Done!");
logger.info("... Done!");
} catch (Exception e) {
} catch (Exception e) {
throw new SevereException("Config", "unable to save config.xml");
throw new SevereException("Config", "unable to save config.xml");
}
}
}
}
//Getters
//Getters
//comms
//comms
private Element getCommsElement()
private Element getCommsElement()
{
{
return (Element) document.getElementsByTagName("comms").item(0);
return (Element) document.getElementsByTagName("comms").item(0);
}
}
public String getServerName()
public String getServerName()
{
{
return XMLConfigHelper.getStringProperty(getCommsElement(), "name",
return XMLConfigHelper.getStringProperty(getCommsElement(), "name",
getDefaultServerName(), false, true, document, configFile);
getDefaultServerName(), false, true, document, configFile);
}
}
public int getPort()
public int getPort()
{
{
return XMLConfigHelper.getIntProperty(getCommsElement(), "port",
return XMLConfigHelper.getIntProperty(getCommsElement(), "port",
getDefaultPort(), false, true, document, configFile);
getDefaultPort(), false, true, document, configFile);
}
}
//default getters
//default getters
public String getDefaultServerName()
public String getDefaultServerName()
{
{
return "Stream-Pi Server";
return "Stream-Pi Server";
}
}
public static int getDefaultPort()
public static int getDefaultPort()
{
{
return 6504;
return 6504;
}
}
//server
//server
private Element getDividerPositionsElement()
private Element getDividerPositionsElement()
{
{
return (Element) document.getElementsByTagName("divider-positions").item(0);
return (Element) document.getElementsByTagName("divider-positions").item(0);
}
}
public String getDefaultLeftDividerPositions()
public String getDefaultLeftDividerPositions()
{
{
return "3.0";
return "3.0";
}
}
public double[] getLeftDividerPositions()
public double[] getLeftDividerPositions()
{
{
String[] strArr = XMLConfigHelper.getStringProperty(getDividerPositionsElement(), "left",
String[] strArr = XMLConfigHelper.getStringProperty(getDividerPositionsElement(), "left",
getDefaultLeftDividerPositions(), false, true, document, configFile)
getDefaultLeftDividerPositions(), false, true, document, configFile)
.split(",");
.split(",");
double[] r = new double[strArr.length];
double[] r = new double[strArr.length];
for (int i = 0;i<strArr.length;i++)
for (int i = 0;i<strArr.length;i++)
{
{
r[i] = Double.parseDouble(strArr[i]);
r[i] = Double.parseDouble(strArr[i]);
}
}
return r;
return r;
}
}
public void setLeftDividerPositions(double[] position)
public void setLeftDividerPositions(double[] position)
{
{
String r = Arrays.toString(position);
String r = Arrays.toString(position);
getDividerPositionsElement().getElementsByTagName("left").item(0).setTextContent(r.substring(1, r.length()-1));
getDividerPositionsElement().getElementsByTagName("left").item(0).setTextContent(r.substring(1, r.length()-1));
}
}
public String getDefaultRightDividerPositions()
public String getDefaultRightDividerPositions()
{
{
return "3.0";
return "3.0";
}
}
public double[] getRightDividerPositions()
public double[] getRightDividerPositions()
{
{
String[] strArr = XMLConfigHelper.getStringProperty(getDividerPositionsElement(), "right",
String[] strArr = XMLConfigHelper.getStringProperty(getDividerPositionsElement(), "right",
getDefaultRightDividerPositions(), false, true, document, configFile)
getDefaultRightDividerPositions(), false, true, document, configFile)
.split(",");
.split(",");
double[] r = new double[strArr.length];
double[] r = new double[strArr.length];
for (int i = 0;i<strArr.length;i++)
for (int i = 0;i<strArr.length;i++)
{
{
r[i] = Double.parseDouble(strArr[i]);
r[i] = Double.parseDouble(strArr[i]);
}
}
return r;
return r;
}
}
public void setRightDividerPositions(double[] position)
public void setRightDividerPositions(double[] position)
{
{
String r = Arrays.toString(position);
String r = Arrays.toString(position);
getDividerPositionsElement().getElementsByTagName("right").item(0).setTextContent(r.substring(1, r.length()-1));
getDividerPositionsElement().getElementsByTagName("right").item(0).setTextContent(r.substring(1, r.length()-1));
}
}
private Element getActionGridElement()
private Element getActionGridElement()
{
{
return (Element) document.getElementsByTagName("action-grid").item(0);
return (Element) document.getElementsByTagName("action-grid").item(0);
}
}
public int getActionGridActionGap()
public int getActionGridActionGap()
{
{
return XMLConfigHelper.getIntProperty(getActionGridElement(), "gap",
return XMLConfigHelper.getIntProperty(getActionGridElement(), "gap",
getDefaultActionGridActionGap(), false, true, document, configFile);
getDefaultActionGridActionGap(), false, true, document, configFile);
}
}
public int getActionGridActionSize()
public int getActionGridActionSize()
{
{
return XMLConfigHelper.getIntProperty(getActionGridElement(), "size",
return XMLConfigHelper.getIntProperty(getActionGridElement(), "size",
getDefaultActionGridSize(), false, true, document, configFile);
getDefaultActionGridSize(), false, true, document, configFile);
}
}
public String getCurrentThemeFullName()
public String getCurrentThemeFullName()
{
{
return XMLConfigHelper.getStringProperty(document, "current-theme-full-name",
return XMLConfigHelper.getStringProperty(document, "current-theme-full-name",
getDefaultCurrentThemeFullName(), false, true, document, configFile);
getDefaultCurrentThemeFullName(), false, true, document, configFile);
}
}
public String getThemesPath()
public String getThemesPath()
{
{
return XMLConfigHelper.getStringProperty(document, "themes-path",
return XMLConfigHelper.getStringProperty(document, "themes-path",
getDefaultThemesPath(), false, true, document, configFile);
getDefaultThemesPath(), false, true, document, configFile);
}
}
public String getPluginsPath()
public String getPluginsPath()
{
{
return XMLConfigHelper.getStringProperty(document, "plugins-path",
return XMLConfigHelper.getStringProperty(document, "plugins-path",
getDefaultPluginsPath(), false, true, document, configFile);
getDefaultPluginsPath(), false, true, document, configFile);
}
}
//default getters
//default getters
public String getDefaultCurrentThemeFullName()
public String getDefaultCurrentThemeFullName()
{
{
return "com.stream_pi.defaultlight";
return "com.stream_pi.defaultlight";
}
}
public String getDefaultThemesPath()
public String getDefaultThemesPath()
{
{
return ServerInfo.getInstance().getPrePath()+"Themes/";
return ServerInfo.getInstance().getPrePath()+"Themes/";
}
}
public String getDefaultPluginsPath()
public String getDefaultPluginsPath()
{
{
return ServerInfo.getInstance().getPrePath()+"Plugins/";
return ServerInfo.getInstance().getPrePath()+"Plugins/";
}
}
//server > startup-window-size
//server > startup-window-size
private Element getStartupWindowSizeElement()
private Element getStartupWindowSizeElement()
{
{
return (Element) document.getElementsByTagName("startup-window-size").item(0);
return (Element) document.getElementsByTagName("startup-window-size").item(0);
}
}
public double getStartupWindowWidth()
public double getStartupWindowWidth()
{
{
return XMLConfigHelper.getDoubleProperty(getStartupWindowSizeElement(), "width",
return XMLConfigHelper.getDoubleProperty(getStartupWindowSizeElement(), "width",
getDefaultStartupWindowWidth(), false, true, document, configFile);
getDefaultStartupWindowWidth(), false, true, document, configFile);
}
}
public double getStartupWindowHeight()
public double getStartupWindowHeight()
{
{
return XMLConfigHelper.getDoubleProperty(getStartupWindowSizeElement(), "height",
return XMLConfigHelper.getDoubleProperty(getStartupWindowSizeElement(), "height",
getDefaultStartupWindowHeight(), false, true, document, configFile);
getDefaultStartupWindowHeight(), false, true, document, configFile);
}
}
//default getters
//default getters
public int getDefaultStartupWindowWidth()
public int getDefaultStartupWindowWidth()
{
{
return 1024;
return 1024;
}
}
public int getDefaultStartupWindowHeight()
public int getDefaultStartupWindowHeight()
{
{
return 768;
return 768;
}
}
//sound on action clicked
//sound on action clicked
private Element getSoundOnActionClickedElement()
private Element getSoundOnActionClickedElement()
{
{
return (Element) document.getElementsByTagName("sound-on-action-clicked").item(0);
return (Element) document.getElementsByTagName("sound-on-action-clicked").item(0);
}
}
//others
//others
private Element getOthersElement()
private Element getOthersElement()
{
{
return (Element) document.getElementsByTagName("others").item(0);
return (Element) document.getElementsByTagName("others").item(0);
}
}
public boolean getStartOnBoot()
public boolean getStartOnBoot()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "start-on-boot",
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "start-on-boot",
getDefaultStartOnBoot(), false, true, document, configFile);
getDefaultStartOnBoot(), false, true, document, configFile);
}
}
public boolean getMinimiseToSystemTrayOnClose()
public boolean getMinimiseToSystemTrayOnClose()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "minimize-to-tray-on-close",
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "minimize-to-tray-on-close",
getDefaultMinimiseToSystemTrayOnClose(), false, true, document, configFile);
getDefaultMinimiseToSystemTrayOnClose(), false, true, document, configFile);
}
}
public boolean isFirstTimeUse()
public boolean isFirstTimeUse()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "first-time-use", true, false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "first-time-use", true, false, true, document, configFile);
}
}
public boolean isAllowDonatePopup()
public boolean isAllowDonatePopup()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "allow-donate-popup", true, false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "allow-donate-popup", true, false, true, document, configFile);
}
}
//default getters
//default getters
public boolean getDefaultStartOnBoot()
public boolean getDefaultStartOnBoot()
{
{
return false;
return false;
}
}
public boolean getDefaultMinimiseToSystemTrayOnClose()
public boolean getDefaultMinimiseToSystemTrayOnClose()
{
{
return true;
return true;
}
}
//Setters
//Setters
//comms
//comms
public void setServerName(String name)
public void setServerName(String name)
{
{
getCommsElement().getElementsByTagName("name").item(0).setTextContent(name);
getCommsElement().getElementsByTagName("name").item(0).setTextContent(name);
}
}
public void setServerPort(int port)
public void setServerPort(int port)
{
{
getCommsElement().getElementsByTagName("port").item(0).setTextContent(port+"");
getCommsElement().getElementsByTagName("port").item(0).setTextContent(port+"");
}
}
//server
//server
public int getDefaultActionGridActionGap()
public int getDefaultActionGridActionGap()
{
{
return 5;
return 5;
}
}
public int getDefaultActionGridSize()
public int getDefaultActionGridSize()
{
{
return 100;
return 100;
}
}
public void setActionGridSize(int size)
public void setActionGridSize(int size)
{
{
getActionGridElement().getElementsByTagName("size").item(0).setTextContent(size+"");
getActionGridElement().getElementsByTagName("size").item(0).setTextContent(size+"");
}
}
public void setActionGridGap(int size)
public void setActionGridGap(int size)
{
{
getActionGridElement().getElementsByTagName("gap").item(0).setTextContent(size+"");
getActionGridElement().getElementsByTagName("gap").item(0).setTextContent(size+"");
}
}
public void setPluginsPath(String path)
public void setPluginsPath(String path)
{
{
document.getElementsByTagName("plugins-path").item(0).setTextContent(path);
document.getElementsByTagName("plugins-path").item(0).setTextContent(path);
}
}
public void setThemesPath(String path)
public void setThemesPath(String path)
{
{
document.getElementsByTagName("themes-path").item(0).setTextContent(path);
document.getElementsByTagName("themes-path").item(0).setTextContent(path);
}
}
public void setCurrentThemeFullName(String themeName)
public void setCurrentThemeFullName(String themeName)
{
{
document.getElementsByTagName("current-theme-full-name").item(0).setTextContent(themeName);
document.getElementsByTagName("current-theme-full-name").item(0).setTextContent(themeName);
}
}
//server > startup-window-size
//server > startup-window-size
public void setStartupWindowSize(double width, double height)
public void setStartupWindowSize(double width, double height)
{
{
setStartupWindowWidth(width);
setStartupWindowWidth(width);
setStartupWindowHeight(height);
setStartupWindowHeight(height);
}
}
public void setStartupWindowWidth(double width)
public void setStartupWindowWidth(double width)
{
{
getStartupWindowSizeElement().getElementsByTagName("width").item(0).setTextContent(width+"");
getStartupWindowSizeElement().getElementsByTagName("width").item(0).setTextContent(width+"");
}
}
public void setStartupWindowHeight(double height)
public void setStartupWindowHeight(double height)
{
{
getStartupWindowSizeElement().getElementsByTagName("height").item(0).setTextContent(height+"");
getStartupWindowSizeElement().getElementsByTagName("height").item(0).setTextContent(height+"");
}
}
//others
//others
public void setStartupOnBoot(boolean value)
public void setStartupOnBoot(boolean value)
{
{
getOthersElement().getElementsByTagName("start-on-boot").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("start-on-boot").item(0).setTextContent(value+"");
}
}
public void setMinimiseToSystemTrayOnClose(boolean value)
public void setMinimiseToSystemTrayOnClose(boolean value)
{
{
getOthersElement().getElementsByTagName("minimize-to-tray-on-close").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("minimize-to-tray-on-close").item(0).setTextContent(value+"");
}
}
public void setFirstTimeUse(boolean value)
public void setFirstTimeUse(boolean value)
{
{
getOthersElement().getElementsByTagName("first-time-use").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("first-time-use").item(0).setTextContent(value+"");
}
}
public void setAllowDonatePopup(boolean value)
public void setAllowDonatePopup(boolean value)
{
{
getOthersElement().getElementsByTagName("allow-donate-popup").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("allow-donate-popup").item(0).setTextContent(value+"");
}
}
public static void unzipToDefaultPrePath() throws Exception
public static void unzipToDefaultPrePath() throws Exception
{
{
IOHelper.unzip(Objects.requireNonNull(Main.class.getResourceAsStream("Default.zip")), ServerInfo.getInstance().getPrePath());
IOHelper.unzip(Objects.requireNonNull(Main.class.getResourceAsStream("Default.zip")), ServerInfo.getInstance().getPrePath());
Config config = Config.getInstance();
Config config = Config.getInstance();
config.setThemesPath(config.getDefaultThemesPath());
config.setThemesPath(config.getDefaultThemesPath());
config.setPluginsPath(config.getDefaultPluginsPath());
config.setPluginsPath(config.getDefaultPluginsPath());
if(SystemTray.isSupported())
if(SystemTray.isSupported())
{
{
config.setMinimiseToSystemTrayOnClose(true);
config.setMinimiseToSystemTrayOnClose(true);
}
}
config.save();
config.save();
}
}
public void setShowAlertsPopup(boolean value)
public void setShowAlertsPopup(boolean value)
{
{
getOthersElement().getElementsByTagName("alerts-popup").item(0).setTextContent(value+"");
getOthersElement().getElementsByTagName("alerts-popup").item(0).setTextContent(value+"");
}
}
public boolean isShowAlertsPopup()
public boolean isShowAlertsPopup()
{
{
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "alerts-popup", getDefaultIsShowAlertsPopup(), false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getOthersElement(), "alerts-popup", getDefaultIsShowAlertsPopup(), false, true, document, configFile);
}
}
public boolean getDefaultIsShowAlertsPopup()
public boolean getDefaultIsShowAlertsPopup()
{
{
return true;
return true;
}
}
public void setSoundOnActionClickedStatus(boolean value)
public void setSoundOnActionClickedStatus(boolean value)
{
{
getSoundOnActionClickedElement().getElementsByTagName("status").item(0).setTextContent(value+"");
getSoundOnActionClickedElement().getElementsByTagName("status").item(0).setTextContent(value+"");
}
}
public boolean getSoundOnActionClickedStatus()
public boolean getSoundOnActionClickedStatus()
{
{
return XMLConfigHelper.getBooleanProperty(getSoundOnActionClickedElement(), "status", getDefaultSoundOnActionClickedStatus(), false, true, document, configFile);
return XMLConfigHelper.getBooleanProperty(getSoundOnActionClickedElement(), "status", getDefaultSoundOnActionClickedStatus(), false, true, document, configFile);
}
}
public boolean getDefaultSoundOnActionClickedStatus()
public boolean getDefaultSoundOnActionClickedStatus()
{
{
return false;
return false;
}
}
public void setSoundOnActionClickedFilePath(String value)
public void setSoundOnActionClickedFilePath(String value)
{
{
getSoundOnActionClickedElement().getElementsByTagName("file-path").item(0).setTextContent(value);
getSoundOnActionClickedElement().getElementsByTagName("file-path").item(0).setTextContent(value);
}
}
public String getSoundOnActionClickedFilePath()
public String getSoundOnActionClickedFilePath()
{
{
return XMLConfigHelper.getStringProperty(getSoundOnActionClickedElement(), "file-path", getDefaultSoundOnActionClickedFilePath(), false, true, document, configFile);
return XMLConfigHelper.getStringProperty(getSoundOnActionClickedElement(), "file-path", getDefaultSoundOnActionClickedFilePath(), false, true, document, configFile);
}
}
public String getDefaultSoundOnActionClickedFilePath()
public String getDefaultSoundOnActionClickedFilePath()
{
{
return null; //To be replaced with a real default beep sound later.
return null; //To be replaced with a real default beep sound later.
}
}
}
}
package com.stream_pi.server.window.dashboard;
package com.stream_pi.server.window.dashboard;
import java.util.logging.Logger;
import java.util.logging.Logger;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionGridPane;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionGridPane;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPane;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPane;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Orientation;
import javafx.geometry.Orientation;
import javafx.scene.control.SplitPane;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class DashboardBase extends SplitPane implements DashboardInterface {
public class DashboardBase extends SplitPane implements DashboardInterface {
private final SplitPane leftSplitPane;
private final SplitPane leftSplitPane;
private Logger logger;
private Logger logger;
public ClientProfile currentClientProfile;
public ClientProfile currentClientProfile;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public DashboardBase(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
public DashboardBase(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
{
{
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
logger = Logger.getLogger(DashboardBase.class.getName());
logger = Logger.getLogger(DashboardBase.class.getName());
leftSplitPane = new SplitPane();
leftSplitPane = new SplitPane();
leftSplitPane.getStyleClass().add("dashboard_left_split_pane");
leftSplitPane.getStyleClass().add("dashboard_left_split_pane");
leftSplitPane.setOrientation(Orientation.VERTICAL);
leftSplitPane.setOrientation(Orientation.VERTICAL);
getStyleClass().add("dashboard_right_split_pane");
getStyleClass().add("dashboard_right_split_pane");
getItems().add(leftSplitPane);
getItems().add(leftSplitPane);
setPluginsPane(new PluginsPane(hostServices));
setPluginsPane(new PluginsPane(hostServices));
setClientDetailsPane(new ClientAndProfileSelectorPane(this));
setClientDetailsPane(new ClientAndProfileSelectorPane(this));
setActionGridPane(new ActionGridPane(exceptionAndAlertHandler));
setActionGridPane(new ActionGridPane(exceptionAndAlertHandler));
setActionDetailsPane(new ActionDetailsPane(exceptionAndAlertHandler, hostServices, getActionGridPane()));
setActionDetailsPane(new ActionDetailsPane(exceptionAndAlertHandler, hostServices, getActionGridPane()));
getActionGridPane().setActionDetailsPaneListener(getActionDetailsPane());
getActionGridPane().setActionDetailsPaneListener(getActionDetailsPane());
}
}
private PluginsPane pluginsPane;
private PluginsPane pluginsPane;
private void setPluginsPane(PluginsPane pluginsPane)
private void setPluginsPane(PluginsPane pluginsPane)
{
{
this.pluginsPane = pluginsPane;
this.pluginsPane = pluginsPane;
getItems().add(this.pluginsPane);
getItems().add(this.pluginsPane);
}
}
public PluginsPane getPluginsPane()
public PluginsPane getPluginsPane()
{
{
return pluginsPane;
return pluginsPane;
}
}
private ClientAndProfileSelectorPane clientAndProfileSelectorPane;
private ClientAndProfileSelectorPane clientAndProfileSelectorPane;
private void setClientDetailsPane(ClientAndProfileSelectorPane clientAndProfileSelectorPane)
private void setClientDetailsPane(ClientAndProfileSelectorPane clientAndProfileSelectorPane)
{
{
this.clientAndProfileSelectorPane = clientAndProfileSelectorPane;
this.clientAndProfileSelectorPane = clientAndProfileSelectorPane;
leftSplitPane.getItems().add(this.clientAndProfileSelectorPane);
leftSplitPane.getItems().add(this.clientAndProfileSelectorPane);
}
}
public ClientAndProfileSelectorPane getClientAndProfileSelectorPane()
public ClientAndProfileSelectorPane getClientAndProfileSelectorPane()
{
{
return clientAndProfileSelectorPane;
return clientAndProfileSelectorPane;
}
}
private ActionGridPane actionGridPane;
private ActionGridPane actionGridPane;
private void setActionGridPane(ActionGridPane actionGridPane)
private void setActionGridPane(ActionGridPane actionGridPane)
{
{
this.actionGridPane = actionGridPane;
this.actionGridPane = actionGridPane;
leftSplitPane.getItems().add(this.actionGridPane);
leftSplitPane.getItems().add(this.actionGridPane);
}
}
public ActionGridPane getActionGridPane()
public ActionGridPane getActionGridPane()
{
{
return actionGridPane;
return actionGridPane;
}
}
private ActionDetailsPane actionDetailsPane;
private ActionDetailsPane actionDetailsPane;
private void setActionDetailsPane(ActionDetailsPane actionDetailsPane)
private void setActionDetailsPane(ActionDetailsPane actionDetailsPane)
{
{
this.actionDetailsPane = actionDetailsPane;
this.actionDetailsPane = actionDetailsPane;
leftSplitPane.getItems().add(this.actionDetailsPane);
leftSplitPane.getItems().add(this.actionDetailsPane);
}
}
public ActionDetailsPane getActionDetailsPane()
public ActionDetailsPane getActionDetailsPane()
{
{
return actionDetailsPane;
return actionDetailsPane;
}
}
public void newSelectedClientConnection(ClientConnection clientConnection)
public void newSelectedClientConnection(ClientConnection clientConnection)
{
{
if(clientConnection == null)
if(clientConnection == null)
{
{
logger.info("Remove action grid");
logger.info("Remove action grid");
}
}
else
else
{
{
getActionDetailsPane().setClientConnection(clientConnection);
getActionDetailsPane().setClientConnection(clientConnection);
getActionGridPane().setClientConnection(clientConnection);
getActionGridPane().setClientConnection(clientConnection);
}
}
}
}
public void newSelectedClientProfile(ClientProfile clientProfile)
public void newSelectedClientProfile(ClientProfile clientProfile)
{
{
this.currentClientProfile = clientProfile;
this.currentClientProfile = clientProfile;
getActionDetailsPane().setClientProfile(clientProfile);
getActionDetailsPane().setClientProfile(clientProfile);
drawProfile(this.currentClientProfile);
drawProfile(this.currentClientProfile);
}
}
public void reDrawProfile()
{
drawProfile(getActionGridPane().getCurrentProfile());
}
public void drawProfile(ClientProfile clientProfile)
public void drawProfile(ClientProfile clientProfile)
{
{
logger.info("Drawing ...");
logger.info("Drawing ...");
getActionGridPane().setClientProfile(clientProfile);
getActionGridPane().setClientProfile(clientProfile);
try
try
{
{
getActionGridPane().setFreshRender(true);
getActionGridPane().setFreshRender(true);
getActionGridPane().renderGrid();
getActionGridPane().renderGrid();
getActionGridPane().renderActions();
getActionGridPane().renderActions();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
public SplitPane getLeftSplitPane()
public SplitPane getLeftSplitPane()
{
{
return leftSplitPane;
return leftSplitPane;
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.CombineAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.action_api.otheractions.FolderAction;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.action.ExternalPlugins;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
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.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.HashMap;
import java.util.HashMap;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ActionDetailsPaneListener actionDetailsPaneListener;
private ActionDetailsPaneListener actionDetailsPaneListener;
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
logger = Logger.getLogger(ActionGridPane.class.getName());
logger = Logger.getLogger(ActionGridPane.class.getName());
actionBoxHashMap = new HashMap<>();
actionBoxHashMap = new HashMap<>();
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
getStyleClass().add("action_grid_pane_parent");
getStyleClass().add("action_grid_pane_parent");
actionsGridPane = new GridPane();
actionsGridPane = new GridPane();
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
setContent(actionsGridPane);
setContent(actionsGridPane);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
private HashMap<String, ActionBox> actionBoxHashMap;
private HashMap<String, ActionBox> actionBoxHashMap;
public ActionBox getActionBoxByIDAndProfileID(String actionID, String profileID)
public ActionBox getActionBoxByIDAndProfileID(String actionID, String profileID)
{
{
// Returns null when there is no such action available
// Returns null when there is no such action available
if(getClientProfile() == null)
if(getClientProfile() == null)
{
{
return null;
return null;
}
}
if(!getClientProfile().getID().equals(profileID))
if(!getClientProfile().getID().equals(profileID))
{
{
return null;
return null;
}
}
return actionBoxHashMap.getOrDefault(actionID, null);
return actionBoxHashMap.getOrDefault(actionID, null);
}
}
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
}
}
private String currentParent = null;
private String currentParent = null;
@Override
@Override
public ExternalPlugin createNewActionFromExternalPlugin(String moduleName) throws Exception
public ExternalPlugin createNewActionFromExternalPlugin(String moduleName) throws Exception
{
{
ExternalPlugin newAction = ExternalPlugins.getInstance().getPluginByModuleName(moduleName).clone();
ExternalPlugin newAction = ExternalPlugins.getInstance().getPluginByModuleName(moduleName).clone();
if(newAction.getActionType() == ActionType.TOGGLE)
if(newAction.getActionType() == ActionType.TOGGLE)
{
{
newAction.setCurrentIconState("false__false");
newAction.setCurrentIconState("false__false");
}
}
newAction.setIDRandom();
newAction.setIDRandom();
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayText("Untitled Action");
newAction.setDisplayText("Untitled Action");
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setBgColourHex("");
newAction.setBgColourHex("");
newAction.setDisplayTextFontColourHex("");
newAction.setDisplayTextFontColourHex("");
return newAction;
return newAction;
}
}
@Override
@Override
public Action createNewOtherAction(ActionType actionType) throws Exception
public Action createNewOtherAction(ActionType actionType) throws Exception
{
{
Action newAction;
Action newAction;
String displayText;
String displayText;
if(actionType == ActionType.FOLDER)
if(actionType == ActionType.FOLDER)
{
{
displayText = "Untitled Folder";
displayText = "Untitled Folder";
newAction = new FolderAction();
newAction = new FolderAction();
}
}
else if(actionType == ActionType.COMBINE)
else if(actionType == ActionType.COMBINE)
{
{
displayText = "Untitled Combine";
displayText = "Untitled Combine";
newAction = new CombineAction();
newAction = new CombineAction();
}
}
else
else
throw new IllegalArgumentException("External Plugins are not supported here!");
throw new IllegalArgumentException("External Plugins are not supported here!");
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.setBgColourHex("");
newAction.setBgColourHex("");
newAction.setDisplayTextFontColourHex("");
newAction.setDisplayTextFontColourHex("");
return newAction;
return newAction;
}
}
@Override
@Override
public void setCurrentParent(String currentParent) {
public void setCurrentParent(String currentParent) {
this.currentParent = currentParent;
this.currentParent = currentParent;
}
}
@Override
@Override
public ClientConnection getClientConnection() {
public ClientConnection getClientConnection() {
return clientConnection;
return clientConnection;
}
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
private ClientConnection clientConnection;
private ClientConnection clientConnection;
public void setClientConnection(ClientConnection clientConnection)
public void setClientConnection(ClientConnection clientConnection)
{
{
this.clientConnection = clientConnection;
this.clientConnection = clientConnection;
}
}
public Client getClient() {
public Client getClient() {
return getClientConnection().getClient();
return getClientConnection().getClient();
}
}
private int rows, cols;
private int rows, cols;
private GridPane actionsGridPane;
private GridPane actionsGridPane;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClientProfile(ClientProfile clientProfile)
public void setClientProfile(ClientProfile clientProfile)
{
{
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
setCurrentParent("root");
setCurrentParent("root");
setRows(clientProfile.getRows());
setRows(clientProfile.getRows());
setCols(clientProfile.getCols());
setCols(clientProfile.getCols());
}
}
@Override
@Override
public String getCurrentParent() {
public String getCurrentParent() {
return currentParent;
return currentParent;
}
}
@Override
@Override
public ClientProfile getCurrentProfile() {
public ClientProfile getCurrentProfile() {
return clientProfile;
return clientProfile;
}
}
public StackPane getFolderBackButton() throws SevereException
public StackPane getFolderBackButton() throws SevereException
{
{
StackPane stackPane = new StackPane();
StackPane stackPane = new StackPane();
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box_valid");
stackPane.getStyleClass().add("action_box_valid");
stackPane.setPrefSize(
stackPane.setPrefSize(
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize()
Config.getInstance().getActionGridActionSize()
);
);
FontIcon fontIcon = new FontIcon("fas-chevron-left");
FontIcon fontIcon = new FontIcon("fas-chevron-left");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.setIconSize((int) (Config.getInstance().getActionGridActionSize() * 0.8));
fontIcon.setIconSize((int) (Config.getInstance().getActionGridActionSize() * 0.8));
stackPane.setAlignment(Pos.CENTER);
stackPane.setAlignment(Pos.CENTER);
stackPane.getChildren().add(fontIcon);
stackPane.getChildren().add(fontIcon);
stackPane.setOnMouseClicked(e->returnToPreviousParent());
stackPane.setOnMouseClicked(e->returnToPreviousParent());
return stackPane;
return stackPane;
}
}
private ActionBox[][] actionBoxes;
private ActionBox[][] actionBoxes;
private boolean isFreshRender = true;
private boolean isFreshRender = true;
private Node folderBackButton = null;
private Node folderBackButton = null;
public void renderGrid() throws SevereException
public void renderGrid() throws SevereException
{
{
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
if(isFreshRender)
if(isFreshRender)
{
{
clear();
clear();
actionBoxes = new ActionBox[cols][rows];
actionBoxes = new ActionBox[cols][rows];
}
}
boolean isFolder = false;
boolean isFolder = false;
if(getCurrentParent().equals("root"))
if(getCurrentParent().equals("root"))
{
{
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
actionBoxes[0][0] = addBlankActionBox(0,0);
actionBoxes[0][0] = addBlankActionBox(0,0);
}
}
}
}
else
else
{
{
isFolder = true;
isFolder = true;
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
}
}
else
else
{
{
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
}
}
folderBackButton = getFolderBackButton();
folderBackButton = getFolderBackButton();
actionsGridPane.add(folderBackButton, 0,0);
actionsGridPane.add(folderBackButton, 0,0);
}
}
for(int row = 0; row<rows; row++)
for(int row = 0; row<rows; row++)
{
{
for(int col = 0; col<cols; col++)
for(int col = 0; col<cols; col++)
{
{
if(row == 0 && col == 0 && isFolder)
if(row == 0 && col == 0 && isFolder)
continue;
continue;
if(isFreshRender)
if(isFreshRender)
{
{
actionBoxes[col][row] = addBlankActionBox(col, row);
actionBoxes[col][row] = addBlankActionBox(col, row);
}
}
else
else
{
{
if(actionBoxes[col][row].getAction() != null)
if(actionBoxes[col][row].getAction() != null)
{
{
actionBoxes[col][row].clear();
actionBoxes[col][row].clear();
}
}
}
}
}
}
}
}
isFreshRender = false;
isFreshRender = false;
}
}
public void setFreshRender(boolean freshRender)
public void setFreshRender(boolean freshRender)
{
{
isFreshRender = freshRender;
isFreshRender = freshRender;
}
}
public ActionBox addBlankActionBox(int col, int row) throws SevereException {
public ActionBox addBlankActionBox(int col, int row) throws SevereException
{
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this,
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this,
col, row);
col, row);
actionsGridPane.add(actionBox, col, row);
if(getClient().getOrientation() == Orientation.HORIZONTAL)
{
actionsGridPane.add(actionBox, col, row);
}
else
{
actionsGridPane.add(actionBox, row, col);
}
return actionBox;
return actionBox;
}
}
public void renderActions()
public void renderActions()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(String action1x : getClientProfile().getActionsKeySet())
for(String action1x : getClientProfile().getActionsKeySet())
{
{
Action eachAction = getClientProfile().getActionByID(action1x);
Action eachAction = getClientProfile().getActionByID(action1x);
logger.info("action ID : "+eachAction.getID()+
logger.info("action ID : "+eachAction.getID()+
"\nInvalid : "+eachAction.isInvalid());
"\nInvalid : "+eachAction.isInvalid());
try {
try {
renderAction(eachAction);
renderAction(eachAction);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
errors.append("*").append(e.getShortMessage()).append("\n");
errors.append("*").append(e.getShortMessage()).append("\n");
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
}
}
}
}
public void clear()
public void clear()
{
{
actionBoxHashMap.clear();
actionBoxHashMap.clear();
actionsGridPane.getChildren().clear();
actionsGridPane.getChildren().clear();
}
}
private Logger logger;
private Logger logger;
public void renderAction(Action action) throws SevereException, MinorException
public void renderAction(Action action) throws SevereException, MinorException
{
{
if(!action.getParent().equals(currentParent))
if(!action.getParent().equals(currentParent))
{
{
logger.info("Skipping action "+action.getID()+", not current parent!");
logger.info("Skipping action "+action.getID()+", not current parent!");
return;
return;
}
}
if(action.getLocation().getRow()==-1)
if(action.getLocation().getRow()==-1)
{
{
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
return;
return;
}
}
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
{
{
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
" Consider increasing rows/cols from client settings and relocating/deleting it.");
" Consider increasing rows/cols from client settings and relocating/deleting it.");
}
}
Location location = action.getLocation();
Location location = action.getLocation();
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
actionBox.clear();
actionBox.clear();
actionBox.setAction(action);
actionBox.setAction(action);
actionBox.init();
actionBox.init();
actionBoxHashMap.put(action.getID(), actionBox);
actionBoxHashMap.put(action.getID(), actionBox);
/*ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
/*ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
Location location = action.getLocation();
Location location = action.getLocation();
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
actionBox.setRow(location.getRow());
actionBox.setRow(location.getRow());
actionBox.setCol(location.getCol());
actionBox.setCol(location.getCol());
for(Node node : actionsGridPane.getChildren())
for(Node node : actionsGridPane.getChildren())
{
{
if(GridPane.getColumnIndex(node) == location.getRow() &&
if(GridPane.getColumnIndex(node) == location.getRow() &&
GridPane.getRowIndex(node) == location.getCol())
GridPane.getRowIndex(node) == location.getCol())
{
{
actionsGridPane.getChildren().remove(node);
actionsGridPane.getChildren().remove(node);
break;
break;
}
}
}
}
System.out.println(location.getCol()+","+location.getRow());
System.out.println(location.getCol()+","+location.getRow());
actionsGridPane.add(actionBox, location.getRow(), location.getCol());*/
actionsGridPane.add(actionBox, location.getRow(), location.getCol());*/
}
}
public void setRows(int rows)
public void setRows(int rows)
{
{
this.rows = rows;
this.rows = rows;
}
}
public void setCols(int cols)
public void setCols(int cols)
{
{
this.cols = cols;
this.cols = cols;
}
}
public int getRows()
public int getRows()
{
{
return rows;
return rows;
}
}
public int getCols()
public int getCols()
{
{
return cols;
return cols;
}
}
@Override
@Override
public void addActionToCurrentClientProfile(Action newAction) {
public void addActionToCurrentClientProfile(Action newAction) {
try {
try {
getClientProfile().addAction(newAction);
getClientProfile().addAction(newAction);
} catch (CloneNotSupportedException e) {
} catch (CloneNotSupportedException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private String previousParent;
private String previousParent;
public void setPreviousParent(String previousParent) {
public void setPreviousParent(String previousParent) {
this.previousParent = previousParent;
this.previousParent = previousParent;
}
}
public String getPreviousParent() {
public String getPreviousParent() {
return previousParent;
return previousParent;
}
}
@Override
@Override
public void renderFolder(FolderAction action) {
public void renderFolder(FolderAction action) {
setCurrentParent(action.getID());
setCurrentParent(action.getID());
setPreviousParent(action.getParent());
setPreviousParent(action.getParent());
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void returnToPreviousParent()
public void returnToPreviousParent()
{
{
setCurrentParent(getPreviousParent());
setCurrentParent(getPreviousParent());
if(!getPreviousParent().equals("root"))
if(!getPreviousParent().equals("root"))
{
{
System.out.println("parent : "+getPreviousParent());
System.out.println("parent : "+getPreviousParent());
setPreviousParent(getClientProfile().getActionByID(
setPreviousParent(getClientProfile().getActionByID(
getPreviousParent()
getPreviousParent()
).getParent());
).getParent());
}
}
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}