util
Clone or download
Modified Files
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+patreon: streampi
\ No newline at end of file
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,27 @@
+name: Build
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ branches:
+ - master
+
+jobs:
+ build:
+ name: Build
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+
+ - name: Setup Java 11
+ uses: actions/setup-java@v1
+ with:
+ java-version: 11
+
+ - name: Verify project
+ run: mvn clean verify
+
+# TODO: Deploy Snapshots
--- 'a/.gitignore'
+++ b/.gitignore
@@ -1,2 +1,12 @@
+# Maven
+target/
+
+# IntelliJ IDEA
.idea/
-target/
\ No newline at end of file
+*.iml
+
+# Eclipse
+.settings/
+.project
+.factorypath
+.classpath
--- 'a/.idea/.gitignore'
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
--- 'a/.idea/compiler.xml'
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="CompilerConfiguration">
- <annotationProcessing>
- <profile name="Maven default annotation processors profile" enabled="true">
- <sourceOutputDir name="target/generated-sources/annotations" />
- <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
- <outputRelativeToContentRoot value="true" />
- <module name="Util" />
- </profile>
- </annotationProcessing>
- </component>
-</project>
\ No newline at end of file
--- 'a/.idea/discord.xml'
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="DiscordProjectSettings">
- <option name="show" value="PROJECT_FILES" />
- </component>
-</project>
\ No newline at end of file
--- 'a/.idea/encodings.xml'
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="Encoding">
- <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
- </component>
-</project>
\ No newline at end of file
--- 'a/.idea/jarRepositories.xml'
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="RemoteRepositoriesConfiguration">
- <remote-repository>
- <option name="id" value="central" />
- <option name="name" value="Central Repository" />
- <option name="url" value="https://repo.maven.apache.org/maven2" />
- </remote-repository>
- <remote-repository>
- <option name="id" value="central" />
- <option name="name" value="Maven Central repository" />
- <option name="url" value="https://repo1.maven.org/maven2" />
- </remote-repository>
- <remote-repository>
- <option name="id" value="jboss.community" />
- <option name="name" value="JBoss Community repository" />
- <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
- </remote-repository>
- <remote-repository>
- <option name="id" value="central" />
- <option name="name" value="bintray" />
- <option name="url" value="https://jcenter.bintray.com" />
- </remote-repository>
- </component>
-</project>
\ No newline at end of file
--- 'a/.idea/misc.xml'
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="ExternalStorageConfigurationManager" enabled="true" />
- <component name="MavenProjectsManager">
- <option name="originalFiles">
- <list>
- <option value="$PROJECT_DIR$/pom.xml" />
- </list>
- </option>
- </component>
- <component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="GraalVM 11 20.2.0" project-jdk-type="JavaSDK">
- <output url="file://$PROJECT_DIR$/out" />
- </component>
-</project>
\ No newline at end of file
--- 'a/.idea/uiDesigner.xml'
+++ /dev/null
@@ -1,124 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="Palette2">
- <group name="Swing">
- <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
- </item>
- <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
- </item>
- <item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
- </item>
- <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
- <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
- </item>
- <item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
- <initial-values>
- <property name="text" value="Button" />
- </initial-values>
- </item>
- <item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
- <initial-values>
- <property name="text" value="RadioButton" />
- </initial-values>
- </item>
- <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
- <initial-values>
- <property name="text" value="CheckBox" />
- </initial-values>
- </item>
- <item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
- <initial-values>
- <property name="text" value="Label" />
- </initial-values>
- </item>
- <item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
- <preferred-size width="150" height="-1" />
- </default-constraints>
- </item>
- <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
- <preferred-size width="150" height="-1" />
- </default-constraints>
- </item>
- <item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
- <preferred-size width="150" height="-1" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
- </item>
- <item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
- <preferred-size width="150" height="50" />
- </default-constraints>
- </item>
- <item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
- <preferred-size width="200" height="200" />
- </default-constraints>
- </item>
- <item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
- <preferred-size width="200" height="200" />
- </default-constraints>
- </item>
- <item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
- </item>
- <item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
- </item>
- <item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
- </item>
- <item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
- </item>
- <item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
- <preferred-size width="-1" height="20" />
- </default-constraints>
- </item>
- <item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
- <default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
- </item>
- <item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
- <default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
- </item>
- </group>
- </component>
-</project>
\ No newline at end of file
--- 'a/.idea/vcs.xml'
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
- <component name="VcsDirectoryMappings">
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
- </component>
-</project>
\ No newline at end of file
--- /dev/null
+++ b/README.md
@@ -0,0 +1,17 @@
+# util
+
+
+
+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`
+
+
--- 'a/Util.iml'
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
--- 'a/pom.xml'
+++ b/pom.xml
@@ -4,9 +4,11 @@
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>
- <groupId>com.StreamPi</groupId>
- <artifactId>Util</artifactId>
- <version>1.0.0</version>
+ <groupId>com.stream-pi</groupId>
+ <artifactId>util</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <url>https://stream-pi.com/</url>
<build>
<plugins>
@@ -36,20 +38,14 @@
</plugins>
</build>
-
-
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <maven.compiler.source>11</maven.compiler.source>
- <maven.compiler.target>11</maven.compiler.target>
-
+ <maven.compiler.release>11</maven.compiler.release>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
-
- <JavaFXVersion>16-ea+4</JavaFXVersion>
-
+ <JavaFXVersion>16-ea+6</JavaFXVersion>
</properties>
<dependencies>
@@ -72,8 +68,6 @@
<version>${JavaFXVersion}</version>
</dependency>
-
-
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
--- 'a/src/main/java/com/StreamPi/Util/Exception/MinorException.java'
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.StreamPi.Util.Exception;
-
-public class MinorException extends StreamPiException {
-
- public MinorException(String message)
- {
- super(message);
- }
-
- public MinorException(String title, String message)
- {
- super(title, message);
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/Exception/SevereException.java'
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.StreamPi.Util.Exception;
-
-public class SevereException extends StreamPiException{
- public SevereException(String message)
- {
- super(message);
- }
-
- public SevereException(String title, String message)
- {
- super(title, message);
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/Exception/StreamPiException.java'
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.StreamPi.Util.Exception;
-
-public class StreamPiException extends Exception {
- private String title;
- private String message;
-
-
- public StreamPiException(String message)
- {
- super(message);
-
- this.title = "";
- this.message = message;
- }
-
- public StreamPiException(String title, String message)
- {
- super(message);
- this.title = title;
- this.message = message;
- }
-
- public String getShortMessage()
- {
- return message;
- }
-
- public String getTitle()
- {
- return title;
- }
-
- public void setTitle(String title)
- {
- this.title = title;
- }
-
- public void setShortMessage(String message)
- {
- this.message = message;
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/FormHelper/HBoxInputBox.java'
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.StreamPi.Util.FormHelper;
-
-import javafx.geometry.Insets;
-import javafx.scene.control.CheckBox;
-import javafx.scene.control.Label;
-import javafx.scene.control.TextField;
-import javafx.scene.layout.HBox;
-import javafx.scene.layout.Priority;
-import javafx.scene.layout.Region;
-
-public class HBoxInputBox extends HBox {
- private TextField textField;
- public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
- {
- textField.setPrefWidth(prefWidth);
-
- Label label = new Label(labelText);
-
-
- getChildren().addAll(label, new SpaceFiller(SpaceFiller.FillerType.HBox), textField);
-
- if(enablerCheckBox != null)
- {
- textField.disableProperty().bind(enablerCheckBox.selectedProperty());
- HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
- getChildren().add(enablerCheckBox);
- }
-
- this.textField = textField;
- }
-
- public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
- {
- this(labelText, textField, 100, enablerCheckBox);
- }
-
- public HBoxInputBox(String labelText, TextField textField)
- {
- this(labelText, textField, 100, null);
- }
-
- public HBoxInputBox(String labelText, TextField textField, int prefWidth)
- {
- this(labelText, textField, prefWidth, null);
- }
-
-
- public TextField getTextField()
- {
- return textField;
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/FormHelper/HBoxInputBoxWithFileChooser.java'
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.StreamPi.Util.FormHelper;
-
-import javafx.geometry.Insets;
-import javafx.scene.control.Button;
-import javafx.scene.control.CheckBox;
-import javafx.scene.control.Label;
-import javafx.scene.control.TextField;
-import javafx.scene.layout.HBox;
-import javafx.scene.layout.Priority;
-import javafx.scene.layout.Region;
-import javafx.stage.FileChooser;
-import javafx.stage.Window;
-import org.kordamp.ikonli.javafx.FontIcon;
-
-import java.io.File;
-
-public class HBoxInputBoxWithFileChooser extends HBox {
- public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
- {
- textField.setDisable(true);
-
- HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
- setHgrow(hBoxInputBox, Priority.ALWAYS);
- getChildren().addAll(hBoxInputBox);
- setSpacing(5.0);
-
- Button button = new Button();
- FontIcon fontIcon = new FontIcon("far-folder");
- //fontIcon.setIconColor(Paint.valueOf(iconColorHex));
- //fontIcon.setIconSize(iconSize);
- button.setGraphic(fontIcon);
-
- button.setOnAction(event -> {
- FileChooser fileChooser = new FileChooser();
-
- fileChooser.getExtensionFilters().addAll(
- extensionFilter
- );
-
-
- try {
- File selectedDirectory = fileChooser.showOpenDialog(button.getScene().getWindow());
- textField.setText(selectedDirectory.getAbsolutePath());
- }
- catch (NullPointerException e)
- {
- // No folder selected
- }
- });
-
- getChildren().add(button);
-
- if(enablerCheckBox!=null)
- {
- button.disableProperty().bind(enablerCheckBox.selectedProperty());
- HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
- getChildren().add(enablerCheckBox);
- }
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/FormHelper/SpaceFiller.java'
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.StreamPi.Util.FormHelper;
-
-import javafx.scene.layout.HBox;
-import javafx.scene.layout.Priority;
-import javafx.scene.layout.Region;
-import javafx.scene.layout.VBox;
-
-public class SpaceFiller extends Region {
-
- public SpaceFiller(FillerType fillerType)
- {
- if(fillerType == FillerType.HBox)
- {
- HBox.setHgrow(this, Priority.ALWAYS);
- }
- else if(fillerType == FillerType.VBox)
- {
- VBox.setVgrow(this, Priority.ALWAYS);
- }
- }
-
- public enum FillerType
- {
- HBox, VBox
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/Platform/Platform.java'
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.StreamPi.Util.Platform;
-
-public enum Platform {
- WINDOWS, LINUX, MAC, ANDROID, IOS, OTHER;
-
- public static String getUIName(Platform platform)
- {
- switch (platform)
- {
- case WINDOWS: return "Windows";
- case LINUX: return "Linux";
- case MAC: return "MacOS";
- case ANDROID: return "Android";
- case IOS: return "iOS";
- default: return "Unknown";
- }
- }
-}
--- 'a/src/main/java/com/StreamPi/Util/Platform/ReleaseStatus.java'
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
-ReleaseStatus.java
-
-Contributors : Debayan Sutradhar (@dubbadhar)
-
-Enum to store the current status of the Server Release
- */
-package com.StreamPi.Util.Platform;
-
-public enum ReleaseStatus {
- INTERNAL, ALPHA, BETA, STABLE
-}
--- 'a/src/main/java/com/StreamPi/Util/Version/Version.java'
+++ /dev/null
@@ -1,102 +0,0 @@
-package com.StreamPi.Util.Version;
-
-
-import com.StreamPi.Util.Exception.MinorException;
-
-import java.io.Serializable;
-
-public class Version implements Serializable {
- private int major, minor, revision;
-
- public Version()
- {
- major = 0;
- minor = 0;
- revision = 0;
- }
-
- public Version(int major, int minor, int revision)
- {
- this.major = major;
- this.minor = minor;
- this.revision = revision;
- }
-
- public Version(String version) throws MinorException
- {
- String[] v = version.trim().split("\\.");
- if(v.length == 3)
- {
- try
- {
- major = Integer.parseInt(v[0]);
- minor = Integer.parseInt(v[1]);
- revision = Integer.parseInt(v[2]);
- }
- catch (NumberFormatException e)
- {
- throw new MinorException("Invalid versioning!");
- }
- }
- else
- {
- throw new MinorException("Invalid versioning!");
- }
- }
-
- public int getMajor()
- {
- return major;
- }
-
- public int getMinor()
- {
- return minor;
- }
-
- public int getRevision()
- {
- return minor;
- }
-
- public String getText()
- {
- return this.major+"."+this.minor+"."+this.revision;
- }
-
- public void setMajor(int major)
- {
- this.major = major;
- }
-
- public void setMinor(int minor)
- {
- this.minor = minor;
- }
-
- public void setRevision(int revision)
- {
- this.revision = revision;
- }
-
- public boolean isBiggerThan(Version version)
- {
- if(major>version.major)
- return true;
- else
- {
- if(minor > version.minor)
- return true;
- else
- {
- return revision > version.revision;
- }
- }
- }
-
- public boolean isEqual(Version version)
- {
- return version.major == this.major && version.minor == this.minor && version.revision == this.revision;
- }
-
-}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/alert/StreamPiAlert.java
@@ -0,0 +1,306 @@
+/*
+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;
+
+import com.stream_pi.util.uihelper.SpaceFiller;
+import org.kordamp.ikonli.javafx.FontIcon;
+
+import javafx.application.Platform;
+import javafx.collections.ListChangeListener;
+import javafx.geometry.Insets;
+import javafx.scene.Node;
+import javafx.scene.control.Button;
+import javafx.scene.control.Label;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.control.ScrollPane.ScrollBarPolicy;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Pane;
+import javafx.scene.layout.Priority;
+import javafx.scene.layout.VBox;
+
+/**
+ * Custom Alert Dialog for Server and Client
+ */
+public class StreamPiAlert
+{
+ private String title;
+ private String[] buttons;
+ private StreamPiAlertType streamPiAlertType;
+ private Pane contentPane;
+
+ private static StackPane stackPaneParent = null;
+
+ /**
+ * 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.getStyleClass().add("alert_pane_parent");
+ stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
+ {
+ if(stackPaneParent.getChildren().size() > 0)
+ {
+ stackPaneParent.setVisible(true);
+ stackPaneParent.toFront();
+ }
+ else
+ {
+ stackPaneParent.setVisible(false);
+ stackPaneParent.toBack();
+ }
+ });
+ }
+
+ /**
+ * Returns the parent node
+ * @return StackPane parent where the alert boxes will be shown
+ */
+ public static StackPane getParent()
+ {
+ return stackPaneParent;
+ }
+
+ 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,
+ Pane contentPane)
+ {
+ set(title, streamPiAlertType, contentPane, "OK");
+ }
+
+ /**
+ * Sets the Alert type
+ * @param streamPiAlertType Alert Type
+ */
+ public void setStreamPiAlertType(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)
+ {
+ 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)
+ {
+ 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)
+ {
+ 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)
+ {
+ 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)
+ {
+ Label label = new Label(contentText);
+ label.setWrapText(true);
+ VBox vBox = new VBox(label);
+ 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,
+ Pane contentPane, String... buttons)
+ {
+ this.title = title;
+ this.buttons = buttons;
+ this.contentPane = contentPane;
+ this.streamPiAlertType = streamPiAlertType;
+ }
+
+ /**
+ * Set on click Listener
+ * @param streamPiAlertListener Alert Listener, triggered when a button is clicked
+ */
+ public void setOnClicked(StreamPiAlertListener streamPiAlertListener)
+ {
+ this.streamPiAlertListener = streamPiAlertListener;
+ }
+
+ /**
+ * @return Heading of the Alert Box
+ */
+ public String getTitle()
+ {
+ return title;
+ }
+
+ /**
+ * @return Button Choices
+ */
+ public String[] getButtons()
+ {
+ return buttons;
+ }
+
+ /**
+ * @param contentPane Alert Body Node
+ */
+ public void setAlertContent(Pane contentPane)
+ {
+ this.contentPane = contentPane;
+ }
+
+ /**
+ * Set all the button choices
+ * @param buttons Array of button choices
+ */
+ public void setButtons(String... buttons)
+ {
+ this.buttons = buttons;
+ }
+
+ /**
+ * Create and return the final AlertBox Pane, which will be added to the parent node
+ * @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())
+ title = "Alert";
+
+ Label label = new Label(title);
+ label.getStyleClass().add("alert_pane_header_text");
+
+ FontIcon fontIcon = new FontIcon(streamPiAlertType.getIconCode());
+ fontIcon.getStyleClass().addAll("alert_header_icon", streamPiAlertType.getIconStyleClassName());
+
+ HBox header = new HBox(label, SpaceFiller.horizontal(), fontIcon);
+ header.getStyleClass().add("alert_header");
+
+
+ header.setPadding(new Insets(10));
+
+ HBox buttonBar = new HBox();
+ buttonBar.getStyleClass().add("alert_button_bar");
+
+ for (String eachButtonString : buttons)
+ {
+ Button button = new Button(eachButtonString);
+ button.setOnAction(event -> {
+ if(this.streamPiAlertListener != null)
+ {
+ this.streamPiAlertListener.onClick(eachButtonString);
+ }
+ destroy();
+ });
+
+ button.getStyleClass().add("alert_button");
+ buttonBar.getChildren().add(button);
+ }
+
+ ScrollPane scrollPane = new ScrollPane(contentPane);
+ scrollPane.prefHeightProperty().bind(contentPane.heightProperty().add(20));
+ scrollPane.getStyleClass().add("alert_scroll_pane");
+ scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
+ scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
+ VBox.setVgrow(scrollPane, Priority.ALWAYS);
+
+ contentPane.getStyleClass().add("alert_content_pane");
+ contentPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
+
+ VBox alertVBox = new VBox( header, scrollPane, buttonBar);
+ alertVBox.getStyleClass().add("alert_pane");
+ alertVBox.setMaxHeight(Double.NEGATIVE_INFINITY);
+
+ return alertVBox;
+ }
+
+ /**
+ * @return The body node of the Alert Box
+ */
+ public Pane getContentPane()
+ {
+ return contentPane;
+ }
+
+ /**
+ * Adds the Alert Box to the parent node
+ */
+ private Node popupNode;
+ public void show()
+ {
+ Platform.runLater(()->
+ {
+ popupNode = getAlertPane(getTitle(), getContentPane());
+ stackPaneParent.getChildren().add(popupNode);
+ });
+ }
+
+ /**
+ * Removes the alert from the parent pane
+ */
+ public void destroy()
+ {
+ Platform.runLater(()-> stackPaneParent.getChildren().remove(popupNode));
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/alert/StreamPiAlertListener.java
@@ -0,0 +1,27 @@
+/*
+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;
+
+/**
+ * Alert Listener. Triggered when a button on StreamPiAlert is clicked.
+ */
+public abstract class StreamPiAlertListener {
+ /**
+ * @param buttonClicked Button choice which was clicked
+ */
+ public abstract void onClick(String buttonClicked);
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/alert/StreamPiAlertType.java
@@ -0,0 +1,55 @@
+/*
+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;
+
+/**
+ * Stream-Pi Alert Type Enumerator
+ */
+public enum StreamPiAlertType {
+ INFORMATION("fas-info", "alert_information_icon"),
+ WARNING("fas-exclamation-triangle", "alert_warning_icon"),
+ ERROR("fas-times", "alert_error_icon");
+
+ private final String fontAwesomeIconCode;
+ private final String alertIconStyleClassName;
+
+ /**
+ * @param fontAwesomeIconCode Ikonli Font Icon code
+ * @param alertIconStyleClassName Icon CSS Style Class
+ */
+ StreamPiAlertType(String fontAwesomeIconCode, String alertIconStyleClassName)
+ {
+ this.fontAwesomeIconCode = fontAwesomeIconCode;
+ this.alertIconStyleClassName = alertIconStyleClassName;
+ }
+
+ /**
+ * @return Ikonli Font Icon code
+ */
+ public String getIconCode()
+ {
+ return fontAwesomeIconCode;
+ }
+
+ /**
+ * @return Icon CSS Style Class
+ */
+ public String getIconStyleClassName()
+ {
+ return alertIconStyleClassName;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/combobox/StreamPiComboBox.java
@@ -0,0 +1,255 @@
+/*
+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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.stream_pi.util.uihelper.SpaceFiller;
+
+import org.kordamp.ikonli.javafx.FontIcon;
+
+import javafx.application.Platform;
+import javafx.collections.ListChangeListener;
+import javafx.scene.Node;
+import javafx.scene.control.Label;
+import javafx.scene.control.ScrollPane;
+import javafx.scene.control.ToggleButton;
+import javafx.scene.control.ScrollPane.ScrollBarPolicy;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBox;
+
+/**
+ * Custom Combo Box for Server and Client
+ * @param <T> Combo Box List Type
+ */
+public class StreamPiComboBox<T> extends HBox
+{
+ private List<T> options;
+ 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) {
+ stackPaneParent = parent;
+ stackPaneParent.getStyleClass().add("combo_box_pane_parent");
+ stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
+ {
+ if(stackPaneParent.getChildren().size() > 0)
+ {
+ stackPaneParent.setVisible(true);
+ stackPaneParent.toFront();
+ }
+ else
+ {
+ stackPaneParent.setVisible(false);
+ stackPaneParent.toBack();
+ }
+ });
+ }
+
+ /**
+ * Constructor to create Combo Box with all the options
+ * @param options List of Options
+ */
+ public StreamPiComboBox(List<T> options)
+ {
+ setup();
+ setOptions(options);
+ }
+
+ /**
+ * @return List of Combo Box Options
+ */
+ public List<T> getOptions()
+ {
+ return options;
+ }
+
+ /**
+ * Constructor to create Combo Box with empty list
+ */
+ public StreamPiComboBox()
+ {
+ setup();
+ }
+
+ private Label currentSelectedLabel;
+
+ /**
+ * init of Combo Box
+ */
+ private void setup()
+ {
+ buttons = new ArrayList<>();
+
+ getStyleClass().add("combo_box");
+ setOnMouseClicked(event -> show());
+
+ currentSelectedLabel = new Label();
+ currentSelectedLabel.getStyleClass().add("combo_box_current_selected_label");
+
+ FontIcon fontIcon = new FontIcon();
+ fontIcon.getStyleClass().add("combo_box_drop_down_icon");
+
+ getChildren().addAll(
+ currentSelectedLabel,
+ SpaceFiller.horizontal(),
+ fontIcon
+ );
+ }
+
+ /**
+ * Set Combo Box options
+ * @param options Combo Box Options
+ */
+ public void setOptions(List<T> options)
+ {
+ this.options = options;
+ setCurrentSelectedItemIndex(0);
+ }
+
+ private int currentIndex = 0;
+ private List<ToggleButton> buttons;
+
+ /**
+ * @return Final Scroll Pane
+ */
+ public ScrollPane getPopupScrollPane()
+ {
+ buttons.clear();
+
+ ScrollPane scrollPane = new ScrollPane();
+ scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
+ scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
+ scrollPane.getStyleClass().add("combo_box_popup");
+
+ VBox vBox = new VBox();
+ vBox.getStyleClass().add("combo_box_popup_vbox");
+ vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
+
+ scrollPane.maxHeightProperty().bind(vBox.heightProperty().add(20));
+
+ scrollPane.setContent(vBox);
+
+ //scrollPane.setMaxHeight(Double.NEGATIVE_INFINITY);
+
+ for(int i = 0;i<options.size();i++)
+ {
+ T eachOptionObj = options.get(i);
+ String displayText = streamPiComboBoxFactory.getOptionDisplayText(eachOptionObj);
+
+ ToggleButton optionButton = new ToggleButton(displayText);
+ optionButton.getStyleClass().add("combo_box_list_option_button");
+ optionButton.setSelected(i == currentIndex);
+ optionButton.setUserData(i);
+ optionButton.setOnAction(event->
+ {
+ setCurrentSelectedItemIndex((int) optionButton.getUserData());
+
+ if(streamPiComboBoxListener != null)
+ streamPiComboBoxListener.onNewItemSelected(options.get(currentIndex));
+
+ destroy();
+ });
+ vBox.getChildren().addAll(optionButton);
+ buttons.add(optionButton);
+ }
+
+ return scrollPane;
+ }
+
+ /**
+ * @return Current Selected Option Index
+ */
+ public int getCurrentIndex()
+ {
+ return currentIndex;
+ }
+
+ /**
+ * @return Current Selected Item
+ */
+ public T getCurrentSelectedItem()
+ {
+ return options.get(currentIndex);
+ }
+
+ /**
+ * @param index Current item index to be selected
+ */
+ public void setCurrentSelectedItemIndex(int index)
+ {
+ this.currentIndex = index;
+ setCurrentSelectedLabelText(streamPiComboBoxFactory.getOptionDisplayText(options.get(index)));
+ }
+
+ /**
+ * @param text Name of the option
+ */
+ private void setCurrentSelectedLabelText(String text)
+ {
+ currentSelectedLabel.setText(text);
+ }
+
+ 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)
+ {
+ this.streamPiComboBoxListener = streamPiComboBoxListener;
+ }
+
+ private Node popupNode;
+
+ /**
+ * Adds the Combo Box to the parent node
+ */
+ public void show()
+ {
+ Platform.runLater(()->{
+ popupNode = getPopupScrollPane();
+ stackPaneParent.getChildren().add(popupNode);
+ });
+ }
+
+ /**
+ * Removes the combo box from the parent pane
+ */
+ public void destroy()
+ {
+ Platform.runLater(()->{
+ stackPaneParent.getChildren().remove(popupNode);
+ });
+ }
+
+ private StreamPiComboBoxFactory<T> streamPiComboBoxFactory;
+
+ /**
+ * @param streamPiComboBoxFactory Factory for the Combo Box
+ */
+ public void setStreamPiComboBoxFactory(StreamPiComboBoxFactory<T> streamPiComboBoxFactory)
+ {
+ this.streamPiComboBoxFactory = streamPiComboBoxFactory;
+ }
+}
\ No newline at end of file
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/combobox/StreamPiComboBoxFactory.java
@@ -0,0 +1,30 @@
+/*
+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;
+
+/**
+ * Factory Class for Stream Pi Combo Box
+ * @param <T> Option Type
+ */
+public abstract class StreamPiComboBoxFactory<T>
+{
+ /**
+ * @param object Combo Box Option
+ * @return Label Text
+ */
+ public abstract String getOptionDisplayText(T object);
+}
\ No newline at end of file
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/combobox/StreamPiComboBoxListener.java
@@ -0,0 +1,27 @@
+/*
+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;
+
+/**
+ * Combo Box Listener. Triggered when an option in Combo Box is clicked.
+ */
+public abstract class StreamPiComboBoxListener<T> {
+ /**
+ * @param selectedItem Choice which was clicked
+ */
+ public abstract void onNewItemSelected(T selectedItem);
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/comms/Message.java
@@ -0,0 +1,47 @@
+package com.stream_pi.util.comms;
+
+import java.io.Serializable;
+
+public class Message implements Serializable
+{
+ private String header;
+ private MessageType messageType;
+ private Object value;
+
+ public Message(String header, MessageType messageType, Object value)
+ {
+ this.header = header;
+ this.messageType = messageType;
+ this.value = value;
+ }
+
+ public void setHeader(String header)
+ {
+ this.header = header;
+ }
+
+ public void setMessageType(MessageType messageType)
+ {
+ this.messageType = messageType;
+ }
+
+ public void setValue(Object value)
+ {
+ this.value = value;
+ }
+
+ public String getHeader()
+ {
+ return header;
+ }
+
+ public MessageType getMessageType()
+ {
+ return messageType;
+ }
+
+ public Object getValue()
+ {
+ return value;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/comms/MessageType.java
@@ -0,0 +1,8 @@
+package com.stream_pi.util.comms;
+
+import java.io.Serializable;
+
+public enum MessageType implements Serializable
+{
+ ICON, STRING_ARRAY;
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/exception/MinorException.java
@@ -0,0 +1,30 @@
+/*
+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;
+
+public class MinorException extends StreamPiException {
+
+ public MinorException(String message)
+ {
+ super(message);
+ }
+
+ public MinorException(String title, String message)
+ {
+ super(title, message);
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/exception/SevereException.java
@@ -0,0 +1,30 @@
+/*
+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;
+
+public class SevereException extends StreamPiException {
+
+ public SevereException(String message)
+ {
+ super(message);
+ }
+
+ public SevereException(String title, String message)
+ {
+ super(title, message);
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/exception/StreamPiException.java
@@ -0,0 +1,58 @@
+/*
+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;
+
+public class StreamPiException extends Exception {
+
+ private String title;
+ private String message;
+
+ public StreamPiException(String message)
+ {
+ super(message);
+
+ this.title = "";
+ this.message = message;
+ }
+
+ public StreamPiException(String title, String message)
+ {
+ super(message);
+ this.title = title;
+ this.message = message;
+ }
+
+ public String getShortMessage()
+ {
+ return message;
+ }
+
+ public String getTitle()
+ {
+ return title;
+ }
+
+ public void setTitle(String title)
+ {
+ this.title = title;
+ }
+
+ public void setShortMessage(String message)
+ {
+ this.message = message;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/iohelper/IOHelper.java
@@ -0,0 +1,66 @@
+/*
+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;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+public class IOHelper {
+
+ public static void unzip(InputStream inputStream, String destDir) throws Exception {
+ File dir = new File(destDir);
+ // create output directory if it doesn't exist
+ if(!dir.exists()) dir.mkdirs();
+ InputStream fis;
+ //buffer for read and write data to file
+ byte[] buffer = new byte[1024];
+
+ fis = inputStream;
+ ZipInputStream zis = new ZipInputStream(fis);
+ ZipEntry ze = zis.getNextEntry();
+ while(ze != null){
+ String fileName = ze.getName();
+
+ File newFile = new File(destDir + File.separator + fileName);
+
+ if(ze.isDirectory())
+ {
+ newFile.mkdirs();
+ }
+ else
+ {
+ FileOutputStream fos = new FileOutputStream(newFile);
+ int len;
+ while ((len = zis.read(buffer)) > 0)
+ {
+ fos.write(buffer, 0, len);
+ }
+ fos.close();
+ }
+ //close this ZipEntry
+ zis.closeEntry();
+ ze = zis.getNextEntry();
+ }
+ //close last ZipEntry
+ zis.closeEntry();
+ zis.close();
+ fis.close();
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/loggerhelper/StreamPiLogFallbackHandler.java
@@ -0,0 +1,34 @@
+/*
+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;
+
+import java.util.logging.ConsoleHandler;
+
+public class StreamPiLogFallbackHandler extends ConsoleHandler{
+
+ public StreamPiLogFallbackHandler() throws Exception
+ {
+ super();
+
+ setFormatter(new StreamPiLogFormatter());
+ }
+
+ public void closeHandler()
+ {
+ close();
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/loggerhelper/StreamPiLogFileHandler.java
@@ -0,0 +1,35 @@
+/*
+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;
+
+import java.util.logging.FileHandler;
+
+public class StreamPiLogFileHandler extends FileHandler {
+
+ public StreamPiLogFileHandler(String logFilePath) throws Exception
+ {
+ super(logFilePath, false);
+
+ setFormatter(new StreamPiLogFormatter());
+ }
+
+ public void closeHandler()
+ {
+ close();
+ }
+
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/loggerhelper/StreamPiLogFormatter.java
@@ -0,0 +1,28 @@
+/*
+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;
+
+import java.util.logging.LogRecord;
+import java.util.logging.SimpleFormatter;
+
+public class StreamPiLogFormatter extends SimpleFormatter{
+ @Override
+ public String format(LogRecord record)
+ {
+ return "["+Thread.currentThread().getName()+"] :: "+ record.getSourceClassName()+"@"+record.getSourceMethodName()+" -> " + ":" + record.getLevel() + " = "+ record.getMessage() + "\n";
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/platform/Platform.java
@@ -0,0 +1,39 @@
+/*
+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;
+
+public enum Platform {
+ WINDOWS("Windows"),
+ LINUX("Linux"),
+ MAC("MacOS"),
+ ANDROID("Android"),
+ IOS("iOS"),
+ LINUX_RPI("Raspberry Pi"),
+ UNKNOWN("Unknown");
+
+ final private String UIName;
+
+ Platform(String UIName)
+ {
+ this.UIName = UIName;
+ }
+
+ public String getUIName()
+ {
+ return UIName;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/platform/ReleaseStatus.java
@@ -0,0 +1,36 @@
+/*
+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;
+
+public enum ReleaseStatus {
+
+ EA("Early Access"),
+ GA("General Availability");
+
+ private final String UIName;
+
+ ReleaseStatus(String UIName)
+ {
+ this.UIName = UIName;
+ }
+
+ public String getUIName()
+ {
+ return UIName;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/startatboot/SoftwareType.java
@@ -0,0 +1,21 @@
+/*
+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;
+
+public enum SoftwareType {
+ SERVER, CLIENT
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/startatboot/StartAtBoot.java
@@ -0,0 +1,153 @@
+/*
+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;
+
+import com.stream_pi.util.platform.Platform;
+import com.stream_pi.util.exception.MinorException;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+
+public class StartAtBoot {
+
+ SoftwareType softwareType;
+ Platform platform;
+
+ public StartAtBoot(SoftwareType softwareType, Platform platform)
+ {
+ this.softwareType = softwareType;
+ this.platform = platform;
+ }
+
+ public void create(File runnerFile) throws MinorException
+ {
+ if(platform == Platform.WINDOWS)
+ createStarterForWindows(runnerFile);
+ else if(platform == Platform.LINUX || platform == Platform.LINUX_RPI)
+ createStarterForLinux(runnerFile);
+ else if(platform == Platform.MAC)
+ createStarterForMac(runnerFile);
+ else if(platform == Platform.UNKNOWN)
+ unknownPlatformException();
+ }
+
+ public boolean delete() throws MinorException {
+ if(platform == Platform.WINDOWS)
+ return deleteStarterForWindows();
+ else if (platform == Platform.LINUX || platform == Platform.LINUX_RPI)
+ return deleteStarterForLinux();
+ else if(platform == Platform.MAC)
+ deleteStarterForMac();
+ else if(platform == Platform.UNKNOWN)
+ unknownPlatformException();
+
+ return false;
+ }
+
+ private void createStarterForLinux(File runnerFile) throws MinorException
+ {
+ try
+ {
+ String sysDDirectoryPath = System.getProperty("user.home")+"/.local/share/systemd/user/";
+
+ File sysDDirectoryFile = new File(sysDDirectoryPath);
+
+ if(!sysDDirectoryFile.exists())
+ sysDDirectoryFile.mkdirs();
+
+ File sysDServiceFile = new File(sysDDirectoryPath+"stream-pi-"+ softwareType+".service");
+
+ FileWriter fw = new FileWriter(sysDServiceFile);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write("[Unit]\n" +
+ "Description=Stream-Pi "+softwareType+"\n" +
+ "[Service]\n" +
+ "Type=oneshot\n" +
+ "WorkingDirectory="+runnerFile.getAbsoluteFile().getParent()+"\n" +
+ "ExecStart="+runnerFile.getAbsoluteFile().getParent()+"/"+runnerFile.getName()+"\n" +
+ "[Install]\n" +
+ "WantedBy=default.target\n");
+ bw.close();
+
+ Runtime.getRuntime().exec("systemctl --user daemon-reload");
+ Runtime.getRuntime().exec("systemctl --user enable stream-pi-"+softwareType+".service");
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new MinorException("Unable to set start at boot",e.getMessage());
+ }
+ }
+
+ private boolean deleteStarterForLinux() throws MinorException
+ {
+ try
+ {
+ boolean f1 = new File(System.getProperty("user.home")+"/.local/share/systemd/user/stream-pi-"+
+ softwareType+".service").delete();
+
+ Runtime.getRuntime().exec("systemctl --user daemon-reload");
+
+ return f1;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new MinorException("Unable to unset start at boot",e.getMessage());
+ }
+ }
+
+ private void createStarterForWindows(File runnerFile) throws MinorException
+ {
+ File initFile = new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat");
+
+ try
+ {
+ FileWriter fw = new FileWriter(initFile);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write("cd "+runnerFile.getAbsoluteFile().getParent()+"\n" +
+ runnerFile.getName());
+ bw.close();
+ }
+ catch (Exception e)
+ {
+ throw new MinorException(e.getMessage());
+ }
+ }
+
+ private boolean deleteStarterForWindows()
+ {
+ return new File(System.getenv("APPDATA")+"/Microsoft/Windows/Start Menu/Programs/Startup/streampi_starter_"+ softwareType +".bat").delete();
+ }
+
+
+ private void createStarterForMac(File runnerFile) throws MinorException
+ {
+ throw new MinorException("Mac Starter feature is not implemented yet.");
+ }
+
+ private void deleteStarterForMac() throws MinorException
+ {
+ throw new MinorException("Mac Starter feature is not implemented yet.");
+ }
+
+ private void unknownPlatformException() throws MinorException
+ {
+ throw new MinorException("Cannot implemented starter feature. Unknown platform.");
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/uihelper/HBoxInputBox.java
@@ -0,0 +1,63 @@
+/*
+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;
+
+import javafx.geometry.Insets;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.Label;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.HBox;
+
+public class HBoxInputBox extends HBox {
+
+ private TextField textField;
+
+ public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
+ {
+ textField.setPrefWidth(prefWidth);
+ Label label = new Label(labelText);
+ getChildren().addAll(label, SpaceFiller.horizontal(), textField);
+
+ if(enablerCheckBox != null)
+ {
+ textField.disableProperty().bind(enablerCheckBox.selectedProperty());
+ HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
+ getChildren().add(enablerCheckBox);
+ }
+ this.textField = textField;
+ }
+
+ public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
+ {
+ this(labelText, textField, 100, enablerCheckBox);
+ }
+
+ public HBoxInputBox(String labelText, TextField textField)
+ {
+ this(labelText, textField, 100, null);
+ }
+
+ public HBoxInputBox(String labelText, TextField textField, int prefWidth)
+ {
+ this(labelText, textField, prefWidth, null);
+ }
+
+ public TextField getTextField()
+ {
+ return textField;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/uihelper/HBoxInputBoxWithFileChooser.java
@@ -0,0 +1,72 @@
+/*
+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;
+
+import javafx.geometry.Insets;
+import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
+import javafx.scene.control.TextField;
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
+import javafx.stage.FileChooser;
+import org.kordamp.ikonli.javafx.FontIcon;
+
+import java.io.File;
+
+public class HBoxInputBoxWithFileChooser extends HBox {
+
+ public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
+ {
+ textField.setDisable(true);
+
+ HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
+ setHgrow(hBoxInputBox, Priority.ALWAYS);
+ getChildren().addAll(hBoxInputBox);
+ setSpacing(5.0);
+
+ Button button = new Button();
+ FontIcon fontIcon = new FontIcon("far-folder");
+ //fontIcon.setIconColor(Paint.valueOf(iconColorHex));
+ //fontIcon.setIconSize(iconSize);
+ button.setGraphic(fontIcon);
+
+ button.setOnAction(event -> {
+ FileChooser fileChooser = new FileChooser();
+ fileChooser.getExtensionFilters().addAll(
+ extensionFilter
+ );
+
+ try {
+ File selectedDirectory = fileChooser.showOpenDialog(button.getScene().getWindow());
+ textField.setText(selectedDirectory.getAbsolutePath());
+ }
+ catch (NullPointerException e)
+ {
+ // No folder selected
+ }
+ });
+
+ getChildren().add(button);
+
+ if(enablerCheckBox!=null)
+ {
+ button.disableProperty().bind(enablerCheckBox.selectedProperty());
+ HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
+ getChildren().add(enablerCheckBox);
+ }
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/uihelper/SpaceFiller.java
@@ -0,0 +1,39 @@
+/*
+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;
+
+import javafx.scene.layout.HBox;
+import javafx.scene.layout.Priority;
+import javafx.scene.layout.Region;
+import javafx.scene.layout.VBox;
+
+public class SpaceFiller {
+
+ public static Region horizontal()
+ {
+ final Region region = new Region();
+ HBox.setHgrow(region, Priority.ALWAYS);
+ return region;
+ }
+
+ public static Region vertical()
+ {
+ final Region region = new Region();
+ VBox.setVgrow(region, Priority.ALWAYS);
+ return region;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/version/Version.java
@@ -0,0 +1,122 @@
+/*
+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;
+
+
+import com.stream_pi.util.exception.MinorException;
+
+import java.io.Serializable;
+
+public class Version implements Serializable {
+ private int major, minor, revision;
+
+ public Version()
+ {
+ major = 0;
+ minor = 0;
+ revision = 0;
+ }
+
+ public Version(int major, int minor, int revision)
+ {
+ this.major = major;
+ this.minor = minor;
+ this.revision = revision;
+ }
+
+ public Version(String version) throws MinorException
+ {
+ String[] v = version.trim().split("\\.");
+ if(v.length == 3)
+ {
+ try
+ {
+ major = Integer.parseInt(v[0]);
+ minor = Integer.parseInt(v[1]);
+ revision = Integer.parseInt(v[2]);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new MinorException("Invalid versioning!");
+ }
+ }
+ else
+ {
+ throw new MinorException("Invalid versioning!");
+ }
+ }
+
+ public int getMajor()
+ {
+ return major;
+ }
+
+ public int getMinor()
+ {
+ return minor;
+ }
+
+ public int getRevision()
+ {
+ return minor;
+ }
+
+ public String getText()
+ {
+ return this.major+"."+this.minor+"."+this.revision;
+ }
+
+ public void setMajor(int major)
+ {
+ this.major = major;
+ }
+
+ public void setMinor(int minor)
+ {
+ this.minor = minor;
+ }
+
+ public void setRevision(int revision)
+ {
+ this.revision = revision;
+ }
+
+ public boolean isBiggerThan(Version version)
+ {
+ if (major == version.major)
+ {
+ if (minor == version.minor)
+ {
+ return revision > version.revision;
+ }
+ else
+ {
+ return minor > version.minor;
+ }
+ }
+ else
+ {
+ return major > version.major;
+ }
+ }
+
+ public boolean isEqual(Version version)
+ {
+ return version.major == this.major && version.minor == this.minor && version.revision == this.revision;
+ }
+
+}
--- /dev/null
+++ b/src/main/java/com/stream_pi/util/xmlconfighelper/XMLConfigHelper.java
@@ -0,0 +1,207 @@
+/*
+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;
+
+import java.io.File;
+import java.util.logging.Logger;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class XMLConfigHelper {
+
+ private static final Logger logger = Logger.getLogger(XMLConfigHelper.class.getName());
+
+ public static String getStringProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return getProperty(parentElement, propertyName, false, null, null);
+ }
+
+ public static int getIntProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return Integer.parseInt(getProperty(parentElement, propertyName, false, null, null));
+ }
+
+
+ public static double getDoubleProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return Double.parseDouble(getProperty(parentElement, propertyName, false, null, null));
+ }
+
+
+ public static boolean getBooleanProperty(Element parentElement, String propertyName) throws Exception
+ {
+ 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
+ {
+ try {
+ return parentElement.getElementsByTagName(propertyName).item(0).getTextContent();
+ }
+ catch (Exception e)
+ {
+ logger.warning("CANNOT get property "+parentElement.getNodeName()+"."+propertyName+"!");
+
+ if (createNewIfDoesntExist)
+ {
+ logger.warning("Creating new property by that name ...");
+ Element newProp = document.createElement(propertyName);
+ parentElement.appendChild(newProp);
+ save(document, file);
+ }
+ throw e;
+ }
+ }
+
+ public static void save(Document document, File file) throws Exception
+ {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ Result output = new StreamResult(file);
+ Source input = new DOMSource(document);
+ transformer.transform(input, output);
+ }
+
+ public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace)
+ {
+ return getStringProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
+ }
+
+
+ public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
+ Document document, File file)
+ {
+ String tbr = ifNotPresent;
+ try
+ {
+ tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file);
+ }
+ catch(Exception e)
+ {
+ if(printStackTrace)
+ e.printStackTrace();
+ }
+ return tbr;
+ }
+
+
+ public static void removeChilds(Node node) {
+ while (node.hasChildNodes())
+ node.removeChild(node.getFirstChild());
+ }
+
+ public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace)
+ {
+ return getIntProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
+ }
+
+
+ public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
+ Document document, File file)
+ {
+ int tbr = ifNotPresent;
+
+ try
+ {
+ tbr = Integer.parseInt(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
+ }
+ catch(Exception e)
+ {
+ if(printStackTrace)
+ e.printStackTrace();
+ }
+ return tbr;
+ }
+
+ public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent)
+ {
+ return getDoubleProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
+ }
+
+ public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace)
+ {
+ return getDoubleProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
+ }
+
+ public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
+ Document document, File file)
+ {
+ double tbr = ifNotPresent;
+
+ try
+ {
+ tbr = Double.parseDouble(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
+ }
+ catch(Exception e)
+ {
+ if(printStackTrace)
+ e.printStackTrace();
+ }
+ return tbr;
+ }
+
+ public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent)
+ {
+ return getStringProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
+ }
+
+ public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace)
+ {
+ return getBooleanProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
+ }
+
+ public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
+ Document document, File file)
+ {
+ boolean tbr = ifNotPresent;
+
+ try
+ {
+ tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file).equals("true");
+ }
+ catch(Exception e)
+ {
+ if(printStackTrace)
+ e.printStackTrace();
+ }
+ return tbr;
+ }
+
+ public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent)
+ {
+ return getBooleanProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
+ }
+
+ public static boolean doesElementExist(Element parent, String nameOfElement)
+ {
+ return parent.getElementsByTagName(nameOfElement).getLength() > 0;
+ }
+
+ public static boolean doesElementExist(Document document, String nameOfElement)
+ {
+ return document.getElementsByTagName(nameOfElement).getLength() > 0;
+ }
+}
--- 'a/src/main/java/module-info.java'
+++ b/src/main/java/module-info.java
@@ -1,12 +1,37 @@
-module com.StreamPi.Util {
+/*
+Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
+Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
- requires org.kordamp.ikonli.javafx;
- requires org.kordamp.ikonli.fontawesome5;
- requires javafx.base;
- requires javafx.controls;
+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.
- exports com.StreamPi.Util.Version;
- exports com.StreamPi.Util.Exception;
- exports com.StreamPi.Util.Platform;
- exports com.StreamPi.Util.FormHelper;
+Originally Written by : Debayan Sutradhar (rnayabed)
+*/
+
+module com.stream_pi.util
+{
+ requires transitive org.kordamp.ikonli.javafx;
+ requires transitive org.kordamp.ikonli.fontawesome5;
+ requires transitive javafx.base;
+ requires transitive java.logging;
+ requires transitive javafx.controls;
+ requires transitive java.xml;
+
+ exports com.stream_pi.util.version;
+ exports com.stream_pi.util.exception;
+ exports com.stream_pi.util.platform;
+ exports com.stream_pi.util.uihelper;
+ exports com.stream_pi.util.startatboot;
+ exports com.stream_pi.util.alert;
+ exports com.stream_pi.util.combobox;
+ exports com.stream_pi.util.xmlconfighelper;
+ exports com.stream_pi.util.loggerhelper;
+ exports com.stream_pi.util.iohelper;
+ exports com.stream_pi.util.comms;
}
\ No newline at end of file