You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2009/08/31 13:45:56 UTC

svn commit: r809548 - in /myfaces/tobago/trunk: core/src/main/java/org/apache/myfaces/tobago/renderkit/ core/src/main/java/org/apache/myfaces/tobago/taglib/decl/ theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/stand...

Author: lofwyr
Date: Mon Aug 31 11:45:55 2009
New Revision: 809548

URL: http://svn.apache.org/viewvc?rev=809548&view=rev
Log:
TOBAGO-606: Layout-Manager
 - make max/min/preferred/sizes attributes adaptable in the renderer.

Added:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRenderer.java
      - copied, changed from r805731, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRenderer.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRendererBase.java
Modified:
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractLayoutableRendererBaseWrapper.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java
    myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsGridLayoutComponent.java
    myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractLayoutableRendererBaseWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractLayoutableRendererBaseWrapper.java?rev=809548&r1=809547&r2=809548&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractLayoutableRendererBaseWrapper.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/AbstractLayoutableRendererBaseWrapper.java Mon Aug 31 11:45:55 2009
@@ -18,12 +18,47 @@
  */
 
 
+import org.apache.myfaces.tobago.layout.Measure;
+
+import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
 public abstract class AbstractLayoutableRendererBaseWrapper extends AbstractRendererBaseWrapper
-    implements LayoutableRenderer {
+    implements LayoutableRenderer, LayoutComponentRenderer {
 
   protected final LayoutableRenderer getLayoutableRenderer(FacesContext facesContext) {
     return (LayoutableRenderer) getRenderer(facesContext);
   }
+
+  public Measure getWidth(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getWidth(facesContext, component);
+  }
+
+  public Measure getHeight(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getHeight(facesContext, component);
+  }
+
+  public Measure getMinimumWidth(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getMinimumWidth(facesContext, component);
+  }
+
+  public Measure getMinimumHeight(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getMinimumHeight(facesContext, component);
+  }
+
+  public Measure getPreferredWidth(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getPreferredWidth(facesContext, component);
+  }
+
+  public Measure getPreferredHeight(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getPreferredHeight(facesContext, component);
+  }
+
+  public Measure getMaximumWidth(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getMaximumWidth(facesContext, component);
+  }
+
+  public Measure getMaximumHeight(FacesContext facesContext, UIComponent component) {
+    return ((LayoutComponentRenderer) getRenderer(facesContext)).getMaximumHeight(facesContext, component);
+  }
 }

Copied: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRenderer.java (from r805731, myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRenderer.java)
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRenderer.java?p2=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRenderer.java&p1=myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRenderer.java&r1=805731&r2=809548&rev=809548&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRenderer.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRenderer.java Mon Aug 31 11:45:55 2009
@@ -1,5 +1,10 @@
 package org.apache.myfaces.tobago.renderkit;
 
+import org.apache.myfaces.tobago.layout.Measure;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -17,29 +22,22 @@
  * limitations under the License.
  */
 
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.ConverterException;
-import java.io.IOException;
-
+public interface LayoutComponentRenderer {
 
-public interface LayoutableRenderer {
-  void decode(FacesContext context, UIComponent component);
+  Measure getWidth(FacesContext facesContext, UIComponent component);
 
-  void encodeBegin(FacesContext context, UIComponent component) throws IOException;
+  Measure getHeight(FacesContext facesContext, UIComponent component);
 
-  void encodeChildren(FacesContext context, UIComponent component) throws IOException;
+  Measure getMinimumWidth(FacesContext facesContext, UIComponent component);
 
-  void encodeEnd(FacesContext context, UIComponent component) throws IOException;
+  Measure getMinimumHeight(FacesContext facesContext, UIComponent component);
 
-  String convertClientId(FacesContext context, String clientId);
+  Measure getPreferredWidth(FacesContext facesContext, UIComponent component);
 
-  boolean getRendersChildren();
+  Measure getPreferredHeight(FacesContext facesContext, UIComponent component);
 
-  Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
-      throws ConverterException;
+  Measure getMaximumWidth(FacesContext facesContext, UIComponent component);
 
-  String getRendererName(String rendererType);
+  Measure getMaximumHeight(FacesContext facesContext, UIComponent component);
 
-  void prepareRender(FacesContext facesContext, UIComponent component) throws IOException;
 }

Added: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRendererBase.java?rev=809548&view=auto
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRendererBase.java (added)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutComponentRendererBase.java Mon Aug 31 11:45:55 2009
@@ -0,0 +1,60 @@
+package org.apache.myfaces.tobago.renderkit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.myfaces.tobago.component.Attributes;
+import org.apache.myfaces.tobago.config.ThemeConfig;
+import org.apache.myfaces.tobago.layout.Measure;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+public abstract class LayoutComponentRendererBase extends RendererBase implements LayoutComponentRenderer {
+
+  public Measure getWidth(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.WIDTH);
+  }
+
+  public Measure getHeight(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.HEIGHT);
+  }
+
+  public Measure getMinimumWidth(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.MINIMUM_WIDTH);
+  }
+
+  public Measure getMinimumHeight(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.MINIMUM_HEIGHT);
+  }
+
+  public Measure getPreferredWidth(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.PREFERRED_WIDTH);
+  }
+
+  public Measure getPreferredHeight(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.PREFERRED_HEIGHT);
+  }
+
+  public Measure getMaximumWidth(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.MAXIMUM_WIDTH);
+  }
+
+  public Measure getMaximumHeight(FacesContext facesContext, UIComponent component) {
+    return ThemeConfig.getMeasure(facesContext, component, Attributes.MAXIMUM_HEIGHT);
+  }
+}

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java?rev=809548&r1=809547&r2=809548&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/renderkit/LayoutableRendererBase.java Mon Aug 31 11:45:55 2009
@@ -25,8 +25,9 @@
 import javax.faces.context.FacesContext;
 import java.io.IOException;
 
