]> source.dussan.org Git - vaadin-framework.git/commitdiff
LayoutResizeTest and small optimizations to BoxLayout
authorJouni Koivuviita <jouni@jounikoivuviita.com>
Fri, 20 Apr 2012 15:13:25 +0000 (18:13 +0300)
committerJouni Koivuviita <jouni@jounikoivuviita.com>
Fri, 20 Apr 2012 15:13:25 +0000 (18:13 +0300)
WebContent/layout-resize-test.html [new file with mode: 0644]
src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
src/com/vaadin/terminal/gwt/client/LayoutManager.java
src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java
tests/testbench/com/vaadin/tests/components/orderedlayout/BoxLayoutTest.java
tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutResizeTest.java [new file with mode: 0644]

diff --git a/WebContent/layout-resize-test.html b/WebContent/layout-resize-test.html
new file mode 100644 (file)
index 0000000..b798402
--- /dev/null
@@ -0,0 +1,41 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>LayoutResizeTest opener</title>
+</head>
+<body>
+
+<button onclick="testV7()">Open LayoutResizeTest (Vaadin 7)</button><br>
+<button onclick="testV6()">Open LayoutResizeTest (Vaadin 6)</button><br>
+<button onclick="resize1()">Resize to 650x450</button><br>
+<button onclick="resize2()">Resize to 950x750</button>
+
+
+<script>
+var win1, win2;
+
+function testV7() {
+       win1 = window.open('/vaadin/run/com.vaadin.tests.components.orderedlayout.LayoutResizeTest?restartApplication&debug','layoutResizeTestV7','width=800,height=600');
+}
+
+function testV6() {
+       win2 = window.open('/LayoutBenchmark/?restartApplication&debug','layoutResizeTestV6','width=800,height=600');
+}
+
+function resize1() {
+       if(win1)
+               win1.resizeTo(650,450);
+       if(win2)
+               win2.resizeTo(650,450);
+}
+
+function resize2() {
+       if(win1)
+               win1.resizeTo(950,750);
+       if(win2)
+               win2.resizeTo(950,750);
+}
+</script>
+</body>
+</html>
\ No newline at end of file
index 518f91df7da4777aff9a7436b438f41d9f3fc854..abea4a43e4a0e85ec3a0ee730794fb66ab74ce68 100644 (file)
@@ -24,7 +24,7 @@
        <replace-with class="com.vaadin.terminal.gwt.client.ui.HorizontalBoxLayoutConnector">
                <when-type-is class="com.vaadin.terminal.gwt.client.ui.orderedlayout.HorizontalLayoutConnector" />
        </replace-with>
-
+       
        <!-- Use own Scheduler implementation to be able to track if commands are 
                running -->
        <replace-with class="com.vaadin.terminal.gwt.client.VSchedulerImpl">
index a40a2e841f82475d02001899bf1e951433d40875..628a247d391a60b89ef524c5aa49ad7abd0df84f 100644 (file)
@@ -30,6 +30,8 @@ public class LayoutManager {
 
     private static final boolean debugLogging = false;
 
+    private static int totalLayoutTime = 0;
+
     private ApplicationConnection connection;
     private final Set<Element> measuredNonConnectorElements = new HashSet<Element>();
     private final MeasuredSize nullSize = new MeasuredSize();
@@ -365,6 +367,12 @@ public class LayoutManager {
 
         VConsole.log("Total layout phase time: "
                 + totalDuration.elapsedMillis() + "ms");
+
+        totalLayoutTime += totalDuration.elapsedMillis();
+        VConsole.log("");
+        VConsole.log("### Total combined layout phase: " + totalLayoutTime
+                + "ms");
+        VConsole.log("");
     }
 
     private void logConnectorStatus(int connectorId) {
index 2966f8b8ca6b8974228aac7270c7280c4867f11a..b3857cdae9eb1229816ec402e85ff3950d6af14a 100644 (file)
@@ -30,8 +30,8 @@ import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutServ
 import com.vaadin.terminal.gwt.client.ui.orderedlayout.AbstractOrderedLayoutState;
 
 public abstract class AbstractBoxLayoutConnector extends
-        AbstractLayoutConnector implements Paintable, PreLayoutListener,
-        PostLayoutListener {
+        AbstractLayoutConnector implements Paintable, /* PreLayoutListener, */
+PostLayoutListener {
 
     AbstractOrderedLayoutServerRPC rpc;
 
@@ -218,15 +218,24 @@ public abstract class AbstractBoxLayoutConnector extends
                 getWidget().updateCaptionOffset(slot.getCaptionElement());
             }
         } else {
-            getLayoutManager().removeElementResizeListener(
-                    slot.getCaptionElement(), slotCaptionResizeListener);
+            // getLayoutManager().removeElementResizeListener(
+            // slot.getCaptionElement(), slotCaptionResizeListener);
         }
 
         if (!slot.hasCaption()) {
             childCaptionElementHeight.remove(child.getWidget().getElement());
         }
 
+        if (needsFixedHeight()) {
+            getWidget().clearHeight();
+            getLayoutManager().setNeedsMeasure(this);
+        }
+
         updateLayoutHeight();
+
+        if (needsExpand()) {
+            updateExpand();
+        }
     }
 
     @Override
@@ -290,7 +299,9 @@ public abstract class AbstractBoxLayoutConnector extends
         getWidget().setSpacing(getState().isSpacing());
 
         if (needsFixedHeight()) {
+            getWidget().clearHeight();
             setLayoutHeightListener(true);
+            getLayoutManager().setNeedsMeasure(this);
         } else {
             setLayoutHeightListener(false);
         }
@@ -365,7 +376,10 @@ public abstract class AbstractBoxLayoutConnector extends
             }
 
             if (needsFixedHeight()) {
+                getWidget().clearHeight();
                 setLayoutHeightListener(true);
+                getLayoutManager().setNeedsMeasure(
+                        AbstractBoxLayoutConnector.this);
             } else {
                 setLayoutHeightListener(false);
             }
