Author: alexsmirnov
Date: 2009-05-05 18:28:33 -0400 (Tue, 05 May 2009)
New Revision: 14025
Added:
trunk/ui/layout/src/main/java/org/richfaces/component/LayoutStructure.java
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutPanelRenderer.java
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutRenderer.java
trunk/ui/layout/src/test/java/org/richfaces/component/
trunk/ui/layout/src/test/java/org/richfaces/component/LayoutStructureTest.java
Removed:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java
trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx
trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx
Modified:
trunk/samples/layout-sample/src/main/java/org/richfaces/samples/LayoutBean.java
trunk/samples/layout-sample/src/main/webapp/pages/index.xhtml
trunk/samples/themes/src/main/templates/org/richfaces/oldschool.jspx
trunk/samples/themes/src/main/templates/org/richfaces/smooth.jspx
trunk/ui/layout/src/main/config/component/layout.xml
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/resources/org/richfaces/renderkit/html/css/simple.xcss
Log:
https://jira.jboss.org/jira/browse/RF-6602
https://jira.jboss.org/jira/browse/RF-6629
https://jira.jboss.org/jira/browse/RF-6713
https://jira.jboss.org/jira/browse/RF-6641
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-05
17:33:02 UTC (rev 14024)
+++
trunk/samples/layout-sample/src/main/java/org/richfaces/samples/LayoutBean.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -22,7 +22,7 @@
private boolean rendered = true;
- private float width;
+ private String width;
/**
* @return the rendered
@@ -41,14 +41,14 @@
/**
* @return the width
*/
- public float getWidth() {
+ public String getWidth() {
return width;
}
/**
* @param width the width to set
*/
- public void setWidth(float width) {
+ public void setWidth(String width) {
this.width = width;
}
Modified: trunk/samples/layout-sample/src/main/webapp/pages/index.xhtml
===================================================================
(Binary files differ)
Modified: trunk/samples/themes/src/main/templates/org/richfaces/oldschool.jspx
===================================================================
--- trunk/samples/themes/src/main/templates/org/richfaces/oldschool.jspx 2009-05-05
17:33:02 UTC (rev 14024)
+++ trunk/samples/themes/src/main/templates/org/richfaces/oldschool.jspx 2009-05-05
22:28:33 UTC (rev 14025)
@@ -15,7 +15,6 @@
<c:set var="namespace"
value="#{this:prolog(context,component)}"/>
<html x:xmlns="#{namespace}"
x:lang="#{context.viewRoot.locale}">
<head>
-<meta http-equiv="content-type" content="text/html; charset=utf-8"
/>
<title>#{component.attributes['pageTitle']}</title>
<f:call name="themeStyle"/>
<f:call name="themeScript"/>
@@ -36,10 +35,11 @@
</head>
<body x:passThruWithExclusions="value,name,type,id">
- <table border="0" cellpadding="0" cellspacing="0"
class="rich-page">
+ <table border="0" cellpadding="0" cellspacing="0"
class="rich-page #{component.attributes['pageClass']}">
+ <tbody>
<tr>
<td class="header_bg">
- <div class="header_content">
+ <div class="header_content rich-page-header
#{component.attributes['headerClass']}">
<!-- begin header -->
<u:insertFacet name="header"/>
<!-- end header -->
@@ -48,15 +48,16 @@
</tr>
<tr>
<td width="100%" height="100%"
class="bg_tabbody">
- <table cellpadding="0" cellspacing="0" border="0"
width="100%" height="100%">
+ <table cellpadding="0" cellspacing="0" border="0"
width="100%" height="100%" class="rich-page-content
#{component.attributes['contentClass']}">
+ <tbody>
<tr>
- <td class="menu_col">
+ <td class="menu_col rich-page-sidebar
#{component.attributes['sidebarClass']}">
<div class="menu_width spacer"
style="width:#{component.attributes['sidebarWidth']}px"></div>
<!-- begin menu -->
<u:insertFacet name="sidebar"/>
<!-- end meny -->
</td>
- <td class="content_col">
+ <td class="content_col rich-page-body
#{component.attributes['bodyClass']}">
<!-- begin content -->
<vcp:body>
<f:call name="renderChildren" />
@@ -64,18 +65,20 @@
<!-- end content -->
</td>
</tr>
+ </tbody>
</table>
</td>
</tr>
<tr>
<td class="footer_bg">
- <div class="footer_bg_content">
+ <div class="footer_bg_content rich-page-footer
#{component.attributes['footerClass']}">
<!-- begin footer -->
<u:insertFacet name="footer"/>
<!-- end footer -->
</div>
</td>
</tr>
+ </tbody>
</table>
</body>
</html>
Modified: trunk/samples/themes/src/main/templates/org/richfaces/smooth.jspx
===================================================================
--- trunk/samples/themes/src/main/templates/org/richfaces/smooth.jspx 2009-05-05 17:33:02
UTC (rev 14024)
+++ trunk/samples/themes/src/main/templates/org/richfaces/smooth.jspx 2009-05-05 22:28:33
UTC (rev 14025)
@@ -35,21 +35,24 @@
</head>
<body x:passThruWithExclusions="value,name,type,id">
-<table class="rich-page" border="0" cellpadding="0"
cellspacing="0">
+<table class="rich-page #{component.attributes['pageClass']}"
border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" class="common_box">
<table height="100%" cellpadding="0" cellspacing="0"
class="page_size">
+ <thead>
<tr>
- <td colspan="3" class="header_bg_left">
+ <th colspan="3" class="header_bg_left">
<div class="header_bg_right">
<!-- div class="spacer" style="height : 15px"></div
-->
- <div class="header_content">
+ <div class="header_content rich-page-header
#{component.attributes['headerClass']}">
<u:insertFacet name="header"/>
</div>
</div>
- </td>
+ </th>
</tr>
+ </thead>
+ <tbody>
<tr>
<td class="left_col">
<div class="left_strut">
@@ -57,18 +60,20 @@
</div>
</td>
<td width="100%" height="100%"
class="bg_tabbody">
- <table class="content_body" cellpadding="0"
cellspacing="0" width="100%" height="100%">
+ <table class="content_body rich-page-content
#{component.attributes['contentClass']}" cellpadding="0"
cellspacing="0" width="100%" height="100%">
+ <tbody>
<tr>
- <td class="menu_col">
+ <td class="menu_col rich-page-sidebar
#{component.attributes['sidebarClass']}">
<div class="spacer"
style="width:#{component.attributes['sidebarWidth']}px"></div>
<u:insertFacet name="sidebar"/>
</td>
- <td class="content_col">
+ <td class="content_col rich-page-body
#{component.attributes['bodyClass']}">
<vcp:body>
<f:call name="renderChildren" />
</vcp:body>
</td>
</tr>
+ </tbody>
</table>
</td>
<td class="right_col">
@@ -80,13 +85,14 @@
<tr>
<td colspan="3" class="footer_bg_left">
<div class="footer_bg_right">
- <div class="footer_bg_content">
+ <div class="footer_bg_content rich-page-footer
#{component.attributes['footerClass']}">
<u:insertFacet name="footer"/>
</div>
</div>
</td>
</tr>
+ </tbody>
</table>
</td>
Modified: trunk/ui/layout/src/main/config/component/layout.xml
===================================================================
--- trunk/ui/layout/src/main/config/component/layout.xml 2009-05-05 17:33:02 UTC (rev
14024)
+++ trunk/ui/layout/src/main/config/component/layout.xml 2009-05-05 22:28:33 UTC (rev
14025)
@@ -11,9 +11,9 @@
<![CDATA[
]]>
</description>
- <renderer generate="true" override="true">
+ <renderer generate="false" override="true">
<name>org.richfaces.LayoutRenderer</name>
- <template>org/richfaces/htmlLayout.jspx</template>
+ <classname>org.richfaces.renderkit.html.LayoutRenderer</classname>
</renderer>
<tag>
<name>layout</name>
Modified: trunk/ui/layout/src/main/config/component/layoutPanel.xml
===================================================================
--- trunk/ui/layout/src/main/config/component/layoutPanel.xml 2009-05-05 17:33:02 UTC (rev
14024)
+++ trunk/ui/layout/src/main/config/component/layoutPanel.xml 2009-05-05 22:28:33 UTC (rev
14025)
@@ -11,9 +11,9 @@
<![CDATA[
]]>
</description>
- <renderer generate="true" override="true">
+ <renderer generate="false" override="true">
<name>org.richfaces.LayoutPanelRenderer</name>
- <template>org/richfaces/htmlLayoutPanel.jspx</template>
+ <classname>org.richfaces.renderkit.html.LayoutPanelRenderer</classname>
</renderer>
<tag>
<name>layoutPanel</name>
@@ -38,7 +38,7 @@
<property>
<name>width</name>
- <classname>float</classname>
+ <classname>java.lang.String</classname>
<description>Sets the width of the layout area
</description>
</property>
Added: trunk/ui/layout/src/main/java/org/richfaces/component/LayoutStructure.java
===================================================================
--- trunk/ui/layout/src/main/java/org/richfaces/component/LayoutStructure.java
(rev 0)
+++ trunk/ui/layout/src/main/java/org/richfaces/component/LayoutStructure.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -0,0 +1,291 @@
+/**
+ *
+ */
+package org.richfaces.component;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class LayoutStructure implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5700775901583881224L;
+
+ private UILayoutPanel top = null;
+ private UILayoutPanel bottom = null;
+ private UILayoutPanel left = null;
+ private UILayoutPanel right = null;
+ private UILayoutPanel center = null;
+ private int deep = 0;
+ private List<Column> columns;
+
+ public LayoutStructure(UILayout layout) {
+ sortPanels(layout);
+ }
+
+ public LayoutStructure(UILayoutPanel panel){
+ UIComponent parent = panel.getParent();
+ if (parent instanceof UILayout) {
+ UILayout layout = (UILayout) parent;
+ sortPanels(layout);
+ } else {
+ throw new FacesException("Layout panel should be children of UILayout
pomponent");
+ }
+ }
+
+ /**
+ * @param layout
+ * @throws FacesException
+ */
+ public void sortPanels(UILayout layout) throws FacesException {
+ this.deep = layoutDeep(layout);
+ for (UIComponent child : layout.getChildren()) {
+ if (child instanceof UILayoutPanel && child.isRendered()) {
+ UILayoutPanel layoutPanel = (UILayoutPanel) child;
+ LayoutPosition position = layoutPanel.getPosition();
+ if (LayoutPosition.top.equals(position)) {
+ if (null != top) {
+ throw new FacesException(
+ "Duplicate layoutPanel's with same position"
+ + position);
+ }
+ top = layoutPanel;
+ } else if (LayoutPosition.bottom.equals(position)) {
+ if (null != bottom) {
+ throw new FacesException(
+ "Duplicate layoutPanel's with same position"
+ + position);
+ }
+ bottom = layoutPanel;
+ } else if (LayoutPosition.left.equals(position)) {
+ if (null != left) {
+ throw new FacesException(
+ "Duplicate layoutPanel's with same position"
+ + position);
+ }
+ left = layoutPanel;
+ } else if (LayoutPosition.right.equals(position)) {
+ if (null != right) {
+ throw new FacesException(
+ "Duplicate layoutPanel's with same position"
+ + position);
+ }
+ right = layoutPanel;
+ } else if (null == position
+ || LayoutPosition.center.equals(position)) {
+ if (null != center) {
+ throw new FacesException(
+ "Duplicate layoutPanel's with same position"
+ + position);
+ }
+ center = layoutPanel;
+ } else {
+
+ }
+ }
+
+ }
+ // Reorganise central row.
+ if(null == left && null != center){
+ left = center;
+ center = null;
+ }
+ if(null == left && null != right){
+ left = right;
+ right = null;
+ }
+ if(null == center && null != right){
+ center = right;
+ right = null;
+ }
+ this.columns = new ArrayList<Column>(3);
+ if(null != left){
+ columns.add(new Column(left));
+ }
+ if(null != center){
+ columns.add(new Column(center));
+ }
+ if(null != right){
+ columns.add(new Column(right));
+ }
+ }
+
+ /**
+ * @throws NumberFormatException
+ */
+ public void calculateWidth() throws NumberFormatException {
+ // calculate widths.
+ if(getColumns()>0){
+ float totalPercent = 0.0f;
+ int numOfPercentColumns = 0;
+ float totalPart = 0.0f;
+ int numOfPartColumns = 0;
+ // Collect width information.
+ for (Column column : columns) {
+ String width = column.panel.getWidth();
+ if(null == width || 0 ==width.length()){
+ column.partWidth = 1.0f;
+ totalPart += column.partWidth;
+ numOfPartColumns++;
+ } else if(width.startsWith("*")){
+ column.partWidth = Float.parseFloat(width.substring(1));
+ totalPart += column.partWidth;
+ numOfPartColumns++;
+ } else if(width.endsWith("%")) {
+ column.percentWidth = Float.parseFloat(width.substring(0,width.length()-1));
+ totalPercent += column.percentWidth;
+ numOfPercentColumns++;
+ }
+ }
+ float partToPercent=0.0f;
+ float percentCoefficient = 1.0f;
+ if(numOfPartColumns>0 && numOfPercentColumns >0){
+ float rest = 100.00f - totalPercent;
+ partToPercent = rest/totalPart;
+ } else if(numOfPartColumns>0){
+ partToPercent = 100.00f/totalPart;
+ } else if(numOfPercentColumns == columns.size()){
+ percentCoefficient = 100.00f/totalPercent;
+ }
+ // TODO - calculate precisious coefficient.
+ percentCoefficient*=0.98f;
+ // Recalculate width.
+ for (Column column : columns) {
+ if(column.partWidth>0.0f){
+ column.percentWidth = column.partWidth*partToPercent;
+ }
+ column.percentWidth = column.percentWidth*percentCoefficient;
+ }
+ }
+ }
+
+ /**
+ * @return the top
+ */
+ public UILayoutPanel getTop() {
+ return top;
+ }
+
+ /**
+ * @return the bottom
+ */
+ public UILayoutPanel getBottom() {
+ return bottom;
+ }
+
+ /**
+ * @return the left
+ */
+ public UILayoutPanel getLeft() {
+ return left;
+ }
+
+ /**
+ * @return the right
+ */
+ public UILayoutPanel getRight() {
+ return right;
+ }
+
+ /**
+ * @return the center
+ */
+ public UILayoutPanel getCenter() {
+ return center;
+ }
+
+ /**
+ * @return the columns
+ */
+ public int getColumns() {
+ return columns.size();
+ }
+
+ /**
+ */
+ public String getWidth(UILayoutPanel panel){
+ return getWidth(panel,1.0f);
+ }
+
+ /**
+ * @param panel
+ * @param coeeficient
+ * @return
+ */
+ public String getWidth(UILayoutPanel panel, float coeeficient){
+ if(this.top == panel || this.bottom == panel){
+ return panel.getWidth();
+ } else {
+ for (Column column : columns) {
+ if(column.panel == panel){
+ if(column.percentWidth>0){
+ return String.format((Locale)null, "%2.2f%%",
column.percentWidth*coeeficient);
+ } else {
+ return panel.getWidth();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Calculate deep of layout components.
+ * @param component
+ * @return
+ */
+ protected int layoutDeep(UIComponent component) {
+ int deep = 0;
+ if(null != component){
+ deep = layoutDeep(component.getParent());
+ if(component instanceof UILayout){
+ deep++;
+ }
+ }
+ return deep;
+ }
+
+
+ static class Column {
+ private final UILayoutPanel panel;
+ private float percentWidth = 0.0f;
+ private float partWidth = 0.0f;
+
+ public Column(UILayoutPanel panel) {
+ this.panel = panel;
+ }
+
+ public String getWidth(){
+ if(percentWidth>0.0f){
+ return String.format((Locale)null, "%2.2f%%", percentWidth);
+ } else {
+ return panel.getWidth();
+ }
+ }
+
+ /**
+ * @return the percentWidth
+ */
+ public float getPercentWidth() {
+ return percentWidth;
+ }
+ }
+
+
+ /**
+ * @return the deep
+ */
+ public int getDeep() {
+ return deep;
+ }
+}
Property changes on:
trunk/ui/layout/src/main/java/org/richfaces/component/LayoutStructure.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-05
17:33:02 UTC (rev 14024)
+++ trunk/ui/layout/src/main/java/org/richfaces/component/UILayoutPanel.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -33,13 +33,13 @@
* Get Panel width.
* @return
*/
- public abstract float getWidth();
+ public abstract String getWidth();
/**
* Set Panel width.
* @param newvalue
*/
- public abstract void setWidth(float newvalue);
+ public abstract void setWidth(String newvalue);
}
Deleted:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java
===================================================================
---
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java 2009-05-05
17:33:02 UTC (rev 14024)
+++
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -1,66 +0,0 @@
-/**
- *
- */
-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;
- }
-}
Deleted:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java
===================================================================
---
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java 2009-05-05
17:33:02 UTC (rev 14024)
+++
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -1,109 +0,0 @@
-/**
- *
- */
-package org.richfaces.renderkit;
-
-import java.io.IOException;
-import java.util.Map;
-
-import javax.faces.FacesException;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-
-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 AbstractLayoutRenderer extends
- HeaderResourcesRendererBase {
-
- public void renderLayout(FacesContext context, UILayout layout)
- throws IOException {
- // Detect layout content;
- UILayoutPanel top = null;
- UILayoutPanel bottom = null;
- UILayoutPanel left = null;
- UILayoutPanel right = null;
- UILayoutPanel center = null;
- int columns = 0;
- for (UIComponent child : layout.getChildren()) {
- if (child instanceof UILayoutPanel && child.isRendered()) {
- UILayoutPanel layoutPanel = (UILayoutPanel) child;
- LayoutPosition position = layoutPanel.getPosition();
- if (LayoutPosition.top.equals(position)) {
- if (null != top) {
- throw new FacesException(
- "Duplicate layoutPanel's with same position"
- + position);
- }
- top = layoutPanel;
- } else if (LayoutPosition.bottom.equals(position)) {
- if (null != bottom) {
- throw new FacesException(
- "Duplicate layoutPanel's with same position"
- + position);
- }
- bottom = layoutPanel;
- } else if (LayoutPosition.left.equals(position)) {
- if (null != left) {
- throw new FacesException(
- "Duplicate layoutPanel's with same position"
- + position);
- }
- left = layoutPanel;
- columns++;
- } else if (LayoutPosition.right.equals(position)) {
- if (null != right) {
- throw new FacesException(
- "Duplicate layoutPanel's with same position"
- + position);
- }
- right = layoutPanel;
- columns++;
- } else if (null == position
- || LayoutPosition.center.equals(position)) {
- if (null != center) {
- throw new FacesException(
- "Duplicate layoutPanel's with same position"
- + position);
- }
- center = layoutPanel;
- columns++;
- } else {
-
- }
- }
- }
- ResponseWriter writer = context.getResponseWriter();
- if (null != top) {
- top.encodeAll(context);
- }
- if (columns > 0) {
- // Reorder panels to fill ordeg left->center->right.
- if (null != left) {
- left.encodeAll(context);
- }
- if (null != center) {
- center.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);
- }
- }
-}
Copied:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutPanelRenderer.java (from
rev 14023,
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutPanelRenderer.java)
===================================================================
--- trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutPanelRenderer.java
(rev 0)
+++
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutPanelRenderer.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -0,0 +1,91 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.LayoutPosition;
+import org.richfaces.component.LayoutStructure;
+import org.richfaces.component.UILayout;
+import org.richfaces.component.UILayoutPanel;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class LayoutPanelRenderer extends RendererBase {
+ private static final Object[] LAYOUT_EXCLUSIONS = { HTML.id_ATTRIBUTE,
+ HTML.style_ATTRIBUTE };
+
+ @Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context,
+ UIComponent component) throws IOException {
+ writer.startElement(HTML.DIV_ELEM, component);
+ getUtils().encodeCustomId(context, component);
+ getUtils().encodePassThruWithExclusionsArray(context, component,
+ LAYOUT_EXCLUSIONS);
+ String layoutStyle = layoutStyle(context, (UILayoutPanel) component);
+ if (null != layoutStyle) {
+ writer.writeAttribute(HTML.style_ATTRIBUTE, layoutStyle, "style");
+
+ }
+ }
+
+ public String layoutStyle(FacesContext context, UILayoutPanel panel) {
+ StringBuilder style = new StringBuilder();
+ LayoutPosition position = panel.getPosition();
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ Object parentLayout = requestMap.get(LayoutRenderer.LAYOUT_STRUCTURE_ATTRIBUTE);
+ LayoutStructure structure;
+ if (null != parentLayout && parentLayout instanceof LayoutStructure) {
+ structure = (LayoutStructure) parentLayout;
+ } else {
+ structure = new LayoutStructure(panel);
+ structure.calculateWidth();
+ }
+ 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;");
+ }
+ // calculate real width.
+ float coef = 1.0f-((float)structure.getDeep()/100.00f);
+ String width = structure.getWidth(panel,coef);
+ if(null != width){
+ style.append("width:").append(width).append(";");
+ coef = coef*0.95f;
+ width = structure.getWidth(panel,coef);;
+ style.append("*width:").append(width).append(";");
+ }
+ } else {
+ // top and buttom style.
+ }
+ return style.length() > 0 ? style.toString() : null;
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
+ UIComponent component) throws IOException {
+ writer.endElement(HTML.DIV_ELEM);
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UILayoutPanel.class;
+ }
+}
Property changes on:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutPanelRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutRenderer.java
(from rev 14023,
trunk/ui/layout/src/main/java/org/richfaces/renderkit/AbstractLayoutRenderer.java)
===================================================================
--- trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutRenderer.java
(rev 0)
+++
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutRenderer.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -0,0 +1,97 @@
+/**
+ *
+ */
+package org.richfaces.renderkit.html;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
+import org.richfaces.component.LayoutPosition;
+import org.richfaces.component.LayoutStructure;
+import org.richfaces.component.UILayout;
+import org.richfaces.component.UILayoutPanel;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class LayoutRenderer extends
+ RendererBase {
+
+ public static final String LAYOUT_STRUCTURE_ATTRIBUTE =
UILayout.class.getName()+".structure";
+ private static final Object[] LAYOUT_EXCLUSIONS =
{HTML.id_ATTRIBUTE,HTML.style_ATTRIBUTE};
+ @Override
+ protected void doEncodeBegin(ResponseWriter writer, FacesContext context,
+ UIComponent component) throws IOException {
+ writer.startElement(HTML.DIV_ELEM, component);
+ getUtils().encodeCustomId(context, component);
+ getUtils().encodePassThruWithExclusionsArray(context, component, LAYOUT_EXCLUSIONS);
+ Object style = component.getAttributes().get("style");
+ writer.writeAttribute(HTML.style_ATTRIBUTE,null==style?"":(style.toString()+";")+"zoom:1;","style");
+ }
+
+
+ @Override
+ protected void doEncodeChildren(ResponseWriter writer,
+ FacesContext context, UIComponent component) throws IOException {
+ renderLayout(writer,context, (UILayout) component);
+ }
+
+ public void renderLayout(ResponseWriter writer,FacesContext context, UILayout layout)
+ throws IOException {
+ LayoutStructure structure = new LayoutStructure(layout);
+ structure.calculateWidth();
+ Map<String, Object> requestMap = context.getExternalContext().getRequestMap();
+ Object oldLayout = requestMap.get(LAYOUT_STRUCTURE_ATTRIBUTE);
+ requestMap.put(LAYOUT_STRUCTURE_ATTRIBUTE, structure);
+ // Detect layout content;
+ if (null != structure.getTop()) {
+ structure.getTop().encodeAll(context);
+ }
+ if (structure.getColumns() > 0) {
+ // Reorder panels to fill ordeg left->center->right.
+ if (null != structure.getLeft()) {
+ structure.getLeft().encodeAll(context);
+ }
+ if (null != structure.getCenter()) {
+ structure.getCenter().encodeAll(context);
+ }
+ if (null != structure.getRight()) {
+ structure.getRight().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 != structure.getBottom()) {
+ renderChild(context, structure.getBottom());
+ }
+ requestMap.put(LAYOUT_STRUCTURE_ATTRIBUTE, oldLayout);
+ }
+
+ @Override
+ protected void doEncodeEnd(ResponseWriter writer, FacesContext context,
+ UIComponent component) throws IOException {
+ writer.endElement(HTML.DIV_ELEM);
+ }
+
+ @Override
+ public boolean getRendersChildren() {
+ return true;
+ }
+
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UILayout.class;
+ }
+}
Property changes on:
trunk/ui/layout/src/main/java/org/richfaces/renderkit/html/LayoutRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/ui/layout/src/main/resources/org/richfaces/renderkit/html/css/simple.xcss
===================================================================
---
trunk/ui/layout/src/main/resources/org/richfaces/renderkit/html/css/simple.xcss 2009-05-05
17:33:02 UTC (rev 14024)
+++
trunk/ui/layout/src/main/resources/org/richfaces/renderkit/html/css/simple.xcss 2009-05-05
22:28:33 UTC (rev 14025)
@@ -34,6 +34,13 @@
<u:style name="padding" value="0 20px" />
<u:style name="color" skin="trimColor" />
</u:selector>
+ <u:selector name=".rich-page-subheader">
+ <u:style name="border-bottom" value="1px solid" />
+ <u:style name="border-bottom-color"
skin="generalBackgroundColor" />
+ <u:style name="background-color"
skin="headerGradientColor"/>
+ <u:style name="padding" value="0 20px" />
+ <u:style name="color" skin="trimColor" />
+ </u:selector>
<u:selector name=".rich-page-content">
<!-- u:style name="background-image">
Deleted: trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx
===================================================================
--- trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx 2009-05-05 17:33:02
UTC (rev 14024)
+++ trunk/ui/layout/src/main/templates/org/richfaces/htmlLayout.jspx 2009-05-05 22:28:33
UTC (rev 14025)
@@ -1,24 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<f:root
-
xmlns:f="http://ajax4jsf.org/cdk/template"
- xmlns:c="
http://java.sun.com/jsf/core"
- xmlns:ui="
http://ajax4jsf.org/cdk/ui"
- xmlns:u="
http://ajax4jsf.org/cdk/u"
- xmlns:x="
http://ajax4jsf.org/cdk/x"
-
xmlns:h="http://jsf.exadel.com/header"
-
xmlns:vcp="http://ajax4jsf.org/cdk/vcp"
- class="org.richfaces.renderkit.html.LayoutRenderer"
- baseclass="org.richfaces.renderkit.AbstractLayoutRenderer"
- component="org.richfaces.component.UILayout"
- >
- <!-- h:styles>css/layout.css</h:styles-->
- <f:clientid var="clientId"/>
- <div id="#{clientId}"
- style="#{component.attributes['style']};zoom:1;"
- x:passThruWithExclusions="value,name,type,id,style" >
- <vcp:body>
- <f:call name="renderLayout" />
- </vcp:body>
-
- </div>
-</f:root>
\ No newline at end of file
Deleted: trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx
===================================================================
--- trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx 2009-05-05
17:33:02 UTC (rev 14024)
+++ trunk/ui/layout/src/main/templates/org/richfaces/htmlLayoutPanel.jspx 2009-05-05
22:28:33 UTC (rev 14025)
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<f:root
-
xmlns:f="http://ajax4jsf.org/cdk/template"
- xmlns:c="
http://java.sun.com/jsf/core"
- xmlns:ui="
http://ajax4jsf.org/cdk/ui"
- xmlns:u="
http://ajax4jsf.org/cdk/u"
-
xmlns:h="http://jsf.exadel.com/header"
- xmlns:vcp="
http://jsf.exadel.com/vcp"
- xmlns:x="
http://ajax4jsf.org/cdk/x"
- class="org.richfaces.renderkit.html.LayoutPanelRenderer"
- baseclass="org.richfaces.renderkit.AbstractLayoutPanelRenderer"
- component="org.richfaces.component.UILayoutPanel"
- >
- <f:clientid var="clientId"/>
- <div id="#{clientId}"
x:style="#{this:layoutStyle(context,component)}"
- x:passThruWithExclusions="type,id,style"
- >
- <vcp:body>
- <f:call name="renderChildren" />
- </vcp:body>
- </div>
-</f:root>
\ No newline at end of file
Added: trunk/ui/layout/src/test/java/org/richfaces/component/LayoutStructureTest.java
===================================================================
--- trunk/ui/layout/src/test/java/org/richfaces/component/LayoutStructureTest.java
(rev 0)
+++
trunk/ui/layout/src/test/java/org/richfaces/component/LayoutStructureTest.java 2009-05-05
22:28:33 UTC (rev 14025)
@@ -0,0 +1,86 @@
+package org.richfaces.component;
+
+import java.util.List;
+
+import javax.faces.component.UIComponent;
+
+import org.richfaces.component.html.HtmlLayout;
+import org.richfaces.component.html.HtmlLayoutPanel;
+
+import junit.framework.TestCase;
+
+public class LayoutStructureTest extends TestCase {
+
+ protected UILayout createLayout(String leftWidth,String centerWidth,String rightWidth)
{
+ UILayout layout = new HtmlLayout();
+ layout.setId("layout");
+ List<UIComponent> children = layout.getChildren();
+ UILayoutPanel panel = new HtmlLayoutPanel();
+ panel.setPosition(LayoutPosition.left);
+ panel.setId("left");
+ panel.setWidth(leftWidth);
+ children.add(panel);
+
+ panel = new HtmlLayoutPanel();
+ panel.setPosition(LayoutPosition.top);
+ panel.setId("top");
+ children.add(panel);
+
+ panel = new HtmlLayoutPanel();
+ panel.setPosition(LayoutPosition.right);
+ panel.setId("right");
+ panel.setWidth(rightWidth);
+ children.add(panel);
+
+ panel = new HtmlLayoutPanel();
+ panel.setPosition(LayoutPosition.center);
+ panel.setId("center");
+ panel.setWidth(centerWidth);
+ children.add(panel);
+
+ panel = new HtmlLayoutPanel();
+ panel.setPosition(LayoutPosition.bottom);
+ panel.setId("bottom");
+ children.add(panel);
+ return layout;
+ }
+
+ public void testSortPanels() throws Exception {
+ LayoutStructure struct = new LayoutStructure(createLayout(null, null, null));
+ assertEquals("top", struct.getTop().getId());
+ assertEquals("bottom", struct.getBottom().getId());
+ assertEquals("left", struct.getLeft().getId());
+ assertEquals("right", struct.getRight().getId());
+ assertEquals("center", struct.getCenter().getId());
+ }
+
+ public void testCalculateWidth() throws Exception {
+ LayoutStructure struct = new LayoutStructure(createLayout(null, null, null));
+ struct.calculateWidth();
+ assertEquals("32.67%", struct.getWidth(struct.getLeft()));
+ assertEquals("32.67%", struct.getWidth(struct.getCenter()));
+ assertEquals("32.67%", struct.getWidth(struct.getRight()));
+ }
+
+ public void testCalculateWidth1() throws Exception {
+ LayoutStructure struct = new LayoutStructure(createLayout("50%", null,
null));
+ struct.calculateWidth();
+ assertEquals("49.00%", struct.getWidth(struct.getLeft()));
+ assertEquals("24.50%", struct.getWidth(struct.getCenter()));
+ assertEquals("24.50%", struct.getWidth(struct.getRight()));
+ }
+ public void testCalculateWidth2() throws Exception {
+ LayoutStructure struct = new LayoutStructure(createLayout("50%",
"*2", "*1"));
+ struct.calculateWidth();
+ assertEquals("49.00%", struct.getWidth(struct.getLeft()));
+ assertEquals("32.67%", struct.getWidth(struct.getCenter()));
+ assertEquals("16.33%", struct.getWidth(struct.getRight()));
+ }
+ public void testCalculateWidth3() throws Exception {
+ LayoutStructure struct = new LayoutStructure(createLayout("50%",
"20%", "10%"));
+ struct.calculateWidth();
+ assertEquals("61.25%", struct.getWidth(struct.getLeft()));
+ assertEquals("24.50%", struct.getWidth(struct.getCenter()));
+ assertEquals("12.25%", struct.getWidth(struct.getRight()));
+ }
+}
Property changes on:
trunk/ui/layout/src/test/java/org/richfaces/component/LayoutStructureTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain