1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.util;
17
18 import java.awt.Image;
19 import java.util.HashMap;
20
21 import javax.swing.ImageIcon;
22
23
24
25
26
27
28
29
30
31 public class ImageCache {
32
33 private HashMap images;
34
35
36
37
38 public ImageCache() {
39 images = new HashMap();
40 }
41
42 public void addImage(String name, Image image) {
43 images.put(name, image);
44 }
45
46 public void addImage(String name, ImageIcon image) {
47 images.put(name, image);
48 }
49
50 public Image getImage(String name) {
51 Object img = images.get(name);
52 if (img instanceof ImageIcon) {
53 return ((ImageIcon) img).getImage();
54 } else {
55 return (Image) img;
56 }
57 }
58
59 public ImageIcon getImageIcon(String name) {
60 Object img = images.get(name);
61 if (img instanceof Image) {
62 return new ImageIcon((Image)img);
63 } else {
64 return (ImageIcon) img;
65 }
66 }
67
68 public void clear() {
69 images.clear();
70 images = null;
71 }
72
73 }