KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > plaf > CGManager


1 /*
2  * $Id: CGManager.java,v 1.11 2005/03/15 10:38:28 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings.plaf;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.wings.SComponent;
19 import org.wings.SIcon;
20 import org.wings.SLayoutManager;
21 import org.wings.plaf.PrefixAndSuffixDelegate;
22 import org.wings.session.PropertyService;
23 import org.wings.session.SessionManager;
24 import org.wings.style.Style;
25 import org.wings.style.StyleSheet;
26
27 import java.io.Serializable JavaDoc;
28
29 /**
30  * The CGManager holds a reference to the current laf.
31  * It delegates to a session related CGDefaults table, that is backed by
32  * the laf's defaults.
33  */

34 public class CGManager implements Serializable JavaDoc {
35     private final transient static Log log = LogFactory.getLog(CGManager.class);
36
37     private LookAndFeel lookAndFeel;
38     private CGDefaults defaults = null;
39
40     /**
41      * Get an Object from the defaults table.
42      * If the there's no value associated to the <code>key</code>, the request
43      * is delegated to the laf's defaults table.
44      *
45      * @param key the lookup key
46      */

47     public Object JavaDoc get(String JavaDoc key) {
48         return getDefaults().get(key);
49     }
50
51     /**
52      * Get an Object from the defaults table.
53      * If the there's no value associated to the <code>key</code>, the request
54      * is delegated to the laf's defaults table.
55      *
56      * @param key the lookup key
57      * @param clazz the class of the object in question
58      */

59     public Object JavaDoc getObject(String JavaDoc key, Class JavaDoc clazz) {
60         return getDefaults().get(key, clazz);
61     }
62
63     /**
64      * Get a ComponentCG from the defaults table.
65      * If the there's no value associated to the <code>target</code>'s cgClassID, the request
66      * is delegated to the laf's defaults table.
67      *
68      * @param target the SComponent
69      */

70     public ComponentCG getCG(SComponent target) {
71         return (ComponentCG) getDefaults().get(target.getClass(), ComponentCG.class);
72     }
73
74     /**
75      * Get a ComponentCG from the defaults table.
76      * If the there's no value associated to the <code>target</code>'s cgClassID, the request
77      * is delegated to the laf's defaults table.
78      *
79      * @param cgClassID the cg class id
80      */

81     public ComponentCG getCG(String JavaDoc cgClassID) {
82         return (ComponentCG) getDefaults().get(cgClassID, ComponentCG.class);
83     }
84
85     /**
86      * Get a LayoutManagerCG from the defaults table.
87      * If the there's no value associated to the <code>target</code>'s cgClassID, the request
88      * is delegated to the laf's defaults table.
89      *
90      * @param target the SLayoutManager
91      */

92     public LayoutCG getCG(SLayoutManager target) {
93         return (LayoutCG) getDefaults().get(target.getClass(), LayoutCG.class);
94     }
95
96     /**
97      * Get a StyleSheet from the defaults table.
98      * If the there's no value associated to the <code>key</code>, the request
99      * is delegated to the laf's defaults table.
100      *
101      * @param key the lookup key
102      */

103     public StyleSheet getStyleSheet(String JavaDoc key) {
104         return (StyleSheet) getDefaults().get(key, StyleSheet.class);
105     }
106
107     /**
108      * Get a Style from the defaults table.
109      * If the there's no value associated to the <code>key</code>, the request
110      * is delegated to the laf's defaults table.
111      *
112      * @param key the lookup key
113      */

114     public Style getStyle(String JavaDoc key) {
115         return (Style) getDefaults().get(key, Style.class);
116     }
117
118     /**
119      * Get a Icon from the defaults table.
120      * If the there's no value associated to the <code>key</code>, the request
121      * is delegated to the laf's defaults table.
122      *
123      * @param key the lookup key
124      */

125     public SIcon getIcon(String JavaDoc key) {
126         return (SIcon) getDefaults().get(key, SIcon.class);
127     }
128
129     /**
130      * Set the defaults table.
131      *
132      * @param defaults the defaults table
133      */

134     public void setDefaults(CGDefaults defaults) {
135         this.defaults = defaults;
136     }
137
138     /**
139      * Return the defaults table.
140      *
141      * @return the defaults table
142      */

143     public CGDefaults getDefaults() {
144         if (defaults == null) {
145             log.warn("defaults == null");
146         }
147         return defaults;
148     }
149
150
151     /**
152      * Returns the current default look and feel.
153      *
154      * @return the current default look and feel
155      * @see #setLookAndFeel
156      */

157     public LookAndFeel getLookAndFeel() {
158         return lookAndFeel;
159     }
160
161     /**
162      * Set the current default look and feel using a LookAndFeel object.
163      *
164      * @param newLookAndFeel the LookAndFeel object
165      * @see #getLookAndFeel
166      */

167     public void setLookAndFeel(LookAndFeel newLookAndFeel) {
168         lookAndFeel = newLookAndFeel;
169
170         if (newLookAndFeel != null) {
171             setDefaults(newLookAndFeel.createDefaults());
172         } else {
173             log.warn("lookandfeel == null");
174             setDefaults(null);
175         }
176
177         // have the session fire a propertyChangeEvent regarding the new lookAndFeel
178
if (SessionManager.getSession() != null) {
179             ((PropertyService) SessionManager.getSession())
180                     .setProperty("lookAndFeel", "" + newLookAndFeel.hashCode());
181         }
182     }
183
184     /**
185      * @return the delegate responsible for the Prefix and Suffix of the target
186      */

187     public PrefixAndSuffixDelegate getPrefixSuffixDelegate() {
188         PrefixAndSuffixDelegate del = (PrefixAndSuffixDelegate) getDefaults().get("AbstractComponentCG.PrefixAndSuffixDelegate", PrefixAndSuffixDelegate.class);
189         return del;
190     }
191 }
192
193
194
Popular Tags