1 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 ; 28 29 34 public class CGManager implements Serializable { 35 private final transient static Log log = LogFactory.getLog(CGManager.class); 36 37 private LookAndFeel lookAndFeel; 38 private CGDefaults defaults = null; 39 40 47 public Object get(String key) { 48 return getDefaults().get(key); 49 } 50 51 59 public Object getObject(String key, Class clazz) { 60 return getDefaults().get(key, clazz); 61 } 62 63 70 public ComponentCG getCG(SComponent target) { 71 return (ComponentCG) getDefaults().get(target.getClass(), ComponentCG.class); 72 } 73 74 81 public ComponentCG getCG(String cgClassID) { 82 return (ComponentCG) getDefaults().get(cgClassID, ComponentCG.class); 83 } 84 85 92 public LayoutCG getCG(SLayoutManager target) { 93 return (LayoutCG) getDefaults().get(target.getClass(), LayoutCG.class); 94 } 95 96 103 public StyleSheet getStyleSheet(String key) { 104 return (StyleSheet) getDefaults().get(key, StyleSheet.class); 105 } 106 107 114 public Style getStyle(String key) { 115 return (Style) getDefaults().get(key, Style.class); 116 } 117 118 125 public SIcon getIcon(String key) { 126 return (SIcon) getDefaults().get(key, SIcon.class); 127 } 128 129 134 public void setDefaults(CGDefaults defaults) { 135 this.defaults = defaults; 136 } 137 138 143 public CGDefaults getDefaults() { 144 if (defaults == null) { 145 log.warn("defaults == null"); 146 } 147 return defaults; 148 } 149 150 151 157 public LookAndFeel getLookAndFeel() { 158 return lookAndFeel; 159 } 160 161 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 if (SessionManager.getSession() != null) { 179 ((PropertyService) SessionManager.getSession()) 180 .setProperty("lookAndFeel", "" + newLookAndFeel.hashCode()); 181 } 182 } 183 184 187 public PrefixAndSuffixDelegate getPrefixSuffixDelegate() { 188 PrefixAndSuffixDelegate del = (PrefixAndSuffixDelegate) getDefaults().get("AbstractComponentCG.PrefixAndSuffixDelegate", PrefixAndSuffixDelegate.class); 189 return del; 190 } 191 } 192 193 194 | Popular Tags |