commit 10/04/2025

This commit is contained in:
rdkartono
2025-04-10 16:21:56 +07:00
parent 7cdefa6f1d
commit b6a3076993
23 changed files with 420 additions and 119681 deletions

View File

@@ -1,7 +1,14 @@
package id.co.gtc.erhacam;
import javafx.animation.KeyFrame;
import javafx.animation.PauseTransition;
import javafx.animation.Timeline;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Scene;
@@ -14,10 +21,7 @@ import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.*;
import javafx.util.Duration;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -87,27 +91,8 @@ public class AutoCloseAlert {
clear();
}
/**
* Show an alert with a title, content, and automatically close after a few seconds
* @param title the title of the alert
* @param content the content of the alert
* @param seconds the number of seconds before the alert is closed, or put 0 to keep it open
* @param onClose What to do after auto close
*/
public static void show(String title, String content, int seconds, Consumer<String> onClose){
if (Platform.isFxApplicationThread()){
Stage alertStage = _showtext(title, "", content);
closeAlertStage(seconds, onClose, alertStage);
} else {
Platform.runLater(()->{
Stage alertStage = _showtext(title, "", content);
closeAlertStage(seconds, onClose, alertStage);
});
}
}
/**
@@ -150,6 +135,87 @@ public class AutoCloseAlert {
}
}
public static void showpictures(String[] pictures, int seconds, Consumer<String> onClose){
List<Image> images = new ArrayList<>();
if (pictures != null){
for(String pp : pictures){
Image ii = LoadImage(pp);
if (ii!=null) images.add(ii);
}
}
if (!images.isEmpty()){
Image[] source = images.toArray(new Image[0]);
if (Platform.isFxApplicationThread()){
_showpictures(source, seconds, onClose);
} else {
Platform.runLater(()-> _showpictures(source,seconds, onClose));
}
}
}
private static void _showpictures(Image[] pictures, int seconds, Consumer<String> onClose){
close();
Stage alertStage = new Stage();
alertStage.initModality(Modality.APPLICATION_MODAL);
alertStage.initStyle(StageStyle.UTILITY);
alertStage.setAlwaysOnTop(true);
alertStage.setResizable(false);
int width = (int) Screen.getPrimary().getBounds().getWidth();
int height = (int) Screen.getPrimary().getBounds().getHeight();
ImageView imageView = new ImageView();
imageView.setPreserveRatio(true);
imageView.setFitWidth(width);
imageView.setFitHeight(height);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(imageView);
alertStage.setScene(new Scene(borderPane, width, height));
alertStage.centerOnScreen();
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(0), event -> {
System.out.println("First timeline, showing the alertstage");
alertStage.show();
}));
for(int xx = 0; xx < pictures.length; xx++){
final int index = xx;
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(seconds*(index+1)), event -> {
System.out.println("showpicture timeline keyframe "+index);
imageView.setImage(pictures[index]);
}));
}
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(seconds* (pictures.length+1)), event -> {
System.out.println("showpicture timeline finished");
alertStage.close();
if (currentAlertStage == alertStage) {
currentAlertStage = null;
}
if (onClose!=null) onClose.accept(shownTitle);
clear();
}));
timeline.play();
System.out.println("showpicture timeline play");
currentAlertStage = alertStage;
shownTitle = "";
shownContent = "";
shownHeader = "";
}
private static Stage _showbanner(Image image){
close();