1
1
package de .felixroske .jfxsupport ;
2
2
3
+ import java .util .ArrayList ;
4
+ import java .util .List ;
5
+
3
6
import org .springframework .boot .SpringApplication ;
4
7
import org .springframework .context .ConfigurableApplicationContext ;
8
+ import org .springframework .core .env .Environment ;
5
9
6
10
import javafx .application .Application ;
7
11
import javafx .scene .Scene ;
@@ -22,7 +26,7 @@ public abstract class AbstractJavaFxApplicationSupport extends Application {
22
26
private static Stage stage ;
23
27
private static Scene scene ;
24
28
25
- protected static Image icon ;
29
+ protected static List < Image > icons = new ArrayList <>() ;
26
30
27
31
public static Stage getStage () {
28
32
return stage ;
@@ -31,11 +35,36 @@ public static Stage getStage() {
31
35
public static Scene getScene () {
32
36
return scene ;
33
37
}
38
+
39
+ private List <String > propertyArrayReader (Environment env , String propName ) {
40
+ ArrayList <String > list = new ArrayList <>();
41
+ int counter =0 ;
42
+ String prop = env .getProperty (propName +"[" + counter + "]" );
43
+
44
+ while (prop != null ) {
45
+ list .add (prop );
46
+ counter ++;
47
+ prop = env .getProperty (propName +"[" + counter + "]" );
48
+ }
49
+
50
+ return list ;
51
+ }
34
52
35
53
@ Override
36
54
public void init () throws Exception {
37
55
applicationContext = SpringApplication .run (getClass (), savedArgs );
38
- icon = new Image (getClass ().getResource ("/icon.png" ).toExternalForm ());
56
+ List <String > fsImages = propertyArrayReader (applicationContext .getEnvironment (), "javafx.appicons" );
57
+
58
+ if (!fsImages .isEmpty ()) {
59
+ fsImages .forEach ((s ) -> icons .add (new Image (getClass ().getResource (s ).toExternalForm ())));
60
+ }
61
+ else { // add factory images
62
+ icons .add (new Image (getClass ().getResource ("/icons/gear_16x16.png" ).toExternalForm ()));
63
+ icons .add (new Image (getClass ().getResource ("/icons/gear_24x24.png" ).toExternalForm ()));
64
+ icons .add (new Image (getClass ().getResource ("/icons/gear_36x36.png" ).toExternalForm ()));
65
+ icons .add (new Image (getClass ().getResource ("/icons/gear_42x42.png" ).toExternalForm ()));
66
+ icons .add (new Image (getClass ().getResource ("/icons/gear_64x64.png" ).toExternalForm ()));
67
+ }
39
68
}
40
69
41
70
@ Override
@@ -55,8 +84,7 @@ public static void showView(Class<? extends AbstractFxmlView> newView) {
55
84
scene .setRoot (view .getView ());
56
85
}
57
86
58
- // stage.setTitle(windowTitle);
59
- stage .getIcons ().add (icon );
87
+ stage .getIcons ().addAll (icons );
60
88
stage .setScene (scene );
61
89
// stage.setResizable(true);
62
90
// stage.centerOnScreen();
0 commit comments