@@ -46,23 +46,49 @@ This file is part of the iText (R) project.
4646
4747import java .awt .Image ;
4848import java .awt .Toolkit ;
49- import java .util .ArrayList ;
5049import java .util .List ;
50+ import java .util .stream .Collectors ;
51+ import java .util .stream .IntStream ;
5152
52- public class FrameIconUtil {
53-
53+ public final class FrameIconUtil {
54+ /**
55+ * Scale between two subsequent icon sizes.
56+ */
57+ private static final int DIM_SCALE = 2 ;
58+ /**
59+ * Minimum width/height of an icon.
60+ */
61+ private static final int MIN_DIM = 16 ;
62+ /**
63+ * Maximum width/height of an icon.
64+ */
65+ private static final int MAX_DIM = 1024 ;
66+ /**
67+ * Path in resources to the logo.
68+ */
5469 private static final String LOGO_ICON = "logo.png" ;
5570
5671 private FrameIconUtil () {
72+ // static class
5773 }
5874
5975 public static List <Image > loadFrameIcons () {
60- List <Image > images = new ArrayList <>();
61- final Image image = Toolkit .getDefaultToolkit ().getImage (Rups .class .getResource (LOGO_ICON ));
62- // Add several scaled instances of the image to let the platform decide which ones to use
63- for (int i = 16 ; i <= 1024 ; i *= 2 ) {
64- images .add (image .getScaledInstance (i , i , Image .SCALE_SMOOTH ));
76+ return LazyHolder .SCALED_ICONS ;
77+ }
78+
79+ /**
80+ * Wrapper to lazily load the logo from resource and prepare all scaled
81+ * versions of it.
82+ */
83+ private static final class LazyHolder {
84+ private static final List <Image > SCALED_ICONS ;
85+
86+ static {
87+ final Image image = Toolkit .getDefaultToolkit ()
88+ .getImage (Rups .class .getResource (LOGO_ICON ));
89+ SCALED_ICONS = IntStream .iterate (MIN_DIM , dim -> dim <= MAX_DIM , dim -> dim * DIM_SCALE )
90+ .mapToObj (dim -> image .getScaledInstance (dim , dim , Image .SCALE_SMOOTH ))
91+ .collect (Collectors .toUnmodifiableList ());
6592 }
66- return images ;
6793 }
6894}
0 commit comments