[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf/ui ...

Norman Richards norman.richards at jboss.com
Sat Apr 28 19:47:56 EDT 2007


  User: nrichards
  Date: 07/04/28 19:47:56

  Modified:    src/pdf/org/jboss/seam/pdf/ui     UIBarChart.java
                        UIChart.java UIChartData.java
  Added:       src/pdf/org/jboss/seam/pdf/ui     UILineChart.java
  Log:
  add line chart, support higher quality rendering
  
  Revision  Changes    Path
  1.2       +4 -5      jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIBarChart.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIBarChart.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIBarChart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UIBarChart.java	26 Apr 2007 22:48:28 -0000	1.1
  +++ UIBarChart.java	28 Apr 2007 23:47:56 -0000	1.2
  @@ -14,7 +14,7 @@
   {
       String title;
       String categoryAxisLabel;
  -    String valueAxisLabel;
  +    String domainAxisLabel;
       CategoryDataset dataset;
       String orientation;
       
  @@ -36,7 +36,7 @@
       }
   
       public void setValueAxisLabel(String valueAxisLabel) {
  -        this.valueAxisLabel = valueAxisLabel;
  +        this.domainAxisLabel = valueAxisLabel;
       }
   
       public void setLegend(boolean legend) {
  @@ -62,11 +62,10 @@
   
       @Override
       public JFreeChart getChart(FacesContext context) {
  -        System.out.println("3d=" + is3D);
           if (!is3D) {
               return ChartFactory.createBarChart(title,
                       categoryAxisLabel,
  -                    valueAxisLabel,
  +                    domainAxisLabel,
                       dataset,
                       plotOrientation(orientation),
                       legend,
  @@ -75,7 +74,7 @@
           } else {
               return ChartFactory.createBarChart3D(title,
                       categoryAxisLabel,
  -                    valueAxisLabel,
  +                    domainAxisLabel,
                       dataset,
                       plotOrientation(orientation),
                       legend,
  
  
  
  1.2       +23 -10    jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChart.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIChart.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UIChart.java	26 Apr 2007 22:48:28 -0000	1.1
  +++ UIChart.java	28 Apr 2007 23:47:56 -0000	1.2
  @@ -1,5 +1,7 @@
   package org.jboss.seam.pdf.ui;
   
  +import java.awt.Graphics2D;
  +import java.awt.geom.Rectangle2D;
   import java.io.IOException;
   
   import javax.faces.context.FacesContext;
  @@ -8,6 +10,11 @@
   import org.jfree.data.general.Dataset;
   
   import com.lowagie.text.*;
  +import com.lowagie.text.pdf.DefaultFontMapper;
  +import com.lowagie.text.pdf.PdfContentByte;
  +import com.lowagie.text.pdf.PdfTemplate;
  +import com.lowagie.text.pdf.PdfWriter;
  +import com.sun.javadoc.Doc;
   
   public abstract class UIChart 
       extends ITextComponent 
  @@ -33,11 +40,17 @@
           height = (Float) valueBinding(context, "height", height);
           width =  (Float) valueBinding(context, "width", width);
           
  -        org.jboss.seam.core.Image seamImage = new org.jboss.seam.core.Image();  
  -        seamImage.setBufferedImage(chart.createBufferedImage((int)width,(int)height));
           
           try {
  -            image = Image.getInstance(seamImage.getImage());           
  +            UIDocument doc = (UIDocument) findITextParent(getParent(), UIDocument.class);
  +            PdfWriter writer = (PdfWriter) doc.getWriter();
  +            PdfContentByte cb = writer.getDirectContent(); 
  +            PdfTemplate tp = cb.createTemplate(width, height); 
  +            Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper());             
  +            chart.draw(g2, new Rectangle2D.Double(0, 0, width, height); ); 
  +            g2.dispose(); 
  +            
  +            image = new ImgTemplate(tp);
           } catch (Exception e) {
               throw new RuntimeException(e);            
           }
  
  
  
  1.2       +1 -2      jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChartData.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIChartData.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIChartData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UIChartData.java	26 Apr 2007 22:48:28 -0000	1.1
  +++ UIChartData.java	28 Apr 2007 23:47:56 -0000	1.2
  @@ -11,7 +11,6 @@
   public class UIChartData 
       extends ITextComponent 
   {
  - 
       String key;
       String columnKey;
       String rowKey;
  
  
  
  1.1      date: 2007/04/28 23:47:56;  author: nrichards;  state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UILineChart.java
  
  Index: UILineChart.java
  ===================================================================
  package org.jboss.seam.pdf.ui;
  
  import javax.faces.context.FacesContext;
  
  import org.jfree.chart.ChartFactory;
  import org.jfree.chart.JFreeChart;
  import org.jfree.chart.plot.PlotOrientation;
  import org.jfree.data.category.CategoryDataset;
  import org.jfree.data.category.DefaultCategoryDataset;
  import org.jfree.data.general.Dataset;
  
  public class UILineChart
      extends UIChart 
  {
      String title;
      String domainAxisLabel;
      String rangeAxisLabel;
      CategoryDataset dataset;
      String orientation;
      
      boolean legend;
      boolean tooltips;
      boolean urls;
      boolean is3D = false;
      
      public void setTitle(String title) {
          this.title = title;
      }
      
      public void setOrientation(String orientation) {
          this.orientation = orientation;
      }
      
      public void setDomainAxisLabel(String domainAxisLabel) {
          this.domainAxisLabel = domainAxisLabel;
      }
  
      public void setRangeAxisLabel(String rangeAxisLabel) {
          this.rangeAxisLabel = rangeAxisLabel;
      }
  
      public void setLegend(boolean legend) {
          this.legend = legend;
      }
      
      public void setTooltips(boolean tooltips) {
          this.tooltips = tooltips;
      }
      
      public void setUrls(boolean urls) {
          this.urls = urls;
      }
      
      public void setIs3D(boolean is3D) {
          this.is3D = true;
      }
      
      @Override
      public void createDataset() {
          dataset = new DefaultCategoryDataset();
      }
  
      @Override
      public JFreeChart getChart(FacesContext context) {
          if (!is3D) {
              return ChartFactory.createLineChart(title,
                      domainAxisLabel,
                      rangeAxisLabel,
                      dataset,
                      plotOrientation(orientation),
                      legend,
                      tooltips,
                      urls);
          } else {
              return ChartFactory.createLineChart3D(title,
                      domainAxisLabel,
                      rangeAxisLabel,
                      dataset,
                      plotOrientation(orientation),
                      legend,
                      tooltips,
                      urls);
          }
      }
  
      @Override
      public Dataset getDataset() {        
          return dataset;
      }
  
      public PlotOrientation plotOrientation(String orientation) {
          if (orientation != null && orientation.equalsIgnoreCase("horizontal")) {
              return PlotOrientation.HORIZONTAL;
          } else {
              return PlotOrientation.VERTICAL;
          }
      }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list