commit 27/03/2025
This commit is contained in:
@@ -6,19 +6,22 @@ import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Screen;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.StageStyle;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static Config.SomeCodes.ValidString;
|
||||
import static Config.SomeCodes.*;
|
||||
|
||||
public class AutoCloseAlert {
|
||||
|
||||
@@ -26,13 +29,23 @@ public class AutoCloseAlert {
|
||||
public static String shownTitle = "";
|
||||
public static String shownContent = "";
|
||||
public static String shownHeader = "";
|
||||
public static Image shownBanner = null;
|
||||
public static Image banner_01;
|
||||
public static Image banner_02;
|
||||
|
||||
private static void clear(){
|
||||
shownTitle = "";
|
||||
shownContent = "";
|
||||
shownHeader = "";
|
||||
public static void init(){
|
||||
String f_01 = ExtractResource("/IU photoboth-01.jpg");
|
||||
System.out.println("Banner 01 extracted as file: "+f_01);
|
||||
String f_02 = ExtractResource("/IU photoboth-02.jpg");
|
||||
System.out.println("Banner 02 extracted as file: "+f_02);
|
||||
banner_01 = LoadImage(f_01);
|
||||
if (banner_01!=null) System.out.println("Banner 01 loaded"); else System.out.println("Banner 01 not loaded");
|
||||
banner_02 = LoadImage(f_02);
|
||||
if (banner_02!=null) System.out.println("Banner 02 loaded"); else System.out.println("Banner 02 not loaded");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Close the current alert if it is shown
|
||||
*/
|
||||
@@ -54,6 +67,7 @@ public class AutoCloseAlert {
|
||||
Stage alertStage = _showtext(title, "", content);
|
||||
closeAlertStage(seconds, onClose, alertStage);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +88,48 @@ public class AutoCloseAlert {
|
||||
});
|
||||
}
|
||||
|
||||
public static void showbanner(Image b1, int seconds, Consumer<String> onClose){
|
||||
Platform.runLater(()->{
|
||||
Stage alertStage = _showbanner(b1);
|
||||
closeAlertStage(seconds, onClose, alertStage);
|
||||
});
|
||||
}
|
||||
|
||||
private static Stage _showbanner(Image image){
|
||||
close();
|
||||
|
||||
Stage alertStage = new Stage();
|
||||
alertStage.initModality(Modality.APPLICATION_MODAL);
|
||||
alertStage.initStyle(StageStyle.UTILITY);
|
||||
alertStage.setAlwaysOnTop(true);
|
||||
alertStage.setResizable(false);
|
||||
//System.out.println("_showbanner creating stage");
|
||||
|
||||
if (image!=null){
|
||||
ImageView imageView = new ImageView(image);
|
||||
imageView.setPreserveRatio(true);
|
||||
imageView.setFitWidth(1280);
|
||||
imageView.setSmooth(true);
|
||||
StackPane stackPane = new StackPane(imageView);
|
||||
alertStage.setScene(new Scene(stackPane, 1280, 720));
|
||||
//System.out.println("_showbanner setscene");
|
||||
} //else System.out.println("_showbanner not setscene because image is null");
|
||||
|
||||
alertStage.centerOnScreen();
|
||||
alertStage.show();
|
||||
//System.out.println("_showbanner show stage");
|
||||
|
||||
currentAlertStage = alertStage;
|
||||
shownBanner = image;
|
||||
shownTitle = "";
|
||||
shownContent = "";
|
||||
shownHeader = "";
|
||||
|
||||
return alertStage;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create an alert with a title, header, and content
|
||||
* @param title the title
|
||||
@@ -123,6 +179,7 @@ public class AutoCloseAlert {
|
||||
shownHeader = ValidString(header) ? header : "";
|
||||
shownContent = ValidString(content) ? content : "";
|
||||
shownTitle = ValidString(title) ? title : "";
|
||||
shownBanner = null;
|
||||
|
||||
return alertStage;
|
||||
}
|
||||
@@ -147,4 +204,23 @@ public class AutoCloseAlert {
|
||||
delay.play();
|
||||
}
|
||||
}
|
||||
|
||||
private static Image LoadImage(String filename){
|
||||
if (ValidFile(filename)){
|
||||
try{
|
||||
Image mm = new Image(Paths.get(filename).toUri().toString());
|
||||
System.out.println("Load image from "+filename);
|
||||
return mm;
|
||||
} catch (Exception e){
|
||||
System.out.println("Error loading image: " + filename+", Message: "+e.getMessage());
|
||||
}
|
||||
} else System.out.println("LoadImage: Invalid file: "+filename);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void clear(){
|
||||
shownTitle = "";
|
||||
shownContent = "";
|
||||
shownHeader = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user