48 Image t = check();
49 if (t == null) {
50 t = reconstitute();
51 setThing(t);
52 }
53 return t;
54 }
55
56 /**
57 * Create the Ref
58 */
59 AppletImageRef(URL url) {
60 this.url = url;
61 }
62
63 /**
64 * Flushes the cached object. Forces the next invocation of get() to
65 * invoke reconstitute().
66 */
67 public synchronized void flush() {
68 SoftReference s = soft;
69 if (s != null) s.clear();
70 soft = null;
71 }
72
73 /**
74 * Sets the thing to the specified object.
75 * @param thing the specified object
76 */
77 public synchronized void setThing(Object thing) {
78 flush();
79 soft = new SoftReference(thing);
80 }
81
82 /**
83 * Checks to see what object is being pointed at by this Ref and returns it.
84 */
85 public synchronized Image check() {
86 SoftReference<Image> s = soft;
87 if (s == null) return null;
88 return s.get();
89 }
90
91 /**
92 * Reconsitute the image. Only called when the ref has been flushed.
93 */
94 public Image reconstitute() {
95 Image img = Toolkit.getDefaultToolkit().createImage(new URLImageSource(url));
96 return img;
97 }
98 }
|
48 Image t = check();
49 if (t == null) {
50 t = reconstitute();
51 setThing(t);
52 }
53 return t;
54 }
55
56 /**
57 * Create the Ref
58 */
59 AppletImageRef(URL url) {
60 this.url = url;
61 }
62
63 /**
64 * Flushes the cached object. Forces the next invocation of get() to
65 * invoke reconstitute().
66 */
67 public synchronized void flush() {
68 SoftReference<Image> s = soft;
69 if (s != null) s.clear();
70 soft = null;
71 }
72
73 /**
74 * Sets the thing to the specified object.
75 * @param thing the specified object
76 */
77 public synchronized void setThing(Image thing) {
78 flush();
79 soft = new SoftReference<>(thing);
80 }
81
82 /**
83 * Checks to see what object is being pointed at by this Ref and returns it.
84 */
85 public synchronized Image check() {
86 SoftReference<Image> s = soft;
87 if (s == null) return null;
88 return s.get();
89 }
90
91 /**
92 * Reconsitute the image. Only called when the ref has been flushed.
93 */
94 public Image reconstitute() {
95 Image img = Toolkit.getDefaultToolkit().createImage(new URLImageSource(url));
96 return img;
97 }
98 }
|