Author: alexsmirnov
Date: 2009-05-04 20:24:43 -0400 (Mon, 04 May 2009)
New Revision: 14015
Added:
trunk/samples/layout-sample/src/main/webapp/pages/RF-6641.xhtml
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java
Modified:
trunk/samples/layout-sample/src/main/java/org/richfaces/samples/LayoutBean.java
trunk/samples/layout-sample/src/main/webapp/pages/layout.xhtml
trunk/ui/layout/src/main/config/component/layoutPanel.xml
trunk/ui/layout/src/main/java/org/richfaces/component/UILayoutPanel.java
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java
trunk/ui/layout/src/main/java/org/richfaces/taglib/PageTagHandler.java
trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx
trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx
Log:
Start moving layout panels from CSS to style attributes.
Modified: trunk/samples/layout-sample/src/main/java/org/richfaces/samples/LayoutBean.java
===================================================================
---
trunk/samples/layout-sample/src/main/java/org/richfaces/samples/LayoutBean.java 2009-05-04
22:02:51 UTC (rev 14014)
+++
trunk/samples/layout-sample/src/main/java/org/richfaces/samples/LayoutBean.java 2009-05-05
00:24:43 UTC (rev 14015)
@@ -22,7 +22,7 @@
private boolean rendered = true;
- private String width;
+ private float width;
/**
* @return the rendered
@@ -41,14 +41,14 @@
/**
* @return the width
*/
- public String getWidth() {
+ public float getWidth() {
return width;
}
/**
* @param width the width to set
*/
- public void setWidth(String width) {
+ public void setWidth(float width) {
this.width = width;
}
Added: trunk/samples/layout-sample/src/main/webapp/pages/RF-6641.xhtml
===================================================================
--- trunk/samples/layout-sample/src/main/webapp/pages/RF-6641.xhtml
(rev 0)
+++ trunk/samples/layout-sample/src/main/webapp/pages/RF-6641.xhtml 2009-05-05 00:24:43
UTC (rev 14015)
@@ -0,0 +1,40 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:rich="http://richfaces.org/rich"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:c="http://java.sun.com/jsp/jstl/core">
+<body>
+<h:form>
+ <rich:layout>
+ <rich:layoutPanel position="left">
+
+ <rich:layout>
+
+ <rich:layoutPanel position="top">
+ <p>top</p>
+ </rich:layoutPanel>
+ <rich:layoutPanel position="center">
+ <p>center</p>
+ </rich:layoutPanel>
+ <rich:layoutPanel position="left">
+ <p>left</p>
+ </rich:layoutPanel>
+ <rich:layoutPanel position="right">
+ <p>right</p>
+ </rich:layoutPanel>
+ <rich:layoutPanel position="bottom">
+ <p>bottom</p>
+ </rich:layoutPanel>
+ </rich:layout>
+ </rich:layoutPanel>
+
+ <rich:layoutPanel position="center">
+ <p>center-right</p>
+ </rich:layoutPanel>
+ </rich:layout>
+</h:form>
+</body>
+</html>
\ No newline at end of file
Property changes on: trunk/samples/layout-sample/src/main/webapp/pages/RF-6641.xhtml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/samples/layout-sample/src/main/webapp/pages/layout.xhtml
===================================================================
--- trunk/samples/layout-sample/src/main/webapp/pages/layout.xhtml 2009-05-04 22:02:51 UTC
(rev 14014)
+++ trunk/samples/layout-sample/src/main/webapp/pages/layout.xhtml 2009-05-05 00:24:43 UTC
(rev 14015)
@@ -1,10 +1,10 @@
-<layout:page
xmlns="http://www.w3.org/1999/xhtml"
+<rich:page
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
-
xmlns:layout="http://richfaces.org/layout"
xmlns:c="http://java.sun.com/jsp/jstl/core"
+
xmlns:rich="http://richfaces.org/rich"
markupposition="xhtml"
contentposition="text/html"
theme="#{bean.theme}"
@@ -19,7 +19,8 @@
<f:facet name="pageHeader">
<style>
- .yui-u {text-align: center;}
+ .layout {text-align: center;border-width: 1px;border-color: red;border-style: solid;}
+ .layoutPanel {text-align: center;border-width: 1px;border-color: blue;margin:
0px;border-style: dotted;}
</style>
</f:facet>
<f:facet name="header">
@@ -53,12 +54,29 @@
<!-- body of the page -->
- <layout:layout>
- <layout:layoutPanel position="center">Center
panel</layout:layoutPanel>
- <layout:layoutPanel position="left">Left</layout:layoutPanel>
- <layout:layoutPanel
position="right">Right</layout:layoutPanel>
- <layout:layoutPanel position="top">Top</layout:layoutPanel>
- <layout:layoutPanel
position="bottom">Bottom</layout:layoutPanel>
- </layout:layout>
+ <div class="layout" style="zoom: 1">
+ <div class="layoutPanel top" style="">Top</div>
+ <div class="layoutPanel left" style="float: left; width:
38%">Left
+ panel xxxx yyy zzz</div>
+ <div class="layoutPanel center" style="float: left; width:
35%">
+ <div class="layout" style="zoom: 1">
+ <div class="layoutPanel top" style="">Top</div>
+ <div class="layoutPanel left" style="float: left; width:
38%">Left
+ panel xxxx yyy zzz</div>
+ <div class="layoutPanel center" style="float: left; width:
35%">Center
+ panel dhisdf ncdl dcd</div>
+ <div class="layoutPanel right" style="float: right; width:
25%">Right
+ wersdupsdo; osajo;sca</div>
+ <div
+ style="display: block; height: 0; clear: both; visibility:
hidden;">.</div>
+ <div class="layoutPanel bottom" style="">Bottom</div>
+ </div>
+ </div>
+ <div class="layoutPanel right" style="float: right; width:
25%">Right
+ wersdupsdo; osajo;sca</div>
+ <div
+ style="display: block; height: 0; clear: both; visibility:
hidden;">.</div>
+ <div class="layoutPanel bottom" style="">Bottom</div>
+ </div>
-</layout:page>
\ No newline at end of file
+</rich:page>
\ No newline at end of file
Modified: trunk/ui/layout/src/main/config/component/layoutPanel.xml
===================================================================
--- trunk/ui/layout/src/main/config/component/layoutPanel.xml 2009-05-04 22:02:51 UTC (rev
14014)
+++ trunk/ui/layout/src/main/config/component/layoutPanel.xml 2009-05-05 00:24:43 UTC (rev
14015)
@@ -38,7 +38,7 @@
<property>
<name>width</name>
- <classname>java.lang.String</classname>
+ <classname>float</classname>
<description>Sets the width of the layout area
</description>
</property>
Modified: trunk/ui/layout/src/main/java/org/richfaces/component/UILayoutPanel.java
===================================================================
--- trunk/ui/layout/src/main/java/org/richfaces/component/UILayoutPanel.java 2009-05-04
22:02:51 UTC (rev 14014)
+++ trunk/ui/layout/src/main/java/org/richfaces/component/UILayoutPanel.java 2009-05-05
00:24:43 UTC (rev 14015)
@@ -33,13 +33,13 @@
* Get Panel width.
* @return
*/
- public abstract String getWidth();
+ public abstract float getWidth();
/**
* Set Panel width.
* @param newvalue
*/
- public abstract void setWidth(String newvalue);
+ public abstract void setWidth(float newvalue);
}
Added:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java
===================================================================
---
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java
(rev 0)
+++
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java 2009-05-05
00:24:43 UTC (rev 14015)
@@ -0,0 +1,66 @@
+/**
+ *
+ */
+package org.richfaces.renderkit;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.LayoutPosition;
+import org.richfaces.component.UILayout;
+import org.richfaces.component.UILayoutPanel;
+
+/**
+ * @author asmirnov
+ *
+ */
+public abstract class AbstractLayoutPanelRenderer extends
+ HeaderResourcesRendererBase {
+
+ public String layoutStyle(FacesContext context, UILayoutPanel panel) {
+ StringBuilder style = new StringBuilder();
+ LayoutPosition position = panel.getPosition();
+ Object componentStyle = panel.getAttributes().get(HTML.style_ATTRIBUTE);
+ if(null != componentStyle){
+ style.append(componentStyle).append(";");
+ }
+ if(!LayoutPosition.top.equals(position)&&!LayoutPosition.bottom.equals(position)){
+ if(LayoutPosition.right.equals(position)){
+ style.append("float:right;");
+ } else {
+ style.append("float:left;");
+ }
+ // find siblings.
+ // get layout depth.
+ int deep = layoutDeep(panel);
+ // calculate real width.
+ float width = panel.getWidth();
+ if(width>=0.0f){
+ style.append("width:").append(width).append("%;");
+ width = width/(1.0f+(float)deep);
+ style.append("*width:").append(width).append("%;");
+ }
+ } else {
+ // top and buttom style.
+ }
+ return style.length()>0?style.toString():null;
+ }
+
+ /**
+ * Calculate deep of layout components.
+ * @param component
+ * @return
+ */
+ private int layoutDeep(UIComponent component) {
+ int deep = 0;
+ if(null != component){
+ deep = layoutDeep(component.getParent());
+ if(component instanceof UILayout){
+ deep++;
+ }
+ }
+ return deep;
+ }
+}
Property changes on:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java
===================================================================
---
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java 2009-05-04
22:02:51 UTC (rev 14014)
+++
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java 2009-05-05
00:24:43 UTC (rev 14015)
@@ -4,6 +4,7 @@
package org.richfaces.renderkit;
import java.io.IOException;
+import java.util.Map;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
@@ -86,90 +87,23 @@
}
if (columns > 0) {
// Reorder panels to fill ordeg left->center->right.
- if (null == left) {
- if (null == center) {
- left = right;
- right = null;
- } else {
- left = center;
- center = right;
- right = null;
- }
- } else if (null == center) {
- center = right;
- right = null;
- }
- if (columns > 1) {
- // Render Y! CSS Grid
- writer.startElement(HTML.DIV_ELEM, layout);
- // calculate class.
- String yahooClass = calculateLayoutClass(left, right, center);
- writer.writeAttribute(HTML.class_ATTRIBUTE, yahooClass, null);
- left.getAttributes().put("first", "first");
- center.getAttributes().remove("first");
+ if (null != left) {
left.encodeAll(context);
+ }
+ if (null != center) {
center.encodeAll(context);
- if (null != right) {
- right.getAttributes().remove("first");
- right.encodeAll(context);
- }
- writer.endElement(HTML.DIV_ELEM);
- } else {
- left.encodeAll(context);
- }
+ }
+ if (null != right) {
+ right.encodeAll(context);
+ }
}
+ // line separator.
+ writer.startElement(HTML.DIV_ELEM, layout);
+ writer.writeAttribute(HTML.style_ATTRIBUTE, "display: block; height: 0; clear:
both; visibility: hidden;", null);
+ writer.writeText(".", null);
+ writer.endElement(HTML.DIV_ELEM);
if (null != bottom) {
renderChild(context, bottom);
}
}
-
- /**
- * @param left
- * @param right
- * @param center
- * @return
- */
- protected String calculateLayoutClass(UILayoutPanel left,
- UILayoutPanel right, UILayoutPanel center) {
- String yahooClass = "yui-g";
- if (null != left && null != right && null != center) {
- // We have only equal size for an three-column layout.
- yahooClass = "yui-gb";
- } else if(null != left && null != center){
- int leftPart = 0;
- String leftWidth = left.getWidth();
- if(!isEmpty(leftWidth)){
- leftPart = Integer.parseInt(leftWidth);
- }
- int rightPart = 0;
- String centerWidth = center.getWidth();
- if(!isEmpty(centerWidth)){
- rightPart = Integer.parseInt(centerWidth);
- if(0 ==leftPart && 0>rightPart &&
centerWidth.endsWith("%")){
- leftPart = 100 - rightPart;
- }
- }
- if(0 > leftPart && 0 == rightPart &&
leftWidth.endsWith("%")){
- rightPart = 100 - leftPart;
- }
- // Calculate properly class.
- if(0>leftPart && 0>rightPart){
- double ratio = (double)leftPart/(double)(leftPart+rightPart);
- if (ratio <= 0.25) {
- yahooClass = "yui-gf";
- } else if (ratio <= 0.33) {
- yahooClass = "yui-gd";
- } else if (ratio <= 0.66) {
- yahooClass = "yui-gc";
- } else {
- yahooClass = "yui-ge";
- }
- }
- }
- return yahooClass;
- }
-
- private boolean isEmpty(String leftWidth) {
- return null == leftWidth || leftWidth.length() == 0;
- }
}
Modified: trunk/ui/layout/src/main/java/org/richfaces/taglib/PageTagHandler.java
===================================================================
--- trunk/ui/layout/src/main/java/org/richfaces/taglib/PageTagHandler.java 2009-05-04
22:02:51 UTC (rev 14014)
+++ trunk/ui/layout/src/main/java/org/richfaces/taglib/PageTagHandler.java 2009-05-05
00:24:43 UTC (rev 14015)
@@ -45,10 +45,12 @@
if (this.contentType != null) {
String v = this.contentType.getValue(ctx);
ctx.getFacesContext().getExternalContext().getRequestMap().put("facelets.ContentType",
v);
+ root.getAttributes().put("contentType", v);
}
if (this.encoding != null) {
String v = this.encoding.getValue(ctx);
ctx.getFacesContext().getExternalContext().getRequestMap().put("facelets.Encoding",
v);
+ root.getAttributes().put("encoding", v);
}
}
}
Modified: trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx
===================================================================
--- trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx 2009-05-04 22:02:51
UTC (rev 14014)
+++ trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx 2009-05-05 00:24:43
UTC (rev 14015)
@@ -11,11 +11,11 @@
baseclass="org.richfaces.renderkit.AbstractLayoutRenderer"
component="org.richfaces.component.UILayout"
- <h:styles>css/layout.css</h:styles>
+ <!-- h:styles>css/layout.css</h:styles-->
<f:clientid var="clientId"/>
<div id="#{clientId}"
- x:passThruWithExclusions="value,name,type,id"
- >
+ style="#{component.attributes['style']};zoom:1;"
+ x:passThruWithExclusions="value,name,type,id,style" >
<vcp:body>
<f:call name="renderLayout" />
</vcp:body>
Modified: trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx
===================================================================
--- trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx 2009-05-04
22:02:51 UTC (rev 14014)
+++ trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx 2009-05-05
00:24:43 UTC (rev 14015)
@@ -8,13 +8,12 @@
xmlns:vcp="
http://jsf.exadel.com/vcp"
xmlns:x="
http://ajax4jsf.org/cdk/x"
class="org.richfaces.renderkit.html.LayoutPanelRenderer"
- baseclass="org.ajax4jsf.renderkit.AjaxComponentRendererBase"
+ baseclass="org.richfaces.renderkit.AbstractLayoutPanelRenderer"
component="org.richfaces.component.UILayoutPanel"
<f:clientid var="clientId"/>
- <c:set var="styleClass"
value="#{component.attributes['styleClass']}"/>
- <div id="#{clientId}" class="yui-u
#{component.attributes['first']} #{styleClass}"
- x:passThruWithExclusions="type,id, styleClass"
+ <div id="#{clientId}"
x:style="#{this:layoutStyle(context,component)}"
+ x:passThruWithExclusions="type,id,style"
<vcp:body>
<f:call name="renderChildren" />