util
Clone or download
1. Update SpaceFiller to contain static methods to easily create Regions 2. Remove unnecessary whitespace 3. Add a simple Github Action workflow to verify the project 4. Update .gitignore Also contains the following updates to pom.xml: 1. Update groupId to com.stream-pi 2. Remove unnecessary transitive dependency 3. Update version from 1.0.0 to 1.0.0-SNAPSHOT 4. Use maven.compiler.release instead of source and target
Modified Files
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
.idea/
# Maven
target/
target/
Util.iml
# IntelliJ IDEA
.idea/
*.iml
# Eclipse
.settings/
.settings/
.project
.project
.factorypath
.factorypath
.classpath
.classpath
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stream_pi</groupId>
<groupId>com.stream-pi</groupId>
<artifactId>util</artifactId>
<artifactId>util</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<url>https://stream-pi.com/</url>
<url>https://stream-pi.com/</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<javafx.version>16-ea+6</javafx.version>
<ikonli.version>11.5.0</ikonli.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<version>${ikonli.version}</version>
</dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${ikonli.version}</version>
</dependency>
</dependencies>
<build>
<build>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.0</version>
<executions>
<executions>
<execution>
<execution>
<id>test-jar</id>
<id>test-jar</id>
<phase>package</phase>
<phase>package</phase>
<goals>
<goals>
<goal>test-jar</goal>
<goal>test-jar</goal>
</goals>
</goals>
</execution>
</execution>
</executions>
</executions>
</plugin>
</plugin>
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
</plugin>
</plugins>
</plugins>
</build>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<IkonliVersion>11.5.0</IkonliVersion>
<IkonliFA5PackVersion>11.5.0</IkonliFA5PackVersion>
<JavaFXVersion>16-ea+6</JavaFXVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-fontawesome5-pack</artifactId>
<version>${IkonliFA5PackVersion}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${JavaFXVersion}</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>${JavaFXVersion}</version>
</dependency>
<dependency>
<groupId>org.kordamp.ikonli</groupId>
<artifactId>ikonli-javafx</artifactId>
<version>${IkonliVersion}</version>
</dependency>
</dependencies>
</project>
</project>
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.alert;
package com.stream_pi.util.alert;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
/**
/**
* Custom Alert Dialog for Server and Client
* Custom Alert Dialog for Server and Client
*/
*/
public class StreamPiAlert
public class StreamPiAlert
{
{
private String title;
private String title;
private String[] buttons;
private String[] buttons;
private StreamPiAlertType streamPiAlertType;
private StreamPiAlertType streamPiAlertType;
private Pane contentPane;
private Pane contentPane;
private static StackPane stackPaneParent = null;
private static StackPane stackPaneParent = null;
/**
/**
* Sets the parent where the alert will be shown
* Sets the parent where the alert will be shown
* @param parent StackPane where the alert dialog will be shown
* @param parent StackPane where the alert dialog will be shown
*/
*/
public static void setParent(StackPane parent)
public static void setParent(StackPane parent)
{
{
stackPaneParent = parent;
stackPaneParent = parent;
stackPaneParent.getStyleClass().add("alert_pane_parent");
stackPaneParent.getStyleClass().add("alert_pane_parent");
stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
{
{
if(stackPaneParent.getChildren().size() > 0)
if(stackPaneParent.getChildren().size() > 0)
{
{
stackPaneParent.setVisible(true);
stackPaneParent.setVisible(true);
stackPaneParent.toFront();
stackPaneParent.toFront();
}
}
else
else
{
{
stackPaneParent.setVisible(false);
stackPaneParent.setVisible(false);
stackPaneParent.toBack();
stackPaneParent.toBack();
}
}
});
});
}
}
/**
/**
* Returns the parent node
* Returns the parent node
* @return StackPane parent where the alert boxes will be shown
* @return StackPane parent where the alert boxes will be shown
*/
*/
public static StackPane getParent()
public static StackPane getParent()
{
{
return stackPaneParent;
return stackPaneParent;
}
}
private StreamPiAlertListener streamPiAlertListener = null;
private StreamPiAlertListener streamPiAlertListener = null;
/**
/**
* Public constructor to make an alert with just title, pre-made content pane (mainly for forms, complex dialogs)
* 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 title Heading of the Alert
* @param streamPiAlertType Alert Type
* @param streamPiAlertType Alert Type
* @param contentPane The main body of the alert
* @param contentPane The main body of the alert
*/
*/
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
Pane contentPane)
Pane contentPane)
{
{
set(title, streamPiAlertType, contentPane, "OK");
set(title, streamPiAlertType, contentPane, "OK");
}
}
/**
/**
* Sets the Alert type
* Sets the Alert type
* @param streamPiAlertType Alert Type
* @param streamPiAlertType Alert Type
*/
*/
public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
{
{
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
/**
/**
* Constructor for very simple alert, with just title and body text
* Constructor for very simple alert, with just title and body text
* Default AlertType will be INFORMATION
* Default AlertType will be INFORMATION
* @param title Heading
* @param title Heading
* @param contentText Body Text
* @param contentText Body Text
*/
*/
public StreamPiAlert(String title, String contentText)
public StreamPiAlert(String title, String contentText)
{
{
this(title, contentText, StreamPiAlertType.INFORMATION);
this(title, contentText, StreamPiAlertType.INFORMATION);
}
}
/**
/**
* Constructor for alert with just "Alert" heading,
* Constructor for alert with just "Alert" heading,
* content text and alert type
* content text and alert type
* @param contentText Body Text
* @param contentText Body Text
* @param alertType Alert Type
* @param alertType Alert Type
*/
*/
public StreamPiAlert(String contentText, StreamPiAlertType alertType)
public StreamPiAlert(String contentText, StreamPiAlertType alertType)
{
{
this("Alert", contentText, alertType);
this("Alert", contentText, alertType);
}
}
/**
/**
* Constructor to create Alert box with title, Alert Type and button choices
* Constructor to create Alert box with title, Alert Type and button choices
* @param title Heading
* @param title Heading
* @param streamPiAlertType Alert Type
* @param streamPiAlertType Alert Type
* @param buttons Button choices
* @param buttons Button choices
*/
*/
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, String... buttons)
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, String... buttons)
{
{
set(title, streamPiAlertType, null, buttons);
set(title, streamPiAlertType, null, buttons);
}
}
/**
/**
* Constructor to create Alert Box with title, Alert Type, Body and button choices
* Constructor to create Alert Box with title, Alert Type, Body and button choices
* @param title Heading of the alert box
* @param title Heading of the alert box
* @param streamPiAlertType Alert Type
* @param streamPiAlertType Alert Type
* @param contentPane Alert Body
* @param contentPane Alert Body
* @param buttons Button choices
* @param buttons Button choices
*/
*/
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, Pane contentPane, String... buttons)
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, Pane contentPane, String... buttons)
{
{
set(title, streamPiAlertType, contentPane, buttons);
set(title, streamPiAlertType, contentPane, buttons);
}
}
/**
/**
* Constructor to create Alert Box with Heading, content text, Alert Type
* Constructor to create Alert Box with Heading, content text, Alert Type
* @param title Heading
* @param title Heading
* @param contentText Body Text
* @param contentText Body Text
* @param streamPiAlertType Alert Type
* @param streamPiAlertType Alert Type
*/
*/
public StreamPiAlert(String title, String contentText, StreamPiAlertType streamPiAlertType)
public StreamPiAlert(String title, String contentText, StreamPiAlertType streamPiAlertType)
{
{
Label label = new Label(contentText);
Label label = new Label(contentText);
label.setWrapText(true);
label.setWrapText(true);
VBox vBox = new VBox(label);
VBox vBox = new VBox(label);
set(title, streamPiAlertType, vBox, "OK");
set(title, streamPiAlertType, vBox, "OK");
}
}
/**
/**
* Sets the alert properties
* Sets the alert properties
* @param title Heading
* @param title Heading
* @param streamPiAlertType Alert Type
* @param streamPiAlertType Alert Type
* @param contentPane Body
* @param contentPane Body
* @param buttons Button choices
* @param buttons Button choices
*/
*/
private void set(String title, StreamPiAlertType streamPiAlertType,
private void set(String title, StreamPiAlertType streamPiAlertType,
Pane contentPane, String... buttons)
Pane contentPane, String... buttons)
{
{
this.title = title;
this.title = title;
this.buttons = buttons;
this.buttons = buttons;
this.contentPane = contentPane;
this.contentPane = contentPane;
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
/**
/**
* Set on click Listener
* Set on click Listener
* @param streamPiAlertListener Alert Listener, triggered when a button is clicked
* @param streamPiAlertListener Alert Listener, triggered when a button is clicked
*/
*/
public void setOnClicked(StreamPiAlertListener streamPiAlertListener)
public void setOnClicked(StreamPiAlertListener streamPiAlertListener)
{
{
this.streamPiAlertListener = streamPiAlertListener;
this.streamPiAlertListener = streamPiAlertListener;
}
}
/**
/**
* @return Heading of the Alert Box
* @return Heading of the Alert Box
*/
*/
public String getTitle()
public String getTitle()
{
{
return title;
return title;
}
}
/**
/**
* @return Button Choices
* @return Button Choices
*/
*/
public String[] getButtons()
public String[] getButtons()
{
{
return buttons;
return buttons;
}
}
/**
/**
* @param contentPane Alert Body Node
* @param contentPane Alert Body Node
*/
*/
public void setAlertContent(Pane contentPane)
public void setAlertContent(Pane contentPane)
{
{
this.contentPane = contentPane;
this.contentPane = contentPane;
}
}
/**
/**
* Set all the button choices
* Set all the button choices
* @param buttons Array of button choices
* @param buttons Array of button choices
*/
*/
public void setButtons(String... buttons)
public void setButtons(String... buttons)
{
{
this.buttons = buttons;
this.buttons = buttons;
}
}
/**
/**
* Create and return the final AlertBox Pane, which will be added to the parent node
* Create and return the final AlertBox Pane, which will be added to the parent node
* @param title Heading
* @param title Heading
* @param contentPane The Alert Body Pane
* @param contentPane The Alert Body Pane
* @return Final VBox to be shown in the parent Stack Pane
* @return Final VBox to be shown in the parent Stack Pane
*/
*/
private VBox getAlertPane(String title, Pane contentPane)
private VBox getAlertPane(String title, Pane contentPane)
{
{
if(title.isEmpty())
if(title.isEmpty())
title = "Alert";
title = "Alert";
Label label = new Label(title);
Label label = new Label(title);
label.getStyleClass().add("alert_pane_header_text");
label.getStyleClass().add("alert_pane_header_text");
FontIcon fontIcon = new FontIcon(streamPiAlertType.getIconCode());
FontIcon fontIcon = new FontIcon(streamPiAlertType.getIconCode());
fontIcon.getStyleClass().addAll("alert_header_icon", streamPiAlertType.getIconStyleClassName());
fontIcon.getStyleClass().addAll("alert_header_icon", streamPiAlertType.getIconStyleClassName());
HBox header = new HBox(label, new SpaceFiller(SpaceFiller.FillerType.HBox), fontIcon);
HBox header = new HBox(label, SpaceFiller.horizontal(), fontIcon);
header.getStyleClass().add("alert_header");
header.getStyleClass().add("alert_header");
header.setPadding(new Insets(10));
header.setPadding(new Insets(10));
HBox buttonBar = new HBox();
HBox buttonBar = new HBox();
buttonBar.getStyleClass().add("alert_button_bar");
buttonBar.getStyleClass().add("alert_button_bar");
for (String eachButtonString : buttons)
for (String eachButtonString : buttons)
{
{
Button button = new Button(eachButtonString);
Button button = new Button(eachButtonString);
button.setOnAction(event -> {
button.setOnAction(event -> {
if(this.streamPiAlertListener != null)
if(this.streamPiAlertListener != null)
{
this.streamPiAlertListener.onClick(eachButtonString);
this.streamPiAlertListener.onClick(eachButtonString);
}
destroy();
destroy();
});
});
button.getStyleClass().add("alert_button");
button.getStyleClass().add("alert_button");
buttonBar.getChildren().add(button);
buttonBar.getChildren().add(button);
}
}
contentPane.getStyleClass().add("alert_content_pane");
ScrollPane scrollPane = new ScrollPane(contentPane);
ScrollPane scrollPane = new ScrollPane(contentPane);
scrollPane.prefHeightProperty().bind(contentPane.heightProperty().add(20));
scrollPane.prefHeightProperty().bind(contentPane.heightProperty().add(20));
scrollPane.getStyleClass().add("alert_scroll_pane");
scrollPane.getStyleClass().add("alert_scroll_pane");
contentPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
contentPane.getStyleClass().add("alert_content_pane");
contentPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
VBox alertVBox = new VBox( header, scrollPane, buttonBar);
VBox alertVBox = new VBox( header, scrollPane, buttonBar);
alertVBox.getStyleClass().add("alert_pane");
alertVBox.getStyleClass().add("alert_pane");
alertVBox.setMaxHeight(Double.NEGATIVE_INFINITY);
alertVBox.setMaxHeight(Double.NEGATIVE_INFINITY);
return alertVBox;
return alertVBox;
}
}
/**
/**
* @return The body node of the Alert Box
* @return The body node of the Alert Box
*/
*/
public Pane getContentPane()
public Pane getContentPane()
{
{
return contentPane;
return contentPane;
}
}
/**
/**
* Adds the Alert Box to the parent node
* Adds the Alert Box to the parent node
*/
*/
private Node popupNode;
private Node popupNode;
public void show()
public void show()
{
{
Platform.runLater(()->
Platform.runLater(()->
{
{
popupNode = getAlertPane(getTitle(), getContentPane());
popupNode = getAlertPane(getTitle(), getContentPane());
stackPaneParent.getChildren().add(popupNode);
stackPaneParent.getChildren().add(popupNode);
});
});
}
}
/**
/**
* Removes the alert from the parent pane
* Removes the alert from the parent pane
*/
*/
public void destroy()
public void destroy()
{
{
Platform.runLater(()-> stackPaneParent.getChildren().remove(popupNode));
Platform.runLater(()-> stackPaneParent.getChildren().remove(popupNode));
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.combobox;
package com.stream_pi.util.combobox;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import com.stream_pi.util.uihelper.SpaceFiller;
import com.stream_pi.util.uihelper.SpaceFiller;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.application.Platform;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ListChangeListener;
import javafx.scene.Node;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.control.ScrollPane.ScrollBarPolicy;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
/**
/**
* Custom Combo Box for Server and Client
* Custom Combo Box for Server and Client
* @param <T> Combo Box List Type
* @param <T> Combo Box List Type
*/
*/
public class StreamPiComboBox<T> extends HBox
public class StreamPiComboBox<T> extends HBox
{
{
private List<T> options;
private List<T> options;
private static StackPane stackPaneParent;
private static StackPane stackPaneParent;
/**
/**
* Sets the parent where the Combo Box will be shown
* Sets the parent where the Combo Box will be shown
* @param parent StackPane where the Combo Box dialog will be shown
* @param parent StackPane where the Combo Box dialog will be shown
*/
*/
public static void setParent(StackPane parent) {
public static void setParent(StackPane parent) {
stackPaneParent = parent;
stackPaneParent = parent;
stackPaneParent.getStyleClass().add("combo_box_pane_parent");
stackPaneParent.getStyleClass().add("combo_box_pane_parent");
stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
stackPaneParent.getChildren().addListener((ListChangeListener<Node>) c ->
{
{
if(stackPaneParent.getChildren().size() > 0)
if(stackPaneParent.getChildren().size() > 0)
{
{
stackPaneParent.setVisible(true);
stackPaneParent.setVisible(true);
stackPaneParent.toFront();
stackPaneParent.toFront();
}
}
else
else
{
{
stackPaneParent.setVisible(false);
stackPaneParent.setVisible(false);
stackPaneParent.toBack();
stackPaneParent.toBack();
}
}
});
});
}
}
/**
/**
* Constructor to create Combo Box with all the options
* Constructor to create Combo Box with all the options
* @param options List of Options
* @param options List of Options
*/
*/
public StreamPiComboBox(List<T> options)
public StreamPiComboBox(List<T> options)
{
{
setup();
setup();
setOptions(options);
setOptions(options);
}
}
/**
/**
* @return List of Combo Box Options
* @return List of Combo Box Options
*/
*/
public List<T> getOptions()
public List<T> getOptions()
{
{
return options;
return options;
}
}
/**
/**
* Constructor to create Combo Box with empty list
* Constructor to create Combo Box with empty list
*/
*/
public StreamPiComboBox()
public StreamPiComboBox()
{
{
setup();
setup();
}
}
private Label currentSelectedLabel;
private Label currentSelectedLabel;
/**
/**
* init of Combo Box
* init of Combo Box
*/
*/
private void setup()
private void setup()
{
{
buttons = new ArrayList<>();
buttons = new ArrayList<>();
getStyleClass().add("combo_box");
getStyleClass().add("combo_box");
setOnMouseClicked(event->show());
setOnMouseClicked(event -> show());
currentSelectedLabel = new Label();
currentSelectedLabel = new Label();
currentSelectedLabel.getStyleClass().add("combo_box_current_selected_label");
currentSelectedLabel.getStyleClass().add("combo_box_current_selected_label");
FontIcon fontIcon = new FontIcon();
FontIcon fontIcon = new FontIcon();
fontIcon.getStyleClass().add("combo_box_drop_down_icon");
fontIcon.getStyleClass().add("combo_box_drop_down_icon");
getChildren().addAll(
getChildren().addAll(
currentSelectedLabel,
currentSelectedLabel,
new SpaceFiller(SpaceFiller.FillerType.HBox),
SpaceFiller.horizontal(),
fontIcon
fontIcon
);
);
}
}
/**
/**
* Set Combo Box options
* Set Combo Box options
* @param options Combo Box Options
* @param options Combo Box Options
*/
*/
public void setOptions(List<T> options)
public void setOptions(List<T> options)
{
{
this.options = options;
this.options = options;
setCurrentSelectedItemIndex(0);
setCurrentSelectedItemIndex(0);
}
}
private int currentIndex = 0;
private int currentIndex = 0;
private List<ToggleButton> buttons;
private List<ToggleButton> buttons;
/**
/**
* @return Final Scroll Pane
* @return Final Scroll Pane
*/
*/
public ScrollPane getPopupScrollPane()
public ScrollPane getPopupScrollPane()
{
{
buttons.clear();
buttons.clear();
ScrollPane scrollPane = new ScrollPane();
ScrollPane scrollPane = new ScrollPane();
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.getStyleClass().add("combo_box_popup");
scrollPane.getStyleClass().add("combo_box_popup");
VBox vBox = new VBox();
VBox vBox = new VBox();
vBox.getStyleClass().add("combo_box_popup_vbox");
vBox.getStyleClass().add("combo_box_popup_vbox");
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
vBox.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.maxHeightProperty().bind(vBox.heightProperty().add(20));
scrollPane.maxHeightProperty().bind(vBox.heightProperty().add(20));
scrollPane.setContent(vBox);
scrollPane.setContent(vBox);
//scrollPane.setMaxHeight(Double.NEGATIVE_INFINITY);
//scrollPane.setMaxHeight(Double.NEGATIVE_INFINITY);
for(int i = 0;i<options.size();i++)
for(int i = 0;i<options.size();i++)
{
{
T eachOptionObj = options.get(i);
T eachOptionObj = options.get(i);
String displayText = streamPiComboBoxFactory.getOptionDisplayText(eachOptionObj);
String displayText = streamPiComboBoxFactory.getOptionDisplayText(eachOptionObj);
ToggleButton optionButton = new ToggleButton(displayText);
ToggleButton optionButton = new ToggleButton(displayText);
optionButton.getStyleClass().add("combo_box_list_option_button");
optionButton.getStyleClass().add("combo_box_list_option_button");
optionButton.setSelected(i == currentIndex);
optionButton.setSelected(i == currentIndex);
optionButton.setUserData(i);
optionButton.setUserData(i);
optionButton.setOnAction(event->
optionButton.setOnAction(event->
{
{
setCurrentSelectedItemIndex((int) optionButton.getUserData());
setCurrentSelectedItemIndex((int) optionButton.getUserData());
if(streamPiComboBoxListener != null)
if(streamPiComboBoxListener != null)
streamPiComboBoxListener.onNewItemSelected(options.get(currentIndex));
streamPiComboBoxListener.onNewItemSelected(options.get(currentIndex));
destroy();
destroy();
});
});
vBox.getChildren().addAll(optionButton);
vBox.getChildren().addAll(optionButton);
buttons.add(optionButton);
buttons.add(optionButton);
}
}
return scrollPane;
return scrollPane;
}
}
/**
/**
* @return Current Selected Option Index
* @return Current Selected Option Index
*/
*/
public int getCurrentIndex()
public int getCurrentIndex()
{
{
return currentIndex;
return currentIndex;
}
}
/**
/**
* @return Current Selected Item
* @return Current Selected Item
*/
*/
public T getCurrentSelectedItem()
public T getCurrentSelectedItem()
{
{
return options.get(currentIndex);
return options.get(currentIndex);
}
}
/**
/**
* @param index Current item index to be selected
* @param index Current item index to be selected
*/
*/
public void setCurrentSelectedItemIndex(int index)
public void setCurrentSelectedItemIndex(int index)
{
{
this.currentIndex = index;
this.currentIndex = index;
setCurrentSelectedLabelText(streamPiComboBoxFactory.getOptionDisplayText(options.get(index)));
setCurrentSelectedLabelText(streamPiComboBoxFactory.getOptionDisplayText(options.get(index)));
}
}
/**
/**
* @param text Name of the option
* @param text Name of the option
*/
*/
private void setCurrentSelectedLabelText(String text)
private void setCurrentSelectedLabelText(String text)
{
{
currentSelectedLabel.setText(text);
currentSelectedLabel.setText(text);
}
}
private StreamPiComboBoxListener<T> streamPiComboBoxListener = null;
private StreamPiComboBoxListener<T> streamPiComboBoxListener = null;
/**
/**
* Set on click Listener
* Set on click Listener
* @param streamPiComboBoxListener Combo Box Listener, triggered when an option is clicked
* @param streamPiComboBoxListener Combo Box Listener, triggered when an option is clicked
*/
*/
public void setStreamPiComboBoxListener(StreamPiComboBoxListener<T> streamPiComboBoxListener)
public void setStreamPiComboBoxListener(StreamPiComboBoxListener<T> streamPiComboBoxListener)
{
{
this.streamPiComboBoxListener = streamPiComboBoxListener;
this.streamPiComboBoxListener = streamPiComboBoxListener;
}
}
private Node popupNode;
private Node popupNode;
/**
/**
* Adds the Combo Box to the parent node
* Adds the Combo Box to the parent node
*/
*/
public void show()
public void show()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
popupNode = getPopupScrollPane();
popupNode = getPopupScrollPane();
stackPaneParent.getChildren().add(popupNode);
stackPaneParent.getChildren().add(popupNode);
});
});
}
}
/**
/**
* Removes the combo box from the parent pane
* Removes the combo box from the parent pane
*/
*/
public void destroy()
public void destroy()
{
{
Platform.runLater(()->{
Platform.runLater(()->{
stackPaneParent.getChildren().remove(popupNode);
stackPaneParent.getChildren().remove(popupNode);
});
});
}
}
private StreamPiComboBoxFactory<T> streamPiComboBoxFactory;
private StreamPiComboBoxFactory<T> streamPiComboBoxFactory;
/**
/**
* @param streamPiComboBoxFactory Factory for the Combo Box
* @param streamPiComboBoxFactory Factory for the Combo Box
*/
*/
public void setStreamPiComboBoxFactory(StreamPiComboBoxFactory<T> streamPiComboBoxFactory)
public void setStreamPiComboBoxFactory(StreamPiComboBoxFactory<T> streamPiComboBoxFactory)
{
{
this.streamPiComboBoxFactory = streamPiComboBoxFactory;
this.streamPiComboBoxFactory = streamPiComboBoxFactory;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.exception;
package com.stream_pi.util.exception;
public class SevereException extends StreamPiException{
public class SevereException extends StreamPiException {
public SevereException(String message)
public SevereException(String message)
{
{
super(message);
super(message);
}
}
public SevereException(String title, String message)
public SevereException(String title, String message)
{
{
super(title, message);
super(title, message);
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.exception;
package com.stream_pi.util.exception;
public class StreamPiException extends Exception {
public class StreamPiException extends Exception {
private String title;
private String title;
private String message;
private String message;
public StreamPiException(String message)
public StreamPiException(String message)
{
{
super(message);
super(message);
this.title = "";
this.title = "";
this.message = message;
this.message = message;
}
}
public StreamPiException(String title, String message)
public StreamPiException(String title, String message)
{
{
super(message);
super(message);
this.title = title;
this.title = title;
this.message = message;
this.message = message;
}
}
public String getShortMessage()
public String getShortMessage()
{
{
return message;
return message;
}
}
public String getTitle()
public String getTitle()
{
{
return title;
return title;
}
}
public void setTitle(String title)
public void setTitle(String title)
{
{
this.title = title;
this.title = title;
}
}
public void setShortMessage(String message)
public void setShortMessage(String message)
{
{
this.message = message;
this.message = message;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.iohelper;
package com.stream_pi.util.iohelper;
import java.io.File;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipInputStream;
public class IOHelper {
public class IOHelper {
public static void unzip(InputStream inputStream, String destDir) throws Exception{
public static void unzip(InputStream inputStream, String destDir) throws Exception {
File dir = new File(destDir);
File dir = new File(destDir);
// create output directory if it doesn't exist
// create output directory if it doesn't exist
if(!dir.exists()) dir.mkdirs();
if(!dir.exists()) dir.mkdirs();
InputStream fis;
InputStream fis;
//buffer for read and write data to file
//buffer for read and write data to file
byte[] buffer = new byte[1024];
byte[] buffer = new byte[1024];
fis = inputStream;
fis = inputStream;
ZipInputStream zis = new ZipInputStream(fis);
ZipInputStream zis = new ZipInputStream(fis);
ZipEntry ze = zis.getNextEntry();
ZipEntry ze = zis.getNextEntry();
while(ze != null){
while(ze != null){
String fileName = ze.getName();
String fileName = ze.getName();
File newFile = new File(destDir + File.separator + fileName);
File newFile = new File(destDir + File.separator + fileName);
if(ze.isDirectory())
if(ze.isDirectory())
{
{
newFile.mkdirs();
newFile.mkdirs();
}
}
else
else
{
{
FileOutputStream fos = new FileOutputStream(newFile);
FileOutputStream fos = new FileOutputStream(newFile);
int len;
int len;
while ((len = zis.read(buffer)) > 0) {
while ((len = zis.read(buffer)) > 0)
fos.write(buffer, 0, len);
{
fos.write(buffer, 0, len);
}
}
fos.close();
fos.close();
}
}
//close this ZipEntry
//close this ZipEntry
zis.closeEntry();
zis.closeEntry();
ze = zis.getNextEntry();
ze = zis.getNextEntry();
}
}
//close last ZipEntry
//close last ZipEntry
zis.closeEntry();
zis.closeEntry();
zis.close();
zis.close();
fis.close();
fis.close();
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.loggerhelper;
package com.stream_pi.util.loggerhelper;
import java.util.logging.ConsoleHandler;
import java.util.logging.ConsoleHandler;
public class StreamPiLogFallbackHandler extends ConsoleHandler{
public class StreamPiLogFallbackHandler extends ConsoleHandler{
public StreamPiLogFallbackHandler() throws Exception
public StreamPiLogFallbackHandler() throws Exception
{
{
super();
super();
setFormatter(new StreamPiLogFormatter());
setFormatter(new StreamPiLogFormatter());
}
}
public void closeHandler()
public void closeHandler()
{
{
close();
close();
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.platform;
package com.stream_pi.util.platform;
public enum ReleaseStatus {
public enum ReleaseStatus {
EA("Early Access"), GA("General Availability");
EA("Early Access"),
GA("General Availability");
private final String UIName;
private final String UIName;
ReleaseStatus(String UIName)
ReleaseStatus(String UIName)
{
{
this.UIName = UIName;
this.UIName = UIName;
}
}
public String getUIName()
public String getUIName()
{
{
return UIName;
return UIName;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.uihelper;
package com.stream_pi.util.uihelper;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
public class HBoxInputBox extends HBox {
public class HBoxInputBox extends HBox {
private TextField textField;
private TextField textField;
public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
public HBoxInputBox(String labelText, TextField textField, int prefWidth, CheckBox enablerCheckBox)
{
{
textField.setPrefWidth(prefWidth);
textField.setPrefWidth(prefWidth);
Label label = new Label(labelText);
Label label = new Label(labelText);
getChildren().addAll(label, SpaceFiller.horizontal(), textField);
getChildren().addAll(label, new SpaceFiller(SpaceFiller.FillerType.HBox), textField);
if(enablerCheckBox != null)
if(enablerCheckBox != null)
{
{
textField.disableProperty().bind(enablerCheckBox.selectedProperty());
textField.disableProperty().bind(enablerCheckBox.selectedProperty());
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
getChildren().add(enablerCheckBox);
getChildren().add(enablerCheckBox);
}
}
this.textField = textField;
this.textField = textField;
}
}
public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
public HBoxInputBox(String labelText, TextField textField, CheckBox enablerCheckBox)
{
{
this(labelText, textField, 100, enablerCheckBox);
this(labelText, textField, 100, enablerCheckBox);
}
}
public HBoxInputBox(String labelText, TextField textField)
public HBoxInputBox(String labelText, TextField textField)
{
{
this(labelText, textField, 100, null);
this(labelText, textField, 100, null);
}
}
public HBoxInputBox(String labelText, TextField textField, int prefWidth)
public HBoxInputBox(String labelText, TextField textField, int prefWidth)
{
{
this(labelText, textField, prefWidth, null);
this(labelText, textField, prefWidth, null);
}
}
public TextField getTextField()
public TextField getTextField()
{
{
return textField;
return textField;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.uihelper;
package com.stream_pi.util.uihelper;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import java.io.File;
import java.io.File;
public class HBoxInputBoxWithFileChooser extends HBox {
public class HBoxInputBoxWithFileChooser extends HBox {
public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
public HBoxInputBoxWithFileChooser(String labelText, TextField textField, CheckBox enablerCheckBox, FileChooser.ExtensionFilter extensionFilter)
{
{
textField.setDisable(true);
textField.setDisable(true);
HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
HBoxInputBox hBoxInputBox = new HBoxInputBox(labelText, textField, 300);
setHgrow(hBoxInputBox, Priority.ALWAYS);
setHgrow(hBoxInputBox, Priority.ALWAYS);
getChildren().addAll(hBoxInputBox);
getChildren().addAll(hBoxInputBox);
setSpacing(5.0);
setSpacing(5.0);
Button button = new Button();
Button button = new Button();
FontIcon fontIcon = new FontIcon("far-folder");
FontIcon fontIcon = new FontIcon("far-folder");
//fontIcon.setIconColor(Paint.valueOf(iconColorHex));
//fontIcon.setIconColor(Paint.valueOf(iconColorHex));
//fontIcon.setIconSize(iconSize);
//fontIcon.setIconSize(iconSize);
button.setGraphic(fontIcon);
button.setGraphic(fontIcon);
button.setOnAction(event -> {
button.setOnAction(event -> {
FileChooser fileChooser = new FileChooser();
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(
fileChooser.getExtensionFilters().addAll(
extensionFilter
extensionFilter
);
);
try {
try {
File selectedDirectory = fileChooser.showOpenDialog(button.getScene().getWindow());
File selectedDirectory = fileChooser.showOpenDialog(button.getScene().getWindow());
textField.setText(selectedDirectory.getAbsolutePath());
textField.setText(selectedDirectory.getAbsolutePath());
}
}
catch (NullPointerException e)
catch (NullPointerException e)
{
{
// No folder selected
// No folder selected
}
}
});
});
getChildren().add(button);
getChildren().add(button);
if(enablerCheckBox!=null)
if(enablerCheckBox!=null)
{
{
button.disableProperty().bind(enablerCheckBox.selectedProperty());
button.disableProperty().bind(enablerCheckBox.selectedProperty());
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
HBox.setMargin(enablerCheckBox, new Insets(0, 0, 0, 45));
getChildren().add(enablerCheckBox);
getChildren().add(enablerCheckBox);
}
}
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.uihelper;
package com.stream_pi.util.uihelper;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
public class SpaceFiller extends Region {
public class SpaceFiller {
public SpaceFiller(FillerType fillerType)
public static Region horizontal()
{
{
if(fillerType == FillerType.HBox)
final Region region = new Region();
{
HBox.setHgrow(region, Priority.ALWAYS);
HBox.setHgrow(this, Priority.ALWAYS);
return region;
}
else if(fillerType == FillerType.VBox)
{
VBox.setVgrow(this, Priority.ALWAYS);
}
}
}
public enum FillerType
public static Region vertical()
{
{
HBox, VBox
final Region region = new Region();
VBox.setVgrow(region, Priority.ALWAYS);
return region;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.version;
package com.stream_pi.util.version;
import com.stream_pi.util.exception.MinorException;
import com.stream_pi.util.exception.MinorException;
import java.io.Serializable;
import java.io.Serializable;
public class Version implements Serializable {
public class Version implements Serializable {
private int major, minor, revision;
private int major, minor, revision;
public Version()
public Version()
{
{
major = 0;
major = 0;
minor = 0;
minor = 0;
revision = 0;
revision = 0;
}
}
public Version(int major, int minor, int revision)
public Version(int major, int minor, int revision)
{
{
this.major = major;
this.major = major;
this.minor = minor;
this.minor = minor;
this.revision = revision;
this.revision = revision;
}
}
public Version(String version) throws MinorException
public Version(String version) throws MinorException
{
{
String[] v = version.trim().split("\\.");
String[] v = version.trim().split("\\.");
if(v.length == 3)
if(v.length == 3)
{
{
try
try
{
{
major = Integer.parseInt(v[0]);
major = Integer.parseInt(v[0]);
minor = Integer.parseInt(v[1]);
minor = Integer.parseInt(v[1]);
revision = Integer.parseInt(v[2]);
revision = Integer.parseInt(v[2]);
}
}
catch (NumberFormatException e)
catch (NumberFormatException e)
{
{
throw new MinorException("Invalid versioning!");
throw new MinorException("Invalid versioning!");
}
}
}
}
else
else
{
{
throw new MinorException("Invalid versioning!");
throw new MinorException("Invalid versioning!");
}
}
}
}
public int getMajor()
public int getMajor()
{
{
return major;
return major;
}
}
public int getMinor()
public int getMinor()
{
{
return minor;
return minor;
}
}
public int getRevision()
public int getRevision()
{
{
return minor;
return minor;
}
}
public String getText()
public String getText()
{
{
return this.major+"."+this.minor+"."+this.revision;
return this.major+"."+this.minor+"."+this.revision;
}
}
public void setMajor(int major)
public void setMajor(int major)
{
{
this.major = major;
this.major = major;
}
}
public void setMinor(int minor)
public void setMinor(int minor)
{
{
this.minor = minor;
this.minor = minor;
}
}
public void setRevision(int revision)
public void setRevision(int revision)
{
{
this.revision = revision;
this.revision = revision;
}
}
public boolean isBiggerThan(Version version)
public boolean isBiggerThan(Version version)
{
{
if(major>version.major)
if (major == version.major)
return true;
else if(major < version.major)
return false;
else
{
{
if (minor > version.minor)
if (minor == version.minor)
return true;
{
else if(minor < version.minor)
return revision > version.revision;
return false;
}
else
else
{
{
if(revision > version.revision)
return minor > version.minor;
return true;
else
return false;
}
}
}
}
else
{
return major > version.major;
}
}
}
public boolean isEqual(Version version)
public boolean isEqual(Version version)
{
{
return version.major == this.major && version.minor == this.minor && version.revision == this.revision;
return version.major == this.major && version.minor == this.minor && version.revision == this.revision;
}
}
}
}
/*
/*
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Stream-Pi - Free & Open-Source Modular Cross-Platform Programmable Macro Pad
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
Copyright (C) 2019-2021 Debayan Sutradhar (rnayabed), Samuel Quiñones (SamuelQuinones)
This program is free software: you can redistribute it and/or modify
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
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
(at your option) any later version.
This program is distributed in the hope that it will be useful,
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
GNU General Public License for more details.
Originally Written by : Debayan Sutradhar (rnayabed)
Originally Written by : Debayan Sutradhar (rnayabed)
*/
*/
package com.stream_pi.util.xmlconfighelper;
package com.stream_pi.util.xmlconfighelper;
import java.io.File;
import java.io.File;
import java.util.logging.Logger;
import java.util.logging.Logger;
import javax.xml.transform.Result;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.Node;
public class XMLConfigHelper {
public class XMLConfigHelper {
private static Logger logger = Logger.getLogger(XMLConfigHelper.class.getName());
private static final Logger logger = Logger.getLogger(XMLConfigHelper.class.getName());
public static String getStringProperty(Element parentElement, String propertyName) throws Exception
public static String getStringProperty(Element parentElement, String propertyName) throws Exception
{
{
return getProperty(parentElement, propertyName, false, null, null);
return getProperty(parentElement, propertyName, false, null, null);
}
}
public static int getIntProperty(Element parentElement, String propertyName) throws Exception
public static int getIntProperty(Element parentElement, String propertyName) throws Exception
{
{
return Integer.parseInt(getProperty(parentElement, propertyName, false, null, null));
return Integer.parseInt(getProperty(parentElement, propertyName, false, null, null));
}
}
public static double getDoubleProperty(Element parentElement, String propertyName) throws Exception
public static double getDoubleProperty(Element parentElement, String propertyName) throws Exception
{
{
return Double.parseDouble(getProperty(parentElement, propertyName, false, null, null));
return Double.parseDouble(getProperty(parentElement, propertyName, false, null, null));
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName) throws Exception
public static boolean getBooleanProperty(Element parentElement, String propertyName) throws Exception
{
{
return getProperty(parentElement, propertyName, false, null, null).equals("true");
return getProperty(parentElement, propertyName, false, null, null).equals("true");
}
}
public static String getProperty(Element parentElement, String propertyName, boolean createNewIfDoesntExist, Document document, File file) throws Exception
public static String getProperty(Element parentElement, String propertyName, boolean createNewIfDoesntExist, Document document, File file) throws Exception
{
{
try {
try {
return parentElement.getElementsByTagName(propertyName).item(0).getTextContent();
return parentElement.getElementsByTagName(propertyName).item(0).getTextContent();
}
}
catch (Exception e)
catch (Exception e)
{
{
logger.warning("CANNOT get property "+parentElement.getNodeName()+"."+propertyName+"!");
logger.warning("CANNOT get property "+parentElement.getNodeName()+"."+propertyName+"!");
if(createNewIfDoesntExist)
if (createNewIfDoesntExist)
{
{
logger.warning("Creating new property by that name ...");
logger.warning("Creating new property by that name ...");
Element newProp = document.createElement(propertyName);
Element newProp = document.createElement(propertyName);
parentElement.appendChild(newProp);
parentElement.appendChild(newProp);
save(document, file);
save(document, file);
}
}
throw e;
throw e;
}
}
}
}
public static void save(Document document, File file) throws Exception
public static void save(Document document, File file) throws Exception
{
{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(file);
Result output = new StreamResult(file);
Source input = new DOMSource(document);
Source input = new DOMSource(document);
transformer.transform(input, output);
transformer.transform(input, output);
}
}
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace)
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace)
{
{
return getStringProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getStringProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
String tbr = ifNotPresent;
String tbr = ifNotPresent;
try
try
{
{
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file);
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file);
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static void removeChilds(Node node) {
public static void removeChilds(Node node) {
while (node.hasChildNodes())
while (node.hasChildNodes())
node.removeChild(node.getFirstChild());
node.removeChild(node.getFirstChild());
}
}
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace)
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace)
{
{
return getIntProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getIntProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static int getIntProperty(Element parentElement, String propertyName, int ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
int tbr = ifNotPresent;
int tbr = ifNotPresent;
try
try
{
{
tbr = Integer.parseInt(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
tbr = Integer.parseInt(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent)
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent)
{
{
return getDoubleProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
return getDoubleProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
}
}
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace)
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace)
{
{
return getDoubleProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getDoubleProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static double getDoubleProperty(Element parentElement, String propertyName, double ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
double tbr = ifNotPresent;
double tbr = ifNotPresent;
try
try
{
{
tbr = Double.parseDouble(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
tbr = Double.parseDouble(getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file));
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent)
public static String getStringProperty(Element parentElement, String propertyName, String ifNotPresent)
{
{
return getStringProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
return getStringProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace)
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace)
{
{
return getBooleanProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
return getBooleanProperty(parentElement, propertyName, ifNotPresent, printStackTrace, false, null, null);
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent, boolean printStackTrace, boolean createNewIfDoesntExist,
Document document, File file)
Document document, File file)
{
{
boolean tbr = ifNotPresent;
boolean tbr = ifNotPresent;
try
try
{
{
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file).equals("true");
tbr = getProperty(parentElement, propertyName, createNewIfDoesntExist, document, file).equals("true");
}
}
catch(Exception e)
catch(Exception e)
{
{
if(printStackTrace)
if(printStackTrace)
e.printStackTrace();
e.printStackTrace();
}
}
return tbr;
return tbr;
}
}
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent)
public static boolean getBooleanProperty(Element parentElement, String propertyName, boolean ifNotPresent)
{
{
return getBooleanProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
return getBooleanProperty(parentElement, propertyName, ifNotPresent, true, false, null, null);
}
}
public static boolean doesElementExist(Element parent, String nameOfElement)
public static boolean doesElementExist(Element parent, String nameOfElement)
{
{
return parent.getElementsByTagName(nameOfElement).getLength() > 0;
return parent.getElementsByTagName(nameOfElement).getLength() > 0;
}
}
public static boolean doesElementExist(Document document, String nameOfElement)
public static boolean doesElementExist(Document document, String nameOfElement)
{
{
return document.getElementsByTagName(nameOfElement).getLength() > 0;
return document.getElementsByTagName(nameOfElement).getLength() > 0;
}
}
}
}