[richfaces-svn-commits] JBoss Rich Faces SVN: r13583 - in trunk/ui/colorPicker/src: main/java/org/richfaces and 5 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Apr 14 13:59:26 EDT 2009


Author: nbelaevski
Date: 2009-04-14 13:59:25 -0400 (Tue, 14 Apr 2009)
New Revision: 13583

Added:
   trunk/ui/colorPicker/src/main/java/org/richfaces/convert/
   trunk/ui/colorPicker/src/main/java/org/richfaces/convert/AWTColorConverter.java
   trunk/ui/colorPicker/src/main/java/org/richfaces/convert/IntegerColorConverter.java
   trunk/ui/colorPicker/src/main/java/org/richfaces/convert/LongColorConverter.java
   trunk/ui/colorPicker/src/test/java/org/richfaces/convert/
   trunk/ui/colorPicker/src/test/java/org/richfaces/convert/AWTColorConverterTest.java
   trunk/ui/colorPicker/src/test/java/org/richfaces/convert/IntegerColorConverterTest.java
   trunk/ui/colorPicker/src/test/java/org/richfaces/convert/LongColorConverterTest.java
Modified:
   trunk/ui/colorPicker/src/main/config/component/colorPicker.xml
   trunk/ui/colorPicker/src/main/java/org/richfaces/component/UIColorPicker.java
   trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
Log:
https://jira.jboss.org/jira/browse/RF-6757

Modified: trunk/ui/colorPicker/src/main/config/component/colorPicker.xml
===================================================================
--- trunk/ui/colorPicker/src/main/config/component/colorPicker.xml	2009-04-14 17:32:33 UTC (rev 13582)
+++ trunk/ui/colorPicker/src/main/config/component/colorPicker.xml	2009-04-14 17:59:25 UTC (rev 13583)
@@ -96,5 +96,20 @@
 		</property>
 		
 	</component>
+	
+	<converter generate="false">
+		<id>org.richfaces.IntegerColor</id>
+		<classname>org.richfaces.convert.IntegerColorConverter</classname>
+	</converter>
+	
+	<converter generate="false">
+		<id>org.richfaces.LongColor</id>
+		<classname>org.richfaces.convert.LongColorConverter</classname>
+	</converter>
+
+	<converter generate="false">
+		<id>org.richfaces.AWTColor</id>
+		<classname>org.richfaces.convert.AWTColorConverter</classname>
+	</converter>
 </components>
 	
\ No newline at end of file

Modified: trunk/ui/colorPicker/src/main/java/org/richfaces/component/UIColorPicker.java
===================================================================
--- trunk/ui/colorPicker/src/main/java/org/richfaces/component/UIColorPicker.java	2009-04-14 17:32:33 UTC (rev 13582)
+++ trunk/ui/colorPicker/src/main/java/org/richfaces/component/UIColorPicker.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -4,8 +4,18 @@
 
 package org.richfaces.component;
 
+import java.awt.Color;
+
+import javax.el.ValueExpression;
+import javax.faces.application.Application;
 import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
 
+import org.richfaces.convert.AWTColorConverter;
+import org.richfaces.convert.IntegerColorConverter;
+import org.richfaces.convert.LongColorConverter;
+
 /**
  * JSF component class
  *
@@ -16,11 +26,43 @@
 	
 	public static final String COMPONENT_FAMILY = "org.richfaces.ColorPicker";
 
-    @Override
-    public void setValue(Object value) {
-        // TODO Remove it 
-        super.setValue(value);
-    }
+	public static final String COLOR_MODE_RGB = "rgb";
 	
+	public static final String COLOR_MODE_HEX = "hex";
+
+	public abstract String getColorMode();
+	public abstract void setColorMode(String colorMode);
 	
+	@Override
+	public Converter getConverter() {
+		Converter converter = super.getConverter();
+		if (converter == null) {
+			ValueExpression valueExpression = this.getValueExpression("value");
+			if (valueExpression != null) {
+				FacesContext context = getFacesContext();
+				
+			    Class<?> converterType = valueExpression.getType(context.getELContext());
+			    Application application = context.getApplication();
+				if (converterType != null && !String.class.equals(converterType) && 
+			    		!Object.class.equals(converterType) && !Integer.class.equals(converterType) && 
+			    		!Long.class.equals(converterType) /* standard integer or long converter won't suite our needs */) {
+
+			    	converter = application.createConverter(converterType);
+			    }
+			    
+			    if (converter == null) {
+			    	if (Long.class.equals(converterType)) {
+			    		converter = application.createConverter(LongColorConverter.CONVERTER_ID);
+			    	} else if (Integer.class.equals(converterType)) {
+			    		converter = application.createConverter(IntegerColorConverter.CONVERTER_ID);
+			    	} else if (Color.class.equals(converterType)) {
+			    		converter = application.createConverter(AWTColorConverter.CONVERTER_ID);
+			    	}
+			    }
+			}
+		}
+		
+		return converter;
+	}
+	
 }

