server

Clone or download

Refactored, and added style classes

Modified Files

M pom.xml
+5 −2
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stream_pi</groupId>
<groupId>com.stream_pi</groupId>
<artifactId>server</artifactId>
<artifactId>server</artifactId>
<version>1.0.0</version>
<version>1.0.0</version>
<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.target>11</maven.compiler.target>
<client.plugin.version>0.1.35</client.plugin.version>
<client.plugin.version>0.1.36</client.plugin.version>
<JavaFXVersion>16-ea+6</JavaFXVersion>
<JavaFXVersion>16-ea+6</JavaFXVersion>
<CommonsBeanUtilsVersion>1.9.4</CommonsBeanUtilsVersion>
<CommonsBeanUtilsVersion>1.9.4</CommonsBeanUtilsVersion>
<CommonsConfigurationVersion>2.7</CommonsConfigurationVersion>
<CommonsConfigurationVersion>2.7</CommonsConfigurationVersion>
<ActionAPIVersion>1.0.0</ActionAPIVersion>
<ActionAPIVersion>1.0.0</ActionAPIVersion>
<ThemeAPIVersion>1.0.0</ThemeAPIVersion>
<ThemeAPIVersion>1.0.0</ThemeAPIVersion>
<UtilVersion>1.0.0</UtilVersion>
<UtilVersion>1.0.0</UtilVersion>
<!--CommAPIVersion>1.0.0</CommAPIVersion-->
<!--CommAPIVersion>1.0.0</CommAPIVersion-->
<Log4JVersion>2.14.0</Log4JVersion>
<Log4JVersion>2.14.0</Log4JVersion>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<MainClassName>com.stream_pi.server.Main</MainClassName>
<MainClassName>com.stream_pi.server.Main</MainClassName>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<artifactId>javafx-controls</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-media</artifactId>
<artifactId>javafx-media</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${IkonliFA5PackVersion}</version>
<version>${IkonliFA5PackVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<artifactId>ikonli-javafx</artifactId>
<version>${IkonliVersion}</version>
<version>${IkonliVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<artifactId>javafx-base</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream_pi</groupId>
<groupId>com.stream_pi</groupId>
<artifactId>action_api</artifactId>
<artifactId>action_api</artifactId>
<version>${ActionAPIVersion}</version>
<version>${ActionAPIVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream_pi</groupId>
<groupId>com.stream_pi</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>${UtilVersion}</version>
<version>${UtilVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>com.stream_pi</groupId>
<groupId>com.stream_pi</groupId>
<artifactId>themeapi</artifactId>
<artifactId>themeapi</artifactId>
<version>${ThemeAPIVersion}</version>
<version>${ThemeAPIVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.json</groupId>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<artifactId>json</artifactId>
<version>20201115</version>
<version>20201115</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
<repositories>
<repositories>
<repository>
<repository>
<id>gluon-releases</id>
<id>gluon-releases</id>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
</repository>
</repository>
</repositories>
</repositories>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.8.1</version>
<configuration>
<configuration>
<release>11</release>
<release>11</release>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.5</version>
<version>0.0.5</version>
<configuration>
<configuration>
<commandlineArgs>-DStreamPi.startupRunnerFileName=run_min -DStreamPi.startupMode=maximise</commandlineArgs>
<commandlineArgs>-DStreamPi.startupRunnerFileName=run_min -DStreamPi.startupMode=maximise</commandlineArgs>
<options>
<options>
<option>-Dglass.gtk.uiScale=1.0</option>
<option>-Dglass.gtk.uiScale=1.0</option>
</options>
</options>
<mainClass>${MainClassName}</mainClass>
<mainClass>${MainClassName}</mainClass>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>com.gluonhq</groupId>
<groupId>com.gluonhq</groupId>
<artifactId>client-maven-plugin</artifactId>
<artifactId>client-maven-plugin</artifactId>
<version>${client.plugin.version}</version>
<version>${client.plugin.version}</version>
<configuration>
<configuration>
<nativeImageArgs>
<list>--initialize-at-build-time=com.sun.org.apache.xml.internal.serializer.ToXMLStream</list>
<!--list>-Dsvm.targetName=android</list-->
</nativeImageArgs>
<bundlesList>
<bundlesList>
<list>com.sun.org.apache.xerces.internal.impl.msg.XMLMessages</list>
<list>com.sun.org.apache.xerces.internal.impl.msg.XMLMessages</list>
</bundlesList>
</bundlesList>
<reflectionList>
<reflectionList>
<list>java.util.logging.FileHandler</list>
<list>java.util.logging.FileHandler</list>
</reflectionList>
</reflectionList>
<nativeImageArgs>--report-unsupported-elements-at-runtime,--initialize-at-build-time=com.sun.org.apache.xml.internal.serializer.ToXMLStream,-Dsvm.targetname=android,--enable-https,--enable-http,-H:Log=registerResource</nativeImageArgs>
<mainClass>${MainClassName}</mainClass>
<mainClass>${MainClassName}</mainClass>
</configuration>
</configuration>
</plugin>
</plugin>
<plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<version>3.2.0</version>
<configuration>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
<includeEmptyDirs>true</includeEmptyDirs>
</configuration>
</configuration>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
<pluginRepositories>
<pluginRepositories>
<pluginRepository>
<pluginRepository>
<id>gluon-releases</id>
<id>gluon-releases</id>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
<url>http://nexus.gluonhq.com/nexus/content/repositories/releases/</url>
</pluginRepository>
</pluginRepository>
<pluginRepository>
<pluginRepository>
<id>gluon-snapshots</id>
<id>gluon-snapshots</id>
<url>https://nexus.gluonhq.com/nexus/content/repositories/public-snapshots</url>
<url>https://nexus.gluonhq.com/nexus/content/repositories/public-snapshots</url>
</pluginRepository>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
</project>
</project>
package com.stream_pi.server.window.dashboard;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnections;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.CacheHint;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
public class ClientAndProfileSelectorPane extends HBox {
private DashboardInterface dashboard;
public ClientAndProfileSelectorPane(DashboardInterface dashboard)
{
this.dashboard = dashboard;
VBox.setVgrow(this, Priority.NEVER);
getStyleClass().add("client_and_profile_selector_pane");
setPadding(new Insets(10));
setMinHeight(90);
initUI();
loadData();
setCache(true);
setCacheHint(CacheHint.SPEED);
}
private ComboBox<ClientConnection> clientsComboBox;
private Label noClientsConnectedLabel;
private ComboBox<ClientProfile> clientProfilesComboBox;
public void initUI()
{
noClientsConnectedLabel = new Label("No Clients Connected");
noClientsConnectedLabel.getStyleClass().add("client_and_profile_selector_pane_no_clients_connected_label");
noClientsConnectedLabel.managedProperty().bind(noClientsConnectedLabel.visibleProperty());
clientsComboBox = new ComboBox<>();
clientsComboBox.getStyleClass().add("client_and_profile_selector_pane_client_selector_combo_box");
clientsComboBox.setPromptText("Choose client");
clientsComboBox.valueProperty().addListener((observableValue, oldVal, newVal) -> {
if(oldVal!=newVal && newVal!=null)
{
dashboard.newSelectedClientConnection(newVal);
clientProfilesComboBox.setItems(FXCollections.observableArrayList(newVal.getClient().getAllClientProfiles()));
clientProfilesComboBox.setVisible(true);
}
});
clientsComboBox.managedProperty().bind(clientsComboBox.visibleProperty());
Callback<ListView<ClientConnection>, ListCell<ClientConnection>> clientsComboBoxFactory = new Callback<>() {
@Override
public ListCell<ClientConnection> call(ListView<ClientConnection> clientConnectionListView) {
return new ListCell<>() {
@Override
protected void updateItem(ClientConnection clientConnection, boolean b) {
super.updateItem(clientConnection, b);
if(clientConnection == null)
{
setText("Choose client");
}
else
{
Client client = clientConnection.getClient();
setText(client.getNickName());
}
}
};
}
};
clientsComboBox.setCellFactory(clientsComboBoxFactory);
clientsComboBox.setButtonCell(clientsComboBoxFactory.call(null));
clientProfilesComboBox = new ComboBox<>();
clientProfilesComboBox.getStyleClass().add("client_and_profile_selector_pane_profile_selector_combo_box");
clientProfilesComboBox.setPromptText("Choose Profile");
clientProfilesComboBox.valueProperty().addListener((observableValue, oldVal, newVal) -> {
if(oldVal!=newVal && newVal!=null)
{
dashboard.newSelectedClientProfile(newVal);
}
});
clientProfilesComboBox.managedProperty().bind(clientProfilesComboBox.visibleProperty());
Callback<ListView<ClientProfile>, ListCell<ClientProfile>> clientProfilesComboBoxFactory = new Callback<ListView<ClientProfile>, ListCell<ClientProfile>>() {
@Override
public ListCell<ClientProfile> call(ListView<ClientProfile> clientProfileListView) {
return new ListCell<>()
{
@Override
protected void updateItem(ClientProfile profile, boolean b) {
super.updateItem(profile, b);
if(profile == null)
{
setText("Choose Profile");
}
else
{
setText(profile.getName());
}
}
};
}
};
clientProfilesComboBox.setCellFactory(clientProfilesComboBoxFactory);
clientProfilesComboBox.setButtonCell(clientProfilesComboBoxFactory.call(null));
VBox stack = new VBox(noClientsConnectedLabel, clientsComboBox, clientProfilesComboBox);
stack.getStyleClass().add("client_and_profile_selector_pane_stack");
getChildren().addAll(stack);
}
private void loadData()
{
clientsComboBox.getSelectionModel().clearSelection();
clientProfilesComboBox.getSelectionModel().clearSelection();
if(ClientConnections.getInstance().getConnections().size() == 0)
{
noClientsConnectedLabel.setVisible(true);
clientsComboBox.setVisible(false);
clientProfilesComboBox.setVisible(false);
dashboard.newSelectedClientConnection(null);
}
else
{
noClientsConnectedLabel.setVisible(false);
clientsComboBox.setVisible(true);
clientProfilesComboBox.setVisible(false);
clientsComboBox.setItems(FXCollections.observableArrayList(ClientConnections.getInstance().getConnections()));
}
}
public void refresh()
{
loadData();
}
}
package com.stream_pi.server.window.dashboard;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnections;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.scene.CacheHint;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
public class ClientDetailsPane extends HBox {
private DashboardInterface dashboard;
public ClientDetailsPane(DashboardInterface dashboard)
{
this.dashboard = dashboard;
VBox.setVgrow(this, Priority.NEVER);
getStyleClass().add("client_details_pane");
setPadding(new Insets(10));
setMinHeight(90);
initUI();
loadData();
setCache(true);
setCacheHint(CacheHint.SPEED);
}
private ComboBox<ClientConnection> clientsComboBox;
private Label noClientsConnectedLabel;
private ComboBox<ClientProfile> clientProfilesComboBox;
public void initUI()
{
noClientsConnectedLabel = new Label("No Clients Connected");
noClientsConnectedLabel.managedProperty().bind(noClientsConnectedLabel.visibleProperty());
clientsComboBox = new ComboBox<>();
clientsComboBox.setPromptText("Choose client");
clientsComboBox.valueProperty().addListener((observableValue, oldVal, newVal) -> {
if(oldVal!=newVal && newVal!=null)
{
dashboard.newSelectedClientConnection(newVal);
clientProfilesComboBox.setItems(FXCollections.observableArrayList(newVal.getClient().getAllClientProfiles()));
clientProfilesComboBox.setVisible(true);
}
});
clientsComboBox.managedProperty().bind(clientsComboBox.visibleProperty());
Callback<ListView<ClientConnection>, ListCell<ClientConnection>> clientsComboBoxFactory = new Callback<>() {
@Override
public ListCell<ClientConnection> call(ListView<ClientConnection> clientConnectionListView) {
return new ListCell<>() {
@Override
protected void updateItem(ClientConnection clientConnection, boolean b) {
super.updateItem(clientConnection, b);
if(clientConnection == null)
{
setText("Choose client");
}
else
{
Client client = clientConnection.getClient();
setText(client.getNickName());
}
}
};
}
};
clientsComboBox.setCellFactory(clientsComboBoxFactory);
clientsComboBox.setButtonCell(clientsComboBoxFactory.call(null));
clientProfilesComboBox = new ComboBox<>();
clientProfilesComboBox.setPromptText("Choose Profile");
clientProfilesComboBox.valueProperty().addListener((observableValue, oldVal, newVal) -> {
if(oldVal!=newVal && newVal!=null)
{
dashboard.newSelectedClientProfile(newVal);
}
});
clientProfilesComboBox.managedProperty().bind(clientProfilesComboBox.visibleProperty());
Callback<ListView<ClientProfile>, ListCell<ClientProfile>> clientProfilesComboBoxFactory = new Callback<ListView<ClientProfile>, ListCell<ClientProfile>>() {
@Override
public ListCell<ClientProfile> call(ListView<ClientProfile> clientProfileListView) {
return new ListCell<>()
{
@Override
protected void updateItem(ClientProfile profile, boolean b) {
super.updateItem(profile, b);
if(profile == null)
{
setText("Choose Profile");
}
else
{
setText(profile.getName());
}
}
};
}
};
clientProfilesComboBox.setCellFactory(clientProfilesComboBoxFactory);
clientProfilesComboBox.setButtonCell(clientProfilesComboBoxFactory.call(null));
VBox stack = new VBox(noClientsConnectedLabel, clientsComboBox, clientProfilesComboBox);
stack.setSpacing(10);
getChildren().addAll(stack);
}
private void loadData()
{
clientsComboBox.getSelectionModel().clearSelection();
clientProfilesComboBox.getSelectionModel().clearSelection();
if(ClientConnections.getInstance().getConnections().size() == 0)
{
noClientsConnectedLabel.setVisible(true);
clientsComboBox.setVisible(false);
clientProfilesComboBox.setVisible(false);
dashboard.newSelectedClientConnection(null);
}
else
{
noClientsConnectedLabel.setVisible(false);
clientsComboBox.setVisible(true);
clientProfilesComboBox.setVisible(false);
clientsComboBox.setItems(FXCollections.observableArrayList(ClientConnections.getInstance().getConnections()));
}
}
public void refresh()
{
loadData();
}
}
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.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 HBox implements DashboardInterface {
public class DashboardBase extends HBox implements DashboardInterface {
private final VBox leftPane;
private final VBox leftPane;
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());
leftPane = new VBox();
leftPane = new VBox();
HBox.setHgrow(leftPane, Priority.ALWAYS);
HBox.setHgrow(leftPane, Priority.ALWAYS);
getChildren().add(leftPane);
getChildren().add(leftPane);
setPluginsPane(new PluginsPane(hostServices));
setPluginsPane(new PluginsPane(hostServices));
setClientDetailsPane(new ClientDetailsPane(this));
setClientDetailsPane(new ClientAndProfileSelectorPane(this));
setActionGridPane(new ActionGridPane(exceptionAndAlertHandler));
setActionGridPane(new ActionGridPane(exceptionAndAlertHandler));
setActionDetailsPane(new ActionDetailsPane(exceptionAndAlertHandler, hostServices));
setActionDetailsPane(new ActionDetailsPane(exceptionAndAlertHandler, hostServices));
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;
getChildren().add(this.pluginsPane);
getChildren().add(this.pluginsPane);
}
}
public PluginsPane getPluginsPane()
public PluginsPane getPluginsPane()
{
{
return pluginsPane;
return pluginsPane;
}
}
private ClientDetailsPane clientDetailsPane;
private ClientAndProfileSelectorPane clientAndProfileSelectorPane;
private void setClientDetailsPane(ClientDetailsPane clientDetailsPane)
private void setClientDetailsPane(ClientAndProfileSelectorPane clientAndProfileSelectorPane)
{
{
this.clientDetailsPane = clientDetailsPane;
this.clientAndProfileSelectorPane = clientAndProfileSelectorPane;
leftPane.getChildren().add(this.clientDetailsPane);
leftPane.getChildren().add(this.clientAndProfileSelectorPane);
}
}
public ClientDetailsPane getClientDetailsPane()
public ClientAndProfileSelectorPane getClientDetailsPane()
{
{
return clientDetailsPane;
return clientAndProfileSelectorPane;
}
}
private ActionGridPane actionGridPane;
private ActionGridPane actionGridPane;
private void setActionGridPane(ActionGridPane actionGridPane)
private void setActionGridPane(ActionGridPane actionGridPane)
{
{
this.actionGridPane = actionGridPane;
this.actionGridPane = actionGridPane;
leftPane.getChildren().add(this.actionGridPane);
leftPane.getChildren().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;
leftPane.getChildren().add(this.actionDetailsPane);
leftPane.getChildren().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().setClient(clientConnection.getClient());
getActionDetailsPane().setClient(clientConnection.getClient());
getActionGridPane().setClient(clientConnection.getClient());
getActionGridPane().setClient(clientConnection.getClient());
}
}
}
}
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 drawProfile(ClientProfile clientProfile)
public void drawProfile(ClientProfile clientProfile)
{
{
logger.info("Drawing ...");
logger.info("Drawing ...");
getActionGridPane().setClientProfile(clientProfile);
getActionGridPane().setClientProfile(clientProfile);
try {
try {
getActionGridPane().renderGrid();
getActionGridPane().renderGrid();
getActionGridPane().renderActions();
getActionGridPane().renderActions();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
}
}
}
}
package com.stream_pi.server.window.dashboard;
package com.stream_pi.server.window.dashboard;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.ActionType;
import com.stream_pi.actionapi.action.ActionType;
import com.stream_pi.actionapi.action.DisplayTextAlignment;
import com.stream_pi.actionapi.action.DisplayTextAlignment;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Type;
import com.stream_pi.actionapi.actionproperty.property.Type;
import com.stream_pi.actionapi.normalaction.NormalAction;
import com.stream_pi.actionapi.normalaction.NormalAction;
import com.stream_pi.actionapi.otheractions.CombineAction;
import com.stream_pi.actionapi.otheractions.CombineAction;
import com.stream_pi.actionapi.otheractions.FolderAction;
import com.stream_pi.actionapi.otheractions.FolderAction;
import com.stream_pi.server.action.NormalActionPlugins;
import com.stream_pi.server.action.NormalActionPlugins;
import com.stream_pi.util.uihelper.SpaceFiller;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.image.ImageView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashMap;
public class PluginsPane extends VBox {
public class PluginsPane extends VBox {
private Button settingsButton;
private Button settingsButton;
public PluginsPane(HostServices hostServices)
public PluginsPane(HostServices hostServices)
{
{
setMinWidth(250);
setMinWidth(250);
getStyleClass().add("plugins_pane");
getStyleClass().add("plugins_pane");
setPadding(new Insets(10));
setPadding(new Insets(10));
setSpacing(10.0);
this.hostServices = hostServices;
this.hostServices = hostServices;
initUI();
initUI();
}
}
private Accordion pluginsAccordion;
private Accordion pluginsAccordion;
public void initUI()
public void initUI()
{
{
pluginsAccordion = new Accordion();
pluginsAccordion = new Accordion();
pluginsAccordion.getStyleClass().add("plugins_pane_accordion");
pluginsAccordion.setCache(true);
pluginsAccordion.setCache(true);
Region r = new Region();
VBox.setVgrow(r, Priority.ALWAYS);
settingsButton = new Button();
settingsButton = new Button();
settingsButton.getStyleClass().add("plugins_pane_settings_button");
FontIcon cog = new FontIcon("fas-cog");
FontIcon cog = new FontIcon("fas-cog");
settingsButton.setGraphic(cog);
settingsButton.setGraphic(cog);
HBox settingsHBox = new HBox(settingsButton);
HBox settingsHBox = new HBox(settingsButton);
settingsHBox.getStyleClass().add("plugins_pane_settings_button_parent");
settingsHBox.setAlignment(Pos.CENTER_RIGHT);
settingsHBox.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(new Label("Plugins"), pluginsAccordion, r, settingsHBox);
Label pluginsLabel = new Label("Plugins");
pluginsLabel.getStyleClass().add("plugins_pane_top_label");
getChildren().addAll(pluginsLabel, pluginsAccordion, new SpaceFiller(SpaceFiller.FillerType.VBox), settingsHBox);
}
}
public Button getSettingsButton()
public Button getSettingsButton()
{
{
return settingsButton;
return settingsButton;
}
}
public void clearData()
public void clearData()
{
{
pluginsAccordion.getPanes().clear();
pluginsAccordion.getPanes().clear();
}
}
public void loadData()
public void loadData()
{
{
HashMap<String, ArrayList<NormalAction>> sortedPlugins = NormalActionPlugins.getInstance().getSortedPlugins();
HashMap<String, ArrayList<NormalAction>> sortedPlugins = NormalActionPlugins.getInstance().getSortedPlugins();
for(String eachCategory : sortedPlugins.keySet())
for(String eachCategory : sortedPlugins.keySet())
{
{
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.setSpacing(5);
vBox.getStyleClass().add("plugins_pane_each_plugin_box_parent");
TitledPane pane = new TitledPane(eachCategory, vBox);
TitledPane pane = new TitledPane(eachCategory, vBox);
pane.getStyleClass().add("plugins_pane_each_plugin_category_titled_pane");
for(NormalAction eachAction : sortedPlugins.get(eachCategory))
for(NormalAction eachAction : sortedPlugins.get(eachCategory))
{
{
if(!eachAction.isVisibleInPluginsPane())
if(!eachAction.isVisibleInPluginsPane())
continue;
continue;
Button eachNormalActionPluginButton = new Button();
Button eachNormalActionPluginButton = new Button();
eachNormalActionPluginButton.getStyleClass().add("plugins_pane_each_plugin_button");
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
eachNormalActionPluginButton.setMaxWidth(Double.MAX_VALUE);
eachNormalActionPluginButton.setMaxWidth(Double.MAX_VALUE);
eachNormalActionPluginButton.setAlignment(Pos.CENTER_LEFT);
eachNormalActionPluginButton.setAlignment(Pos.CENTER_LEFT);
Node graphic = eachAction.getServerButtonGraphic();
Node graphic = eachAction.getServerButtonGraphic();
if(graphic == null)
if(graphic == null)
{
{
FontIcon cogs = new FontIcon("fas-cogs");
FontIcon cogs = new FontIcon("fas-cogs");
cogs.getStyleClass().add("dashboard_plugins_pane_action_icon");
cogs.getStyleClass().add("plugins_pane_each_plugin_button_icon");
eachNormalActionPluginButton.setGraphic(cogs);
eachNormalActionPluginButton.setGraphic(cogs);
}
}
else
else
{
{
if(graphic instanceof FontIcon)
if(graphic instanceof FontIcon)
{
{
FontIcon fi = (FontIcon) graphic;
FontIcon fi = (FontIcon) graphic;
fi.getStyleClass().add("plugins_pane_each_plugin_button_icon");
eachNormalActionPluginButton.setGraphic(fi);
eachNormalActionPluginButton.setGraphic(fi);
}
}
else if(graphic instanceof ImageView)
else if(graphic instanceof ImageView)
{
{
ImageView iv = (ImageView) graphic;
ImageView iv = (ImageView) graphic;
iv.getStyleClass().add("dashboard_plugins_pane_action_icon_imageview");
iv.getStyleClass().add("plugins_pane_each_plugin_button_imageview");
iv.setPreserveRatio(false);
iv.setPreserveRatio(false);
eachNormalActionPluginButton.setGraphic(iv);
eachNormalActionPluginButton.setGraphic(iv);
}
}
}
}
eachNormalActionPluginButton.setText(eachAction.getName());
eachNormalActionPluginButton.setText(eachAction.getName());
eachNormalActionPluginButton.setOnDragDetected(mouseEvent -> {
eachNormalActionPluginButton.setOnDragDetected(mouseEvent -> {
Dragboard db = eachNormalActionPluginButton.startDragAndDrop(TransferMode.ANY);
Dragboard db = eachNormalActionPluginButton.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(Action.getDataFormat(), createFakeAction(eachAction, "Untitled action"));
content.put(Action.getDataFormat(), createFakeAction(eachAction, "Untitled action"));
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
});
});
HBox hBox = new HBox(eachNormalActionPluginButton);
HBox hBox = new HBox(eachNormalActionPluginButton);
hBox.setSpacing(5.0);
hBox.getStyleClass().add("plugins_pane_each_plugin_box");
hBox.setAlignment(Pos.TOP_LEFT);
hBox.setAlignment(Pos.TOP_LEFT);
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
HBox.setHgrow(eachNormalActionPluginButton, Priority.ALWAYS);
if(eachAction.getHelpLink() != null) {
if(eachAction.getHelpLink() != null) {
Button helpButton = new Button();
Button helpButton = new Button();
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
questionIcon.getStyleClass().add("dashboard_plugins_pane_action_help_icon");
questionIcon.getStyleClass().add("dashboard_plugins_pane_action_help_icon");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> hostServices.showDocument(eachAction.getHelpLink()));
helpButton.setOnAction(event -> hostServices.showDocument(eachAction.getHelpLink()));
hBox.getChildren().add(helpButton);
hBox.getChildren().add(helpButton);
}
}
vBox.getChildren().add(hBox);
vBox.getChildren().add(hBox);
}
}
if(vBox.getChildren().size() > 0)
if(vBox.getChildren().size() > 0)
pluginsAccordion.getPanes().add(pane);
pluginsAccordion.getPanes().add(pane);
}
}
}
}
private HostServices hostServices;
private HostServices hostServices;
public Action createFakeAction(Action action, String displayText)
public Action createFakeAction(Action action, String displayText)
{
{
Action newAction = new Action(action.getActionType());
Action newAction = new Action(action.getActionType());
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
newAction.setModuleName(action.getModuleName());
newAction.setModuleName(action.getModuleName());
newAction.setVersion(action.getVersion());
newAction.setVersion(action.getVersion());
newAction.setName(action.getName());
newAction.setName(action.getName());
}
}
newAction.setClientProperties(action.getClientProperties());
newAction.setClientProperties(action.getClientProperties());
for(Property property : newAction.getClientProperties().get())
for(Property property : newAction.getClientProperties().get())
{
{
if(property.getType() == Type.STRING || property.getType() == Type.INTEGER || property.getType() == Type.DOUBLE)
if(property.getType() == Type.STRING || property.getType() == Type.INTEGER || property.getType() == Type.DOUBLE)
property.setRawValue(property.getDefaultRawValue());
property.setRawValue(property.getDefaultRawValue());
}
}
// newAction.setLocation(location);
// newAction.setLocation(location);
newAction.setIDRandom();
newAction.setIDRandom();
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayText(displayText);
newAction.setDisplayText(displayText);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setShowIcon(false);
newAction.setShowIcon(false);
newAction.setHasIcon(false);
newAction.setHasIcon(false);
//action.setParent(root);
//action.setParent(root);
newAction.setBgColourHex("");
newAction.setBgColourHex("");
newAction.setDisplayTextFontColourHex("");
newAction.setDisplayTextFontColourHex("");
return newAction;
return newAction;
}
}
public void loadOtherActions()
public void loadOtherActions()
{
{
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.getStyleClass().add("plugins_pane_each_plugin_box_parent");
Button folderActionButton = new Button("Folder");
Button folderActionButton = new Button("Folder");
folderActionButton.getStyleClass().add("plugins_pane_each_plugin_button");
folderActionButton.setMaxWidth(Double.MAX_VALUE);
folderActionButton.setMaxWidth(Double.MAX_VALUE);
folderActionButton.setAlignment(Pos.CENTER_LEFT);
folderActionButton.setAlignment(Pos.CENTER_LEFT);
FontIcon folder = new FontIcon("fas-folder");
FontIcon folder = new FontIcon("fas-folder");
folderActionButton.setGraphic(folder);
folderActionButton.setGraphic(folder);
folderActionButton.setOnDragDetected(mouseEvent -> {
folderActionButton.setOnDragDetected(mouseEvent -> {
Dragboard db = folderActionButton.startDragAndDrop(TransferMode.ANY);
Dragboard db = folderActionButton.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(Action.getDataFormat(), createFakeAction(new FolderAction(), "Untitled Folder"));
content.put(Action.getDataFormat(), createFakeAction(new FolderAction(), "Untitled Folder"));
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
});
});
Button combineActionButton = new Button("Combine");
Button combineActionButton = new Button("Combine");
combineActionButton.getStyleClass().add("plugins_pane_each_plugin_button");
combineActionButton.setMaxWidth(Double.MAX_VALUE);
combineActionButton.setMaxWidth(Double.MAX_VALUE);
combineActionButton.setAlignment(Pos.CENTER_LEFT);
combineActionButton.setAlignment(Pos.CENTER_LEFT);
FontIcon list = new FontIcon("fas-list");
FontIcon list = new FontIcon("fas-list");
combineActionButton.setGraphic(list);
combineActionButton.setGraphic(list);
combineActionButton.setOnDragDetected(mouseEvent -> {
combineActionButton.setOnDragDetected(mouseEvent -> {
Dragboard db = combineActionButton.startDragAndDrop(TransferMode.ANY);
Dragboard db = combineActionButton.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(Action.getDataFormat(), createFakeAction(new CombineAction(), "Untitled Combine"));
content.put(Action.getDataFormat(), createFakeAction(new CombineAction(), "Untitled Combine"));
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
});
});
HBox.setHgrow(folderActionButton, Priority.ALWAYS);
HBox h1 = new HBox(folderActionButton);
h1.getStyleClass().add("plugins_pane_each_plugin_box");
HBox.setHgrow(combineActionButton, Priority.ALWAYS);
HBox h2 = new HBox(combineActionButton);
h2.getStyleClass().add("plugins_pane_each_plugin_box");
vBox.getChildren().addAll(h1, h2);
vBox.getChildren().addAll(folderActionButton, combineActionButton);
vBox.setSpacing(5);
TitledPane pane = new TitledPane("StreamPi", vBox);
TitledPane pane = new TitledPane("StreamPi", vBox);
pane.getStyleClass().add("plugins_pane_each_plugin_category_titled_pane");
pluginsAccordion.getPanes().add(pane);
pluginsAccordion.getPanes().add(pane);
pluginsAccordion.setCache(true);
pluginsAccordion.setCache(true);
pluginsAccordion.setCacheHint(CacheHint.SPEED);
pluginsAccordion.setCacheHint(CacheHint.SPEED);
}
}
}
}
package com.stream_pi.server.window.dashboard.actiondetailpane;
package com.stream_pi.server.window.dashboard.actiondetailpane;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.ActionType;
import com.stream_pi.actionapi.action.ActionType;
import com.stream_pi.actionapi.action.DisplayTextAlignment;
import com.stream_pi.actionapi.action.DisplayTextAlignment;
import com.stream_pi.actionapi.action.Location;
import com.stream_pi.actionapi.action.Location;
import com.stream_pi.actionapi.actionproperty.property.ControlType;
import com.stream_pi.actionapi.actionproperty.property.ControlType;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Type;
import com.stream_pi.actionapi.actionproperty.property.Type;
import com.stream_pi.actionapi.otheractions.CombineAction;
import com.stream_pi.actionapi.otheractions.CombineAction;
import com.stream_pi.actionapi.otheractions.FolderAction;
import com.stream_pi.actionapi.otheractions.FolderAction;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
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.connection.ClientConnections;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
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.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.collections.FXCollections;
import javafx.collections.FXCollections;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.paint.Paint;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import javafx.stage.Window;
import javafx.stage.Window;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.io.File;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ActionDetailsPane extends VBox implements ActionDetailsPaneListener {
public class ActionDetailsPane extends VBox implements ActionDetailsPaneListener {
private ScrollPane scrollPane;
private ScrollPane scrollPane;
private VBox vbox;
private VBox vbox;
private VBox clientPropertiesVBox;
private VBox clientPropertiesVBox;
private Button saveButton;
private Button saveButton;
private Button deleteButton;
private Button deleteButton;
private Button openFolderButton;
private Button openFolderButton;
private HBox buttonBar;
private HBox buttonBar;
private Label actionHeadingLabel;
private Label actionHeadingLabel;
private Logger logger;
private Logger logger;
private Button returnButtonForCombineActionChild;
private Button returnButtonForCombineActionChild;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private HostServices hostServices;
private HostServices hostServices;
public ActionDetailsPane(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices) {
public ActionDetailsPane(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices) {
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
logger = Logger.getLogger(ActionDetailsPane.class.getName());
logger = Logger.getLogger(ActionDetailsPane.class.getName());
setSpacing(10.0);
setSpacing(10.0);
// VBox.setVgrow(this, Priority.SOMETIMES);
clientPropertiesVBox = new VBox();
clientPropertiesVBox = new VBox();
clientPropertiesVBox.setSpacing(10.0);
clientPropertiesVBox.setSpacing(10.0);
vbox = new VBox();
vbox = new VBox();
vbox.setPadding(new Insets(0, 25, 0, 5));
vbox.setPadding(new Insets(0, 25, 0, 5));
vbox.getStyleClass().add("action_details_pane_vbox");
vbox.getStyleClass().add("action_details_pane_vbox");
vbox.setSpacing(10.0);
vbox.setSpacing(10.0);
getStyleClass().add("action_details_pane");
getStyleClass().add("action_details_pane");
// setPadding(new Insets(5,50,5,50));
// setMinHeight(245);
scrollPane = new ScrollPane();
scrollPane = new ScrollPane();
VBox.setMargin(scrollPane, new Insets(0, 0, 0, 10));
VBox.setMargin(scrollPane, new Insets(0, 0, 0, 10));
scrollPane.getStyleClass().add("action_details_pane_scroll_pane");
scrollPane.getStyleClass().add("action_details_pane_scroll_pane");
setMinHeight(310);
setMinHeight(310);
scrollPane.setContent(vbox);
scrollPane.setContent(vbox);
vbox.prefWidthProperty().bind(scrollPane.widthProperty());
vbox.prefWidthProperty().bind(scrollPane.widthProperty());
scrollPane.prefWidthProperty().bind(widthProperty());
scrollPane.prefWidthProperty().bind(widthProperty());
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
openFolderButton = new Button("Open Folder");
openFolderButton = new Button("Open Folder");
FontIcon folderOpenIcon = new FontIcon("far-folder-open");
FontIcon folderOpenIcon = new FontIcon("far-folder-open");
openFolderButton.setGraphic(folderOpenIcon);
openFolderButton.setGraphic(folderOpenIcon);
openFolderButton.setOnAction(event -> onOpenFolderButtonClicked());
openFolderButton.setOnAction(event -> onOpenFolderButtonClicked());
saveButton = new Button("Apply Changes");
saveButton = new Button("Apply Changes");
FontIcon syncIcon = new FontIcon("fas-sync-alt");
FontIcon syncIcon = new FontIcon("fas-sync-alt");
saveButton.setGraphic(syncIcon);
saveButton.setGraphic(syncIcon);
saveButton.setOnAction(event -> onSaveButtonClicked());
saveButton.setOnAction(event -> onSaveButtonClicked());
deleteButton = new Button("Delete action");
deleteButton = new Button("Delete action");
FontIcon deleteIcon = new FontIcon("fas-trash");
FontIcon deleteIcon = new FontIcon("fas-trash");
deleteIcon.setIconColor(Paint.valueOf("#FF0000"));
deleteIcon.setIconColor(Paint.valueOf("#FF0000"));
deleteButton.setTextFill(Paint.valueOf("#FF0000"));
deleteButton.setTextFill(Paint.valueOf("#FF0000"));
deleteButton.setGraphic(deleteIcon);
deleteButton.setGraphic(deleteIcon);
deleteButton.setOnAction(event -> onDeleteButtonClicked());
deleteButton.setOnAction(event -> onDeleteButtonClicked());
returnButtonForCombineActionChild = new Button("Return");
returnButtonForCombineActionChild = new Button("Return");
returnButtonForCombineActionChild.setGraphic(new FontIcon("fas-caret-left"));
returnButtonForCombineActionChild.setGraphic(new FontIcon("fas-caret-left"));
returnButtonForCombineActionChild.managedProperty().bind(returnButtonForCombineActionChild.visibleProperty());
returnButtonForCombineActionChild.managedProperty().bind(returnButtonForCombineActionChild.visibleProperty());
returnButtonForCombineActionChild.setOnAction(event -> {
returnButtonForCombineActionChild.setOnAction(event -> {
try {
try {
logger.info("@@## : " + action.getParent());
logger.info("@@## : " + action.getParent());
onActionClicked(getClientProfile().getActionByID(action.getParent()), getActionBox());
onActionClicked(getClientProfile().getActionByID(action.getParent()), getActionBox());
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
}
}
});
});
buttonBar = new HBox(openFolderButton, returnButtonForCombineActionChild, saveButton, deleteButton);
buttonBar = new HBox(openFolderButton, returnButtonForCombineActionChild, saveButton, deleteButton);
buttonBar.getStyleClass().add("action_details_pane_button_bar");
buttonBar.setPadding(new Insets(10, 10, 10, 0));
buttonBar.setPadding(new Insets(10, 10, 10, 0));
buttonBar.setAlignment(Pos.CENTER_RIGHT);
buttonBar.setAlignment(Pos.CENTER_RIGHT);
buttonBar.setVisible(false);
buttonBar.setVisible(false);
buttonBar.setSpacing(10.0);
buttonBar.setSpacing(10.0);
actionHeadingLabel = new Label();
actionHeadingLabel = new Label();
actionHeadingLabel.getStyleClass().add("action_details_pane_heading_label");
actionHeadingLabel.getStyleClass().add("action_details_pane_action_heading_label");
HBox headingHBox = new HBox(actionHeadingLabel);
HBox headingHBox = new HBox(actionHeadingLabel);
headingHBox.getStyleClass().add("action_details_pane_heading_box");
headingHBox.setPadding(new Insets(5, 10, 0, 10));
headingHBox.setPadding(new Insets(5, 10, 0, 10));
getChildren().addAll(headingHBox, scrollPane, buttonBar);
getChildren().addAll(headingHBox, scrollPane, buttonBar);
displayTextAlignmentComboBox = new ComboBox<>(FXCollections.observableArrayList(DisplayTextAlignment.TOP,
displayTextAlignmentComboBox = new ComboBox<>(FXCollections.observableArrayList(DisplayTextAlignment.TOP,
DisplayTextAlignment.CENTER, DisplayTextAlignment.BOTTOM));
DisplayTextAlignment.CENTER, DisplayTextAlignment.BOTTOM));
displayTextAlignmentComboBox.managedProperty().bind(displayTextAlignmentComboBox.visibleProperty());
displayTextAlignmentComboBox.managedProperty().bind(displayTextAlignmentComboBox.visibleProperty());
actionClientProperties = new ArrayList<>();
actionClientProperties = new ArrayList<>();
displayNameTextField = new TextField();
displayNameTextField = new TextField();
displayNameTextField.managedProperty().bind(displayNameTextField.visibleProperty());
displayNameTextField.managedProperty().bind(displayNameTextField.visibleProperty());
iconFileTextField = new TextField();
iconFileTextField = new TextField();
iconFileTextField.managedProperty().bind(iconFileTextField.visibleProperty());
iconFileTextField.managedProperty().bind(iconFileTextField.visibleProperty());
iconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
iconFileTextField.textProperty().addListener((observableValue, s, t1) -> {
try {
try {
if (!s.equals(t1) && t1.length() > 0) {
if (!s.equals(t1) && t1.length() > 0) {
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
byte[] iconFileByteArray = Files.readAllBytes(new File(t1).toPath());
hideIconCheckBox.setDisable(false);
hideIconCheckBox.setDisable(false);
hideIconCheckBox.setSelected(false);
hideIconCheckBox.setSelected(false);
clearIconButton.setDisable(false);
clearIconButton.setDisable(false);
System.out.println("ABABABABABBABABBABABABCCCCCCCCCCCCCCCCCC");
System.out.println("ABABABABABBABABBABABABCCCCCCCCCCCCCCCCCC");
action.setIcon(iconFileByteArray);
action.setIcon(iconFileByteArray);
setSendIcon(true);
setSendIcon(true);
System.out.println(action.getIconAsByteArray().length);
System.out.println(action.getIconAsByteArray().length);
}
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException(e.getMessage()));
}
}
});
});
clearIconButton = new Button("Clear Icon");
clearIconButton = new Button("Clear Icon");
clearIconButton.managedProperty().bind(clearIconButton.visibleProperty());
clearIconButton.managedProperty().bind(clearIconButton.visibleProperty());
clearIconButton.setOnAction(event -> {
clearIconButton.setOnAction(event -> {
hideIconCheckBox.setDisable(true);
hideIconCheckBox.setDisable(true);
hideIconCheckBox.setSelected(false);
hideIconCheckBox.setSelected(false);
clearIconButton.setDisable(true);
clearIconButton.setDisable(true);
iconFileTextField.clear();
iconFileTextField.clear();
});
});
hideDisplayTextCheckBox = new CheckBox("Hide");
hideDisplayTextCheckBox = new CheckBox("Hide");
hideDisplayTextCheckBox.managedProperty().bind(hideDisplayTextCheckBox.visibleProperty());
hideDisplayTextCheckBox.managedProperty().bind(hideDisplayTextCheckBox.visibleProperty());
hideIconCheckBox = new CheckBox("Hide");
hideIconCheckBox = new CheckBox("Hide");
hideIconCheckBox.managedProperty().bind(hideIconCheckBox.visibleProperty());
hideIconCheckBox.managedProperty().bind(hideIconCheckBox.visibleProperty());
actionBackgroundColourPicker = new ColorPicker();
actionBackgroundColourPicker = new ColorPicker();
actionBackgroundColourPicker.managedProperty().bind(actionBackgroundColourPicker.visibleProperty());
actionBackgroundColourPicker.managedProperty().bind(actionBackgroundColourPicker.visibleProperty());
displayTextColourPicker = new ColorPicker();
displayTextColourPicker = new ColorPicker();
displayTextColourPicker.managedProperty().bind(displayTextColourPicker.visibleProperty());
displayTextColourPicker.managedProperty().bind(displayTextColourPicker.visibleProperty());
actionBackgroundColourTransparentCheckBox = new CheckBox("Default");
actionBackgroundColourTransparentCheckBox = new CheckBox("Default");
actionBackgroundColourPicker.disableProperty()
actionBackgroundColourPicker.disableProperty()
.bind(actionBackgroundColourTransparentCheckBox.selectedProperty());
.bind(actionBackgroundColourTransparentCheckBox.selectedProperty());
HBox.setMargin(actionBackgroundColourTransparentCheckBox, new Insets(0, 0, 0, 10));
HBox.setMargin(actionBackgroundColourTransparentCheckBox, new Insets(0, 0, 0, 10));
displayTextColourDefaultCheckBox = new CheckBox("Default");
displayTextColourDefaultCheckBox = new CheckBox("Default");
displayTextColourPicker.disableProperty()
displayTextColourPicker.disableProperty()
.bind(displayTextColourDefaultCheckBox.selectedProperty());
.bind(displayTextColourDefaultCheckBox.selectedProperty());
HBox.setMargin(displayTextColourDefaultCheckBox, new Insets(0, 0, 0, 10));
HBox.setMargin(displayTextColourDefaultCheckBox, new Insets(0, 0, 0, 10));
Region r = new Region();
Region r = new Region();
HBox.setHgrow(r, Priority.ALWAYS);
HBox.setHgrow(r, Priority.ALWAYS);
Region r1 = new Region();
Region r1 = new Region();
HBox.setHgrow(r1, Priority.ALWAYS);
HBox.setHgrow(r1, Priority.ALWAYS);
HBox displayTextColourHBox = new HBox(new Label("Display Text Colour"), r1, displayTextColourPicker,
HBox displayTextColourHBox = new HBox(new Label("Display Text Colour"), r1, displayTextColourPicker,
displayTextColourDefaultCheckBox);
displayTextColourDefaultCheckBox);
displayTextColourHBox.setAlignment(Pos.CENTER);
displayTextColourHBox.setAlignment(Pos.CENTER);
displayTextColourHBox.setSpacing(5.0);
displayTextColourHBox.setSpacing(5.0);
HBox bgColourHBox = new HBox(new Label("Background Colour"), r, actionBackgroundColourPicker,
HBox bgColourHBox = new HBox(new Label("Background Colour"), r, actionBackgroundColourPicker,
actionBackgroundColourTransparentCheckBox);
actionBackgroundColourTransparentCheckBox);
bgColourHBox.setAlignment(Pos.CENTER);
bgColourHBox.setAlignment(Pos.CENTER);
bgColourHBox.setSpacing(5.0);
bgColourHBox.setSpacing(5.0);
HBox clearIconHBox = new HBox(clearIconButton);
HBox clearIconHBox = new HBox(clearIconButton);
clearIconHBox.setAlignment(Pos.CENTER_RIGHT);
clearIconHBox.setAlignment(Pos.CENTER_RIGHT);
displayTextFieldHBox = new HBoxInputBox("Display Name", displayNameTextField, hideDisplayTextCheckBox);
displayTextFieldHBox = new HBoxInputBox("Display Name", displayNameTextField, hideDisplayTextCheckBox);
normalActionsPropsVBox = new VBox(displayTextColourHBox,
normalActionsPropsVBox = new VBox(displayTextColourHBox,
new HBox(new Label("Alignment"), new SpaceFiller(SpaceFiller.FillerType.HBox),
new HBox(new Label("Alignment"), new SpaceFiller(SpaceFiller.FillerType.HBox),
displayTextAlignmentComboBox),
displayTextAlignmentComboBox),
new HBoxInputBoxWithFileChooser("Icon", iconFileTextField, hideIconCheckBox,
new HBoxInputBoxWithFileChooser("Icon", iconFileTextField, hideIconCheckBox,
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif")),
new FileChooser.ExtensionFilter("Images", "*.jpeg", "*.jpg", "*.png", "*.gif")),
clearIconHBox, bgColourHBox);
clearIconHBox, bgColourHBox);
normalActionsPropsVBox.managedProperty().bind(normalActionsPropsVBox.visibleProperty());
normalActionsPropsVBox.managedProperty().bind(normalActionsPropsVBox.visibleProperty());
normalActionsPropsVBox.setSpacing(10.0);
normalActionsPropsVBox.setSpacing(10.0);
vbox.getChildren().addAll(displayTextFieldHBox, normalActionsPropsVBox, clientPropertiesVBox);
vbox.getChildren().addAll(displayTextFieldHBox, normalActionsPropsVBox, clientPropertiesVBox);
vbox.setVisible(false);
vbox.setVisible(false);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
setOnDragOver(dragEvent -> {
setOnDragOver(dragEvent -> {
if (dragEvent.getDragboard().hasContent(Action.getDataFormat()) && action != null) {
if (dragEvent.getDragboard().hasContent(Action.getDataFormat()) && action != null) {
if (action.getActionType() == ActionType.COMBINE) {
if (action.getActionType() == ActionType.COMBINE) {
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.consume();
dragEvent.consume();
}
}
}
}
});
});
setOnDragDropped(dragEvent -> {
setOnDragDropped(dragEvent -> {
try {
try {
Action newAction = (Action) dragEvent.getDragboard().getContent(Action.getDataFormat());
Action newAction = (Action) dragEvent.getDragboard().getContent(Action.getDataFormat());
if (newAction.getActionType() == ActionType.NORMAL) {
if (newAction.getActionType() == ActionType.NORMAL) {
newAction.setLocation(new Location(-1, -1));
newAction.setLocation(new Location(-1, -1));
newAction.setParent(this.action.getID());
newAction.setParent(this.action.getID());
combineActionPropertiesPane.getCombineAction().addChild(newAction.getID());
combineActionPropertiesPane.getCombineAction().addChild(newAction.getID());
addActionToCurrentClientProfile(newAction);
addActionToCurrentClientProfile(newAction);
ClientConnection connection = ClientConnections.getInstance()
ClientConnection connection = ClientConnections.getInstance()
.getClientConnectionBySocketAddress(getClient().getRemoteSocketAddress());
.getClientConnectionBySocketAddress(getClient().getRemoteSocketAddress());
connection.saveActionDetails(getClientProfile().getID(), newAction);
connection.saveActionDetails(getClientProfile().getID(), newAction);
combineActionPropertiesPane.renderProps();
combineActionPropertiesPane.renderProps();
saveAction();
saveAction();
}
}
} catch (MinorException e) {
} catch (MinorException e) {
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
} catch (SevereException e) {
} catch (SevereException e) {
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
e.printStackTrace();
e.printStackTrace();
} catch (CloneNotSupportedException e) {
} catch (CloneNotSupportedException e) {
e.printStackTrace();
e.printStackTrace();
}
}
});
});
}
}
private VBox normalActionsPropsVBox;
private VBox normalActionsPropsVBox;
private HBox displayTextFieldHBox;
private HBox displayTextFieldHBox;
private Client client;
private Client client;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClient(Client client) {
public void setClient(Client client) {
this.client = client;
this.client = client;
}
}
public Client getClient() {
public Client getClient() {
return client;
return client;
}
}
public void setClientProfile(ClientProfile clientProfile) {
public void setClientProfile(ClientProfile clientProfile) {
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
}
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
public void setActionHeadingLabelText(String text) {
public void setActionHeadingLabelText(String text) {
actionHeadingLabel.setText(text);
actionHeadingLabel.setText(text);
}
}
private Action action;
private Action action;
public Action getAction() {
public Action getAction() {
return action;
return action;
}
}
private ActionBox actionBox;
private ActionBox actionBox;
public ActionBox getActionBox() {
public ActionBox getActionBox() {
return actionBox;
return actionBox;
}
}
@Override
@Override
public void onActionClicked(Action action, ActionBox actionBox) throws MinorException {
public void onActionClicked(Action action, ActionBox actionBox) throws MinorException {
this.action = action;
this.action = action;
this.actionBox = actionBox;
this.actionBox = actionBox;
System.out.println(action.getActionType());
logger.info("action Display text : "+action.getDisplayText());
logger.info("action Display text : "+action.getDisplayText());
clear();
clear();
renderActionProperties();
renderActionProperties();
}
}
private TextField displayNameTextField;
private TextField displayNameTextField;
private CheckBox hideDisplayTextCheckBox;
private CheckBox hideDisplayTextCheckBox;
private CheckBox hideIconCheckBox;
private CheckBox hideIconCheckBox;
private TextField iconFileTextField;
private TextField iconFileTextField;
private Button clearIconButton;
private Button clearIconButton;
private ColorPicker actionBackgroundColourPicker;
private ColorPicker actionBackgroundColourPicker;
private ColorPicker displayTextColourPicker;
private ColorPicker displayTextColourPicker;
private CheckBox actionBackgroundColourTransparentCheckBox;
private CheckBox actionBackgroundColourTransparentCheckBox;
private CheckBox displayTextColourDefaultCheckBox;
private CheckBox displayTextColourDefaultCheckBox;
private ComboBox<DisplayTextAlignment> displayTextAlignmentComboBox;
private ComboBox<DisplayTextAlignment> displayTextAlignmentComboBox;
public void clear()
public void clear()
{
{
sendIcon = false;
sendIcon = false;
actionClientProperties.clear();
actionClientProperties.clear();
displayNameTextField.clear();
displayNameTextField.clear();
iconFileTextField.clear();
iconFileTextField.clear();
clientPropertiesVBox.getChildren().clear();
clientPropertiesVBox.getChildren().clear();
vbox.setVisible(false);
vbox.setVisible(false);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
buttonBar.setVisible(false);
buttonBar.setVisible(false);
setActionHeadingLabelText("");
setActionHeadingLabelText("");
actionBackgroundColourPicker.setValue(Color.WHITE);
actionBackgroundColourPicker.setValue(Color.WHITE);
displayTextColourPicker.setValue(Color.WHITE);
displayTextColourPicker.setValue(Color.WHITE);
}
}
boolean isCombineChild = false;
boolean isCombineChild = false;
public boolean isCombineChild() {
public boolean isCombineChild() {
return isCombineChild;
return isCombineChild;
}
}
public void renderActionProperties() throws MinorException
public void renderActionProperties() throws MinorException
{
{
if(action.getLocation().getCol() == -1) //Combine Child action
//Combine Child action
isCombineChild = true;
isCombineChild = action.getLocation().getCol() == -1;
else
isCombineChild = false;
displayNameTextField.setText(action.getDisplayText());
displayNameTextField.setText(action.getDisplayText());
System.out.println(action.getDisplayText()+"@@@@::::"+isCombineChild);
if(isCombineChild)
if(isCombineChild)
{
{
setReturnButtonForCombineActionChildVisible(true);
setReturnButtonForCombineActionChildVisible(true);
normalActionsPropsVBox.setVisible(false);
normalActionsPropsVBox.setVisible(false);
hideDisplayTextCheckBox.setSelected(false);
hideDisplayTextCheckBox.setSelected(false);
hideDisplayTextCheckBox.setVisible(false);
hideDisplayTextCheckBox.setVisible(false);
}
}
else
else
{
{
normalActionsPropsVBox.setVisible(true);
normalActionsPropsVBox.setVisible(true);
setReturnButtonForCombineActionChildVisible(false);
setReturnButtonForCombineActionChildVisible(false);
hideDisplayTextCheckBox.setVisible(true);
hideDisplayTextCheckBox.setVisible(true);
setFolderButtonVisible(action.getActionType().equals(ActionType.FOLDER));
setFolderButtonVisible(action.getActionType().equals(ActionType.FOLDER));
displayTextAlignmentComboBox.getSelectionModel().select(action.getDisplayTextAlignment());
displayTextAlignmentComboBox.getSelectionModel().select(action.getDisplayTextAlignment());
if(!action.getBgColourHex().isEmpty())
if(!action.getBgColourHex().isEmpty())
actionBackgroundColourPicker.setValue(Color.valueOf(action.getBgColourHex()));
actionBackgroundColourPicker.setValue(Color.valueOf(action.getBgColourHex()));
else
else
actionBackgroundColourTransparentCheckBox.setSelected(true);
actionBackgroundColourTransparentCheckBox.setSelected(true);
if(!action.getDisplayTextFontColourHex().isEmpty())
if(!action.getDisplayTextFontColourHex().isEmpty())
displayTextColourPicker.setValue(Color.valueOf(action.getDisplayTextFontColourHex()));
displayTextColourPicker.setValue(Color.valueOf(action.getDisplayTextFontColourHex()));
else
else
displayTextColourDefaultCheckBox.setSelected(true);
displayTextColourDefaultCheckBox.setSelected(true);
hideDisplayTextCheckBox.setSelected(!action.isShowDisplayText());
hideDisplayTextCheckBox.setSelected(!action.isShowDisplayText());
hideIconCheckBox.setDisable(!action.isHasIcon());
hideIconCheckBox.setDisable(!action.isHasIcon());
hideIconCheckBox.setSelected(!action.isShowIcon());
hideIconCheckBox.setSelected(!action.isShowIcon());
if(!action.isHasIcon())
if(!action.isHasIcon())
{
{
hideIconCheckBox.setSelected(false);
hideIconCheckBox.setSelected(false);
}
}
clearIconButton.setDisable(!action.isHasIcon());
clearIconButton.setDisable(!action.isHasIcon());
}
}
buttonBar.setVisible(true);
buttonBar.setVisible(true);
vbox.setVisible(true);
vbox.setVisible(true);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
if(action.isInvalid())
if(action.isInvalid())
setActionHeadingLabelText("Invalid action ("+action.getModuleName()+")");
setActionHeadingLabelText("Invalid action ("+action.getModuleName()+")");
else
else
setActionHeadingLabelText(action.getName());
setActionHeadingLabelText(action.getName());
}
}
else if(action.getActionType() == ActionType.COMBINE)
else if(action.getActionType() == ActionType.COMBINE)
setActionHeadingLabelText("Combine action");
setActionHeadingLabelText("Combine action");
else if(action.getActionType() == ActionType.FOLDER)
else if(action.getActionType() == ActionType.FOLDER)
setActionHeadingLabelText("Folder action");
setActionHeadingLabelText("Folder action");
if(!action.isInvalid())
if(!action.isInvalid())
{
{
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
renderClientProperties();
renderClientProperties();
else if(action.getActionType() == ActionType.COMBINE)
else if(action.getActionType() == ActionType.COMBINE)
renderCombineActionProperties();
renderCombineActionProperties();
}
}
}
}
private CombineActionPropertiesPane combineActionPropertiesPane;
private CombineActionPropertiesPane combineActionPropertiesPane;
public CombineActionPropertiesPane getCombineActionPropertiesPane() {
public CombineActionPropertiesPane getCombineActionPropertiesPane() {
return combineActionPropertiesPane;
return combineActionPropertiesPane;
}
}
public void setReturnButtonForCombineActionChildVisible(boolean visible)
public void setReturnButtonForCombineActionChildVisible(boolean visible)
{
{
returnButtonForCombineActionChild.setVisible(visible);
returnButtonForCombineActionChild.setVisible(visible);
}
}
public void renderCombineActionProperties()
public void renderCombineActionProperties()
{
{
try {
try
logger.info("@@@@@ : "+action.getClientProperties().getSize());
{
combineActionPropertiesPane = new CombineActionPropertiesPane(getActionAsCombineAction(action),
combineActionPropertiesPane = new CombineActionPropertiesPane(getActionAsCombineAction(action),
getClientProfile(),
getClientProfile(),
this
this
);
);
clientPropertiesVBox.getChildren().add(combineActionPropertiesPane);
clientPropertiesVBox.getChildren().add(combineActionPropertiesPane);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
public void setAction(Action action) {
public void setAction(Action action) {
this.action = action;
this.action = action;
}
}
public FolderAction getActionAsFolderAction(Action action)
public FolderAction getActionAsFolderAction(Action action)
{
{
FolderAction folderAction = new FolderAction();
FolderAction folderAction = new FolderAction();
folderAction.setDisplayText(action.getDisplayText());
folderAction.setDisplayText(action.getDisplayText());
folderAction.setName(action.getName());
folderAction.setName(action.getName());
folderAction.setID(action.getID());
folderAction.setID(action.getID());
folderAction.setLocation(action.getLocation());
folderAction.setLocation(action.getLocation());
folderAction.setBgColourHex(action.getBgColourHex());
folderAction.setBgColourHex(action.getBgColourHex());
folderAction.setParent(action.getParent());
folderAction.setParent(action.getParent());
folderAction.getClientProperties().set(action.getClientProperties());
folderAction.getClientProperties().set(action.getClientProperties());
folderAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
folderAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
folderAction.setShowIcon(action.isShowIcon());
folderAction.setShowIcon(action.isShowIcon());
folderAction.setHasIcon(action.isHasIcon());
folderAction.setHasIcon(action.isHasIcon());
if(folderAction.isHasIcon())
if(folderAction.isHasIcon())
folderAction.setIcon(action.getIconAsByteArray());
folderAction.setIcon(action.getIconAsByteArray());
folderAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
folderAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
return folderAction;
return folderAction;
}
}
public CombineAction getActionAsCombineAction(Action action)
public CombineAction getActionAsCombineAction(Action action)
{
{
CombineAction combineAction = new CombineAction();
CombineAction combineAction = new CombineAction();
combineAction.setDisplayText(action.getDisplayText());
combineAction.setDisplayText(action.getDisplayText());
combineAction.setName(action.getName());
combineAction.setName(action.getName());
combineAction.setID(action.getID());
combineAction.setID(action.getID());
combineAction.setLocation(action.getLocation());
combineAction.setLocation(action.getLocation());
combineAction.setBgColourHex(action.getBgColourHex());
combineAction.setBgColourHex(action.getBgColourHex());
combineAction.setParent(action.getParent());
combineAction.setParent(action.getParent());
combineAction.getClientProperties().set(action.getClientProperties());
combineAction.getClientProperties().set(action.getClientProperties());
combineAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
combineAction.setDisplayTextAlignment(action.getDisplayTextAlignment());
combineAction.setShowIcon(action.isShowIcon());
combineAction.setShowIcon(action.isShowIcon());
combineAction.setHasIcon(action.isHasIcon());
combineAction.setHasIcon(action.isHasIcon());
if(combineAction.isHasIcon())
if(combineAction.isHasIcon())
combineAction.setIcon(action.getIconAsByteArray());
combineAction.setIcon(action.getIconAsByteArray());
combineAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
combineAction.setDisplayTextFontColourHex(action.getDisplayTextFontColourHex());
for(Property prop : combineAction.getClientProperties().get())
for(Property prop : combineAction.getClientProperties().get())
{
{
System.out.println("PROP : "+prop.getName()+","+prop.getRawValue());
System.out.println("PROP : "+prop.getName()+","+prop.getRawValue());
}
}
return combineAction;
return combineAction;
}
}
public void onOpenFolderButtonClicked()
public void onOpenFolderButtonClicked()
{
{
FolderAction folderAction = getActionAsFolderAction(action);
FolderAction folderAction = getActionAsFolderAction(action);
actionBox.getActionGridPaneListener().renderFolder(folderAction);
actionBox.getActionGridPaneListener().renderFolder(folderAction);
clear();
clear();
}
}
@Override
@Override
public Window getCurrentWindow() {
public Window getCurrentWindow() {
return getScene().getWindow();
return getScene().getWindow();
}
}
private ArrayList<UIPropertyBox> actionClientProperties;
private ArrayList<UIPropertyBox> actionClientProperties;
public void renderClientProperties() throws MinorException
public void renderClientProperties() throws MinorException
{
{
for(int i =0;i< action.getClientProperties().getSize(); i++)
for(int i =0;i< action.getClientProperties().getSize(); i++)
{
{
Property eachProperty = action.getClientProperties().get().get(i);
Property eachProperty = action.getClientProperties().get().get(i);
if(!eachProperty.isVisible())
if(!eachProperty.isVisible())
continue;
continue;
Label label = new Label(eachProperty.getDisplayName());
Label label = new Label(eachProperty.getDisplayName());
HBox hBox = new HBox(label);
HBox hBox = new HBox(label);
hBox.setSpacing(5.0);
hBox.setSpacing(5.0);
hBox.setAlignment(Pos.CENTER_LEFT);
hBox.setAlignment(Pos.CENTER_LEFT);
Node controlNode = null;
Node controlNode = null;
if(eachProperty.getHelpLink() != null)
if(eachProperty.getHelpLink() != null)
{
{
Button helpButton = new Button();
Button helpButton = new Button();
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> {
helpButton.setOnAction(event -> {
hostServices.showDocument(eachProperty.getHelpLink());
hostServices.showDocument(eachProperty.getHelpLink());
});
});
hBox.getChildren().add(helpButton);
hBox.getChildren().add(helpButton);
}
}
hBox.getChildren().add(new SpaceFiller(SpaceFiller.FillerType.HBox));
hBox.getChildren().add(new SpaceFiller(SpaceFiller.FillerType.HBox));
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
{
{
ComboBox<String> comboBox = new ComboBox<>();
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
controlNode = comboBox;
controlNode = comboBox;
}
}
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
TextField textField = new TextField(eachProperty.getRawValue());
TextField textField = new TextField(eachProperty.getRawValue());
controlNode= textField;
controlNode= textField;
}
}
else if(eachProperty.getControlType() == ControlType.TOGGLE)
else if(eachProperty.getControlType() == ControlType.TOGGLE)
{
{
ToggleButton toggleButton = new ToggleButton();
ToggleButton toggleButton = new ToggleButton();
toggleButton.setSelected(eachProperty.getBoolValue());
toggleButton.setSelected(eachProperty.getBoolValue());
if(eachProperty.getBoolValue())
if(eachProperty.getBoolValue())
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
if(t1)
if(t1)
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
});
});
controlNode = toggleButton;
controlNode = toggleButton;
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getDoubleValue());
slider.setValue(eachProperty.getDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
controlNode = slider;
controlNode = slider;
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getIntValue());
slider.setValue(eachProperty.getIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setBlockIncrement(1.0);
slider.setBlockIncrement(1.0);
slider.setSnapToTicks(true);
slider.setSnapToTicks(true);
controlNode = slider;
controlNode = slider;
}
}
hBox.getChildren().add(controlNode);
hBox.getChildren().add(controlNode);
UIPropertyBox clientProperty = new UIPropertyBox(i, eachProperty.getDisplayName(), controlNode,
UIPropertyBox clientProperty = new UIPropertyBox(i, eachProperty.getDisplayName(), controlNode,
eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
actionClientProperties.add(clientProperty);
actionClientProperties.add(clientProperty);
clientPropertiesVBox.getChildren().add(hBox);
clientPropertiesVBox.getChildren().add(hBox);
}
}
}
}
public void onSaveButtonClicked()
public void onSaveButtonClicked()
{
{
try {
try {
// saveButton.setDisable(true);
// saveButton.setDisable(true);
// deleteButton.setDisable(true);
// deleteButton.setDisable(true);
validateForm();
validateForm();
saveAction();
saveAction();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
private boolean sendIcon = false;
private boolean sendIcon = false;
@Override
@Override
public void setSendIcon(boolean sendIcon)
public void setSendIcon(boolean sendIcon)
{
{
this.sendIcon = sendIcon;
this.sendIcon = sendIcon;
}
}
public void addActionToCurrentClientProfile(Action newAction) throws CloneNotSupportedException {
public void addActionToCurrentClientProfile(Action newAction) throws CloneNotSupportedException {
getClientProfile().addAction(newAction);
getClientProfile().addAction(newAction);
}
}
@Override
@Override
public void saveAction(Action action, boolean runAsync)
public void saveAction(Action action, boolean runAsync)
{
{
new OnSaveActionTask(
new OnSaveActionTask(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
getClient().getRemoteSocketAddress()
getClient().getRemoteSocketAddress()
),
),
action,
action,
displayNameTextField.getText(),
displayNameTextField.getText(),
isCombineChild(),
isCombineChild(),
!hideDisplayTextCheckBox.isSelected(),
!hideDisplayTextCheckBox.isSelected(),
displayTextColourDefaultCheckBox.isSelected(),
displayTextColourDefaultCheckBox.isSelected(),
"#" + displayTextColourPicker.getValue().toString().substring(2),
"#" + displayTextColourPicker.getValue().toString().substring(2),
clearIconButton.isDisable(),
clearIconButton.isDisable(),
!hideIconCheckBox.isSelected(),
!hideIconCheckBox.isSelected(),
displayTextAlignmentComboBox.getSelectionModel().getSelectedItem(),
displayTextAlignmentComboBox.getSelectionModel().getSelectedItem(),
actionBackgroundColourTransparentCheckBox.isSelected(),
actionBackgroundColourTransparentCheckBox.isSelected(),
"#" + actionBackgroundColourPicker.getValue().toString().substring(2),
"#" + actionBackgroundColourPicker.getValue().toString().substring(2),
getCombineActionPropertiesPane(),
getCombineActionPropertiesPane(),
clientProfile, sendIcon, actionBox, actionClientProperties, exceptionAndAlertHandler,
clientProfile, sendIcon, actionBox, actionClientProperties, exceptionAndAlertHandler,
saveButton, deleteButton, runAsync
saveButton, deleteButton, runAsync
);
);
}
}
@Override
@Override
public void saveAction()
public void saveAction()
{
{
saveAction(action, true);
saveAction(action, true);
}
}
public void setFolderButtonVisible(boolean visible)
public void setFolderButtonVisible(boolean visible)
{
{
openFolderButton.setVisible(visible);
openFolderButton.setVisible(visible);
}
}
public void validateForm() throws MinorException
public void validateForm() throws MinorException
{
{
String displayNameStr = displayNameTextField.getText();
String displayNameStr = displayNameTextField.getText();
StringBuilder finalErrors = new StringBuilder();
StringBuilder finalErrors = new StringBuilder();
if(displayNameStr.isBlank())
if(displayNameStr.isBlank())
{
{
finalErrors.append(" * Display Name cannot be blank\n");
finalErrors.append(" * Display Name cannot be blank\n");
}
}
if(!isCombineChild())
if(!isCombineChild())
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
if(hideDisplayTextCheckBox.isSelected() && hideIconCheckBox.isSelected())
if(hideDisplayTextCheckBox.isSelected() && hideIconCheckBox.isSelected())
finalErrors.append(" * Both Icon and display text check box cannot be hidden.\n");
finalErrors.append(" * Both Icon and display text check box cannot be hidden.\n");
}
}
else
else
{
{
if(hideDisplayTextCheckBox.isSelected())
if(hideDisplayTextCheckBox.isSelected())
finalErrors.append(" * Display Text cannot be hidden, since there is also no icon.\n");
finalErrors.append(" * Display Text cannot be hidden, since there is also no icon.\n");
}
}
}
}
for (UIPropertyBox clientProperty : actionClientProperties) {
for (UIPropertyBox clientProperty : actionClientProperties) {
Node controlNode = clientProperty.getControlNode();
Node controlNode = clientProperty.getControlNode();
if (clientProperty.getControlType() == ControlType.TEXT_FIELD)
if (clientProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
String value = ((TextField) controlNode).getText();
String value = ((TextField) controlNode).getText();
if(clientProperty.getType() == Type.INTEGER)
if(clientProperty.getType() == Type.INTEGER)
{
{
try
try
{
{
Integer.parseInt(value);
Integer.parseInt(value);
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" must be integer.\n");
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" must be integer.\n");
}
}
}
}
else
else
{
{
if(value.isBlank() && !clientProperty.isCanBeBlank())
if(value.isBlank() && !clientProperty.isCanBeBlank())
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" cannot be blank.\n");
finalErrors.append(" -> ").append(clientProperty.getDisplayName()).append(" cannot be blank.\n");
}
}
}
}
}
}
if(!finalErrors.toString().isEmpty())
if(!finalErrors.toString().isEmpty())
{
{
throw new MinorException("You made mistakes",
throw new MinorException("You made mistakes",
finalErrors.toString());
finalErrors.toString());
}
}
}
}
public void onDeleteButtonClicked()
public void onDeleteButtonClicked()
{
{
new OnDeleteActionTask(
new OnDeleteActionTask(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
ClientConnections.getInstance().getClientConnectionBySocketAddress(
getClient().getRemoteSocketAddress()
getClient().getRemoteSocketAddress()
),
),
action,
action,
isCombineChild(),
isCombineChild(),
getCombineActionPropertiesPane(),
getCombineActionPropertiesPane(),
clientProfile, actionBox, this, exceptionAndAlertHandler,
clientProfile, actionBox, this, exceptionAndAlertHandler,
!isCombineChild
!isCombineChild
);
);
}
}
}
}
package com.stream_pi.server.window.dashboard.actiondetailpane;
package com.stream_pi.server.window.dashboard.actiondetailpane;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.otheractions.CombineAction;
import com.stream_pi.actionapi.otheractions.CombineAction;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import javafx.event.ActionEvent;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
public class CombineActionPropertiesPane extends VBox {
public class CombineActionPropertiesPane extends VBox {
private CombineAction combineAction;
private CombineAction combineAction;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
private ActionDetailsPane actionDetailsPane;
private ActionDetailsPane actionDetailsPane;
public CombineAction getCombineAction() {
public CombineAction getCombineAction() {
return combineAction;
return combineAction;
}
}
public CombineActionPropertiesPane(CombineAction combineAction, ClientProfile clientProfile, ActionDetailsPane actionDetailsPane) throws MinorException {
public CombineActionPropertiesPane(CombineAction combineAction, ClientProfile clientProfile, ActionDetailsPane actionDetailsPane) throws MinorException {
this.combineAction = combineAction;
this.combineAction = combineAction;
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
this.actionDetailsPane = actionDetailsPane;
this.actionDetailsPane = actionDetailsPane;
setSpacing(10.0);
setSpacing(10.0);
setPadding(new Insets(0,0,10,0));
setPadding(new Insets(0,0,10,0));
renderProps();
renderProps();
}
}
public void renderProps() throws MinorException {
public void renderProps() throws MinorException {
getChildren().clear();
getChildren().clear();
int i = 0;
int i = 0;
for(String actionID : combineAction.getChildrenIDSequential())
for(String actionID : combineAction.getChildrenIDSequential())
{
{
Action action = clientProfile.getActionByID(actionID);
Action action = clientProfile.getActionByID(actionID);
System.out.println("232323xxxxxxxxxxxx : "+action.getID());
System.out.println("232323xxxxxxxxxxxx : "+action.getID());
Button settingsButton = new Button();
Button settingsButton = new Button();
FontIcon settingsFontIcon = new FontIcon("fas-cog");
FontIcon settingsFontIcon = new FontIcon("fas-cog");
settingsButton.setGraphic(settingsFontIcon);
settingsButton.setGraphic(settingsFontIcon);
settingsButton.setOnAction(event -> onSettingsButtonClicked(action));
settingsButton.setOnAction(event -> onSettingsButtonClicked(action));
Button upButton = new Button();
Button upButton = new Button();
FontIcon upButtonFontIcon = new FontIcon("fas-chevron-up");
FontIcon upButtonFontIcon = new FontIcon("fas-chevron-up");
upButton.setGraphic(upButtonFontIcon);
upButton.setGraphic(upButtonFontIcon);
Button downButton = new Button();
Button downButton = new Button();
FontIcon downButtonFontIcon = new FontIcon("fas-chevron-down");
FontIcon downButtonFontIcon = new FontIcon("fas-chevron-down");
downButton.setGraphic(downButtonFontIcon);
downButton.setGraphic(downButtonFontIcon);
Label displayTextLabel = new Label(action.getDisplayText());
Label displayTextLabel = new Label(action.getDisplayText());
displayTextLabel.setId(action.getID());
displayTextLabel.setId(action.getID());
Region r = new Region();
Region r = new Region();
HBox.setHgrow(r, Priority.ALWAYS);
HBox.setHgrow(r, Priority.ALWAYS);
HBox actionHBox = new HBox(displayTextLabel, r, settingsButton, upButton, downButton);
HBox actionHBox = new HBox(displayTextLabel, r, settingsButton, upButton, downButton);
actionHBox.setSpacing(5.0);
actionHBox.setSpacing(5.0);
upButton.setUserData(i);
upButton.setUserData(i);
downButton.setUserData(i);
downButton.setUserData(i);
upButton.setOnAction(this::onUpButtonClicked);
upButton.setOnAction(this::onUpButtonClicked);
downButton.setOnAction(this::onDownButtonClicked);
downButton.setOnAction(this::onDownButtonClicked);
System.out.println("67878678678678");
getChildren().add(actionHBox);
getChildren().add(actionHBox);
System.out.println("9mhmmn");
i++;
i++;
}
}
}
}
public void onSettingsButtonClicked(Action action)
public void onSettingsButtonClicked(Action action)
{
{
actionDetailsPane.clear();
actionDetailsPane.clear();
actionDetailsPane.setAction(action);
actionDetailsPane.setAction(action);
try {
try {
actionDetailsPane.renderActionProperties();
actionDetailsPane.renderActionProperties();
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void onUpButtonClicked(ActionEvent event) {
public void onUpButtonClicked(ActionEvent event) {
try {
try {
Node node = (Node) event.getSource();
Node node = (Node) event.getSource();
int currentIndex = (int) node.getUserData();
int currentIndex = (int) node.getUserData();
if(currentIndex > 0)
if(currentIndex > 0)
{
{
Property current = combineAction.getClientProperties().getSingleProperty(currentIndex+"");
Property current = combineAction.getClientProperties().getSingleProperty(currentIndex+"");
Property aboveOne = combineAction.getClientProperties().getSingleProperty((currentIndex-1)+"");
Property aboveOne = combineAction.getClientProperties().getSingleProperty((currentIndex-1)+"");
combineAction.addChild(current.getRawValue(), currentIndex-1);
combineAction.addChild(current.getRawValue(), currentIndex-1);
combineAction.addChild(aboveOne.getRawValue(), currentIndex);
combineAction.addChild(aboveOne.getRawValue(), currentIndex);
actionDetailsPane.saveAction();
actionDetailsPane.saveAction();
renderProps();
renderProps();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void onDownButtonClicked(ActionEvent event)
public void onDownButtonClicked(ActionEvent event)
{
{
try {
try {
Node node = (Node) event.getSource();
Node node = (Node) event.getSource();
int currentIndex = (int) node.getUserData();
int currentIndex = (int) node.getUserData();
if(currentIndex < getChildren().size() - 1)
if(currentIndex < getChildren().size() - 1)
{
{
Property current = combineAction.getClientProperties().getSingleProperty(currentIndex+"");
Property current = combineAction.getClientProperties().getSingleProperty(currentIndex+"");
Property belowOne = combineAction.getClientProperties().getSingleProperty((currentIndex+1)+"");
Property belowOne = combineAction.getClientProperties().getSingleProperty((currentIndex+1)+"");
combineAction.addChild(current.getRawValue(), currentIndex+1);
combineAction.addChild(current.getRawValue(), currentIndex+1);
combineAction.addChild(belowOne.getRawValue(), currentIndex);
combineAction.addChild(belowOne.getRawValue(), currentIndex);
actionDetailsPane.saveAction();
actionDetailsPane.saveAction();
renderProps();
renderProps();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public List<String> getFinalChildren()
public List<String> getFinalChildren()
{
{
ArrayList<String> children = new ArrayList<>();
ArrayList<String> children = new ArrayList<>();
for(int i = 0;i<getChildren().size();i++)
for(int i = 0;i<getChildren().size();i++)
{
{
HBox hBox = (HBox) getChildren().get(i);
HBox hBox = (HBox) getChildren().get(i);
Label label = (Label) hBox.getChildren().get(0);
Label label = (Label) hBox.getChildren().get(0);
children.add(label.getId());
children.add(label.getId());
}
}
return children;
return children;
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.ActionType;
import com.stream_pi.actionapi.action.ActionType;
import com.stream_pi.actionapi.action.DisplayTextAlignment;
import com.stream_pi.actionapi.action.DisplayTextAlignment;
import com.stream_pi.actionapi.action.Location;
import com.stream_pi.actionapi.action.Location;
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 javafx.application.Platform;
import javafx.application.Platform;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseButton;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Background;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextAlignment;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectInputStream;
import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
public class ActionBox extends StackPane{
public class ActionBox extends StackPane{
private Label displayTextLabel;
private Label displayTextLabel;
private int row;
private int row;
private int col;
private int col;
public void setRow(int row) {
public void setRow(int row) {
this.row = row;
this.row = row;
}
}
public void setCol(int col) {
public void setCol(int col) {
this.col = col;
this.col = col;
}
}
public int getRow() {
public int getRow() {
return row;
return row;
}
}
public int getCol() {
public int getCol() {
return col;
return col;
}
}
private ActionDetailsPaneListener actionDetailsPaneListener;
private ActionDetailsPaneListener actionDetailsPaneListener;
public void clear()
public void clear()
{
{
setAction(null);
setAction(null);
setInvalid(false);
setInvalid(false);
setBackground(Background.EMPTY);
setBackground(Background.EMPTY);
setStyle(null);
setStyle(null);
getChildren().clear();
getChildren().clear();
}
}
public void baseInit()
public void baseInit()
{
{
displayTextLabel = new Label();
displayTextLabel = new Label();
displayTextLabel.setWrapText(true);
displayTextLabel.setWrapText(true);
displayTextLabel.setTextAlignment(TextAlignment.CENTER);
displayTextLabel.setTextAlignment(TextAlignment.CENTER);
displayTextLabel.getStyleClass().add("action_box_display_text_label");
displayTextLabel.getStyleClass().add("action_box_display_text_label");
displayTextLabel.prefHeightProperty().bind(heightProperty());
displayTextLabel.prefHeightProperty().bind(heightProperty());
displayTextLabel.prefWidthProperty().bind(widthProperty());
displayTextLabel.prefWidthProperty().bind(widthProperty());
getChildren().addAll(displayTextLabel);
getChildren().addAll(displayTextLabel);
setMinSize(size, size);
setMinSize(size, size);
setMaxSize(size, size);
setMaxSize(size, size);
getStyleClass().add("action_box");
getStyleClass().add("action_box");
getStyleClass().add("action_box_icon_not_present");
getStyleClass().add("action_box_icon_not_present");
getStyleClass().add("action_box_valid");
getStyleClass().add("action_box_valid");
setOnDragOver(dragEvent ->
setOnDragOver(dragEvent ->
{
{
if(dragEvent.getDragboard().hasContent(Action.getDataFormat()))
if(dragEvent.getDragboard().hasContent(Action.getDataFormat()))
{
{
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.consume();
dragEvent.consume();
}
}
});
});
setOnDragDropped(dragEvent ->
setOnDragDropped(dragEvent ->
{
{
try
try
{
{
if(action == null)
if(action == null)
{
{
Action action = (Action) dragEvent.getDragboard().getContent(Action.getDataFormat());
Action action = (Action) dragEvent.getDragboard().getContent(Action.getDataFormat());
action.setLocation(new Location(getRow(),
action.setLocation(new Location(getRow(),
getCol()));
getCol()));
action.setParent(getStreamPiParent());
action.setParent(getStreamPiParent());
action.setIDRandom();
action.setIDRandom();
actionGridPaneListener.addActionToCurrentClientProfile(action);
actionGridPaneListener.addActionToCurrentClientProfile(action);
setAction(action);
setAction(action);
init();
init();
actionDetailsPaneListener.onActionClicked(action, this);
actionDetailsPaneListener.onActionClicked(action, this);
if(action.isHasIcon())
if(action.isHasIcon())
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.saveAction();
actionDetailsPaneListener.saveAction();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
});
});
setOnDragDetected(mouseEvent -> {
setOnDragDetected(mouseEvent -> {
try {
try {
if(action!=null)
if(action!=null)
{
{
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
Dragboard db = startDragAndDrop(TransferMode.ANY);
Dragboard db = startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
Action newAction = (Action) action.clone();
Action newAction = (Action) action.clone();
newAction.setIDRandom();
newAction.setIDRandom();
newAction.setParent(getStreamPiParent());
newAction.setParent(getStreamPiParent());
content.put(Action.getDataFormat(), newAction);
content.put(Action.getDataFormat(), newAction);
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
}
}
}
}
}
}
catch (CloneNotSupportedException e)
catch (CloneNotSupportedException e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
setOnMouseClicked(mouseEvent -> {
setOnMouseClicked(mouseEvent -> {
if(action != null && mouseEvent.getButton().equals(MouseButton.PRIMARY))
if(action != null && mouseEvent.getButton().equals(MouseButton.PRIMARY))
{
{
if(mouseEvent.getClickCount() == 2 && action.getActionType() == ActionType.FOLDER)
if(mouseEvent.getClickCount() == 2 && action.getActionType() == ActionType.FOLDER)
{
{
getActionDetailsPaneListener().onOpenFolderButtonClicked();
getActionDetailsPaneListener().onOpenFolderButtonClicked();
}
}
else
else
{
{
try
try
{
{
actionDetailsPaneListener.onActionClicked(action, this);
actionDetailsPaneListener.onActionClicked(action, this);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
});
});
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
public void setInvalid(boolean invalid)
public void setInvalid(boolean invalid)
{
{
if(invalid)
if(invalid)
{
{
getStyleClass().remove("action_box_valid");
getStyleClass().remove("action_box_valid");
getStyleClass().add("action_box_invalid");
getStyleClass().add("action_box_invalid");
}
}
else
else
{
{
getStyleClass().remove("action_box_invalid");
getStyleClass().remove("action_box_invalid");
getStyleClass().add("action_box_valid");
getStyleClass().add("action_box_valid");
}
}
}
}
public ActionDetailsPaneListener getActionDetailsPaneListener() {
public ActionDetailsPaneListener getActionDetailsPaneListener() {
return actionDetailsPaneListener;
return actionDetailsPaneListener;
}
}
public ActionGridPaneListener getActionGridPaneListener() {
public ActionGridPaneListener getActionGridPaneListener() {
return actionGridPaneListener;
return actionGridPaneListener;
}
}
private int size;
private int size;
private ActionGridPaneListener actionGridPaneListener;
private ActionGridPaneListener actionGridPaneListener;
public ActionBox(int size, ActionDetailsPaneListener actionDetailsPaneListener, ActionGridPaneListener actionGridPaneListener)
public ActionBox(int size, ActionDetailsPaneListener actionDetailsPaneListener, ActionGridPaneListener actionGridPaneListener)
{
{
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.size = size;
this.size = size;
baseInit();
baseInit();
}
}
public static Action deserialize(ByteBuffer buffer) {
public static Action deserialize(ByteBuffer buffer) {
try {
try {
ByteArrayInputStream is = new ByteArrayInputStream(buffer.array());
ByteArrayInputStream is = new ByteArrayInputStream(buffer.array());
ObjectInputStream ois = new ObjectInputStream(is);
ObjectInputStream ois = new ObjectInputStream(is);
Action obj = (Action) ois.readObject();
Action obj = (Action) ois.readObject();
return obj;
return obj;
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
throw new RuntimeException(e);
throw new RuntimeException(e);
}
}
}
}
public void setIcon(byte[] iconByteArray)
public void setIcon(byte[] iconByteArray)
{
{
if(iconByteArray == null)
if(iconByteArray == null)
{
{
getStyleClass().remove("action_box_icon_present");
getStyleClass().remove("action_box_icon_present");
getStyleClass().add("action_box_icon_not_present");
getStyleClass().add("action_box_icon_not_present");
setBackground(null);
setBackground(null);
return;
return;
}
}
else
else
{
{
getStyleClass().add("action_box_icon_present");
getStyleClass().add("action_box_icon_present");
getStyleClass().remove("action_box_icon_not_present");
getStyleClass().remove("action_box_icon_not_present");
setBackground(
setBackground(
new Background(
new Background(
new BackgroundImage(new Image(
new BackgroundImage(new Image(
new ByteArrayInputStream(iconByteArray), size, size, false, true
new ByteArrayInputStream(iconByteArray), size, size, false, true
), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
new BackgroundSize(100, 100, true, true, true, false))
new BackgroundSize(100, 100, true, true, true, false))
)
)
);
);
}
}
}
}
private Action action;
private Action action;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private String parent;
private String parent;
public String getStreamPiParent() {
public String getStreamPiParent() {
return parent;
return parent;
}
}
public void setStreamPiParent(String parent) {
public void setStreamPiParent(String parent) {
this.parent = parent;
this.parent = parent;
}
}
public ActionBox(int size, Action action, ActionDetailsPaneListener actionDetailsPaneListener, ExceptionAndAlertHandler exceptionAndAlertHandler, ActionGridPaneListener actionGridPaneListener)
public ActionBox(int size, Action action, ActionDetailsPaneListener actionDetailsPaneListener, ExceptionAndAlertHandler exceptionAndAlertHandler, ActionGridPaneListener actionGridPaneListener)
{
{
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.action = action;
this.action = action;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.size = size;
this.size = size;
baseInit();
baseInit();
init();
init();
}
}
public void setAction(Action action)
public void setAction(Action action)
{
{
this.action = action;
this.action = action;
}
}
public void init()
public void init()
{
{
if(action.isShowDisplayText())
if(action.isShowDisplayText())
setDisplayTextLabel(action.getDisplayText());
setDisplayTextLabel(action.getDisplayText());
else
else
setDisplayTextLabel("");
setDisplayTextLabel("");
setDisplayTextAlignment(action.getDisplayTextAlignment());
setDisplayTextAlignment(action.getDisplayTextAlignment());
setBackgroundColour(action.getBgColourHex());
setBackgroundColour(action.getBgColourHex());
setDisplayTextFontColour(action.getDisplayTextFontColourHex());
setDisplayTextFontColour(action.getDisplayTextFontColourHex());
setInvalid(action.isInvalid());
setInvalid(action.isInvalid());
Platform.runLater(()->{
Platform.runLater(()->{
if(action.isHasIcon() && action.isShowIcon())
if(action.isHasIcon() && action.isShowIcon())
{
{
setIcon(action.getIconAsByteArray());
setIcon(action.getIconAsByteArray());
}
}
else
else
{
{
setIcon(null);
setIcon(null);
}
}
});
});
}
}
public void setDisplayTextLabel(String text)
public void setDisplayTextLabel(String text)
{
{
displayTextLabel.setText(text);
displayTextLabel.setText(text);
}
}
public void setDisplayTextAlignment(DisplayTextAlignment displayTextAlignment)
public void setDisplayTextAlignment(DisplayTextAlignment displayTextAlignment)
{
{
if(displayTextAlignment == DisplayTextAlignment.CENTER)
if(displayTextAlignment == DisplayTextAlignment.CENTER)
displayTextLabel.setAlignment(Pos.CENTER);
displayTextLabel.setAlignment(Pos.CENTER);
else if (displayTextAlignment == DisplayTextAlignment.BOTTOM)
else if (displayTextAlignment == DisplayTextAlignment.BOTTOM)
displayTextLabel.setAlignment(Pos.BOTTOM_CENTER);
displayTextLabel.setAlignment(Pos.BOTTOM_CENTER);
else if (displayTextAlignment == DisplayTextAlignment.TOP)
else if (displayTextAlignment == DisplayTextAlignment.TOP)
displayTextLabel.setAlignment(Pos.TOP_CENTER);
displayTextLabel.setAlignment(Pos.TOP_CENTER);
}
}
public void setDisplayTextFontColour(String colour)
public void setDisplayTextFontColour(String colour)
{
{
System.out.println("COLOr : "+colour);
System.out.println("COLOr : "+colour);
if(!colour.isEmpty())
if(!colour.isEmpty())
displayTextLabel.setStyle("-fx-text-fill : "+colour+";");
displayTextLabel.setStyle("-fx-text-fill : "+colour+";");
}
}
public void setBackgroundColour(String colour)
public void setBackgroundColour(String colour)
{
{
System.out.println("COLOr : "+colour);
System.out.println("COLOr : "+colour);
if(!colour.isEmpty() && action.getIconAsByteArray() == null)
if(!colour.isEmpty() && action.getIconAsByteArray() == null)
setStyle("-fx-background-color : "+colour);
setStyle("-fx-background-color : "+colour);
}
}
}
}
package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.Action;
import com.stream_pi.actionapi.action.Location;
import com.stream_pi.actionapi.action.Location;
import com.stream_pi.actionapi.otheractions.FolderAction;
import com.stream_pi.actionapi.otheractions.FolderAction;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.Client;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener {
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ActionDetailsPaneListener actionDetailsPaneListener;
private ActionDetailsPaneListener actionDetailsPaneListener;
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler)
{
{
logger = Logger.getLogger(ActionGridPane.class.getName());
logger = Logger.getLogger(ActionGridPane.class.getName());
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
getStyleClass().add("action_grid_pane_scroll_pane");
getStyleClass().add("action_grid_pane_parent");
VBox.setVgrow(this, Priority.ALWAYS);
VBox.setVgrow(this, Priority.ALWAYS);
actionsGridPane = new GridPane();
actionsGridPane = new GridPane();
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
actionsGridPane.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
setContent(actionsGridPane);
setContent(actionsGridPane);
}
}
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
public void setActionDetailsPaneListener(ActionDetailsPaneListener actionDetailsPaneListener) {
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
}
}
private String currentParent;
private String currentParent;
public void setCurrentParent(String currentParent) {
public void setCurrentParent(String currentParent) {
this.currentParent = currentParent;
this.currentParent = currentParent;
}
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
private Client client;
private Client client;
public void setClient(Client client) {
public void setClient(Client client) {
this.client = client;
this.client = client;
}
}
public Client getClient() {
public Client getClient() {
return client;
return client;
}
}
private int rows, cols;
private int rows, cols;
private GridPane actionsGridPane;
private GridPane actionsGridPane;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClientProfile(ClientProfile clientProfile)
public void setClientProfile(ClientProfile clientProfile)
{
{
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
setCurrentParent("root");
setCurrentParent("root");
setRows(clientProfile.getRows());
setRows(clientProfile.getRows());
setCols(clientProfile.getCols());
setCols(clientProfile.getCols());
}
}
public String getCurrentParent() {
public String getCurrentParent() {
return currentParent;
return currentParent;
}
}
public StackPane getFolderBackButton() throws SevereException
public StackPane getFolderBackButton() throws SevereException
{
{
StackPane stackPane = new StackPane();
StackPane stackPane = new StackPane();
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box_valid");
stackPane.getStyleClass().add("action_box_valid");
stackPane.setPrefSize(
stackPane.setPrefSize(
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize(),
Config.getInstance().getActionGridActionSize()
Config.getInstance().getActionGridActionSize()
);
);
FontIcon fontIcon = new FontIcon("fas-chevron-left");
FontIcon fontIcon = new FontIcon("fas-chevron-left");
fontIcon.setIconSize(Config.getInstance().getActionGridActionSize() - 30);
fontIcon.setIconSize(Config.getInstance().getActionGridActionSize() - 30);
stackPane.setAlignment(Pos.CENTER);
stackPane.setAlignment(Pos.CENTER);
stackPane.getChildren().add(fontIcon);
stackPane.getChildren().add(fontIcon);
stackPane.setOnMouseClicked(e->returnToPreviousParent());
stackPane.setOnMouseClicked(e->returnToPreviousParent());
return stackPane;
return stackPane;
}
}
public void renderGrid() throws SevereException {
public void renderGrid() throws SevereException {
clear();
clear();
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setHgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
actionsGridPane.setVgap(Config.getInstance().getActionGridActionGap());
boolean isFolder = false;
boolean isFolder = false;
if(!getCurrentParent().equals("root"))
if(!getCurrentParent().equals("root"))
{
{
isFolder = true;
isFolder = true;
actionsGridPane.add(getFolderBackButton(), 0,0);
actionsGridPane.add(getFolderBackButton(), 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;
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this);
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), actionDetailsPaneListener, this);
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
actionBox.setRow(row);
actionBox.setRow(row);
actionBox.setCol(col);
actionBox.setCol(col);
actionsGridPane.add(actionBox, row, col);
actionsGridPane.add(actionBox, row, col);
}
}
}
}
}
}
public void renderActions()
public void renderActions()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(String action1x : getClientProfile().getActionsKeySet())
for(String action1x : getClientProfile().getActionsKeySet())
{
{
Action eachAction = getClientProfile().getActionByID(action1x);
Action eachAction = getClientProfile().getActionByID(action1x);
logger.info("action ID : "+eachAction.getID()+
logger.info("action ID : "+eachAction.getID()+
"\nInvalid : "+eachAction.isInvalid());
"\nInvalid : "+eachAction.isInvalid());
try {
try {
renderAction(eachAction);
renderAction(eachAction);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
errors.append("*").append(e.getShortMessage()).append("\n");
errors.append("*").append(e.getShortMessage()).append("\n");
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
}
}
}
}
public void clear()
public void clear()
{
{
actionsGridPane.getChildren().clear();
actionsGridPane.getChildren().clear();
}
}
private Logger logger;
private Logger logger;
public void renderAction(Action action) throws SevereException, MinorException
public void renderAction(Action action) throws SevereException, MinorException
{
{
if(!action.getParent().equals(currentParent))
if(!action.getParent().equals(currentParent))
{
{
logger.info("Skipping action "+action.getID()+", not current parent!");
logger.info("Skipping action "+action.getID()+", not current parent!");
return;
return;
}
}
if(action.getLocation().getRow()==-1)
if(action.getLocation().getRow()==-1)
{
{
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
logger.info("action has -1 rowIndex. Probably Combine action. Skipping ...");
return;
return;
}
}
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
if(action.getLocation().getRow() >= rows || action.getLocation().getCol() >= cols)
{
{
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
throw new MinorException("action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
" Consider increasing rows/cols from client settings and relocating/deleting it.");
" Consider increasing rows/cols from client settings and relocating/deleting it.");
}
}
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
ActionBox actionBox = new ActionBox(Config.getInstance().getActionGridActionSize(), action, actionDetailsPaneListener, exceptionAndAlertHandler, this);
Location location = action.getLocation();
Location location = action.getLocation();
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
actionBox.setRow(location.getRow());
actionBox.setRow(location.getRow());
actionBox.setCol(location.getCol());
actionBox.setCol(location.getCol());
for(Node node : actionsGridPane.getChildren())
for(Node node : actionsGridPane.getChildren())
{
{
if(GridPane.getColumnIndex(node) == location.getRow() &&
if(GridPane.getColumnIndex(node) == location.getRow() &&
GridPane.getRowIndex(node) == location.getCol())
GridPane.getRowIndex(node) == location.getCol())
{
{
actionsGridPane.getChildren().remove(node);
actionsGridPane.getChildren().remove(node);
break;
break;
}
}
}
}
System.out.println(location.getCol()+","+location.getRow());
System.out.println(location.getCol()+","+location.getRow());
actionsGridPane.add(actionBox, location.getRow(), location.getCol());
actionsGridPane.add(actionBox, location.getRow(), location.getCol());
}
}
public void setRows(int rows)
public void setRows(int rows)
{
{
this.rows = rows;
this.rows = rows;
}
}
public void setCols(int cols)
public void setCols(int cols)
{
{
this.cols = cols;
this.cols = cols;
}
}
public int getRows()
public int getRows()
{
{
return rows;
return rows;
}
}
public int getCols()
public int getCols()
{
{
return cols;
return cols;
}
}
@Override
@Override
public void addActionToCurrentClientProfile(Action newAction) {
public void addActionToCurrentClientProfile(Action newAction) {
try {
try {
getClientProfile().addAction(newAction);
getClientProfile().addAction(newAction);
} catch (CloneNotSupportedException e) {
} catch (CloneNotSupportedException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private String previousParent;
private String previousParent;
public void setPreviousParent(String previousParent) {
public void setPreviousParent(String previousParent) {
this.previousParent = previousParent;
this.previousParent = previousParent;
}
}
public String getPreviousParent() {
public String getPreviousParent() {
return previousParent;
return previousParent;
}
}
@Override
@Override
public void renderFolder(FolderAction action) {
public void renderFolder(FolderAction action) {
setCurrentParent(action.getID());
setCurrentParent(action.getID());
setPreviousParent(action.getParent());
setPreviousParent(action.getParent());
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
public void returnToPreviousParent()
public void returnToPreviousParent()
{
{
setCurrentParent(getPreviousParent());
setCurrentParent(getPreviousParent());
if(!getPreviousParent().equals("root"))
if(!getPreviousParent().equals("root"))
{
{
System.out.println("parent : "+getPreviousParent());
System.out.println("parent : "+getPreviousParent());
setPreviousParent(getClientProfile().getActionByID(
setPreviousParent(getClientProfile().getActionByID(
getPreviousParent()
getPreviousParent()
).getParent());
).getParent());
}
}
try {
try {
renderGrid();
renderGrid();
renderActions();
renderActions();
} catch (SevereException e) {
} catch (SevereException e) {
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.actionapi.ActionAPI;
import com.stream_pi.actionapi.ActionAPI;
import com.stream_pi.server.info.License;
import com.stream_pi.server.info.License;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.Main;
import com.stream_pi.server.Main;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextArea;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.ImageView;
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 About extends VBox{
public class About extends VBox{
private HostServices hostServices;
private HostServices hostServices;
public About(HostServices hostServices)
public About(HostServices hostServices)
{
{
getStyleClass().add("about");
getStyleClass().add("about");
this.hostServices = hostServices;
this.hostServices = hostServices;
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
Image appIcon = new Image(Main.class.getResourceAsStream("app_icon.png"));
Image appIcon = new Image(Main.class.getResourceAsStream("app_icon.png"));
ImageView appIconImageView = new ImageView(appIcon);
ImageView appIconImageView = new ImageView(appIcon);
appIconImageView.setFitHeight(196);
appIconImageView.setFitHeight(196);
appIconImageView.setFitWidth(182);
appIconImageView.setFitWidth(182);
Label licenseLabel = new Label("License");
Label licenseLabel = new Label("License");
licenseLabel.getStyleClass().add("settings_about_license_label");
licenseLabel.getStyleClass().add("about_license_label");
VBox.setMargin(licenseLabel, new Insets(20, 0 , 10 ,0));
VBox.setMargin(licenseLabel, new Insets(20, 0 , 10 ,0));
TextArea licenseTextArea = new TextArea(License.getLicense());
TextArea licenseTextArea = new TextArea(License.getLicense());
licenseTextArea.setWrapText(false);
licenseTextArea.setWrapText(false);
licenseTextArea.setEditable(false);
licenseTextArea.setEditable(false);
licenseTextArea.setMaxWidth(550);
licenseTextArea.setMaxWidth(550);
VBox.setVgrow(licenseTextArea, Priority.ALWAYS);
VBox.setVgrow(licenseTextArea, Priority.ALWAYS);
HBox links = new HBox();
HBox links = new HBox();
Hyperlink github = new Hyperlink("GitHub");
Hyperlink github = new Hyperlink("GitHub");
github.setOnAction(event -> {
github.setOnAction(event -> openWebpage("https://github.com/Stream-Pi"));
openWebpage("https://github.com/Stream-Pi");
});
Hyperlink discord = new Hyperlink("Discord");
Hyperlink discord = new Hyperlink("Discord");
discord.setOnAction(event -> {
discord.setOnAction(event -> openWebpage("https://discord.gg/BExqGmk"));
openWebpage("https://discord.gg/BExqGmk");
});
Hyperlink website = new Hyperlink("Website");
Hyperlink website = new Hyperlink("Website");
website.setOnAction(event -> {
website.setOnAction(event -> openWebpage("https://stream-pi.com"));
openWebpage("https://stream-pi.com");
});
Hyperlink twitter = new Hyperlink("Twitter");
Hyperlink twitter = new Hyperlink("Twitter");
twitter.setOnAction(event -> {
twitter.setOnAction(event -> openWebpage("https://twitter.com/Stream_Pi"));
openWebpage("https://twitter.com/Stream_Pi");
});
Hyperlink matrix = new Hyperlink("Matrix");
Hyperlink matrix = new Hyperlink("Matrix");
matrix.setOnAction(event -> {
matrix.setOnAction(event -> openWebpage("https://matrix.to/#/#stream-pi_general:matrix.org"));
openWebpage("https://matrix.to/#/#stream-pi_general:matrix.org");
});
links.setSpacing(30);
links.setSpacing(30);
links.setAlignment(Pos.CENTER);
links.setAlignment(Pos.CENTER);
links.getChildren().addAll(github, matrix, discord, website, twitter);
links.getChildren().addAll(github, matrix, discord, website, twitter);
Hyperlink donateButton = new Hyperlink("DONATE");
Hyperlink donateButton = new Hyperlink("DONATE");
donateButton.setOnAction(event -> {
donateButton.setOnAction(event -> {
openWebpage("https://www.patreon.com/streampi");
openWebpage("https://www.patreon.com/streampi");
});
});
donateButton.getStyleClass().add("settings_about_donate_hyperlink");
donateButton.getStyleClass().add("settings_about_donate_hyperlink");
ServerInfo serverInfo = ServerInfo.getInstance();
ServerInfo serverInfo = ServerInfo.getInstance();
Label versionText = new Label(serverInfo.getVersion().getText() + " - "+ serverInfo.getPlatformType().getUIName() + " - "+ serverInfo.getReleaseStatus().getUIName());
Label versionText = new Label(serverInfo.getVersion().getText() + " - "+ serverInfo.getPlatformType().getUIName() + " - "+ serverInfo.getReleaseStatus().getUIName());
Label commStandardLabel = new Label("Comm Standard "+serverInfo.getCommStandardVersion().getText());
Label commStandardLabel = new Label("Comm Standard "+serverInfo.getCommStandardVersion().getText());
Label minThemeAPILabel = new Label("Min ThemeAPI "+serverInfo.getMinThemeSupportVersion().getText());
Label minThemeAPILabel = new Label("Min ThemeAPI "+serverInfo.getMinThemeSupportVersion().getText());
Label minActionAPILabel = new Label("Min ActionAPI "+serverInfo.getMinPluginSupportVersion().getText());
Label minActionAPILabel = new Label("Min ActionAPI "+serverInfo.getMinPluginSupportVersion().getText());
Label currentActionAPILabel = new Label("ActionAPI "+ ActionAPI.API_VERSION.getText());
Label currentActionAPILabel = new Label("ActionAPI "+ ActionAPI.API_VERSION.getText());
setSpacing(3);
setSpacing(3);
getChildren().addAll(appIconImageView, licenseLabel, licenseTextArea, links, donateButton, versionText, commStandardLabel, minThemeAPILabel, minActionAPILabel, currentActionAPILabel);
getChildren().addAll(appIconImageView, licenseLabel, licenseTextArea, links, donateButton, versionText, commStandardLabel, minThemeAPILabel, minActionAPILabel, currentActionAPILabel);
}
}
public void openWebpage(String url) {
public void openWebpage(String url) {
hostServices.showDocument(url);
hostServices.showDocument(url);
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
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.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import 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.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.platform.ReleaseStatus;
import com.stream_pi.util.platform.ReleaseStatus;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.FXCollections;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import javafx.util.Callback;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ClientsSettings extends VBox {
public class ClientsSettings extends VBox {
private VBox clientsSettingsVBox;
private VBox clientsSettingsVBox;
private Button saveButton;
private Button saveButton;
private ServerListener serverListener;
private ServerListener serverListener;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public ClientsSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener)
public ClientsSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener)
{
{
getStyleClass().add("clients_settings");
getStyleClass().add("clients_settings");
this.serverListener = serverListener;
this.serverListener = serverListener;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
clientSettingsVBoxArrayList = new ArrayList<>();
clientSettingsVBoxArrayList = new ArrayList<>();
setPadding(new Insets(10.0));
logger = Logger.getLogger(ClientsSettings.class.getName());
logger = Logger.getLogger(ClientsSettings.class.getName());
clientsSettingsVBox = new VBox();
clientsSettingsVBox = new VBox();
clientsSettingsVBox.setSpacing(20.0);
clientsSettingsVBox.getStyleClass().add("clients_settings_vbox");
clientsSettingsVBox.setAlignment(Pos.TOP_CENTER);
clientsSettingsVBox.setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("clients_settings_scroll_pane");
scrollPane.getStyleClass().add("clients_settings_scroll_pane");
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
clientsSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
clientsSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
scrollPane.setContent(clientsSettingsVBox);
scrollPane.setContent(clientsSettingsVBox);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event -> onSaveButtonClicked());
saveButton.setOnAction(event -> onSaveButtonClicked());
HBox hBox = new HBox(saveButton);
HBox hBox = new HBox(saveButton);
hBox.setAlignment(Pos.CENTER_RIGHT);
hBox.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(scrollPane, hBox);
getChildren().addAll(scrollPane, hBox);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
public void onSaveButtonClicked()
public void onSaveButtonClicked()
{
{
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
Platform.runLater(()->saveButton.setDisable(true));
Platform.runLater(()->saveButton.setDisable(true));
StringBuilder finalErrors = new StringBuilder();
StringBuilder finalErrors = new StringBuilder();
for(ClientSettingsVBox clientSettingsVBox : clientSettingsVBoxArrayList)
for(ClientSettingsVBox clientSettingsVBox : clientSettingsVBoxArrayList)
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(clientSettingsVBox.getNickname().isBlank())
if(clientSettingsVBox.getNickname().isBlank())
errors.append(" Cannot have blank nickname. \n");
errors.append(" Cannot have blank nickname. \n");
try {
try {
Double.parseDouble(clientSettingsVBox.getStartupWindowHeight());
Double.parseDouble(clientSettingsVBox.getStartupWindowHeight());
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append(" Must have integer display height. \n");
errors.append(" Must have integer display height. \n");
}
}
try {
try {
Double.parseDouble(clientSettingsVBox.getStartupWindowWidth());
Double.parseDouble(clientSettingsVBox.getStartupWindowWidth());
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append(" Must have integer display width. \n");
errors.append(" Must have integer display width. \n");
}
}
for(ClientProfileVBox clientProfileVBox : clientSettingsVBox.getClientProfileVBoxes())
for(ClientProfileVBox clientProfileVBox : clientSettingsVBox.getClientProfileVBoxes())
{
{
StringBuilder errors2 = new StringBuilder();
StringBuilder errors2 = new StringBuilder();
if(clientProfileVBox.getName().isBlank())
if(clientProfileVBox.getName().isBlank())
errors2.append(" cannot have blank nickname. \n");
errors2.append(" cannot have blank nickname. \n");
try {
try {
Integer.parseInt(clientProfileVBox.getActionSize());
Integer.parseInt(clientProfileVBox.getActionSize());
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors2.append(" Must have integer action Size. \n");
errors2.append(" Must have integer action Size. \n");
}
}
try {
try {
Integer.parseInt(clientProfileVBox.getActionGap());
Integer.parseInt(clientProfileVBox.getActionGap());
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors2.append(" Must have integer action Gap. \n");
errors2.append(" Must have integer action Gap. \n");
}
}
try {
try {
int rows = Integer.parseInt(clientProfileVBox.getRows());
int rows = Integer.parseInt(clientProfileVBox.getRows());
int actionsSize = Integer.parseInt(clientProfileVBox.getActionSize());
int actionsSize = Integer.parseInt(clientProfileVBox.getActionSize());
double startupWidth = Double.parseDouble(clientSettingsVBox.getStartupWindowWidth());
double startupWidth = Double.parseDouble(clientSettingsVBox.getStartupWindowWidth());
if((rows*actionsSize) > (startupWidth - 25) && clientSettingsVBox.getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID)
if((rows*actionsSize) > (startupWidth - 25) && clientSettingsVBox.getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID)
{
{
errors2.append(" Rows out of bounds of screen size. \n"+startupWidth);
errors2.append(" Rows out of bounds of screen size. \n"+startupWidth);
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors2.append(" Must have integer Rows. \n");
errors2.append(" Must have integer Rows. \n");
}
}
try {
try {
int cols = Integer.parseInt(clientProfileVBox.getCols());
int cols = Integer.parseInt(clientProfileVBox.getCols());
int actionsSize = Integer.parseInt(clientProfileVBox.getActionSize());
int actionsSize = Integer.parseInt(clientProfileVBox.getActionSize());
double startupHeight = Double.parseDouble(clientSettingsVBox.getStartupWindowHeight());
double startupHeight = Double.parseDouble(clientSettingsVBox.getStartupWindowHeight());
if((cols*actionsSize) > (startupHeight - 25) && clientSettingsVBox.getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID)
if((cols*actionsSize) > (startupHeight - 25) && clientSettingsVBox.getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID)
{
{
errors2.append(" Cols out of bounds of screen size. \n"+startupHeight);
errors2.append(" Cols out of bounds of screen size. \n"+startupHeight);
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors2.append(" Must have integer Columns. \n");
errors2.append(" Must have integer Columns. \n");
}
}
if(!errors2.toString().isEmpty())
if(!errors2.toString().isEmpty())
{
{
errors.append(" ")
errors.append(" ")
.append(clientProfileVBox.getRealName())
.append(clientProfileVBox.getRealName())
.append("\n")
.append("\n")
.append(errors2.toString())
.append(errors2.toString())
.append("\n");
.append("\n");
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
finalErrors.append("* ")
finalErrors.append("* ")
.append(clientSettingsVBox.getRealNickName())
.append(clientSettingsVBox.getRealNickName())
.append("\n")
.append("\n")
.append(errors.toString())
.append(errors.toString())
.append("\n");
.append("\n");
}
}
}
}
if(!finalErrors.toString().isEmpty())
if(!finalErrors.toString().isEmpty())
throw new MinorException("You made form mistakes",
throw new MinorException("You made form mistakes",
"Please fix the following issues : \n"+finalErrors.toString());
"Please fix the following issues : \n"+finalErrors.toString());
//save details and values
//save details and values
for(ClientSettingsVBox clientSettingsVBox : clientSettingsVBoxArrayList)
for(ClientSettingsVBox clientSettingsVBox : clientSettingsVBoxArrayList)
{
{
clientSettingsVBox.saveClientAndProfileDetails();
clientSettingsVBox.saveClientAndProfileDetails();
}
}
loadData();
loadData();
serverListener.clearTemp();
serverListener.clearTemp();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (CloneNotSupportedException e)
catch (CloneNotSupportedException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(new SevereException(
exceptionAndAlertHandler.handleSevereException(new SevereException(
e.getMessage()
e.getMessage()
));
));
}
}
finally
finally
{
{
Platform.runLater(()->saveButton.setDisable(false));
Platform.runLater(()->saveButton.setDisable(false));
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
private ArrayList<ClientSettingsVBox> clientSettingsVBoxArrayList;
private ArrayList<ClientSettingsVBox> clientSettingsVBoxArrayList;
public void loadData()
public void loadData()
{
{
logger.info("Loading client data into ClientsSettings ...");
logger.info("Loading client data into ClientsSettings ...");
Platform.runLater(()-> clientsSettingsVBox.getChildren().clear());
Platform.runLater(()-> clientsSettingsVBox.getChildren().clear());
clientSettingsVBoxArrayList.clear();
clientSettingsVBoxArrayList.clear();
List<ClientConnection> clientConnections = ClientConnections.getInstance().getConnections();
List<ClientConnection> clientConnections = ClientConnections.getInstance().getConnections();
if(clientConnections.size() == 0)
if(clientConnections.size() == 0)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
clientsSettingsVBox.getChildren().add(new Label("No Clients Connected."));
clientsSettingsVBox.getChildren().add(new Label("No Clients Connected."));
saveButton.setVisible(false);
saveButton.setVisible(false);
});
});
}
}
else
else
{
{
Platform.runLater(()->saveButton.setVisible(true));
Platform.runLater(()->saveButton.setVisible(true));
for (ClientConnection clientConnection : clientConnections) {
for (ClientConnection clientConnection : clientConnections) {
ClientSettingsVBox clientSettingsVBox = new ClientSettingsVBox(clientConnection);
ClientSettingsVBox clientSettingsVBox = new ClientSettingsVBox(clientConnection);
clientSettingsVBoxArrayList.add(clientSettingsVBox);
clientSettingsVBoxArrayList.add(clientSettingsVBox);
Platform.runLater(()->clientsSettingsVBox.getChildren().add(clientSettingsVBox));
Platform.runLater(()->clientsSettingsVBox.getChildren().add(clientSettingsVBox));
}
}
}
}
logger.info("... Done!");
logger.info("... Done!");
}
}
public class ClientSettingsVBox extends VBox
public class ClientSettingsVBox extends VBox
{
{
private ComboBox<ClientProfile> profilesComboBox;
private ComboBox<ClientProfile> profilesComboBox;
private ComboBox<ClientTheme> themesComboBox;
private ComboBox<ClientTheme> themesComboBox;
private TextField startupWindowHeightTextField;
private TextField startupWindowHeightTextField;
public String getStartupWindowHeight() {
public String getStartupWindowHeight() {
return startupWindowHeightTextField.getText();
return startupWindowHeightTextField.getText();
}
}
private TextField startupWindowWidthTextField;
private TextField startupWindowWidthTextField;
public String getStartupWindowWidth() {
public String getStartupWindowWidth() {
return startupWindowWidthTextField.getText();
return startupWindowWidthTextField.getText();
}
}
private TextField nicknameTextField;
private TextField nicknameTextField;
public String getNickname() {
public String getNickname() {
return nicknameTextField.getText();
return nicknameTextField.getText();
}
}
private Label nickNameLabel;
private Label nickNameLabel;
private Label versionLabel;
private Label versionLabel;
public String getRealNickName()
public String getRealNickName()
{
{
return nickNameLabel.getText();
return nickNameLabel.getText();
}
}
private com.stream_pi.util.platform.Platform platform;
private com.stream_pi.util.platform.Platform platform;
public com.stream_pi.util.platform.Platform getPlatform() {
public com.stream_pi.util.platform.Platform getPlatform() {
return platform;
return platform;
}
}
private Label socketConnectionLabel;
private Label socketConnectionLabel;
private ClientConnection connection;
private ClientConnection connection;
private Accordion profilesAccordion;
private Accordion profilesAccordion;
private ArrayList<ClientProfileVBox> clientProfileVBoxes;
private ArrayList<ClientProfileVBox> clientProfileVBoxes;
private Label platformLabel;
private Label platformLabel;
private HBoxInputBox startupWindowHeightInputBox, startupWindowWidthInputBox;
private HBoxInputBox startupWindowHeightInputBox, startupWindowWidthInputBox;
public ArrayList<ClientProfileVBox> getClientProfileVBoxes() {
public ArrayList<ClientProfileVBox> getClientProfileVBoxes() {
return clientProfileVBoxes;
return clientProfileVBoxes;
}
}
public ClientSettingsVBox(ClientConnection connection)
public ClientSettingsVBox(ClientConnection connection)
{
{
this.connection = connection;
this.connection = connection;
this.platform = connection.getClient().getPlatform();
this.platform = connection.getClient().getPlatform();
clientProfileVBoxes = new ArrayList<>();
clientProfileVBoxes = new ArrayList<>();
getStyleClass().add("clients_settings_each_client_box");
initUI();
initUI();
loadValues();
loadValues();
}
}
public ClientConnection getConnection()
public ClientConnection getConnection()
{
{
return connection;
return connection;
}
}
public void saveClientAndProfileDetails() throws SevereException, CloneNotSupportedException, MinorException {
public void saveClientAndProfileDetails() throws SevereException, CloneNotSupportedException, MinorException {
System.out.println("IIN");
System.out.println("IIN");
getConnection().saveClientDetails(
getConnection().saveClientDetails(
nicknameTextField.getText(),
nicknameTextField.getText(),
startupWindowWidthTextField.getText(),
startupWindowWidthTextField.getText(),
startupWindowHeightTextField.getText(),
startupWindowHeightTextField.getText(),
profilesComboBox.getSelectionModel().getSelectedItem().getID(),
profilesComboBox.getSelectionModel().getSelectedItem().getID(),
themesComboBox.getSelectionModel().getSelectedItem().getThemeFullName()
themesComboBox.getSelectionModel().getSelectedItem().getThemeFullName()
);
);
System.out.println("OUT");
System.out.println("OUT");
logger.info("Profiles : ");
logger.info("Profiles : ");
for(ClientProfileVBox clientProfileVBox : clientProfileVBoxes)
for(ClientProfileVBox clientProfileVBox : clientProfileVBoxes)
{
{
logger.info("Name : "+clientProfileVBox.getClientProfile().getName());
logger.info("Name : "+clientProfileVBox.getClientProfile().getName());
getConnection().saveProfileDetails(clientProfileVBox.getClientProfile());
getConnection().saveProfileDetails(clientProfileVBox.getClientProfile());
}
}
//remove deleted client profiles
//remove deleted client profiles
for(ClientProfile clientProfile : connection.getClient().getAllClientProfiles())
for(ClientProfile clientProfile : connection.getClient().getAllClientProfiles())
{
{
boolean found = false;
boolean found = false;
for(ClientProfileVBox clientProfileVBox : clientProfileVBoxes)
for(ClientProfileVBox clientProfileVBox : clientProfileVBoxes)
{
{
if(clientProfileVBox.getClientProfile().getID().equals(clientProfile.getID()))
if(clientProfileVBox.getClientProfile().getID().equals(clientProfile.getID()))
{
{
found = true;
found = true;
break;
break;
}
}
}
}
if(!found)
if(!found)
{
{
connection.getClient().removeProfileFromID(clientProfile.getID());
connection.getClient().removeProfileFromID(clientProfile.getID());
connection.deleteProfile(clientProfile.getID());
connection.deleteProfile(clientProfile.getID());
}
}
}
}
}
}
public void initUI()
public void initUI()
{
{
profilesComboBox = new ComboBox<>();
profilesComboBox = new ComboBox<>();
Callback<ListView<ClientProfile>, ListCell<ClientProfile>> profilesComboBoxFactory = new Callback<>() {
Callback<ListView<ClientProfile>, ListCell<ClientProfile>> profilesComboBoxFactory = new Callback<>() {
@Override
@Override
public ListCell<ClientProfile> call(ListView<ClientProfile> clientConnectionListView) {
public ListCell<ClientProfile> call(ListView<ClientProfile> clientConnectionListView) {
return new ListCell<>() {
return new ListCell<>() {
@Override
@Override
protected void updateItem(ClientProfile clientProfile, boolean b) {
protected void updateItem(ClientProfile clientProfile, boolean b) {
super.updateItem(clientProfile, b);
super.updateItem(clientProfile, b);
if(clientProfile == null)
if(clientProfile == null)
{
{
setText(null);
setText(null);
}
}
else
else
{
{
setText(clientProfile.getName());
setText(clientProfile.getName());
}
}
}
}
};
};
}
}
};
};
profilesComboBox.setCellFactory(profilesComboBoxFactory);
profilesComboBox.setCellFactory(profilesComboBoxFactory);
profilesComboBox.setButtonCell(profilesComboBoxFactory.call(null));
profilesComboBox.setButtonCell(profilesComboBoxFactory.call(null));
themesComboBox = new ComboBox<>();
themesComboBox = new ComboBox<>();
Callback<ListView<ClientTheme>, ListCell<ClientTheme>> themesComboBoxFactory = new Callback<>() {
Callback<ListView<ClientTheme>, ListCell<ClientTheme>> themesComboBoxFactory = new Callback<>() {
@Override
@Override
public ListCell<ClientTheme> call(ListView<ClientTheme> clientConnectionListView) {
public ListCell<ClientTheme> call(ListView<ClientTheme> clientConnectionListView) {
return new ListCell<>() {
return new ListCell<>() {
@Override
@Override
protected void updateItem(ClientTheme clientTheme, boolean b) {
protected void updateItem(ClientTheme clientTheme, boolean b) {
super.updateItem(clientTheme, b);
super.updateItem(clientTheme, b);
if(clientTheme == null)
if(clientTheme == null)
{
{
setText(null);
setText(null);
}
}
else
else
{
{
setText(clientTheme.getShortName());
setText(clientTheme.getShortName());
}
}
}
}
};
};
}
}
};
};
themesComboBox.setCellFactory(themesComboBoxFactory);
themesComboBox.setCellFactory(themesComboBoxFactory);
themesComboBox.setButtonCell(themesComboBoxFactory.call(null));
themesComboBox.setButtonCell(themesComboBoxFactory.call(null));
startupWindowHeightTextField = new TextField();
startupWindowHeightTextField = new TextField();
startupWindowWidthTextField = new TextField();
startupWindowWidthTextField = new TextField();
platformLabel = new Label();
platformLabel = new Label();
platformLabel.getStyleClass().add("settings_client_platform_label");
platformLabel.getStyleClass().add("settings_client_platform_label");
socketConnectionLabel = new Label();
socketConnectionLabel = new Label();
socketConnectionLabel.getStyleClass().add("settings_client_socket_connection_label");
socketConnectionLabel.getStyleClass().add("settings_client_socket_connection_label");
nicknameTextField = new TextField();
nicknameTextField = new TextField();
nickNameLabel = new Label();
nickNameLabel = new Label();
nickNameLabel.getStyleClass().add("settings_client_nick_name_label");
nickNameLabel.getStyleClass().add("settings_client_nick_name_label");
versionLabel = new Label();
versionLabel = new Label();
versionLabel.getStyleClass().add("settings_client_version_label");
versionLabel.getStyleClass().add("settings_client_version_label");
profilesAccordion = new Accordion();
profilesAccordion = new Accordion();
VBox.setMargin(profilesAccordion, new Insets(0,0,20,0));
VBox.setMargin(profilesAccordion, new Insets(0,0,20,0));
Button addNewProfileButton = new Button("Add new Profile");
Button addNewProfileButton = new Button("Add new Profile");
addNewProfileButton.setOnAction(event -> onNewProfileButtonClicked());
addNewProfileButton.setOnAction(event -> onNewProfileButtonClicked());
setSpacing(10.0);
setSpacing(10.0);
getStyleClass().add("settings_clients_each_client");
getStyleClass().add("settings_clients_each_client");
startupWindowHeightInputBox = new HBoxInputBox("Startup window Height", startupWindowHeightTextField);
startupWindowHeightInputBox = new HBoxInputBox("Startup window Height", startupWindowHeightTextField);
startupWindowHeightInputBox.managedProperty().bind(startupWindowHeightInputBox.visibleProperty());
startupWindowHeightInputBox.managedProperty().bind(startupWindowHeightInputBox.visibleProperty());
startupWindowWidthInputBox = new HBoxInputBox("Startup window Width", startupWindowWidthTextField);
startupWindowWidthInputBox = new HBoxInputBox("Startup window Width", startupWindowWidthTextField);
startupWindowWidthInputBox.managedProperty().bind(startupWindowWidthInputBox.visibleProperty());
startupWindowWidthInputBox.managedProperty().bind(startupWindowWidthInputBox.visibleProperty());
this.getChildren().addAll(
this.getChildren().addAll(
nickNameLabel,
nickNameLabel,
socketConnectionLabel,
socketConnectionLabel,
platformLabel,
platformLabel,
versionLabel,
versionLabel,
new HBoxInputBox("Nickname",nicknameTextField),
new HBoxInputBox("Nickname",nicknameTextField),
new HBox(
new HBox(
new Label("Theme"),
new Label("Theme"),
new SpaceFiller(SpaceFiller.FillerType.HBox),
new SpaceFiller(SpaceFiller.FillerType.HBox),
themesComboBox
themesComboBox
),
),
startupWindowHeightInputBox,
startupWindowHeightInputBox,
startupWindowWidthInputBox,
startupWindowWidthInputBox,
new HBox(new Label("Startup Profile"),
new HBox(new Label("Startup Profile"),
new SpaceFiller(SpaceFiller.FillerType.HBox),
new SpaceFiller(SpaceFiller.FillerType.HBox),
profilesComboBox),
profilesComboBox),
addNewProfileButton,
addNewProfileButton,
profilesAccordion);
profilesAccordion);
}
}
public void loadValues()
public void loadValues()
{
{
Client client = connection.getClient();
Client client = connection.getClient();
profilesComboBox.setItems(FXCollections.observableList(client.getAllClientProfiles()));
profilesComboBox.setItems(FXCollections.observableList(client.getAllClientProfiles()));
profilesComboBox.getSelectionModel().select(
profilesComboBox.getSelectionModel().select(
client.getProfileByID(client.getDefaultProfileID())
client.getProfileByID(client.getDefaultProfileID())
);
);
themesComboBox.setItems(FXCollections.observableList(client.getThemes()));
themesComboBox.setItems(FXCollections.observableList(client.getThemes()));
themesComboBox.getSelectionModel().select(
themesComboBox.getSelectionModel().select(
client.getThemeByFullName(
client.getThemeByFullName(
client.getDefaultThemeFullName()
client.getDefaultThemeFullName()
)
)
);
);
nicknameTextField.setText(client.getNickName());
nicknameTextField.setText(client.getNickName());
if(client.getPlatform() == com.stream_pi.util.platform.Platform.ANDROID)
if(client.getPlatform() == com.stream_pi.util.platform.Platform.ANDROID)
{
{
startupWindowHeightInputBox.setVisible(false);
startupWindowHeightInputBox.setVisible(false);
startupWindowWidthInputBox.setVisible(false);
startupWindowWidthInputBox.setVisible(false);
}
}
platformLabel.setText("Platform : "+client.getPlatform().getUIName());
platformLabel.setText("Platform : "+client.getPlatform().getUIName());
startupWindowWidthTextField.setText(client.getStartupDisplayWidth()+"");
startupWindowWidthTextField.setText(client.getStartupDisplayWidth()+"");
startupWindowHeightTextField.setText(client.getStartupDisplayHeight()+"");
startupWindowHeightTextField.setText(client.getStartupDisplayHeight()+"");
socketConnectionLabel.setText(client.getRemoteSocketAddress().toString().substring(1)); //substring removes the `/`
socketConnectionLabel.setText(client.getRemoteSocketAddress().toString().substring(1)); //substring removes the `/`
nickNameLabel.setText(client.getNickName());
nickNameLabel.setText(client.getNickName());
versionLabel.setText(client.getReleaseStatus().getUIName()+" "+client.getVersion().getText());
versionLabel.setText(client.getReleaseStatus().getUIName()+" "+client.getVersion().getText());
//add profiles
//add profiles
for(ClientProfile clientProfile : client.getAllClientProfiles())
for(ClientProfile clientProfile : client.getAllClientProfiles())
{
{
TitledPane titledPane = new TitledPane();
TitledPane titledPane = new TitledPane();
titledPane.setText(clientProfile.getName());
titledPane.setText(clientProfile.getName());
ClientProfileVBox clientProfileVBox = new ClientProfileVBox(clientProfile);
ClientProfileVBox clientProfileVBox = new ClientProfileVBox(clientProfile);
clientProfileVBox.getRemoveButton().setOnAction(event -> onProfileDeleteButtonClicked(clientProfileVBox, titledPane));
clientProfileVBox.getRemoveButton().setOnAction(event -> onProfileDeleteButtonClicked(clientProfileVBox, titledPane));
titledPane.setContent(clientProfileVBox);
titledPane.setContent(clientProfileVBox);
clientProfileVBoxes.add(clientProfileVBox);
clientProfileVBoxes.add(clientProfileVBox);
profilesAccordion.getPanes().add(titledPane);
profilesAccordion.getPanes().add(titledPane);
}
}
}
}
public void onNewProfileButtonClicked()
public void onNewProfileButtonClicked()
{
{
ClientProfile clientProfile = new ClientProfile(
ClientProfile clientProfile = new ClientProfile(
"Untitled Profile",
"Untitled Profile",
3,
3,
3,
3,
100,
100,
5
5
);
);
ClientProfileVBox clientProfileVBox = new ClientProfileVBox(clientProfile);
ClientProfileVBox clientProfileVBox = new ClientProfileVBox(clientProfile);
TitledPane titledPane = new TitledPane();
TitledPane titledPane = new TitledPane();
titledPane.setContent(clientProfileVBox);
titledPane.setContent(clientProfileVBox);
titledPane.setText(clientProfile.getName());
titledPane.setText(clientProfile.getName());
clientProfileVBox.getRemoveButton().setOnAction(event -> onProfileDeleteButtonClicked(clientProfileVBox, titledPane));
clientProfileVBox.getRemoveButton().setOnAction(event -> onProfileDeleteButtonClicked(clientProfileVBox, titledPane));
clientProfileVBoxes.add(clientProfileVBox);
clientProfileVBoxes.add(clientProfileVBox);
profilesAccordion.getPanes().add(titledPane);
profilesAccordion.getPanes().add(titledPane);
}
}
public void onProfileDeleteButtonClicked(ClientProfileVBox clientProfileVBox, TitledPane titledPane)
public void onProfileDeleteButtonClicked(ClientProfileVBox clientProfileVBox, TitledPane titledPane)
{
{
if(clientProfileVBoxes.size() == 1)
if(clientProfileVBoxes.size() == 1)
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Only one",
exceptionAndAlertHandler.handleMinorException(new MinorException("Only one",
"You cannot delete all profiles"));
"You cannot delete all profiles"));
}
}
else
else
{
{
if(profilesComboBox.getSelectionModel().getSelectedItem().getID().equals(clientProfileVBox.getClientProfile().getID()))
if(profilesComboBox.getSelectionModel().getSelectedItem().getID().equals(clientProfileVBox.getClientProfile().getID()))
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Default",
exceptionAndAlertHandler.handleMinorException(new MinorException("Default",
"You cannot delete default profile. Change to another one to delete this."));
"You cannot delete default profile. Change to another one to delete this."));
}
}
else
else
{
{
clientProfileVBoxes.remove(clientProfileVBox);
clientProfileVBoxes.remove(clientProfileVBox);
profilesComboBox.getItems().remove(clientProfileVBox.getClientProfile());
profilesComboBox.getItems().remove(clientProfileVBox.getClientProfile());
profilesAccordion.getPanes().remove(titledPane);
profilesAccordion.getPanes().remove(titledPane);
}
}
}
}
}
}
}
}
public class ClientProfileVBox extends VBox
public class ClientProfileVBox extends VBox
{
{
private TextField nameTextField;
private TextField nameTextField;
public String getName()
public String getName()
{
{
return nameTextField.getText();
return nameTextField.getText();
}
}
private TextField rowsTextField;
private TextField rowsTextField;
public String getRows()
public String getRows()
{
{
return rowsTextField.getText();
return rowsTextField.getText();
}
}
private TextField colsTextField;
private TextField colsTextField;
public String getCols()
public String getCols()
{
{
return colsTextField.getText();
return colsTextField.getText();
}
}
private TextField actionSizeTextField;
private TextField actionSizeTextField;
public String getActionSize()
public String getActionSize()
{
{
return actionSizeTextField.getText();
return actionSizeTextField.getText();
}
}
private TextField actionGapTextField;
private TextField actionGapTextField;
public String getActionGap()
public String getActionGap()
{
{
return actionGapTextField.getText();
return actionGapTextField.getText();
}
}
private Button removeButton;
private Button removeButton;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public String getRealName()
public String getRealName()
{
{
return clientProfile.getName();
return clientProfile.getName();
}
}
public ClientProfileVBox(ClientProfile clientProfile)
public ClientProfileVBox(ClientProfile clientProfile)
{
{
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
initUI();
initUI();
loadValues(clientProfile);
loadValues(clientProfile);
}
}
public void initUI()
public void initUI()
{
{
setPadding(new Insets(5.0));
setPadding(new Insets(5.0));
setSpacing(10.0);
setSpacing(10.0);
nameTextField = new TextField();
nameTextField = new TextField();
rowsTextField = new TextField();
rowsTextField = new TextField();
colsTextField = new TextField();
colsTextField = new TextField();
actionSizeTextField = new TextField();
actionSizeTextField = new TextField();
actionGapTextField = new TextField();
actionGapTextField = new TextField();
removeButton = new Button("Remove");
removeButton = new Button("Remove");
HBox hBox = new HBox(removeButton);
HBox hBox = new HBox(removeButton);
hBox.setAlignment(Pos.CENTER_RIGHT);
hBox.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(
getChildren().addAll(
new HBoxInputBox("Name ", nameTextField),
new HBoxInputBox("Name ", nameTextField),
new HBoxInputBox("Columns", rowsTextField),
new HBoxInputBox("Columns", rowsTextField),
new HBoxInputBox("Rows", colsTextField),
new HBoxInputBox("Rows", colsTextField),
new HBoxInputBox("action Size", actionSizeTextField),
new HBoxInputBox("action Size", actionSizeTextField),
new HBoxInputBox("action Gap", actionGapTextField),
new HBoxInputBox("action Gap", actionGapTextField),
hBox
hBox
);
);
}
}
public Button getRemoveButton()
public Button getRemoveButton()
{
{
return removeButton;
return removeButton;
}
}
public void loadValues(ClientProfile clientProfile)
public void loadValues(ClientProfile clientProfile)
{
{
nameTextField.setText(clientProfile.getName());
nameTextField.setText(clientProfile.getName());
rowsTextField.setText(clientProfile.getRows()+"");
rowsTextField.setText(clientProfile.getRows()+"");
colsTextField.setText(clientProfile.getCols()+"");
colsTextField.setText(clientProfile.getCols()+"");
actionSizeTextField.setText(clientProfile.getActionSize()+"");
actionSizeTextField.setText(clientProfile.getActionSize()+"");
actionGapTextField.setText(clientProfile.getActionGap()+"");
actionGapTextField.setText(clientProfile.getActionGap()+"");
}
}
public ClientProfile getClientProfile()
public ClientProfile getClientProfile()
{
{
clientProfile.setActionGap(Integer.parseInt(actionGapTextField.getText()));
clientProfile.setActionGap(Integer.parseInt(actionGapTextField.getText()));
clientProfile.setActionSize(Integer.parseInt(actionSizeTextField.getText()));
clientProfile.setActionSize(Integer.parseInt(actionSizeTextField.getText()));
clientProfile.setRows(Integer.parseInt(rowsTextField.getText()));
clientProfile.setRows(Integer.parseInt(rowsTextField.getText()));
clientProfile.setCols(Integer.parseInt(colsTextField.getText()));
clientProfile.setCols(Integer.parseInt(colsTextField.getText()));
clientProfile.setName(nameTextField.getText());
clientProfile.setName(nameTextField.getText());
return clientProfile;
return clientProfile;
}
}
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.startatboot.SoftwareType;
import com.stream_pi.util.startatboot.SoftwareType;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.version.Version;
import com.stream_pi.util.version.Version;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.DirectoryChooser;
import org.json.JSONObject;
import org.json.JSONObject;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.awt.SystemTray;
import java.awt.SystemTray;
import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.File;
import java.io.File;
import java.io.InputStreamReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URL;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class GeneralSettings extends ScrollPane {
public class GeneralSettings extends VBox {
private final TextField serverNameTextField;
private final TextField serverNameTextField;
private final TextField portTextField;
private final TextField portTextField;
private final TextField pluginsPathTextField;
private final TextField pluginsPathTextField;
private final TextField themesPathTextField;
private final TextField themesPathTextField;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxGap;
private final TextField actionGridPaneActionBoxGap;
private final ToggleButton startOnBootToggleButton;
private final ToggleButton startOnBootToggleButton;
private final ToggleButton closeOnXToggleButton;
private final ToggleButton closeOnXToggleButton;
private final Button saveButton;
private final Button saveButton;
private final Button checkForUpdatesButton;
private final Button checkForUpdatesButton;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ServerListener serverListener;
private ServerListener serverListener;
private HostServices hostServices;
private HostServices hostServices;
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
getStyleClass().add("general_settings_scroll_pane");
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.serverListener = serverListener;
this.serverListener = serverListener;
logger = Logger.getLogger(GeneralSettings.class.getName());
logger = Logger.getLogger(GeneralSettings.class.getName());
setHbarPolicy(ScrollBarPolicy.NEVER);
serverNameTextField = new TextField();
serverNameTextField = new TextField();
portTextField = new TextField();
portTextField = new TextField();
pluginsPathTextField = new TextField();
pluginsPathTextField = new TextField();
themesPathTextField = new TextField();
themesPathTextField = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxGap = new TextField();
actionGridPaneActionBoxGap = new TextField();
startOnBootToggleButton = new ToggleButton("Start on Boot");
startOnBootToggleButton = new ToggleButton("Start on Boot");
closeOnXToggleButton = new ToggleButton("Quit On window Close");
closeOnXToggleButton = new ToggleButton("Quit On window Close");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
checkForUpdatesButton.setOnAction(event->checkForUpdates());
getStyleClass().add("general_settings");
VBox vBox = new VBox();
prefWidthProperty().bind(widthProperty());
vBox.prefWidthProperty().bind(widthProperty());
setAlignment(Pos.CENTER);
vBox.setAlignment(Pos.CENTER);
setSpacing(5);
vBox.setSpacing(5);
vBox.getChildren().addAll(
getChildren().addAll(
getUIInputBox("Server Name", serverNameTextField),
getUIInputBox("Server Name", serverNameTextField),
getUIInputBox("Port", portTextField),
getUIInputBox("Port", portTextField),
getUIInputBox("action Grid Pane action Box Size", actionGridPaneActionBoxSize),
getUIInputBox("action Grid Pane action Box Size", actionGridPaneActionBoxSize),
getUIInputBox("action Grid Pane action Box Gap", actionGridPaneActionBoxGap),
getUIInputBox("action Grid Pane action Box Gap", actionGridPaneActionBoxGap),
getUIInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
getUIInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
getUIInputBoxWithDirectoryChooser("Themes Path", themesPathTextField)
getUIInputBoxWithDirectoryChooser("Themes Path", themesPathTextField)
);
);
serverNameTextField.setPrefWidth(200);
serverNameTextField.setPrefWidth(200);
HBox toggleButtons = new HBox(closeOnXToggleButton, startOnBootToggleButton);
HBox toggleButtons = new HBox(closeOnXToggleButton, startOnBootToggleButton);
toggleButtons.setSpacing(10.0);
toggleButtons.setSpacing(10.0);
VBox.setMargin(toggleButtons, new Insets(30, 0 , 0,0));
VBox.setMargin(toggleButtons, new Insets(30, 0 , 0,0));
toggleButtons.setAlignment(Pos.CENTER);
toggleButtons.setAlignment(Pos.CENTER);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event->save());
saveButton.setOnAction(event->save());
vBox.getChildren().addAll(toggleButtons, checkForUpdatesButton, saveButton);
getChildren().addAll(toggleButtons, checkForUpdatesButton, saveButton);
vBox.setPadding(new Insets(10));
setPadding(new Insets(10));
vBox.getStyleClass().add("general_settings");
setContent(vBox);
}
}
private HBox getUIInputBoxWithDirectoryChooser(String labelText, TextField textField)
private HBox getUIInputBoxWithDirectoryChooser(String labelText, TextField textField)
{
{
HBox hBox = getUIInputBox(labelText, textField);
HBox hBox = getUIInputBox(labelText, textField);
hBox.setSpacing(5.0);
hBox.setSpacing(5.0);
TextField tf = (TextField) hBox.getChildren().get(2);
TextField tf = (TextField) hBox.getChildren().get(2);
tf.setPrefWidth(300);
tf.setPrefWidth(300);
tf.setDisable(true);
tf.setDisable(true);
Button button = new Button();
Button button = new Button();
FontIcon fontIcon = new FontIcon("far-folder");
FontIcon fontIcon = new FontIcon("far-folder");
button.setGraphic(fontIcon);
button.setGraphic(fontIcon);
button.setOnAction(event -> {
button.setOnAction(event -> {
DirectoryChooser directoryChooser = new DirectoryChooser();
DirectoryChooser directoryChooser = new DirectoryChooser();
try {
try {
File selectedDirectory = directoryChooser.showDialog(getScene().getWindow());
File selectedDirectory = directoryChooser.showDialog(getScene().getWindow());
textField.setText(selectedDirectory.getAbsolutePath());
textField.setText(selectedDirectory.getAbsolutePath());
}
}
catch (NullPointerException e)
catch (NullPointerException e)
{
{
logger.info("No folder selected");
logger.info("No folder selected");
}
}
});
});
hBox.getChildren().add(button);
hBox.getChildren().add(button);
return hBox;
return hBox;
}
}
private HBox getUIInputBox(String labelText, TextField textField)
private HBox getUIInputBox(String labelText, TextField textField)
{
{
textField.setPrefWidth(100);
textField.setPrefWidth(100);
Label label = new Label(labelText);
Label label = new Label(labelText);
Region region = new Region();
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HBox.setHgrow(region, Priority.ALWAYS);
return new HBox(label, region, textField);
return new HBox(label, region, textField);
}
}
public void loadDataFromConfig() throws SevereException {
public void loadDataFromConfig() throws SevereException {
Config config = Config.getInstance();
Config config = Config.getInstance();
Platform.runLater(()->
Platform.runLater(()->
{
{
serverNameTextField.setText(config.getServerName());
serverNameTextField.setText(config.getServerName());
portTextField.setText(config.getPort()+"");
portTextField.setText(config.getPort()+"");
pluginsPathTextField.setText(config.getPluginsPath());
pluginsPathTextField.setText(config.getPluginsPath());
themesPathTextField.setText(config.getThemesPath());
themesPathTextField.setText(config.getThemesPath());
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
closeOnXToggleButton.setSelected(config.getCloseOnX());
closeOnXToggleButton.setSelected(config.getCloseOnX());
startOnBootToggleButton.setSelected(config.getStartOnBoot());
startOnBootToggleButton.setSelected(config.getStartOnBoot());
});
});
}
}
public void save()
public void save()
{
{
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try {
try {
boolean toBeReloaded = false;
boolean toBeReloaded = false;
boolean dashToBeReRendered = false;
boolean dashToBeReRendered = false;
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(true);
saveButton.setDisable(true);
serverNameTextField.setDisable(true);
serverNameTextField.setDisable(true);
portTextField.setDisable(true);
portTextField.setDisable(true);
closeOnXToggleButton.setDisable(true);
closeOnXToggleButton.setDisable(true);
startOnBootToggleButton.setDisable(true);
startOnBootToggleButton.setDisable(true);
});
});
String serverNameStr = serverNameTextField.getText();
String serverNameStr = serverNameTextField.getText();
String serverPortStr = portTextField.getText();
String serverPortStr = portTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
boolean closeOnX = closeOnXToggleButton.isSelected();
boolean closeOnX = closeOnXToggleButton.isSelected();
boolean startOnBoot = startOnBootToggleButton.isSelected();
boolean startOnBoot = startOnBootToggleButton.isSelected();
Config config = Config.getInstance();
Config config = Config.getInstance();
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(serverNameStr.isBlank())
if(serverNameStr.isBlank())
{
{
errors.append("* Server Name cannot be blank.\n");
errors.append("* Server Name cannot be blank.\n");
}
}
else
else
{
{
if(!config.getServerName().equals(serverNameStr))
if(!config.getServerName().equals(serverNameStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
int serverPort=-1;
int serverPort=-1;
try {
try {
serverPort = Integer.parseInt(serverPortStr);
serverPort = Integer.parseInt(serverPortStr);
if (serverPort < 1024)
if (serverPort < 1024)
errors.append("* Server Port must be more than 1024");
errors.append("* Server Port must be more than 1024");
if(config.getPort()!=serverPort)
if(config.getPort()!=serverPort)
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* Server Port must be integer.\n");
errors.append("* Server Port must be integer.\n");
}
}
int actionSize=-1;
int actionSize=-1;
try {
try {
actionSize = Integer.parseInt(actionGridActionBoxSize);
actionSize = Integer.parseInt(actionGridActionBoxSize);
if(config.getActionGridActionSize() != actionSize)
if(config.getActionGridActionSize() != actionSize)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Size must be integer.\n");
errors.append("* action Size must be integer.\n");
}
}
int actionGap=-1;
int actionGap=-1;
try {
try {
actionGap = Integer.parseInt(actionGridActionBoxGap);
actionGap = Integer.parseInt(actionGridActionBoxGap);
if(config.getActionGridActionGap() != actionGap)
if(config.getActionGridActionGap() != actionGap)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Gap must be integer.\n");
errors.append("* action Gap must be integer.\n");
}
}
if(pluginsPathStr.isBlank())
if(pluginsPathStr.isBlank())
{
{
errors.append("* Plugins Path must not be blank.\n");
errors.append("* Plugins Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getPluginsPath().equals(pluginsPathStr))
if(!config.getPluginsPath().equals(pluginsPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(themesPathStr.isBlank())
if(themesPathStr.isBlank())
{
{
errors.append("* Themes Path must not be blank.\n");
errors.append("* Themes Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getThemesPath().equals(themesPathStr))
if(!config.getThemesPath().equals(themesPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
throw new MinorException("settings", "Please rectify the following errors and try again :\n"+errors.toString());
throw new MinorException("settings", "Please rectify the following errors and try again :\n"+errors.toString());
}
}
if(config.getStartOnBoot() != startOnBoot)
if(config.getStartOnBoot() != startOnBoot)
{
{
if(ServerInfo.getInstance().getRunnerFileName() == null)
if(ServerInfo.getInstance().getRunnerFileName() == null)
{
{
new StreamPiAlert("Uh Oh", "No Runner File Name Specified as startup arguments. Cant set run at boot.", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh", "No Runner File Name Specified as startup arguments. Cant set run at boot.", StreamPiAlertType.ERROR).show();
startOnBoot = false;
startOnBoot = false;
}
}
else
else
{
{
StartAtBoot startAtBoot = new StartAtBoot(SoftwareType.SERVER, ServerInfo.getInstance().getPlatformType());
StartAtBoot startAtBoot = new StartAtBoot(SoftwareType.SERVER, ServerInfo.getInstance().getPlatformType());
if(startOnBoot)
if(startOnBoot)
{
{
startAtBoot.create(new File(ServerInfo.getInstance().getRunnerFileName()));
startAtBoot.create(new File(ServerInfo.getInstance().getRunnerFileName()));
}
}
else
else
{
{
boolean result = startAtBoot.delete();
boolean result = startAtBoot.delete();
if(!result)
if(!result)
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
}
}
}
if(!closeOnX)
if(!closeOnX)
{
{
System.out.println("XYZ");
System.out.println("XYZ");
if(!SystemTray.isSupported())
if(!SystemTray.isSupported())
{
{
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
alert.show();
alert.show();
closeOnX = true;
closeOnX = true;
}
}
else
else
{
{
System.out.println("YES");
System.out.println("YES");
}
}
}
}
config.setServerName(serverNameStr);
config.setServerName(serverNameStr);
config.setServerPort(serverPort);
config.setServerPort(serverPort);
config.setActionGridGap(actionGap);
config.setActionGridGap(actionGap);
config.setActionGridSize(actionSize);
config.setActionGridSize(actionSize);
config.setPluginsPath(pluginsPathStr);
config.setPluginsPath(pluginsPathStr);
config.setThemesPath(themesPathStr);
config.setThemesPath(themesPathStr);
config.setCloseOnX(closeOnX);
config.setCloseOnX(closeOnX);
config.setStartupOnBoot(startOnBoot);
config.setStartupOnBoot(startOnBoot);
config.save();
config.save();
loadDataFromConfig();
loadDataFromConfig();
if(toBeReloaded)
if(toBeReloaded)
{
{
new StreamPiAlert("Restart","Restart to see changes", StreamPiAlertType.INFORMATION).show();
new StreamPiAlert("Restart","Restart to see changes", StreamPiAlertType.INFORMATION).show();
}
}
if(dashToBeReRendered)
if(dashToBeReRendered)
{
{
serverListener.clearTemp();
serverListener.clearTemp();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
finally {
finally {
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(false);
saveButton.setDisable(false);
serverNameTextField.setDisable(false);
serverNameTextField.setDisable(false);
portTextField.setDisable(false);
portTextField.setDisable(false);
closeOnXToggleButton.setDisable(false);
closeOnXToggleButton.setDisable(false);
startOnBootToggleButton.setDisable(false);
startOnBootToggleButton.setDisable(false);
});
});
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
public void checkForUpdates()
public void checkForUpdates()
{
{
new Thread(new Task<Void>()
new Thread(new Task<Void>()
{
{
@Override
@Override
protected Void call() throws Exception {
protected Void call() throws Exception {
try
try
{
{
Platform.runLater(()->checkForUpdatesButton.setDisable(true));
Platform.runLater(()->checkForUpdatesButton.setDisable(true));
String jsonRaw = readUrl("https://stream-pi.com/API/get_latest.php?TYPE=SERVER");
String jsonRaw = readUrl("https://stream-pi.com/API/get_latest.php?TYPE=SERVER");
System.out.println(jsonRaw);
System.out.println(jsonRaw);
JSONObject jsonObject = new JSONObject(jsonRaw);
JSONObject jsonObject = new JSONObject(jsonRaw);
String latestVersionRaw = jsonObject.getString("Version");
String latestVersionRaw = jsonObject.getString("Version");
String releasePage = jsonObject.getString("Release Page");
String releasePage = jsonObject.getString("Release Page");
Version latestVersion = new Version(latestVersionRaw);
Version latestVersion = new Version(latestVersionRaw);
Version currentVersion = ServerInfo.getInstance().getVersion();
Version currentVersion = ServerInfo.getInstance().getVersion();
if(latestVersion.isBiggerThan(currentVersion))
if(latestVersion.isBiggerThan(currentVersion))
{
{
VBox vBox = new VBox();
VBox vBox = new VBox();
Hyperlink urlLabel = new Hyperlink(releasePage);
Hyperlink urlLabel = new Hyperlink(releasePage);
urlLabel.setOnAction(event->hostServices.showDocument(releasePage));
urlLabel.setOnAction(event->hostServices.showDocument(releasePage));
Label label = new Label(
Label label = new Label(
"New Version "+latestVersionRaw+" Available.\n" +
"New Version "+latestVersionRaw+" Available.\n" +
"Current Version "+currentVersion.getText()+".\n"+
"Current Version "+currentVersion.getText()+".\n"+
"Changelog and install instructions are included in the release page.\n" +
"Changelog and install instructions are included in the release page.\n" +
"It is recommended to update to ensure maximum stability and least bugs.");
"It is recommended to update to ensure maximum stability and least bugs.");
label.setWrapText(true);
label.setWrapText(true);
vBox.setSpacing(5);
vBox.setSpacing(5);
vBox.getChildren().addAll(
vBox.getChildren().addAll(
urlLabel,
urlLabel,
label
label
);
);
new StreamPiAlert("New Update Available!", StreamPiAlertType.INFORMATION, vBox).show();;
new StreamPiAlert("New Update Available!", StreamPiAlertType.INFORMATION, vBox).show();;
}
}
else
else
{
{
new StreamPiAlert("Up to Date", "Server is upto date. ("+currentVersion.getText()+")", StreamPiAlertType.INFORMATION).show();;
new StreamPiAlert("Up to Date", "Server is upto date. ("+currentVersion.getText()+")", StreamPiAlertType.INFORMATION).show();;
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
new StreamPiAlert("Uh Oh", "Update Check Failed. API Error/Network issue.", StreamPiAlertType.WARNING).show();;
new StreamPiAlert("Uh Oh", "Update Check Failed. API Error/Network issue.", StreamPiAlertType.WARNING).show();;
}
}
finally
finally
{
{
Platform.runLater(()->checkForUpdatesButton.setDisable(false));
Platform.runLater(()->checkForUpdatesButton.setDisable(false));
}
}
return null;
return null;
}
}
}).start();;
}).start();;
}
}
private String readUrl(String urlString) throws Exception {
private String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
BufferedReader reader = null;
try {
try {
URL url = new URL(urlString);
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuffer buffer = new StringBuffer();
StringBuffer buffer = new StringBuffer();
int read;
int read;
char[] chars = new char[1024];
char[] chars = new char[1024];
while ((read = reader.read(chars)) != -1)
while ((read = reader.read(chars)) != -1)
buffer.append(chars, 0, read);
buffer.append(chars, 0, read);
return buffer.toString();
return buffer.toString();
} finally {
} finally {
if (reader != null)
if (reader != null)
reader.close();
reader.close();
}
}
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.actionapi.actionproperty.property.ControlType;
import com.stream_pi.actionapi.actionproperty.property.ControlType;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Property;
import com.stream_pi.actionapi.actionproperty.property.Type;
import com.stream_pi.actionapi.actionproperty.property.Type;
import com.stream_pi.actionapi.normalaction.NormalAction;
import com.stream_pi.actionapi.normalaction.NormalAction;
import com.stream_pi.server.action.NormalActionPlugins;
import com.stream_pi.server.action.NormalActionPlugins;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.connection.ServerListener;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller.FillerType;
import com.stream_pi.util.uihelper.SpaceFiller.FillerType;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class PluginsSettings extends VBox {
public class PluginsSettings extends VBox {
private VBox pluginsSettingsVBox;
private VBox pluginsSettingsVBox;
private ServerListener serverListener;
private ServerListener serverListener;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private HostServices hostServices;
private HostServices hostServices;
public PluginsSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
public PluginsSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, HostServices hostServices)
{
{
getStyleClass().add("plugins_settings");
getStyleClass().add("plugins_settings");
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
pluginProperties = new ArrayList<>();
pluginProperties = new ArrayList<>();
logger = Logger.getLogger(PluginsSettings.class.getName());
logger = Logger.getLogger(PluginsSettings.class.getName());
setPadding(new Insets(10));
pluginsSettingsVBox = new VBox();
pluginsSettingsVBox = new VBox();
pluginsSettingsVBox.setSpacing(10.0);
pluginsSettingsVBox.getStyleClass().add("plugins_settings_vbox");
pluginsSettingsVBox.setAlignment(Pos.TOP_CENTER);
pluginsSettingsVBox.setAlignment(Pos.TOP_CENTER);
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("plugins_settings_scroll_pane");
scrollPane.getStyleClass().add("plugins_settings_scroll_pane");
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
pluginsSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
pluginsSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(25));
scrollPane.setContent(pluginsSettingsVBox);
scrollPane.setContent(pluginsSettingsVBox);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event -> onSaveButtonClicked());
saveButton.setOnAction(event -> onSaveButtonClicked());
HBox hBox = new HBox(saveButton);
HBox hBox = new HBox(saveButton);
hBox.setAlignment(Pos.CENTER_RIGHT);
hBox.setAlignment(Pos.CENTER_RIGHT);
getChildren().addAll(scrollPane, hBox);
getChildren().addAll(scrollPane, hBox);
}
}
private Button saveButton;
private Button saveButton;
public void onSaveButtonClicked()
public void onSaveButtonClicked()
{
{
try {
try {
//form validation
//form validation
StringBuilder finalErrors = new StringBuilder();
StringBuilder finalErrors = new StringBuilder();
for (PluginProperties p : pluginProperties)
for (PluginProperties p : pluginProperties)
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(int j = 0; j < p.getServerPropertyUIBox().size(); j++)
for(int j = 0; j < p.getServerPropertyUIBox().size(); j++)
{
{
UIPropertyBox serverProperty = p.getServerPropertyUIBox().get(j);
UIPropertyBox serverProperty = p.getServerPropertyUIBox().get(j);
Node controlNode = serverProperty.getControlNode();
Node controlNode = serverProperty.getControlNode();
if (serverProperty.getControlType() == ControlType.TEXT_FIELD)
if (serverProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
String value = ((TextField) controlNode).getText();
String value = ((TextField) controlNode).getText();
if(serverProperty.getType() == Type.INTEGER)
if(serverProperty.getType() == Type.INTEGER)
{
{
try
try
{
{
Integer.parseInt(value);
Integer.parseInt(value);
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" must be integer.\n");
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" must be integer.\n");
}
}
}
}
else
else
{
{
if(value.isBlank() && !serverProperty.isCanBeBlank())
if(value.isBlank() && !serverProperty.isCanBeBlank())
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" cannot be blank.\n");
errors.append(" -> ").append(serverProperty.getDisplayName()).append(" cannot be blank.\n");
}
}
}
}
}
}
if(!errors.toString().isBlank())
if(!errors.toString().isBlank())
{
{
finalErrors.append(" * ").append(p.getName()).append("\n").append(errors.toString()).append("\n");
finalErrors.append(" * ").append(p.getName()).append("\n").append(errors.toString()).append("\n");
}
}
}
}
if(!finalErrors.toString().isEmpty())
if(!finalErrors.toString().isEmpty())
{
{
throw new MinorException("Form Validation Errors",
throw new MinorException("Form Validation Errors",
"Please rectify the following errors and try again \n"+finalErrors.toString());
"Please rectify the following errors and try again \n"+finalErrors.toString());
}
}
//save
//save
for (PluginProperties pp : pluginProperties) {
for (PluginProperties pp : pluginProperties) {
for (int j = 0; j < pp.getServerPropertyUIBox().size(); j++) {
for (int j = 0; j < pp.getServerPropertyUIBox().size(); j++) {
UIPropertyBox serverProperty = pp.getServerPropertyUIBox().get(j);
UIPropertyBox serverProperty = pp.getServerPropertyUIBox().get(j);
String rawValue = serverProperty.getRawValue();
String rawValue = serverProperty.getRawValue();
NormalActionPlugins.getInstance().getActionFromIndex(pp.getIndex())
NormalActionPlugins.getInstance().getActionFromIndex(pp.getIndex())
.getServerProperties().get()
.getServerProperties().get()
.get(serverProperty.getIndex()).setRawValue(rawValue);
.get(serverProperty.getIndex()).setRawValue(rawValue);
}
}
}
}
NormalActionPlugins.getInstance().saveServerSettings();
NormalActionPlugins.getInstance().saveServerSettings();
NormalActionPlugins.getInstance().initPlugins();
NormalActionPlugins.getInstance().initPlugins();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
private ArrayList<PluginProperties> pluginProperties;
private ArrayList<PluginProperties> pluginProperties;
public void showPluginInitError()
public void showPluginInitError()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
pluginsSettingsVBox.getChildren().add(new Label("Plugin init error. Resolve issues and restart."));
pluginsSettingsVBox.getChildren().add(new Label("Plugin init error. Resolve issues and restart."));
saveButton.setVisible(false);
saveButton.setVisible(false);
});
});
}
}
public void loadPlugins() throws MinorException {
public void loadPlugins() throws MinorException {
pluginProperties.clear();
pluginProperties.clear();
List<NormalAction> actions = NormalActionPlugins.getInstance().getPlugins();
List<NormalAction> actions = NormalActionPlugins.getInstance().getPlugins();
System.out.println("asdasdasdasd"+actions.size());
Platform.runLater(()-> pluginsSettingsVBox.getChildren().clear());
Platform.runLater(()-> pluginsSettingsVBox.getChildren().clear());
if(actions.size() == 0)
if(actions.size() == 0)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
pluginsSettingsVBox.getChildren().add(new Label("No Plugins Installed."));
Label l = new Label("No Plugins Installed.");
l.getStyleClass().add("plugins_pane_no_plugins_installed_label");
pluginsSettingsVBox.getChildren().add(l);
saveButton.setVisible(false);
saveButton.setVisible(false);
});
});
return;
return;
}
}
else
else
{
{
Platform.runLater(()->saveButton.setVisible(true));
Platform.runLater(()->saveButton.setVisible(true));
}
}
for(int i = 0; i<actions.size(); i++)
for(int i = 0; i<actions.size(); i++)
{
{
NormalAction action = actions.get(i);
NormalAction action = actions.get(i);
if(!action.isVisibleInServerSettingsPane())
if(!action.isVisibleInServerSettingsPane())
continue;
continue;
Label headingLabel = new Label(action.getName());
Label headingLabel = new Label(action.getName());
headingLabel.getStyleClass().add("settings_plugins_each_action_heading");
headingLabel.getStyleClass().add("plugins_settings_each_plugin_heading_label");
HBox headerHBox = new HBox(headingLabel);
HBox headerHBox = new HBox(headingLabel);
headerHBox.getStyleClass().add("plugins_settings_each_plugin_header");
if (action.getHelpLink()!=null)
if (action.getHelpLink()!=null)
{
{
Button helpButton = new Button();
Button helpButton = new Button();
helpButton.getStyleClass().add("plugins_settings_each_plugin_help_button");
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
questionIcon.getStyleClass().add("settings_plugins_plugin_help_icon");
questionIcon.getStyleClass().add("plugins_settings_each_plugin_help_icon");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> hostServices.showDocument(action.getHelpLink()));
helpButton.setOnAction(event -> hostServices.showDocument(action.getHelpLink()));
headerHBox.getChildren().addAll(new SpaceFiller(FillerType.HBox),helpButton);
headerHBox.getChildren().addAll(new SpaceFiller(FillerType.HBox),helpButton);
}
}
Label authorLabel = new Label(action.getAuthor());
Label authorLabel = new Label(action.getAuthor());
authorLabel.getStyleClass().add("plugins_settings_each_plugin_author_label");
Label moduleLabel = new Label(action.getModuleName());
Label moduleLabel = new Label(action.getModuleName());
moduleLabel.getStyleClass().add("plugins_settings_each_plugin_module_label");
Label versionLabel = new Label("Version : "+action.getVersion().getText());
Label versionLabel = new Label("Version : "+action.getVersion().getText());
versionLabel.getStyleClass().add("plugins_settings_each_plugin_version_label");
VBox serverPropertiesVBox = new VBox();
VBox serverPropertiesVBox = new VBox();
serverPropertiesVBox.getStyleClass().add("plugins_settings_each_plugin_server_properties_box");
serverPropertiesVBox.setSpacing(10.0);
serverPropertiesVBox.setSpacing(10.0);
List<Property> serverProperties = action.getServerProperties().get();
List<Property> serverProperties = action.getServerProperties().get();
ArrayList<UIPropertyBox> serverPropertyArrayList = new ArrayList<>();
ArrayList<UIPropertyBox> serverPropertyArrayList = new ArrayList<>();
for(int j =0; j<serverProperties.size(); j++)
for(int j =0; j<serverProperties.size(); j++)
{
{
Property eachProperty = serverProperties.get(j);
Property eachProperty = serverProperties.get(j);
if(!eachProperty.isVisible())
if(!eachProperty.isVisible())
continue;
continue;
Label label = new Label(eachProperty.getDisplayName());
Label label = new Label(eachProperty.getDisplayName());
Region region = new Region();
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HBox.setHgrow(region, Priority.ALWAYS);
HBox hBox = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox));
HBox hBox = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox));
//hBox.setId(j+"");
//hBox.setId(j+"");
Node controlNode = null;
Node controlNode = null;
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
if(eachProperty.getControlType() == ControlType.COMBO_BOX)
{
{
ComboBox<String> comboBox = new ComboBox<>();
ComboBox<String> comboBox = new ComboBox<>();
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getItems().addAll(eachProperty.getListValue());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
comboBox.getSelectionModel().select(eachProperty.getSelectedIndex());
hBox.getChildren().add(comboBox);
hBox.getChildren().add(comboBox);
controlNode = comboBox;
controlNode = comboBox;
}
}
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
else if(eachProperty.getControlType() == ControlType.TEXT_FIELD)
{
{
TextField textField = new TextField(eachProperty.getRawValue());
TextField textField = new TextField(eachProperty.getRawValue());
hBox.getChildren().add(textField);
hBox.getChildren().add(textField);
controlNode = textField;
controlNode = textField;
}
}
else if(eachProperty.getControlType() == ControlType.TOGGLE)
else if(eachProperty.getControlType() == ControlType.TOGGLE)
{
{
ToggleButton toggleButton = new ToggleButton();
ToggleButton toggleButton = new ToggleButton();
toggleButton.setSelected(eachProperty.getBoolValue());
toggleButton.setSelected(eachProperty.getBoolValue());
if(eachProperty.getBoolValue())
if(eachProperty.getBoolValue())
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
toggleButton.selectedProperty().addListener((observableValue, aBoolean, t1) -> {
if(t1)
if(t1)
toggleButton.setText("ON");
toggleButton.setText("ON");
else
else
toggleButton.setText("OFF");
toggleButton.setText("OFF");
});
});
hBox.getChildren().add(toggleButton);
hBox.getChildren().add(toggleButton);
controlNode = toggleButton;
controlNode = toggleButton;
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
else if(eachProperty.getControlType() == ControlType.SLIDER_DOUBLE)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getDoubleValue());
slider.setValue(eachProperty.getDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMax(eachProperty.getMaxDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
slider.setMin(eachProperty.getMinDoubleValue());
hBox.getChildren().add(slider);
hBox.getChildren().add(slider);
controlNode = slider;
controlNode = slider;
}
}
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
else if(eachProperty.getControlType() == ControlType.SLIDER_INTEGER)
{
{
Slider slider = new Slider();
Slider slider = new Slider();
slider.setValue(eachProperty.getIntValue());
slider.setValue(eachProperty.getIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMax(eachProperty.getMaxIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setMin(eachProperty.getMinIntValue());
slider.setBlockIncrement(1.0);
slider.setBlockIncrement(1.0);
slider.setSnapToTicks(true);
slider.setSnapToTicks(true);
hBox.getChildren().add(slider);
hBox.getChildren().add(slider);
controlNode = slider;
controlNode = slider;
}
}
UIPropertyBox serverProperty = new UIPropertyBox(j, eachProperty.getDisplayName(), controlNode, eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
UIPropertyBox serverProperty = new UIPropertyBox(j, eachProperty.getDisplayName(), controlNode, eachProperty.getControlType(), eachProperty.getType(), eachProperty.isCanBeBlank());
serverPropertyArrayList.add(serverProperty);
serverPropertyArrayList.add(serverProperty);
serverPropertiesVBox.getChildren().add(hBox);
serverPropertiesVBox.getChildren().add(hBox);
}
}
PluginProperties pp = new PluginProperties(i, serverPropertyArrayList, action.getName());
PluginProperties pp = new PluginProperties(i, serverPropertyArrayList, action.getName());
pluginProperties.add(pp);
pluginProperties.add(pp);
Region region1 = new Region();
region1.setPrefHeight(5);
Platform.runLater(()->{
Platform.runLater(()->{
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.getStyleClass().add("plugins_settings_each_plugin_box");
vBox.setSpacing(5.0);
vBox.setSpacing(5.0);
vBox.getChildren().addAll(headerHBox, authorLabel, moduleLabel, versionLabel, serverPropertiesVBox);
vBox.getChildren().addAll(headerHBox, authorLabel, moduleLabel, versionLabel, serverPropertiesVBox);
if(action.getButtonBar()!=null)
if(action.getButtonBar()!=null)
vBox.getChildren().add(new HBox(new SpaceFiller(SpaceFiller.FillerType.HBox), action.getButtonBar()));
{
HBox buttonBarHBox = new HBox(new SpaceFiller(SpaceFiller.FillerType.HBox), action.getButtonBar());
vBox.getChildren().add(region1);
buttonBarHBox.getStyleClass().add("plugins_settings_each_plugin_button_bar");
//vBox.setId(i+"");
vBox.getChildren().add(buttonBarHBox);
}
vBox.getStyleClass().add("settings_plugins_each_action");
pluginsSettingsVBox.getChildren().add(vBox);
pluginsSettingsVBox.getChildren().add(vBox);
});
});
}
}
}
}
public class PluginProperties
public class PluginProperties
{
{
private int index;
private int index;
private ArrayList<UIPropertyBox> serverProperty;
private ArrayList<UIPropertyBox> serverProperty;
private String name;
private String name;
public PluginProperties(int index, ArrayList<UIPropertyBox> serverProperty, String name)
public PluginProperties(int index, ArrayList<UIPropertyBox> serverProperty, String name)
{
{
this.index = index;
this.index = index;
this.serverProperty = serverProperty;
this.serverProperty = serverProperty;
this.name = name;
this.name = name;
}
}
public String getName()
public String getName()
{
{
return name;
return name;
}
}
public int getIndex() {
public int getIndex() {
return index;
return index;
}
}
public ArrayList<UIPropertyBox> getServerPropertyUIBox() {
public ArrayList<UIPropertyBox> getServerPropertyUIBox() {
return serverProperty;
return serverProperty;
}
}
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.server.controller.Controller;
import com.stream_pi.server.controller.Controller;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.themeapi.Theme;
import com.stream_pi.themeapi.Theme;
import com.stream_pi.themeapi.Themes;
import com.stream_pi.themeapi.Themes;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.*;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class ThemesSettings extends VBox
public class ThemesSettings extends VBox
{
{
private VBox themesSettingsVBox;
private VBox themesSettingsVBox;
private Controller controller;
private Controller controller;
private Logger logger;
private Logger logger;
private HostServices hostServices;
private HostServices hostServices;
public ThemesSettings(HostServices hostServices)
public ThemesSettings(HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
getStyleClass().add("themes_settings");
getStyleClass().add("themes_settings");
logger = Logger.getLogger(ThemesSettings.class.getName());
logger = Logger.getLogger(ThemesSettings.class.getName());
setPadding(new Insets(10));
setPadding(new Insets(10));
themesSettingsVBox = new VBox();
themesSettingsVBox = new VBox();
themesSettingsVBox.getStyleClass().add("themes_settings_vbox");
themesSettingsVBox.setSpacing(10.0);
themesSettingsVBox.setSpacing(10.0);
themesSettingsVBox.setAlignment(Pos.TOP_CENTER);
themesSettingsVBox.setAlignment(Pos.TOP_CENTER);
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.getStyleClass().add("themes_settings_scroll_pane");
scrollPane.getStyleClass().add("themes_settings_scroll_pane");
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
scrollPane.maxWidthProperty().bind(widthProperty().multiply(0.8));
themesSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
themesSettingsVBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setContent(themesSettingsVBox);
scrollPane.setContent(themesSettingsVBox);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
setAlignment(Pos.TOP_CENTER);
setAlignment(Pos.TOP_CENTER);
getChildren().addAll(scrollPane);
getChildren().addAll(scrollPane);
toggleButtons = new ArrayList<>();
toggleButtons = new ArrayList<>();
}
}
public void setController(Controller controller)
public void setController(Controller controller)
{
{
this.controller = controller;
this.controller = controller;
}
}
private Themes themes;
private Themes themes;
private String currentThemeFullName;
private String currentThemeFullName;
public void setThemes(Themes themes)
public void setThemes(Themes themes)
{
{
this.themes = themes;
this.themes = themes;
}
}
public void setCurrentThemeFullName(String currentThemeFullName)
public void setCurrentThemeFullName(String currentThemeFullName)
{
{
this.currentThemeFullName = currentThemeFullName;
this.currentThemeFullName = currentThemeFullName;
}
}
private ArrayList<ToggleButton> toggleButtons;
private ArrayList<ToggleButton> toggleButtons;
public void loadThemes()
public void loadThemes()
{
{
toggleButtons.clear();
toggleButtons.clear();
Platform.runLater(()-> themesSettingsVBox.getChildren().clear());
Platform.runLater(()-> themesSettingsVBox.getChildren().clear());
for(int i = 0; i<themes.getThemeList().size(); i++)
for(int i = 0; i<themes.getThemeList().size(); i++)
{
{
Theme theme = themes.getThemeList().get(i);
Theme theme = themes.getThemeList().get(i);
Label shortNameLabel = new Label(theme.getShortName());
Label shortNameLabel = new Label(theme.getShortName());
shortNameLabel.getStyleClass().add("settings_themes_each_theme_heading");
shortNameLabel.getStyleClass().add("themes_settings_each_theme_heading");
Label authorLabel = new Label(theme.getAuthor());
Label authorLabel = new Label(theme.getAuthor());
authorLabel.getStyleClass().add("themes_settings_each_theme_author_label");
Label fullNameLabel = new Label(theme.getFullName());
Label fullNameLabel = new Label(theme.getFullName());
fullNameLabel.getStyleClass().add("themes_settings_each_theme_full_name_label");
HBox topRowHBox = new HBox(shortNameLabel);
HBox topRowHBox = new HBox(shortNameLabel);
topRowHBox.getStyleClass().add("themes_settings_each_theme_header");
Label versionLabel = new Label("Version : "+theme.getVersion().getText());
versionLabel.getStyleClass().add("themes_settings_each_theme_version_label");
if(theme.getWebsite() != null)
if(theme.getWebsite() != null)
{
{
Button helpButton = new Button();
Button helpButton = new Button();
helpButton.getStyleClass().add("themes_settings_each_theme_help_button");
FontIcon questionIcon = new FontIcon("fas-question");
FontIcon questionIcon = new FontIcon("fas-question");
questionIcon.getStyleClass().add("settings_themes_theme_help_icon");
questionIcon.getStyleClass().add("themes_settings_each_theme_help_icon");
helpButton.setGraphic(questionIcon);
helpButton.setGraphic(questionIcon);
helpButton.setOnAction(event -> hostServices.showDocument(theme.getWebsite()));
helpButton.setOnAction(event -> hostServices.showDocument(theme.getWebsite()));
topRowHBox.getChildren().addAll(new SpaceFiller(SpaceFiller.FillerType.HBox), helpButton);
topRowHBox.getChildren().addAll(new SpaceFiller(SpaceFiller.FillerType.HBox), helpButton);
}
}
Label versionLabel = new Label("Version : "+theme.getVersion().getText());
ToggleButton toggleButton = new ToggleButton();
ToggleButton toggleButton = new ToggleButton();
toggleButton.getStyleClass().add("themes_settings_each_theme_toggle_button");
toggleButton.setSelected(theme.getFullName().equals(currentThemeFullName));
toggleButton.setSelected(theme.getFullName().equals(currentThemeFullName));
toggleButton.setId(theme.getFullName());
toggleButton.setId(theme.getFullName());
if(theme.getFullName().equals(currentThemeFullName))
if(theme.getFullName().equals(currentThemeFullName))
{
{
toggleButton.setText("ON");
toggleButton.setText("ON");
toggleButton.setSelected(true);
toggleButton.setSelected(true);
toggleButton.setDisable(true);
toggleButton.setDisable(true);
}
}
else
else
{
{
toggleButton.setText("OFF");
toggleButton.setText("OFF");
}
}
toggleButton.setOnAction(event -> {
toggleButton.setOnAction(event -> {
ToggleButton toggleButton1 = (ToggleButton) event.getSource();
ToggleButton toggleButton1 = (ToggleButton) event.getSource();
toggleButton.setText("ON");
toggleButton.setText("ON");
try {
try {
Config.getInstance().setCurrentThemeFullName(toggleButton1.getId());
Config.getInstance().setCurrentThemeFullName(toggleButton1.getId());
Config.getInstance().save();
Config.getInstance().save();
for(ToggleButton toggleButton2 : toggleButtons)
for(ToggleButton toggleButton2 : toggleButtons)
{
{
if(toggleButton2.getId().equals(Config.getInstance().getCurrentThemeFullName()))
if(toggleButton2.getId().equals(Config.getInstance().getCurrentThemeFullName()))
{
{
toggleButton2.setDisable(true);
toggleButton2.setDisable(true);
toggleButton2.setText("ON");
toggleButton2.setText("ON");
toggleButton2.setSelected(true);
toggleButton2.setSelected(true);
}
}
else
else
{
{
toggleButton2.setDisable(false);
toggleButton2.setDisable(false);
toggleButton2.setText("OFF");
toggleButton2.setText("OFF");
toggleButton2.setSelected(false);
toggleButton2.setSelected(false);
}
}
}
}
controller.initThemes();
controller.initThemes();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
controller.handleSevereException(e);
controller.handleSevereException(e);
}
}
});
});
HBox hBox = new HBox(toggleButton);
HBox hBox = new HBox(toggleButton);
hBox.getStyleClass().add("themes_settings_each_theme_toggle_button_parent");
Region region1 = new Region();
region1.setPrefHeight(5);
hBox.setAlignment(Pos.TOP_RIGHT);
hBox.setAlignment(Pos.TOP_RIGHT);
VBox vBox = new VBox(topRowHBox, authorLabel, versionLabel, fullNameLabel, hBox, region1);
VBox vBox = new VBox(topRowHBox, authorLabel, fullNameLabel, versionLabel, hBox);
vBox.setSpacing(5.0);
vBox.getStyleClass().add("settings_themes_each_theme");
vBox.getStyleClass().add("theme_settings_each_theme_box");
Platform.runLater(()->themesSettingsVBox.getChildren().add(vBox));
Platform.runLater(()->themesSettingsVBox.getChildren().add(vBox));
toggleButtons.add(toggleButton);
toggleButtons.add(toggleButton);
}
}
}
}
}
}
A style_classes.txt
+90 −0
dashboard
Action Detail Pane - action_details_pane
Heading HBox - action_details_pane_heading_box
Heading Label - action_details_pane_heading_label
Scroll Pane - action_details_pane_scroll_pane
VBox (Content Pane) - action_details_pane_vbox
Bottom Button Bar - action_details_pane_button_bar
Action Grid Pane (Scroll Pane) - action_grid_pane_parent
Main Grid Pane - action_grid_pane
Action Box - action_box
Is Icon Present ?
yes : action_box_icon_present
no : action_box_icon_not_present
Is Action Valid (is plugin by module name found) ?
yes : action_box_valid
no : action_box_invalid
Display Text Label - action_box_display_text_label
Client & Profile Selector Pane - client_and_profile_selector_pane
Stack VBox - client_and_profile_selector_pane_stack
"No Clients Connected" Label - client_and_profile_selector_pane_no_clients_connected_label
Client Combo Box - client_and_profile_selector_pane_client_selector_combo_box
Profile Combo Box - client_and_profile_selector_pane_profile_selector_combo_box
Plugins Pane - plugins_pane
"Plugins" Label - plugins_pane_top_label
Accordion - plugins_pane_accordion
Category - plugins_pane_each_plugin_category_titled_pane
VBox - plugins_pane_each_plugin_box_parent
HBox - plugins_pane_each_plugin_box
Each Plugin Button - plugins_pane_each_plugin_button
Icon - plugins_pane_each_plugin_button_icon
OR
ImageView (NOT RECOMMENDED FOR USE) - plugins_pane_each_plugin_button_imageview
HBox - plugins_pane_settings_button
Settings Button - plugins_pane_settings_button
settings
General - general_settings
Plugins - plugins_settings
Scroll Pane (CENTER) - plugins_settings_scroll_pane
VBox - plugins_settings_vbox
"No Plugins Present Label" - plugins_pane_no_plugins_installed_label
Each Plugin Box - plugins_settings_each_plugin_box
Header HBox - plugins_settings_each_plugin_header
Heading - plugins_settings_each_plugin_heading_label
Help Button - plugins_settings_each_plugin_help_button
Help Icon - plugins_settings_each_plugin_help_icon
Author Label - plugins_settings_each_plugin_author_label
Module Label - plugins_settings_each_plugin_module_label
Version Label - plugins_settings_each_plugin_version_label
Server Properties Box - plugins_settings_each_plugin_server_properties_box
buttonBarHBox - plugins_settings_each_plugin_button_bar
Themes - themes_settings
Scroll Pane (CENTER) - themes_settings_scroll_pane
VBox - themes_settings_vbox
Each Theme Box - theme_settings_each_theme_box
Heading HBox - themes_settings_each_theme_header
Heading Label - themes_settings_each_theme_heading
Help Button - themes_settings_each_theme_help_button
Help Icon - themes_settings_each_theme_help_icon
Author Label - themes_settings_each_theme_author_label
Full Name Label - themes_settings_each_theme_full_name_label
Version Label - themes_settings_each_theme_version_label
Toggle Button HBox - themes_settings_each_theme_toggle_button_parent
Toggle Button - themes_settings_each_theme_toggle_button
Client - clients_settings
Scroll Pane (CENTER) - clients_settings_scroll_pane
VBox - clients_settings_vbox
Each Client Box - clients_settings_each_client_box
About - about
License Label - about_license_label