KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > model > Cell


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12 package org.displaytag.model;
13
14 import org.apache.commons.lang.builder.ToStringBuilder;
15 import org.apache.commons.lang.builder.ToStringStyle;
16 import org.displaytag.util.HtmlAttributeMap;
17
18
19 /**
20  * <p>
21  * Represents a table cell.
22  * </p>
23  * <p>
24  * A cell is used only when the content is placed as content of the column tag and need to be evaluated during
25  * iteration.
26  * </p>
27  * @author Fabrizio Giustina
28  * @version $Revision: 970 $ ($Author: fgiust $)
29  */

30 public class Cell implements Comparable JavaDoc, Cloneable JavaDoc
31 {
32
33     /**
34      * empty cell object. Use as placeholder for empty cell to avoid useless object creation.
35      */

36     public static final Cell EMPTY_CELL = new Cell();
37
38     /**
39      * content of the cell.
40      */

41     private Object JavaDoc staticValue;
42
43     /**
44      * Per row html attributes (style, class).
45      */

46     private HtmlAttributeMap attributes;
47
48     /**
49      * Creates a new empty cell. This should never be done, use EMPTY_CELL instead.
50      */

51     private Cell()
52     {
53         super();
54     }
55
56     /**
57      * Creates a cell with a static value.
58      * @param value Object value of the Cell object
59      */

60     public Cell(Object JavaDoc value)
61     {
62         this.staticValue = value;
63     }
64
65     /**
66      * get the static value for the cell.
67      * @return the Object value of this.staticValue.
68      */

69     public Object JavaDoc getStaticValue()
70     {
71         return this.staticValue;
72     }
73
74     /**
75      * Compare the Cell value to another Cell.
76      * @param obj Object to compare this cell to
77      * @return int
78      * @see java.lang.Comparable#compareTo(Object)
79      */

80     public int compareTo(Object JavaDoc obj)
81     {
82
83         if (this.staticValue == null)
84         {
85             return -1;
86         }
87
88         if (obj instanceof Cell)
89         {
90             return ((Comparable JavaDoc) this.staticValue).compareTo(((Cell) obj).getStaticValue());
91         }
92
93         return ((Comparable JavaDoc) this.staticValue).compareTo(obj);
94
95     }
96
97     /**
98      * Simple toString wich output the static value.
99      * @return String represantation of the cell
100      */

101     public String JavaDoc toString()
102     {
103         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) //
104
.append("staticValue", this.staticValue).toString(); //$NON-NLS-1$
105
}
106
107     public void setPerRowAttributes(HtmlAttributeMap perRowValues)
108     {
109         this.attributes = perRowValues;
110     }
111
112     public HtmlAttributeMap getPerRowAttributes()
113     {
114         return this.attributes;
115     }
116
117 }
Popular Tags