Added: trunk/ui/colorPicker/src/main/java/org/richfaces/convert/AWTColorConverter.java
===================================================================
--- trunk/ui/colorPicker/src/main/java/org/richfaces/convert/AWTColorConverter.java	                        (rev 0)
+++ trunk/ui/colorPicker/src/main/java/org/richfaces/convert/AWTColorConverter.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -0,0 +1,74 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.convert;
+
+import java.awt.Color;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+public class AWTColorConverter extends IntegerColorConverter {
+
+	public static final String CONVERTER_ID = "org.richfaces.AWTColor";
+
+	public Object getAsObject(FacesContext context, UIComponent component,
+			String value) {
+		
+		if (context == null) {
+			throw new NullPointerException("context");
+		}
+		
+		if (component == null) {
+			throw new NullPointerException("component");
+		}
+		
+		Integer convertedValue = (Integer) super.getAsObject(context, component, value);
+		if (convertedValue != null) {
+			return new Color(convertedValue.intValue());
+		} else {
+			return null;
+		}
+	}
+
+	public String getAsString(FacesContext context, UIComponent component,
+			Object value) {
+
+		if (context == null) {
+			throw new NullPointerException("context");
+		}
+		
+		if (component == null) {
+			throw new NullPointerException("component");
+		}
+		
+		Integer rgb = null;
+		if (value != null) {
+			rgb = 0xFFFFFF & ((Color) value).getRGB();
+		}
+		
+		return super.getAsString(context, component, rgb);
+	}
+}

Added: trunk/ui/colorPicker/src/main/java/org/richfaces/convert/IntegerColorConverter.java
===================================================================
--- trunk/ui/colorPicker/src/main/java/org/richfaces/convert/IntegerColorConverter.java	                        (rev 0)
+++ trunk/ui/colorPicker/src/main/java/org/richfaces/convert/IntegerColorConverter.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -0,0 +1,142 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.convert;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+
+import org.ajax4jsf.Messages;
+import org.richfaces.component.UIColorPicker;
+import org.richfaces.component.util.MessageUtil;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+public class IntegerColorConverter implements Converter {
+
+	private static final Pattern NUMBER = Pattern.compile("(\\d+)");
+	
+	public static final String CONVERTER_ID = "org.richfaces.IntegerColor";
+
+	private int convertToInteger(String colorValue) {
+		int result = 0;
+
+		if (colorValue.charAt(0) == '#') {
+			result = Integer.parseInt(colorValue.substring(1), 16);
+		} else {
+			Matcher matcher = NUMBER.matcher(colorValue);
+			for (int i = 1; i <= 3; i++) {
+				if (!matcher.find()) {
+					throw new IllegalArgumentException(colorValue);
+				}
+			
+				if (i != 1) {
+					result <<= 8;
+				}
+				
+				result |= (0xFF & Short.parseShort(matcher.group(1)));
+			}
+		}
+		
+		return result;
+	}
+	
+	private String convertToString(int value, String colorMode) {
+		if (UIColorPicker.COLOR_MODE_RGB.equals(colorMode)) {
+			StringBuilder sb = new StringBuilder("rgb(");
+			
+			sb.append((value & 0xFF0000) >> 16);
+			sb.append(", ");
+			sb.append((value & 0x00FF00) >> 8);
+			sb.append(", ");
+			sb.append(value & 0xFF);
+
+			sb.append(")");
+			return sb.toString();
+		} else {
+			StringBuilder sb = new StringBuilder("#");
+			String hexString = Integer.toHexString(value);
+			for (int i = 0; i < 6 - hexString.length(); i++) {
+				sb.append('0');
+			}
+			sb.append(hexString);
+			return sb.toString();
+		}
+	}
+
+	public Object getAsObject(FacesContext context, UIComponent component,
+			String value) {
+		
+		if (context == null) {
+			throw new NullPointerException("context");
+		}
+		
+		if (component == null) {
+			throw new NullPointerException("component");
+		}
+		
+		if (value != null && value.length() != 0) {
+			try {
+				return convertToInteger(value);
+			} catch (Exception e) {
+				Object label = MessageUtil.getLabel(context, component);
+				String summary = Messages.getMessage(Messages.COMPONENT_CONVERSION_ERROR, label, value);
+
+				throw new ConverterException(new FacesMessage(summary), e);
+			}
+		} else {
+			return null;
+		}
+	}
+
+	public String getAsString(FacesContext context, UIComponent component,
+			Object value) {
+		
+		if (context == null) {
+			throw new NullPointerException("context");
+		}
+		
+		if (component == null) {
+			throw new NullPointerException("component");
+		}
+		
+		if (value != null) {
+			try {
+				return convertToString((Integer) value, ((UIColorPicker) component).getColorMode());
+			} catch (Exception e) {
+				Object label = MessageUtil.getLabel(context, component);
+				String summary = Messages.getMessage(Messages.COMPONENT_CONVERSION_ERROR, label, value);
+
+				throw new ConverterException(new FacesMessage(summary), e);
+			}
+		} else {
+			return "";
+		}
+	}
+}

