client
Clone or download
Modified Files
package com.stream_pi.client.window.dashboard.actiongridpane;
package com.stream_pi.client.window.dashboard.actiongridpane;
import java.util.logging.Logger;
import java.util.logging.Logger;
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.Location;
import com.stream_pi.action_api.action.Location;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.controller.ClientListener;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.ClientInfo;
import com.stream_pi.client.info.StartupFlags;
import com.stream_pi.client.info.StartupFlags;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.io.Config;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.profile.ClientProfile;
import com.stream_pi.client.window.ExceptionAndAlertHandler;
import com.stream_pi.client.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 javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.CacheHint;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener
public class ActionGridPane extends ScrollPane implements ActionGridPaneListener
{
{
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ClientListener clientListener;
private ClientListener clientListener;
private ActionBox[][] actionBoxes;
private ActionBox[][] actionBoxes;
private GridPane actionsGridPane;
private GridPane actionsGridPane;
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ClientListener clientListener)
public ActionGridPane(ExceptionAndAlertHandler exceptionAndAlertHandler, ClientListener clientListener)
{
{
this.clientListener = clientListener;
this.clientListener = clientListener;
logger = Logger.getLogger(ActionGridPane.class.getName());
logger = Logger.getLogger(ActionGridPane.class.getName());
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
getStyleClass().add("action_grid_pane_parent");
getStyleClass().add("action_grid_pane_parent");
actionsGridPane = new GridPane();
actionsGridPane = new GridPane();
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.setPadding(new Insets(5.0));
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.getStyleClass().add("action_grid_pane");
actionsGridPane.prefWidthProperty().bind(widthProperty().subtract(20));
actionsGridPane.prefWidthProperty().bind(widthProperty().subtract(20));
actionsGridPane.prefHeightProperty().bind(heightProperty().subtract(20));
actionsGridPane.prefHeightProperty().bind(heightProperty().subtract(20));
setContent(actionsGridPane);
setContent(actionsGridPane);
actionsGridPane.setAlignment(Pos.CENTER);
actionsGridPane.setAlignment(Pos.CENTER);
VBox.setVgrow(this, Priority.ALWAYS);
VBox.setVgrow(this, Priority.ALWAYS);
setCache(true);
setCache(true);
setCacheHint(CacheHint.SPEED);
setCacheHint(CacheHint.SPEED);
}
}
private String currentParent;
private String currentParent;
public void setCurrentParent(String currentParent) {
public void setCurrentParent(String currentParent) {
this.currentParent = currentParent;
this.currentParent = currentParent;
}
}
public ClientProfile getClientProfile() {
public ClientProfile getClientProfile() {
return clientProfile;
return clientProfile;
}
}
private int rows, cols;
private int rows, cols;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
public void setClientProfile(ClientProfile clientProfile)
public void setClientProfile(ClientProfile clientProfile)
{
{
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
setCurrentParent("root");
setCurrentParent("root");
setRows(clientProfile.getRows());
setRows(clientProfile.getRows());
setCols(clientProfile.getCols());
setCols(clientProfile.getCols());
}
}
public void actionFailed(String profileID, String actionID)
public void actionFailed(String profileID, String actionID)
{
{
if(getClientProfile().getID().equals(profileID))
if(getClientProfile().getID().equals(profileID))
{
{
Action action = getClientProfile().getActionFromID(actionID);
Action action = getClientProfile().getActionFromID(actionID);
if(action != null)
if(action != null)
{
{
if(currentParent.equals(action.getParent()))
if(currentParent.equals(action.getParent()))
{
{
failShow(action);
failShow(action);
}
}
else
else
{
{
if(action.getLocation().getCol() == -1)
if(action.getLocation().getCol() == -1)
{
{
failShow(getClientProfile().getActionFromID(action.getParent()));
failShow(getClientProfile().getActionFromID(action.getParent()));
}
}
}
}
}
}
}
}
}
}
public void failShow(Action action)
public void failShow(Action action)
{
{
actionBoxes[action.getLocation().getCol()][action.getLocation().getRow()].animateStatus();
actionBoxes[action.getLocation().getCol()][action.getLocation().getRow()].animateStatus();
}
}
public String getCurrentParent() {
public String getCurrentParent() {
return currentParent;
return currentParent;
}
}
public StackPane getFolderBackButton()
public StackPane getFolderBackButton()
{
{
StackPane stackPane = new StackPane();
StackPane stackPane = new StackPane();
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box");
stackPane.getStyleClass().add("action_box_valid");
stackPane.getStyleClass().add("action_box_valid");
stackPane.setPrefSize(
stackPane.setPrefSize(
getClientProfile().getActionSize(),
getClientProfile().getActionSize(),
getClientProfile().getActionSize()
getClientProfile().getActionSize()
);
);
FontIcon fontIcon = new FontIcon("fas-chevron-left");
FontIcon fontIcon = new FontIcon("fas-chevron-left");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.getStyleClass().add("folder_action_back_button_icon");
fontIcon.setIconSize(getClientProfile().getActionSize() - 30);
fontIcon.setIconSize(getClientProfile().getActionSize() - 30);
stackPane.setAlignment(Pos.CENTER);
stackPane.setAlignment(Pos.CENTER);
stackPane.getChildren().add(fontIcon);
stackPane.getChildren().add(fontIcon);
stackPane.setOnMouseClicked(e->returnToPreviousParent());
stackPane.setOnMouseClicked(e->returnToPreviousParent());
return stackPane;
return stackPane;
}
}
private boolean isFreshRender = true;
private boolean isFreshRender = true;
private Node folderBackButton = null;
private Node folderBackButton = null;
public void renderGrid()
public void renderGrid()
{
{
actionsGridPane.setHgap(getClientProfile().getActionGap());
actionsGridPane.setHgap(getClientProfile().getActionGap());
actionsGridPane.setVgap(getClientProfile().getActionGap());
actionsGridPane.setVgap(getClientProfile().getActionGap());
if(isFreshRender)
if(isFreshRender)
{
{
clear();
clear();
actionBoxes = new ActionBox[cols][rows];
actionBoxes = new ActionBox[cols][rows];
}
}
boolean isFolder = false;
boolean isFolder = false;
if(getCurrentParent().equals("root"))
if(getCurrentParent().equals("root"))
{
{
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
actionBoxes[0][0] = addBlankActionBox(0,0);
actionBoxes[0][0] = addBlankActionBox(0,0);
}
}
}
}
else
else
{
{
isFolder = true;
isFolder = true;
if(folderBackButton != null)
if(folderBackButton != null)
{
{
actionsGridPane.getChildren().remove(folderBackButton);
actionsGridPane.getChildren().remove(folderBackButton);
folderBackButton = null;
folderBackButton = null;
}
}
else
else
{
{
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
actionsGridPane.getChildren().remove(actionBoxes[0][0]);
}
}
folderBackButton = getFolderBackButton();
folderBackButton = getFolderBackButton();
actionsGridPane.add(folderBackButton, 0,0);
actionsGridPane.add(folderBackButton, 0,0);
}
}
for(int row = 0; row<rows; row++)
for(int row = 0; row<rows; row++)
{
{
for(int col = 0; col<cols; col++)
for(int col = 0; col<cols; col++)
{
{
if(row == 0 && col == 0 && isFolder)
if(row == 0 && col == 0 && isFolder)
continue;
continue;
if(isFreshRender)
if(isFreshRender)
{
{
actionBoxes[col][row] = addBlankActionBox(col, row);
actionBoxes[col][row] = addBlankActionBox(col, row);
}
}
else
else
{
{
if(actionBoxes[col][row].getAction() != null)
if(actionBoxes[col][row].getAction() != null)
{
{
actionBoxes[col][row].clear();
actionBoxes[col][row].clear();
}
}
}
}
}
}
}
}
isFreshRender = false;
isFreshRender = false;
}
}
public void setFreshRender(boolean isFreshRender) {
public void setFreshRender(boolean isFreshRender) {
this.isFreshRender = isFreshRender;
this.isFreshRender = isFreshRender;
}
}
public void renderActions()
public void renderActions()
{
{
StringBuilder errors = new StringBuilder();
StringBuilder errors = new StringBuilder();
for(Action eachAction : getClientProfile().getActions())
for(Action eachAction : getClientProfile().getActions())
{
{
logger.info("Action ID : "+eachAction.getID()+"\nInvalid : "+eachAction.isInvalid());
logger.info("Action ID : "+eachAction.getID()+"\nInvalid : "+eachAction.isInvalid());
try {
try {
renderAction(eachAction);
renderAction(eachAction);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
errors.append("*").append(e.getShortMessage()).append("\n");
errors.append("*").append(e.getShortMessage()).append("\n");
}
}
}
}
if(!errors.toString().isEmpty())
if(!errors.toString().isEmpty())
{
{
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error while rendering following actions", errors.toString()));
}
}
}
}
public void clear()
public void clear()
{
{
actionsGridPane.getChildren().clear();
actionsGridPane.getChildren().clear();
}
}
private Logger logger;
private Logger logger;
public void clearActionBox(int col, int row)
public void clearActionBox(int col, int row)
{
{
actionBoxes[col][row].clear();
actionBoxes[col][row].clear();
}
}
public ActionBox getActionBox(int col, int row)
public ActionBox getActionBox(int col, int row)
{
{
return actionBoxes[col][row];
return actionBoxes[col][row];
}
}
public ActionBox addBlankActionBox(int col, int row)
public ActionBox addBlankActionBox(int col, int row)
{
{
ActionBox actionBox = new ActionBox(getClientProfile().getActionSize(), exceptionAndAlertHandler, clientListener, this, row, col);
ActionBox actionBox = new ActionBox(getClientProfile().getActionSize(), exceptionAndAlertHandler, clientListener, this, row, col);
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
try
try
{
{
if(Config.getInstance().isInvertRowsColsOnDeviceRotate() && ClientInfo.getInstance().isPhone())
if(Config.getInstance().isInvertRowsColsOnDeviceRotate() && ClientInfo.getInstance().isPhone())
{
{
if(clientListener.getCurrentOrientation() == Orientation.HORIZONTAL)
if(clientListener.getCurrentOrientation() == Orientation.HORIZONTAL)
{
{
actionsGridPane.add(actionBox, col, row);
actionsGridPane.add(actionBox, col, row);
}
}
else
else
{
{
actionsGridPane.add(actionBox, row, col);
actionsGridPane.add(actionBox, row, col);
}
}
}
}
else
else
{
{
actionsGridPane.add(actionBox, col, row);
actionsGridPane.add(actionBox, col, row);
}
}
}
}
catch (SevereException e)
catch (SevereException e)
{
{
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
return actionBox;
return actionBox;
}
}
public void toggleOffAllToggleActions()
public void toggleOffAllToggleActions()
{
{
for(Node each : actionsGridPane.getChildren())
for(Node each : actionsGridPane.getChildren())
{
{
if(each instanceof ActionBox)
if(each instanceof ActionBox)
{
{
ActionBox eachActionBox = (ActionBox) each;
ActionBox eachActionBox = (ActionBox) each;
if(eachActionBox.getAction() != null)
if(eachActionBox.getAction() != null)
{
{
if(eachActionBox.getAction().getActionType() == ActionType.TOGGLE)
if(eachActionBox.getAction().getActionType() == ActionType.TOGGLE)
{
{
if(eachActionBox.getCurrentToggleStatus()) // ON
if(eachActionBox.getCurrentToggleStatus()) // ON
{
{
eachActionBox.toggle();
eachActionBox.toggle();
}
}
}
}
}
}
}
}
}
}
}
}
public void renderAction(Action action) throws SevereException, MinorException
public void renderAction(Action action) throws SevereException, MinorException
{
{
if(!action.getParent().equals(currentParent))
if(!action.getParent().equals(currentParent))
{
{
logger.info("Skipping action "+action.getID()+", not current parent!");
logger.info("Skipping action "+action.getID()+", not current parent!");
return;
return;
}
}
if(action.getLocation().getRow()==-1)
if(action.getLocation().getRow()==-1)
{
{
logger.info("Action has -1 rowIndex. Probably Combine Action. Skipping ...");
logger.info("Action has -1 rowIndex. Probably Combine Action. Skipping ...");
return;
return;
}
}
if(action.getLocation().getRow() > rows || action.getLocation().getCol() > cols)
if(action.getLocation().getRow() > rows || action.getLocation().getCol() > cols)
{
{
throw new MinorException("Action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
throw new MinorException("Action "+action.getDisplayText()+" ("+action.getID()+") falls outside bounds.\n" +
" Consider increasing rows/cols from client settings and relocating/deleting it.");
" Consider increasing rows/cols from client settings and relocating/deleting it.");
}
}
Location location = action.getLocation();
Location location = action.getLocation();
if( getClientProfile().getCols() < location.getCol() || getClientProfile().getRows() < location.getRow())
return;
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
ActionBox actionBox = actionBoxes[location.getCol()][location.getRow()];
if(actionBox.getAction()!=null)
if(actionBox.getAction()!=null)
{
{
if(!actionBox.getAction().getID().equals(action.getID()))
if(!actionBox.getAction().getID().equals(action.getID()))
{
{
actionBox.clear();
actionBox.clear();
}
}
}
}
else
else
{
{
actionBox.clear();
actionBox.clear();
}
}
boolean oldToggleStatus = actionBox.getCurrentToggleStatus();
boolean oldToggleStatus = actionBox.getCurrentToggleStatus();
actionBox.setAction(action);
actionBox.setAction(action);
actionBox.setCurrentToggleStatus(oldToggleStatus);
actionBox.setCurrentToggleStatus(oldToggleStatus);
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
actionBox.init();
actionBox.init();
/*ActionBox actionBox = new ActionBox(getClientProfile().getActionSize(), action, exceptionAndAlertHandler, this, location.getRow(), location.getCol());
/*ActionBox actionBox = new ActionBox(getClientProfile().getActionSize(), action, exceptionAndAlertHandler, this, location.getRow(), location.getCol());
actionBox.setStreamPiParent(currentParent);
actionBox.setStreamPiParent(currentParent);
clearActionBox(location.getCol(), location.getRow());
clearActionBox(location.getCol(), location.getRow());
System.out.println(location.getCol()+","+location.getRow());
System.out.println(location.getCol()+","+location.getRow());
add(actionBox, location.getRow(), location.getCol());
add(actionBox, location.getRow(), location.getCol());
actionBoxes[location.getCol()][location.getRow()] = actionBox;*/
actionBoxes[location.getCol()][location.getRow()] = actionBox;*/
}
}
public void setRows(int rows)
public void setRows(int rows)
{
{
this.rows = rows;
this.rows = rows;
}
}
public void setCols(int cols)
public void setCols(int cols)
{
{
this.cols = cols;
this.cols = cols;
}
}
public int getRows()
public int getRows()
{
{
return rows;
return rows;
}
}
public int getCols()
public int getCols()
{
{
return cols;
return cols;
}
}
private String previousParent;
private String previousParent;
public void setPreviousParent(String previousParent) {
public void setPreviousParent(String previousParent) {
this.previousParent = previousParent;
this.previousParent = previousParent;
}
}
public String getPreviousParent() {
public String getPreviousParent() {
return previousParent;
return previousParent;
}
}
@Override
@Override
public void renderFolder(String actionID) {
public void renderFolder(String actionID) {
setCurrentParent(clientProfile.getActionFromID(actionID).getID());
setCurrentParent(clientProfile.getActionFromID(actionID).getID());
setPreviousParent(clientProfile.getActionFromID(actionID).getParent());
setPreviousParent(clientProfile.getActionFromID(actionID).getParent());
renderGrid();
renderGrid();
renderActions();
renderActions();
}
}
@Override
@Override
public void normalActionClicked(String ID)
public void normalActionClicked(String ID)
{
{
clientListener.onActionClicked(getClientProfile().getID(), ID, false);
clientListener.onActionClicked(getClientProfile().getID(), ID, false);
}
}
@Override
@Override
public void toggleActionClicked(String ID, boolean toggleState)
public void toggleActionClicked(String ID, boolean toggleState)
{
{
clientListener.onActionClicked(getClientProfile().getID(), ID, toggleState);
clientListener.onActionClicked(getClientProfile().getID(), ID, toggleState);
}
}
@Override
@Override
public ActionBox getActionBoxByLocation(Location location)
public ActionBox getActionBoxByLocation(Location location)
{
{
return getActionBox(location.getCol(), location.getRow());
return getActionBox(location.getCol(), location.getRow());
}
}
@Override
@Override
public boolean isConnected()
public boolean isConnected()
{
{
return clientListener.isConnected();
return clientListener.isConnected();
}
}
@Override
@Override
public void combineActionClicked(String ID) {
public void combineActionClicked(String ID) {
if(clientListener.isConnected())
if(clientListener.isConnected())
{
{
new Thread(new Task<Void>() {
new Thread(new Task<Void>() {
@Override
@Override
protected Void call()
protected Void call()
{
{
Action action = getClientProfile().getActionFromID(ID);
Action action = getClientProfile().getActionFromID(ID);
for(int i = 0;i<action.getClientProperties().get().size();i++)
for(int i = 0;i<action.getClientProperties().get().size();i++)
{
{
try {
try {
logger.info("Clicking "+i+", '"+action.getClientProperties().getSingleProperty(i+"").getRawValue()+"'");
logger.info("Clicking "+i+", '"+action.getClientProperties().getSingleProperty(i+"").getRawValue()+"'");
normalActionClicked(action.getClientProperties().getSingleProperty(i+"").getRawValue());
normalActionClicked(action.getClientProperties().getSingleProperty(i+"").getRawValue());
} catch (MinorException e) {
} catch (MinorException e) {
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
}
}
}
}
return null;
return null;
}
}
}).start();
}).start();
}
}
}
}
public void returnToPreviousParent()
public void returnToPreviousParent()
{
{
setCurrentParent(getPreviousParent());
setCurrentParent(getPreviousParent());
if(!getPreviousParent().equals("root"))
if(!getPreviousParent().equals("root"))
{
{
System.out.println("parent : "+getPreviousParent());
System.out.println("parent : "+getPreviousParent());
setPreviousParent(getClientProfile().getActionFromID(
setPreviousParent(getClientProfile().getActionFromID(
getPreviousParent()
getPreviousParent()
).getParent());
).getParent());
}
}
renderGrid();
renderGrid();
renderActions();
renderActions();
}
}
}
}