FileDocCategorySizeDatePackage
NumericCellRenderer.javaAPI DocExample2909Mon Jul 23 13:26:34 BST 2007org.apache.struts2.components.table.renderer

NumericCellRenderer

public class NumericCellRenderer extends AbstractCellRenderer

Fields Summary
DecimalFormat
_formater
String
_formatString
this is the format string that DecimalFormat would use.
String
_negativeColor
if set the is the color to use if Number is negative.
String
_positiveColor
if set this is the color to render if number is positive
Constructors Summary
public NumericCellRenderer()



      
        super();
    
Methods Summary
public java.lang.StringgetCellValue(org.apache.struts2.components.table.WebTable table, java.lang.Object data, int row, int col)

        StringBuffer retVal = new StringBuffer(128);

        if (data == null) {
            return "";
        }

        if (data instanceof Number) {
            double cellValue = ((Number) data).doubleValue();

            if (cellValue >= 0) {
                processNumber(retVal, _positiveColor, cellValue);
            } else {
                processNumber(retVal, _negativeColor, cellValue);
            }

            return retVal.toString();
        }

        return data.toString();
    
protected voidprocessNumber(java.lang.StringBuffer buf, java.lang.String color, double cellValue)

        if (color != null) {
            buf.append(" <font color='").append(color).append("'>");
        }

        buf.append(_formater.format(cellValue));

        if (color != null) {
            buf.append("</font>");
        }
    
public voidsetFormatString(java.lang.String format)

        _formatString = format;
        _formater.applyPattern(_formatString);
    
public voidsetNegativeColor(java.lang.String color)

        _negativeColor = color;
    
public voidsetPositiveColor(java.lang.String color)

        _positiveColor = color;