util

Clone or download

Documentation, Refactoring

Modified Files

A README.md
+21 −0
# util
![version](https://img.shields.io/badge/Version-1.0.0-green)
This package contains the shared code between Server and Client,
like Alerts, ComboBox, etc.
## Prerequisites
---
* Java >= 11
* Maven >= 3.6.3
## Build And Install Locally
---
`mvn clean install`
M pom.xml
+1 −8
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stream_pi</groupId>
<groupId>com.stream_pi</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>1.0.0</version>
<version>1.0.0</version>
<url>https://stream-pi.com/</url>
<url>https://stream-pi.com/</url>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.0</version>
<executions>
<executions>
<execution>
<execution>
<id>test-jar</id>
<id>test-jar</id>
<phase>package</phase>
<phase>package</phase>
<goals>
<goals>
<goal>test-jar</goal>
<goal>test-jar</goal>
</goals>
</goals>
</execution>
</execution>
</executions>
</executions>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.8.1</version>
<configuration>
<configuration>
<release>11</release>
<release>11</release>
</configuration>
</configuration>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
<properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.target>11</maven.compiler.target>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<JavaFXVersion>16-ea+6</JavaFXVersion>
<JavaFXVersion>16-ea+5</JavaFXVersion>
</properties>
</properties>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${IkonliFA5PackVersion}</version>
<version>${IkonliFA5PackVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<artifactId>javafx-controls</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.openjfx</groupId>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<artifactId>javafx-base</artifactId>
<version>${JavaFXVersion}</version>
<version>${JavaFXVersion}</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<artifactId>ikonli-javafx</artifactId>
<version>${IkonliVersion}</version>
<version>${IkonliVersion}</version>
</dependency>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.alert;
package com.stream_pi.util.alert;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class StreamPiAlert {
/**
* Custom Alert Dialog for Server and Client
*/
public class StreamPiAlert
{
private String title;
private String title;
private String[] buttons;
private String[] buttons;
private StreamPiAlertType streamPiAlertType;
private StreamPiAlertType streamPiAlertType;
private Pane contentPane;
private Pane contentPane;
private static StackPane stackPaneParent = null;
private static StackPane stackPaneParent = null;
public static void setParent(StackPane parent) {
/**
* Sets the parent where the alert will be shown
* @param parent StackPane where the alert dialog will be shown
*/
public static void setParent(StackPane parent)
{
stackPaneParent = parent;
stackPaneParent = parent;
stackPaneParent.getStyleClass().add("alert_pane_parent");
stackPaneParent.getStyleClass().add("alert_pane_parent");
stackPaneParent.getChildren().addListener(new ListChangeListener<Node>()
stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
{
{
@Override
if(stackPaneParent.getChildren().size() > 0)
public void onChanged(Change<? extends Node> c) {
{
if(stackPaneParent.getChildren().size() > 0)
stackPaneParent.setVisible(true);
{
stackPaneParent.toFront();
stackPaneParent.setVisible(true);
}
stackPaneParent.toFront();
else
}
{
else
stackPaneParent.setVisible(false);
{
stackPaneParent.toBack();
stackPaneParent.setVisible(false);
stackPaneParent.toBack();
}
}
}
});
});
}
}
public static StackPane getParent() {
/**
* Returns the parent node
* @return StackPane parent where the alert boxes will be shown
*/
public static StackPane getParent()
{
return stackPaneParent;
return stackPaneParent;
}
}
private StreamPiAlertListener streamPiAlertListener = null;
private StreamPiAlertListener streamPiAlertListener = null;
/**
* Public constructor to make an alert with just title, pre-made content pane (mainly for forms, complex dialogs)
* @param title Heading of the Alert
* @param streamPiAlertType Alert Type
* @param contentPane The main body of the alert
*/
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
Pane contentPane) {
Pane contentPane)
set(title, streamPiAlertType, contentPane, new String[]{ "OK" });
{
set(title, streamPiAlertType, contentPane, "OK");
}
}
/**
* Sets the Alert type
* @param streamPiAlertType Alert Type
*/
public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
{
{
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
/**
* Constructor for very simple alert, with just title and body text
* Default AlertType will be INFORMATION
* @param title Heading
* @param contentText Body Text
*/
public StreamPiAlert(String title, String contentText)
public StreamPiAlert(String title, String contentText)
{
{
this(title, contentText, StreamPiAlertType.INFORMATION);
this(title, contentText, StreamPiAlertType.INFORMATION);
}
}
/**
* Constructor for alert with just "Alert" heading,
* content text and alert type
* @param contentText Body Text
* @param alertType Alert Type
*/
public StreamPiAlert(String contentText, StreamPiAlertType alertType)
public StreamPiAlert(String contentText, StreamPiAlertType alertType)
{
{
this("Alert", contentText, alertType);
this("Alert", contentText, alertType);
}
}
/**
* Constructor to create Alert box with title, Alert Type and button choices
* @param title Heading
* @param streamPiAlertType Alert Type
* @param buttons Button choices
*/
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, String... buttons)
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, String... buttons)
{
{
set(title, streamPiAlertType, null, buttons);
set(title, streamPiAlertType, null, buttons);
}
}
/**
* Constructor to create Alert Box with title, Alert Type, Body and button choices
* @param title Heading of the alert box
* @param streamPiAlertType Alert Type
* @param contentPane Alert Body
* @param buttons Button choices
*/
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, Pane contentPane, String... buttons)
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, Pane contentPane, String... buttons)
{
{
set(title, streamPiAlertType, contentPane, buttons);
set(title, streamPiAlertType, contentPane, buttons);
}
}
/**
* Constructor to create Alert Box with Heading, content text, Alert Type
* @param title Heading
* @param contentText Body Text
* @param streamPiAlertType Alert Type
*/
public StreamPiAlert(String title, String contentText, StreamPiAlertType streamPiAlertType)
public StreamPiAlert(String title, String contentText, StreamPiAlertType streamPiAlertType)
{
{
Label label = new Label(contentText);
Label label = new Label(contentText);
label.setWrapText(true);
label.setWrapText(true);
VBox vBox = new VBox(label);
VBox vBox = new VBox(label);
set(title, streamPiAlertType, vBox, new String[]{ "OK" });
set(title, streamPiAlertType, vBox, "OK");
}
}
/**
* Sets the alert properties
* @param title Heading
* @param streamPiAlertType Alert Type
* @param contentPane Body
* @param buttons Button choices
*/
private void set(String title, StreamPiAlertType streamPiAlertType,
private void set(String title, StreamPiAlertType streamPiAlertType,
Pane contentPane, String... buttons)
Pane contentPane, String... buttons)
{
{
this.title = title;
this.title = title;
this.buttons = buttons;
this.buttons = buttons;
this.contentPane = contentPane;
this.contentPane = contentPane;
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
/**
public void setOnClicked(StreamPiAlertListener streamPiAlertListener) {
* Set on click Listener
* @param streamPiAlertListener Alert Listener, triggered when a button is clicked
*/
public void setOnClicked(StreamPiAlertListener streamPiAlertListener)
{
this.streamPiAlertListener = streamPiAlertListener;
this.streamPiAlertListener = streamPiAlertListener;
}
}
public String getTitle() {
/**
* @return Heading of the Alert Box
*/
public String getTitle()
{
return title;
return title;
}
}
public String[] getButtons() {
/**
* @return Button Choices
*/
public String[] getButtons()
{
return buttons;
return buttons;
}
}
public void setAlertContent(Pane contentPane) {
/**
* @param contentPane Alert Body Node
*/
public void setAlertContent(Pane contentPane)
{
this.contentPane = contentPane;
this.contentPane = contentPane;
}
}
public void setButtons(String... buttons) {
/**
* Set all the button choices
* @param buttons Array of button choices
*/
public void setButtons(String... buttons)
{
this.buttons = buttons;
this.buttons = buttons;
}
}
public VBox getAlertPane(String title, Pane alertPane) {
/**
VBox alertVBox = new VBox();
* Create and return the final AlertBox Pane, which will be added to the parent node
alertVBox.getStyleClass().add("alert_pane");
* @param title Heading
* @param contentPane The Alert Body Pane
* @return Final VBox to be shown in the parent Stack Pane
*/
private VBox getAlertPane(String title, Pane contentPane)
{
if(title.isEmpty())
if(title.isEmpty())
title = "Alert";
title = "Alert";
Label label = new Label(title);
Label label = new Label(title);
label.getStyleClass().add("alert_pane_header_text");
label.getStyleClass().add("alert_pane_header_text");
FontIcon fontIcon = new FontIcon(streamPiAlertType.getIconCode());
FontIcon fontIcon = new FontIcon(streamPiAlertType.getIconCode());
fontIcon.getStyleClass().addAll("alert_header_icon", streamPiAlertType.getIconStyleClassName());
fontIcon.getStyleClass().addAll("alert_header_icon", streamPiAlertType.getIconStyleClassName());
HBox header = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox), fontIcon);
HBox header = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox), fontIcon);
header.getStyleClass().add("alert_header");
header.getStyleClass().add("alert_header");
header.setPadding(new Insets(10));
header.setPadding(new Insets(10));
HBox buttonBar = new HBox();
HBox buttonBar = new HBox();
buttonBar.getStyleClass().add("alert_button_bar");
buttonBar.getStyleClass().add("alert_button_bar");
for (String eachButtonString : buttons) {
for (String eachButtonString : buttons)
{
Button button = new Button(eachButtonString);
Button button = new Button(eachButtonString);
button.setOnAction(event -> {
button.setOnAction(event -> {
if(this.streamPiAlertListener != null)
if(this.streamPiAlertListener != null)
this.streamPiAlertListener.onClick(eachButtonString);
this.streamPiAlertListener.onClick(eachButtonString);
destroy();
destroy();
});
});
button.getStyleClass().add("alert_button");
button.getStyleClass().add("alert_button");
buttonBar.getChildren().add(button);
buttonBar.getChildren().add(button);
}
}
alertPane.getStyleClass().add("alert_content_pane");
contentPane.getStyleClass().add("alert_content_pane");
ScrollPane scrollPane = new ScrollPane(alertPane);
ScrollPane scrollPane = new ScrollPane(contentPane);
scrollPane.prefHeightProperty().bind(alertPane.heightProperty().add(20));
scrollPane.prefHeightProperty().bind(contentPane.heightProperty().add(20));
scrollPane.getStyleClass().add("alert_scroll_pane");
scrollPane.getStyleClass().add("alert_scroll_pane");
alertPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
contentPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
alertVBox.getChildren().addAll(
VBox alertVBox = new VBox( header, scrollPane, buttonBar);
header,
alertVBox.getStyleClass().add("alert_pane");
scrollPane,
buttonBar
);
alertVBox.setMaxHeight(Double.NEGATIVE_INFINITY);
alertVBox.setMaxHeight(Double.NEGATIVE_INFINITY);
return alertVBox;
return alertVBox;
}
}
/**
* @return The body node of the Alert Box
*/
public Pane getContentPane()
public Pane getContentPane()
{
{
return contentPane;
return contentPane;
}
}
/**
* Adds the Alert Box to the parent node
*/
private Node popupNode;
private Node popupNode;
public void show()
public void show()
{
{
Platform.runLater(()->{
Platform.runLater(()->
{
popupNode = getAlertPane(getTitle(), getContentPane());
popupNode = getAlertPane(getTitle(), getContentPane());
stackPaneParent.getChildren().add(popupNode);
stackPaneParent.getChildren().add(popupNode);
});
});
}
}
/**
* Removes the alert from the parent pane
*/
public void destroy()
public void destroy()
{
{
Platform.runLater(()->{
Platform.runLater(()-> stackPaneParent.getChildren().remove(popupNode));
stackPaneParent.getChildren().remove(popupNode);
});
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.alert;
package com.stream_pi.util.alert;
/**
* Alert Listener. Triggered when a button on StreamPiAlert is clicked.
*/
public abstract class StreamPiAlertListener {
public abstract class StreamPiAlertListener {
/**
* @param buttonClicked Button choice which was clicked
*/
public abstract void onClick(String buttonClicked);
public abstract void onClick(String buttonClicked);
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.alert;
package com.stream_pi.util.alert;
/**
* Stream-Pi Alert Type Enumerator
*/
public enum StreamPiAlertType {
public enum StreamPiAlertType {
INFORMATION("fas-info", "alert_information_icon"),
INFORMATION("fas-info", "alert_information_icon"),
WARNING("fas-exclamation-triangle", "alert_warning_icon"),
WARNING("fas-exclamation-triangle", "alert_warning_icon"),
ERROR("fas-times", "alert_error_icon");
ERROR("fas-times", "alert_error_icon");
private final String fontAwesomeIconCode;
private final String fontAwesomeIconCode;
private final String alertIconStyleClassName;
private final String alertIconStyleClassName;
/**
* @param fontAwesomeIconCode Ikonli Font Icon code
* @param alertIconStyleClassName Icon CSS Style Class
*/
StreamPiAlertType(String fontAwesomeIconCode, String alertIconStyleClassName)
StreamPiAlertType(String fontAwesomeIconCode, String alertIconStyleClassName)
{
{
this.fontAwesomeIconCode = fontAwesomeIconCode;
this.fontAwesomeIconCode = fontAwesomeIconCode;
this.alertIconStyleClassName = alertIconStyleClassName;
this.alertIconStyleClassName = alertIconStyleClassName;
}
}
/**
* @return Ikonli Font Icon code
*/
public String getIconCode()
public String getIconCode()
{
{
return fontAwesomeIconCode;
return fontAwesomeIconCode;
}
}
/**
* @return Icon CSS Style Class
*/
public String getIconStyleClassName()
public String getIconStyleClassName()
{
{
return alertIconStyleClassName;
return alertIconStyleClassName;
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.combobox;
package com.stream_pi.util.combobox;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
/**
* Custom Combo Box for Server and Client
* @param <T> Combo Box List Type
*/
public class StreamPiComboBox<T> extends HBox
public class StreamPiComboBox<T> extends HBox
{
{
private List<T> options;
private List<T> options;
private static StackPane stackPaneParent;
private static StackPane stackPaneParent;
/**
* Sets the parent where the Combo Box will be shown
* @param parent StackPane where the Combo Box dialog will be shown
*/
public static void setParent(StackPane parent) {
public static void setParent(StackPane parent) {
stackPaneParent = parent;
stackPaneParent = parent;
stackPaneParent.getStyleClass().add("combobox_pane_parent");
stackPaneParent.getStyleClass().add("combo_box_pane_parent");
stackPaneParent.getChildren().addListener(new ListChangeListener<Node>()
stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
{
{
@Override
if(stackPaneParent.getChildren().size() > 0)
public void onChanged(Change<? extends Node> c) {
{
if(stackPaneParent.getChildren().size() > 0)
stackPaneParent.setVisible(true);
{
stackPaneParent.toFront();
stackPaneParent.setVisible(true);
}
stackPaneParent.toFront();
else
}
{
else
stackPaneParent.setVisible(false);
{
stackPaneParent.toBack();
stackPaneParent.setVisible(false);
stackPaneParent.toBack();
}
}
}
});
});
}
}
/**
* Constructor to create Combo Box with all the options
* @param options List of Options
*/
public StreamPiComboBox(List<T> options)
public StreamPiComboBox(List<T> options)
{
{
setup();
setup();
setOptions(options);
setOptions(options);
}
}
/**
* @return List of Combo Box Options
*/
public List<T> getOptions()
public List<T> getOptions()
{
{
return options;
return options;
}
}
/**
* Constructor to create Combo Box with empty list
*/
public StreamPiComboBox()
public StreamPiComboBox()
{
{
setup();
setup();
}
}
private Label currentSelectedLabel;
private Label currentSelectedLabel;
/**
* init of Combo Box
*/
private void setup()
private void setup()
{
{
buttons = new ArrayList<>();
buttons = new ArrayList<>();
getStyleClass().add("combo_box");
getStyleClass().add("combo_box");
setOnMouseClicked(event->show());
setOnMouseClicked(event->show());
currentSelectedLabel = new Label();
currentSelectedLabel = new Label();
currentSelectedLabel.getStyleClass().add("combo_box_current_selected_label");
FontIcon fontIcon = new FontIcon();
FontIcon fontIcon = new FontIcon();
fontIcon.getStyleClass().add("combo_box_drop_down_icon");
fontIcon.getStyleClass().add("combo_box_drop_down_icon");
getChildren().addAll(
getChildren().addAll(
currentSelectedLabel,
currentSelectedLabel,
new SpaceFiller(SpaceFiller.FillerType.HBox),
new SpaceFiller(SpaceFiller.FillerType.HBox),
fontIcon
fontIcon
);
);
}
}
/**
* Set Combo Box options
* @param options Combo Box Options
*/
public void setOptions(List<T> options)
public void setOptions(List<T> options)
{
{
this.options = options;
this.options = options;
setCurrentSelectedItemIndex(0);
setCurrentSelectedItemIndex(0);
}
}
private int currentIndex = 0;
private int currentIndex = 0;
private List<ToggleButton> buttons;
private List<ToggleButton> buttons;
/**
* @return Final Scroll Pane
*/
public ScrollPane getPopupScrollPane()
public ScrollPane getPopupScrollPane()
{
{
buttons.clear();
buttons.clear();
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.getStyleClass().add("combo_box_popup");
scrollPane.getStyleClass().add("combo_box_popup");
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.getStyleClass().add("combo_box_popup_vbox");
vBox.getStyleClass().add("combo_box_popup_vbox");
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setContent(vBox);
scrollPane.setContent(vBox);
for(int i = 0;i<options.size();i++)
for(int i = 0;i<options.size();i++)
{
{
T eachOptionObj = options.get(i);
T eachOptionObj = options.get(i);
String displayText = streamPiComboBoxFactory.getOptionDisplayText(eachOptionObj);
String displayText = streamPiComboBoxFactory.getOptionDisplayText(eachOptionObj);
ToggleButton optionButton = new ToggleButton(displayText);
ToggleButton optionButton = new ToggleButton(displayText);
optionButton.getStyleClass().add("combo_box_list_option_button");
optionButton.setSelected(i == currentIndex);
optionButton.setSelected(i == currentIndex);
optionButton.setUserData(i);
optionButton.setUserData(i);
optionButton.setOnAction(event->
optionButton.setOnAction(event->
{
{
setCurrentSelectedItemIndex((int) optionButton.getUserData());
setCurrentSelectedItemIndex((int) optionButton.getUserData());
if(streamPiComboBoxListener != null)
if(streamPiComboBoxListener != null)
streamPiComboBoxListener.onNewItemSelected(options.get(currentIndex));
streamPiComboBoxListener.onNewItemSelected(options.get(currentIndex));
destroy();
destroy();
});
});
vBox.getChildren().addAll(optionButton);
vBox.getChildren().addAll(optionButton);
buttons.add(optionButton);
buttons.add(optionButton);
}
}
return scrollPane;
return scrollPane;
}
}
/**
* @return Current Selected Option Index
*/
public int getCurrentIndex()
public int getCurrentIndex()
{
{
return currentIndex;
return currentIndex;
}
}
/**
* @return Current Selected Item
*/
public T getCurrentSelectedItem()
public T getCurrentSelectedItem()
{
{
return options.get(currentIndex);
return options.get(currentIndex);
}
}
/**
* @param index Current item index to be selected
*/
public void setCurrentSelectedItemIndex(int index)
public void setCurrentSelectedItemIndex(int index)
{
{
this.currentIndex = index;
this.currentIndex = index;
setCurrentSelectedLabelText(streamPiComboBoxFactory.getOptionDisplayText(options.get(index)));
setCurrentSelectedLabelText(streamPiComboBoxFactory.getOptionDisplayText(options.get(index)));
}
}
/**
* @param text Name of the option
*/
private void setCurrentSelectedLabelText(String text)
private void setCurrentSelectedLabelText(String text)
{
{
currentSelectedLabel.setText(text);
currentSelectedLabel.setText(text);
}
}
private StreamPiComboBoxListener<T> streamPiComboBoxListener = null;
private StreamPiComboBoxListener<T> streamPiComboBoxListener = null;
/**
* Set on click Listener
* @param streamPiComboBoxListener Combo Box Listener, triggered when an option is clicked
*/
public void setStreamPiComboBoxListener(StreamPiComboBoxListener<T> streamPiComboBoxListener)
public void setStreamPiComboBoxListener(StreamPiComboBoxListener<T> streamPiComboBoxListener)
{
{
this.streamPiComboBoxListener = streamPiComboBoxListener;
this.streamPiComboBoxListener = streamPiComboBoxListener;
}
}
private Node popupNode;
private Node popupNode;
/**
* Adds the Combo Box to the parent node
*/
public void show()
public void show()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
popupNode = getPopupScrollPane();
popupNode = getPopupScrollPane();
stackPaneParent.getChildren().add(popupNode);
stackPaneParent.getChildren().add(popupNode);
});
});
}
}
/**
* Removes the combo box from the parent pane
*/
public void destroy()
public void destroy()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
stackPaneParent.getChildren().remove(popupNode);
stackPaneParent.getChildren().remove(popupNode);
});
});
}
}
private StreamPiComboBoxFactory<T> streamPiComboBoxFactory;
private StreamPiComboBoxFactory<T> streamPiComboBoxFactory;
/**
* @param streamPiComboBoxFactory Factory for the Combo Box
*/
public void setStreamPiComboBoxFactory(StreamPiComboBoxFactory<T> streamPiComboBoxFactory)
public void setStreamPiComboBoxFactory(StreamPiComboBoxFactory<T> streamPiComboBoxFactory)
{
{
this.streamPiComboBoxFactory = streamPiComboBoxFactory;
this.streamPiComboBoxFactory = streamPiComboBoxFactory;
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.combobox;
package com.stream_pi.util.combobox;
public abstract class StreamPiComboBoxFactory<T>
public abstract class StreamPiComboBoxFactory<T>
{
{
public abstract String getOptionDisplayText(T object);
public abstract String getOptionDisplayText(T object);
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.combobox;
package com.stream_pi.util.combobox;
public abstract class StreamPiComboBoxListener<T> {
public abstract class StreamPiComboBoxListener<T> {
public abstract void onNewItemSelected(T selectedItem);
public abstract void onNewItemSelected(T selectedItem);
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.exception;
package com.stream_pi.util.exception;
public class MinorException extends StreamPiException {
public class MinorException extends StreamPiException {
public MinorException(String message)
public MinorException(String message)
{
{
super(message);
super(message);
}
}
public MinorException(String title, String message)
public MinorException(String title, String message)
{
{
super(title, message);
super(title, message);
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.exception;
package com.stream_pi.util.exception;
public class SevereException extends StreamPiException{
public class SevereException extends StreamPiException{
public SevereException(String message)
public SevereException(String message)
{
{
super(message);
super(message);
}
}
public SevereException(String title, String message)
public SevereException(String title, String message)
{
{
super(title, message);
super(title, message);
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.exception;
package com.stream_pi.util.exception;
public class StreamPiException extends Exception {
public class StreamPiException extends Exception {
private String title;
private String title;
private String message;
private String message;
public StreamPiException(String message)
public StreamPiException(String message)
{
{
super(message);
super(message);
this.title = "";
this.title = "";
this.message = message;
this.message = message;
}
}
public StreamPiException(String title, String message)
public StreamPiException(String title, String message)
{
{
super(message);
super(message);
this.title = title;
this.title = title;
this.message = message;
this.message = message;
}
}
public String getShortMessage()
public String getShortMessage()
{
{
return message;
return message;
}
}
public String getTitle()
public String getTitle()
{
{
return title;
return title;
}
}
public void setTitle(String title)
public void setTitle(String title)
{
{
this.title = title;
this.title = title;
}
}
public void setShortMessage(String message)
public void setShortMessage(String message)
{
{
this.message = message;
this.message = message;
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.iohelper;
package com.stream_pi.util.iohelper;
import java.io.File;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipInputStream;
public class IOHelper {
public class IOHelper {
public static void unzip(InputStream inputStream, String destDir) throws Exception{
public static void unzip(InputStream inputStream, String destDir) throws Exception{
File dir = new File(destDir);
File dir = new File(destDir);
// create output directory if it doesn't exist
// create output directory if it doesn't exist
if(!dir.exists()) dir.mkdirs();
if(!dir.exists()) dir.mkdirs();
InputStream fis;
InputStream fis;
//buffer for read and write data to file
//buffer for read and write data to file
byte[] buffer = new byte[1024];
byte[] buffer = new byte[1024];
fis = inputStream;
fis = inputStream;
ZipInputStream zis = new ZipInputStream(fis);
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry ze = zis.getNextEntry();
ZipEntry ze = zis.getNextEntry();
while(ze != null){
while(ze != null){
String fileName = ze.getName();
String fileName = ze.getName();
File newFile = new File(destDir + File.separator + fileName);
File newFile = new File(destDir + File.separator + fileName);
if(ze.isDirectory())
if(ze.isDirectory())
{
{
newFile.mkdirs();
newFile.mkdirs();
}
}
else
else
{
{
FileOutputStream fos = new FileOutputStream(newFile);
FileOutputStream fos = new FileOutputStream(newFile);
int len;
int len;
while ((len = zis.read(buffer)) > 0) {
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
fos.write(buffer, 0, len);
}
}
fos.close();
fos.close();
}
}
//close this ZipEntry
//close this ZipEntry
zis.closeEntry();
zis.closeEntry();
ze = zis.getNextEntry();
ze = zis.getNextEntry();
}
}
//close last ZipEntry
//close last ZipEntry
zis.closeEntry();
zis.closeEntry();
zis.close();
zis.close();
fis.close();
fis.close();
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.loggerhelper;
package com.stream_pi.util.loggerhelper;
import java.util.logging.ConsoleHandler;
import java.util.logging.ConsoleHandler;
public class StreamPiLogFallbackHandler extends ConsoleHandler{
public class StreamPiLogFallbackHandler extends ConsoleHandler{
public StreamPiLogFallbackHandler() throws Exception
public StreamPiLogFallbackHandler() throws Exception
{
{
super();
super();
setFormatter(new StreamPiLogFormatter());
setFormatter(new StreamPiLogFormatter());
}
}
public void closeHandler()
public void closeHandler()
{
{
close();
close();
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.loggerhelper;
package com.stream_pi.util.loggerhelper;
import java.util.logging.FileHandler;
import java.util.logging.FileHandler;
public class StreamPiLogFileHandler extends FileHandler {
public class StreamPiLogFileHandler extends FileHandler {
public StreamPiLogFileHandler(String logFilePath) throws Exception
public StreamPiLogFileHandler(String logFilePath) throws Exception
{
{
super(logFilePath, false);
super(logFilePath, false);
setFormatter(new StreamPiLogFormatter());
setFormatter(new StreamPiLogFormatter());
}
}
public void closeHandler()
public void closeHandler()
{
{
close();
close();
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.loggerhelper;
package com.stream_pi.util.loggerhelper;
import java.util.logging.LogRecord;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
import java.util.logging.SimpleFormatter;
public class StreamPiLogFormatter extends SimpleFormatter{
public class StreamPiLogFormatter extends SimpleFormatter{
@Override
@Override
public String format(LogRecord record)
public String format(LogRecord record)
{
{
return "["+Thread.currentThread().getName()+"] :: "+ record.getSourceClassName()+"@"+record.getSourceMethodName()+" -> " + ":" + record.getLevel() + " = "+ record.getMessage() + "\n";
return "["+Thread.currentThread().getName()+"] :: "+ record.getSourceClassName()+"@"+record.getSourceMethodName()+" -> " + ":" + record.getLevel() + " = "+ record.getMessage() + "\n";
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.platform;
package com.stream_pi.util.platform;
public enum Platform {
public enum Platform {
WINDOWS("Windows"),
WINDOWS("Windows"),
LINUX("Linux"),
LINUX("Linux"),
MAC("MacOS"),
MAC("MacOS"),
ANDROID("Android"),
ANDROID("Android"),
IOS("iOS"),
IOS("iOS"),
LINUX_RPI("Raspberry Pi"),
LINUX_RPI("Raspberry Pi"),
UNKNOWN("Unknown");
UNKNOWN("Unknown");
final private String UIName;
final private String UIName;
Platform(String UIName)
Platform(String UIName)
{
{
this.UIName = UIName;
this.UIName = UIName;
}
}
public String getUIName()
public String getUIName()
{
{
return UIName;
return UIName;
}
}
}
}
/*
/*
ReleaseStatus.java
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Written By : Debayan Sutradhar (@rnayabed)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Enum to store the current status of the Server Release
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.platform;
package com.stream_pi.util.platform;
public enum ReleaseStatus {
public enum ReleaseStatus {
EA("Early Access"), GA("General Availability");
EA("Early Access"), GA("General Availability");
private final String UIName;
private final String UIName;
ReleaseStatus(String UIName)
ReleaseStatus(String UIName)
{
{
this.UIName = UIName;
this.UIName = UIName;
}
}
public String getUIName()
public String getUIName()
{
{
return UIName;
return UIName;
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.startatboot;
package com.stream_pi.util.startatboot;
public enum SoftwareType {
public enum SoftwareType {
SERVER, CLIENT
SERVER, CLIENT
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.startatboot;
package com.stream_pi.util.startatboot;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.platform.Platform;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import java.io.BufferedWriter;
import java.io.BufferedWriter;
import java.io.File;
import java.io.File;
import java.io.FileWriter;
import java.io.FileWriter;
public class StartAtBoot {
public class StartAtBoot {
SoftwareType softwareType;
SoftwareType softwareType;
Platform platform;
Platform platform;
public StartAtBoot(SoftwareType softwareType, Platform platform)
public StartAtBoot(SoftwareType softwareType, Platform platform)
{
{
this.softwareType = softwareType;
this.softwareType = softwareType;
this.platform = platform;
this.platform = platform;
}
}
public void create(File runnerFile) throws MinorException
public void create(File runnerFile) throws MinorException
{
{
if(platform == Platform.WINDOWS)
if(platform == Platform.WINDOWS)
createStarterForWindows(runnerFile);
createStarterForWindows(runnerFile);
else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI)
else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI)
createStarterForLinux(runnerFile);
createStarterForLinux(runnerFile);
else if(platform == Platform.MAC)
else if(platform == Platform.MAC)
createStarterForMac(runnerFile);
createStarterForMac(runnerFile);
else if(platform == Platform.UNKNOWN)
else if(platform == Platform.UNKNOWN)
unknownPlatformException();
unknownPlatformException();
}
}
public boolean delete() throws MinorException {
public boolean delete() throws MinorException {
if(platform == Platform.WINDOWS)
if(platform == Platform.WINDOWS)
return deleteStarterForWindows();
return deleteStarterForWindows();
else if (platform == Platform.LINUX || platform == Platform.LINUX_RPI)
else if (platform == Platform.LINUX || platform == Platform.LINUX_RPI)
return deleteStarterForLinux();
return deleteStarterForLinux();
else if(platform == Platform.MAC)
else if(platform == Platform.MAC)
deleteStarterForMac();
deleteStarterForMac();
else if(platform == Platform.UNKNOWN)
else if(platform == Platform.UNKNOWN)
unknownPlatformException();
unknownPlatformException();
return false;
return false;
}
}
private void createStarterForLinux(File runnerFile) throws MinorException
private void createStarterForLinux(File runnerFile) throws MinorException
{
{
try
try
{
{
String sysDDirectoryPath = System.getProperty("user.home")+"/.local/share/systemd/user/";
String sysDDirectoryPath = System.getProperty("user.home")+"/.local/share/systemd/user/";
File sysDDirectoryFile = new File(sysDDirectoryPath);
File sysDDirectoryFile = new File(sysDDirectoryPath);
if(!sysDDirectoryFile.exists())
if(!sysDDirectoryFile.exists())
sysDDirectoryFile.mkdirs();
sysDDirectoryFile.mkdirs();
File sysDServiceFile = new File(sysDDirectoryPath+"stream-pi-"+ softwareType+".service");
File sysDServiceFile = new File(sysDDirectoryPath+"stream-pi-"+ softwareType+".service");
FileWriter fw = new FileWriter(sysDServiceFile);
FileWriter fw = new FileWriter(sysDServiceFile);
BufferedWriter bw = new BufferedWriter(fw);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("[Unit]\n" +
bw.write("[Unit]\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"Description=Stream-Pi "+softwareType+"\n" +
"[Service]\n" +
"[Service]\n" +
"Type=oneshot\n" +
"Type=oneshot\n" +
"WorkingDirectory="+runnerFile.getAbsoluteFile().getParent()+"\n" +
"WorkingDirectory="+runnerFile.getAbsoluteFile().getParent()+"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
"[Install]\n" +
"[Install]\n" +
"WantedBy=default.target\n");
"WantedBy=default.target\n");
bw.close();
bw.close();
Runtime.getRuntime().exec("systemctl --user daemon-reload");
Runtime.getRuntime().exec("systemctl --user daemon-reload");
Runtime.getRuntime().exec("systemctl --user enable stream-pi-"+softwareType+".service");
Runtime.getRuntime().exec("systemctl --user enable stream-pi-"+softwareType+".service");
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new MinorException("Unable to set start at boot",e.getMessage());
throw new MinorException("Unable to set start at boot",e.getMessage());
}
}
}
}
private boolean deleteStarterForLinux() throws MinorException
private boolean deleteStarterForLinux() throws MinorException
{
{
try
try
{
{
boolean f1 = new File(System.getProperty("user.home")+"/.local/share/systemd/user/stream-pi-"+
boolean f1 = new File(System.getProperty("user.home")+"/.local/share/systemd/user/stream-pi-"+
softwareType+".service").delete();
softwareType+".service").delete();
Runtime.getRuntime().exec("systemctl --user daemon-reload");
Runtime.getRuntime().exec("systemctl --user daemon-reload");
return f1;
return f1;
}
}
catch (Exception e)
catch (Exception e)
{
{
e.printStackTrace();
e.printStackTrace();
throw new MinorException("Unable to unset start at boot",e.getMessage());
throw new MinorException("Unable to unset start at boot",e.getMessage());
}
}
}
}
private void createStarterForWindows(File runnerFile) throws MinorException
private void createStarterForWindows(File runnerFile) throws MinorException
{
{
File initFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat");
File initFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat");
try
try
{
{
FileWriter fw = new FileWriter(initFile);
FileWriter fw = new FileWriter(initFile);
BufferedWriter bw = new BufferedWriter(fw);
BufferedWriter bw = new BufferedWriter(fw);
bw.write("cd "+runnerFile.getAbsoluteFile().getParent()+"\n" +
bw.write("cd "+runnerFile.getAbsoluteFile().getParent()+"\n" +
runnerFile.getName());
runnerFile.getName());
bw.close();
bw.close();
}
}
catch (Exception e)
catch (Exception e)
{
{
throw new MinorException(e.getMessage());
throw new MinorException(e.getMessage());
}
}
}
}
private boolean deleteStarterForWindows()
private boolean deleteStarterForWindows()
{
{
return new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat").delete();
return new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat").delete();
}
}
private void createStarterForMac(File runnerFile) throws MinorException
private void createStarterForMac(File runnerFile) throws MinorException
{
{
throw new MinorException("Mac Starter feature is not implemented yet.");
throw new MinorException("Mac Starter feature is not implemented yet.");
}
}
private void deleteStarterForMac() throws MinorException
private void deleteStarterForMac() throws MinorException
{
{
throw new MinorException("Mac Starter feature is not implemented yet.");
throw new MinorException("Mac Starter feature is not implemented yet.");
}
}
private void unknownPlatformException() throws MinorException
private void unknownPlatformException() throws MinorException
{
{
throw new MinorException("Cannot implemented starter feature. Unknown platform.");
throw new MinorException("Cannot implemented starter feature. Unknown platform.");
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.uihelper;
package com.stream_pi.util.uihelper;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
public class HBoxInputBox extends HBox {
public class HBoxInputBox extends HBox {
private TextField textField;
private TextField textField;
public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
{
{
textField.setPrefWidth(prefWidth);
textField.setPrefWidth(prefWidth);
Label label = new Label(labelText);
Label label = new Label(labelText);
getChildren().addAll(label, new SpaceFiller(SpaceFiller.FillerType.HBox), textField);
getChildren().addAll(label, new SpaceFiller(SpaceFiller.FillerType.HBox), textField);
if(enablerCheckBox != null)
if(enablerCheckBox != null)
{
{
textField.disableProperty().bind(enablerCheckBox.selectedProperty());
textField.disableProperty().bind(enablerCheckBox.selectedProperty());
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
getChildren().add(enablerCheckBox);
getChildren().add(enablerCheckBox);
}
}
this.textField = textField;
this.textField = textField;
}
}
public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
{
{
this(labelText, textField, 100, enablerCheckBox);
this(labelText, textField, 100, enablerCheckBox);
}
}
public HBoxInputBox(String labelText, TextField textField)
public HBoxInputBox(String labelText, TextField textField)
{
{
this(labelText, textField, 100, null);
this(labelText, textField, 100, null);
}
}
public HBoxInputBox(String labelText, TextField textField, int prefWidth)
public HBoxInputBox(String labelText, TextField textField, int prefWidth)
{
{
this(labelText, textField, prefWidth, null);
this(labelText, textField, prefWidth, null);
}
}
public TextField getTextField()
public TextField getTextField()
{
{
return textField;
return textField;
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.uihelper;
package com.stream_pi.util.uihelper;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.io.File;
import java.io.File;
public class HBoxInputBoxWithFileChooser extends HBox {
public class HBoxInputBoxWithFileChooser extends HBox {
public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
{
{
textField.setDisable(true);
textField.setDisable(true);
HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
setHgrow(hBoxInputBox, Priority.ALWAYS);
setHgrow(hBoxInputBox, Priority.ALWAYS);
getChildren().addAll(hBoxInputBox);
getChildren().addAll(hBoxInputBox);
setSpacing(5.0);
setSpacing(5.0);
Button button = new Button();
Button button = new Button();
FontIcon fontIcon = new FontIcon("far-folder");
FontIcon fontIcon = new FontIcon("far-folder");
//fontIcon.setIconColor(Paint.valueOf(iconColorHex));
//fontIcon.setIconColor(Paint.valueOf(iconColorHex));
//fontIcon.setIconSize(iconSize);
//fontIcon.setIconSize(iconSize);
button.setGraphic(fontIcon);
button.setGraphic(fontIcon);
button.setOnAction(event -> {
button.setOnAction(event -> {
FileChooser fileChooser = new FileChooser();
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(
fileChooser.getExtensionFilters().addAll(
extensionFilter
extensionFilter
);
);
try {
try {
File selectedDirectory = fileChooser.showOpenDialog(button.getScene().getWindow());
File selectedDirectory = fileChooser.showOpenDialog(button.getScene().getWindow());
textField.setText(selectedDirectory.getAbsolutePath());
textField.setText(selectedDirectory.getAbsolutePath());
}
}
catch (NullPointerException e)
catch (NullPointerException e)
{
{
// No folder selected
// No folder selected
}
}
});
});
getChildren().add(button);
getChildren().add(button);
if(enablerCheckBox!=null)
if(enablerCheckBox!=null)
{
{
button.disableProperty().bind(enablerCheckBox.selectedProperty());
button.disableProperty().bind(enablerCheckBox.selectedProperty());
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
getChildren().add(enablerCheckBox);
getChildren().add(enablerCheckBox);
}
}
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.uihelper;
package com.stream_pi.util.uihelper;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class SpaceFiller extends Region {
public class SpaceFiller extends Region {
public SpaceFiller(FillerType fillerType)
public SpaceFiller(FillerType fillerType)
{
{
if(fillerType == FillerType.HBox)
if(fillerType == FillerType.HBox)
{
{
HBox.setHgrow(this, Priority.ALWAYS);
HBox.setHgrow(this, Priority.ALWAYS);
}
}
else if(fillerType == FillerType.VBox)
else if(fillerType == FillerType.VBox)
{
{
VBox.setVgrow(this, Priority.ALWAYS);
VBox.setVgrow(this, Priority.ALWAYS);
}
}
}
}
public enum FillerType
public enum FillerType
{
{
HBox, VBox
HBox, VBox
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.version;
package com.stream_pi.util.version;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import java.io.Serializable;
import java.io.Serializable;
public class Version implements Serializable {
public class Version implements Serializable {
private int major, minor, revision;
private int major, minor, revision;
public Version()
public Version()
{
{
major = 0;
major = 0;
minor = 0;
minor = 0;
revision = 0;
revision = 0;
}
}
public Version(int major, int minor, int revision)
public Version(int major, int minor, int revision)
{
{
this.major = major;
this.major = major;
this.minor = minor;
this.minor = minor;
this.revision = revision;
this.revision = revision;
}
}
public Version(String version) throws MinorException
public Version(String version) throws MinorException
{
{
String[] v = version.trim().split("\\.");
String[] v = version.trim().split("\\.");
if(v.length == 3)
if(v.length == 3)
{
{
try
try
{
{
major = Integer.parseInt(v[0]);
major = Integer.parseInt(v[0]);
minor = Integer.parseInt(v[1]);
minor = Integer.parseInt(v[1]);
revision = Integer.parseInt(v[2]);
revision = Integer.parseInt(v[2]);
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
throw new MinorException("Invalid versioning!");
throw new MinorException("Invalid versioning!");
}
}
}
}
else
else
{
{
throw new MinorException("Invalid versioning!");
throw new MinorException("Invalid versioning!");
}
}
}
}
public int getMajor()
public int getMajor()
{
{
return major;
return major;
}
}
public int getMinor()
public int getMinor()
{
{
return minor;
return minor;
}
}
public int getRevision()
public int getRevision()
{
{
return minor;
return minor;
}
}
public String getText()
public String getText()
{
{
return this.major+"."+this.minor+"."+this.revision;
return this.major+"."+this.minor+"."+this.revision;
}
}
public void setMajor(int major)
public void setMajor(int major)
{
{
this.major = major;
this.major = major;
}
}
public void setMinor(int minor)
public void setMinor(int minor)
{
{
this.minor = minor;
this.minor = minor;
}
}
public void setRevision(int revision)
public void setRevision(int revision)
{
{
this.revision = revision;
this.revision = revision;
}
}
public boolean isBiggerThan(Version version)
public boolean isBiggerThan(Version version)
{
{
if(major>version.major)
if(major>version.major)
return true;
return true;
else if(major < version.major)
else if(major < version.major)
return false;
return false;
else
else
{
{
if (minor > version.minor)
if (minor > version.minor)
return true;
return true;
else if(minor < version.minor)
else if(minor < version.minor)
return false;
return false;
else
else
{
{
if(revision > version.revision)
if(revision > version.revision)
return true;
return true;
else
else
return false;
return false;
}
}
}
}
}
}
public boolean isEqual(Version version)
public boolean isEqual(Version version)
{
{
return version.major == this.major && version.minor == this.minor && version.revision == this.revision;
return version.major == this.major && version.minor == this.minor && version.revision == this.revision;
}
}
}
}
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
package com.stream_pi.util.xmlconfighelper;
package com.stream_pi.util.xmlconfighelper;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
import javax.xml.transform.Result;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Node;
public class XMLConfigHelper {
public class XMLConfigHelper {
private static Logger logger = Logger.getLogger(XMLConfigHelper.class.getName());
private static Logger logger = Logger.getLogger(XMLConfigHelper.class.getName());
public static String getStringProperty(Element parentElement, String propertyName) throws Exception
public static String getStringProperty(Element parentElement, String propertyName) throws Exception
{
{
return getProperty(parentElement, propertyName, false, null, null);
return getProperty(parentElement, propertyName, false, null, null);
}
}
public static int getIntProperty(Element parentElement, String propertyName) throws Exception
public static int getIntProperty(Element parentElement, String propertyName) throws Exception
{
{
return Integer.parseInt(getProperty(parentElement, propertyName, false, null, null));
return Integer.parseInt(getProperty(parentElement, propertyName, false, null, null));
}
}
public static double getDoubleProperty(Element parentElement, String propertyName) throws Exception
public static double getDoubleProperty(Element parentElement, String propertyName) throws Exception
{
{
return Double.parseDouble(getProperty(parentElement, propertyName, false, null, null));
return Double.parseDouble(getProperty(parentElement, propertyName, false, null, null));
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName) throws Exception
public static boolean getBooleanProperty(Element parentElement, String propertyName) throws Exception
{
{
return getProperty(parentElement, propertyName, false, null, null).equals("true");
return getProperty(parentElement, propertyName, false, null, null).equals("true");
}
}
public static String getProperty(Element parentElement, String propertyName, boolean createNewIfDoesntExist, Document document, File file) throws Exception
public static String getProperty(Element parentElement, String propertyName, boolean createNewIfDoesntExist, Document document, File file) throws Exception
{
{
try {
try {
return parentElement.getElementsByTagName(propertyName).item(0).getTextContent();
return parentElement.getElementsByTagName(propertyName).item(0).getTextContent();
}
}
catch (Exception e)
catch (Exception e)
{
{
logger.warning("CANNOT get property "+parentElement.getNodeName()+"."+propertyName+"!");
logger.warning("CANNOT get property "+parentElement.getNodeName()+"."+propertyName+"!");
if(createNewIfDoesntExist)
if(createNewIfDoesntExist)
{
{
logger.warning("Creating new property by that name ...");
logger.warning("Creating new property by that name ...");
Element newProp = document.createElement(propertyName);
Element newProp = document.createElement(propertyName);
parentElement.appendChild(newProp);
parentElement.appendChild(newProp);
save(document, file);
save(document, file);
}
}
throw e;
throw e;
}
}
}
}
public static void save(Document document, File file) throws Exception
public static void save(Document document, File file) throws Exception
{
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(file);
Result output = new StreamResult(file);
Source input = new DOMSource(document);
Source input = new DOMSource(document);
transformer.transform(input, output);
transformer.transform(input, output);
}
}
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace)
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace)
{
{
return getStringProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getStringProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
String tbr = ifNotPresent;
String tbr = ifNotPresent;
try
try
{
{
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file);
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file);
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static void removeChilds(Node node) {
public static void removeChilds(Node node) {
while (node.hasChildNodes())
while (node.hasChildNodes())
node.removeChild(node.getFirstChild());
node.removeChild(node.getFirstChild());
}
}
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace)
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace)
{
{
return getIntProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getIntProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
int tbr = ifNotPresent;
int tbr = ifNotPresent;
try
try
{
{
tbr = Integer.parseInt(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
tbr = Integer.parseInt(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent)
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent)
{
{
return getDoubleProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
return getDoubleProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
}
}
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace)
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace)
{
{
return getDoubleProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getDoubleProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
double tbr = ifNotPresent;
double tbr = ifNotPresent;
try
try
{
{
tbr = Double.parseDouble(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
tbr = Double.parseDouble(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent)
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent)
{
{
return getStringProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
return getStringProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace)
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace)
{
{
return getBooleanProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getBooleanProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
boolean tbr = ifNotPresent;
boolean tbr = ifNotPresent;
try
try
{
{
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file).equals("true");
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file).equals("true");
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent)
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent)
{
{
return getBooleanProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
return getBooleanProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
}
}
public static boolean doesElementExist(Element parent, String nameOfElement)
public static boolean doesElementExist(Element parent, String nameOfElement)
{
{
return parent.getElementsByTagName(nameOfElement).getLength() > 0;
return parent.getElementsByTagName(nameOfElement).getLength() > 0;
}
}
public static boolean doesElementExist(Document document, String nameOfElement)
public static boolean doesElementExist(Document document, String nameOfElement)
{
{
return document.getElementsByTagName(nameOfElement).getLength() > 0;
return document.getElementsByTagName(nameOfElement).getLength() > 0;
}
}
}
}
module com.stream_pi.util {
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
*/
module com.stream_pi.util
{
requires transitive org.kordamp.ikonli.javafx;
requires transitive org.kordamp.ikonli.javafx;
requires transitive org.kordamp.ikonli.fontawesome5;
requires transitive org.kordamp.ikonli.fontawesome5;
requires transitive javafx.base;
requires transitive javafx.base;
requires transitive java.logging;
requires transitive java.logging;
requires transitive javafx.controls;
requires transitive javafx.controls;
requires transitive java.xml;
requires transitive java.xml;
exports com.stream_pi.util.version;
exports com.stream_pi.util.version;
exports com.stream_pi.util.exception;
exports com.stream_pi.util.exception;
exports com.stream_pi.util.platform;
exports com.stream_pi.util.platform;
exports com.stream_pi.util.uihelper;
exports com.stream_pi.util.uihelper;
exports com.stream_pi.util.startatboot;
exports com.stream_pi.util.startatboot;
exports com.stream_pi.util.alert;
exports com.stream_pi.util.alert;
exports com.stream_pi.util.combobox;
exports com.stream_pi.util.combobox;
exports com.stream_pi.util.xmlconfighelper;
exports com.stream_pi.util.xmlconfighelper;
exports com.stream_pi.util.loggerhelper;
exports com.stream_pi.util.loggerhelper;
exports com.stream_pi.util.iohelper;
exports com.stream_pi.util.iohelper;
}
}