+// todo: may be removed when refactoring of the layout manager is done (TOBAGO-606)
 public abstract class LayoutableRendererBase
-    extends RendererBase implements LayoutableRenderer {
+    extends LayoutComponentRendererBase implements LayoutableRenderer {
 
   private static final Log LOG = LogFactory.getLog(LayoutableRendererBase.class);
 

Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsGridLayoutComponent.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsGridLayoutComponent.java?rev=809548&r1=809547&r2=809548&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsGridLayoutComponent.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/IsGridLayoutComponent.java Mon Aug 31 11:45:55 2009
@@ -38,7 +38,14 @@
    *
    * @param width The width for this component.
    */
-  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getWidth(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+          + "getFacesContext(), this, \"width\")")
   void setWidth(String width);
 
   /**
@@ -46,26 +53,52 @@
    *
    * @param height The height for this component.
    */
-  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getHeight(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+          + "getFacesContext(), this, \"height\")")
   void setHeight(String height);
 
   /**
    * @param minimumWidth The minimum width for this component.
    */
-  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getMinimumWidth(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+          + "getFacesContext(), this, \"minimumWidth\")")
   void setMinimumWidth(String minimumWidth);
 
   /**
    * @param minimumHeight The minimum height for this component.
    */
-  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getMinimumHeight(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+          + "getFacesContext(), this, \"minimumHeight\")")
   void setMinimumHeight(String minimumHeight);
 
   /**
    * @param preferredWidth The preferred width for this component.
    */
   @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
-      defaultCode = "org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getPreferredWidth(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
           + "getFacesContext(), this, \"preferredWidth\")")
   void setPreferredWidth(String preferredWidth);
 
@@ -73,20 +106,39 @@
    * @param preferredHeight The preferred height for this component.
    */
   @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
-      defaultCode = "org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getPreferredHeight(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
           + "getFacesContext(), this, \"preferredHeight\")")
   void setPreferredHeight(String preferredHeight);
 
   /**
    * @param maximumWidth The maximum width for this component.
    */
