From: Debayan Sutradhar Date: Sat, 19 Dec 2020 00:52:28 +0530 Subject: Updated Alert System --- Updated Alert System --- --- 'a/src/main/java/com/StreamPi/Util/Alert/StreamPiAlert.java' +++ b/src/main/java/com/StreamPi/Util/Alert/StreamPiAlert.java @@ -3,25 +3,34 @@ package com.StreamPi.Util.Alert; import com.StreamPi.Util.FormHelper.SpaceFiller; import com.StreamPi.Util.FormHelper.SpaceFiller.FillerType; +import org.kordamp.ikonli.javafx.FontIcon; + 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.StackPane; +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 Node contentNode; + private Pane contentPane; private static StackPane stackPaneParent; public static void setParent(StackPane parent) { stackPaneParent = parent; + + stackPaneParent.getStyleClass().add("alert_pane_parent"); } public static StackPane getParent() { @@ -31,8 +40,8 @@ public class StreamPiAlert { private StreamPiAlertListener streamPiAlertListener = null; public StreamPiAlert(String title, StreamPiAlertType streamPiAlertType, - Node contentNode, String... buttons) { - set(title, streamPiAlertType, contentNode, buttons); + Pane contentPane, String... buttons) { + set(title, streamPiAlertType, contentPane, buttons); } public void setStreamPiAlertType(StreamPiAlertType streamPiAlertType) @@ -44,24 +53,39 @@ public class StreamPiAlert { { Label label = new Label(contentText); 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) { Label label = new Label(contentText); 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, - Node contentNode, String... buttons) + Pane contentPane, String... buttons) { this.title = title; this.buttons = buttons; - this.contentNode = contentNode; + this.contentPane = contentPane; this.streamPiAlertType = streamPiAlertType; } @@ -79,45 +103,61 @@ public class StreamPiAlert { return buttons; } - public void setAlertContent(Node contentNode) { - this.contentNode = contentNode; + public void setAlertContent(Pane contentPane) { + this.contentPane = contentPane; } public void setButtons(String... buttons) { this.buttons = buttons; } - public VBox getAlertPane(String title, Node alertPane) { + public VBox getAlertPane(String title, Pane alertPane) { VBox alertVBox = new VBox(); - alertVBox.getStyleClass().addAll("alert-pane"); + alertVBox.getStyleClass().add("alert_pane"); 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)); HBox buttonBar = new HBox(); - buttonBar.getStyleClass().add("alert-button-bar"); + 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"); + button.getStyleClass().add("alert_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( header, - alertPane, + scrollPane, buttonBar ); @@ -125,14 +165,14 @@ public class StreamPiAlert { return alertVBox; } - public Node getContentNode() + public Pane getContentPane() { - return contentNode; + return contentPane; } public void show() { - stackPaneParent.getChildren().add(getAlertPane(getTitle(), getContentNode())); + stackPaneParent.getChildren().add(getAlertPane(getTitle(), getContentPane())); stackPaneParent.toFront(); stackPaneParent.setVisible(true); } @@ -141,6 +181,6 @@ public class StreamPiAlert { { stackPaneParent.getChildren().clear(); stackPaneParent.toBack(); - stackPaneParent.setVisible(false); + //stackPaneParent.setVisible(false); } } --- 'a/src/main/java/com/StreamPi/Util/Alert/StreamPiAlertType.java' +++ b/src/main/java/com/StreamPi/Util/Alert/StreamPiAlertType.java @@ -6,7 +6,7 @@ import javafx.scene.paint.Paint; public enum StreamPiAlertType { INFORMATION("fas-info"), - ALERT("fas-exclamation-triangle"), + WARNING("fas-exclamation-triangle"), ERROR("fas-times"); private final String fontAwesomeIconCode; @@ -16,17 +16,8 @@ public enum StreamPiAlertType { this.fontAwesomeIconCode = fontAwesomeIconCode; } - public FontIcon getIcon() + public String getIconCode() { - return getIcon("#000000",13); - } - - public FontIcon getIcon(String colorHex, int size) - { - FontIcon fontIcon = new FontIcon(fontAwesomeIconCode); - fontIcon.setIconSize(size); - fontIcon.setIconColor(Paint.valueOf(colorHex)); - - return fontIcon; + return fontAwesomeIconCode; } } --- 'a/src/main/java/module-info.java' +++ b/src/main/java/module-info.java @@ -10,4 +10,5 @@ module com.StreamPi.Util { exports com.StreamPi.Util.Platform; exports com.StreamPi.Util.FormHelper; exports com.StreamPi.Util.StartAtBoot; + exports com.StreamPi.Util.Alert; } \ No newline at end of file