KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > components > table > renderer > AbstractCellRenderer


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.webwork.components.table.renderer;
6
7 import com.opensymphony.webwork.components.table.WebTable;
8
9
10 /**
11  * this is the base class that most renderers will be derived from.
12  * It allows setting the alignment. Subclasses should set there actuall
13  * content by implementing getCellValue
14  */

15 abstract public class AbstractCellRenderer implements CellRenderer {
16     //~ Instance fields ////////////////////////////////////////////////////////
17

18     /**
19      * used for horizontal cell alignmnet
20      */

21     protected String JavaDoc _alignment = null;
22
23     //~ Methods ////////////////////////////////////////////////////////////////
24

25     public void setAlignment(String JavaDoc alignment) {
26         _alignment = alignment;
27     }
28
29     public String JavaDoc getAlignment() {
30         return _alignment;
31     }
32
33     /**
34      * implememnts CellRenderer renderCell. It sets the alignment. gets the actual
35      * data from getCellValue
36      */

37     public String JavaDoc renderCell(WebTable table, Object JavaDoc data, int row, int col) {
38         if (isAligned()) {
39             StringBuffer JavaDoc buf = new StringBuffer JavaDoc(256);
40             buf.append("<div align='").append(_alignment).append("'>");
41             buf.append(getCellValue(table, data, row, col));
42             buf.append("</div>");
43
44             return buf.toString();
45         }
46
47         return getCellValue(table, data, row, col);
48     }
49
50     protected boolean isAligned() {
51         return _alignment != null;
52     }
53
54     /**
55      * this is the method that subclasses need to implement to set their value.
56      * they should not override renderCell unless they want to change the alignmnent
57      * renderering
58      */

59     abstract protected String JavaDoc getCellValue(WebTable table, Object JavaDoc data, int row, int col);
60 }
61
Popular Tags