780b1bbd050556e1a42cd45cfe97dc3ae5bdb47a
1 package be
.nikiroo
.fanfix_swing
.images
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.util
.HashMap
;
8 import javax
.swing
.ImageIcon
;
10 import be
.nikiroo
.utils
.IOUtils
;
13 * Icons generator for this project.
17 public class IconGenerator
{
19 * The available icons.
24 /** Icon used to clear text fields */
26 /** Search icon (magnifying glass) */
28 /** An interrogation point */
30 /** A small, left-pointed arrow */
32 /** A small, right-pointed arrow */
34 /** A small, up-pointed arrow */
36 /** A small, down-pointed arrow */
38 /** An empty (transparent) icon */
43 * The available sizes.
48 /** 4x4 pixels, only for {@link Icon#empty} */
50 /** 8x8 pixels, only for {@link Icon#empty} */
63 private Size(int size
) {
68 * Return the size in pixels.
72 public int getSize() {
77 static private Map
<String
, ImageIcon
> map
= new HashMap
<String
, ImageIcon
>();
80 * Generate a new image.
82 * @param name the name of the resource
83 * @param size the requested size
85 * @return the image, or NULL if it does not exist or does not exist at that
88 static public ImageIcon
get(Icon name
, Size size
) {
89 String key
= String
.format("%s-%dx%d.png", name
.name(), size
.getSize(), size
.getSize());
90 if (!map
.containsKey(key
)) {
91 map
.put(key
, generate(key
));
98 * Generate a new image.
100 * @param filename the file name of the resource (no directory)
102 * @return the image, or NULL if it does not exist or does not exist at that
105 static private ImageIcon
generate(String filename
) {
107 InputStream in
= IOUtils
.openResource(IconGenerator
.class, filename
);
110 return new ImageIcon(IOUtils
.toByteArray(in
));
115 } catch (IOException e
) {