List of usage examples for com.vaadin.client Util parseRelativeSize
public static FloatSize parseRelativeSize(AbstractComponentState state)
From source file:org.vaadin.addons.portallayout.gwt.client.portal.strategy.AbsolutePortalHeightRedistributionStrategy.java
License:Apache License
@Override public void redistributeHeights(PortalLayoutConnector portalConnector) { Profiler.enter("PLC.recalcHeight"); for (ComponentConnector cc : portalConnector.getCurrentChildren()) { PortletConnector portletConnector = PortalLayoutUtil.getPortletConnectorForContent(cc); PortletSlot slot = portletConnector.getPortletChrome().getAssociatedSlot(); if (portletConnector.hasRelativeHeight()) { if (!portletConnector.isCollapsed()) { float relativeHeight = Util.parseRelativeSize(portletConnector.getState().height); slot.setHeight(relativeHeight + "%"); }/* w w w . j a va 2 s. c om*/ } } Profiler.leave("PLC.recalcHeight"); }
From source file:org.vaadin.addons.portallayout.gwt.client.portal.strategy.StackHeightRedistributionStrategy.java
License:Apache License
@Override public void redistributeHeights(PortalLayoutConnector portalConnector) { Profiler.enter("PLC.recalcHeight"); Iterator<ComponentConnector> it = portalConnector.getCurrentChildren().iterator(); List<ComponentConnector> relativeHeightPortlets = new ArrayList<ComponentConnector>(); double totalPercentage = 0; int totalFixedHeightConsumption = 0; while (it.hasNext()) { ComponentConnector cc = it.next(); PortletConnector portletConnector = PortalLayoutUtil.getPortletConnectorForContent(cc); if (portletConnector != null) { if (portletConnector.hasRelativeHeight()) { totalPercentage += Util.parseRelativeSize(portletConnector.getState().height); relativeHeightPortlets.add(cc); } else { PortletChrome portletWidget = portletConnector.getPortletChrome(); totalFixedHeightConsumption += cc.getLayoutManager() .getOuterHeight(portletWidget.getAssociatedSlot().getElement()); }/* ww w.j ava 2 s . com*/ } } if (totalPercentage > 0) { totalPercentage = Math.max(totalPercentage, 100); int totalPortalHeight = portalConnector.getLayoutManager() .getInnerHeight(portalConnector.getWidget().getElement()); boolean isSpacing = portalConnector.getState().spacing; int spacingConsumption = 0; if (isSpacing && portalConnector.getView().getWidgetCount() > 0) { Element spacingEl = portalConnector.getWidget().getElement().getChild(0).cast(); spacingConsumption += new ComputedStyle(spacingEl).getIntProperty("height") * portalConnector.getView().getWidgetCount() - 1; } int reservedForRelativeSize = totalPortalHeight - totalFixedHeightConsumption - spacingConsumption; double ratio = reservedForRelativeSize / (double) totalPortalHeight * 100d; for (ComponentConnector cc : relativeHeightPortlets) { PortletConnector portletConnector = PortalLayoutUtil.getPortletConnectorForContent(cc); if (!portletConnector.isCollapsed()) { float percentageHeight = Util.parseRelativeSize(portletConnector.getState().height); double slotHeight = (percentageHeight / totalPercentage * ratio); int headerHeight = portletConnector.getPortletChrome().getHeader().getOffsetHeight(); double headerHeightPercentage = (double) headerHeight / totalPortalHeight * 100d; String slotHeightStr = Math.max(slotHeight, headerHeightPercentage) + "%"; portletConnector.getPortletChrome().getAssociatedSlot().setHeight(slotHeightStr); } } } Profiler.leave("PLC.recalcHeight"); }