Added: trunk/ui/colorPicker/src/main/java/org/richfaces/convert/LongColorConverter.java
===================================================================
--- trunk/ui/colorPicker/src/main/java/org/richfaces/convert/LongColorConverter.java	                        (rev 0)
+++ trunk/ui/colorPicker/src/main/java/org/richfaces/convert/LongColorConverter.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -0,0 +1,71 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.convert;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+public class LongColorConverter extends IntegerColorConverter {
+
+	@Override
+	public Object getAsObject(FacesContext context, UIComponent component,
+			String value) {
+		if (context == null) {
+			throw new NullPointerException("context");
+		}
+		
+		if (component == null) {
+			throw new NullPointerException("component");
+		}
+		
+		Integer integer = (Integer) super.getAsObject(context, component, value);
+		if (integer != null) {
+			return Long.valueOf(integer.intValue());
+		} else {
+			return null;
+		}
+	}
+	
+	@Override
+	public String getAsString(FacesContext context, UIComponent component,
+			Object value) {
+
+		if (context == null) {
+			throw new NullPointerException("context");
+		}
+		
+		if (component == null) {
+			throw new NullPointerException("component");
+		}
+		
+		Integer intValue = null;
+		if (value != null) {
+			intValue = 0xFFFFFF & ((Long) value).intValue();
+		}
+		
+		return super.getAsString(context, component, intValue);
+	}
+}

Modified: trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx
===================================================================
--- trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx	2009-04-14 17:32:33 UTC (rev 13582)
+++ trunk/ui/colorPicker/src/main/templates/org/richfaces/htmlColorPicker.jspx	2009-04-14 17:59:25 UTC (rev 13583)
@@ -10,6 +10,9 @@
 	baseclass="org.richfaces.renderkit.ColorPickerRendererBase"
 	component="org.richfaces.component.UIColorPicker" 
 	>
+	
+	<jsp:directive.page import="org.richfaces.component.UIColorPicker" />
+	
 	<f:clientid var="clientId"/>
 	<h:scripts>/org/richfaces/renderkit/html/scripts/jquery/jquery.js, /org/richfaces/renderkit/html/scripts/jquery.utils.js, /org/richfaces/renderkit/html/scripts/pngFix.js, /org/richfaces/renderkit/html/scripts/ui.core.js, /org/richfaces/renderkit/html/scripts/ui.colorpicker.js</h:scripts>
 	<h:styles>/org/richfaces/renderkit/html/css/colorPicker.xcss</h:styles>		
@@ -107,10 +110,8 @@
 		colorMode = (String) component.getAttributes().get("colorMode");
 		showEvent = (String) component.getAttributes().get("showEvent");
 
