001    /**
002     * www.jcoverage.com
003     * Copyright (C)2003 jcoverage ltd.
004     *
005     * This file is part of jcoverage.
006     *
007     * jcoverage is free software; you can redistribute it and/or modify
008     * it under the terms of the GNU General Public License as published
009     * by the Free Software Foundation; either version 2 of the License,
010     * or (at your option) any later version.
011     *
012     * jcoverage is distributed in the hope that it will be useful, but
013     * WITHOUT ANY WARRANTY; without even the implied warranty of
014     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     * General Public License for more details.
016     *
017     * You should have received a copy of the GNU General Public License
018     * along with jcoverage; if not, write to the Free Software
019     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
020     * USA
021     *
022     */
023    package com.jcoverage.reporting.html;
024    
025    import java.io.PrintWriter;
026    
027    import org.apache.log4j.Logger;
028    
029    import com.jcoverage.reporting.Column;
030    import com.jcoverage.reporting.FormattingContext;
031    import com.jcoverage.reporting.Line;
032    
033    /**
034     *
035     */
036    public class DefaultColumnRenderer implements ColumnRenderer {
037      
038      static Logger logger=Logger.getLogger(DefaultColumnRenderer.class);
039      
040      String label;
041    
042      public DefaultColumnRenderer(String label) {
043        this.label=label;
044      }
045    
046      public DefaultColumnRenderer() {
047      }
048    
049      public void renderField(FormattingContext ctx,PrintWriter writer,Column column,Line line,String href) {
050        if (getClassId()!=null) {
051          writer.println("<td class=\""+getClassId()+"\">");
052        } else {
053          writer.println("<td>");
054        }
055        if (href!=null) {
056          writer.print("<a href="+href+">");
057        }
058        writer.print(getValueAsString(line,column));
059        if (href!=null) {
060          writer.print("</a>");
061        }
062        writer.println("</td>");
063      }
064    
065      public String getValueAsString(Line line,Column column) {
066        return line.getField(column).toString();
067      }
068    
069      public void renderTitle(FormattingContext ctx,PrintWriter writer,Column column,boolean remainder) {
070        writer.print("<th");
071        if (getWidth()!=null) {
072          writer.print(" width=\""+getWidth()+"\"");
073        }
074        if (remainder) {
075          writer.print(" class=\"remainder\"");
076        }
077        writer.print(">");
078        if (label!=null) {
079          writer.print(label);
080        } else {
081          writer.print(column.getLabel());
082        }
083        writer.print("</th>");
084      }
085    
086      public String getWidth() {
087        return null;
088      }
089    
090      public String getClassId() {
091        return null;
092      }
093      
094    }