com.vaadin.ui
Class CssLayout

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractComponentContainer
              extended by com.vaadin.ui.AbstractLayout
                  extended by com.vaadin.ui.CssLayout
All Implemented Interfaces:
LayoutEvents.LayoutClickNotifier, MethodEventSource, ClientConnector, Sizeable, com.vaadin.shared.Connector, Component, ComponentContainer, HasComponents, HasComponents.ComponentAttachDetachNotifier, Layout, java.io.Serializable, java.lang.Iterable<Component>
Direct Known Subclasses:
ColorPickerPreview, Navigator.EmptyView

public class CssLayout
extends AbstractLayout
implements LayoutEvents.LayoutClickNotifier

CssLayout is a layout component that can be used in browser environment only. It simply renders components and their captions into a same div element. Component layout can then be adjusted with css.

In comparison to HorizontalLayout and VerticalLayout

With CustomLayout one can often achieve similar results (good looking layouts with web technologies), but with CustomLayout developer needs to work with fixed templates.

By extending CssLayout one can also inject some css rules straight to child components using getCss(Component).

(*) Relative sizes (set from server side) are treated bit differently than in other layouts in Vaadin. In cssLayout the size is calculated relatively to CSS layouts content area which is pretty much as in html and css. In other layouts the size of component is calculated relatively to the "slot" given by layout.

Also note that client side framework in Vaadin modifies inline style properties width and height. This happens on each update to component. If one wants to set component sizes with CSS, component must have undefined size on server side (which is not the default for all components) and the size must be defined with class styles - not by directly injecting width and height.

Since:
6.1 brought in from "FastLayouts" incubator project
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Layout
Layout.AlignmentHandler, Layout.MarginHandler, Layout.SpacingHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
 
Field Summary
protected  java.util.LinkedList<Component> components
          Custom layout slots containing the components.
 
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
CssLayout()
          Constructs an empty CssLayout.
CssLayout(Component... children)
          Constructs a CssLayout with the given components in the given order.
 
Method Summary
 void addComponent(Component c)
          Add a component into this container.
 void addComponent(Component c, int index)
          Adds a component into indexed position in this container.
 void addComponentAsFirst(Component c)
          Adds a component into this container.
 void addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
          Add a click listener to the layout.
 void addListener(LayoutEvents.LayoutClickListener listener)
          Deprecated. As of 7.0, replaced by #addLayoutClickListener(LayoutClickListener)
 void beforeClientResponse(boolean initial)
          Called before the shared state and RPC invocations are sent to the client.
 Component getComponent(int index)
          Returns the component at the given position.
 int getComponentCount()
          Gets the number of contained components.
 int getComponentIndex(Component component)
          Returns the index of the given component.
protected  java.lang.String getCss(Component c)
          Returns styles to be applied to given component.
protected  com.vaadin.shared.ui.csslayout.CssLayoutState getState()
          Returns the shared state bean with information to be sent from the server to the client.
 java.util.Iterator<Component> iterator()
          Gets the component container iterator for going trough all the components in the container.
 void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
          Reads the component state from the given design.
 void removeComponent(Component c)
          Removes the component from this container.
 void removeLayoutClickListener(LayoutEvents.LayoutClickListener listener)
          Removes an LayoutClickListener.
 void removeListener(LayoutEvents.LayoutClickListener listener)
          Deprecated. As of 7.0, replaced by #removeLayoutClickListener(LayoutClickListener)
 void replaceComponent(Component oldComponent, Component newComponent)
          Replaces the component in the container with another one without changing position.
 void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
          Writes the component state to the given design.
 
Methods inherited from class com.vaadin.ui.AbstractLayout
readMargin, writeMargin
 
Methods inherited from class com.vaadin.ui.AbstractComponentContainer
addComponentAttachListener, addComponentDetachListener, addComponents, addListener, addListener, fireComponentAttachEvent, fireComponentDetachEvent, getComponentIterator, moveComponentsFrom, removeAllComponents, removeComponentAttachListener, removeComponentDetachListener, removeListener, removeListener, setHeight, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCaption, getComponentError, getCustomAttributes, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getState, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidthUndefined
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.ComponentContainer
addComponents, addListener, addListener, getComponentIterator, moveComponentsFrom, removeAllComponents, removeListener, removeListener
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
 
Methods inherited from interface com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier
addComponentAttachListener, addComponentDetachListener, removeComponentAttachListener, removeComponentDetachListener
 

Field Detail

components

protected java.util.LinkedList<Component> components
Custom layout slots containing the components.

Constructor Detail

CssLayout

public CssLayout()
Constructs an empty CssLayout.


CssLayout

public CssLayout(Component... children)
Constructs a CssLayout with the given components in the given order.

Parameters:
children - Components to add to the container.
See Also:
AbstractComponentContainer.addComponents(Component...)
Method Detail

addComponent

public void addComponent(Component c)
Add a component into this container. The component is added to the right or below the previous component.

Specified by:
addComponent in interface ComponentContainer
Overrides:
addComponent in class AbstractComponentContainer
Parameters:
c - the component to be added.
See Also:
ComponentContainer.addComponent(Component)

addComponentAsFirst

public void addComponentAsFirst(Component c)
Adds a component into this container. The component is added to the left or on top of the other components.

