]> source.dussan.org Git - vaadin-framework.git/commitdiff
Updated AbstractOrderedLayout to no longer use paintContent
authorArtur Signell <artur@vaadin.com>
Sun, 13 May 2012 21:45:28 +0000 (00:45 +0300)
committerArtur Signell <artur@vaadin.com>
Sun, 13 May 2012 23:10:34 +0000 (02:10 +0300)
src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java
src/com/vaadin/terminal/gwt/client/ui/orderedlayout/AbstractOrderedLayoutState.java
src/com/vaadin/ui/AbstractOrderedLayout.java

index 174da61bd390017c78dd10926b9a91193d0c1a13..d15766db217c51a4c223e385123be348747567ae 100644 (file)
@@ -9,17 +9,14 @@ import com.google.gwt.dom.client.Style;
 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;
@@ -29,7 +26,7 @@ import com.vaadin.terminal.gwt.client.ui.layout.ComponentConnectorLayoutSlot;
 import com.vaadin.terminal.gwt.client.ui.layout.VLayoutSlot;
 
 public abstract class AbstractOrderedLayoutConnector extends
-        AbstractLayoutConnector implements Paintable, DirectionalManagedLayout {
+        AbstractLayoutConnector implements DirectionalManagedLayout {
 
     AbstractOrderedLayoutServerRpc rpc;
 
@@ -100,35 +97,23 @@ public abstract class AbstractOrderedLayoutConnector extends
         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);
         }
 
index bf542d3951b6e861550b6515918f1d61a0b3ba95..1d573584904ba98ed3dc4b155ebe4e8b3802c486 100644 (file)
@@ -3,11 +3,48 @@
  */
 package com.vaadin.terminal.gwt.client.ui.orderedlayout;
 
+import java.io.Serializable;
+import java.util.HashMap;
+
+import com.vaadin.terminal.gwt.client.Connector;
 import com.vaadin.terminal.gwt.client.ui.AbstractLayoutState;
+import com.vaadin.terminal.gwt.client.ui.AlignmentInfo;
 
 public class AbstractOrderedLayoutState extends AbstractLayoutState {
     private boolean spacing = false;
 
+    public HashMap<Connector, ChildComponentData> childData = new HashMap<Connector, ChildComponentData>();
+
+    public static class ChildComponentData implements Serializable {
+        private int alignmentBitmask = AlignmentInfo.TOP_LEFT.getBitMask();
+        private float expandRatio = 0.0f;
+
+        public int getAlignmentBitmask() {
+            return alignmentBitmask;
+        }
+
+        public void setAlignmentBitmask(int alignmentBitmask) {
+            this.alignmentBitmask = alignmentBitmask;
+        }
+
+        public float getExpandRatio() {
+            return expandRatio;
+        }
+
+        public void setExpandRatio(float expandRatio) {
+            this.expandRatio = expandRatio;
+        }
+
+    }
+
+    public HashMap<Connector, ChildComponentData> getChildData() {
+        return childData;
+    }
+
+    public void setChildData(HashMap<Connector, ChildComponentData> childData) {
+        this.childData = childData;
+    }
+
     public boolean isSpacing() {
         return spacing;
     }
index 3606fa6572853965dd508bdb201019a2b93c83ad..2cd6fc2a9aa790726d66b83522bcba4dad41708e 100644 (file)
@@ -4,28 +4,23 @@
 
 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() {
 
@@ -48,10 +43,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
     /**
      * 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);
     }
@@ -75,11 +66,11 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         components.add(c);
         try {
             super.addComponent(c);
-            requestRepaint();
         } catch (IllegalArgumentException e) {
             components.remove(c);
             throw e;
         }
+        componentAdded(c);
     }
 
     /**
@@ -98,11 +89,12 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         components.addFirst(c);
         try {
             super.addComponent(c);
-            requestRepaint();
         } catch (IllegalArgumentException e) {
             components.remove(c);
             throw e;
         }
+        componentAdded(c);
+
     }
 
     /**
@@ -127,11 +119,23 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         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();
+
     }
 
     /**
@@ -143,10 +147,8 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
     @Override
     public void removeComponent(Component c) {
         components.remove(c);
-        componentToAlignment.remove(c);
-        componentToExpandRatio.remove(c);
         super.removeComponent(c);
-        requestRepaint();
+        componentRemoved(c);
     }
 
     /**
@@ -169,24 +171,6 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
         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) {
 
@@ -213,17 +197,16 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
             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);
             }
 
@@ -239,21 +222,17 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
      */
     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(
@@ -269,12 +248,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
      * .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());
     }
 
     /*
@@ -326,13 +307,14 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
      * @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();
     };
 
     /**
@@ -340,11 +322,16 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
      * 
      * @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) {