-		boolean isRgbMode = "rgb".equals(colorMode);
-		
 		if (value == null || value.length() == 0){
-			if (isRgbMode) {
+			if (UIColorPicker.COLOR_MODE_RGB.equals(colorMode)) {
 				value = "rgb(255, 255, 255)";
 			} else {
 				value = "#ffffff";

Added: trunk/ui/colorPicker/src/test/java/org/richfaces/convert/AWTColorConverterTest.java
===================================================================
--- trunk/ui/colorPicker/src/test/java/org/richfaces/convert/AWTColorConverterTest.java	                        (rev 0)
+++ trunk/ui/colorPicker/src/test/java/org/richfaces/convert/AWTColorConverterTest.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -0,0 +1,69 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.convert;
+
+import java.awt.Color;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIColorPicker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class AWTColorConverterTest extends AbstractAjax4JsfTestCase {
+
+	public AWTColorConverterTest(String name) {
+		super(name);
+	}
+
+	private UIColorPicker colorPicker;
+	
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+
+		colorPicker = (UIColorPicker) application.createComponent(UIColorPicker.COMPONENT_TYPE);
+	}
+	
+	@Override
+	public void tearDown() throws Exception {
+		super.tearDown();
+
+		colorPicker = null;
+	}
+	
+	public void testConverterRegistration() throws Exception {
+		assertNotNull(facesContext.getApplication().createConverter(AWTColorConverter.CONVERTER_ID));
+	}
+	
+	public void testConversion() throws Exception {
+		AWTColorConverter converter = new AWTColorConverter();
+		
+		assertNull(converter.getAsObject(facesContext, colorPicker, null));
+		assertNull(converter.getAsObject(facesContext, colorPicker, ""));
+		assertEquals("", converter.getAsString(facesContext, colorPicker, null));
+
+		assertEquals(new Color(0x66, 0x33, 0xcc), converter.getAsObject(facesContext, colorPicker, "#6633cc"));
+		assertEquals("#6633cc", converter.getAsString(facesContext, colorPicker, new Color(0x66, 0x33, 0xcc)));
+	}
+}

Added: trunk/ui/colorPicker/src/test/java/org/richfaces/convert/IntegerColorConverterTest.java
===================================================================
--- trunk/ui/colorPicker/src/test/java/org/richfaces/convert/IntegerColorConverterTest.java	                        (rev 0)
+++ trunk/ui/colorPicker/src/test/java/org/richfaces/convert/IntegerColorConverterTest.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -0,0 +1,131 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.convert;
+
+import javax.faces.convert.ConverterException;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIColorPicker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class IntegerColorConverterTest extends AbstractAjax4JsfTestCase {
+
+	public IntegerColorConverterTest(String name) {
+		super(name);
+	}
+
+	private UIColorPicker colorPicker;
+	
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+
+		colorPicker = (UIColorPicker) application.createComponent(UIColorPicker.COMPONENT_TYPE);
+	}
+	
+	@Override
+	public void tearDown() throws Exception {
+		super.tearDown();
+
+		colorPicker = null;
+	}
+	
+	public void testConverterRegistration() throws Exception {
+		assertNotNull(facesContext.getApplication().createConverter(IntegerColorConverter.CONVERTER_ID));
+	}
+	
+	public void testGetAsString() throws Exception {
+		IntegerColorConverter converter = new IntegerColorConverter();
+		
+		assertEquals("", converter.getAsString(facesContext, colorPicker, null));
+		
+		assertEquals("#ef0023", converter.getAsString(facesContext, colorPicker, 0xef0023));
+		assertEquals("#000000", converter.getAsString(facesContext, colorPicker, 0x0));
+		assertEquals("#012345", converter.getAsString(facesContext, colorPicker, 0x012345));
+		assertEquals("#6633cc", converter.getAsString(facesContext, colorPicker, 0x6633cc));
+	}
+	
+	public void testGetAsStringRGB() throws Exception {
+		colorPicker.setColorMode(UIColorPicker.COLOR_MODE_RGB);
+		IntegerColorConverter converter = new IntegerColorConverter();
+		
+		assertEquals("", converter.getAsString(facesContext, colorPicker, null));
+		
+		assertEquals("rgb(239, 0, 35)", converter.getAsString(facesContext, colorPicker, 0xef0023));
+		assertEquals("rgb(0, 0, 0)", converter.getAsString(facesContext, colorPicker, 0x0));
+		assertEquals("rgb(255, 255, 255)", converter.getAsString(facesContext, colorPicker, 0xffffff));
+		assertEquals("rgb(1, 35, 69)", converter.getAsString(facesContext, colorPicker, 0x012345));
+		assertEquals("rgb(102, 51, 204)", converter.getAsString(facesContext, colorPicker, 0x6633cc));
+	}
+	
+	public void testGetAsObject() throws Exception {
+		IntegerColorConverter converter = new IntegerColorConverter();
+		
+		assertNull(converter.getAsObject(facesContext, colorPicker, null));
+		assertNull(converter.getAsObject(facesContext, colorPicker, ""));
+
+		assertEquals(0x0, converter.getAsObject(facesContext, colorPicker, "#000000"));
+		assertEquals(0x6633cc, converter.getAsObject(facesContext, colorPicker, "#6633cc"));
+		assertEquals(0x123456, converter.getAsObject(facesContext, colorPicker, "#123456"));
+		assertEquals(0x0fec, converter.getAsObject(facesContext, colorPicker, "#000fec"));
+	}
+	
+	public void testGetAsObjectRGB() throws Exception {
+		colorPicker.setColorMode(UIColorPicker.COLOR_MODE_RGB);
+		IntegerColorConverter converter = new IntegerColorConverter();
+		
+		assertNull(converter.getAsObject(facesContext, colorPicker, null));
+		assertNull(converter.getAsObject(facesContext, colorPicker, ""));
+		
+		assertEquals(0xef0023, converter.getAsObject(facesContext, colorPicker, "rgb(239, 0, 35)"));
+		assertEquals(0x0, converter.getAsObject(facesContext, colorPicker, "rgb(0, 0, 0)"));
+		assertEquals(0xffffff, converter.getAsObject(facesContext, colorPicker, "rgb(255, 255, 255)"));
+		assertEquals(0x012345, converter.getAsObject(facesContext, colorPicker, "rgb(1, 35, 69)"));
+		assertEquals(0x6633cc, converter.getAsObject(facesContext, colorPicker, "rgb(102, 51, 204)"));
+	}
+	
+	public void testConversionErrorsHex() throws Exception {
+		IntegerColorConverter converter = new IntegerColorConverter();
+
+		try {
+			converter.getAsObject(facesContext, colorPicker, "#12sq34");
+			
+			fail();
+		} catch (ConverterException e) {
+		}
+	}
+
+	public void testConversionErrorsRGB() throws Exception {
+		colorPicker.setColorMode(UIColorPicker.COLOR_MODE_RGB);
+		IntegerColorConverter converter = new IntegerColorConverter();
+	
+		try {
+			converter.getAsObject(facesContext, colorPicker, "rgb(1, 2)");
+			
+			fail();
+		} catch (ConverterException e) {
+		}
+	}
+}

Added: trunk/ui/colorPicker/src/test/java/org/richfaces/convert/LongColorConverterTest.java
===================================================================
--- trunk/ui/colorPicker/src/test/java/org/richfaces/convert/LongColorConverterTest.java	                        (rev 0)
+++ trunk/ui/colorPicker/src/test/java/org/richfaces/convert/LongColorConverterTest.java	2009-04-14 17:59:25 UTC (rev 13583)
@@ -0,0 +1,67 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.richfaces.convert;
+
+import org.ajax4jsf.tests.AbstractAjax4JsfTestCase;
+import org.richfaces.component.UIColorPicker;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class LongColorConverterTest extends AbstractAjax4JsfTestCase {
+
+	public LongColorConverterTest(String name) {
+		super(name);
+	}
+
+	private UIColorPicker colorPicker;
+	
+	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+
+		colorPicker = (UIColorPicker) application.createComponent(UIColorPicker.COMPONENT_TYPE);
+	}
+	
+	@Override
+	public void tearDown() throws Exception {
+		super.tearDown();
+
+		colorPicker = null;
+	}
+	
+	public void testConverterRegistration() throws Exception {
+		assertNotNull(facesContext.getApplication().createConverter(LongColorConverter.CONVERTER_ID));
+	}
+	
+	public void testConversion() throws Exception {
+		LongColorConverter converter = new LongColorConverter();
+		
+		assertNull(converter.getAsObject(facesContext, colorPicker, null));
+		assertNull(converter.getAsObject(facesContext, colorPicker, ""));
+		assertEquals("", converter.getAsString(facesContext, colorPicker, null));
+
+		assertEquals(0x6633ccL, converter.getAsObject(facesContext, colorPicker, "#6633cc"));
+		assertEquals("#6633cc", converter.getAsString(facesContext, colorPicker, 0x6633ccL));
+	}
+}




More information about the richfaces-svn-commits mailing list