package com.ht.ui.controls;

import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.animation.TimelineBuilder;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.util.Duration;

public class MessageInfoLabel extends Label {
	private Timeline messageAnimate;
	private double opacity = 1;

	/**
	 * 用于显示提示信息, 提示信息显示后自动消失, 默认显示时间为1秒，消失时间为2秒，共显示3秒
	 * @param parent
	 */
	public MessageInfoLabel() {
		this(1, 2);
	}
	
	public MessageInfoLabel(double animDelay, double animDur) {
		this(animDelay, animDur, 1);
	}
	public MessageInfoLabel(double animDelay, double animDur, double opacity) {
		super();
		getStyleClass().add("message");
		setOpacity(0);
		
		this.opacity = opacity;
		messageAnimate = TimelineBuilder
				.create()
				.keyFrames(
						new KeyFrame(Duration.seconds(animDur),
								new EventHandler<ActionEvent>() {
									public void handle(ActionEvent t) {
									}
								}, new KeyValue(opacityProperty(), 0,
										Interpolator.EASE_BOTH))).build();
		messageAnimate.setDelay(Duration.seconds(animDelay));
	}
	
	/**
	 * messageLabel.show("请输入能耗数据");
	 * @param msg
	 */
	public void show(String msg) {
		setText(msg);
		setOpacity(opacity);
		messageAnimate.stop();
		messageAnimate.play();
	}
	
}
