package bluej.groupwork.ui;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
import threadchecker.OnThread;
import threadchecker.Tag;
@OnThread(Tag.FXPlatform)
public class ActivityIndicator
extends StackPane{
private ProgressBar progressBar;
private Label messageLabel;
private Timeline animation;
public ActivityIndicator()
{
progressBar = new ProgressBar();
progressBar.setVisible(false);
getChildren().add(progressBar);
messageLabel = new Label();
messageLabel.setVisible(false);
getChildren().add(messageLabel);
}
| Set the activity indicator's running state. This is safe to call
| from any thread.
|
| @param running The new running state
|
public void setRunning(boolean running)
{
messageLabel.setVisible(!running);
progressBar.setVisible(running);
if (animation != null)
{
animation.stop();
animation = null;
}
if (running)
{
animation = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(progressBar.progressProperty(), 0.0)),
new KeyFrame(Duration.millis(1000), new KeyValue(progressBar.progressProperty(), 1.0)));
animation.setAutoReverse(true);
animation.setCycleCount(Animation.INDEFINITE);
animation.playFromStart();
}
}
| Set message to display when the activity indicator is not in a running state.
| @param msg
|
public void setMessage(String msg)
{
if (msg != null){
messageLabel.setText(msg);
}
}
}
top,
use,
map,
class ActivityIndicator
. ActivityIndicator
. setRunning
. setMessage
73 neLoCode
+ 5 LoComm