@@ -388,13 +402,9 @@ public abstract class AbstractBoxLayoutConnector extends
         return hasExpandRatio.size() > 0 && canApplyExpand;
     }
 
-    public void preLayout() {
-        resizeCount = 0;
-        if (needsFixedHeight()) {
-            getWidget().clearHeight();
-            getLayoutManager().setNeedsMeasure(this);
-        }
-    }
+    // public void preLayout() {
+    // resizeCount = 0;
+    // }
 
     public void postLayout() {
         if (needsFixedHeight()) {
@@ -410,19 +420,25 @@ public abstract class AbstractBoxLayoutConnector extends
                             .getOuterHeight(captionElement));
                 }
             }
+            // System.out.println("  ###  SlotCaption sizes: "
+            // + childCaptionElementHeight.values().toString());
 
             // If no height has been set, use the natural height for the
             // component (this is mostly just a precaution so that something
             // renders correctly)
-            String h = getWidget().getElement().getStyle().getHeight();
-            if (h == null || h.equals("")) {
-                int height = getLayoutManager().getOuterHeight(
-                        getWidget().getElement())
-                        - getLayoutManager().getMarginHeight(
-                                getWidget().getElement());
-                // int height = getMaxHeight();
-                getWidget().getElement().getStyle().setHeight(height, Unit.PX);
-            }
+            // String h = getWidget().getElement().getStyle().getHeight();
+            // if (h == null || h.equals("")) {
+            // int height = getLayoutManager().getOuterHeight(
+            // getWidget().getElement())
+            // - getLayoutManager().getMarginHeight(
+            // getWidget().getElement());
+            int height = getMaxHeight()
+                    + getLayoutManager().getBorderHeight(
+                            getWidget().getElement())
+                    + getLayoutManager().getPaddingHeight(
+                            getWidget().getElement());
+            getWidget().getElement().getStyle().setHeight(height, Unit.PX);
+            // }
         }
         // System.err.println("Element resize listeners fired for " +
         // resizeCount
@@ -459,6 +475,7 @@ public abstract class AbstractBoxLayoutConnector extends
                 // Caption element already detached
                 getLayoutManager().removeElementResizeListener(captionElement,
                         slotCaptionResizeListener);
+                childCaptionElementHeight.remove(widgetElement);
                 return;
             }
 
@@ -476,6 +493,13 @@ public abstract class AbstractBoxLayoutConnector extends
             int h = getLayoutManager().getOuterHeight(captionElement)
                     - getLayoutManager().getMarginHeight(captionElement);
             childCaptionElementHeight.put(widgetElement, h);
+            // System.out.println("Caption size: " + h);
+
+            if (needsFixedHeight()) {
+                getWidget().clearHeight();
+                getLayoutManager().setNeedsMeasure(
+                        AbstractBoxLayoutConnector.this);
+            }
 
             updateLayoutHeight();
 
index e52979267af3d4a5c697646c03027c3a4b01286b..6b3f1efde7de451c9ab1de451fb9908ee4d4a583 100644 (file)
@@ -115,8 +115,8 @@ public class BoxLayoutTest extends AbstractTestRoot {
                         grid.addComponent(new Label("Grid cell 2"));
                         grid.addComponent(grow);
                         grid.addComponent(new Label("Grid cell 4"));
-                        // l.addComponent(grid);
-                        l.addComponent(new TextField("Some field"));
+                        l.addComponent(grid);
+                        // l.addComponent(new TextField("Some field"));
                     }
                 });
         header.addComponent(addComponent);
