001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017: import org.wings.template.StringTemplateSource;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.net.URL;
022:
023: /**
024: * Default layout for all {@link SRootContainer} derivates.
025: * <p/>
026: * There might be situations when you want to use a custom SRootLayout. Why?
027: * Because by setting an SFrame's layout you can change the look of a whole
028: * application. Since only the object called "frame" will be replaced with
029: * the content element, you can statically define XHTML elements such as a
030: * border, a title or a footer line by defining your own template with a STemplateLayout.
031: */
032: public class SRootLayout extends STemplateLayout {
033: private final static Log LOG = LogFactory.getLog(SRootLayout.class);
034:
035: /**
036: * Use the default template.
037: */
038: public SRootLayout() {
039: setTemplate(new StringTemplateSource(
040: "<object name=\"frame\"></object>\n"
041: + "<object name=\"windows\"></object>"));
042: }
043:
044: /**
045: * Read the template from a file.
046: *
047: * @throws java.io.IOException
048: */
049: public SRootLayout(String tmplFileName) throws IOException {
050: setTemplate(new File(tmplFileName));
051: }
052:
053: /**
054: * Read the template from a file.
055: *
056: * @throws java.io.IOException
057: */
058: public SRootLayout(File tmplFile) throws IOException {
059: setTemplate(tmplFile);
060: }
061:
062: /**
063: * Read the template from an URL.
064: * The content is cached.
065: */
066: public SRootLayout(URL url) throws java.io.IOException {
067: setTemplate(url);
068: }
069:
070: public void addComponent(SComponent c, Object constraint, int index) {
071: }
072:
073: public void removeComponent(SComponent comp) {
074: }
075:
076: public SComponent getComponent(String name) {
077: if ("frame".equals(name)) {
078: int count = container.getComponentCount();
079: if (count > 0) {
080: return container.getComponent(0);
081: } else {
082: throw new IllegalStateException(
083: "The root container contains "
084: + count
085: + " components but a root container can not contain more than 1 component.");
086: }
087: } else if ("windows".equals(name)) {
088: if (container instanceof SRootContainer) {
089: return ((SRootContainer) container).getWindowsPane();
090: }
091: }
092: return null;
093: }
094:
095: // this has been overridden as noop in STemplateLayout
096: // give it back the original behaviour
097: public void setContainer(SContainer container) {
098: this.container = container;
099: }
100: }
|