util
Clone or download
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 org.kordamp.ikonli.javafx.FontIcon;
import javafx.geometry.Insets;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
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;
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.Region;
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 Pane contentPane;
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");
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,
Pane contentPane, String... buttons) {
Pane contentPane, String... buttons) {
set(title, streamPiAlertType, contentPane, 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);
VBox vBox = new VBox(label);
set(title, StreamPiAlertType.INFORMATION, vBox, 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);
VBox vBox = new VBox(label);
set(title, StreamPiAlertType.INFORMATION, vBox, new String[]{ "OK" });
set(title, StreamPiAlertType.INFORMATION, vBox, new String[]{ "OK" });
}
}
public StreamPiAlert(String title, String contentText, StreamPiAlertType streamPiAlertType)
public StreamPiAlert(String title, String contentText, StreamPiAlertType streamPiAlertType)
{
{
Label label = new Label(contentText);
Label label = new Label(contentText);
label.setWrapText(true);
label.setWrapText(true);
VBox vBox = new VBox(label);
VBox vBox = new VBox(label);
set(title, streamPiAlertType, vBox, new String[]{ "OK" });
set(title, streamPiAlertType, vBox, new String[]{ "OK" });
}
}
private void set(String title, StreamPiAlertType streamPiAlertType,
private void set(String title, StreamPiAlertType streamPiAlertType,
Pane contentPane, String... buttons)
Pane contentPane, String... buttons)
{
{
this.title = title;
this.title = title;
this.buttons = buttons;
this.buttons = buttons;
this.contentPane = contentPane;
this.contentPane = contentPane;
this.streamPiAlertType = streamPiAlertType;
this.streamPiAlertType = streamPiAlertType;
}
}
public void setOnClicked(StreamPiAlertListener streamPiAlertListener) {
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(Pane contentPane) {
public void setAlertContent(Pane contentPane) {
this.contentPane = contentPane;
this.contentPane = contentPane;
}
}
public void setButtons(String... buttons) {
public void setButtons(String... buttons) {
this.buttons = buttons;
this.buttons = buttons;
}
}
public VBox getAlertPane(String title, Pane alertPane) {
public VBox getAlertPane(String title, Pane alertPane) {
VBox alertVBox = new VBox();
VBox alertVBox = new VBox();
alertVBox.getStyleClass().add("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 fontIcon = new FontIcon(streamPiAlertType.getIconCode());
fontIcon.getStyleClass().add("alert_header_icon");
fontIcon.getStyleClass().addAll("alert_header_icon", streamPiAlertType.getIconStyleClassName());
HBox header = new HBox(label, new SpaceFiller(FillerType.HBox), fontIcon);
HBox header = new HBox(label, new SpaceFiller(FillerType.HBox), fontIcon);
header.getStyleClass().add("alert_header");
header.getStyleClass().add("alert_header");
header.setPadding(new Insets(10));
header.setPadding(new Insets(10));
HBox buttonBar = new HBox();
HBox buttonBar = new HBox();
buttonBar.getStyleClass().add("alert_button_bar");
buttonBar.getStyleClass().add("alert_button_bar");
for (String eachButtonString : buttons) {
for (String eachButtonString : buttons) {
Button button = new Button(eachButtonString);
Button button = new Button(eachButtonString);
button.setOnAction(event -> {
button.setOnAction(event -> {
if(this.streamPiAlertListener != null)
if(this.streamPiAlertListener != null)
this.streamPiAlertListener.onClick(eachButtonString);
this.streamPiAlertListener.onClick(eachButtonString);
destroy();
destroy();
});
});
button.getStyleClass().add("alert_button");
button.getStyleClass().add("alert_button");
buttonBar.getChildren().add(button);
buttonBar.getChildren().add(button);
}
}
alertPane.getStyleClass().add("alert_content_pane");
alertPane.getStyleClass().add("alert_content_pane");
ScrollPane scrollPane = new ScrollPane(alertPane);
ScrollPane scrollPane = new ScrollPane(alertPane);
alertPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
alertPane.prefWidthProperty().bind(scrollPane.widthProperty().subtract(10));
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setHbarPolicy(ScrollBarPolicy.NEVER);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
scrollPane.setVbarPolicy(ScrollBarPolicy.AS_NEEDED);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
VBox.setVgrow(scrollPane, Priority.ALWAYS);
alertVBox.getChildren().addAll(
alertVBox.getChildren().addAll(
header,
header,
scrollPane,
scrollPane,
buttonBar
buttonBar
);
);
return alertVBox;
return alertVBox;
}
}
public Pane getContentPane()
public Pane getContentPane()
{
{
return contentPane;
return contentPane;
}
}
public void show()
public void show()
{
{
stackPaneParent.getChildren().add(getAlertPane(getTitle(), getContentPane()));
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;
public abstract class StreamPiAlertListener {
public abstract class StreamPiAlertListener {
abstract void onClick(String buttonClicked);
public abstract void onClick(String buttonClicked);
}
}
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_information_icon"),
WARNING("fas-exclamation-triangle"),
WARNING("fas-exclamation-triangle", "alert_warning_icon"),
ERROR("fas-times");
ERROR("fas-times", "alert_error_icon");
private final String fontAwesomeIconCode;
private final String fontAwesomeIconCode;
private final String alertIconStyleClassName;
StreamPiAlertType(String fontAwesomeIconCode)
StreamPiAlertType(String fontAwesomeIconCode, String alertIconStyleClassName)
{
{
this.fontAwesomeIconCode = fontAwesomeIconCode;
this.fontAwesomeIconCode = fontAwesomeIconCode;
this.alertIconStyleClassName = alertIconStyleClassName;
}
}
public String getIconCode()
public String getIconCode()
{
{
return fontAwesomeIconCode;
return fontAwesomeIconCode;
}
}
public String getIconStyleClassName()
{
return alertIconStyleClassName;
}
}
}