server
Clone or download
Modified Files
package com.stream_pi.server.controller;
package com.stream_pi.server.controller;
import com.stream_pi.action_api.action.ServerConnection;
import com.stream_pi.action_api.action.ServerConnection;
import com.stream_pi.action_api.action.PropertySaver;
import com.stream_pi.action_api.action.PropertySaver;
import com.stream_pi.action_api.normalaction.NormalAction;
import com.stream_pi.action_api.normalaction.NormalAction;
import com.stream_pi.server.Main;
import com.stream_pi.server.Main;
import com.stream_pi.server.action.NormalActionPlugins;
import com.stream_pi.server.action.NormalActionPlugins;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.ClientConnections;
import com.stream_pi.server.connection.MainServer;
import com.stream_pi.server.connection.MainServer;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.window.Base;
import com.stream_pi.server.window.Base;
import com.stream_pi.server.window.dashboard.DonatePopupContent;
import com.stream_pi.server.window.dashboard.DonatePopupContent;
import com.stream_pi.server.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.server.window.firsttimeuse.FirstTimeUse;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertListener;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.alert.StreamPiAlertType;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.iohelper.IOHelper;
import javafx.animation.Interpolator;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.event.EventHandler;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.stage.WindowEvent;
import java.awt.SystemTray;
import java.awt.SystemTray;
import javafx.util.Duration;
import javafx.util.Duration;
import java.awt.Toolkit;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon;
import java.awt.PopupMenu;
import java.awt.PopupMenu;
import java.awt.MenuItem;
import java.awt.MenuItem;
import java.io.File;
import java.io.File;
import java.net.Inet4Address;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.net.UnknownHostException;
import java.util.Enumeration;
import java.util.Enumeration;
import java.util.Random;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Level;
public class Controller extends Base implements PropertySaver, ServerConnection
public class Controller extends Base implements PropertySaver, ServerConnection
{
{
MainServer mainServer;
MainServer mainServer;
public void setupDashWindow() throws SevereException
public void setupDashWindow() throws SevereException
{
{
try
try
{
{
StringBuilder ips = new StringBuilder();
StringBuilder ips = new StringBuilder();
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
while(e.hasMoreElements())
while(e.hasMoreElements())
{
{
NetworkInterface n = e.nextElement();
NetworkInterface n = e.nextElement();
Enumeration<InetAddress> ee = n.getInetAddresses();
Enumeration<InetAddress> ee = n.getInetAddresses();
while (ee.hasMoreElements())
while (ee.hasMoreElements())
{
{
InetAddress i = ee.nextElement();
InetAddress i = ee.nextElement();
String hostAddress = i.getHostAddress();
String hostAddress = i.getHostAddress();
if(i instanceof Inet4Address)
if(i instanceof Inet4Address)
{
{
ips.append(hostAddress);
ips.append(hostAddress);
if(e.hasMoreElements())
if(e.hasMoreElements())
ips.append(" / ");
ips.append(" / ");
}
}
}
}
}
}
getStage().setTitle("Stream-Pi Server - IP(s): "+ips.toString()+" | Port: "+ Config.getInstance().getPort()); //Sets title
getStage().setTitle("Stream-Pi Server - IP(s): "+ips.toString()+" | Port: "+ Config.getInstance().getPort()); //Sets title
getStage().setOnCloseRequest(this::onCloseRequest);
getStage().setOnCloseRequest(this::onCloseRequest);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
@Override
@Override
public void init()
public void init()
{
{
try {
try {
initBase();
initBase();
setupDashWindow();
setupDashWindow();
setupSettingsWindowsAnimations();
setupSettingsWindowsAnimations();
NormalActionPlugins.getInstance().setPropertySaver(this);
NormalActionPlugins.getInstance().setPropertySaver(this);
NormalActionPlugins.getInstance().setServerConnection(this);
NormalActionPlugins.getInstance().setServerConnection(this);
getDashboardPane().getPluginsPane().getSettingsButton().setOnAction(event -> {
getDashboardPane().getPluginsPane().getSettingsButton().setOnAction(event -> {
openSettingsTimeLine.play();
openSettingsTimeLine.play();
});
});
getSettingsPane().getCloseButton().setOnAction(event -> {
getSettingsPane().getCloseButton().setOnAction(event -> {
closeSettingsTimeLine.play();
closeSettingsTimeLine.play();
});
});
getSettingsPane().getThemesSettings().setController(this);
getSettingsPane().getThemesSettings().setController(this);
mainServer = new MainServer(this, this);
mainServer = new MainServer(this, this);
if(getConfig().isFirstTimeUse())
if(getConfig().isFirstTimeUse())
{
{
Stage stage = new Stage();
Stage stage = new Stage();
Scene s = new Scene(new FirstTimeUse(this, this), 512, 300);
Scene s = new Scene(new FirstTimeUse(this, this),
getConfig().getStartupWindowWidth(), getConfig().getStartupWindowHeight());
stage.setResizable(false);
stage.setResizable(false);
stage.setScene(s);
stage.setScene(s);
stage.setTitle("Stream-Pi Server Setup");
stage.setTitle("Stream-Pi Server Setup");
stage.initModality(Modality.APPLICATION_MODAL);
stage.initModality(Modality.APPLICATION_MODAL);
stage.setOnCloseRequest(event->Platform.exit());
stage.setOnCloseRequest(event->Platform.exit());
stage.show();
stage.show();
}
}
else
else
{
{
if(getConfig().isAllowDonatePopup())
if(getConfig().isAllowDonatePopup())
{
{
if(new Random().nextInt(5) == 3)
if(new Random().nextInt(5) == 3)
new DonatePopupContent(getHostServices(), this).show();
new DonatePopupContent(getHostServices(), this).show();
}
}
othInit();
othInit();
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
@Override
@Override
public void othInit()
public void othInit()
{
{
try
try
{
{
if(ServerInfo.getInstance().isStartMinimised() && SystemTray.isSupported())
if(ServerInfo.getInstance().isStartMinimised() && SystemTray.isSupported())
minimiseApp();
minimiseApp();
else
else
getStage().show();
getStage().show();
}
}
catch(MinorException e)
catch(MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try
try
{
{
getSettingsPane().getGeneralSettings().loadDataFromConfig();
getSettingsPane().getGeneralSettings().loadDataFromConfig();
//themes
//themes
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().loadThemes();
getSettingsPane().getThemesSettings().loadThemes();
//clients
//clients
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getClientsSettings().loadData();
try
try
{
{
//Plugins
//Plugins
Platform.runLater(()->{
Platform.runLater(()->{
getDashboardPane().getPluginsPane().clearData();
getDashboardPane().getPluginsPane().clearData();
getDashboardPane().getPluginsPane().loadOtherActions();
getDashboardPane().getPluginsPane().loadOtherActions();
});
});
NormalActionPlugins.setPluginsLocation(getConfig().getPluginsPath());
NormalActionPlugins.setPluginsLocation(getConfig().getPluginsPath());
NormalActionPlugins.getInstance().init();
NormalActionPlugins.getInstance().init();
Platform.runLater(()->getDashboardPane().getPluginsPane().loadData());
Platform.runLater(()->getDashboardPane().getPluginsPane().loadData());
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getPluginsSettings().loadPlugins();
}
}
catch (MinorException e)
catch (MinorException e)
{
{
getSettingsPane().getPluginsSettings().showPluginInitError();
getSettingsPane().getPluginsSettings().showPluginInitError();
handleMinorException(e);
handleMinorException(e);
}
}
//Server
//Server
mainServer.setPort(getConfig().getPort());
mainServer.setPort(getConfig().getPort());
mainServer.start();
mainServer.start();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
private void setupSettingsWindowsAnimations()
private void setupSettingsWindowsAnimations()
{
{
Node settingsNode = getSettingsPane();
Node settingsNode = getSettingsPane();
Node dashboardNode = getDashboardPane();
Node dashboardNode = getDashboardPane();
openSettingsTimeLine = new Timeline();
openSettingsTimeLine = new Timeline();
openSettingsTimeLine.setCycleCount(1);
openSettingsTimeLine.setCycleCount(1);
openSettingsTimeLine.getKeyFrames().addAll(
openSettingsTimeLine.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
0.0D, Interpolator.EASE_IN),
0.0D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.1D, Interpolator.EASE_IN),
1.1D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.1D, Interpolator.EASE_IN),
1.1D, Interpolator.EASE_IN),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.1D, Interpolator.EASE_IN)),
1.1D, Interpolator.EASE_IN)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
0.0D, Interpolator.LINEAR),
0.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
0.9D, Interpolator.LINEAR))
0.9D, Interpolator.LINEAR))
);
);
openSettingsTimeLine.setOnFinished(event1 -> {
openSettingsTimeLine.setOnFinished(event1 -> {
settingsNode.toFront();
settingsNode.toFront();
});
});
closeSettingsTimeLine = new Timeline();
closeSettingsTimeLine = new Timeline();
closeSettingsTimeLine.setCycleCount(1);
closeSettingsTimeLine.setCycleCount(1);
closeSettingsTimeLine.getKeyFrames().addAll(
closeSettingsTimeLine.getKeyFrames().addAll(
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.0D, Interpolator.LINEAR)),
1.0D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(settingsNode.opacityProperty(),
new KeyValue(settingsNode.opacityProperty(),
0.0D, Interpolator.LINEAR),
0.0D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleXProperty(),
new KeyValue(settingsNode.scaleXProperty(),
1.1D, Interpolator.LINEAR),
1.1D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleYProperty(),
new KeyValue(settingsNode.scaleYProperty(),
1.1D, Interpolator.LINEAR),
1.1D, Interpolator.LINEAR),
new KeyValue(settingsNode.scaleZProperty(),
new KeyValue(settingsNode.scaleZProperty(),
1.1D, Interpolator.LINEAR)),
1.1D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(0.0D),
new KeyFrame(Duration.millis(0.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
0.0D, Interpolator.LINEAR),
0.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
0.9D, Interpolator.LINEAR),
0.9D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
0.9D, Interpolator.LINEAR)),
0.9D, Interpolator.LINEAR)),
new KeyFrame(Duration.millis(90.0D),
new KeyFrame(Duration.millis(90.0D),
new KeyValue(dashboardNode.opacityProperty(),
new KeyValue(dashboardNode.opacityProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleXProperty(),
new KeyValue(dashboardNode.scaleXProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleYProperty(),
new KeyValue(dashboardNode.scaleYProperty(),
1.0D, Interpolator.LINEAR),
1.0D, Interpolator.LINEAR),
new KeyValue(dashboardNode.scaleZProperty(),
new KeyValue(dashboardNode.scaleZProperty(),
1.0D, Interpolator.LINEAR))
1.0D, Interpolator.LINEAR))
);
);
closeSettingsTimeLine.setOnFinished(event1 -> {
closeSettingsTimeLine.setOnFinished(event1 -> {
dashboardNode.toFront();
dashboardNode.toFront();
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call() {
protected Void call() {
try {
try {
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getGeneralSettings().loadDataFromConfig();
getSettingsPane().getGeneralSettings().loadDataFromConfig();
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setThemes(getThemes());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().setCurrentThemeFullName(getCurrentTheme().getFullName());
getSettingsPane().getThemesSettings().loadThemes();
getSettingsPane().getThemesSettings().loadThemes();
getSettingsPane().setDefaultTabToGeneral();
getSettingsPane().setDefaultTabToGeneral();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
return null;
return null;
}
}
}).start();
}).start();
});
});
}
}
private Timeline openSettingsTimeLine;
private Timeline openSettingsTimeLine;
private Timeline closeSettingsTimeLine;
private Timeline closeSettingsTimeLine;
public Controller(){
public Controller(){
mainServer = null;
mainServer = null;
}
}
public void onCloseRequest(WindowEvent event)
public void onCloseRequest(WindowEvent event)
{
{
try
try
{
{
if(Config.getInstance().getMinimiseToSystemTrayOnClose() &&
if(Config.getInstance().getMinimiseToSystemTrayOnClose() &&
SystemTray.isSupported())
SystemTray.isSupported())
{
{
minimiseApp();
minimiseApp();
event.consume();
event.consume();
return;
return;
}
}
getConfig().setStartupWindowSize(
getConfig().setStartupWindowSize(
getWidth(),
getWidth(),
getHeight()
getHeight()
);
);
getConfig().save();
getConfig().save();
onQuitApp();
onQuitApp();
NormalActionPlugins.getInstance().shutDownActions();
NormalActionPlugins.getInstance().shutDownActions();
Platform.exit();
Platform.exit();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
handleMinorException(e);
handleMinorException(e);
}
}
finally
finally
{
{
closeLogger();
closeLogger();
}
}
}
}
public void onQuitApp()
public void onQuitApp()
{
{
if(mainServer!=null)
if(mainServer!=null)
mainServer.stopListeningForConnections();
mainServer.stopListeningForConnections();
ClientConnections.getInstance().disconnectAll();
ClientConnections.getInstance().disconnectAll();
getLogger().info("Shutting down ...");
getLogger().info("Shutting down ...");
}
}
public void minimiseApp() throws MinorException
public void minimiseApp() throws MinorException
{
{
try
try
{
{
SystemTray systemTray = SystemTray.getSystemTray();
SystemTray systemTray = SystemTray.getSystemTray();
if(getTrayIcon() == null)
if(getTrayIcon() == null)
initIconTray(systemTray);
initIconTray(systemTray);
systemTray.add(getTrayIcon());
systemTray.add(getTrayIcon());
getStage().hide();
getStage().hide();
getStage().setOnShown(windowEvent -> {
getStage().setOnShown(windowEvent -> {
systemTray.remove(getTrayIcon());
systemTray.remove(getTrayIcon());
});
});
}
}
catch(Exception e)
catch(Exception e)
{
{
throw new MinorException(e.getMessage());
throw new MinorException(e.getMessage());
}
}
}
}
public void initIconTray(SystemTray systemTray)
public void initIconTray(SystemTray systemTray)
{
{
Platform.setImplicitExit(false);
Platform.setImplicitExit(false);
PopupMenu popup = new PopupMenu();
PopupMenu popup = new PopupMenu();
MenuItem showItem = new MenuItem("Show");
MenuItem showItem = new MenuItem("Show");
showItem.addActionListener(l->{
showItem.addActionListener(l->{
Platform.runLater(()->{
Platform.runLater(()->{
getStage().show();
getStage().show();
});
});
});
});
MenuItem exitItem = new MenuItem("Exit");
MenuItem exitItem = new MenuItem("Exit");
exitItem.addActionListener(l->{
exitItem.addActionListener(l->{
systemTray.remove(getTrayIcon());
systemTray.remove(getTrayIcon());
onQuitApp();
onQuitApp();
Platform.exit();
Platform.exit();
});
});
popup.add(showItem);
popup.add(showItem);
popup.addSeparator();
popup.addSeparator();
popup.add(exitItem);
popup.add(exitItem);
TrayIcon trayIcon = new TrayIcon(
TrayIcon trayIcon = new TrayIcon(
Toolkit.getDefaultToolkit().getImage(Main.class.getResource("app_icon.png")),
Toolkit.getDefaultToolkit().getImage(Main.class.getResource("app_icon.png")),
"Stream-Pi Server",
"Stream-Pi Server",
popup
popup
);
);
trayIcon.setImageAutoSize(true);
trayIcon.setImageAutoSize(true);
this.trayIcon = trayIcon;
this.trayIcon = trayIcon;
}
}
private TrayIcon trayIcon = null;
private TrayIcon trayIcon = null;
public TrayIcon getTrayIcon()
public TrayIcon getTrayIcon()
{
{
return trayIcon;
return trayIcon;
}
}
@Override
@Override
public void handleMinorException(MinorException e) {
public void handleMinorException(MinorException e) {
getLogger().log(Level.SEVERE, e.getMessage(), e);
getLogger().log(Level.SEVERE, e.getMessage(), e);
e.printStackTrace();
e.printStackTrace();
Platform.runLater(()->{
Platform.runLater(()->{
new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show();
new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.WARNING).show();
});
});
}
}
@Override
@Override
public void handleSevereException(SevereException e) {
public void handleSevereException(SevereException e) {
getLogger().log(Level.SEVERE, e.getMessage(), e);
getLogger().log(Level.SEVERE, e.getMessage(), e);
e.printStackTrace();
e.printStackTrace();
Platform.runLater(()->{
Platform.runLater(()->{
StreamPiAlert alert = new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert(e.getTitle(), e.getShortMessage(), StreamPiAlertType.ERROR);
alert.setOnClicked(new StreamPiAlertListener()
alert.setOnClicked(new StreamPiAlertListener()
{
{
@Override
@Override
public void onClick(String txt)
public void onClick(String txt)
{
{
onQuitApp();
onQuitApp();
Platform.exit();
Platform.exit();
}
}
});
});
alert.show();
alert.show();
});
});
}
}
@Override
@Override
public synchronized boolean onNormalActionClicked(NormalAction action) {
public synchronized boolean onNormalActionClicked(NormalAction action) {
try{
try{
getLogger().info("action "+action.getID()+" clicked!");
getLogger().info("action "+action.getID()+" clicked!");
action.onActionClicked();
action.onActionClicked();
return true;
return true;
}
}
catch (Exception e)
catch (Exception e)
{
{
//check if its windows UAC related
//check if its windows UAC related
if(e.getMessage().contains("operation requires elevation"))
if(e.getMessage().contains("operation requires elevation"))
{
{
handleMinorException(new MinorException(
handleMinorException(new MinorException(
"Action Execution Failed!",
"Action Execution Failed!",
"Error running action at ["+action.getLocation().getRow()+","+action.getLocation().getCol()+"] ("+action.getDisplayText()+")\n"+
"Error running action at ["+action.getLocation().getRow()+","+action.getLocation().getCol()+"] ("+action.getDisplayText()+")\n"+
"This action requires higher UAC privileges. Re-launch Stream-Pi Server with 'Administrator Privileges' in order to run this command.")
"This action requires higher UAC privileges. Re-launch Stream-Pi Server with 'Administrator Privileges' in order to run this command.")
);
);
}
}
else
else
{
{
handleMinorException(new MinorException(
handleMinorException(new MinorException(
"Action Execution Failed!",
"Action Execution Failed!",
"Error running action at ["+action.getLocation().getRow()+","+action.getLocation().getCol()+"] ("+action.getDisplayText()+")\n"+
"Error running action at ["+action.getLocation().getRow()+","+action.getLocation().getCol()+"] ("+action.getDisplayText()+")\n"+
"Check stacktrace/log to know what exactly happened\n\nMessage : \n"+e.getMessage() )
"Check stacktrace/log to know what exactly happened\n\nMessage : \n"+e.getMessage() )
);
);
}
}
return false;
return false;
}
}
}
}
@Override
@Override
public void clearTemp() {
public void clearTemp() {
Platform.runLater(() -> {
Platform.runLater(() -> {
getDashboardPane().getClientDetailsPane().refresh();
getDashboardPane().getClientDetailsPane().refresh();
getDashboardPane().getActionGridPane().clear();
getDashboardPane().getActionGridPane().clear();
getDashboardPane().getActionGridPane().setFreshRender(true);
getDashboardPane().getActionGridPane().setFreshRender(true);
getDashboardPane().getActionDetailsPane().clear();
getDashboardPane().getActionDetailsPane().clear();
getSettingsPane().getClientsSettings().loadData();
getSettingsPane().getClientsSettings().loadData();
});
});
}
}
@Override
@Override
public void saveServerProperties() {
public void saveServerProperties() {
try {
try {
NormalActionPlugins.getInstance().saveServerSettings();
NormalActionPlugins.getInstance().saveServerSettings();
getSettingsPane().getPluginsSettings().loadPlugins();
getSettingsPane().getPluginsSettings().loadPlugins();
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
handleMinorException(e);
handleMinorException(e);
}
}
}
}
@Override
@Override
public com.stream_pi.util.platform.Platform getPlatform() {
public com.stream_pi.util.platform.Platform getPlatform() {
return ServerInfo.getInstance().getPlatformType();
return ServerInfo.getInstance().getPlatformType();
}
}
}
}
package com.stream_pi.server.window;
package com.stream_pi.server.window;
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.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.Main;
import com.stream_pi.server.Main;
import com.stream_pi.server.window.dashboard.DashboardBase;
import com.stream_pi.server.window.dashboard.DashboardBase;
import com.stream_pi.server.window.settings.SettingsBase;
import com.stream_pi.server.window.settings.SettingsBase;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Theme;
import com.stream_pi.theme_api.Themes;
import com.stream_pi.theme_api.Themes;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.exception.SevereException;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.iohelper.IOHelper;
import com.stream_pi.util.loggerhelper.StreamPiLogFallbackHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFallbackHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFileHandler;
import com.stream_pi.util.loggerhelper.StreamPiLogFileHandler;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Font;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.Stage;
import java.awt.*;
import java.awt.*;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
public abstract class Base extends StackPane implements ExceptionAndAlertHandler, ServerListener {
public abstract class Base extends StackPane implements ExceptionAndAlertHandler, ServerListener {
private Config config;
private Config config;
private ServerInfo serverInfo;
private ServerInfo serverInfo;
private Stage stage;
private Stage stage;
private HostServices hostServices;
private HostServices hostServices;
public Logger getLogger(){
public Logger getLogger(){
return logger;
return logger;
}
}
private SettingsBase settingsBase;
private SettingsBase settingsBase;
private DashboardBase dashboardBase;
private DashboardBase dashboardBase;
private StackPane alertStackPane;
private StackPane alertStackPane;
public void setHostServices(HostServices hostServices)
public void setHostServices(HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
}
}
public HostServices getHostServices()
public HostServices getHostServices()
{
{
return hostServices;
return hostServices;
}
}
private Logger logger = null;
private Logger logger = null;
private StreamPiLogFileHandler logFileHandler = null;
private StreamPiLogFileHandler logFileHandler = null;
private StreamPiLogFallbackHandler logFallbackHandler = null;
private StreamPiLogFallbackHandler logFallbackHandler = null;
@Override
@Override
public void initLogger() throws SevereException
public void initLogger()
{
{
try
try
{
{
if(logger != null || logFileHandler != null)
if(logFileHandler != null)
return;
return;
closeLogger();
closeLogger();
logger = Logger.getLogger("");
logger = Logger.getLogger("");
if(new File(ServerInfo.getInstance().getPrePath()).getAbsoluteFile().getParentFile().canWrite())
if(new File(ServerInfo.getInstance().getPrePath()).getAbsoluteFile().getParentFile().canWrite())
{
{
String path = ServerInfo.getInstance().getPrePath()+"../streampi.log";
String path = ServerInfo.getInstance().getPrePath()+"../stream-pi-server.log";
if(ServerInfo.getInstance().getPlatformType() == Platform.ANDROID)
if(ServerInfo.getInstance().getPlatformType() == Platform.ANDROID)
path = ServerInfo.getInstance().getPrePath()+"streampi.log";
path = ServerInfo.getInstance().getPrePath()+"stream-pi-server.log";
logFileHandler = new StreamPiLogFileHandler(path);
logFileHandler = new StreamPiLogFileHandler(path);
logger.addHandler(logFileHandler);
logger.addHandler(logFileHandler);
}
}
else
else
{
{
logFallbackHandler = new StreamPiLogFallbackHandler();
logFallbackHandler = new StreamPiLogFallbackHandler();
logger.addHandler(logFallbackHandler);
logger.addHandler(logFallbackHandler);
}
}
}
}
catch(Exception e)
catch(Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
logFallbackHandler = new StreamPiLogFallbackHandler();
logFallbackHandler = new StreamPiLogFallbackHandler();
logger.addHandler(logFallbackHandler);
logger.addHandler(logFallbackHandler);
}
}
}
}
public void closeLogger()
public void closeLogger()
{
{
if(logFileHandler != null)
if(logFileHandler != null)
logFileHandler.close();
logFileHandler.close();
else if(logFallbackHandler != null)
else if(logFallbackHandler != null)
logFallbackHandler.close();
logFallbackHandler.close();
}
}
public void initBase() throws SevereException
public void initBase() throws SevereException
{
{
stage = (Stage) getScene().getWindow();
stage = (Stage) getScene().getWindow();
getStage().getIcons().add(new Image(Main.class.getResourceAsStream("app_icon.png")));
getStage().getIcons().add(new Image(Main.class.getResourceAsStream("app_icon.png")));
getStage().setMinWidth(500);
getStage().setMinWidth(500);
getStage().setMinHeight(500);
getStage().setMinHeight(500);
serverInfo = ServerInfo.getInstance();
serverInfo = ServerInfo.getInstance();
settingsBase = new SettingsBase(getHostServices(), this, this);
settingsBase = new SettingsBase(getHostServices(), this, this);
settingsBase.prefWidthProperty().bind(widthProperty());
settingsBase.prefWidthProperty().bind(widthProperty());
settingsBase.prefHeightProperty().bind(heightProperty());
settingsBase.prefHeightProperty().bind(heightProperty());
dashboardBase = new DashboardBase(this, getHostServices());
dashboardBase = new DashboardBase(this, getHostServices());
dashboardBase.prefWidthProperty().bind(widthProperty());
dashboardBase.prefWidthProperty().bind(widthProperty());
dashboardBase.prefHeightProperty().bind(heightProperty());
dashboardBase.prefHeightProperty().bind(heightProperty());
alertStackPane = new StackPane();
alertStackPane = new StackPane();
alertStackPane.setVisible(false);
alertStackPane.setVisible(false);
StreamPiAlert.setParent(alertStackPane);
StreamPiAlert.setParent(alertStackPane);
getChildren().clear();
getChildren().clear();
getChildren().addAll(alertStackPane);
getChildren().addAll(alertStackPane);
initLogger();
initLogger();
checkPrePathDirectory();
checkPrePathDirectory();
getChildren().addAll(settingsBase, dashboardBase);
getChildren().addAll(settingsBase, dashboardBase);
config = Config.getInstance();
config = Config.getInstance();
initThemes();
initThemes();
stage.setWidth(config.getStartupWindowWidth());
stage.setWidth(config.getStartupWindowWidth());
stage.setHeight(config.getStartupWindowHeight());
stage.setHeight(config.getStartupWindowHeight());
stage.centerOnScreen();
stage.centerOnScreen();
dashboardBase.toFront();
dashboardBase.toFront();
}
}
private void checkPrePathDirectory() throws SevereException
private void checkPrePathDirectory() throws SevereException
{
{
try
try
{
{
File filex = new File(ServerInfo.getInstance().getPrePath());
File filex = new File(ServerInfo.getInstance().getPrePath());
if(!filex.exists())
if(!filex.exists())
{
{
boolean result = filex.mkdirs();
boolean result = filex.mkdirs();
if(result)
if(result)
{
{
IOHelper.unzip(Main.class.getResourceAsStream("Default.obj"), ServerInfo.getInstance().getPrePath());
IOHelper.unzip(Main.class.getResourceAsStream("Default.zip"), ServerInfo.getInstance().getPrePath());
Config.getInstance().setThemesPath(ServerInfo.getInstance().getPrePath()+"Themes/");
Config.getInstance().setThemesPath(ServerInfo.getInstance().getPrePath()+"Themes/");
Config.getInstance().setPluginsPath(ServerInfo.getInstance().getPrePath()+"Plugins/");
Config.getInstance().setPluginsPath(ServerInfo.getInstance().getPrePath()+"Plugins/");
if(SystemTray.isSupported())
if(SystemTray.isSupported())
{
{
Config.getInstance().setMinimiseToSystemTrayOnClose(true);
Config.getInstance().setMinimiseToSystemTrayOnClose(true);
}
}
Config.getInstance().save();
Config.getInstance().save();
initLogger();
}
}
else
else
{
{
setPrefSize(300,300);
setPrefSize(300,300);
clearStylesheets();
clearStylesheets();
applyDefaultStylesheet();
applyDefaultStylesheet();
applyDefaultIconsStylesheet();
applyDefaultIconsStylesheet();
getStage().show();
getStage().show();
throw new SevereException("No storage permission. Give it!");
throw new SevereException("No storage permission. Give it!");
}
}
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException(e.getMessage());
throw new SevereException(e.getMessage());
}
}
}
}
public void initThemes() throws SevereException {
public void initThemes() throws SevereException {
clearStylesheets();
clearStylesheets();
registerThemes();
registerThemes();
applyDefaultStylesheet();
applyDefaultStylesheet();
applyDefaultTheme();
applyDefaultTheme();
applyDefaultIconsStylesheet();
applyDefaultIconsStylesheet();
}
}
public Stage getStage()
public Stage getStage()
{
{
return stage;
return stage;
}
}
public void applyDefaultStylesheet()
public void applyDefaultStylesheet()
{
{
logger.info("Applying default stylesheet ...");
logger.info("Applying default stylesheet ...");
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
getStylesheets().add(Main.class.getResource("style.css").toExternalForm());
logger.info("... Done!");
logger.info("... Done!");
}
}
public void applyDefaultIconsStylesheet()
public void applyDefaultIconsStylesheet()
{
{
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
Font.loadFont(Main.class.getResourceAsStream("Roboto.ttf"), 13);
getStylesheets().add(Main.class.getResource("default_icons.css").toExternalForm());
getStylesheets().add(Main.class.getResource("default_icons.css").toExternalForm());
}
}
public DashboardBase getDashboardPane()
public DashboardBase getDashboardPane()
{
{
return dashboardBase;
return dashboardBase;
}
}
public SettingsBase getSettingsPane()
public SettingsBase getSettingsPane()
{
{
return settingsBase;
return settingsBase;
}
}
public Config getConfig()
public Config getConfig()
{
{
return config;
return config;
}
}
public ServerInfo getServerInfo()
public ServerInfo getServerInfo()
{
{
return serverInfo;
return serverInfo;
}
}
private Theme currentTheme;
private Theme currentTheme;
public Theme getCurrentTheme()
public Theme getCurrentTheme()
{
{
return currentTheme;
return currentTheme;
}
}
public void applyTheme(Theme t)
public void applyTheme(Theme t)
{
{
logger.info("Applying theme '"+t.getFullName()+"' ...");
logger.info("Applying theme '"+t.getFullName()+"' ...");
if(t.getFonts() != null)
if(t.getFonts() != null)
{
{
for(String fontFile : t.getFonts())
for(String fontFile : t.getFonts())
{
{
Font.loadFont(fontFile.replace("%20",""), 13);
Font.loadFont(fontFile.replace("%20",""), 13);
}
}
}
}
currentTheme = t;
currentTheme = t;
getStylesheets().addAll(t.getStylesheets());
getStylesheets().addAll(t.getStylesheets());
logger.info("... Done!");
logger.info("... Done!");
}
}
public void clearStylesheets()
public void clearStylesheets()
{
{
getStylesheets().clear();
getStylesheets().clear();
}
}
Themes themes;
Themes themes;
public void registerThemes() throws SevereException
public void registerThemes() throws SevereException
{
{
logger.info("Loading themes ...");
logger.info("Loading themes ...");
themes = new Themes(getConfig().getThemesPath(), getConfig().getCurrentThemeFullName(), serverInfo.getMinThemeSupportVersion());
themes = new Themes(getConfig().getThemesPath(), getConfig().getCurrentThemeFullName(), serverInfo.getMinThemeSupportVersion());
if(themes.getErrors().size()>0)
if(themes.getErrors().size()>0)
{
{
StringBuilder themeErrors = new StringBuilder();
StringBuilder themeErrors = new StringBuilder();
for(MinorException eachException : themes.getErrors())
for(MinorException eachException : themes.getErrors())
{
{
themeErrors.append("\n * ").append(eachException.getShortMessage());
themeErrors.append("\n * ").append(eachException.getShortMessage());
}
}
if(themes.getIsBadThemeTheCurrentOne())
if(themes.getIsBadThemeTheCurrentOne())
{
{
themeErrors.append("\n\nReverted to default theme! (").append(getConfig().getDefaultCurrentThemeFullName()).append(")");
themeErrors.append("\n\nReverted to default theme! (").append(getConfig().getDefaultCurrentThemeFullName()).append(")");
getConfig().setCurrentThemeFullName(getConfig().getDefaultCurrentThemeFullName());
getConfig().setCurrentThemeFullName(getConfig().getDefaultCurrentThemeFullName());
getConfig().save();
getConfig().save();
}
}
handleMinorException(new MinorException("Theme Loading issues", themeErrors.toString()));
handleMinorException(new MinorException("Theme Loading issues", themeErrors.toString()));
}
}
logger.info("... Done!");
logger.info("... Done!");
}
}
public Themes getThemes()
public Themes getThemes()
{
{
return themes;
return themes;
}
}
public void applyDefaultTheme()
public void applyDefaultTheme()
{
{
logger.info("Applying default theme ...");
logger.info("Applying default theme ...");
boolean foundTheme = false;
boolean foundTheme = false;
for(Theme t: themes.getThemeList())
for(Theme t: themes.getThemeList())
{
{
if(t.getFullName().equals(config.getCurrentThemeFullName()))
if(t.getFullName().equals(config.getCurrentThemeFullName()))
{
{
foundTheme = true;
foundTheme = true;
applyTheme(t);
applyTheme(t);
break;
break;
}
}
}
}
if(foundTheme)
if(foundTheme)
logger.info("... Done!");
logger.info("... Done!");
else
else
{
{
logger.info("Theme not found. reverting to light theme ...");
logger.info("Theme not found. reverting to light theme ...");
try {
try {
Config.getInstance().setCurrentThemeFullName("com.streampi.DefaultLight");
Config.getInstance().setCurrentThemeFullName("com.streampi.DefaultLight");
Config.getInstance().save();
Config.getInstance().save();
applyDefaultTheme();
applyDefaultTheme();
}
}
catch (SevereException e)
catch (SevereException e)
{
{
handleSevereException(e);
handleSevereException(e);
}
}
}
}
}
}
}
}
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 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<>();
logger = Logger.getLogger(ClientsSettings.class.getName());
logger = Logger.getLogger(ClientsSettings.class.getName());
clientsSettingsVBox = new VBox();
clientsSettingsVBox = new VBox();
clientsSettingsVBox.getStyleClass().add("clients_settings_vbox");
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 - 50))
{
{
errors2.append(" Rows out of bounds of screen size. \n"+startupWidth);
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());
if((cols*actionsSize) > (startupHeight - 25) && clientSettingsVBox.getPlatform()!= com.stream_pi.util.platform.Platform.ANDROID)
if((cols*actionsSize) > (startupHeight - 50))
{
{
errors2.append(" Cols out of bounds of screen size. \n"+startupHeight);
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 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");
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 {
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("client_settings_each_client_platform_label");
platformLabel.getStyleClass().add("client_settings_each_client_platform_label");
socketConnectionLabel = new Label();
socketConnectionLabel = new Label();
socketConnectionLabel.getStyleClass().add("client_settings_each_client_socket_connection_label");
socketConnectionLabel.getStyleClass().add("client_settings_each_client_socket_connection_label");
nicknameTextField = new TextField();
nicknameTextField = new TextField();
nickNameLabel = new Label();
nickNameLabel = new Label();
nickNameLabel.getStyleClass().add("client_settings_each_client_nick_name_label");
nickNameLabel.getStyleClass().add("client_settings_each_client_nick_name_label");
versionLabel = new Label();
versionLabel = new Label();
versionLabel.getStyleClass().add("client_settings_each_client_version_label");
versionLabel.getStyleClass().add("client_settings_each_client_version_label");
profilesAccordion = new Accordion();
profilesAccordion = new Accordion();
profilesAccordion.getStyleClass().add("client_settings_each_client_profiles_accordion");
profilesAccordion.getStyleClass().add("client_settings_each_client_profiles_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"),
SpaceFiller.horizontal(),
SpaceFiller.horizontal(),
themesComboBox
themesComboBox
),
),
startupWindowHeightInputBox,
startupWindowHeightInputBox,
startupWindowWidthInputBox,
startupWindowWidthInputBox,
new HBox(new Label("Startup Profile"),
new HBox(new Label("Startup Profile"),
SpaceFiller.horizontal(),
SpaceFiller.horizontal(),
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.getStyleClass().add("client_settings_each_client_accordion_each_titled_pane");
titledPane.getStyleClass().add("client_settings_each_client_accordion_each_titled_pane");
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;
getStyleClass().add("client_settings_each_client_accordion_each_profile_box");
getStyleClass().add("client_settings_each_client_accordion_each_profile_box");
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;
}
}
}
}
}
}
PK a[R