server

Clone or download

removed logging stuff

Modified Files

package com.StreamPi.Server.Window.Settings;
package com.StreamPi.Server.Window.Settings;
import com.StreamPi.Server.Client.Client;
import com.StreamPi.Server.Client.Client;
import com.StreamPi.Server.Client.ClientProfile;
import com.StreamPi.Server.Client.ClientProfile;
import com.StreamPi.Server.Client.ClientTheme;
import com.StreamPi.Server.Client.ClientTheme;
import com.StreamPi.Server.Connection.ClientConnection;
import com.StreamPi.Server.Connection.ClientConnection;
import com.StreamPi.Server.Connection.ClientConnections;
import com.StreamPi.Server.Connection.ClientConnections;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Server.Window.ExceptionAndAlertHandler;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.MinorException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.Exception.SevereException;
import com.StreamPi.Util.FormHelper.HBoxInputBox;
import com.StreamPi.Util.FormHelper.HBoxInputBox;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.Platform.ReleaseStatus;
import com.StreamPi.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.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.VBox;
import javafx.scene.layout.VBox;
import javafx.util.Callback;
import javafx.util.Callback;
import org.w3c.dom.Text;
import org.w3c.dom.Text;
import java.lang.reflect.Array;
import java.lang.reflect.Array;
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));
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.setSpacing(20.0);
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());
logger.info("@#@#@#@## : "+rows+","+actionsSize+","+startupWidth+","+(rows*actionsSize)+","+startupWidth);
if((rows*actionsSize) > (startupWidth - 25))
if((rows*actionsSize) > (startupWidth- 25))
{
{
errors2.append(" Rows out of bounds of screen size. \n");
errors2.append(" Rows out of bounds of screen size. \n");
}
}
}
}
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());
logger.info("@#@sd#@#@## : "+cols+","+actionsSize+","+startupHeight+","+(cols*actionsSize)+","+startupHeight);
if((cols*actionsSize) > (startupHeight - 25))
if((cols*actionsSize) > (startupHeight - 25))
{
{
errors2.append(" Cols out of bounds of screen size. \n");
errors2.append(" Cols out of bounds of screen size. \n");
}
}
}
}
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 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;
clientProfileVBoxes = new ArrayList<>();
clientProfileVBoxes = new ArrayList<>();
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.StreamPi.Util.Platform.Platform.ANDROID)
if(client.getPlatform() == com.StreamPi.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;
}
}
}
}
}
}