util

Clone or download

Updated Alert System

Modified Files

package com.StreamPi.Util.Alert;
package com.StreamPi.Util.Alert;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller;
import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
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.ScrollBarPolicy;
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.StackPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.layout.VBox;
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 Node contentNode;
private Pane contentPane;
private static StackPane stackPaneParent;
private static StackPane stackPaneParent;
public static void setParent(StackPane parent) {
public static void setParent(StackPane parent) {
stackPaneParent = parent;
stackPaneParent = parent;
stackPaneParent.getStyleClass().add("alert_pane_parent");
}
}
public static StackPane getParent() {
public static StackPane getParent() {
return stackPaneParent;
return stackPaneParent;
}
}
private StreamPiAlertListener streamPiAlertListener = null;
private StreamPiAlertListener streamPiAlertListener = null;
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType,
Node contentNode, String... buttons) {
Pane contentPane, String... buttons) {
set(title, streamPiAlertType, contentNode, buttons);
set(title, streamPiAlertType, contentPane, buttons);
}
}
public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType)
{
{
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
public StreamPiAlert(String title, String contentText, String... buttons)
public StreamPiAlert(String title, String contentText, String... buttons)
{
{
Label label = new Label(contentText);
Label label = new Label(contentText);
label.setWrapText(true);
label.setWrapText(true);
VBox vBox = new VBox(label);
set(title, StreamPiAlertType.INFORMATION, label, buttons);
set(title, StreamPiAlertType.INFORMATION, vBox, buttons);
}
}
public StreamPiAlert(String title, String contentText)
public StreamPiAlert(String title, String contentText)
{
{
Label label = new Label(contentText);
Label label = new Label(contentText);
label.setWrapText(true);
label.setWrapText(true);
VBox vBox = new VBox(label);
set(title, StreamPiAlertType.INFORMATION, label, new String[]{ "OK" });
set(title, StreamPiAlertType.INFORMATION, vBox, 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,
private void set(String title, StreamPiAlertType streamPiAlertType,
Node contentNode, String... buttons)
Pane contentPane, String... buttons)
{
{
this.title = title;
this.title = title;
this.buttons = buttons;
this.buttons = buttons;
this.contentNode = contentNode;
this.contentPane = contentPane;
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
public void setOnClicked(StreamPiAlertListener streamPiAlertListener) {
public void setOnClicked(StreamPiAlertListener streamPiAlertListener) {
this.streamPiAlertListener = streamPiAlertListener;
this.streamPiAlertListener = streamPiAlertListener;
}
}
public String getTitle() {
public String getTitle() {
return title;
return title;
}
}
public String[] getButtons() {
public String[] getButtons() {
return buttons;
return buttons;
}
}
public void setAlertContent(Node contentNode) {
public void setAlertContent(Pane contentPane) {
this.contentNode = contentNode;
this.contentPane = contentPane;
}
}
public void setButtons(String... buttons) {
public void setButtons(String... buttons) {
this.buttons = buttons;
this.buttons = buttons;
}
}
public VBox getAlertPane(String title, Node alertPane) {
public VBox getAlertPane(String title, Pane alertPane) {
VBox alertVBox = new VBox();
VBox alertVBox = new VBox();
alertVBox.getStyleClass().addAll("alert-pane");
alertVBox.getStyleClass().add("alert_pane");
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.getStyleClass().add("alert_header_icon");
HBox header = new HBox(label, new SpaceFiller(FillerType.HBox), fontIcon);
header.getStyleClass().add("alert_header");
HBox header = new HBox(label, new SpaceFiller(FillerType.HBox), streamPiAlertType.getIcon());
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();
});
});
button.getStyleClass().add("alert-button");
button.getStyleClass().add("alert_button");
buttonBar.getChildren().add(button);
buttonBar.getChildren().add(button);
}
}
alertPane.getStyleClass().addAll("alert-content-pane");
alertPane.getStyleClass().add("alert_content_pane");
ScrollPane scrollPane = new ScrollPane(alertPane);
alertPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
alertVBox.getChildren().addAll(
alertVBox.getChildren().addAll(
header,
header,
alertPane,
scrollPane,
buttonBar
buttonBar
);
);
return alertVBox;
return alertVBox;
}
}
public Node getContentNode()
public Pane getContentPane()
{
{
return contentNode;
return contentPane;
}
}
public void show()
public void show()
{
{
stackPaneParent.getChildren().add(getAlertPane(getTitle(), getContentNode()));
stackPaneParent.getChildren().add(getAlertPane(getTitle(), getContentPane()));
stackPaneParent.toFront();
stackPaneParent.toFront();
stackPaneParent.setVisible(true);
stackPaneParent.setVisible(true);
}
}
public void destroy()
public void destroy()
{
{
stackPaneParent.getChildren().clear();
stackPaneParent.getChildren().clear();
stackPaneParent.toBack();
stackPaneParent.toBack();
stackPaneParent.setVisible(false);
//stackPaneParent.setVisible(false);
}
}
}
}
package com.StreamPi.Util.Alert;
package com.StreamPi.Util.Alert;
import org.kordamp.ikonli.javafx.FontIcon;
import org.kordamp.ikonli.javafx.FontIcon;
import javafx.scene.paint.Paint;
import javafx.scene.paint.Paint;
public enum StreamPiAlertType {
public enum StreamPiAlertType {
INFORMATION("fas-info"),
INFORMATION("fas-info"),
ALERT("fas-exclamation-triangle"),
WARNING("fas-exclamation-triangle"),
ERROR("fas-times");
ERROR("fas-times");
private final String fontAwesomeIconCode;
private final String fontAwesomeIconCode;
StreamPiAlertType(String fontAwesomeIconCode)
StreamPiAlertType(String fontAwesomeIconCode)
{
{
this.fontAwesomeIconCode = fontAwesomeIconCode;
this.fontAwesomeIconCode = fontAwesomeIconCode;
}
}
public FontIcon getIcon()
public String getIconCode()
{
{
return getIcon("#000000",13);
return fontAwesomeIconCode;
}
public FontIcon getIcon(String colorHex, int size)
{
FontIcon fontIcon = new FontIcon(fontAwesomeIconCode);
fontIcon.setIconSize(size);
fontIcon.setIconColor(Paint.valueOf(colorHex));
return fontIcon;
}
}
}
}
module com.StreamPi.Util {
module com.StreamPi.Util {
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.javafx;
requires org.kordamp.ikonli.fontawesome5;
requires org.kordamp.ikonli.fontawesome5;
requires javafx.base;
requires javafx.base;
requires javafx.controls;
requires javafx.controls;
exports com.StreamPi.Util.Version;
exports com.StreamPi.Util.Version;
exports com.StreamPi.Util.Exception;
exports com.StreamPi.Util.Exception;
exports com.StreamPi.Util.Platform;
exports com.StreamPi.Util.Platform;
exports com.StreamPi.Util.FormHelper;
exports com.StreamPi.Util.FormHelper;
exports com.StreamPi.Util.StartAtBoot;
exports com.StreamPi.Util.StartAtBoot;
exports com.StreamPi.Util.Alert;
}
}