util

Clone or download

added Custom logger helpers

Modified Files

M .gitignore
+8 −1
--- 'a/.gitignore'
+++ b/.gitignore
@@ -1,2 +1,9 @@
.idea/
-target/
\ No newline at end of file
+target/
+Util.iml
+
+
+.settings/
+.project
+.factorypath
+.classpath
D .idea/.gitignore
+0 −3
--- 'a/.idea/.gitignore'
+++ /dev/null
@@ -1,3 +0,0 @@
-# Default ignored files
-/shelf/
-/workspace.xml
D .idea/compiler.xml
+0 −13
--- '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
D .idea/discord.xml
+0 −6
--- '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
D .idea/misc.xml
+0 −14
--- '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
D .idea/uiDesigner.xml
+0 −124
--- '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
D .idea/vcs.xml
+0 −6
--- '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
D Util.iml
+0 −2
--- '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
M pom.xml
+3 −29
--- 'a/pom.xml'
+++ b/pom.xml
@@ -8,6 +8,8 @@
<artifactId>Util</artifactId>
<version>1.0.0</version>
+ <url>https://stream-pi.com/</url>
+
<build>
<plugins>
<plugin>
@@ -43,45 +45,17 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
- <CommonsBeanUtilsVersion>1.9.4</CommonsBeanUtilsVersion>
- <CommonsConfigurationVersion>2.7</CommonsConfigurationVersion>
-
- <SL4JVersion>1.7.30</SL4JVersion>
-
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
- <JavaFXVersion>16-ea+4</JavaFXVersion>
+ <JavaFXVersion>16-ea+5</JavaFXVersion>
</properties>
<dependencies>
<dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils</artifactId>
- <version>${CommonsBeanUtilsVersion}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-configuration2</artifactId>
- <version>${CommonsConfigurationVersion}</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>${SL4JVersion}</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${SL4JVersion}</version>
- </dependency>
- <dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${IkonliFA5PackVersion}</version>
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/Alert/StreamPiAlert.java
@@ -0,0 +1,205 @@
+package com.StreamPi.Util.Alert;
+
+import com.StreamPi.Util.FormHelper.SpaceFiller;
+import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
+import com.StreamPi.Util.Platform.Platform;
+
+import org.kordamp.ikonli.javafx.FontIcon;
+
+import javafx.collections.ListChangeListener;
+import javafx.geometry.Insets;
+import javafx.geometry.Pos;
+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.Region;
+import javafx.scene.layout.VBox;
+
+public class StreamPiAlert {
+ private String title;
+ private String[] buttons;
+ private StreamPiAlertType streamPiAlertType;
+ private Pane contentPane;
+
+ private static StackPane stackPaneParent = null;
+
+ public static void setParent(StackPane parent) {
+ stackPaneParent = parent;
+
+ stackPaneParent.getStyleClass().add("alert_pane_parent");
+
+ stackPaneParent.getChildren().addListener(new ListChangeListener<Node>()
+ {
+ @Override
+ public void onChanged(Change<? extends Node> c) {
+ if(stackPaneParent.getChildren().size() > 0)
+ {
+ stackPaneParent.setVisible(true);
+ stackPaneParent.toFront();
+ }
+ else
+ {
+ stackPaneParent.setVisible(false);
+ stackPaneParent.toBack();
+ }
+ }
+ });
+ }
+
+ public static StackPane getParent() {
+ return stackPaneParent;
+ }
+
+ private StreamPiAlertListener streamPiAlertListener = null;
+
+ public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
+ Pane contentPane) {
+ set(title, streamPiAlertType, contentPane, new String[]{ "OK" });
+ }
+
+ public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
+ {
+ this.streamPiAlertType = streamPiAlertType;
+ }
+
+ public StreamPiAlert(String title, String contentText)
+ {
+ Label label = new Label(contentText);
+ label.setWrapText(true);
+
+ VBox vBox = new VBox(label);
+
+ set(title, StreamPiAlertType.INFORMATION, vBox, new String[]{ "OK" });
+ }
+
+ public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, String... buttons)
+ {
+ set(title, streamPiAlertType, null, new String[]{ "OK" });
+ }
+
+
+ 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, new String[]{ "OK" });
+ }
+
+ private void set(String title, StreamPiAlertType streamPiAlertType,
+ Pane contentPane, String... buttons)
+ {
+ this.title = title;
+ this.buttons = buttons;
+ this.contentPane = contentPane;
+ this.streamPiAlertType = streamPiAlertType;
+ }
+
+
+ public void setOnClicked(StreamPiAlertListener streamPiAlertListener) {
+ this.streamPiAlertListener = streamPiAlertListener;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public String[] getButtons() {
+ return buttons;
+ }
+
+ public void setAlertContent(Pane contentPane) {
+ this.contentPane = contentPane;
+ }
+
+ public void setButtons(String... buttons) {
+ this.buttons = buttons;
+ }
+
+ public VBox getAlertPane(String title, Pane alertPane) {
+ VBox alertVBox = new VBox();
+ alertVBox.getStyleClass().add("alert_pane");
+
+ 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, new SpaceFiller(FillerType.HBox), 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);
+ }
+
+ alertPane.getStyleClass().add("alert_content_pane");
+
+ ScrollPane scrollPane = new ScrollPane(alertPane);
+ scrollPane.getStyleClass().add("alert_scroll_pane");
+
+ alertPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
+
+ scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
+ scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
+
+ VBox.setVgrow(scrollPane, Priority.ALWAYS);
+
+ alertVBox.getChildren().addAll(
+ header,
+ scrollPane,
+ buttonBar
+ );
+
+
+ return alertVBox;
+ }
+
+ public Pane getContentPane()
+ {
+ return contentPane;
+ }
+
+ private Node popupNode;
+ public void show()
+ {
+ javafx.application.Platform.runLater(()->{
+ popupNode = getAlertPane(getTitle(), getContentPane());
+ stackPaneParent.getChildren().add(popupNode);
+ });
+ }
+
+ public void destroy()
+ {
+ javafx.application.Platform.runLater(()->{
+ stackPaneParent.getChildren().remove(popupNode);
+ });
+ }
+}
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/Alert/StreamPiAlertListener.java
@@ -0,0 +1,5 @@
+package com.StreamPi.Util.Alert;
+
+public abstract class StreamPiAlertListener {
+ public abstract void onClick(String buttonClicked);
+}
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/Alert/StreamPiAlertType.java
@@ -0,0 +1,30 @@
+package com.StreamPi.Util.Alert;
+
+import org.kordamp.ikonli.javafx.FontIcon;
+
+import javafx.scene.paint.Paint;
+
+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;
+
+ StreamPiAlertType(String fontAwesomeIconCode, String alertIconStyleClassName)
+ {
+ this.fontAwesomeIconCode = fontAwesomeIconCode;
+ this.alertIconStyleClassName = alertIconStyleClassName;
+ }
+
+ public String getIconCode()
+ {
+ return fontAwesomeIconCode;
+ }
+
+ public String getIconStyleClassName()
+ {
+ return alertIconStyleClassName;
+ }
+}
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/ComboBox/StreamPiComboBox.java
@@ -0,0 +1,188 @@
+package com.StreamPi.Util.ComboBox;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.StreamPi.Util.FormHelper.SpaceFiller;
+import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
+
+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;
+
+public class StreamPiComboBox<T> extends HBox
+{
+ private List<T> options;
+
+ private static StackPane stackPaneParent;
+
+ public static void setParent(StackPane parent) {
+ stackPaneParent = parent;
+
+ stackPaneParent.getStyleClass().add("combobox_pane_parent");
+
+ stackPaneParent.getChildren().addListener(new ListChangeListener<Node>()
+ {
+ @Override
+ public void onChanged(Change<? extends Node> c) {
+ if(stackPaneParent.getChildren().size() > 0)
+ {
+ stackPaneParent.setVisible(true);
+ stackPaneParent.toFront();
+ }
+ else
+ {
+ stackPaneParent.setVisible(false);
+ stackPaneParent.toBack();
+ }
+ }
+ });
+ }
+
+ public StreamPiComboBox(List<T> options)
+ {
+ setup();
+
+ setOptions(options);
+ }
+
+ public StreamPiComboBox()
+ {
+ setup();
+ }
+
+ private Label currentSelectedLabel;
+ private void setup()
+ {
+ buttons = new ArrayList<>();
+
+ getStyleClass().add("combo_box");
+ setOnMouseClicked(event->show());
+
+ currentSelectedLabel = new Label();
+
+ FontIcon fontIcon = new FontIcon();
+ fontIcon.getStyleClass().add("combo_box_drop_down_icon");
+
+ getChildren().addAll(
+ currentSelectedLabel,
+ new SpaceFiller(FillerType.HBox),
+ fontIcon
+ );
+ }
+
+ public void setOptions(List<T> options)
+ {
+ this.options = options;
+ setCurrentSelectedItemIndex(0);
+ }
+
+
+ private int currentIndex = 0;
+ private List<ToggleButton> buttons;
+
+ 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.setContent(vBox);
+
+ for(int i = 0;i<options.size();i++)
+ {
+ T eachOptionObj = options.get(i);
+ String displayText = streamPiComboBoxFactory.getOptionDisplayText(eachOptionObj);
+
+ ToggleButton optionButton = new ToggleButton(displayText);
+ 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;
+ }
+
+ public int getCurrentIndex()
+ {
+ return currentIndex;
+ }
+
+ public T getCurrentSelectedItem()
+ {
+ return options.get(currentIndex);
+ }
+
+ public void setCurrentSelectedItemIndex(int index)
+ {
+ this.currentIndex = index;
+
+ setCurrentSelectedLabelText(streamPiComboBoxFactory.getOptionDisplayText(options.get(index)));
+ }
+
+ public void setCurrentSelectedItem(T object)
+ {
+ setCurrentSelectedItemIndex(options.indexOf(object));
+ }
+
+ private void setCurrentSelectedLabelText(String text)
+ {
+ currentSelectedLabel.setText(text);
+ }
+
+ private StreamPiComboBoxListener<T> streamPiComboBoxListener = null;
+
+ public void setStreamPiComboBoxListener(StreamPiComboBoxListener<T> streamPiComboBoxListener)
+ {
+ this.streamPiComboBoxListener = streamPiComboBoxListener;
+ }
+
+ private Node popupNode;
+ public void show()
+ {
+ Platform.runLater(()->{
+ popupNode = getPopupScrollPane();
+ stackPaneParent.getChildren().add(popupNode);
+ });
+ }
+
+ public void destroy()
+ {
+ Platform.runLater(()->{
+ stackPaneParent.getChildren().remove(popupNode);
+ });
+ }
+
+ private StreamPiComboBoxFactory<T> streamPiComboBoxFactory;
+ public void setStreamPiComboBoxFactory(StreamPiComboBoxFactory<T> streamPiComboBoxFactory)
+ {
+ this.streamPiComboBoxFactory = streamPiComboBoxFactory;
+ }
+}
\ No newline at end of file
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/ComboBox/StreamPiComboBoxFactory.java
@@ -0,0 +1,6 @@
+package com.StreamPi.Util.ComboBox;
+
+public abstract class StreamPiComboBoxFactory<T>
+{
+ public abstract String getOptionDisplayText(T object);
+}
\ No newline at end of file
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/ComboBox/StreamPiComboBoxListener.java
@@ -0,0 +1,5 @@
+package com.StreamPi.Util.ComboBox;
+
+public abstract class StreamPiComboBoxListener<T> {
+ public abstract void onNewItemSelected(T selectedItem);
+}
--- 'a/src/main/java/com/StreamPi/Util/FormHelper/HBoxInputBox.java'
+++ b/src/main/java/com/StreamPi/Util/FormHelper/HBoxInputBox.java
@@ -10,16 +10,14 @@ import javafx.scene.layout.Region;
public class HBoxInputBox extends HBox {
private TextField textField;
- public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
+ public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
{
- textField.setPrefWidth(100);
+ textField.setPrefWidth(prefWidth);
Label label = new Label(labelText);
-
getChildren().addAll(label, new SpaceFiller(SpaceFiller.FillerType.HBox), textField);
- setSpacing(5.0);
if(enablerCheckBox != null)
{
@@ -31,11 +29,22 @@ public class HBoxInputBox extends HBox {
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, null);
+ 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'
+++ b/src/main/java/com/StreamPi/Util/FormHelper/HBoxInputBoxWithFileChooser.java
@@ -17,17 +17,13 @@ import java.io.File;
public class HBoxInputBoxWithFileChooser extends HBox {
public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
{
- HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField);
+ textField.setDisable(true);
+ HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
setHgrow(hBoxInputBox, Priority.ALWAYS);
getChildren().addAll(hBoxInputBox);
setSpacing(5.0);
- TextField tf = hBoxInputBox.getTextField();
- tf.setPrefWidth(300);
- tf.setDisable(true);
-
-
Button button = new Button();
FontIcon fontIcon = new FontIcon("far-folder");
//fontIcon.setIconColor(Paint.valueOf(iconColorHex));
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/LoggerHelper/StreamPiLogFileHandler.java
@@ -0,0 +1,15 @@
+package com.StreamPi.Util.LoggerHelper;
+
+import java.io.IOException;
+import java.util.logging.FileHandler;
+
+public class StreamPiLogFileHandler extends FileHandler {
+
+ public StreamPiLogFileHandler() throws IOException, SecurityException
+ {
+ super("streampi.log", false);
+
+ setFormatter(new StreamPiLogFormatter());
+ }
+
+}
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/LoggerHelper/StreamPiLogFormatter.java
@@ -0,0 +1,12 @@
+package com.StreamPi.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";
+ }
+}
--- 'a/src/main/java/com/StreamPi/Util/Platform/Platform.java'
+++ b/src/main/java/com/StreamPi/Util/Platform/Platform.java
@@ -1,18 +1,23 @@
package com.StreamPi.Util.Platform;
public enum Platform {
- WINDOWS, LINUX, MAC, ANDROID, IOS, OTHER;
+ WINDOWS("Windows"),
+ LINUX("Linux"),
+ MAC("MacOS"),
+ ANDROID("Android"),
+ IOS("iOS"),
+ LINUX_RPI("Raspberry Pi"),
+ UNKNOWN("Unknown");
- public static String getUIName(Platform platform)
+ final private String UIName;
+
+ Platform(String UIName)
+ {
+ this.UIName = UIName;
+ }
+
+ public String getUIName()
{
- 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";
- }
+ return UIName;
}
}
--- 'a/src/main/java/com/StreamPi/Util/Platform/ReleaseStatus.java'
+++ b/src/main/java/com/StreamPi/Util/Platform/ReleaseStatus.java
@@ -1,12 +1,25 @@
/*
ReleaseStatus.java
-Contributors : Debayan Sutradhar (@dubbadhar)
+Written By : Debayan Sutradhar (@rnayabed)
Enum to store the current status of the Server Release
- */
+*/
+
package com.StreamPi.Util.Platform;
public enum ReleaseStatus {
- INTERNAL, ALPHA, BETA, STABLE
+ 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/StreamPi/Util/StartAtBoot/SoftwareType.java
@@ -0,0 +1,5 @@
+package com.StreamPi.Util.StartAtBoot;
+
+public enum SoftwareType {
+ SERVER, CLIENT
+}
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/StartAtBoot/StartAtBoot.java
@@ -0,0 +1,110 @@
+package com.StreamPi.Util.StartAtBoot;
+
+import com.StreamPi.Util.Exception.MinorException;
+import com.StreamPi.Util.Platform.Platform;
+
+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
+ {
+ File initFile = new File("/etc/init.d/streampi_starter_"+ softwareType);
+
+ try
+ {
+ FileWriter fw = new FileWriter(initFile);
+ BufferedWriter bw = new BufferedWriter(fw);
+ bw.write("#! /bin/sh\n" +
+ "cd "+runnerFile.getAbsoluteFile().getParent()+"\n" +
+ "sudo ./"+runnerFile.getName()+"\n" +
+ "exit 0\n");
+ bw.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ throw new MinorException(e.getMessage()+"\nTry running as root and try again");
+ }
+ }
+
+ private boolean deleteStarterForLinux()
+ {
+ return new File("/etc/init.d/streampi_starter_"+ softwareType).delete();
+ }
+
+ 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.");
+ }
+}
--- 'a/src/main/java/com/StreamPi/Util/Version/Version.java'
+++ b/src/main/java/com/StreamPi/Util/Version/Version.java
@@ -83,13 +83,20 @@ public class Version implements Serializ
{
if(major>version.major)
return true;
- else
+ else if(major < version.major)
+ return false;
+ else
{
- if(minor > version.minor)
+ if (minor > version.minor)
return true;
+ else if(minor < version.minor)
+ return false;
else
{
- return revision > version.revision;
+ if(revision > version.revision)
+ return true;
+ else
+ return false;
}
}
}
--- /dev/null
+++ b/src/main/java/com/StreamPi/Util/XMLConfigHelper/XMLConfigHelper.java
@@ -0,0 +1,102 @@
+package com.StreamPi.Util.XMLConfigHelper;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class XMLConfigHelper {
+
+ public static String getStringProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return getProperty(parentElement, propertyName);
+ }
+
+ public static int getIntProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return Integer.parseInt(getProperty(parentElement, propertyName));
+ }
+
+ public static boolean getBooleanProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return getProperty(parentElement, propertyName).equals("true");
+ }
+
+ public static String getProperty(Element parentElement, String propertyName) throws Exception
+ {
+ return parentElement.getElementsByTagName(propertyName).item(0).getTextContent();
+ }
+
+
+ public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace)
+ {
+ String tbr = ifNotPresent;
+
+ try
+ {
+ tbr = getProperty(parentElement, propertyName);
+ }
+ catch(Exception e)
+ {
+ if(printStackTrace)
+ e.printStackTrace();
+ }
+
+
+ return tbr;
+ }
+
+
+ public static void removeChilds(Node node) {
+ while (node.hasChildNodes())
+ node.removeChild(node.getFirstChild());
+ }
+
+ public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent)
+ {
+ return getStringProperty(parentElement, propertyName, ifNotPresent, true);
+ }
+
+ public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent)
+ {
+ int tbr = ifNotPresent;
+
+ try
+ {
+ tbr = Integer.parseInt(getProperty(parentElement, propertyName));
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+
+
+ return tbr;
+ }
+
+ public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent)
+ {
+ boolean tbr = ifNotPresent;
+
+ try
+ {
+ tbr = getProperty(parentElement, propertyName).equals("true");
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return tbr;
+ }
+
+ 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,14 +1,20 @@
module com.StreamPi.Util {
- requires org.apache.commons.configuration2;
- requires org.slf4j;
-
- requires org.kordamp.ikonli.javafx;
- requires org.kordamp.ikonli.fontawesome5;
- requires javafx.base;
- requires javafx.controls;
+ 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.StreamPi.Util.Version;
exports com.StreamPi.Util.Exception;
exports com.StreamPi.Util.Platform;
exports com.StreamPi.Util.FormHelper;
+ exports com.StreamPi.Util.StartAtBoot;
+ exports com.StreamPi.Util.Alert;
+ exports com.StreamPi.Util.ComboBox;
+ exports com.StreamPi.Util.XMLConfigHelper;
+ exports com.StreamPi.Util.LoggerHelper;
}
\ No newline at end of file