KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SRootLayout


1 /*
2  * $Id: SRootLayout.java,v 1.7 2005/05/13 22:04:49 oliverscheck 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;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.net.URL JavaDoc;
22
23 /**
24  * This template layout is the default layout for all SContainers.
25  *
26  * There might be situations when you want to use a custom SRootLayout. Why?
27  * Because by setting an SFrame's layout you can change the looks of an
28  * application. Since only the object called "content" will be replaced with
29  * the content element, you can statically define XHTML elements such as a
30  * border, a title or a footer line with defining your own template.
31  */

32 public class SRootLayout extends STemplateLayout {
33     private final static transient Log log = LogFactory.getLog(SRootLayout.class);
34
35     /**
36      * Use the default template.
37      */

38     public SRootLayout() {
39         try {
40             setTemplate(getClass().getResource("template/default.thtml"));
41         } catch (IOException JavaDoc e) {
42             log.error("Unable to get template/default.thtml",e);
43         }
44     }
45
46     /**
47      * Read the template from a file.
48      *
49      * @throws java.io.IOException
50      */

51     public SRootLayout(String JavaDoc tmplFileName) throws IOException JavaDoc {
52         setTemplate(new File JavaDoc(tmplFileName));
53     }
54
55     /**
56      * Read the template from a file.
57      *
58      * @throws java.io.IOException
59      */

60     public SRootLayout(File JavaDoc tmplFile) throws IOException JavaDoc {
61         setTemplate(tmplFile);
62     }
63
64     /**
65      * Read the template from an URL.
66      * The content is cached.
67      */

68     public SRootLayout(URL JavaDoc url) throws java.io.IOException JavaDoc {
69         setTemplate(url);
70     }
71
72     public void addComponent(SComponent c, Object JavaDoc constraint, int index) {}
73
74     public void removeComponent(SComponent comp) {}
75
76     public SComponent getComponent(String JavaDoc name) {
77         if (!"content".equals(name))
78             return null;
79
80         int topmost = container.getComponentCount() - 1;
81         return container.getComponent(topmost);
82     }
83
84     // this has been overridden as noop in STemplateLayout
85
// give it back the original behaviour
86
public void setContainer(SContainer container) {
87         this.container = container;
88     }
89 }
90
Popular Tags