package com.temporaryteam.noticeditor.view;

import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.animation.TranslateTransition;
import javafx.event.ActionEvent;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.util.Duration;

/**
 * Simple notification.
 * @author aNNiMON
 */
public final class Notification {
	
	public static final Duration DURATION_SHORT = new Duration(2000);
	public static final Duration DURATION_LONG = new Duration(5000);
	private static final Duration TRANSITION_DURATION = new Duration(300);

	private static VBox notificationBox;
	private static Label notificationLabel;
	
	private static Timeline hideTimer;
	private static TranslateTransition transitionIn, transitionOut;
	
	public static void init(VBox vbox, Label label) {
		notificationBox = vbox;
		notificationLabel = label;
		
		transitionIn = new TranslateTransition(TRANSITION_DURATION, notificationBox);
		transitionIn.setToY(0);
		
		transitionOut = new TranslateTransition(TRANSITION_DURATION, notificationBox);
		transitionOut.setFromY(0);
		transitionOut.setOnFinished((e) -> notificationBox.setVisible(false));
	}
	
	public static void show(String text) {
		show(text, DURATION_SHORT);
	}
	
	public static void show(String text, Duration duration) {
		if (hideTimer != null) {
			// show new notification while previous exists
			hideTimer.stop();
			transitionOut.stop();
		}
		notificationLabel.setText(text);
		hideTimer = new Timeline(new KeyFrame(duration.add(TRANSITION_DURATION)));
		hideTimer.setOnFinished(Notification::hide);
		hideTimer.playFromStart();
		notificationBox.setVisible(true);
		
		transitionIn.setFromY(notificationBox.getHeight());
		transitionIn.playFromStart();
	}
	
	private static void hide(ActionEvent e) {
		if (hideTimer != null) {
            hideTimer.stop();
            hideTimer = null;
        }
		transitionOut.setToY(notificationBox.getHeight());
		transitionOut.playFromStart();
	}
}

@@ -252,16 +252,82 @@
 t.VBox;%0A
+import javafx.scene.paint.Color;%0Aimport javafx.scene.paint.Paint;%0A
 import j
@@ -347,16 +347,16 @@
 ration;%0A
-
 %0A/**%0A * 
@@ -568,16 +568,18 @@
 (5000);%0A
+%09%0A
 %09private
@@ -641,16 +641,201 @@
 on(300);
+%0A%09private static final Paint PAINT_MESSAGE = Color.WHITE;%0A%09private static final Paint PAINT_ERROR = Color.rgb(255, 80, 80);%0A%09private static final Paint PAINT_SUCCESS = Color.LIGHTGREEN;
 %0A%0A%09priva
@@ -1548,24 +1548,323 @@
 duration) %7B%0A
+%09%09show(text, duration, PAINT_MESSAGE);%0A%09%7D%0A%09%0A%09public static void error(String text) %7B%0A%09%09show(text, DURATION_LONG, PAINT_ERROR);%0A%09%7D%0A%09%0A%09public static void success(String text) %7B%0A%09%09show(text, DURATION_LONG, PAINT_SUCCESS);%0A%09%7D%0A%09%0A%09public static void show(String text, Duration duration, Paint textFill) %7B%0A
 %09%09if (hideTi
@@ -1978,12 +1978,55 @@
 ();%0A
-
 %09%09%7D%0A
+%09%09notificationLabel.setTextFill(textFill);%0A
 %09%09no

Add notification types