/***********************************************************************************
*
* Copyright (c) 2015 Kamil Baczkowicz
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
*
* Kamil Baczkowicz - initial API and implementation and/or initial documentation
*
*/
package pl.baczkowicz.spy.ui.utils;
import javafx.application.Platform;
import javafx.geometry.Point2D;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import pl.baczkowicz.spy.utils.ThreadingUtils;
public class TooltipFactory
{
/**
* Shows the given tooltip for 5 seconds.
*
* @param button The button to be used as the parent
* @param message The message to be shown in the tooltip
*/
public static void createTooltip(final Button button, final String message)
{
final Tooltip tooltip = new Tooltip(message);
button.setTooltip(tooltip);
tooltip.setAutoHide(true);
tooltip.setAutoFix(true);
Point2D p = button.localToScene(0.0, 0.0);
tooltip.show(button.getScene().getWindow(),
p.getX() + button.getScene().getX() + button.getScene().getWindow().getX() - 50,
p.getY() + button.getScene().getY() + button.getScene().getWindow().getY() - 50);
new Thread(new Runnable()
{
@Override
public void run()
{
ThreadingUtils.sleep(5000);
Platform.runLater(new Runnable()
{
@Override
public void run()
{
button.setTooltip(null);
tooltip.hide();
}
});
}
}).start();
}
}