KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dinamica > formatters > AltCellColor


1 package dinamica.formatters;
2
3 import java.util.Locale JavaDoc;
4 import dinamica.*;
5
6 /**
7  * Generic formatter that returns a color name
8  * depending on the row position (even or odd).
9  * The column name should represent column that
10  * would contain the color value, most of the time it
11  * may contain a null value. If it does contain a non-null value, then
12  * this value will be returned and the even/odd rule will be ignored.<br>
13  * The [args] argument should contain the name of two colors, separated by comma. Example:<br>
14  * <xmp>
15  * {fld:MyColName@class:dinamica.formatters.AltCellColor(cyan, white)}
16  * </xmp>
17  * This field marker could be placed into a style attribute, in order
18  * to change the background color of a cell. It was designed to be used
19  * with HGrids (Horizontal grid outputs) to create the alternate cell color effect,
20  * much like the alternate row effect already present in regular grid/table presentations.
21  *
22  * <br><br>
23  * Creation date: 09/07/2005
24  * (c) 2005 Martin Cordova<br>
25  * This code is released under the LGPL license<br>
26  * Dinamica Framework - http://www.martincordova.com<br>
27  * @author Martin Cordova (dinamica@martincordova.com)
28  */

29 public class AltCellColor implements IFormatPlugin
30 {
31
32     /* (non-Javadoc)
33      * @see dinamica.IFormatPlugin#format(java.lang.String, dinamica.Recordset, java.util.Locale, java.lang.String)
34      */

35     public String JavaDoc format(String JavaDoc colName, Recordset rs, Locale JavaDoc locale,
36             String JavaDoc args) throws Throwable JavaDoc
37     {
38         
39         String JavaDoc value = rs.getString(colName);
40         if (value!=null && !value.equals(""))
41             return value;
42         
43         String JavaDoc colors[] = StringUtil.split(args,",");
44         String JavaDoc color = colors[1];
45         int v = rs.getRecordNumber() % 2;
46         if (v==0)
47             color = colors[0];
48         
49         return color;
50     }
51
52 }
53
Popular Tags