KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > plaf > metal > GenericComponentUI


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: GenericComponentUI.java,v $
11    Revision 1.2 2004/04/15 11:24:33 bobintetley
12    (Dan Naab) ComponentUI, UIDefaults/UIManager and Accessibility support.
13    (Antonio Weber) TableColumnModelListener implementation and support
14
15
16 */

17
18 package swingwtx.swing.plaf.metal;
19
20 import swingwtx.swing.plaf.ComponentUI;
21 import swingwtx.swing.JComponent;
22
23 import java.util.HashMap JavaDoc;
24
25 /**
26  * This is a generic ComponentUI wrapper for use with SwingWT.
27  *
28  * The createUI(Class) method creates a new ComponentUI instance intended for wrapping the SWT component
29  * of the given type.
30  *
31  * Why? This allows us to create SWT components that can be custom drawn with Swing code, a la L&F.
32  * This part still has some work. <g>
33  *
34  * @author Naab
35  * @version %I%, %G%
36  */

37 public class GenericComponentUI extends ComponentUI
38 {
39     private static HashMap JavaDoc defaultComponentUIs = new HashMap JavaDoc();
40
41     private Class JavaDoc componentClass;
42
43     public static ComponentUI createUI(JComponent component)
44     {
45         if (component == null)
46             throw new NullPointerException JavaDoc();
47
48         return createUI(component.getClass());
49     }
50
51     public static ComponentUI createUI(Class JavaDoc componentClass)
52     {
53         if (componentClass == null)
54             throw new NullPointerException JavaDoc();
55
56         GenericComponentUI componentUI = null;
57         if (defaultComponentUIs.containsKey(componentClass))
58         {
59             componentUI = (GenericComponentUI) defaultComponentUIs.get(componentClass);
60         }
61         else
62         {
63             componentUI = new GenericComponentUI(componentClass);
64             defaultComponentUIs.put(componentClass, componentUI);
65         }
66         return componentUI;
67     }
68
69     public GenericComponentUI(Class JavaDoc componentClass)
70     {
71         super();
72         this.componentClass = componentClass;
73     }
74 }
75
Popular Tags