com.vaadin.ui.
Class CustomLayout
java.lang.Object
com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractComponentContainer
com.vaadin.ui.AbstractLayout
com.vaadin.ui.CustomLayout
All Implemented Interfaces:
MethodEventSource, Paintable, Sizeable, VariableOwner, Component, ComponentContainer, Layout, Layout.MarginHandler, Serializable, EventListener
- extends AbstractLayout
public class CustomLayout
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.
Since:
3.0
Version:
6.8.18
Author:
Vaadin Ltd., Duy B. Vo (devduy@gmail.com)
See Also:
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent |
---|
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler |
Nested classes/interfaces inherited from interface com.vaadin.ui.Layout |
---|
Layout.AlignmentHandler, Layout.MarginHandler, Layout.MarginInfo, Layout.SpacingHandler |
Nested classes/interfaces inherited from interface com.vaadin.ui.ComponentContainer |
---|
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener |
Nested classes/interfaces inherited from interface com.vaadin.ui.Component |
---|
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener |
Nested classes/interfaces inherited from interface com.vaadin.terminal.Paintable |
---|
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener |
Field Summary |
---|
Fields inherited from class com.vaadin.ui.AbstractLayout |
---|
margins |
Fields inherited from interface com.vaadin.terminal.Sizeable |
---|
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS |
Constructor Summary | |
---|---|
protected |
CustomLayout()
Default constructor only used by subclasses. |
CustomLayout(InputStream templateStream)
Constructs a custom layout with the template given in the stream. |
|
CustomLayout(String template)
Constructor for custom layout with given template name. |
Method Summary | |
---|---|
void |
addComponent(Component c)
Adds the component into this container. |
void |
addComponent(Component c,
String location)
Adds the component into this container to given location. |
Component |
getComponent(String location)
Gets the child-component by its location. |
int |
getComponentCount()
Gets the number of contained components. |
Iterator<Component> |
getComponentIterator()
Gets the component container iterator for going trough all the components in the container. |
String |
getTemplateContents()
Get the contents of the template |
String |
getTemplateName()
Get the name of the template |
protected void |
initTemplateContentsFromInputStream(InputStream templateStream)
|
void |
paintContent(PaintTarget target)
Paints the content of this component. |
void |
removeComponent(Component c)
Removes the component from this container. |
void |
removeComponent(String location)
Removes the component from this container from given location. |
void |
replaceComponent(Component oldComponent,
Component newComponent)
Replaces the component in the container with another one without changing position. |
void |
setMargin(boolean enabled)
Although most layouts support margins, CustomLayout does not. |
void |
setMargin(boolean topEnabled,
boolean rightEnabled,
boolean bottomEnabled,
boolean leftEnabled)
Although most layouts support margins, CustomLayout does not. |
void |
setStyle(String name)
Deprecated. Use setTemplateName(String) instead |
void |
setTemplateContents(String templateContents)
Set the contents of the template used to draw the custom layout. |
void |
setTemplateName(String templateName)
Set the name of the template used to draw custom layout. |
Methods inherited from class com.vaadin.ui.AbstractLayout |
---|
changeVariables, fireClick, getMargin, setMargin |
Methods inherited from class com.vaadin.ui.AbstractComponentContainer |
---|
addListener, addListener, attach, detach, fireComponentAttachEvent, fireComponentDetachEvent, moveComponentsFrom, removeAllComponents, removeListener, removeListener, requestRepaintAll, setEnabled, setHeight, setWidth |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.vaadin.ui.ComponentContainer |
---|
addListener, addListener, moveComponentsFrom, removeAllComponents, removeListener, removeListener, requestRepaintAll |
Methods inherited from interface com.vaadin.ui.Component |
---|
addListener, addStyleName, attach, childRequestedRepaint, detach, getApplication, getCaption, getIcon, getLocale, getParent, getStyleName, getWindow, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setParent, setReadOnly, setStyleName, setVisible |
Methods inherited from interface com.vaadin.terminal.Paintable |
---|
addListener, getDebugId, paint, removeListener, requestRepaint, requestRepaintRequests, setDebugId |
Methods inherited from interface com.vaadin.terminal.VariableOwner |
---|
isImmediate |
Methods inherited from interface com.vaadin.terminal.Sizeable |
---|
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeight, setHeightUnits, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidth, setWidthUnits |
Constructor Detail |
---|
CustomLayout
protected CustomLayout()
Default constructor only used by subclasses. Subclasses are responsible
for setting the appropriate fields. Either
setTemplateName(String)
, that makes layout fetch the template
from theme, or setTemplateContents(String)
.
CustomLayout
public CustomLayout(InputStream templateStream)
throws IOException
- Parameters:
templateStream
- Stream containing template data. Must be using UTF-8 encoding. To use a String as a template use for instance new ByteArrayInputStream("<template>".getBytes()).streamLength
- Length of the templateStream- Throws:
IOException
Constructs a custom layout with the template given in the stream.
CustomLayout
public CustomLayout(String template)
Constructor for custom layout with given template name. Template file is fetched from "<theme>/layout/<templateName>".
Method Detail |
---|
initTemplateContentsFromInputStream
protected void initTemplateContentsFromInputStream(InputStream templateStream)
throws IOException
- Throws:
IOException
addComponent
public void addComponent(Component c,
String location)
- Parameters:
c
- the component to be added.location
- the location of the component.
Adds the component into this container to given location. If the location is already populated, the old component is removed.
addComponent
public void addComponent(Component c)
- Specified by:
addComponent
in interfaceComponentContainer
- Overrides:
addComponent
in classAbstractComponentContainer
- Parameters:
c
- the component to be added.- See Also:
ComponentContainer.addComponent(Component)
Adds the component into this container. The component is added without specifying the location (empty string is then used as location). Only one component can be added to the default "" location and adding more components into that location overwrites the old components.
removeComponent
public void removeComponent(Component c)
- Specified by:
removeComponent
in interfaceComponentContainer
- Overrides:
removeComponent
in classAbstractComponentContainer
- Parameters:
c
- the component to be removed.- See Also:
ComponentContainer.removeComponent(Component)
Removes the component from this container.
removeComponent
public void removeComponent(String location)
- Parameters:
location
- the Location identifier of the component.
Removes the component from this container from given location.
getComponentIterator
public Iterator<Component> getComponentIterator()
- Returns:
- the Iterator of the components inside the container.
Gets the component container iterator for going trough all the components in the container.
getComponentCount
public int getComponentCount()
- Returns:
- the number of contained components
Gets the number of contained components. Consistent with the iterator
returned by getComponentIterator()
.
getComponent
public Component getComponent(String location)
- Parameters:
location
- the name of the location where the requested component resides.- Returns:
- the Component in the given location or null if not found.
Gets the child-component by its location.
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Overrides:
paintContent
in classAbstractLayout
- Parameters:
target
-- Throws:
PaintException
- if the paint operation failed.
Paints the content of this component.
replaceComponent
public void replaceComponent(Component oldComponent,
Component newComponent)
- Parameters:
oldComponent
- the old component that will be replaced.newComponent
- the new component to be replaced.
Description copied from interface: ComponentContainer
Replaces the component in the container with another one without changing position.
This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.
setStyle
@Deprecated
public void setStyle(String name)
- Overrides:
setStyle
in classAbstractComponent
- Parameters:
name
- template name
Deprecated. Use setTemplateName(String)
instead
CustomLayout's template selecting was previously implemented with setStyle. Overriding to improve backwards compatibility.
getTemplateName
public String getTemplateName()
Get the name of the template
getTemplateContents
public String getTemplateContents()
Get the contents of the template
setTemplateName
public void setTemplateName(String templateName)
- Parameters:
templateName
-
Set the name of the template used to draw custom layout. With GWT-adapter, the template with name 'templatename' is loaded from VAADIN/themes/themename/layouts/templatename.html. If the theme has not been set (with Application.setTheme()), themename is 'default'.
setTemplateContents
public void setTemplateContents(String templateContents)
- Parameters:
templateContents
-
Set the contents of the template used to draw the custom layout.
setMargin
public void setMargin(boolean enabled)
- Specified by:
setMargin
in interfaceLayout
- Overrides:
setMargin
in classAbstractLayout
- Throws:
UnsupportedOperationException
Although most layouts support margins, CustomLayout does not. The behaviour of this layout is determined almost completely by the actual template.
setMargin
public void setMargin(boolean topEnabled,
boolean rightEnabled,
boolean bottomEnabled,
boolean leftEnabled)
- Specified by:
setMargin
in interfaceLayout
- Overrides:
setMargin
in classAbstractLayout
- Throws:
UnsupportedOperationException
Although most layouts support margins, CustomLayout does not. The behaviour of this layout is determined almost completely by the actual template.