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 2010/04/26 10:55:04 UTC
svn commit: r937967 - in /myfaces/tobago/trunk:
core/src/main/java/org/apache/myfaces/tobago/internal/component/
core/src/main/java/org/apache/myfaces/tobago/taglib/decl/
example/demo/src/main/webapp/
example/demo/src/main/webapp/WEB-INF/tags/layout/ e...
Author: lofwyr
Date: Mon Apr 26 08:55:03 2010
New Revision: 937967
URL: http://svn.apache.org/viewvc?rev=937967&view=rev
Log:
TOBAGO-606: Implement a new layout manager concept which layouts the components separated from rendering.
- add support for margin, marginLeft, ...
Added:
myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin-fallback.xhtml
myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin.xhtml
Modified:
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIGridLayout.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargin.java
myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargins.java
myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/tags/layout/overview.xhtml
myfaces/tobago/trunk/example/demo/src/main/webapp/init.xhtml
myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/GridLayoutRule.java
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIGridLayout.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIGridLayout.java?rev=937967&r1=937966&r2=937967&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIGridLayout.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIGridLayout.java Mon Apr 26 08:55:03 2010
@@ -50,6 +50,9 @@ public abstract class AbstractUIGridLayo
private Grid grid;
+ /**
+ * Initialize the grid and remove the current width and height values from the component, recursively.
+ */
public void init() {
grid = new Grid(LayoutTokens.parse(getColumns()), LayoutTokens.parse(getRows()));
@@ -201,7 +204,9 @@ public abstract class AbstractUIGridLayo
available = available.subtractNotNegative(head.getMeasure());
}
available = available.subtractNotNegative(LayoutUtils.getBeginOffset(orientation, container));
+ available = available.subtractNotNegative(getMarginBegin(orientation));
available = available.subtractNotNegative(computeSpacing(orientation, 0, heads.length));
+ available = available.subtractNotNegative(getMarginEnd(orientation));
available = available.subtractNotNegative(LayoutUtils.getEndOffset(orientation, container));
List<Measure> partition = list.partition(available);
@@ -265,6 +270,7 @@ public abstract class AbstractUIGridLayo
// compute the position of the cell
Measure position = LayoutUtils.getBeginOffset(orientation, getLayoutContainer());
+ position = position.add(getMarginBegin(orientation));
for (int k = 0; k < i; k++) {
if (heads[k] == null) {
LOG.warn("Measure is null, should be debugged... i=" + i + " k=" + k + " grid=" + grid,
@@ -302,6 +308,13 @@ public abstract class AbstractUIGridLayo
return orientation == Orientation.HORIZONTAL ? getColumnSpacing() : getRowSpacing();
}
+ public Measure getMarginBegin(Orientation orientation) {
+ return orientation == Orientation.HORIZONTAL ? getMarginLeft() : getMarginTop();
+ }
+
+ public Measure getMarginEnd(Orientation orientation) {
+ return orientation == Orientation.HORIZONTAL ? getMarginRight() : getMarginBottom();
+ }
/**
* Compute the sum of the space between the cells.
@@ -336,6 +349,14 @@ public abstract class AbstractUIGridLayo
public abstract Measure getColumnSpacing();
+ public abstract Measure getMarginLeft();
+
+ public abstract Measure getMarginTop();
+
+ public abstract Measure getMarginRight();
+
+ public abstract Measure getMarginBottom();
+
@Override
public boolean getRendersChildren() {
return false;
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargin.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargin.java?rev=937967&r1=937966&r2=937967&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargin.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargin.java Mon Apr 26 08:55:03 2010
@@ -20,14 +20,13 @@ package org.apache.myfaces.tobago.taglib
import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
-/**
- * $Id$
- */
public interface HasMargin {
+
/**
- * Margin between container component and layouted children.
+ * Margin between container component and the children.
*/
@TagAttribute
- @UIComponentTagAttribute()
+ @UIComponentTagAttribute(
+ type = "org.apache.myfaces.tobago.layout.Measure")
void setMargin(String margin);
}
Modified: myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargins.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargins.java?rev=937967&r1=937966&r2=937967&view=diff
==============================================================================
--- myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargins.java (original)
+++ myfaces/tobago/trunk/core/src/main/java/org/apache/myfaces/tobago/taglib/decl/HasMargins.java Mon Apr 26 08:55:03 2010
@@ -20,35 +20,41 @@ package org.apache.myfaces.tobago.taglib
import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
-/**
- * $Id$
- */
public interface HasMargins {
+
/**
- * Top margin between container component and layouted children.
+ * Top margin between container component and the children.
*/
@TagAttribute
- @UIComponentTagAttribute(defaultCode = "getMargin()")
+ @UIComponentTagAttribute(
+ type = "org.apache.myfaces.tobago.layout.Measure",
+ defaultCode = "getMargin()")
void setMarginTop(String margin);
/**
- * Right margin between container component and layouted children.
+ * Right margin between container component and the children.
*/
@TagAttribute
- @UIComponentTagAttribute(defaultCode = "getMargin()")
+ @UIComponentTagAttribute(
+ type = "org.apache.myfaces.tobago.layout.Measure",
+ defaultCode = "getMargin()")
void setMarginRight(String margin);
/**
- * Bottom margin between container component and layouted children.
+ * Bottom margin between container component and the children.
*/
@TagAttribute
- @UIComponentTagAttribute(defaultCode = "getMargin()")
+ @UIComponentTagAttribute(
+ type = "org.apache.myfaces.tobago.layout.Measure",
+ defaultCode = "getMargin()")
void setMarginBottom(String margin);
/**
- * Left margin between container component and layouted children.
+ * Left margin between container component and the children.
*/
@TagAttribute
- @UIComponentTagAttribute(defaultCode = "getMargin()")
+ @UIComponentTagAttribute(
+ type = "org.apache.myfaces.tobago.layout.Measure",
+ defaultCode = "getMargin()")
void setMarginLeft(String margin);
}
Modified: myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/tags/layout/overview.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/tags/layout/overview.xhtml?rev=937967&r1=937966&r2=937967&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/tags/layout/overview.xhtml (original)
+++ myfaces/tobago/trunk/example/demo/src/main/webapp/WEB-INF/tags/layout/overview.xhtml Mon Apr 26 08:55:03 2010
@@ -285,8 +285,7 @@
</f:facet>
<f:facet name="layout">
- <tc:gridLayout border="0" columns="*;4*"
- margin="10px" rows="100px;fixed;*;fixed"/>
+ <tc:gridLayout border="0" columns="*;4*" margin="10px" rows="100px;fixed;*;fixed"/>
</f:facet>
<tc:cell spanX="2">
Modified: myfaces/tobago/trunk/example/demo/src/main/webapp/init.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/demo/src/main/webapp/init.xhtml?rev=937967&r1=937966&r2=937967&view=diff
==============================================================================
--- myfaces/tobago/trunk/example/demo/src/main/webapp/init.xhtml (original)
+++ myfaces/tobago/trunk/example/demo/src/main/webapp/init.xhtml Mon Apr 26 08:55:03 2010
@@ -25,7 +25,7 @@
<tc:loadBundle basename="overview" var="overviewBundle"/>
<tc:page applicationIcon="icon/favicon.ico" label="#{overviewBundle.pageTitle}" id="page">
<f:facet name="layout">
- <tc:gridLayout marginLeft="100px" marginTop="100px" rows="auto;auto"/>
+ <tc:gridLayout marginLeft="100px" marginTop="100px" rowSpacing="40px" rows="auto;auto"/>
</f:facet>
<f:facet name="action">
<tc:link action="/overview/intro.xhtml"/>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin-fallback.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin-fallback.xhtml?rev=937967&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin-fallback.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin-fallback.xhtml Mon Apr 26 08:55:03 2010
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<f:view
+ xmlns:jsp="http://java.sun.com/JSP/Page"
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:tx="http://myfaces.apache.org/tobago/extension"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <tc:page id="page">
+ <tc:gridLayoutConstraint width="600px" height="600px"/>
+ <f:facet name="layout">
+ <tc:gridLayout margin="50"/>
+ </f:facet>
+
+ <tc:image id="id" value="pidgeon-point.jpg"/>
+
+ <tc:script file="script/test-utils.js"/>
+ <tc:script onload="checkLayout('page:id', 50, 50, 500, 500);"/>
+
+ </tc:page>
+</f:view>
Added: myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin.xhtml?rev=937967&view=auto
==============================================================================
--- myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin.xhtml (added)
+++ myfaces/tobago/trunk/example/test/src/main/webapp/tc/gridLayout/margin.xhtml Mon Apr 26 08:55:03 2010
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<f:view
+ xmlns:jsp="http://java.sun.com/JSP/Page"
+ xmlns:tc="http://myfaces.apache.org/tobago/component"
+ xmlns:tx="http://myfaces.apache.org/tobago/extension"
+ xmlns:ui="http://java.sun.com/jsf/facelets"
+ xmlns:f="http://java.sun.com/jsf/core">
+
+ <tc:page id="page">
+ <tc:gridLayoutConstraint width="600px" height="600px"/>
+ <f:facet name="layout">
+ <tc:gridLayout marginLeft="10" marginTop="20px" marginRight="30" marginBottom="40px"/>
+<!--
+ <tc:gridLayout marginLeft="10" marginTop="20px" marginRight="#{10+20}" marginBottom='#{"40px"}'/>
+-->
+ </f:facet>
+
+ <tc:image id="id" value="pidgeon-point.jpg"/>
+
+ <tc:script file="script/test-utils.js"/>
+ <tc:script onload="checkLayout('page:id', 10, 20, 560, 540);"/>
+
+ </tc:page>
+</f:view>
Modified: myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/GridLayoutRule.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/GridLayoutRule.java?rev=937967&r1=937966&r2=937967&view=diff
==============================================================================
--- myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/GridLayoutRule.java (original)
+++ myfaces/tobago/trunk/extension/facelets/src/main/java/org/apache/myfaces/tobago/facelets/GridLayoutRule.java Mon Apr 26 08:55:03 2010
@@ -42,6 +42,21 @@ public class GridLayoutRule extends Meta
if (Attributes.CELLSPACING.equals(name)) {
return new CellspacingMapper(attribute);
}
+ if (Attributes.MARGIN_LEFT.equals(name)) {
+ return new MarginLeftMapper(attribute);
+ }
+ if (Attributes.MARGIN_TOP.equals(name)) {
+ return new MarginTopMapper(attribute);
+ }
+ if (Attributes.MARGIN_RIGHT.equals(name)) {
+ return new MarginRightMapper(attribute);
+ }
+ if (Attributes.MARGIN_BOTTOM.equals(name)) {
+ return new MarginBottomMapper(attribute);
+ }
+ if (Attributes.MARGIN.equals(name)) {
+ return new MarginMapper(attribute);
+ }
}
}
return null;
@@ -85,4 +100,69 @@ public class GridLayoutRule extends Meta
gridLayout.setCellspacing(Measure.parse(attribute.getValue()));
}
}
+
+ static final class MarginLeftMapper extends Metadata {
+ private final TagAttribute attribute;
+
+ MarginLeftMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ UIGridLayout gridLayout = (UIGridLayout) instance;
+ gridLayout.setMarginLeft(Measure.valueOf(attribute.getValue()));
+ }
+ }
+
+ static final class MarginTopMapper extends Metadata {
+ private final TagAttribute attribute;
+
+ MarginTopMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ UIGridLayout gridLayout = (UIGridLayout) instance;
+ gridLayout.setMarginTop(Measure.valueOf(attribute.getValue()));
+ }
+ }
+
+ static final class MarginRightMapper extends Metadata {
+ private final TagAttribute attribute;
+
+ MarginRightMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ UIGridLayout gridLayout = (UIGridLayout) instance;
+ gridLayout.setMarginRight(Measure.valueOf(attribute.getValue()));
+ }
+ }
+
+ static final class MarginBottomMapper extends Metadata {
+ private final TagAttribute attribute;
+
+ MarginBottomMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ UIGridLayout gridLayout = (UIGridLayout) instance;
+ gridLayout.setMarginBottom(Measure.valueOf(attribute.getValue()));
+ }
+ }
+
+ static final class MarginMapper extends Metadata {
+ private final TagAttribute attribute;
+
+ MarginMapper(TagAttribute attribute) {
+ this.attribute = attribute;
+ }
+
+ public void applyMetadata(FaceletContext ctx, Object instance) {
+ UIGridLayout gridLayout = (UIGridLayout) instance;
+ gridLayout.setMargin(Measure.valueOf(attribute.getValue()));
+ }
+ }
}