server

Clone or download

Set min size

Modified Files

package com.StreamPi.Server.Window;
package com.StreamPi.Server.Window;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.Connection.ServerListener;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.IO.Config;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Info.ServerInfo;
import com.StreamPi.Server.Main;
import com.StreamPi.Server.Main;
import com.StreamPi.Server.Window.Dashboard.*;
import com.StreamPi.Server.Window.Dashboard.*;
import com.StreamPi.Server.Window.Settings.SettingsBase;
import com.StreamPi.Server.Window.Settings.SettingsBase;
import com.StreamPi.ThemeAPI.Theme;
import com.StreamPi.ThemeAPI.Theme;
import com.StreamPi.ThemeAPI.Themes;
import com.StreamPi.ThemeAPI.Themes;
import com.StreamPi.Util.Alert.StreamPiAlert;
import com.StreamPi.Util.Alert.StreamPiAlert;
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.LoggerHelper.StreamPiLogFileHandler;
import com.StreamPi.Util.LoggerHelper.StreamPiLogFileHandler;
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.SystemTray;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.TrayIcon;
import java.io.IOException;
import java.io.IOException;
import java.util.logging.LogManager;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.Logger;
import java.awt.PopupMenu;
import java.awt.PopupMenu;
import java.awt.MenuItem;
import java.awt.MenuItem;
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;
public void initLogger() throws SevereException
public void initLogger() throws SevereException
{
{
try
try
{
{
if(logger != null)
if(logger != null)
return;
return;
logger = Logger.getLogger("");
logger = Logger.getLogger("");
logFileHandler = new StreamPiLogFileHandler(ServerInfo.getInstance().getPrePath()+"../streampi.log");
logFileHandler = new StreamPiLogFileHandler(ServerInfo.getInstance().getPrePath()+"../streampi.log");
logger.addHandler(logFileHandler);
logger.addHandler(logFileHandler);
}
}
catch(Exception e)
catch(Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new SevereException("Cant get logger started!");
throw new SevereException("Cant get logger started!");
}
}
}
}
public void closeLogger()
public void closeLogger()
{
{
if(logFileHandler != null)
if(logFileHandler != null)
logFileHandler.close();
logFileHandler.close();
}
}
public void initBase() throws SevereException {
public void initBase() throws SevereException {
initLogger();
initLogger();
getChildren().clear();
getChildren().clear();
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().setMinHeight(500);
config = Config.getInstance();
config = Config.getInstance();
stage.setWidth(config.getStartupWindowWidth());
stage.setWidth(config.getStartupWindowWidth());
stage.setHeight(config.getStartupWindowHeight());
stage.setHeight(config.getStartupWindowHeight());
serverInfo = ServerInfo.getInstance();
serverInfo = ServerInfo.getInstance();
initThemes();
initThemes();
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().addAll(settingsBase, dashboardBase, alertStackPane);
getChildren().addAll(settingsBase, dashboardBase, alertStackPane);
dashboardBase.toFront();
dashboardBase.toFront();
}
}
public void initThemes() throws SevereException {
public void initThemes() throws SevereException {
clearStylesheets();
clearStylesheets();
registerThemes();
registerThemes();
applyDefaultStylesheet();
applyDefaultStylesheet();
applyDefaultTheme();
applyDefaultTheme();
}
}
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 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);
}
}
}
}
}
}
}
}