commit 25/07/2025

This commit is contained in:
2025-07-25 09:32:00 +07:00
parent 49ac4353b3
commit d566e4bc4f
4 changed files with 51 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import javafx.scene.control.TextField;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.PixelFormat; import javafx.scene.image.PixelFormat;
import javafx.scene.image.WritableImage; import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import lombok.NonNull; import lombok.NonNull;
import org.bytedeco.javacv.Frame; import org.bytedeco.javacv.Frame;
import org.bytedeco.javacv.Java2DFrameConverter; import org.bytedeco.javacv.Java2DFrameConverter;
@@ -42,6 +43,7 @@ import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer; import java.util.function.Consumer;
import static org.bytedeco.opencv.global.opencv_core.CV_64F; import static org.bytedeco.opencv.global.opencv_core.CV_64F;
@@ -879,4 +881,30 @@ public class SomeCodes {
mat.data().get(data); mat.data().get(data);
return image; return image;
} }
/**
* Close Stage if not null
* and wait until closed
* @param obj Stage object to close
*/
public static void closeStage(Stage obj) throws InterruptedException {
if (obj != null) {
if (Platform.isFxApplicationThread()) {
// Already on FX thread, just close directly
obj.close();
} else {
CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(() -> {
try {
obj.close();
} finally {
latch.countDown();
}
});
// Wait for runLater task to finish
latch.await();
}
}
}
} }

View File

@@ -24,7 +24,6 @@ import org.tinylog.Logger;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.function.Consumer; import java.util.function.Consumer;
import static Config.SomeCodes.*; import static Config.SomeCodes.*;
@@ -84,8 +83,16 @@ public class AutoCloseAlert {
* Close the current alert if it is shown * Close the current alert if it is shown
*/ */
public static void close(){ public static void close(){
Optional.ofNullable(currentAlertStage).ifPresent(Stage::close); if (currentAlertStage!=null){
try {
closeStage(currentAlertStage);
} catch (InterruptedException e) {
Logger.error("Error closing alert stage: " + e.getMessage());
}
currentAlertStage = null; currentAlertStage = null;
}
clear(); clear();
} }
@@ -188,7 +195,12 @@ public class AutoCloseAlert {
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(0), event -> alertStage.show())); timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(0), event -> alertStage.show()));
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(seconds* (pictures.length)), event -> { timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(seconds* (pictures.length)), event -> {
alertStage.close(); try {
closeStage(alertStage);
} catch (InterruptedException e) {
Logger.error("Error closing alert stage: " + e.getMessage());
}
//alertStage.close();
if (currentAlertStage == alertStage) { if (currentAlertStage == alertStage) {
currentAlertStage = null; currentAlertStage = null;
} }
@@ -329,7 +341,12 @@ public class AutoCloseAlert {
if (seconds>0){ if (seconds>0){
PauseTransition delay = new PauseTransition(Duration.seconds(seconds)); PauseTransition delay = new PauseTransition(Duration.seconds(seconds));
delay.setOnFinished(e -> { delay.setOnFinished(e -> {
alertStage.close(); try {
closeStage(alertStage);
} catch (InterruptedException err) {
Logger.error("Error closing alert stage: " + err.getMessage());
}
//alertStage.close();
if (currentAlertStage == alertStage) { if (currentAlertStage == alertStage) {
currentAlertStage = null; currentAlertStage = null;
} }

View File

@@ -24,7 +24,7 @@ import static Config.SomeCodes.config;
public class MainApplication extends Application { public class MainApplication extends Application {
final String version = "10072025-PRODUCTION-1.0.2"; final String version = "10072025-PRODUCTION-1.0.3";
PhotoCleaner photoCleaner; PhotoCleaner photoCleaner;
public static Map<Integer, Detectors> detectorsList = new HashMap<>(); public static Map<Integer, Detectors> detectorsList = new HashMap<>();