/* * Copyright 2011 Vaadin Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.vaadin.ui; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import com.vaadin.server.JsonPaintTarget; import com.vaadin.server.PaintException; import com.vaadin.server.PaintTarget; import com.vaadin.server.LegacyComponent; import com.vaadin.shared.ui.customlayout.CustomLayoutState; /** *

* A container component with freely designed layout and style. The layout * consists of items with textually represented locations. Each item contains * one sub-component, which can be any Vaadin component, such as a layout. The * adapter and theme are responsible for rendering the layout with a given style * by placing the items in the defined locations. *

* *

* The placement of the locations is not fixed - different themes can define the * locations in a way that is suitable for them. One typical example would be to * create visual design for a web site as a custom layout: the visual design * would define locations for "menu", "body", and "title", for example. The * layout would then be implemented as an XHTML template for each theme. *

* *

* The default theme handles the styles that are not defined by drawing the * subcomponents just as in OrderedLayout. *

* * @author Vaadin Ltd. * @author Duy B. Vo (devduy@gmail.com) * @since 3.0 */ @SuppressWarnings("serial") public class CustomLayout extends AbstractLayout implements LegacyComponent { private static final int BUFFER_SIZE = 10000; /** * Custom layout slots containing the components. */ private final HashMap slots = new HashMap(); /** * Default constructor only used by subclasses. Subclasses are responsible * for setting the appropriate fields. Either * {@link #setTemplateName(String)}, that makes layout fetch the template * from theme, or {@link #setTemplateContents(String)}. */ protected CustomLayout() { setWidth(100, UNITS_PERCENTAGE); } /** * Constructs a custom layout with the template given in the stream. * * @param templateStream * Stream containing template data. Must be using UTF-8 encoding. * To use a String as a template use for instance new * ByteArrayInputStream("