Author: sergeyhalipov
Date: 2008-04-25 15:11:42 -0400 (Fri, 25 Apr 2008)
New Revision: 8200
Added:
trunk/ui/separator/src/main/resources/org/richfaces/renderkit/html/css/separator.xcss
Modified:
trunk/ui/separator/src/main/config/component/separator.xml
trunk/ui/separator/src/main/java/org/richfaces/component/UISeparator.java
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/images/SimpleSeparatorImage.java
trunk/ui/separator/src/main/templates/separator.jspx
trunk/ui/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java
trunk/ui/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java
Log:
http://jira.jboss.com/jira/browse/RF-3250
Modified: trunk/ui/separator/src/main/config/component/separator.xml
===================================================================
--- trunk/ui/separator/src/main/config/component/separator.xml 2008-04-25 16:53:51 UTC
(rev 8199)
+++ trunk/ui/separator/src/main/config/component/separator.xml 2008-04-25 19:11:42 UTC
(rev 8200)
@@ -39,14 +39,12 @@
<classname>java.lang.String</classname>
<description>The separator width that can be defined in pixels or in
percents. The default value is 100%
</description>
- <defaultvalue>""</defaultvalue>
</property>
<property>
<name>height</name>
<classname>java.lang.String</classname>
<description>The separator height. Default value is 6 pixels
</description>
- <defaultvalue>"6px"</defaultvalue>
</property>
<property>
<name>lineType</name>
Modified: trunk/ui/separator/src/main/java/org/richfaces/component/UISeparator.java
===================================================================
--- trunk/ui/separator/src/main/java/org/richfaces/component/UISeparator.java 2008-04-25
16:53:51 UTC (rev 8199)
+++ trunk/ui/separator/src/main/java/org/richfaces/component/UISeparator.java 2008-04-25
19:11:42 UTC (rev 8200)
@@ -28,15 +28,6 @@
*
*/
public abstract class UISeparator extends UIComponentBase {
-
- public static final String DEFAULT_HEIGHT = "6px";
- public static final String DEFAULT_WIDTH = "";
- public static final String LINE_TYPE_BEVEL = "beveled";
- public static final String LINE_TYPE_DOUBLE = "double";
- public static final String LINE_TYPE_DOTTED = "dotted";
- public static final String LINE_TYPE_DASHED = "dashed";
- public static final String LINE_TYPE_SOLID = "solid";
-
public abstract String getLineType();
public abstract void setLineType(String lineType);
Modified:
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java
===================================================================
---
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java 2008-04-25
16:53:51 UTC (rev 8199)
+++
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/SeparatorRendererBase.java 2008-04-25
19:11:42 UTC (rev 8200)
@@ -28,32 +28,46 @@
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.ajax4jsf.util.HtmlDimensions;
import org.ajax4jsf.util.style.CSSFormat;
import org.richfaces.component.UISeparator;
import org.richfaces.renderkit.html.images.BevelSeparatorImage;
import org.richfaces.renderkit.html.images.SimpleSeparatorImage;
-public class SeparatorRendererBase extends RendererBase {
+public class SeparatorRendererBase extends HeaderResourcesRendererBase {
+ public static final String IMAGE_CLASS_BEVEL = "rich-separator-image-bevel";
+ public static final String IMAGE_CLASS_SIMPLE =
"rich-separator-image-simple";
+
+ public static final int DEFAULT_HEIGHT = 6;
+
+ public static final String LINE_TYPE_NONE = "none";
+ public static final String LINE_TYPE_BEVEL = "beveled";
+ public static final String LINE_TYPE_DOUBLE = "double";
+ public static final String LINE_TYPE_DOTTED = "dotted";
+ public static final String LINE_TYPE_DASHED = "dashed";
+ public static final String LINE_TYPE_SOLID = "solid";
+
+
- private static final String[] SUPPORTED_TYPES = {
- UISeparator.LINE_TYPE_BEVEL,
- UISeparator.LINE_TYPE_DASHED,
- UISeparator.LINE_TYPE_DOTTED,
- UISeparator.LINE_TYPE_DOUBLE,
- UISeparator.LINE_TYPE_SOLID
+ public static final String[] SUPPORTED_TYPES = {
+ LINE_TYPE_BEVEL,
+ LINE_TYPE_DASHED,
+ LINE_TYPE_DOTTED,
+ LINE_TYPE_DOUBLE,
+ LINE_TYPE_SOLID
};
- private String getCSSDimension(UIComponent component, String attributeName, String
defaultValue) {
+ private String getCSSDimension(UIComponent component, String attributeName) {
Object hO = component.getAttributes().get(attributeName);
String height;
if (hO == null) {
- height = defaultValue;
+ return null;
} else if (hO instanceof String) {
height = (String) hO;
if (height.trim().length() == 0) {
- height = defaultValue;
+ return null;
}
} else {
height = hO.toString();
@@ -83,23 +97,29 @@
public String backgroundImage(FacesContext context, UIComponent component) throws
IOException {
UISeparator separator = (UISeparator) component;
String lineType = separator.getLineType();
+ if (lineType == null || lineType.trim().length() == 0 ||
LINE_TYPE_NONE.equals(lineType)) {
+ return "none";
+ }
if (! isSupportedLineType(lineType)) {
- lineType = UISeparator.LINE_TYPE_BEVEL;
+ lineType = LINE_TYPE_BEVEL;
}
- String height = getHeight(context, component);
- if (height.trim().endsWith("%"))
- throw new FacesException("It is not allowed to set height of separator
in percent (component " + component.getId() + ")!");
- int h = HtmlDimensions.decode(height).intValue();
+
+ int h = DEFAULT_HEIGHT;
+ String height = getCSSDimension(component, HTML.height_ATTRIBUTE);
+ if (null != height) {
+ if (height.trim().endsWith("%")) {
+ throw new FacesException("It is not allowed to set height of separator
in percent (component " + component.getId() + ")!");
+ }
+ h = HtmlDimensions.decode(height).intValue();
+ }
- if (lineType == null || lineType.trim().length() == 0) {
- lineType = UISeparator.LINE_TYPE_BEVEL;
- }
//XXX by nick - fantonov - equalsIgnoreCase here?
- if (lineType.equalsIgnoreCase(UISeparator.LINE_TYPE_BEVEL) && h < 3)
{
- lineType = UISeparator.LINE_TYPE_SOLID;
+ if (lineType.equalsIgnoreCase(LINE_TYPE_BEVEL) && h < 3) {
+ lineType = LINE_TYPE_SOLID;
}
+
String uri = null;
- if (lineType.equalsIgnoreCase(UISeparator.LINE_TYPE_BEVEL)) {
+ if (lineType.equalsIgnoreCase(LINE_TYPE_BEVEL)) {
uri = getResource(BevelSeparatorImage.class.getName()).getUri(context,
component);
} else {
uri = getResource(SimpleSeparatorImage.class.getName()).getUri(context,
component);
@@ -112,11 +132,20 @@
return uri;
}
- public String getHeight(FacesContext context, UIComponent component) {
- return getCSSDimension(component, "height",
UISeparator.DEFAULT_HEIGHT);
- }
-
- public String getWidth(FacesContext context, UIComponent component) {
- return getCSSDimension(component, "width", UISeparator.DEFAULT_WIDTH);
- }
+ public String getStyle(FacesContext context, UIComponent component) throws
IOException{
+ StringBuffer buff = new StringBuffer();
+
+ String height = getCSSDimension(component, HTML.height_ATTRIBUTE);
+ if (null != height) {
+ buff.append("height: " + height + "; ");
+ }
+ String width = getCSSDimension(component, HTML.width_ATTRIBUTE);
+ if (null != width) {
+ buff.append("width: " + width + "; ");
+ }
+ buff.append("background-image: " + backgroundImage(context, component));
+ buff.append(component.getAttributes().get(HTML.style_ATTRIBUTE));
+
+ return buff.toString();
+ }
}
Modified:
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/images/SimpleSeparatorImage.java
===================================================================
---
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/images/SimpleSeparatorImage.java 2008-04-25
16:53:51 UTC (rev 8199)
+++
trunk/ui/separator/src/main/java/org/richfaces/renderkit/html/images/SimpleSeparatorImage.java 2008-04-25
19:11:42 UTC (rev 8200)
@@ -39,6 +39,7 @@
import org.ajax4jsf.util.HtmlDimensions;
import org.ajax4jsf.util.Zipper2;
import org.richfaces.component.UISeparator;
+import org.richfaces.renderkit.html.SeparatorRendererBase;
import org.richfaces.skin.Skin;
import org.richfaces.skin.SkinFactory;
@@ -124,7 +125,7 @@
byte[] ret = new byte[6];
String tmp = (String) ((UIComponent)
data).getAttributes().get("height");
- int height = HtmlDimensions.decode(tmp == null ? "6" :
tmp).intValue();
+ int height = (tmp == null || "".equals(tmp)) ?
SeparatorRendererBase.DEFAULT_HEIGHT : HtmlDimensions.decode(tmp).intValue();
Zipper2 zipper2 = new Zipper2(ret).addShort((short) height);
String skinParameter = "headerBackgroundColor";
@@ -138,12 +139,12 @@
//XXX by nick - fantonov - ((UISeparator)data).getLineType() ?
tmp = (String) ((UISeparator) data).getLineType();
int lineType = LINE_TYPE_SOLID;
- if (tmp.equalsIgnoreCase(UISeparator.LINE_TYPE_DOTTED)) {
+ if (tmp.equalsIgnoreCase(SeparatorRendererBase.LINE_TYPE_DOTTED)) {
lineType = LINE_TYPE_DOTTED;
- } else if (tmp.equalsIgnoreCase(UISeparator.LINE_TYPE_DASHED)) {
+ } else if (tmp.equalsIgnoreCase(SeparatorRendererBase.LINE_TYPE_DASHED)) {
lineType = LINE_TYPE_DASHED;
} else
- if (tmp.equalsIgnoreCase(UISeparator.LINE_TYPE_DOUBLE) && height > 2)
+ if (tmp.equalsIgnoreCase(SeparatorRendererBase.LINE_TYPE_DOUBLE) &&
height > 2)
{
lineType = LINE_TYPE_DOUBLE;
}
Added:
trunk/ui/separator/src/main/resources/org/richfaces/renderkit/html/css/separator.xcss
===================================================================
--- trunk/ui/separator/src/main/resources/org/richfaces/renderkit/html/css/separator.xcss
(rev 0)
+++
trunk/ui/separator/src/main/resources/org/richfaces/renderkit/html/css/separator.xcss 2008-04-25
19:11:42 UTC (rev 8200)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<f:template
+
xmlns:f="http://jsf.exadel.com/template"
+
xmlns:u="http://jsf.exadel.com/template/util"
+
xmlns="http://www.w3.org/1999/xhtml">
+
+ <u:selector name=".rich-separator">
+ <u:style name="height" value="6px" />
+ <u:style name="background-repeat" value="repeat-x" />
+ <u:style name="background-position" value="center" />
+ </u:selector>
+
+</f:template>
Modified: trunk/ui/separator/src/main/templates/separator.jspx
===================================================================
--- trunk/ui/separator/src/main/templates/separator.jspx 2008-04-25 16:53:51 UTC (rev
8199)
+++ trunk/ui/separator/src/main/templates/separator.jspx 2008-04-25 19:11:42 UTC (rev
8200)
@@ -9,12 +9,11 @@
baseclass="org.richfaces.renderkit.html.SeparatorRendererBase"
component="org.richfaces.component.UISeparator"
- <f:clientid var="clientId"/>
+ <f:clientid var="clientId"/>
+ <h:styles>css/separator.xcss</h:styles>
<div id="#{clientId}" style="font-size: 0px;"
x:passThruWithExclusions="id,width,height,style,class,align,styleClass">
- <div style="width: #{this:getWidth(context, component)}; height:
#{this:getHeight(context, component)};
- background-image: #{this:backgroundImage(context, component)}; background-repeat:
repeat-x;
- background-position:center; #{component.attributes['style']}"
+ <div style="#{this:getStyle(context, component)};"
class="rich-separator #{component.attributes['styleClass']}"/>
</div>
</f:root>
Modified:
trunk/ui/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java
===================================================================
---
trunk/ui/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java 2008-04-25
16:53:51 UTC (rev 8199)
+++
trunk/ui/separator/src/test/java/org/richfaces/component/SeparatorComponentTest.java 2008-04-25
19:11:42 UTC (rev 8200)
@@ -32,6 +32,7 @@
import org.ajax4jsf.resource.ResourceBuilderImpl;
import org.ajax4jsf.resource.image.ImageInfo;
import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.renderkit.html.SeparatorRendererBase;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
@@ -42,14 +43,6 @@
*/
public class SeparatorComponentTest extends AbstractAjax4JsfTestCase {
- private static final String[] SUPPORTED_TYPES = {
- UISeparator.LINE_TYPE_BEVEL,
- UISeparator.LINE_TYPE_DASHED,
- UISeparator.LINE_TYPE_DOTTED,
- UISeparator.LINE_TYPE_DOUBLE,
- UISeparator.LINE_TYPE_SOLID
- };
-
private UISeparator ui;
private UIComponent form;
private UIOutput out1;
@@ -123,7 +116,7 @@
public void testRenderImage() throws Exception {
InternetResourceBuilder builder = ResourceBuilderImpl.getInstance();
- ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_BEVEL);
renderView();
InternetResource resource =
builder.getResource("org.richfaces.renderkit.html.images.BevelSeparatorImage");
assertNotNull(resource);
@@ -136,7 +129,7 @@
assertTrue(info.check());
assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
- ui.setLineType(UISeparator.LINE_TYPE_SOLID);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_SOLID);
renderView();
resource =
builder.getResource("org.richfaces.renderkit.html.images.SimpleSeparatorImage");
assertNotNull(resource);
@@ -150,7 +143,7 @@
assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
- ui.setLineType(UISeparator.LINE_TYPE_DOTTED);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_DOTTED);
renderView();
resource =
builder.getResource("org.richfaces.renderkit.html.images.SimpleSeparatorImage");
assertNotNull(resource);
@@ -163,7 +156,7 @@
assertTrue(info.check());
assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
- ui.setLineType(UISeparator.LINE_TYPE_DASHED);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_DASHED);
renderView();
resource =
builder.getResource("org.richfaces.renderkit.html.images.SimpleSeparatorImage");
assertNotNull(resource);
@@ -176,7 +169,7 @@
assertTrue(info.check());
assertEquals(ImageInfo.FORMAT_GIF, info.getFormat());
- ui.setLineType(UISeparator.LINE_TYPE_DOUBLE);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_DOUBLE);
renderView();
resource =
builder.getResource("org.richfaces.renderkit.html.images.SimpleSeparatorImage");
assertNotNull(resource);
Modified:
trunk/ui/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java
===================================================================
---
trunk/ui/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java 2008-04-25
16:53:51 UTC (rev 8199)
+++
trunk/ui/separator/src/test/java/org/richfaces/renderkit/html/SeparatorRendererTest.java 2008-04-25
19:11:42 UTC (rev 8200)
@@ -29,14 +29,6 @@
*/
public class SeparatorRendererTest extends AbstractAjax4JsfTestCase {
- private static final String[] SUPPORTED_TYPES = {
- UISeparator.LINE_TYPE_BEVEL,
- UISeparator.LINE_TYPE_DASHED,
- UISeparator.LINE_TYPE_DOTTED,
- UISeparator.LINE_TYPE_DOUBLE,
- UISeparator.LINE_TYPE_SOLID
- };
-
private SeparatorRendererBase renderer;
private UISeparator ui;
@@ -70,8 +62,8 @@
}
public void testSupportedTypes() throws Exception {
- for (int i = 0; i < SUPPORTED_TYPES.length; i++) {
- assertEquals(true, renderer.isSupportedLineType(SUPPORTED_TYPES[i]));
+ for (int i = 0; i < SeparatorRendererBase.SUPPORTED_TYPES.length; i++) {
+ assertEquals(true,
renderer.isSupportedLineType(SeparatorRendererBase.SUPPORTED_TYPES[i]));
}
boolean notSupported = renderer.isSupportedLineType("UNDEFINED");
@@ -79,20 +71,20 @@
}
public void testBackgroundImage() throws Exception {
- assertEquals(UISeparator.LINE_TYPE_BEVEL, ui.getLineType());
+ assertEquals(SeparatorRendererBase.LINE_TYPE_BEVEL, ui.getLineType());
ui.setLineType("UNDEFINED");
String uri = renderer.backgroundImage(facesContext, ui);
assertTrue(uri.contains("org.richfaces.renderkit.html.images.BevelSeparatorImage"));
- ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_BEVEL);
uri = renderer.backgroundImage(facesContext, ui);
assertTrue(uri.contains("org.richfaces.renderkit.html.images.BevelSeparatorImage"));
- ui.setLineType(UISeparator.LINE_TYPE_DOTTED);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_DOTTED);
uri = renderer.backgroundImage(facesContext, ui);
assertTrue(uri.contains("org.richfaces.renderkit.html.images.SimpleSeparatorImage"));
- ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_BEVEL);
ui.setHeight("10%");
try {
uri = renderer.backgroundImage(facesContext, ui);
@@ -100,7 +92,7 @@
} catch(Exception ex) {
}
- ui.setLineType(UISeparator.LINE_TYPE_BEVEL);
+ ui.setLineType(SeparatorRendererBase.LINE_TYPE_BEVEL);
ui.setHeight("2");
assertTrue(uri.contains("org.richfaces.renderkit.html.images.SimpleSeparatorImage"));
}