import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.Widget;
-import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.ComponentConnector;
import com.vaadin.terminal.gwt.client.ConnectorHierarchyChangeEvent;
import com.vaadin.terminal.gwt.client.DirectionalManagedLayout;
import com.vaadin.terminal.gwt.client.LayoutManager;
-import com.vaadin.terminal.gwt.client.Paintable;
-import com.vaadin.terminal.gwt.client.UIDL;
import com.vaadin.terminal.gwt.client.Util;
import com.vaadin.terminal.gwt.client.VCaption;
-import com.vaadin.terminal.gwt.client.ValueMap;
import com.vaadin.terminal.gwt.client.communication.RpcProxy;
+import com.vaadin.terminal.gwt.client.communication.StateChangeEvent;
import com.vaadin.terminal.gwt.client.ui.AbstractLayoutConnector;
import com.vaadin.terminal.gwt.client.ui.AlignmentInfo;
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler;
import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
public abstract class AbstractOrderedLayoutConnector extends
- AbstractLayoutConnector implements Paintable, DirectionalManagedLayout {
+ AbstractLayoutConnector implements DirectionalManagedLayout {
AbstractOrderedLayoutServerRpc rpc;
return (VMeasuringOrderedLayout) super.getWidget();
}
- public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
- if (!isRealUpdate(uidl)) {
- return;
- }
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
clickEventHandler.handleEventHandlerRegistration();
VMeasuringOrderedLayout layout = getWidget();
- ValueMap expandRatios = uidl.getMapAttribute("expandRatios");
- ValueMap alignments = uidl.getMapAttribute("alignments");
-
for (ComponentConnector child : getChildren()) {
VLayoutSlot slot = layout.getSlotForChild(child.getWidget());
- String pid = child.getConnectorId();
- AlignmentInfo alignment;
- if (alignments.containsKey(pid)) {
- alignment = new AlignmentInfo(alignments.getInt(pid));
- } else {
- alignment = AlignmentInfo.TOP_LEFT;
- }
+ AlignmentInfo alignment = new AlignmentInfo(getState()
+ .getChildData().get(child).getAlignmentBitmask());
slot.setAlignment(alignment);
- double expandRatio;
- if (expandRatios.containsKey(pid)) {
- expandRatio = expandRatios.getRawNumber(pid);
- } else {
- expandRatio = 0;
- }
+ double expandRatio = getState().getChildData().get(child)
+ .getExpandRatio();
slot.setExpandRatio(expandRatio);
}
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.event.LayoutEvents.LayoutClickNotifier;
-import com.vaadin.terminal.PaintException;
-import com.vaadin.terminal.PaintTarget;
import com.vaadin.terminal.Sizeable;
-import com.vaadin.terminal.Vaadin6Component;
import com.vaadin.terminal.gwt.client.Connector;
import com.vaadin.terminal.gwt.client.MouseEventDetails;
import com.vaadin.terminal.gwt.client.ui.LayoutClickEventHandler;
import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutServerRpc;
import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutState;
+import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutState.ChildComponentData;
@SuppressWarnings("serial")
public abstract class AbstractOrderedLayout extends AbstractLayout implements
- Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier,
- Vaadin6Component {
+ Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier {
private AbstractOrderedLayoutServerRpc rpc = new AbstractOrderedLayoutServerRpc() {
/**
* Mapping from components to alignments (horizontal + vertical).
*/
- private final Map<Component, Alignment> componentToAlignment = new HashMap<Component, Alignment>();
-
- private final Map<Component, Float> componentToExpandRatio = new HashMap<Component, Float>();
-
public AbstractOrderedLayout() {
registerRpc(rpc);
}
components.add(c);
try {
super.addComponent(c);
- requestRepaint();
} catch (IllegalArgumentException e) {
components.remove(c);
throw e;
}
+ componentAdded(c);
}
/**
components.addFirst(c);
try {
super.addComponent(c);
- requestRepaint();
} catch (IllegalArgumentException e) {
components.remove(c);
throw e;
}
+ componentAdded(c);
+
}
/**
components.add(index, c);
try {
super.addComponent(c);
- requestRepaint();
} catch (IllegalArgumentException e) {
components.remove(c);
throw e;
}
+
+ componentAdded(c);
+ }
+
+ private void componentRemoved(Component c) {
+ getState().getChildData().remove(c);
+ requestRepaint();
+ }
+
+ private void componentAdded(Component c) {
+ getState().getChildData().put(c, new ChildComponentData());
+ requestRepaint();
+
}
/**
@Override
public void removeComponent(Component c) {
components.remove(c);
- componentToAlignment.remove(c);
- componentToExpandRatio.remove(c);
super.removeComponent(c);
- requestRepaint();
+ componentRemoved(c);
}
/**
return components.size();
}
- /**
- * Paints the content of this component.
- *
- * @param target
- * the Paint Event.
- * @throws PaintException
- * if the paint operation failed.
- */
- public void paintContent(PaintTarget target) throws PaintException {
- // Add child component alignment info to layout tag
- target.addAttribute("alignments", componentToAlignment);
- target.addAttribute("expandRatios", componentToExpandRatio);
- }
-
- public void changeVariables(Object source, Map<String, Object> variables) {
- // TODO Remove once Vaadin6Component is no longer implemented
- }
-
/* Documented in superclass */
public void replaceComponent(Component oldComponent, Component newComponent) {
removeComponent(oldComponent);
addComponent(newComponent, oldLocation);
} else {
+ // Both old and new are in the layout
if (oldLocation > newLocation) {
components.remove(oldComponent);
components.add(newLocation, oldComponent);
components.remove(newComponent);
- componentToAlignment.remove(newComponent);
components.add(oldLocation, newComponent);
} else {
components.remove(newComponent);
components.add(oldLocation, newComponent);
components.remove(oldComponent);
- componentToAlignment.remove(oldComponent);
components.add(newLocation, oldComponent);
}
*/
public void setComponentAlignment(Component childComponent,
int horizontalAlignment, int verticalAlignment) {
- if (components.contains(childComponent)) {
- // Alignments are bit masks
- componentToAlignment.put(childComponent, new Alignment(
- horizontalAlignment + verticalAlignment));
- requestRepaint();
- } else {
- throw new IllegalArgumentException(
- "Component must be added to layout before using setComponentAlignment()");
- }
+ Alignment a = new Alignment(horizontalAlignment + verticalAlignment);
+ setComponentAlignment(childComponent, a);
}
public void setComponentAlignment(Component childComponent,
Alignment alignment) {
- if (components.contains(childComponent)) {
- componentToAlignment.put(childComponent, alignment);
+ ChildComponentData childData = getState().getChildData().get(
+ childComponent);
+ if (childData != null) {
+ // Alignments are bit masks
+ childData.setAlignmentBitmask(alignment.getBitMask());
requestRepaint();
} else {
throw new IllegalArgumentException(
* .vaadin.ui.Component)
*/
public Alignment getComponentAlignment(Component childComponent) {
- Alignment alignment = componentToAlignment.get(childComponent);
- if (alignment == null) {
- return ALIGNMENT_DEFAULT;
- } else {
- return alignment;
+ ChildComponentData childData = getState().getChildData().get(
+ childComponent);
+ if (childData == null) {
+ throw new IllegalArgumentException(
+ "The given component is not a child of this layout");
}
+
+ return new Alignment(childData.getAlignmentBitmask());
}
/*
* @param ratio
*/
public void setExpandRatio(Component component, float ratio) {
- if (components.contains(component)) {
- componentToExpandRatio.put(component, ratio);
- requestRepaint();
- } else {
+ ChildComponentData childData = getState().getChildData().get(component);
+ if (childData == null) {
throw new IllegalArgumentException(
- "Component must be added to layout before using setExpandRatio()");
+ "The given component is not a child of this layout");
}
+
+ childData.setExpandRatio(ratio);
+ requestRepaint();
};
/**
*
* @param component
* which expand ratios is requested
- * @return expand ratio of given component, 0.0f by default
+ * @return expand ratio of given component, 0.0f by default.
*/
public float getExpandRatio(Component component) {
- Float ratio = componentToExpandRatio.get(component);
- return (ratio == null) ? 0 : ratio.floatValue();
+ ChildComponentData childData = getState().getChildData().get(component);
+ if (childData == null) {
+ throw new IllegalArgumentException(
+ "The given component is not a child of this layout");
+ }
+
+ return childData.getExpandRatio();
}
public void addListener(LayoutClickListener listener) {