Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
add useful method for VToast
Browse files Browse the repository at this point in the history
  • Loading branch information
vran-dev committed Sep 30, 2019
1 parent 9b48c7a commit 0570354
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/main/java/cc/cc1234/main/controller/VToast.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,37 @@
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
import javafx.util.Duration;

public class VToast {

public static void toastSuccess(Stage primaryStage) {
toast(primaryStage, successPanel("√ success"));
public static void toastSuccess(Window parent) {
toast(parent, successPanel("√ success"));
}

public static void toastFailure(Stage primaryStage) {
public static void toastFailure(Window parent) {
toast(parent, failurePanel("× failure"));
}

public static void toastSuccess(Window parent, String message) {
toast(parent, successPanel(message));
}

toast(primaryStage, failurePanel("× failure"));
public static void toastFailure(Window parent, String message) {
toast(parent, failurePanel(message));
}

public static void toast(Stage primaryStage, StackPane panel) {
toast(primaryStage, panel, 1000, 3000);
public static void toastInfo(Window parent, String message) {
toast(parent, infoPanel(message));
}

public static void toast(Stage primaryStage, StackPane root, int fadeInDelay, int fadeOutDelay) {
final Stage toastStage = initToastStage(primaryStage, root);
public static void toast(Window parent, StackPane panel) {
toast(parent, panel, 1000, 3000);
}

public static void toast(Window parent, StackPane root, int fadeInDelay, int fadeOutDelay) {
final Stage toastStage = initToastStage(parent, root);
toastStage.show();
initAnimation(toastStage, fadeInDelay, fadeOutDelay);
}
Expand All @@ -55,15 +67,26 @@ private static StackPane failurePanel(String message) {
return root;
}

private static Stage initToastStage(Stage primaryStage, StackPane root) {
private static StackPane infoPanel(String message) {
Text text = new Text(message);
text.setFont(Font.font("Verdana", 16));
text.setFill(Color.WHITE);

StackPane root = new StackPane(text);
root.setStyle("-fx-background-radius: 20; -fx-background-color: #66bb6a; -fx-padding: 6px;");
root.setOpacity(0);
return root;
}

private static Stage initToastStage(Window parent, StackPane root) {
Stage toastStage = new Stage();
toastStage.initOwner(primaryStage);
toastStage.initOwner(parent);
toastStage.setResizable(false);
toastStage.initStyle(StageStyle.TRANSPARENT);

// set position
toastStage.setX(primaryStage.getX());
toastStage.setY(primaryStage.getY() + primaryStage.getScene().getY() + 10);
toastStage.setX(parent.getX());
toastStage.setY(parent.getY() + parent.getScene().getY() + 10);

Scene scene = new Scene(root);
scene.setFill(Color.TRANSPARENT);
Expand Down

0 comments on commit 0570354

Please sign in to comment.