com.vaadin.ui.
Class CssLayout
java.lang.Object
com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractComponentContainer
com.vaadin.ui.AbstractLayout
com.vaadin.ui.CssLayout
All Implemented Interfaces:
LayoutEvents.LayoutClickNotifier, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, ComponentContainer, Layout, Layout.MarginHandler, Serializable, EventListener
- extends AbstractLayout
- implements LayoutEvents.LayoutClickNotifier
public class CssLayout
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
- rather similar server side api
- no spacing, alignment or expand ratios
- much simpler DOM that can be styled by skilled web developer
- no abstraction of browser differences (developer must ensure that the result works properly on each browser)
- different kind of handling for relative sizes (that are set from server side) (*)
- noticeably faster rendering time in some situations as we rely more on the browser's rendering engine.
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:
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 | |
---|---|
protected LinkedList<Component> |
components
Custom layout slots containing the components. |
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 | |
---|---|
CssLayout()
|
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 |
addListener(LayoutEvents.LayoutClickListener listener)
Add a click listener to the layout. |
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. |
Iterator<Component> |
getComponentIterator()
Gets the component container iterator for going trough all the components in the container. |
protected String |
getCss(Component c)
Returns styles to be applied to given component. |
void |
paintContent(PaintTarget target)
Paints the content of this component. |
void |
removeComponent(Component c)
Removes the component from this container. |
void |
removeListener(LayoutEvents.LayoutClickListener listener)
Removes an LayoutClickListener. |
void |
replaceComponent(Component oldComponent,
Component newComponent)
Replaces the component in the container with another one without changing position. |
Methods inherited from class com.vaadin.ui.AbstractLayout |
---|
changeVariables, fireClick, getMargin, setMargin, setMargin, 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 |
Field Detail |
---|
components
protected LinkedList<Component> components
Custom layout slots containing the components.
Constructor Detail |
---|
CssLayout
public CssLayout()
Method Detail |
---|
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)
Add a component into this container. The component is added to the right or under the previous component.
addComponentAsFirst
public void addComponentAsFirst(Component c)
- Parameters:
c
- the component to be added.
Adds a component into this container. The component is added to the left or on top of the other components.
addComponent
public void addComponent(Component c,
int index)
- 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.
Adds a component into indexed position in this container.
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.
getComponentIterator
public Iterator<Component> getComponentIterator()
- Specified by:
getComponentIterator
in interfaceComponentContainer
- 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()
.
paintContent
public void paintContent(PaintTarget target)
throws PaintException
- Overrides:
paintContent
in classAbstractLayout
- Parameters:
target
- the Paint Event.- Throws:
PaintException
- if the paint operation failed.
Paints the content of this component.
getCss
protected String getCss(Component c)
- Parameters:
c
- the component- Returns:
- css rules to be applied to component
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.
replaceComponent
public void replaceComponent(Component oldComponent,
Component newComponent)
- Specified by:
replaceComponent
in interfaceComponentContainer
- 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.
addListener
public void addListener(LayoutEvents.LayoutClickListener listener)
- Specified by:
addListener
in interfaceLayoutEvents.LayoutClickNotifier
- Parameters:
listener
- The listener to add
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.
removeListener
public void removeListener(LayoutEvents.LayoutClickListener listener)
- Specified by:
removeListener
in interfaceLayoutEvents.LayoutClickNotifier
- Parameters:
listener
- LayoutClickListener to be removed
Description copied from interface: LayoutEvents.LayoutClickNotifier
Removes an LayoutClickListener.
getComponentIndex
public int getComponentIndex(Component component)
- Parameters:
component
- The component to look up.- Returns:
- The index of the component or -1 if the component is not a child.
Returns the index of the given component.
getComponent
public Component getComponent(int index)
throws IndexOutOfBoundsException
- Parameters:
index
- The position of the component.- Returns:
- The component at the given index.
- Throws:
IndexOutOfBoundsException
- If the index is out of range.
Returns the component at the given position.