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

Norman Richards norman.richards at jboss.com
Tue May 1 21:09:04 EDT 2007


  User: nrichards
  Date: 07/05/01 21:09:04

  Modified:    src/pdf/org/jboss/seam/pdf/ui         ITextComponent.java
                        UIBarChart.java UIChart.java UILineChart.java
                        UIPieChart.java
  Added:       src/pdf/org/jboss/seam/pdf/ui         UIColor.java
                        UIStroke.java
  Removed:     src/pdf/org/jboss/seam/pdf/ui         UIPieChart3D.java
  Log:
  add stroke/paint
  
  Revision  Changes    Path
  1.13      +4 -5      jboss-seam/src/pdf/org/jboss/seam/pdf/ui/ITextComponent.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ITextComponent.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/ITextComponent.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- ITextComponent.java	30 Mar 2007 23:09:53 -0000	1.12
  +++ ITextComponent.java	2 May 2007 01:09:04 -0000	1.13
  @@ -1,10 +1,9 @@
   package org.jboss.seam.pdf.ui;
   
  +import javax.el.ValueExpression;
   import javax.faces.*;
   import javax.faces.context.*;
   import javax.faces.component.*;
  -import javax.faces.el.ValueBinding;
  -
   import java.io.*;
   import java.util.List;
   
  @@ -141,10 +140,10 @@
                                  String property, 
                                  Object defaultValue) {
           Object value = defaultValue; 
  -        ValueBinding binding = getValueBinding(property);
  +        ValueExpression expression = getValueExpression(property);
   
  -        if (binding != null) {
  -            value = binding.getValue(context);
  +        if (expression != null) {
  +            value = expression.getValue(context.getELContext());
           }
           return value;
       }
  
  
  
  1.3       +29 -0     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.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- UIBarChart.java	28 Apr 2007 23:47:56 -0000	1.2
  +++ UIBarChart.java	2 May 2007 01:09:04 -0000	1.3
  @@ -1,10 +1,18 @@
   package org.jboss.seam.pdf.ui;
   
  +import java.awt.BasicStroke;
  +import java.awt.Color;
  +import java.awt.Stroke;
  +
   import javax.faces.context.FacesContext;
   
   import org.jfree.chart.ChartFactory;
   import org.jfree.chart.JFreeChart;
  +import org.jfree.chart.plot.CategoryPlot;
  +import org.jfree.chart.plot.Plot;
   import org.jfree.chart.plot.PlotOrientation;
  +import org.jfree.chart.renderer.category.BarRenderer;
  +import org.jfree.chart.renderer.category.CategoryItemRenderer;
   import org.jfree.data.category.CategoryDataset;
   import org.jfree.data.category.DefaultCategoryDataset;
   import org.jfree.data.general.Dataset;
  @@ -61,6 +69,27 @@
       }
   
       @Override
  +    public void configurePlot(Plot p) {
  +        super.configurePlot(p);
  +        CategoryPlot plot = (CategoryPlot) p;
  +        plot.setRangeGridlinePaint(Color.BLUE);
  +        plot.setDomainGridlinePaint(Color.CYAN);
  +        // ...
  +                
  +        configureRenderer((BarRenderer) plot.getRenderer());
  +              
  +    }
  +    
  +    public void configureRenderer(BarRenderer renderer) {
  +        renderer.setItemMargin(0.0);
  +        
  +        
  +        renderer.setBaseOutlineStroke(new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10f, 
  +                new float[] {10,3}, 0));        
  +
  +    }
  +
  +    @Override
       public JFreeChart getChart(FacesContext context) {
           if (!is3D) {
               return ChartFactory.createBarChart(title,
  
  
  
  1.4       +165 -12   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.3
  retrieving revision 1.4
  diff -u -b -r1.3 -r1.4
  --- UIChart.java	29 Apr 2007 03:37:44 -0000	1.3
  +++ UIChart.java	2 May 2007 01:09:04 -0000	1.4
  @@ -1,12 +1,19 @@
   package org.jboss.seam.pdf.ui;
   
  +import java.awt.BasicStroke;
  +import java.awt.Color;
   import java.awt.Graphics2D;
  +import java.awt.Paint;
  +import java.awt.Stroke;
   import java.awt.geom.Rectangle2D;
   import java.io.IOException;
   
  +import javax.faces.component.UIComponent;
   import javax.faces.context.FacesContext;
   
  +import org.jboss.seam.pdf.ITextUtils;
   import org.jfree.chart.JFreeChart;
  +import org.jfree.chart.plot.Plot;
   import org.jfree.data.general.Dataset;
   
   import com.lowagie.text.*;
  @@ -14,7 +21,6 @@
   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 
  @@ -23,6 +29,17 @@
       float height = 300;
       float width  = 400;
   
  +    String borderBackgroundPaint;
  +    String borderPaint;
  +    String borderStroke;
  +    boolean borderVisible = true;
  +    
  +    String plotBackgroundPaint;
  +    Float  plotBackgroundAlpha;
  +    Float  plotForegroundAlpha;
  +    String plotOutlineStroke; 
  +    String plotOutlinePaint;
  +    
       public void setHeight(float height) {
           this.height = height;
       }
  @@ -31,37 +48,175 @@
           this.width = width;
       }
       
  +    public void setBorderBackgroundPaint(String backgroundPaint) {
  +        this.borderBackgroundPaint = backgroundPaint;
  +    }
  +    
  +    public String getBorderBackgroundPaint() {
  +        return (String) valueBinding(FacesContext.getCurrentInstance(), "backgroundPaint", borderBackgroundPaint);
  +    }
  +    
  +    public void setBorderPaint(String borderPaint) {
  +        this.borderPaint = borderPaint;
  +    }
  +    
  +    public String getBorderPaint() {
  +        return (String) valueBinding(FacesContext.getCurrentInstance(), "borderPaint", borderPaint);
  +    }
  +    
  +    public void setBorderStroke(String borderStroke) {
  +        this.borderStroke = borderStroke;
  +    }
  +    
  +    public String getBorderStroke() {
  +        return (String) valueBinding(FacesContext.getCurrentInstance(), "borderStroke", borderStroke);
  +    }
  +    
  +    public void setBorderVisible(boolean borderVisible) {
  +        this.borderVisible = borderVisible;
  +    }
  +    
  +    public boolean getBorderVisible() {
  +        return (Boolean) valueBinding(FacesContext.getCurrentInstance(), "borderVisible", borderVisible);
  +    }
  +    
  +
  +    public void setPlotBackgroundAlpha(Float plotBackgroundAlpha) {
  +        this.plotBackgroundAlpha = plotBackgroundAlpha;
  +    }
  +
  +    public Float getPlotBackgroundAlpha() {
  +        return (Float) valueBinding(FacesContext.getCurrentInstance(), "plotBackgroundAlpha", plotBackgroundAlpha);     
  +    }
  +   
  +    public void setPlotBackgroundPaint(String plotBackgroundPaint) {
  +        this.plotBackgroundPaint = plotBackgroundPaint;
  +    }
  +    
  +    public String getPlotBackgroundPaint() {
  +        return (String) valueBinding(FacesContext.getCurrentInstance(), "plotBackgroundPaint", plotBackgroundPaint);
  +    }
  +
  +    public void setPlotForegroundAlpha(Float plotForegroundAlpha) {
  +        this.plotForegroundAlpha = plotForegroundAlpha;
  +    }
  +    public Float getPlotForegroundAlpha() {
  +        return (Float) valueBinding(FacesContext.getCurrentInstance(), "plotForegroundAlpha", plotForegroundAlpha);
  +    }
  +
  +    public void setPlotOutlinePaint(String plotOutlinePaint) {
  +        this.plotOutlinePaint = plotOutlinePaint;
  +    }
  +    
  +    public String getPlotOutlinePaint() {
  +        return (String) valueBinding(FacesContext.getCurrentInstance(), "plotOutlinePaint", plotOutlinePaint);    
  +    }
  +    
  +    public void setPlotOutlineStroke(String plotOutlineStroke) {
  +        this.plotOutlineStroke = plotOutlineStroke;
  +    }
  +    
  +    public String getPlotOutlineStroke() {
  +        return (String) valueBinding(FacesContext.getCurrentInstance(), "plotOutlineStroke", plotOutlineStroke);
  +    }   
  +    
  +    public Paint findColor(String name) {
  +        UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent(name);
  +        
  +        if (component != null) {
  +            if (component instanceof UIColor) {                
  +                return ((UIColor) component).getPaint();
  +            } else {
  +                throw new RuntimeException();                
  +            }            
  +        }
  +        
  +        return ITextUtils.colorValue(name);        
  +    }
  +    
  +    private Stroke findStroke(String id) {
  +        UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent(id);
  +
  +        if (component instanceof UIStroke) {
  +
  +            return ((UIStroke) component).getStroke();
  +        } else {
  +            throw new RuntimeException();                
  +
  +        }
  +    }
  +    
       public abstract JFreeChart getChart(FacesContext context);
       
       @Override
       public void createITextObject(FacesContext context) {
           JFreeChart chart = getChart(context);
                  
  +        if (borderBackgroundPaint != null) {
  +            chart.setBackgroundPaint(findColor(getBorderBackgroundPaint()));
  +        }
  +        
  +        if (borderPaint != null) {
  +            chart.setBorderPaint(findColor(getBorderPaint()));
  +        }
  +
  +        if (borderStroke != null) {
  +            chart.setBorderStroke(findStroke(getBorderStroke()));
  +        }
  +
  +        chart.setBorderVisible(getBorderVisible());      
  +        
  +        configurePlot(chart.getPlot());         
  +        
           height = (Float) valueBinding(context, "height", height);
           width =  (Float) valueBinding(context, "width", width);        
   
  -        
           try { 
               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) ); 
  +            chart.draw(g2, new Rectangle2D.Double(0, 0, width, height)); 
               g2.dispose(); 
               
               image = new ImgTemplate(tp);
           } catch (Exception e) {             
               throw new RuntimeException(e);
           } 
  +    }   
  +    
  +   
  +
  +    public void configurePlot(Plot plot) {   
  +        if (plotBackgroundAlpha != null) {
  +            plot.setBackgroundAlpha(plotBackgroundAlpha);
  +        }
  +        
  +        if (plotForegroundAlpha != null) {
  +            plot.setForegroundAlpha(plotForegroundAlpha);          
  +        }
   
  +        if (plotBackgroundPaint != null) {
  +            plot.setBackgroundPaint(findColor(plotBackgroundPaint));
       }     
       
  +        if (plotOutlinePaint != null) {
  +            plot.setOutlinePaint(findColor(plotOutlinePaint));
  +        }
  +        
  +        if (plotOutlineStroke != null) { 
  +            plot.setOutlineStroke(findStroke(plotOutlineStroke));
  +        }        
  +    }
  +    
  +    
  +            
       @Override
       public void encodeBegin(FacesContext context) 
           throws IOException
       {       
  -        // bypass super to avoid createITextObject()
  +        // bypass super to avoid createITextObject() before the chart is ready
           createDataset();
       }
       
  @@ -93,6 +248,4 @@
       
       public abstract void createDataset();
       public abstract Dataset getDataset();
  -
  -
   }
  
  
  
  1.2       +6 -0      jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UILineChart.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UILineChart.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UILineChart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UILineChart.java	28 Apr 2007 23:47:56 -0000	1.1
  +++ UILineChart.java	2 May 2007 01:09:04 -0000	1.2
  @@ -4,6 +4,7 @@
   
   import org.jfree.chart.ChartFactory;
   import org.jfree.chart.JFreeChart;
  +import org.jfree.chart.plot.Plot;
   import org.jfree.chart.plot.PlotOrientation;
   import org.jfree.data.category.CategoryDataset;
   import org.jfree.data.category.DefaultCategoryDataset;
  @@ -84,6 +85,11 @@
       }
   
       @Override
  +    public void configurePlot(Plot plot) {
  +        
  +    }
  +    
  +    @Override
       public Dataset getDataset() {        
           return dataset;
       }
  
  
  
  1.2       +16 -1     jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIPieChart.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UIPieChart.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIPieChart.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- UIPieChart.java	26 Apr 2007 22:48:28 -0000	1.1
  +++ UIPieChart.java	2 May 2007 01:09:04 -0000	1.2
  @@ -4,6 +4,7 @@
   
   import org.jfree.chart.ChartFactory;
   import org.jfree.chart.JFreeChart;
  +import org.jfree.chart.plot.Plot;
   import org.jfree.data.general.Dataset;
   import org.jfree.data.general.DefaultPieDataset;
   
  @@ -17,6 +18,7 @@
       boolean legend;
       boolean tooltips;
       boolean urls;
  +    boolean is3D = false;
           
       public void setTitle(String title) {
           this.title = title;
  @@ -34,6 +36,10 @@
           this.urls = urls;
       }
       
  +    public void setIs3D(boolean is3D) {
  +        this.is3D = true;
  +    }
  +    
       @Override
       public void createDataset() {
           data = new DefaultPieDataset();
  @@ -44,6 +50,11 @@
           return data;
       }
       
  +    @Override
  +    public void configurePlot(Plot plot) {
  +        super.configurePlot(plot);
  +    }
  +    
       
       
       @Override
  @@ -52,7 +63,11 @@
           tooltips = (Boolean) valueBinding(context, "tooltips", tooltips);
           urls = (Boolean) valueBinding(context, "urls", urls);
           
  +        if (!is3D) {
           return ChartFactory.createPieChart(title, data, legend, tooltips, urls);
  +        } else {
  +            return ChartFactory.createPieChart3D(title, data, legend, tooltips, urls);
  +        }
       }
   
       public void restoreState(FacesContext context, Object state) {
  
  
  
  1.1      date: 2007/05/02 01:09:04;  author: nrichards;  state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIColor.java
  
  Index: UIColor.java
  ===================================================================
  package org.jboss.seam.pdf.ui;
  
  import java.awt.GradientPaint;
  import java.awt.Paint;
  import java.awt.geom.Point2D;
  
  import javax.el.ValueExpression;
  import javax.faces.component.UIComponentBase;
  import javax.faces.context.FacesContext;
  
  import org.jboss.seam.pdf.ITextUtils;
  
  public class UIColor 
      extends UIComponentBase 
  {
      String color;    
      String color2;
      
      String point;
      String point2;
      
      public void setColor(String color) {
          this.color = color;
      }
      
      public String getColor() {
          return (color != null) ? color : (String) evalExpression("color");
      }
      
      public void setColor2(String color2) {
          this.color2 = color2;
      }
      
      public String getColor2() {
          return (color2 != null) ? color2 : (String) evalExpression("color2");
      }
      
      public void setPoint(String point) {
          this.point = point;
      }
      
      public String getPoint() {
          return (point != null) ? point : (String) evalExpression("point");
      }
      
      public void setPoint2(String point2) {
          this.point2 = point2;
      }
      
      public String getPoint2() {
          return (point2 != null) ? point2 : (String) evalExpression("point2");
      }
  
      @Override
      public String getFamily() {
          return ITextComponent.COMPONENT_FAMILY;
      }     
      
      public Object evalExpression(String el) {
          ValueExpression expr = getValueExpression(el);
          return (expr == null) ? 
                 null : expr.getValue(FacesContext.getCurrentInstance().getELContext());        
      }
  
      public Point2D pointValue(String string) {
          Point2D point = new Point2D.Float();
          float[] vals = ITextUtils.stringToFloatArray(string);
          point.setLocation(vals[0],vals[1]);
          return point;
      }
       
      public Paint getPaint() {
          String c1 = getColor();
          String c2 = getColor2();
                  
          if (c2 == null) {
              return ITextUtils.colorValue(c1);
          } else {
              return new GradientPaint(pointValue(getPoint()),ITextUtils.colorValue(c1),
                                       pointValue(getPoint()),ITextUtils.colorValue(c2));
          }
      }
  }
  
  
  
  1.1      date: 2007/05/02 01:09:04;  author: nrichards;  state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIStroke.java
  
  Index: UIStroke.java
  ===================================================================
  package org.jboss.seam.pdf.ui;
  
  import java.awt.BasicStroke;
  import java.awt.Stroke;
  
  import javax.faces.component.UIComponentBase;
  
  import org.jboss.seam.pdf.ITextUtils;
  
  public class UIStroke 
      extends UIComponentBase 
  {
      Float  width;
      String cap; // CAP_BUTT, CAP_ROUND, CAP_SQUARE
      String join; // JOIN_MITER, JOIN_ROUND, JOIN_BEVEL
      Float  miterLimit =1f;
      String dashString;
      Float  dashPhase = 0f;
      
      public String getCap() {
          return cap;
      }
  
      public void setCap(String cap) {
          this.cap = cap;
      }
  
      public String getDash() {
          return dashString;
      }
  
      public void setDash(String dash) {
          this.dashString = dash;
      }
  
      public float getDashPhase() {
          return dashPhase;
      }
  
      public void setDashPhase(float dashPhase) {
          this.dashPhase = dashPhase;
      }
  
      public String getJoin() {
          return join;
      }
  
      public void setJoin(String join) {
          this.join = join;
      }
  
      public float getMiterlimit() {
          return miterLimit;
      }
  
      public void setMiterLimit(float miterLimit) {
          this.miterLimit = miterLimit;
      }
  
      public float getWidth() {
          return width;
      }
  
      public void setWidth(float width) {
          this.width = width;
      }
      
      public int capValue(String cap) {
          if (cap == null || cap.equalsIgnoreCase("butt")) {
              return BasicStroke.CAP_BUTT;
          } else if (cap.equalsIgnoreCase("round")) {
              return BasicStroke.CAP_ROUND;
          } else if (cap.equalsIgnoreCase("square")) {
              return BasicStroke.CAP_SQUARE;
          }
          throw new RuntimeException("invalid cap value: " + cap);        
      }
      
      public int joinValue(String join) {
          if (cap == null || cap.equalsIgnoreCase("mite")) {
              return BasicStroke.JOIN_MITER;
          } else if (cap.equalsIgnoreCase("round")) {
              return BasicStroke.JOIN_ROUND;
          } else if (cap.equalsIgnoreCase("bevel")) {
              return BasicStroke.JOIN_BEVEL;
          }
          throw new RuntimeException("invalid join value: " + cap);
      }
      
  
      @Override
      public String getFamily() {
          return ITextComponent.COMPONENT_FAMILY;
      }     
      
      public Stroke getStroke() {
          if (width == null) {
              return new BasicStroke();
          } else if (cap == null) {
              return new BasicStroke(getWidth());
          } else if (dashString == null) {
              if (miterLimit == null) {
                  return new BasicStroke(getWidth(), capValue(getCap()), joinValue(getJoin()));
              } else {
                  return new BasicStroke(getWidth(), capValue(getCap()), joinValue(getJoin()), miterLimit); 
              }
          } else {
              return new BasicStroke(getWidth(), 
                                     capValue(getCap()), 
                                     joinValue(getJoin()), 
                                     getMiterlimit(),
                                     ITextUtils.stringToFloatArray(getDash()), 
                                     getDashPhase());
          }
      }
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list