All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.puresoltechnologies.javafx.tasks.TaskProgressPane Maven / Gradle / Ivy
package com.puresoltechnologies.javafx.tasks;
import java.io.IOException;
import com.puresoltechnologies.javafx.utils.FXDefaultFonts;
import com.puresoltechnologies.javafx.utils.ResourceUtils;
import javafx.concurrent.Task;
import javafx.concurrent.Worker.State;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
public class TaskProgressPane extends GridPane {
private final Task task;
private final Image image;
private final ProgressBar progressBar;
private final Button abortButton;
public TaskProgressPane(Task task) {
this(task, null);
}
public TaskProgressPane(Task task, Image image) {
super();
try {
this.image = image;
this.task = task;
Label titleLabel = new Label(task.getTitle());
titleLabel.setFont(FXDefaultFonts.boldFont);
titleLabel.textProperty().bind(task.titleProperty());
ImageView imageView = new ImageView(image);
progressBar = new ProgressBar(0.0);
progressBar.setVisible(false);
progressBar.setMaxWidth(Double.MAX_VALUE);
progressBar.progressProperty().bind(task.progressProperty());
ImageView crossView = ResourceUtils.getImageView(this, "icons/FatCow_Icons16x16/cross.png");
abortButton = new Button("Abort...", crossView);
abortButton.setOnAction(event -> {
task.cancel();
event.consume();
});
Label messageLabel = new Label();
messageLabel.textProperty().bind(task.messageProperty());
task.stateProperty().addListener((event, oldValue, newValue) -> {
if (newValue == State.SCHEDULED) {
progressBar.setVisible(true);
}
});
setConstraints(titleLabel, 1, 0, 2, 1, HPos.LEFT, VPos.BASELINE, Priority.SOMETIMES, Priority.NEVER);
setConstraints(imageView, 0, 1, 1, 3, HPos.LEFT, VPos.TOP, Priority.NEVER, Priority.NEVER);
setConstraints(progressBar, 1, 1, 1, 1, HPos.LEFT, VPos.BASELINE, Priority.ALWAYS, Priority.NEVER);
setConstraints(abortButton, 2, 1, 1, 1, HPos.CENTER, VPos.CENTER, Priority.NEVER, Priority.NEVER);
setConstraints(messageLabel, 1, 2, 2, 1, HPos.LEFT, VPos.BASELINE, Priority.SOMETIMES, Priority.NEVER);
if (image != null) {
getChildren().add(imageView);
}
getChildren().addAll(titleLabel, progressBar, abortButton, messageLabel);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}