]> source.dussan.org Git - vaadin-framework.git/commitdiff
Move logic for parsing percentages to LayoutManager
authorLeif Åstrand <leif@vaadin.com>
Tue, 3 Apr 2012 13:37:27 +0000 (16:37 +0300)
committerLeif Åstrand <leif@vaadin.com>
Tue, 3 Apr 2012 13:37:27 +0000 (16:37 +0300)
src/com/vaadin/terminal/gwt/client/LayoutManager.java
src/com/vaadin/terminal/gwt/client/ui/AbsoluteLayoutConnector.java

index 1de0b80a9e420b6cff3f9af603dff67a4a2b4b0b..6e4d28822b399f315a4fcad90f1a5b104d3aa79a 100644 (file)
@@ -453,6 +453,30 @@ public class LayoutManager {
         currentDependencyTree.setNeedsVerticalMeasure(component, false);
     }
 
+    public void reportHeightAssignedToRelative(ComponentConnector component,
+            int assignedHeight) {
+        assert component.isRelativeHeight();
+
+        float percentSize = parsePercent(component.getState().getHeight());
+        int effectiveHeight = Math.round(assignedHeight * (percentSize / 100));
+
+        reportOuterHeight(component, effectiveHeight);
+    }
+
+    public void reportWidthAssignedToRelative(ComponentConnector component,
+            int assignedWidth) {
+        assert component.isRelativeWidth();
+
+        float percentSize = parsePercent(component.getState().getWidth());
+        int effectiveWidth = Math.round(assignedWidth * (percentSize / 100));
+
+        reportOuterWidth(component, effectiveWidth);
+    }
+
+    private static float parsePercent(String size) {
+        return Float.parseFloat(size.substring(0, size.length() - 1));
+    }
+
     public void reportOuterWidth(ComponentConnector component, int outerWidth) {
         if (!isLayoutRunning()) {
             throw new IllegalStateException(
index e2d92d99e6f993df622bb0c7f3c1586fc315f7d0..d30874b6cc982ec5a8a67a47f52d7ae771f863d7 100644 (file)
@@ -121,11 +121,7 @@ public class AbsoluteLayoutConnector extends
                             - wrapper.getElement().getOffsetTop();
                 }
                 wrapperStyle.setHeight(h, Unit.PX);
-                float percentSize = parsePercent(paintable.getState()
-                        .getHeight());
-                int effectiveHeight = Math.round(h * (percentSize / 100));
-                getLayoutManager()
-                        .reportOuterHeight(paintable, effectiveHeight);
+                getLayoutManager().reportHeightAssignedToRelative(paintable, h);
             } else {
                 wrapperStyle.clearHeight();
             }
@@ -134,10 +130,6 @@ public class AbsoluteLayoutConnector extends
         }
     }
 
-    private static float parsePercent(String size) {
-        return Float.parseFloat(size.substring(0, size.length() - 1));
-    }
-
     public void layoutHorizontally() {
         VAbsoluteLayout layout = getWidget();
         for (ComponentConnector paintable : getChildren()) {
@@ -162,10 +154,7 @@ public class AbsoluteLayoutConnector extends
                             - wrapper.getElement().getOffsetLeft();
                 }
                 wrapperStyle.setWidth(w, Unit.PX);
-                float percentSize = parsePercent(paintable.getState()
-                        .getWidth());
-                int effectiveWidth = Math.round(w * (percentSize / 100));
-                getLayoutManager().reportOuterWidth(paintable, effectiveWidth);
+                getLayoutManager().reportWidthAssignedToRelative(paintable, w);
             } else {
                 wrapperStyle.clearWidth();
             }