01: package dinamica.formatters;
02:
03: import java.util.Locale;
04: import dinamica.*;
05:
06: /**
07: * Generic formatter that returns a color name
08: * depending on the row position (even or odd).
09: * 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: /* (non-Javadoc)
32: * @see dinamica.IFormatPlugin#format(java.lang.String, dinamica.Recordset, java.util.Locale, java.lang.String)
33: */
34: public String format(String colName, Recordset rs, Locale locale,
35: String args) throws Throwable {
36:
37: String value = rs.getString(colName);
38: if (value != null && !value.equals(""))
39: return value;
40:
41: String colors[] = StringUtil.split(args, ",");
42: String color = colors[1];
43: int v = rs.getRecordNumber() % 2;
44: if (v == 0)
45: color = colors[0];
46:
47: return color;
48: }
49:
50: }
|