You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/01/15 14:54:05 UTC

svn commit: r496314 - in /myfaces/tobago/trunk/theme/scarborough/src/main: java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/

Author: bommel
Date: Mon Jan 15 05:54:04 2007
New Revision: 496314

URL: http://svn.apache.org/viewvc?view=rev&rev=496314
Log:
(TOBAGO-19) implement 'fixed' in width calculation of panel renderers

Modified:
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java
    myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago-theme-config.properties

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java?view=diff&rev=496314&r1=496313&r2=496314
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/GridLayoutRenderer.java Mon Jan 15 05:54:04 2007
@@ -65,16 +65,17 @@
 
   private static final Log LOG = LogFactory.getLog(GridLayoutRenderer.class);
 
-  public Dimension getFixedSize(FacesContext facesContext, UIComponent component) {
+  /*public Dimension getFixedSize(FacesContext facesContext, UIComponent component) {
     Dimension dimension = null;
 
     int height = getFixedHeight(facesContext, component);
-    int width = -1; // TODO. implement getFixedWidth
+    int width =  getFixedWidth(facesContext, component);
+        //-1; // TODO. implement getFixedWidth
 
     dimension = new Dimension(width, height);
 
     return dimension;
-  }
+  } */
 
 
   public int getFixedHeight(FacesContext facesContext, UIComponent component) {
@@ -87,6 +88,16 @@
     return height;
   }
 
+  public int getFixedWidth(FacesContext facesContext, UIComponent component) {
+     int width = calculateLayoutWidth(facesContext, component, false);
+
+     RendererBase containerRenderer =
+         ComponentUtil.getRenderer(facesContext, component);
+     width += containerRenderer.getPaddingWidth(facesContext, component);
+     return width;
+   }
+
+
   public int calculateLayoutHeight(
       FacesContext facesContext, UIComponent component, boolean minimum) {
     UIGridLayout layout = (UIGridLayout) UILayout.getLayout(component);
@@ -139,6 +150,82 @@
     return height;
   }
 
+
+  public int calculateLayoutWidth(
+      FacesContext facesContext, UIComponent component, boolean minimum) {
+    UIGridLayout layout = (UIGridLayout) UILayout.getLayout(component);
+    final List<UIGridLayout.Row> rows = layout.ensureRows();
+    UIGridLayout.Row row = rows.get(0);
+
+    String columnLayout
+        = (String) layout.getAttributes().get(ATTR_COLUMNS);
+
+    if (columnLayout == null && !minimum && LOG.isDebugEnabled()) {
+      LOG.debug("No rowLayout found using " + (minimum ? "'minimum'" : "'fixed'")
+          + " for all " + rows.size() + " rows of "
+          + layout.getClientId(facesContext) + " !");
+    }
+    String[] layoutTokens
+        = LayoutInfo.createLayoutTokens(columnLayout, row.getColumns(),
+            minimum ? "minimum" : "fixed");
+
+    if (row.getColumns() != layoutTokens.length) {
+      LOG.warn("Unbalanced layout: rows.size()=" + rows.size()
+          + " != layoutTokens.length=" + layoutTokens.length
+          + " columnLayout='" + columnLayout + "'");
+    }
+    int size = Math.min(rows.size(), layoutTokens.length);
+
+    int width = 0;
+    width += getMarginAsInt(layout.getMarginLeft());
+    width += getMarginAsInt(layout.getMarginRight());
+    for (int i = 0; i < size; i++) {
+      if (!columnIsRendered(rows,  i)) {
+        continue;
+      }
+      width += getCellPadding(facesContext, layout,  i);
+      String token = layoutTokens[i];
+      if (token.matches("\\d+px")) {
+        width += Integer.parseInt(token.replaceAll("\\D", ""));
+      } else if (token.equals("fixed")) {
+        width += getMaxWidth(facesContext, rows, i, false);
+      } else if (token.equals("minimum")) {
+        width += getMaxWidth(facesContext, rows, i, true);
+      } else {
+        if (!minimum && LOG.isWarnEnabled()) {
+          LOG.warn("Unable to calculate Width for token '" + token
+              + "'! using " + (minimum ? "'minimum'" : "'fixed'") + " , component:"
+              + layout.getClientId(facesContext) + " is "
+              + layout.getRendererType());
+        }
+        width += getMaxWidth(facesContext, rows,  i, minimum);
+      }
+    }
+
+    return width;
+  }
+
+  private boolean columnIsRendered(List<UIGridLayout.Row> rows, int column) {
+    for (UIGridLayout.Row row : rows) {
+      Object object = row.getElements().get(column); 
+      if (object instanceof UIComponent) {
+        if (object instanceof UICell) {
+          UICell cell = (UICell) object;
+          if (cell.getSpanX() > 1) {
+            return false;
+          }
+        }
+        UIComponent component = (UIComponent) object;
+        if (component.isRendered()) {
+          return true;
+        }
+      } else if (UIGridLayout.USED.equals(object)) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   private boolean rowIsRendered(UIGridLayout.Row row) {
     for (Object element : row.getElements()) {
       if (element instanceof UIComponent) {
@@ -593,7 +680,11 @@
 
         if (object instanceof UIComponent) {
          UIComponent component = (UIComponent) object;
-
+          if (component instanceof UICell) {
+            if (((UICell)component).getSpanX() > 1) {
+              continue;
+            }
+          }
           int max = -1;
           if (minimum) {
             max = (int) LayoutUtil.getMinimumSize(facesContext, component).getWidth();

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago-theme-config.properties
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago-theme-config.properties?view=diff&rev=496314&r1=496313&r2=496314
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago-theme-config.properties (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/resources/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/property/tobago-theme-config.properties Mon Jan 15 05:54:04 2007
@@ -46,6 +46,10 @@
 Box.paddingTopWhenToolbar=22
 Box.extraPaddingHeightWhenToolbar=10
 
+Button.imageWidth=18
+Button.paddingWidth=10
+Button.fontWidth=8
+
 ColumnSelector.fixedWidth=24
 
 SelectBooleanCheckbox.componentExtraWidth=21