server

Clone or download

Modified Files

package com.stream_pi.server.window.dashboard.actiongridpane;
package com.stream_pi.server.window.dashboard.actiongridpane;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.Action;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.ActionType;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.DisplayTextAlignment;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.server.controller.ActionDataFormats;
import com.stream_pi.server.controller.ActionDataFormats;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.server.window.dashboard.actiondetailpane.ActionDetailsPaneListener;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.Image;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.Dragboard;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseButton;
import javafx.scene.input.TransferMode;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Background;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.TextAlignment;
import javafx.scene.text.TextAlignment;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectInputStream;
import java.nio.ByteBuffer;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.List;
public class ActionBox extends StackPane{
public class ActionBox extends StackPane{
private Label displayTextLabel;
private Label displayTextLabel;
private int row;
private int row;
private int col;
private int col;
public void setRow(int row) {
public void setRow(int row) {
this.row = row;
this.row = row;
}
}
public void setCol(int col) {
public void setCol(int col) {
this.col = col;
this.col = col;
}
}
public int getRow() {
public int getRow() {
return row;
return row;
}
}
public int getCol() {
public int getCol() {
return col;
return col;
}
}
private ActionDetailsPaneListener actionDetailsPaneListener;
private final ActionDetailsPaneListener actionDetailsPaneListener;
public void clear()
public void clear()
{
{
setStyle(null);
setStyle(null);
setAction(null);
setAction(null);
getStyleClass().clear();
getStyleClass().clear();
setBackground(Background.EMPTY);
setBackground(Background.EMPTY);
removeFontIcon();
removeFontIcon();
getChildren().clear();
getChildren().clear();
baseInit();
baseInit();
}
}
public void baseInit()
public void baseInit()
{
{
displayTextLabel = new Label();
displayTextLabel = new Label();
displayTextLabel.setWrapText(true);
displayTextLabel.setWrapText(true);
displayTextLabel.setTextAlignment(TextAlignment.CENTER);
displayTextLabel.setTextAlignment(TextAlignment.CENTER);
displayTextLabel.getStyleClass().add("action_box_display_text_label");
displayTextLabel.getStyleClass().add("action_box_display_text_label");
displayTextLabel.prefHeightProperty().bind(heightProperty());
displayTextLabel.prefHeightProperty().bind(heightProperty());
displayTextLabel.prefWidthProperty().bind(widthProperty());
displayTextLabel.prefWidthProperty().bind(widthProperty());
getChildren().addAll(displayTextLabel);
getChildren().addAll(displayTextLabel);
setMinSize(size, size);
setMinSize(size, size);
setMaxSize(size, size);
setMaxSize(size, size);
getStyleClass().add("action_box");
getStyleClass().add("action_box");
setIcon(null);
setIcon(null);
getStyleClass().add("action_box_valid");
getStyleClass().add("action_box_valid");
setOnDragOver(dragEvent ->
setOnDragOver(dragEvent ->
{
{
if(dragEvent.getDragboard().hasContent(ActionDataFormats.ACTION_TYPE))
if(dragEvent.getDragboard().hasContent(ActionDataFormats.ACTION_TYPE))
{
{
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.acceptTransferModes(TransferMode.ANY);
dragEvent.consume();
dragEvent.consume();
}
}
});
});
setOnDragDropped(dragEvent ->
setOnDragDropped(dragEvent ->
{
{
try
try
{
{
if(action == null)
if(action == null)
{
{
Dragboard db = dragEvent.getDragboard();
Dragboard db = dragEvent.getDragboard();
ActionType actionType = (ActionType) db.getContent(ActionDataFormats.ACTION_TYPE);
ActionType actionType = (ActionType) db.getContent(ActionDataFormats.ACTION_TYPE);
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
if(actionType == ActionType.NORMAL || actionType == ActionType.TOGGLE)
{
{
String moduleName = (String) dragEvent.getDragboard().getContent(ActionDataFormats.MODULE_NAME);
String moduleName = (String) dragEvent.getDragboard().getContent(ActionDataFormats.MODULE_NAME);
ExternalPlugin newAction = actionGridPaneListener.createNewActionFromExternalPlugin(moduleName);
ExternalPlugin newAction = actionGridPaneListener.createNewActionFromExternalPlugin(moduleName);
boolean isNew = (boolean) db.getContent(ActionDataFormats.IS_NEW);
boolean isNew = (boolean) db.getContent(ActionDataFormats.IS_NEW);
if(isNew)
if(isNew)
{
{
newAction.getClientProperties().resetToDefaults();
newAction.getClientProperties().resetToDefaults();
newAction.setDisplayText(newAction.getName());
newAction.setDisplayText(newAction.getName());
if(newAction.getActionType() == ActionType.TOGGLE)
if(newAction.getActionType() == ActionType.TOGGLE)
{
{
newAction.setShowDisplayText(false);
newAction.setShowDisplayText(false);
newAction.setDisplayTextAlignment(DisplayTextAlignment.BOTTOM);
newAction.setDisplayTextAlignment(DisplayTextAlignment.BOTTOM);
}
}
else
else
{
{
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
newAction.setDisplayTextAlignment(DisplayTextAlignment.CENTER);
}
}
if(actionType == ActionType.TOGGLE)
if(actionType == ActionType.TOGGLE)
newAction.setCurrentIconState("false__false");
newAction.setCurrentIconState("false__false");
}
}
else
else
{
{
newAction.setClientProperties((ClientProperties) db.getContent(ActionDataFormats.CLIENT_PROPERTIES));
newAction.setClientProperties((ClientProperties) db.getContent(ActionDataFormats.CLIENT_PROPERTIES));
newAction.setIcons((HashMap<String, byte[]>) db.getContent(ActionDataFormats.ICONS));
newAction.setIcons((HashMap<String, byte[]>) db.getContent(ActionDataFormats.ICONS));
newAction.setCurrentIconState((String) db.getContent(ActionDataFormats.CURRENT_ICON_STATE));
newAction.setCurrentIconState((String) db.getContent(ActionDataFormats.CURRENT_ICON_STATE));
newAction.setBgColourHex((String) db.getContent(ActionDataFormats.BACKGROUND_COLOUR));
newAction.setBgColourHex((String) db.getContent(ActionDataFormats.BACKGROUND_COLOUR));
newAction.setDisplayTextFontColourHex((String) db.getContent(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR));
newAction.setDisplayTextFontColourHex((String) db.getContent(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR));
newAction.setDisplayText((String) db.getContent(ActionDataFormats.DISPLAY_TEXT));
newAction.setDisplayText((String) db.getContent(ActionDataFormats.DISPLAY_TEXT));
newAction.setDisplayTextAlignment((DisplayTextAlignment) db.getContent(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT));
newAction.setDisplayTextAlignment((DisplayTextAlignment) db.getContent(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT));
newAction.setShowDisplayText((boolean) db.getContent(ActionDataFormats.DISPLAY_TEXT_SHOW));
newAction.setShowDisplayText((boolean) db.getContent(ActionDataFormats.DISPLAY_TEXT_SHOW));
}
}
newAction.setLocation(new Location(getRow(),
newAction.setLocation(new Location(getRow(),
getCol()));
getCol()));
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
try
try
{
{
newAction.onActionCreate();
newAction.onActionCreate();
}
}
catch (Exception e)
catch (Exception e)
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onCreate() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onCreate() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
}
}
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
setAction(newAction);
setAction(newAction);
init();
init();
actionDetailsPaneListener.onActionClicked(newAction, this);
actionDetailsPaneListener.onActionClicked(newAction, this);
if(newAction.isHasIcon())
if(newAction.isHasIcon())
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.saveAction(true, false);
actionDetailsPaneListener.saveAction(true, false);
}
}
else
else
{
{
Action newAction = actionGridPaneListener.createNewOtherAction(actionType);
Action newAction = actionGridPaneListener.createNewOtherAction(actionType);
newAction.setLocation(new Location(getRow(),
newAction.setLocation(new Location(getRow(),
getCol()));
getCol()));
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setParent(actionGridPaneListener.getCurrentParent());
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setProfileID(actionGridPaneListener.getCurrentProfile().getID());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
newAction.setSocketAddressForClient(actionGridPaneListener.getClientConnection().getRemoteSocketAddress());
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
actionGridPaneListener.addActionToCurrentClientProfile(newAction);
setAction(newAction);
setAction(newAction);
init();
init();
actionDetailsPaneListener.onActionClicked(newAction, this);
actionDetailsPaneListener.onActionClicked(newAction, this);
if(newAction.isHasIcon())
if(newAction.isHasIcon())
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.setSendIcon(true);
actionDetailsPaneListener.saveAction(true, false);
actionDetailsPaneListener.saveAction(true, false);
}
}
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
setOnDragDetected(mouseEvent -> {
setOnDragDetected(mouseEvent -> {
if(getAction()!=null)
if(getAction()!=null)
{
{
if(getAction().getActionType() == ActionType.NORMAL ||
if(getAction().getActionType() == ActionType.NORMAL ||
getAction().getActionType() == ActionType.TOGGLE)
getAction().getActionType() == ActionType.TOGGLE)
{
{
Dragboard db = startDragAndDrop(TransferMode.ANY);
Dragboard db = startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
ClipboardContent content = new ClipboardContent();
content.put(ActionDataFormats.CLIENT_PROPERTIES, getAction().getClientProperties());
content.put(ActionDataFormats.CLIENT_PROPERTIES, getAction().getClientProperties());
content.put(ActionDataFormats.ICONS, getAction().getIcons());
content.put(ActionDataFormats.ICONS, getAction().getIcons());
content.put(ActionDataFormats.CURRENT_ICON_STATE, getAction().getCurrentIconState());
content.put(ActionDataFormats.CURRENT_ICON_STATE, getAction().getCurrentIconState());
content.put(ActionDataFormats.BACKGROUND_COLOUR, getAction().getBgColourHex());
content.put(ActionDataFormats.BACKGROUND_COLOUR, getAction().getBgColourHex());
content.put(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR, getAction().getDisplayTextFontColourHex());
content.put(ActionDataFormats.DISPLAY_TEXT_FONT_COLOUR, getAction().getDisplayTextFontColourHex());
content.put(ActionDataFormats.DISPLAY_TEXT, getAction().getDisplayText());
content.put(ActionDataFormats.DISPLAY_TEXT, getAction().getDisplayText());
content.put(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT, getAction().getDisplayTextAlignment());
content.put(ActionDataFormats.DISPLAY_TEXT_ALIGNMENT, getAction().getDisplayTextAlignment());
content.put(ActionDataFormats.DISPLAY_TEXT_SHOW, getAction().isShowDisplayText());
content.put(ActionDataFormats.DISPLAY_TEXT_SHOW, getAction().isShowDisplayText());
content.put(ActionDataFormats.IS_NEW, false);
content.put(ActionDataFormats.IS_NEW, false);
content.put(ActionDataFormats.ACTION_TYPE, getAction().getActionType());
content.put(ActionDataFormats.ACTION_TYPE, getAction().getActionType());
content.put(ActionDataFormats.MODULE_NAME, getAction().getModuleName());
content.put(ActionDataFormats.MODULE_NAME, getAction().getModuleName());
db.setContent(content);
db.setContent(content);
mouseEvent.consume();
mouseEvent.consume();
}
}
}
}
});
});
setOnMouseClicked(mouseEvent -> {
setOnMouseClicked(mouseEvent -> {
if(action != null)
if(action != null)
{
{
if(mouseEvent.getClickCount() == 2 && getAction().getActionType() == ActionType.FOLDER)
if(mouseEvent.getClickCount() == 2 && getAction().getActionType() == ActionType.FOLDER)
{
{
getActionDetailsPaneListener().onOpenFolderButtonClicked();
getActionDetailsPaneListener().onOpenFolderButtonClicked();
}
}
else
else
{
{
try
try
{
{
actionDetailsPaneListener.onActionClicked(action, this);
actionDetailsPaneListener.onActionClicked(action, this);
if(mouseEvent.getButton().equals(MouseButton.SECONDARY))
if(mouseEvent.getButton().equals(MouseButton.SECONDARY))
{
{
actionContextMenu.show(this, mouseEvent.getScreenX(),
actionContextMenu.show(this, mouseEvent.getScreenX(),
mouseEvent.getScreenY());
mouseEvent.getScreenY());
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
});
});
actionContextMenu = new ContextMenu();
actionContextMenu = new ContextMenu();
MenuItem deleteActionMenuItem = new MenuItem("Delete Action");
MenuItem deleteActionMenuItem = new MenuItem("Delete Action");
deleteActionMenuItem.getStyleClass().add("action_box_delete_menu_item");
deleteActionMenuItem.getStyleClass().add("action_box_delete_menu_item");
FontIcon deleteIcon = new FontIcon("fas-trash");
FontIcon deleteIcon = new FontIcon("fas-trash");
deleteIcon.getStyleClass().add("action_box_delete_menu_item_icon");
deleteIcon.getStyleClass().add("action_box_delete_menu_item_icon");
deleteActionMenuItem.setGraphic(deleteIcon);
deleteActionMenuItem.setGraphic(deleteIcon);
deleteActionMenuItem.setOnAction(event-> deleteAction());
deleteActionMenuItem.setOnAction(event-> deleteAction());
showToggleOffMenuItem = new MenuItem("Show Toggle OFF");
showToggleOffMenuItem = new MenuItem("Show Toggle OFF");
showToggleOffMenuItem.getStyleClass().add("action_box_toggle_off_menu_item");
showToggleOffMenuItem.getStyleClass().add("action_box_toggle_off_menu_item");
FontIcon toggleOffIcon = new FontIcon("fas-toggle-off");
FontIcon toggleOffIcon = new FontIcon("fas-toggle-off");
toggleOffIcon.getStyleClass().add("action_box_toggle_off_menu_item_icon");
toggleOffIcon.getStyleClass().add("action_box_toggle_off_menu_item_icon");
showToggleOffMenuItem.setGraphic(toggleOffIcon);
showToggleOffMenuItem.setGraphic(toggleOffIcon);
showToggleOffMenuItem.setOnAction(event-> fakeToggle(false));
showToggleOffMenuItem.setOnAction(event-> fakeToggle(false));
showToggleOnMenuItem = new MenuItem("Show Toggle ON");
showToggleOnMenuItem = new MenuItem("Show Toggle ON");
showToggleOnMenuItem.getStyleClass().add("action_box_toggle_on_menu_item");
showToggleOnMenuItem.getStyleClass().add("action_box_toggle_on_menu_item");
FontIcon toggleOnIcon = new FontIcon("fas-toggle-on");
FontIcon toggleOnIcon = new FontIcon("fas-toggle-on");
toggleOnIcon.getStyleClass().add("action_box_toggle_on_menu_item_icon");
toggleOnIcon.getStyleClass().add("action_box_toggle_on_menu_item_icon");
showToggleOnMenuItem.setGraphic(toggleOnIcon);
showToggleOnMenuItem.setGraphic(toggleOnIcon);
showToggleOnMenuItem.setOnAction(event-> fakeToggle(true));
showToggleOnMenuItem.setOnAction(event-> fakeToggle(true));
actionContextMenu.getItems().addAll(deleteActionMenuItem, showToggleOffMenuItem, showToggleOnMenuItem);
actionContextMenu.getItems().addAll(deleteActionMenuItem, showToggleOffMenuItem, showToggleOnMenuItem);
setCache(true);
setCache(true);
setCacheHint(CacheHint.QUALITY);
setCacheHint(CacheHint.QUALITY);
}
}
private MenuItem showToggleOffMenuItem;
private MenuItem showToggleOffMenuItem;
private MenuItem showToggleOnMenuItem;
private MenuItem showToggleOnMenuItem;
private void deleteAction()
private void deleteAction()
{
{
actionDetailsPaneListener.onDeleteButtonClicked();
actionDetailsPaneListener.onDeleteButtonClicked();
}
}
ContextMenu actionContextMenu;
ContextMenu actionContextMenu;
public void setInvalid(boolean invalid)
public void setInvalid(boolean invalid)
{
{
if(invalid)
if(invalid)
{
{
getStyleClass().remove("action_box_valid");
getStyleClass().remove("action_box_valid");
getStyleClass().add("action_box_invalid");
getStyleClass().add("action_box_invalid");
}
}
else
else
{
{
getStyleClass().remove("action_box_invalid");
getStyleClass().remove("action_box_invalid");
getStyleClass().add("action_box_valid");
getStyleClass().add("action_box_valid");
}
}
}
}
public ActionDetailsPaneListener getActionDetailsPaneListener() {
public ActionDetailsPaneListener getActionDetailsPaneListener() {
return actionDetailsPaneListener;
return actionDetailsPaneListener;
}
}
public ActionGridPaneListener getActionGridPaneListener() {
public ActionGridPaneListener getActionGridPaneListener() {
return actionGridPaneListener;
return actionGridPaneListener;
}
}
private int size;
private int size;
private ActionGridPaneListener actionGridPaneListener;
private ActionGridPaneListener actionGridPaneListener;
public ActionBox(int size, ActionDetailsPaneListener actionDetailsPaneListener, ActionGridPaneListener actionGridPaneListener,
public ActionBox(int size, ActionDetailsPaneListener actionDetailsPaneListener, ActionGridPaneListener actionGridPaneListener,
int col, int row)
int col, int row)
{
{
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.size = size;
this.size = size;
this.col = col;
this.col = col;
this.row = row;
this.row = row;
baseInit();
baseInit();
}
}
public void setIcon(byte[] iconByteArray)
public void setIcon(byte[] iconByteArray)
{
{
removeFontIcon();
removeFontIcon();
if(iconByteArray == null)
if(iconByteArray == null)
{
{
getStyleClass().remove("action_box_icon_present");
getStyleClass().remove("action_box_icon_present");
getStyleClass().add("action_box_icon_not_present");
getStyleClass().add("action_box_icon_not_present");
setBackground(null);
setBackground(null);
}
}
else
else
{
{
getStyleClass().add("action_box_icon_present");
getStyleClass().add("action_box_icon_present");
getStyleClass().remove("action_box_icon_not_present");
getStyleClass().remove("action_box_icon_not_present");
setBackground(
setBackground(
new Background(
new Background(
new BackgroundImage(new Image(
new BackgroundImage(new Image(
new ByteArrayInputStream(iconByteArray), size, size, false, true
new ByteArrayInputStream(iconByteArray), size, size, false, true
), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
), BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,
new BackgroundSize(100, 100, true, true, true, false))
new BackgroundSize(100, 100, true, true, true, false))
)
)
);
);
}
}
}
}
public void setDefaultToggleIcon(boolean isToggleOn)
public void setDefaultToggleIcon(boolean isToggleOn)
{
{
String styleClass;
String styleClass;
if(isToggleOn)
if(isToggleOn)
{
{
styleClass = "action_box_toggle_on";
styleClass = "action_box_toggle_on";
}
}
else
else
{
{
styleClass = "action_box_toggle_off";
styleClass = "action_box_toggle_off";
}
}
setBackground(null);
setBackground(null);
if(fontIcon!=null)
if(fontIcon!=null)
{
{
fontIcon.getStyleClass().removeIf(s -> s.equals("action_box_toggle_off") || s.equals("action_box_toggle_on"));
fontIcon.getStyleClass().removeIf(s -> s.equals("action_box_toggle_off") || s.equals("action_box_toggle_on"));
}
}
else
else
{
{
fontIcon = new FontIcon();
fontIcon = new FontIcon();
fontIcon.setIconSize((int) (size * 0.8));
fontIcon.setIconSize((int) (size * 0.8));
getChildren().add(fontIcon);
getChildren().add(fontIcon);
}
}
fontIcon.getStyleClass().add(styleClass);
fontIcon.getStyleClass().add(styleClass);
fontIcon.toBack();
fontIcon.toBack();
}
}
public void removeFontIcon()
public void removeFontIcon()
{
{
if(fontIcon!=null)
if(fontIcon!=null)
{
{
getChildren().remove(fontIcon);
getChildren().remove(fontIcon);
fontIcon = null;
fontIcon = null;
}
}
}
}
FontIcon fontIcon = null;
FontIcon fontIcon = null;
private Action action = null;
private Action action = null;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
public ActionBox(int size, Action action, ActionDetailsPaneListener actionDetailsPaneListener, ExceptionAndAlertHandler exceptionAndAlertHandler, ActionGridPaneListener actionGridPaneListener,
public ActionBox(int size, Action action, ActionDetailsPaneListener actionDetailsPaneListener, ExceptionAndAlertHandler exceptionAndAlertHandler, ActionGridPaneListener actionGridPaneListener,
int col, int row)
int col, int row)
{
{
this.actionGridPaneListener = actionGridPaneListener;
this.actionGridPaneListener = actionGridPaneListener;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.action = action;
this.action = action;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.actionDetailsPaneListener = actionDetailsPaneListener;
this.size = size;
this.size = size;
this.col = col;
this.col = col;
this.row = row;
this.row = row;
baseInit();
baseInit();
init();
init();
}
}
public Action getAction() {
public Action getAction() {
return action;
return action;
}
}
public void setAction(Action action)
public void setAction(Action action)
{
{
this.action = action;
this.action = action;
}
}
public void init()
public void init()
{
{
init(false);
init(false);
}
}
public void init(boolean start)
public void init(boolean start)
{
{
setBackground(null);
setBackground(null);
setStyle(null);
setStyle(null);
showToggleOffMenuItem.setVisible(getAction().getActionType() == ActionType.TOGGLE);
showToggleOffMenuItem.setVisible(getAction().getActionType() == ActionType.TOGGLE);
showToggleOnMenuItem.setVisible(getAction().getActionType() == ActionType.TOGGLE);
showToggleOnMenuItem.setVisible(getAction().getActionType() == ActionType.TOGGLE);
if(getAction().isShowDisplayText())
if(getAction().isShowDisplayText())
setDisplayTextLabel(getAction().getDisplayText());
setDisplayTextLabel(getAction().getDisplayText());
else
else
setDisplayTextLabel("");
setDisplayTextLabel("");
setDisplayTextAlignment(action.getDisplayTextAlignment());
setDisplayTextAlignment(action.getDisplayTextAlignment());
setBackgroundColour(action.getBgColourHex());
setBackgroundColour(action.getBgColourHex());
setDisplayTextFontColour(action.getDisplayTextFontColourHex());
setDisplayTextFontColour(action.getDisplayTextFontColourHex());
setInvalid(action.isInvalid());
setInvalid(action.isInvalid());
Platform.runLater(()->{
Platform.runLater(()->{
try {
try {
if(action.getActionType() == ActionType.TOGGLE)
if(action.getActionType() == ActionType.TOGGLE)
{
{
fakeToggle(start);
fakeToggle(start);
}
}
else
else
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
if(!action.getCurrentIconState().isBlank())
if(!action.getCurrentIconState().isBlank())
{
{
setIcon(action.getCurrentIcon());
setIcon(action.getCurrentIcon());
}
}
}
}
else
else
{
{
setIcon(null);
setIcon(null);
}
}
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
});
});
}
}
public void fakeToggle(boolean isON)
public void fakeToggle(boolean isON)
{
{
String[] toggleStatesHiddenStatus = action.getCurrentIconState().split("__");
String[] toggleStatesHiddenStatus = action.getCurrentIconState().split("__");
boolean isToggleOffHidden = toggleStatesHiddenStatus[0].equals("true");
boolean isToggleOffHidden = toggleStatesHiddenStatus[0].equals("true");
boolean isToggleOnHidden = toggleStatesHiddenStatus[1].equals("true");
boolean isToggleOnHidden = toggleStatesHiddenStatus[1].equals("true");
if(isON) // ON
if(isON) // ON
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
boolean isToggleOnPresent = action.getIcons().containsKey("toggle_on");
boolean isToggleOnPresent = action.getIcons().containsKey("toggle_on");
if(isToggleOnPresent)
if(isToggleOnPresent)
{
{
if(isToggleOnHidden)
if(isToggleOnHidden)
{
{
setDefaultToggleIcon(true);
setDefaultToggleIcon(true);
}
}
else
else
{
{
setIcon(action.getIcons().get("toggle_on"));
setIcon(action.getIcons().get("toggle_on"));
}
}
}
}
else
else
{
{
setDefaultToggleIcon(true);
setDefaultToggleIcon(true);
}
}
}
}
else
else
{
{
setDefaultToggleIcon(true);
setDefaultToggleIcon(true);
}
}
}
}
else // OFF
else // OFF
{
{
if(action.isHasIcon())
if(action.isHasIcon())
{
{
boolean isToggleOffPresent = action.getIcons().containsKey("toggle_off");
boolean isToggleOffPresent = action.getIcons().containsKey("toggle_off");
if(isToggleOffPresent)
if(isToggleOffPresent)
{
{
if(isToggleOffHidden)
if(isToggleOffHidden)
{
{
setDefaultToggleIcon(false);
setDefaultToggleIcon(false);
}
}
else
else
{
{
setIcon(action.getIcons().get("toggle_off"));
setIcon(action.getIcons().get("toggle_off"));
}
}
}
}
else
else
{
{
setDefaultToggleIcon(false);
setDefaultToggleIcon(false);
}
}
}
}
else
else
{
{
setDefaultToggleIcon(false);
setDefaultToggleIcon(false);
}
}
}
}
}
}
public void setDisplayTextLabel(String text)
public void setDisplayTextLabel(String text)
{
{
displayTextLabel.setText(text);
displayTextLabel.setText(text);
}
}
public void setDisplayTextAlignment(DisplayTextAlignment displayTextAlignment)
public void setDisplayTextAlignment(DisplayTextAlignment displayTextAlignment)
{
{
if(displayTextAlignment == DisplayTextAlignment.CENTER)
if(displayTextAlignment == DisplayTextAlignment.CENTER)
displayTextLabel.setAlignment(Pos.CENTER);
displayTextLabel.setAlignment(Pos.CENTER);
else if (displayTextAlignment == DisplayTextAlignment.BOTTOM)
else if (displayTextAlignment == DisplayTextAlignment.BOTTOM)
displayTextLabel.setAlignment(Pos.BOTTOM_CENTER);
displayTextLabel.setAlignment(Pos.BOTTOM_CENTER);
else if (displayTextAlignment == DisplayTextAlignment.TOP)
else if (displayTextAlignment == DisplayTextAlignment.TOP)
displayTextLabel.setAlignment(Pos.TOP_CENTER);
displayTextLabel.setAlignment(Pos.TOP_CENTER);
}
}
public void setDisplayTextFontColour(String colour)
public void setDisplayTextFontColour(String colour)
{
{
if(!colour.isEmpty())
if(!colour.isEmpty())
displayTextLabel.setStyle("-fx-text-fill : "+colour+";");
displayTextLabel.setStyle("-fx-text-fill : "+colour+";");
}
}
public void setBackgroundColour(String colour)
public void setBackgroundColour(String colour)
{
{
if(!colour.isEmpty())
if(!colour.isEmpty())
setStyle("-fx-background-color : "+colour);
setStyle("-fx-background-color : "+colour);
}
}
public void setSelected(boolean status)
public void setSelected(boolean status)
{
{
if(status)
if(status)
{
{
getStyleClass().add("action_box_selected");
getStyleClass().add("action_box_selected");
}
}
else
else
{
{
getStyleClass().remove("action_box_selected");
getStyleClass().remove("action_box_selected");
}
}
}
}
}
}
package com.stream_pi.server.window.settings;
package com.stream_pi.server.window.settings;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.action_api.actionproperty.property.FileExtensionFilter;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.controller.ServerListener;
import com.stream_pi.server.info.StartupFlags;
import com.stream_pi.server.info.StartupFlags;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.io.Config;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.server.info.ServerInfo;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.StreamPiAlert;
import com.stream_pi.util.alert.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.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.CheckForUpdates;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
import com.stream_pi.util.checkforupdates.UpdateHyperlinkOnClick;
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.platform.PlatformType;
import com.stream_pi.util.platform.PlatformType;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.startatboot.StartAtBoot;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBox;
import com.stream_pi.util.uihelper.HBoxInputBoxWithDirectoryChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithDirectoryChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxInputBoxWithFileChooser;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import com.stream_pi.util.uihelper.HBoxWithSpaceBetween;
import javafx.application.HostServices;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.*;
import javafx.scene.layout.*;
import javafx.stage.DirectoryChooser;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import org.controlsfx.control.ToggleSwitch;
import org.controlsfx.control.ToggleSwitch;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import org.w3c.dom.Text;
import org.w3c.dom.Text;
import java.awt.SystemTray;
import java.awt.SystemTray;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
public class GeneralSettings extends VBox {
public class GeneralSettings extends VBox {
private final TextField serverNameTextField;
private final TextField serverNameTextField;
private final TextField portTextField;
private final TextField portTextField;
private final TextField pluginsPathTextField;
private final TextField pluginsPathTextField;
private final TextField themesPathTextField;
private final TextField themesPathTextField;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxSize;
private final TextField actionGridPaneActionBoxGap;
private final TextField actionGridPaneActionBoxGap;
private final ToggleSwitch startOnBootToggleSwitch;
private final ToggleSwitch startOnBootToggleSwitch;
private final HBoxWithSpaceBetween startOnBootHBox;
private final HBoxWithSpaceBetween startOnBootHBox;
private final TextField soundOnActionClickedFilePathTextField;
private final TextField soundOnActionClickedFilePathTextField;
private final ToggleSwitch soundOnActionClickedToggleSwitch;
private final ToggleSwitch soundOnActionClickedToggleSwitch;
private final HBoxWithSpaceBetween soundOnActionClickedToggleSwitchHBox;
private final HBoxWithSpaceBetween soundOnActionClickedToggleSwitchHBox;
private final ToggleSwitch minimizeToSystemTrayOnCloseToggleSwitch;
private final ToggleSwitch minimizeToSystemTrayOnCloseToggleSwitch;
private final HBoxWithSpaceBetween minimizeToSystemTrayOnCloseHBox;
private final HBoxWithSpaceBetween minimizeToSystemTrayOnCloseHBox;
private final ToggleSwitch showAlertsPopupToggleSwitch;
private final ToggleSwitch showAlertsPopupToggleSwitch;
private final HBoxWithSpaceBetween showAlertsPopupHBox;
private final HBoxWithSpaceBetween showAlertsPopupHBox;
private final Button saveButton;
private final Button saveButton;
private final Button checkForUpdatesButton;
private final Button checkForUpdatesButton;
private final Button factoryResetButton;
private final Button factoryResetButton;
private Logger logger;
private Logger logger;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ServerListener serverListener;
private ServerListener serverListener;
private HostServices hostServices;
private HostServices hostServices;
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
public GeneralSettings(ExceptionAndAlertHandler exceptionAndAlertHandler, ServerListener serverListener, HostServices hostServices)
{
{
this.hostServices = hostServices;
this.hostServices = hostServices;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.serverListener = serverListener;
this.serverListener = serverListener;
logger = Logger.getLogger(GeneralSettings.class.getName());
logger = Logger.getLogger(GeneralSettings.class.getName());
serverNameTextField = new TextField();
serverNameTextField = new TextField();
portTextField = new TextField();
portTextField = new TextField();
pluginsPathTextField = new TextField();
pluginsPathTextField = new TextField();
themesPathTextField = new TextField();
themesPathTextField = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxSize = new TextField();
actionGridPaneActionBoxGap = new TextField();
actionGridPaneActionBoxGap = new TextField();
startOnBootToggleSwitch = new ToggleSwitch();
startOnBootToggleSwitch = new ToggleSwitch();
startOnBootHBox = new HBoxWithSpaceBetween("Start on Boot", startOnBootToggleSwitch);
startOnBootHBox = new HBoxWithSpaceBetween("Start on Boot", startOnBootToggleSwitch);
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());
startOnBootHBox.managedProperty().bind(startOnBootHBox.visibleProperty());
soundOnActionClickedToggleSwitch = new ToggleSwitch();
soundOnActionClickedToggleSwitch = new ToggleSwitch();
soundOnActionClickedToggleSwitchHBox = new HBoxWithSpaceBetween("Sound on Action Clicked", soundOnActionClickedToggleSwitch);
soundOnActionClickedToggleSwitchHBox = new HBoxWithSpaceBetween("Sound on Action Clicked", soundOnActionClickedToggleSwitch);
soundOnActionClickedFilePathTextField = new TextField();
soundOnActionClickedFilePathTextField = new TextField();
HBoxInputBoxWithFileChooser soundHBoxInputBoxWithFileChooser = new HBoxInputBoxWithFileChooser("Sound File Path", soundOnActionClickedFilePathTextField,
HBoxInputBoxWithFileChooser soundHBoxInputBoxWithFileChooser = new HBoxInputBoxWithFileChooser("Sound File Path", soundOnActionClickedFilePathTextField,
new FileChooser.ExtensionFilter("Sounds","*.mp3","*.mp4", "*.m4a", "*.m4v","*.wav","*.aif", "*.aiff","*.fxm","*.flv","*.m3u8"));
new FileChooser.ExtensionFilter("Sounds","*.mp3","*.mp4", "*.m4a", "*.m4v","*.wav","*.aif", "*.aiff","*.fxm","*.flv","*.m3u8"));
soundHBoxInputBoxWithFileChooser.setUseLast(false);
soundHBoxInputBoxWithFileChooser.setUseLast(false);
soundHBoxInputBoxWithFileChooser.setRememberThis(false);
soundHBoxInputBoxWithFileChooser.setRememberThis(false);
soundHBoxInputBoxWithFileChooser.getFileChooseButton().disableProperty().bind(soundOnActionClickedToggleSwitch.selectedProperty().not());
soundHBoxInputBoxWithFileChooser.getFileChooseButton().disableProperty().bind(soundOnActionClickedToggleSwitch.selectedProperty().not());
minimizeToSystemTrayOnCloseToggleSwitch = new ToggleSwitch();
minimizeToSystemTrayOnCloseToggleSwitch = new ToggleSwitch();
minimizeToSystemTrayOnCloseHBox = new HBoxWithSpaceBetween("Minimise To Tray On Close", minimizeToSystemTrayOnCloseToggleSwitch);
minimizeToSystemTrayOnCloseHBox = new HBoxWithSpaceBetween("Minimise To Tray On Close", minimizeToSystemTrayOnCloseToggleSwitch);
showAlertsPopupToggleSwitch = new ToggleSwitch();
showAlertsPopupToggleSwitch = new ToggleSwitch();
showAlertsPopupHBox = new HBoxWithSpaceBetween("Show Popup On Alert", showAlertsPopupToggleSwitch);
showAlertsPopupHBox = new HBoxWithSpaceBetween("Show Popup On Alert", showAlertsPopupToggleSwitch);
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton = new Button("Check for updates");
checkForUpdatesButton.setOnAction(event->checkForUpdates());
checkForUpdatesButton.setOnAction(event->checkForUpdates());
factoryResetButton = new Button("Factory Reset");
factoryResetButton = new Button("Factory Reset");
factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
factoryResetButton.setOnAction(actionEvent -> onFactoryResetButtonClicked());
getStyleClass().add("general_settings");
getStyleClass().add("general_settings");
prefWidthProperty().bind(widthProperty());
prefWidthProperty().bind(widthProperty());
setAlignment(Pos.CENTER);
setAlignment(Pos.CENTER);
setSpacing(5);
setSpacing(5);
getChildren().addAll(
getChildren().addAll(
new HBoxInputBox("Server Name", serverNameTextField),
new HBoxInputBox("Server Name", serverNameTextField),
new HBoxInputBox("Port", portTextField),
new HBoxInputBox("Port", portTextField),
new HBoxInputBox("Grid Pane - Box Size", actionGridPaneActionBoxSize),
new HBoxInputBox("Grid Pane - Box Size", actionGridPaneActionBoxSize),
new HBoxInputBox("Grid Pane - Box Gap", actionGridPaneActionBoxGap),
new HBoxInputBox("Grid Pane - Box Gap", actionGridPaneActionBoxGap),
new HBoxInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
new HBoxInputBoxWithDirectoryChooser("Plugins Path", pluginsPathTextField),
new HBoxInputBoxWithDirectoryChooser("Themes Path", themesPathTextField),
new HBoxInputBoxWithDirectoryChooser("Themes Path", themesPathTextField),
soundHBoxInputBoxWithFileChooser,
soundHBoxInputBoxWithFileChooser,
soundOnActionClickedToggleSwitchHBox,
soundOnActionClickedToggleSwitchHBox,
minimizeToSystemTrayOnCloseHBox,
minimizeToSystemTrayOnCloseHBox,
startOnBootHBox,
startOnBootHBox,
showAlertsPopupHBox
showAlertsPopupHBox
);
);
serverNameTextField.setPrefWidth(200);
serverNameTextField.setPrefWidth(200);
saveButton = new Button("Save");
saveButton = new Button("Save");
saveButton.setOnAction(event->save());
saveButton.setOnAction(event->save());
getChildren().addAll(factoryResetButton, checkForUpdatesButton, saveButton);
getChildren().addAll(factoryResetButton, checkForUpdatesButton, saveButton);
setPadding(new Insets(10));
setPadding(new Insets(10));
}
}
private void checkForUpdates()
private void checkForUpdates()
{
{
new CheckForUpdates(checkForUpdatesButton,
new CheckForUpdates(checkForUpdatesButton,
PlatformType.SERVER, ServerInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
PlatformType.SERVER, ServerInfo.getInstance().getVersion(), new UpdateHyperlinkOnClick() {
@Override
@Override
public void handle(ActionEvent actionEvent) {
public void handle(ActionEvent actionEvent) {
hostServices.showDocument(getURL());
hostServices.showDocument(getURL());
}
}
});
});
}
}
public void loadDataFromConfig() throws SevereException {
public void loadDataFromConfig() throws SevereException {
Config config = Config.getInstance();
Config config = Config.getInstance();
Platform.runLater(()->
Platform.runLater(()->
{
{
serverNameTextField.setText(config.getServerName());
serverNameTextField.setText(config.getServerName());
portTextField.setText(config.getPort()+"");
portTextField.setText(config.getPort()+"");
pluginsPathTextField.setText(config.getPluginsPath());
pluginsPathTextField.setText(config.getPluginsPath());
themesPathTextField.setText(config.getThemesPath());
themesPathTextField.setText(config.getThemesPath());
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxSize.setText(config.getActionGridActionSize()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
actionGridPaneActionBoxGap.setText(config.getActionGridActionGap()+"");
minimizeToSystemTrayOnCloseToggleSwitch.setSelected(config.getMinimiseToSystemTrayOnClose());
minimizeToSystemTrayOnCloseToggleSwitch.setSelected(config.getMinimiseToSystemTrayOnClose());
showAlertsPopupToggleSwitch.setSelected(config.isShowAlertsPopup());
showAlertsPopupToggleSwitch.setSelected(config.isShowAlertsPopup());
startOnBootToggleSwitch.setSelected(config.getStartOnBoot());
startOnBootToggleSwitch.setSelected(config.getStartOnBoot());
soundOnActionClickedToggleSwitch.setSelected(config.getSoundOnActionClickedStatus());
soundOnActionClickedToggleSwitch.setSelected(config.getSoundOnActionClickedStatus());
soundOnActionClickedFilePathTextField.setText(config.getSoundOnActionClickedFilePath());
soundOnActionClickedFilePathTextField.setText(config.getSoundOnActionClickedFilePath());
});
});
}
}
public void save()
public void save()
{
{
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
try {
try {
boolean toBeReloaded = false;
boolean toBeReloaded = false;
boolean dashToBeReRendered = false;
boolean dashToBeReRendered = false;
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(true);
saveButton.setDisable(true);
});
});
String serverNameStr = serverNameTextField.getText();
String serverNameStr = serverNameTextField.getText();
String serverPortStr = portTextField.getText();
String serverPortStr = portTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String pluginsPathStr = pluginsPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String themesPathStr = themesPathTextField.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxSize = actionGridPaneActionBoxSize.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
String actionGridActionBoxGap = actionGridPaneActionBoxGap.getText();
boolean minimizeToSystemTrayOnClose = minimizeToSystemTrayOnCloseToggleSwitch.isSelected();
boolean minimizeToSystemTrayOnClose = minimizeToSystemTrayOnCloseToggleSwitch.isSelected();
boolean showAlertsPopup = showAlertsPopupToggleSwitch.isSelected();
boolean showAlertsPopup = showAlertsPopupToggleSwitch.isSelected();
boolean startOnBoot = startOnBootToggleSwitch.isSelected();
boolean startOnBoot = startOnBootToggleSwitch.isSelected();
boolean soundOnActionClicked = soundOnActionClickedToggleSwitch.isSelected();
boolean soundOnActionClicked = soundOnActionClickedToggleSwitch.isSelected();
String soundOnActionClickedFilePath = soundOnActionClickedFilePathTextField.getText();
String soundOnActionClickedFilePath = soundOnActionClickedFilePathTextField.getText();
Config config = Config.getInstance();
Config config = Config.getInstance();
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
if(serverNameStr.isBlank())
if(serverNameStr.isBlank())
{
{
errors.append("* Server Name cannot be blank.\n");
errors.append("* Server Name cannot be blank.\n");
}
}
else
else
{
{
if(!config.getServerName().equals(serverNameStr))
if(!config.getServerName().equals(serverNameStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
int serverPort=-1;
int serverPort=-1;
try {
try {
serverPort = Integer.parseInt(serverPortStr);
serverPort = Integer.parseInt(serverPortStr);
if (serverPort < 1024)
if (serverPort < 1024)
errors.append("* Server Port must be more than 1024\n");
errors.append("* Server Port must be more than 1024\n");
else if(serverPort > 65535)
else if(serverPort > 65535)
errors.append("* Server Port must be lesser than 65535\n");
errors.append("* Server Port must be lesser than 65535\n");
if(config.getPort()!=serverPort)
if(config.getPort()!=serverPort)
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* Server Port must be integer.\n");
errors.append("* Server Port must be integer.\n");
}
}
int actionSize=-1;
int actionSize=-1;
try
try
{
{
actionSize = Integer.parseInt(actionGridActionBoxSize);
actionSize = Integer.parseInt(actionGridActionBoxSize);
if(config.getActionGridActionSize() != actionSize)
if(config.getActionGridActionSize() != actionSize)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Size must be integer.\n");
errors.append("* action Size must be integer.\n");
}
}
int actionGap=-1;
int actionGap=-1;
try
try
{
{
actionGap = Integer.parseInt(actionGridActionBoxGap);
actionGap = Integer.parseInt(actionGridActionBoxGap);
if(config.getActionGridActionGap() != actionGap)
if(config.getActionGridActionGap() != actionGap)
{
{
dashToBeReRendered = true;
dashToBeReRendered = true;
}
}
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
errors.append("* action Gap must be integer.\n");
errors.append("* action Gap must be integer.\n");
}
}
if(pluginsPathStr.isBlank())
if(pluginsPathStr.isBlank())
{
{
errors.append("* Plugins Path must not be blank.\n");
errors.append("* Plugins Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getPluginsPath().equals(pluginsPathStr))
if(!config.getPluginsPath().equals(pluginsPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(themesPathStr.isBlank())
if(themesPathStr.isBlank())
{
{
errors.append("* Themes Path must not be blank.\n");
errors.append("* Themes Path must not be blank.\n");
}
}
else
else
{
{
if(!config.getThemesPath().equals(themesPathStr))
if(!config.getThemesPath().equals(themesPathStr))
{
{
toBeReloaded = true;
toBeReloaded = true;
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
throw new MinorException("Uh Oh!", "Please rectify the following errors and try again :\n"+errors.toString());
throw new MinorException("Uh Oh!", "Please rectify the following errors and try again :\n"+ errors);
}
}
if(config.getStartOnBoot() != startOnBoot)
if(config.getStartOnBoot() != startOnBoot)
{
{
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.SERVER, ServerInfo.getInstance().getPlatform());
StartAtBoot startAtBoot = new StartAtBoot(PlatformType.SERVER, ServerInfo.getInstance().getPlatform());
if(startOnBoot)
if(startOnBoot)
{
{
try
try
{
{
startAtBoot.create(StartupFlags.RUNNER_FILE_NAME);
startAtBoot.create(StartupFlags.RUNNER_FILE_NAME);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
startOnBoot = false;
startOnBoot = false;
}
}
}
}
else
else
{
{
boolean result = startAtBoot.delete();
boolean result = startAtBoot.delete();
if(!result)
if(!result)
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
new StreamPiAlert("Uh Oh!", "Unable to delete starter file", StreamPiAlertType.ERROR).show();
}
}
}
}
if(minimizeToSystemTrayOnClose)
if(minimizeToSystemTrayOnClose)
{
{
if(!SystemTray.isSupported())
if(!SystemTray.isSupported())
{
{
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
StreamPiAlert alert = new StreamPiAlert("Not Supported", "Tray System not supported on this platform ", StreamPiAlertType.ERROR);
alert.show();
alert.show();
minimizeToSystemTrayOnClose = false;
minimizeToSystemTrayOnClose = false;
}
}
}
}
if(soundOnActionClicked)
if(soundOnActionClicked)
{
{
if(soundOnActionClickedFilePath.isBlank())
if(soundOnActionClickedFilePath.isBlank())
{
{
StreamPiAlert alert = new StreamPiAlert("No sound file specified",
StreamPiAlert alert = new StreamPiAlert("No sound file specified",
"Sound File cannot be empty", StreamPiAlertType.ERROR);
"Sound File cannot be empty", StreamPiAlertType.ERROR);
alert.show();
alert.show();
soundOnActionClicked = false;
soundOnActionClicked = false;
}
}
else
else
{
{
File soundFile = new File(soundOnActionClickedFilePath);
File soundFile = new File(soundOnActionClickedFilePath);
if(!soundFile.exists() || !soundFile.isFile())
if(!soundFile.exists() || !soundFile.isFile())
{
{
StreamPiAlert alert = new StreamPiAlert("File not found",
StreamPiAlert alert = new StreamPiAlert("File not found",
"No sound file at \n"+soundOnActionClickedFilePath+"\n" +
"No sound file at \n"+soundOnActionClickedFilePath+"\n" +
"Unable to set sound on action clicked.", StreamPiAlertType.ERROR);
"Unable to set sound on action clicked.", StreamPiAlertType.ERROR);
alert.show();
alert.show();
soundOnActionClicked = false;
soundOnActionClicked = false;
}
}
}
}
}
}
config.setServerName(serverNameStr);
config.setServerName(serverNameStr);
config.setServerPort(serverPort);
config.setServerPort(serverPort);
config.setActionGridGap(actionGap);
config.setActionGridGap(actionGap);
config.setActionGridSize(actionSize);
config.setActionGridSize(actionSize);
config.setPluginsPath(pluginsPathStr);
config.setPluginsPath(pluginsPathStr);
config.setThemesPath(themesPathStr);
config.setThemesPath(themesPathStr);
config.setMinimiseToSystemTrayOnClose(minimizeToSystemTrayOnClose);
config.setMinimiseToSystemTrayOnClose(minimizeToSystemTrayOnClose);
StreamPiAlert.setIsShowPopup(showAlertsPopup);
StreamPiAlert.setIsShowPopup(showAlertsPopup);
config.setShowAlertsPopup(showAlertsPopup);
config.setShowAlertsPopup(showAlertsPopup);
config.setStartupOnBoot(startOnBoot);
config.setStartupOnBoot(startOnBoot);
if(soundOnActionClicked)
if(soundOnActionClicked)
{
{
serverListener.initSoundOnActionClicked();
serverListener.initSoundOnActionClicked();
}
}
config.setSoundOnActionClickedStatus(soundOnActionClicked);
config.setSoundOnActionClickedStatus(soundOnActionClicked);
config.setSoundOnActionClickedFilePath(soundOnActionClickedFilePath);
config.setSoundOnActionClickedFilePath(soundOnActionClickedFilePath);
config.save();
config.save();
loadDataFromConfig();
loadDataFromConfig();
if(toBeReloaded)
if(toBeReloaded)
{
{
StreamPiAlert restartPrompt = new StreamPiAlert(
StreamPiAlert restartPrompt = new StreamPiAlert(
"Warning",
"Warning",
"Stream-Pi Server needs to be restarted for these changes to take effect. Restart?\n" +
"Stream-Pi Server needs to be restarted for these changes to take effect. Restart?\n" +
"All your current connections will be disconnected.",
"All your current connections will be disconnected.",
StreamPiAlertType.WARNING
StreamPiAlertType.WARNING
);
);
String yesOption = "Yes";
String yesOption = "Yes";
String noOption = "No";
String noOption = "No";
restartPrompt.setButtons(yesOption, noOption);
restartPrompt.setButtons(yesOption, noOption);
restartPrompt.setOnClicked(new StreamPiAlertListener() {
restartPrompt.setOnClicked(new StreamPiAlertListener() {
@Override
@Override
public void onClick(String s) {
public void onClick(String s) {
if(s.equals(yesOption))
if(s.equals(yesOption))
{
{
serverListener.restart();
serverListener.restart();
}
}
}
}
});
});
restartPrompt.show();
restartPrompt.show();
}
}
if(dashToBeReRendered)
if(dashToBeReRendered)
{
{
serverListener.clearTemp();
serverListener.clearTemp();
}
}
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
finally {
finally {
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(false);
saveButton.setDisable(false);
});
});
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
private void onFactoryResetButtonClicked()
private void onFactoryResetButtonClicked()
{
{
StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
StreamPiAlert confirmation = new StreamPiAlert("Warning","Are you sure?\n" +
"This will erase everything.",StreamPiAlertType.WARNING);
"This will erase everything.",StreamPiAlertType.WARNING);
String yesButton = "Yes";
String yesButton = "Yes";
String noButton = "No";
String noButton = "No";
confirmation.setButtons(yesButton, noButton);
confirmation.setButtons(yesButton, noButton);
confirmation.setOnClicked(new StreamPiAlertListener() {
confirmation.setOnClicked(new StreamPiAlertListener() {
@Override
@Override
public void onClick(String s) {
public void onClick(String s) {
if(s.equals(yesButton))
if(s.equals(yesButton))
{
{
serverListener.factoryReset();
serverListener.factoryReset();
}
}
}
}
});
});
confirmation.show();
confirmation.show();
}
}
}
}