1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| import java.io.File;
import java.util.Optional;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.image.Image;
import javafx.scene.layout.HBox;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class Main extends Application {
private Stage stage;
@Override
public void start(Stage primaryStage) {
this.stage = primaryStage;
final ProgressBar pbLoadImg = new ProgressBar();
pbLoadImg.setProgress(0);
final Button imgLoad = new Button();
imgLoad.setText("Load");
imgLoad.setOnAction(event -> {
final Optional<Image> image = loadImage();
image.ifPresent(img -> {
// Already loaded (may happen on small images).
if (!img.isBackgroundLoading() || img.getProgress() == 1) {
pbLoadImg.setProgress(1);
// showHistogram(image);
} else { // Still loading (may happen on big images).
pbLoadImg.progressProperty().bind(img.progressProperty());
img.progressProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.doubleValue() == 1) {
pbLoadImg.progressProperty().unbind();
// showHistogram(image);
}
});
}
});
// pbLoadImg.progressProperty().bind();
// //Tracer l'histogramme grayscale de l'image
// //ma progressbar
});
HBox root = new HBox();
root.getChildren().addAll(pbLoadImg, imgLoad);
Scene scene = new Scene(root);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
final Optional<Image> loadImage() {
FileChooser chooser = new FileChooser();
final File file = chooser.showOpenDialog(stage);
Optional<Image> result = Optional.empty();
if (file != null) {
result = Optional.of(new Image(file.toURI().toString(), true));
}
return result;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
} |
Partager