01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.swinglets;
06:
07: import java.util.*;
08: import java.io.*;
09: import java.awt.*;
10: import java.net.*;
11:
12: import com.javelin.swinglets.*;
13:
14: /**
15: * ImageManager is a store for creating and retrieving images in.
16: * <p>
17: *
18: * @author Robin Sharp
19: */
20:
21: public class ImageManager {
22: public static ImageManager getManager() {
23: return imageManager;
24: }
25:
26: /**
27: * Create a GIFEncoder using an SImage.
28: * Removes the image if it is null.
29: */
30: public void put(String name, SImage image) {
31: if (image == null) {
32: images.remove(name);
33: } else {
34: images.put(name, image);
35: }
36: }
37:
38: /**
39: * Find an GIFEncoder by name.
40: * <p>
41: * A broken image is returned if the imgae cannot be found.
42: */
43: public SImage get(String name) {
44: if (name == null)
45: return BROKEN_IMAGE;
46:
47: SImage image = (SImage) images.get(name);
48:
49: if (image == null) {
50: image = BROKEN_IMAGE;
51: }
52:
53: return image;
54: }
55:
56: /**
57: * Get the URL for the ImageManager.
58: */
59: public URL getUrl() {
60: return url;
61: }
62:
63: /**
64: * Set the URL for the SwingletManager
65: */
66: public void setUrl(URL url) {
67: this .url = url;
68: }
69:
70: // PRIVATE ///////////////////////////////////////////////
71:
72: private static ImageManager imageManager = new ImageManager();
73:
74: private Hashtable images = new Hashtable();
75:
76: private URL url;
77:
78: private SImage BROKEN_IMAGE;
79:
80: {
81: try {
82: if (BROKEN_IMAGE == null) {
83: BROKEN_IMAGE = new SImage(30, 30);
84: BROKEN_IMAGE.getGraphics().setColor(Color.black);
85: BROKEN_IMAGE.getGraphics().drawLine(1, 1, 28, 28);
86: BROKEN_IMAGE.getGraphics().drawLine(28, 1, 1, 28);
87: }
88: } catch (Exception e) {
89: e.printStackTrace();
90: }
91: }
92:
93: }
|