aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Koivuviita <jouni@jounikoivuviita.com>2012-04-20 18:13:25 +0300
committerJouni Koivuviita <jouni@jounikoivuviita.com>2012-04-20 18:13:25 +0300
commit13fa0ce71c59cb891bbf789c03f6974cc9d920b7 (patch)
tree313e31040430f5c109ed4c80df8054b4fc19a6e5
parent4ead4970e2951b8d2e6ccd5e4e931d5ab5580bc7 (diff)
downloadvaadin-framework-13fa0ce71c59cb891bbf789c03f6974cc9d920b7.tar.gz
vaadin-framework-13fa0ce71c59cb891bbf789c03f6974cc9d920b7.zip
LayoutResizeTest and small optimizations to BoxLayout
-rw-r--r--WebContent/layout-resize-test.html41
-rw-r--r--src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml2
-rw-r--r--src/com/vaadin/terminal/gwt/client/LayoutManager.java8
-rw-r--r--src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java64
-rw-r--r--tests/testbench/com/vaadin/tests/components/orderedlayout/BoxLayoutTest.java4
-rw-r--r--tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutResizeTest.java138
6 files changed, 234 insertions, 23 deletions
diff --git a/WebContent/layout-resize-test.html b/WebContent/layout-resize-test.html
new file mode 100644
index 0000000000..b798402bb7
--- /dev/null
+++ b/WebContent/layout-resize-test.html
@@ -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
diff --git a/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml b/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
index 518f91df7d..abea4a43e4 100644
--- a/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
+++ b/src/com/vaadin/terminal/gwt/DefaultWidgetSet.gwt.xml
@@ -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">
diff --git a/src/com/vaadin/terminal/gwt/client/LayoutManager.java b/src/com/vaadin/terminal/gwt/client/LayoutManager.java
index a40a2e841f..628a247d39 100644
--- a/src/com/vaadin/terminal/gwt/client/LayoutManager.java
+++ b/src/com/vaadin/terminal/gwt/client/LayoutManager.java
@@ -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) {
diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java
index 2966f8b8ca..b3857cdae9 100644
--- a/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java
+++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractBoxLayoutConnector.java
@@ -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();
diff --git a/tests/testbench/com/vaadin/tests/components/orderedlayout/BoxLayoutTest.java b/tests/testbench/com/vaadin/tests/components/orderedlayout/BoxLayoutTest.java
index e52979267a..6b3f1efde7 100644
--- a/tests/testbench/com/vaadin/tests/components/orderedlayout/BoxLayoutTest.java
+++ b/tests/testbench/com/vaadin/tests/components/orderedlayout/BoxLayoutTest.java
@@ -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
index 0000000000..70777b6441
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/orderedlayout/LayoutResizeTest.java
@@ -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;
+ }
+
+}