/* @ITMillApache2LicenseForJavaFiles@ */ package com.vaadin.ui; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Paintable; import com.vaadin.terminal.gwt.client.MouseEventDetails; import com.vaadin.terminal.gwt.client.ui.VCssLayout; /** * 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 {@link HorizontalLayout} and {@link VerticalLayout} *
* With {@link 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 {@link #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
*
*/
@ClientWidget(VCssLayout.class)
public class CssLayout extends AbstractLayout {
private static final String CLICK_EVENT = VCssLayout.CLICK_EVENT_IDENTIFIER;
/**
* Custom layout slots containing the components.
*/
protected LinkedList
* 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 {@link #addStyleName(String)}.
* With own custom styles it is also very easy to break browser
* compatibility.
*
* @param c
* the component
* @return css rules to be applied to component
*/
protected String getCss(Component c) {
return null;
}
/* Documented in superclass */
public void replaceComponent(Component oldComponent, Component newComponent) {
// Gets the locations
int oldLocation = -1;
int newLocation = -1;
int location = 0;
for (final Iterator i = components.iterator(); i.hasNext();) {
final Component component = (Component) i.next();
if (component == oldComponent) {
oldLocation = location;
}
if (component == newComponent) {
newLocation = location;
}
location++;
}
if (oldLocation == -1) {
addComponent(newComponent);
} else if (newLocation == -1) {
removeComponent(oldComponent);
addComponent(newComponent, oldLocation);
} else {
if (oldLocation > newLocation) {
components.remove(oldComponent);
components.add(newLocation, oldComponent);
components.remove(newComponent);
components.add(oldLocation, newComponent);
} else {
components.remove(newComponent);
components.add(oldLocation, newComponent);
components.remove(oldComponent);
components.add(newLocation, oldComponent);
}
requestRepaint();
}
}
@Override
public void changeVariables(Object source, Map variables) {
super.changeVariables(source, variables);
if (variables.containsKey(CLICK_EVENT)) {
fireClick((Map