diff --git a/tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutResizeTest.java b/tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutResizeTest.java
new file mode 100644 (file)
index 0000000..70777b6
--- /dev/null
@@ -0,0 +1,138 @@
+package com.vaadin.tests.components.orderedlayout;
+
+import com.vaadin.terminal.ThemeResource;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Alignment;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Embedded;
+import com.vaadin.ui.HorizontalLayout;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.VerticalSplitPanel;
+import com.vaadin.ui.themes.Reindeer;
+
+public class LayoutResizeTest extends TestBase {
+
+    @Override
+    protected void setup() {
+        getLayout().setSizeFull();
+
+        HorizontalSplitPanel split1 = new HorizontalSplitPanel();
+        split1.setSizeFull();
+        addComponent(split1);
+
+        VerticalLayout left = new VerticalLayout();
+        left.setSizeFull();
+        split1.setFirstComponent(left);
+
+        left.setSpacing(true);
+        left.setMargin(true);
+
+        left.addComponent(new Label("<h2>Layout resize test</h2>",
+                Label.ContentMode.XHTML));
+
+        Button resize = new Button("Resize to 700x400",
+                new Button.ClickListener() {
+                    public void buttonClick(ClickEvent event) {
+                        event.getButton()
+                                .getRoot()
+                                .executeJavaScript(
+                                        "setTimeout(function() {window.resizeTo(700,400)}, 500)");
+                    }
+                });
+        left.addComponent(resize);
+
+        resize = new Button("Resize to 900x600", new Button.ClickListener() {
+            public void buttonClick(ClickEvent event) {
+                event.getButton()
+                        .getRoot()
+                        .executeJavaScript(
+                                "setTimeout(function() {window.resizeTo(900,600)}, 500)");
+            }
+        });
+        left.addComponent(resize);
+
+        left.addComponent(new Label(
+                "Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies."));
+
+        Table table1 = new Table();
+        table1.setSizeFull();
+        table1.addContainerProperty("Column", String.class, "");
+        for (int i = 1; i <= 100; i++) {
+            table1.addItem(new Object[] { "Value " + i }, i);
+        }
+        left.addComponent(table1);
+        left.setExpandRatio(table1, 1);
+
+        VerticalSplitPanel split2 = new VerticalSplitPanel();
+        split2.setSizeFull();
+        split1.setSecondComponent(split2);
+
+        Table table2 = new Table();
+        table2.setSizeFull();
+        table2.addContainerProperty("Column 1", String.class, "");
+        table2.addContainerProperty("Column 2", String.class, "");
+        table2.addContainerProperty("Column 3", String.class, "");
+        table2.addContainerProperty("Column 4", String.class, "");
+        for (int i = 1; i <= 100; i++) {
+            table2.addItem(new Object[] { "Value " + i, "Value " + i,
+                    "Value " + i, "Value " + i }, i);
+        }
+        split2.setFirstComponent(table2);
+
+        VerticalLayout rows = new VerticalLayout();
+        rows.setWidth("100%");
+        rows.setSpacing(true);
+        rows.setMargin(true);
+        for (int i = 1; i <= 100; i++) {
+            rows.addComponent(getRow(i));
+        }
+        split2.setSecondComponent(rows);
+    }
+
+    private HorizontalLayout getRow(int i) {
+        HorizontalLayout row = new HorizontalLayout();
+        row.setWidth("100%");
+        row.setSpacing(true);
+
+        Embedded icon = new Embedded(null, new ThemeResource(
+                "../runo/icons/32/document.png"));
+        row.addComponent(icon);
+        row.setComponentAlignment(icon, Alignment.MIDDLE_LEFT);
+
+        Label text = new Label(
+                "Row content #"
+                        + i
+                        + ". In pellentesque faucibus vestibulum. Nulla at nulla justo, eget luctus tortor. Nulla facilisi. Duis aliquet.");
+        row.addComponent(text);
+        row.setExpandRatio(text, 1);
+
+        Button button = new Button("Edit");
+        button.addStyleName(Reindeer.BUTTON_SMALL);
+        row.addComponent(button);
+        row.setComponentAlignment(button, Alignment.MIDDLE_LEFT);
+
+        button = new Button("Delete");
+        button.addStyleName(Reindeer.BUTTON_SMALL);
+        row.addComponent(button);
+        row.setComponentAlignment(button, Alignment.MIDDLE_LEFT);
+
+        return row;
+    }
+
+    @Override
+    protected String getDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}