server

Clone or download

added reset to defaults, removed bad debug output

Modified Files

package com.stream_pi.server.window.dashboard.actiondetailpane;
package com.stream_pi.server.window.dashboard.actiondetailpane;
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;
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.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.ClientProperties;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Property;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.actionproperty.property.Type;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.action_api.externalplugin.ExternalPlugin;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.client.ClientProfile;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.connection.ClientConnection;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.uipropertybox.UIPropertyBox;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.ExceptionAndAlertHandler;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
import com.stream_pi.server.window.dashboard.actiongridpane.ActionBox;
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.application.Platform;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.concurrent.Task;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
public class OnSaveActionTask extends Task<Void>
public class OnSaveActionTask extends Task<Void>
{
{
private Logger logger;
private Logger logger;
public OnSaveActionTask(ClientConnection connection, Action action, String delayBeforeRunningString, String displayNameText, boolean isCombineChild,
public OnSaveActionTask(ClientConnection connection, Action action, String delayBeforeRunningString, String displayNameText, boolean isCombineChild,
boolean isShowDisplayText, boolean isDefaultDisplayTextColour, String displayTextFontColour, boolean isClearIcon,
boolean isShowDisplayText, boolean isDefaultDisplayTextColour, String displayTextFontColour, boolean isClearIcon,
boolean isHideDefaultIcon, boolean isHideToggleOffIcon, boolean isHideToggleOnIcon, DisplayTextAlignment displayTextAlignment, boolean isTransparentBackground, String backgroundColour,
boolean isHideDefaultIcon, boolean isHideToggleOffIcon, boolean isHideToggleOnIcon, DisplayTextAlignment displayTextAlignment, boolean isTransparentBackground, String backgroundColour,
CombineActionPropertiesPane combineActionPropertiesPane, ClientProfile clientProfile, boolean sendIcon, ActionBox actionBox,
CombineActionPropertiesPane combineActionPropertiesPane, ClientProfile clientProfile, boolean sendIcon, ActionBox actionBox,
ArrayList<UIPropertyBox> actionClientProperties, ExceptionAndAlertHandler exceptionAndAlertHandler, Button saveButton, Button deleteButton,
ArrayList<UIPropertyBox> actionClientProperties, ExceptionAndAlertHandler exceptionAndAlertHandler, Button saveButton, Button deleteButton,
boolean runOnActionSavedFromServer, boolean runAsync)
boolean runOnActionSavedFromServer, boolean runAsync)
{
{
this.saveButton = saveButton;
this.saveButton = saveButton;
this.deleteButton = deleteButton;
this.deleteButton = deleteButton;
this.delayBeforeRunningString = delayBeforeRunningString;
this.delayBeforeRunningString = delayBeforeRunningString;
this.connection = connection;
this.connection = connection;
this.action = action;
this.action = action;
this.displayNameText = displayNameText;
this.displayNameText = displayNameText;
this.isCombineChild = isCombineChild;
this.isCombineChild = isCombineChild;
this.isShowDisplayText = isShowDisplayText;
this.isShowDisplayText = isShowDisplayText;
this.isDefaultDisplayTextColour = isDefaultDisplayTextColour;
this.isDefaultDisplayTextColour = isDefaultDisplayTextColour;
this.displayTextFontColour = displayTextFontColour;
this.displayTextFontColour = displayTextFontColour;
this.isClearIcon = isClearIcon;
this.isClearIcon = isClearIcon;
this.isHideDefaultIcon = isHideDefaultIcon;
this.isHideDefaultIcon = isHideDefaultIcon;
this.isHideToggleOffIcon = isHideToggleOffIcon;
this.isHideToggleOffIcon = isHideToggleOffIcon;
this.isHideToggleOnIcon = isHideToggleOnIcon;
this.isHideToggleOnIcon = isHideToggleOnIcon;
this.displayTextAlignment = displayTextAlignment;
this.displayTextAlignment = displayTextAlignment;
this.isTransparentBackground = isTransparentBackground;
this.isTransparentBackground = isTransparentBackground;
this.combineActionPropertiesPane = combineActionPropertiesPane;
this.combineActionPropertiesPane = combineActionPropertiesPane;
this.clientProfile = clientProfile;
this.clientProfile = clientProfile;
this.sendIcon = sendIcon;
this.sendIcon = sendIcon;
this.actionBox = actionBox;
this.actionBox = actionBox;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.exceptionAndAlertHandler = exceptionAndAlertHandler;
this.backgroundColour = backgroundColour;
this.backgroundColour = backgroundColour;
this.actionClientProperties = actionClientProperties;
this.actionClientProperties = actionClientProperties;
this.runOnActionSavedFromServer = runOnActionSavedFromServer;
this.runOnActionSavedFromServer = runOnActionSavedFromServer;
logger = Logger.getLogger(getClass().getName());
logger = Logger.getLogger(getClass().getName());
if(runAsync)
if(runAsync)
new Thread(this).start();
new Thread(this).start();
else
else
runTask();
runTask();
}
}
private boolean runOnActionSavedFromServer;
private boolean runOnActionSavedFromServer;
private Button saveButton;
private Button saveButton;
private Button deleteButton;
private Button deleteButton;
private String delayBeforeRunningString;
private String delayBeforeRunningString;
private boolean isShowDisplayText;
private boolean isShowDisplayText;
private boolean isCombineChild;
private boolean isCombineChild;
private String displayNameText;
private String displayNameText;
private boolean isDefaultDisplayTextColour;
private boolean isDefaultDisplayTextColour;
private ArrayList<UIPropertyBox> actionClientProperties;
private ArrayList<UIPropertyBox> actionClientProperties;
private String displayTextFontColour;
private String displayTextFontColour;
private boolean isClearIcon;
private boolean isClearIcon;
private boolean isHideDefaultIcon;
private boolean isHideDefaultIcon;
private boolean isHideToggleOffIcon;
private boolean isHideToggleOffIcon;
private boolean isHideToggleOnIcon;
private boolean isHideToggleOnIcon;
private DisplayTextAlignment displayTextAlignment;
private DisplayTextAlignment displayTextAlignment;
private boolean isTransparentBackground;
private boolean isTransparentBackground;
private String backgroundColour;
private String backgroundColour;
private CombineActionPropertiesPane combineActionPropertiesPane;
private CombineActionPropertiesPane combineActionPropertiesPane;
private ClientProfile clientProfile;
private ClientProfile clientProfile;
private boolean sendIcon;
private boolean sendIcon;
private ActionBox actionBox;
private ActionBox actionBox;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private ExceptionAndAlertHandler exceptionAndAlertHandler;
private Action action;
private Action action;
private ClientConnection connection;
private ClientConnection connection;
private void setSaveDeleteButtonState(boolean state)
private void setSaveDeleteButtonState(boolean state)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
saveButton.setDisable(state);
saveButton.setDisable(state);
deleteButton.setDisable(state);
deleteButton.setDisable(state);
});
});
}
}
private void runTask()
private void runTask()
{
{
action.setDisplayText(displayNameText);
action.setDisplayText(displayNameText);
if(!isCombineChild)
if(!isCombineChild)
{
{
setSaveDeleteButtonState(true);
setSaveDeleteButtonState(true);
action.setShowDisplayText(isShowDisplayText);
action.setShowDisplayText(isShowDisplayText);
if(isDefaultDisplayTextColour)
if(isDefaultDisplayTextColour)
action.setDisplayTextFontColourHex("");
action.setDisplayTextFontColourHex("");
else
else
{
{
action.setDisplayTextFontColourHex(displayTextFontColour);
action.setDisplayTextFontColourHex(displayTextFontColour);
//String fontColour = "#" + displayTextColourPicker.getValue().toString().substring(2);
//String fontColour = "#" + displayTextColourPicker.getValue().toString().substring(2);
//action.setDisplayTextFontColourHex(fontColour);
//action.setDisplayTextFontColourHex(fontColour);
}
}
if(isClearIcon)
if(isClearIcon)
{
{
action.setIcons(null);
action.setIcons(null);
action.setCurrentIconState("");
action.setCurrentIconState("");
}
}
if(action.getActionType() == ActionType.NORMAL)
if(action.getActionType() == ActionType.NORMAL)
{
{
if(isHideDefaultIcon)
if(isHideDefaultIcon)
{
{
if(action.getIcon("default") != null)
if(action.getIcon("default") != null)
action.setCurrentIconState("default");
action.setCurrentIconState("default");
}
}
else
else
{
{
action.setCurrentIconState("");
action.setCurrentIconState("");
}
}
}
}
else if (action.getActionType() == ActionType.TOGGLE)
else if (action.getActionType() == ActionType.TOGGLE)
{
{
action.setCurrentIconState(isHideToggleOffIcon+"__"+isHideToggleOnIcon);
action.setCurrentIconState(isHideToggleOffIcon+"__"+isHideToggleOnIcon);
}
}
action.setDisplayTextAlignment(displayTextAlignment);
action.setDisplayTextAlignment(displayTextAlignment);
if(isTransparentBackground)
if(isTransparentBackground)
action.setBgColourHex("");
action.setBgColourHex("");
else
else
{
{
action.setBgColourHex(backgroundColour);
action.setBgColourHex(backgroundColour);
}
}
}
}
System.out.println("parent : "+action.getParent());
System.out.println("parent : "+action.getParent());
if(action.getActionType() == ActionType.COMBINE)
if(action.getActionType() == ActionType.COMBINE)
{
{
List<String> finalChildren = combineActionPropertiesPane.getFinalChildren();
List<String> finalChildren = combineActionPropertiesPane.getFinalChildren();
System.out.println("2334 "+finalChildren.size());
System.out.println("2334 "+finalChildren.size());
ClientProperties clientProperties = new ClientProperties();
ClientProperties clientProperties = new ClientProperties();
for(int i = 0;i<finalChildren.size();i++)
for(int i = 0;i<finalChildren.size();i++)
{
{
Property property = new Property(i+"", Type.STRING);
Property property = new Property(i+"", Type.STRING);
property.setRawValue(finalChildren.get(i));
property.setRawValue(finalChildren.get(i));
clientProperties.addProperty(property);
clientProperties.addProperty(property);
}
}
action.getClientProperties().set(clientProperties);
action.getClientProperties().set(clientProperties);
}
}
else
else
{
{
action.setDelayBeforeExecuting(Integer.parseInt(delayBeforeRunningString));
action.setDelayBeforeExecuting(Integer.parseInt(delayBeforeRunningString));
//properties
//properties
for (UIPropertyBox clientProperty : actionClientProperties) {
for (UIPropertyBox clientProperty : actionClientProperties) {
action.getClientProperties().get().get(clientProperty.getIndex()).setRawValue(clientProperty.getRawValue());
action.getClientProperties().get().get(clientProperty.getIndex()).setRawValue(clientProperty.getRawValue());
}
}
}
}
try
try
{
{
logger.info("Saving action ... "+action.isHasIcon()+"+"+sendIcon);
logger.info("Saving action ... "+action.isHasIcon()+"+"+sendIcon);
logger.info("BOKA!! : "+action.getProfileID());
if(runOnActionSavedFromServer)
if(runOnActionSavedFromServer)
{
{
for(Property property : action.getClientProperties().get())
{
System.out.println("SSSSSDDD : "+property.getName());
System.out.println("@@@@DDD : "+property.getRawValue());
}
try
try
{
{
if(action instanceof ExternalPlugin)
if(action instanceof ExternalPlugin)
{
{
System.out.println(action.getSocketAddressForClient());
System.out.println(action.getSocketAddressForClient());
((ExternalPlugin) action).onActionSavedFromServer();
((ExternalPlugin) action).onActionSavedFromServer();
}
}
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onActionSavedFromServer() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
exceptionAndAlertHandler.handleMinorException(new MinorException("Error","onActionSavedFromServer() failed for "+action.getModuleName()+"\n\n"+e.getMessage()));
}
}
}
}
connection.saveActionDetails(clientProfile.getID(), action);
connection.saveActionDetails(clientProfile.getID(), action);
if(sendIcon)
if(sendIcon)
{
{
sendAllIcons(clientProfile, action);
sendAllIcons(clientProfile, action);
}
}
if(!isCombineChild)
if(!isCombineChild)
{
{
Platform.runLater(()->{
Platform.runLater(()->{
actionBox.clear();
actionBox.clear();
actionBox.setAction(action);
actionBox.setAction(action);
//actionBox.baseInit();
//actionBox.baseInit();
actionBox.init();
actionBox.init();
});
});
setSaveDeleteButtonState(false);
setSaveDeleteButtonState(false);
}
}
clientProfile.removeActionByID(action.getID());
clientProfile.removeActionByID(action.getID());
clientProfile.addAction(action);
clientProfile.addAction(action);
}
}
catch (SevereException e)
catch (SevereException e)
{
{
e.printStackTrace();
e.printStackTrace();
exceptionAndAlertHandler.handleSevereException(e);
exceptionAndAlertHandler.handleSevereException(e);
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
}
}
}
}
private void sendAllIcons(ClientProfile clientProfile, Action action) throws SevereException
private void sendAllIcons(ClientProfile clientProfile, Action action) throws SevereException
{
{
for(String state : action.getIcons().keySet())
for(String state : action.getIcons().keySet())
{
{
connection.sendIcon(clientProfile.getID(), action.getID(), state, action.getIcon(state));
connection.sendIcon(clientProfile.getID(), action.getID(), state, action.getIcon(state));
}
}
}
}
@Override
@Override
protected Void call() throws Exception
protected Void call() throws Exception
{
{
runTask();
runTask();
return null;
return null;
}
}
}
}
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.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;
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 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.setDisplayText("Untitled Action");
newAction.setDisplayText("Untitled Action");
newAction.setShowDisplayText(true);
newAction.setShowDisplayText(true);
newAction.getClientProperties().resetToDefaults();
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()));
System.out.println("@@#$#$#$ :"+newAction.getProfileID());
System.out.println("@@#$#$#$ :"+newAction.getProfileID());
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)
{
{
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.getButton().equals(MouseButton.PRIMARY))
if(mouseEvent.getButton().equals(MouseButton.PRIMARY))
{
{
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);
}
}
catch (MinorException e)
catch (MinorException e)
{
{
exceptionAndAlertHandler.handleMinorException(e);
exceptionAndAlertHandler.handleMinorException(e);
e.printStackTrace();
e.printStackTrace();
}
}
}
}
}
}
else if(mouseEvent.getButton().equals(MouseButton.SECONDARY))
else if(mouseEvent.getButton().equals(MouseButton.SECONDARY))
{
{
if(getAction().getActionType() == ActionType.TOGGLE)
if(getAction().getActionType() == ActionType.TOGGLE)
{
{
toggleStateContextMenu.show(this, mouseEvent.getScreenX(),
toggleStateContextMenu.show(this, mouseEvent.getScreenX(),
mouseEvent.getScreenY());
mouseEvent.getScreenY());
}
}
}
}
}
}
});
});
toggleStateContextMenu = new ContextMenu();
toggleStateContextMenu = new ContextMenu();
MenuItem showToggleOffMenuItem = new MenuItem("Show Toggle OFF");
MenuItem showToggleOffMenuItem = new MenuItem("Show Toggle OFF");
showToggleOffMenuItem.setOnAction(event-> fakeToggle(false));
showToggleOffMenuItem.setOnAction(event-> fakeToggle(false));
MenuItem showToggleOnMenuItem = new MenuItem("Show Toggle ON");
MenuItem showToggleOnMenuItem = new MenuItem("Show Toggle ON");
showToggleOnMenuItem.setOnAction(event-> fakeToggle(true));
showToggleOnMenuItem.setOnAction(event-> fakeToggle(true));
toggleStateContextMenu.getItems().addAll(showToggleOffMenuItem, showToggleOnMenuItem);
toggleStateContextMenu.getItems().addAll(showToggleOffMenuItem, showToggleOnMenuItem);
setCache(true);
setCache(true);
setCacheHint(CacheHint.QUALITY);
setCacheHint(CacheHint.QUALITY);
}
}
ContextMenu toggleStateContextMenu;
ContextMenu toggleStateContextMenu;
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 static Action deserialize(ByteBuffer buffer) {
public static Action deserialize(ByteBuffer buffer) {
try {
try {
ByteArrayInputStream is = new ByteArrayInputStream(buffer.array());
ByteArrayInputStream is = new ByteArrayInputStream(buffer.array());
ObjectInputStream ois = new ObjectInputStream(is);
ObjectInputStream ois = new ObjectInputStream(is);
Action obj = (Action) ois.readObject();
Action obj = (Action) ois.readObject();
return obj;
return obj;
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
e.printStackTrace();
throw new RuntimeException(e);
throw new RuntimeException(e);
}
}
}
}
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);
removeFontIcon();
removeFontIcon();
fontIcon = new FontIcon();
fontIcon = new FontIcon();
fontIcon.getStyleClass().add(styleClass);
fontIcon.getStyleClass().add(styleClass);
fontIcon.setIconSize((int) (size * 0.8));
fontIcon.setIconSize((int) (size * 0.8));
getChildren().add(fontIcon);
getChildren().add(fontIcon);
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)
{
{
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)
{
{
System.out.println("CURRENT ICONS : "+action.getCurrentIconState());
System.out.println("CURRENT ICONS : "+action.getCurrentIconState());
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)
{
{
System.out.println("COLOr : "+colour);
System.out.println("COLOr : "+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)
{
{
System.out.println("COLOr : "+colour);
System.out.println("COLOr : "+colour);
if(!colour.isEmpty())
if(!colour.isEmpty())
setStyle("-fx-background-color : "+colour);
setStyle("-fx-background-color : "+colour);
}
}
}
}