KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > webapp > model > IconRegistry


1 /*
2  * Copyright © 2004, Rob Gordon.
3  */

4 package org.oddjob.webapp.model;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import org.oddjob.Iconic;
10 import org.oddjob.images.IconTip;
11
12 /**
13  * A registry of icons so they can be served up to
14  * the view. This registry works on the principle that
15  * an icon id identifies the same icon for all jobs.
16  *
17  * @author Rob Gordon.
18  */

19 public class IconRegistry {
20
21     /** The icons. */
22     final private Map JavaDoc icons = new HashMap JavaDoc();
23
24     /**
25      * Register an iconId. If the icon id isn't
26      * registered already, the icon is looked up.
27      *
28      * @param iconId The iconId.
29      * @param iconic The Iconic that can provide
30      * the lookup.
31      */

32     public void register(String JavaDoc iconId, Iconic iconic) {
33         IconTip iconTip = null;
34         synchronized (icons) {
35             iconTip = (IconTip)icons.get(iconId);
36             if (iconTip == null) {
37                 iconTip = iconic.iconForId(iconId);
38                 icons.put(iconId, iconTip);
39             }
40         }
41     }
42
43     /**
44      * Retrieve an IconTip for a given icon id.
45      *
46      * @param iconId The iconId.
47      * @return The IconTip, null if none exists if
48      * nothing is registered for that id.
49      */

50     public IconTip retrieve(String JavaDoc iconId) {
51         synchronized (icons) {
52             return (IconTip)icons.get(iconId);
53         }
54     }
55 }
56
Popular Tags