01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.components.table.renderer;
06:
07: import com.opensymphony.webwork.components.table.WebTable;
08:
09: /**
10: * this is the base class that most renderers will be derived from.
11: * It allows setting the alignment. Subclasses should set there actuall
12: * content by implementing getCellValue
13: */
14: abstract public class AbstractCellRenderer implements CellRenderer {
15:
16: /**
17: * used for horizontal cell alignmnet
18: */
19: protected String _alignment = null;
20:
21: public void setAlignment(String alignment) {
22: _alignment = alignment;
23: }
24:
25: public String getAlignment() {
26: return _alignment;
27: }
28:
29: /**
30: * implememnts CellRenderer renderCell. It sets the alignment. gets the actual
31: * data from getCellValue
32: */
33: public String renderCell(WebTable table, Object data, int row,
34: int col) {
35: if (isAligned()) {
36: StringBuffer buf = new StringBuffer(256);
37: buf.append("<div align='").append(_alignment).append("'>");
38: buf.append(getCellValue(table, data, row, col));
39: buf.append("</div>");
40:
41: return buf.toString();
42: }
43:
44: return getCellValue(table, data, row, col);
45: }
46:
47: protected boolean isAligned() {
48: return _alignment != null;
49: }
50:
51: /**
52: * this is the method that subclasses need to implement to set their value.
53: * they should not override renderCell unless they want to change the alignmnent
54: * renderering
55: */
56: abstract protected String getCellValue(WebTable table, Object data,
57: int row, int col);
58: }
|