-  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getMaximumWidth(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+          + "getFacesContext(), this, \"maximumWidth\")")
   void setMaximumWidth(String maximumWidth);
 
   /**
    * @param maximumHeight The maximum height for this component.
    */
-  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure")
+  @UIComponentTagAttribute(type = "org.apache.myfaces.tobago.layout.Measure",
+      defaultCode = "(getRenderer(getFacesContext()) instanceof "
+          + "org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer)\n"
+          + "        ? ((org.apache.myfaces.tobago.renderkit.LayoutComponentRenderer) "
+          + "getRenderer(getFacesContext()))\n"
+          + "        .getMaximumHeight(getFacesContext(), this)\n"
+          + "        : org.apache.myfaces.tobago.config.ThemeConfig.getMeasure("
+          + "getFacesContext(), this, \"maximumHeight\")")
   void setMaximumHeight(String maximumHeight);
 
   /**

Modified: myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java?rev=809548&r1=809547&r2=809548&view=diff
==============================================================================
--- myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java (original)
+++ myfaces/tobago/trunk/theme/scarborough/src/main/java/org/apache/myfaces/tobago/renderkit/html/scarborough/standard/tag/ButtonRenderer.java Mon Aug 31 11:45:55 2009
@@ -27,12 +27,15 @@
 import org.apache.myfaces.tobago.component.Attributes;
 import org.apache.myfaces.tobago.component.UIButton;
 import org.apache.myfaces.tobago.component.UICommandBase;
+import org.apache.myfaces.tobago.layout.Measure;
+import org.apache.myfaces.tobago.layout.PixelMeasure;
 import org.apache.myfaces.tobago.renderkit.CommandRendererBase;
 import org.apache.myfaces.tobago.renderkit.LabelWithAccessKey;
 import org.apache.myfaces.tobago.renderkit.html.HtmlAttributes;
 import org.apache.myfaces.tobago.renderkit.html.HtmlConstants;
 import org.apache.myfaces.tobago.renderkit.html.util.CommandRendererHelper;
 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtil;
+import org.apache.myfaces.tobago.renderkit.util.RenderUtil;
 import org.apache.myfaces.tobago.util.AccessKeyMap;
 import org.apache.myfaces.tobago.util.ComponentUtil;
 import org.apache.myfaces.tobago.webapp.TobagoResponseWriter;
@@ -136,25 +139,27 @@
     boolean defaultCommand = ComponentUtil.getBooleanAttribute(component, Attributes.DEFAULT_COMMAND);
     return defaultCommand ? "submit" : "button";
   }
-/*
-  public int getPreferredWidth(FacesContext facesContext, UIComponent component) {
+
+  @Override
+  public Measure getPreferredWidth(FacesContext facesContext, UIComponent component) {
+
+    UIButton button = (UIButton) component;
     int width = 0;
-    String imageName = (String) component.getAttributes().get(ATTR_IMAGE);
-    if (imageName != null) {
-      width = getConfiguredValue(facesContext, component, "imageWidth");
+    boolean image = button.getImage() != null;
+    if (image) {
+      width = getConfiguredValue(facesContext, button, "imageWidth");
     }
-    LabelWithAccessKey label = new LabelWithAccessKey(component);
+    LabelWithAccessKey label = new LabelWithAccessKey(button);
 
     if (label.getText() != null) {
-      width += RenderUtil.calculateStringWidth(facesContext, component, label.getText());
+      width += RenderUtil.calculateStringWidth(facesContext, button, label.getText());
     }
-    int padding = getConfiguredValue(facesContext, component, "paddingWidth");
+    int padding = getConfiguredValue(facesContext, button, "paddingWidth");
     width += 2 * padding;
-    if (imageName != null && label.getText() != null) {
+    if (image && label.getText() != null) {
       width += padding;
     }
 
-    return width;
+    return new PixelMeasure(width);
   }
-  */
 }