Parameters:
c - the component to be added.

addComponent

public void addComponent(Component c,
                         int index)
Adds a component into indexed position in this container.

Parameters:
c - the component to be added.
index - the index of the component position. The components currently in and after the position are shifted forwards.

removeComponent

public void removeComponent(Component c)
Removes the component from this container.

Specified by:
removeComponent in interface ComponentContainer
Overrides:
removeComponent in class AbstractComponentContainer
Parameters:
c - the component to be removed.
See Also:
ComponentContainer.removeComponent(Component)

iterator

public java.util.Iterator<Component> iterator()
Gets the component container iterator for going trough all the components in the container.

Specified by:
iterator in interface HasComponents
Specified by:
iterator in interface java.lang.Iterable<Component>
Returns:
the Iterator of the components inside the container.

getComponentCount

public int getComponentCount()
Gets the number of contained components. Consistent with the iterator returned by AbstractComponentContainer.getComponentIterator().

Specified by:
getComponentCount in interface ComponentContainer
Returns:
the number of contained components

beforeClientResponse

public void beforeClientResponse(boolean initial)
Description copied from interface: ClientConnector
Called before the shared state and RPC invocations are sent to the client. Gives the connector an opportunity to set computed/dynamic state values or to invoke last minute RPC methods depending on other component features.

Specified by:
beforeClientResponse in interface ClientConnector
Overrides:
beforeClientResponse in class AbstractComponent
Parameters:
initial - true if the client-side connector will be created and initialized after this method has been invoked. false if there is already an initialized client-side connector.

getState

protected com.vaadin.shared.ui.csslayout.CssLayoutState getState()
Description copied from class: AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().

Overrides:
getState in class AbstractLayout
Returns:
updated component shared state

getCss

protected java.lang.String getCss(Component c)
Returns styles to be applied to given component. Override this method to inject custom style rules to components.

Note that styles are injected over previous styles before actual child rendering. Previous styles are not cleared, but overridden.

Note that one most often achieves better code style, by separating styling to theme (with custom theme and AbstractComponent.addStyleName(String). With own custom styles it is also very easy to break browser compatibility.

Parameters:
c - the component
Returns:
css rules to be applied to component

replaceComponent

public void replaceComponent(Component oldComponent,
                             Component newComponent)
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.

Specified by:
replaceComponent in interface ComponentContainer
Parameters:
oldComponent - the old component that will be replaced.
newComponent - the new component to be replaced.

addLayoutClickListener

public void addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
Description copied from interface: LayoutEvents.LayoutClickNotifier
Add a click listener to the layout. The listener is called whenever the user clicks inside the layout. An event is also triggered when the click targets a component inside a nested layout or Panel, provided the targeted component does not prevent the click event from propagating. A caption is not considered part of a component. The child component that was clicked is included in the LayoutEvents.LayoutClickEvent. Use #removeListener(LayoutClickListener) to remove the listener.

Specified by:
addLayoutClickListener in interface LayoutEvents.LayoutClickNotifier
Parameters:
listener - The listener to add

addListener

@Deprecated
public void addListener(LayoutEvents.LayoutClickListener listener)
Deprecated. As of 7.0, replaced by #addLayoutClickListener(LayoutClickListener)

Specified by:
addListener in interface LayoutEvents.LayoutClickNotifier

removeLayoutClickListener

public void removeLayoutClickListener(LayoutEvents.LayoutClickListener listener)
Description copied from interface: LayoutEvents.LayoutClickNotifier
Removes an LayoutClickListener.

Specified by:
removeLayoutClickListener in interface LayoutEvents.LayoutClickNotifier
Parameters:
listener - LayoutClickListener to be removed

removeListener

@Deprecated
public void removeListener(LayoutEvents.LayoutClickListener listener)
Deprecated. As of 7.0, replaced by #removeLayoutClickListener(LayoutClickListener)

Specified by:
removeListener in interface LayoutEvents.LayoutClickNotifier

getComponentIndex

public int getComponentIndex(Component component)
Returns the index of the given component.

Parameters:
component - The component to look up.
Returns:
The index of the component or -1 if the component is not a child.

getComponent

public Component getComponent(int index)
                       throws java.lang.IndexOutOfBoundsException
Returns the component at the given position.

Parameters:
index - The position of the component.
Returns:
The component at the given index.
Throws:
java.lang.IndexOutOfBoundsException - If the index is out of range.

readDesign

public void readDesign(org.jsoup.nodes.Element design,
                       DesignContext designContext)
Description copied from interface: Component
Reads the component state from the given design.

The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.

It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.

This method must not modify the design.

Specified by:
readDesign in interface Component
Overrides:
readDesign in class AbstractComponent
Parameters:
design - The element to obtain the state from
designContext - The DesignContext instance used for parsing the design

writeDesign

public void writeDesign(org.jsoup.nodes.Element design,
                        DesignContext designContext)
Description copied from interface: Component
Writes the component state to the given design.

The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.

This method must not modify the component state.

Specified by:
writeDesign in interface Component
Overrides:
writeDesign in class AbstractComponent
Parameters:
design - The element to write the component state to. Any previous attributes or child nodes are not cleared.
designContext - The DesignContext instance used for writing the design


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.