1 14 package org.wings; 15 16 import org.wings.template.*; 17 import org.wings.template.parser.PageParser; 18 19 import java.io.File ; 20 import java.net.URL ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 import java.util.Map ; 24 25 54 55 61 public class STemplateLayout 62 extends SAbstractLayoutManager { 63 67 private static final PropertyManager defaultPropertyManager = 68 new PropertyManager() { 69 final Class [] empty = new Class [0]; 70 71 public void setProperty(SComponent c, String name, 72 String value) { 73 } 74 75 public Class [] getSupportedClasses() { 76 return empty; 77 } 78 }; 79 80 83 private static final HashMap propertyManager = new HashMap (); 84 85 89 static { 90 addPropertyManager(new SComponentPropertyManager()); 91 addPropertyManager(new SAbstractIconTextCompoundPropertyManager()); 92 addPropertyManager(new SAbstractButtonPropertyManager()); 93 addPropertyManager(new SLabelPropertyManager()); 94 addPropertyManager(new STextFieldPropertyManager()); 95 addPropertyManager(new STextAreaPropertyManager()); 96 addPropertyManager(new STablePropertyManager()); 97 addPropertyManager(new SFileChooserPropertyManager()); 98 addPropertyManager(new SListPropertyManager()); 99 } 100 101 104 protected HashMap components = new HashMap (); 105 private TemplateSource templateSource = null; 106 107 110 protected PageParser pageParser = PageParser.getInstance(); 111 112 113 public STemplateLayout() {} 114 115 125 public STemplateLayout(TemplateSource source) { 126 setTemplate(source); 127 } 128 129 136 public STemplateLayout(String tmplFileName) throws java.io.IOException { 137 setTemplate(new File (tmplFileName)); 138 } 139 140 148 public STemplateLayout(File tmplFile) throws java.io.IOException { 149 setTemplate(tmplFile); 150 } 151 152 159 public STemplateLayout(URL url) throws java.io.IOException { 160 setTemplate(url); 161 } 162 163 167 public static final PropertyManager getPropertyManager(Class c) { 168 if (c == null) 169 return defaultPropertyManager; 170 171 PropertyManager p = (PropertyManager) propertyManager.get(c); 172 173 if (p == null) 174 return getPropertyManager(c.getSuperclass()); 175 176 return p; 177 } 178 179 187 public static final void addPropertyManager(PropertyManager p) { 188 if (p == null) 189 return; 190 191 Class [] cl = p.getSupportedClasses(); 192 if (cl == null) 193 return; 194 195 for (int i = 0; i < cl.length; i++) { 196 if (!propertyManager.containsKey(cl[i])) 197 propertyManager.put(cl[i], p); 198 } 199 } 200 201 206 public void setTemplate(String templateFileName) 207 throws java.io.IOException { 208 setTemplate(new File (templateFileName)); 209 } 210 211 216 public void setTemplate(File templateFile) throws java.io.IOException { 217 setTemplate(new CachedFileTemplateSource(templateFile)); 218 } 219 220 226 public void setTemplate(URL templateURL) throws java.io.IOException { 227 if ("file".equals(templateURL.getProtocol())) { 228 setTemplate(new File (templateURL.getFile())); 229 } else { 230 setTemplate(new CachedFileTemplateSource(templateURL)); 231 } 232 } 233 234 241 public void setTemplate(TemplateSource source) { 242 templateSource = source; 243 } 244 245 253 public void addComponent(SComponent c, Object constraint, int index) { 254 if (constraint == null) 255 throw new IllegalArgumentException ("null constraint not allowed here"); 256 components.put(constraint.toString(), c); 257 } 258 259 264 public void removeComponent(SComponent comp) { 265 Iterator it = components.entrySet().iterator(); 266 while (it.hasNext()) { 267 Map.Entry e = (Map.Entry ) it.next(); 268 if (e.getValue() == comp) 269 it.remove(); 270 } 271 } 272 273 276 public SComponent getComponent(String name) { 277 return (SComponent) components.get(name); 278 } 279 280 public TemplateSource getTemplateSource() { 281 return templateSource; 282 } 283 284 289 public PageParser getPageParser() { 290 return pageParser; 291 } 292 293 298 public void setPageParser(PageParser pageParser) { 299 this.pageParser = pageParser; 300 } 301 } 302 303 304 | Popular Tags |