View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.chart;
2   
3   /*
4    * Copyright 2006 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.awt.Paint;
20  import java.util.Iterator;
21  import java.util.ResourceBundle;
22  
23  import org.codehaus.mojo.dashboard.report.plugin.beans.CheckstyleError;
24  import org.codehaus.mojo.dashboard.report.plugin.beans.CheckstyleReportBean;
25  import org.codehaus.mojo.dashboard.report.plugin.beans.IDashBoardReportBean;
26  import org.codehaus.mojo.dashboard.report.plugin.utils.ChartUtils;
27  import org.jfree.chart.ChartColor;
28  import org.jfree.data.general.DefaultPieDataset;
29  
30  /**
31   * Checkstyle error dataset strategy class. Corrections written by <a href="mailto:dvicente72@gmail.com">David Vicente</a>
32   *
33   * @author <a href="srivollet@objectif-informatique.fr">Sylvain Rivollet</a>
34   */
35  public class CheckstyleErrorsPieChartStrategy extends AbstractPieChartStrategy
36  {
37  
38      /**
39       * Default constructor
40       *
41       * @param bundle
42       * @param title
43       * @param dashboardReport
44       */
45      public CheckstyleErrorsPieChartStrategy( ResourceBundle bundle, String title, IDashBoardReportBean dashboardReport )
46      {
47          super( bundle, title, dashboardReport );
48      }
49  
50      /**
51       *
52       */
53      public Paint[] getPaintColor()
54      {
55          return new Paint[] { ChartUtils.BLUE_LIGHT, ChartColor.RED, ChartUtils.YELLOW_LIGHT };
56      }
57  
58      /**
59       * give the percentage of iteration compared to the total error count
60       */
61      private float percent( int nbIteration, int nbTotal )
62      {
63          float percent = nbIteration * 100f / nbTotal;
64          percent *= 1000;
65          percent = (int) ( percent + .5 );
66          percent /= 1000;
67          return percent;
68      }
69  
70      public void fillDataset()
71      {
72          if ( mDashboardReport instanceof CheckstyleReportBean )
73          {
74              float percentVal = 0;
75              int nbItInfPercent = 0;
76              CheckstyleReportBean checkstyleReportBean = (CheckstyleReportBean) mDashboardReport;
77              CheckstyleError error = new CheckstyleError();
78              Iterator iterator = checkstyleReportBean.getErrors().iterator();
79  
80              while ( iterator.hasNext() )
81              {
82                  error = (CheckstyleError) iterator.next();
83                  percentVal = percent( error.getNbIteration(), checkstyleReportBean.getNbTotal() );
84  
85                  if ( percentVal > 1 )
86                  {
87                      ( (DefaultPieDataset) this.defaultdataset ).setValue(
88                                                                            error.getMessage() + " = " + percentVal + "%",
89                                                                            error.getNbIteration() );
90                  }
91                  else
92                  {
93                      nbItInfPercent += error.getNbIteration();
94                  }
95              }
96  
97              if ( nbItInfPercent > 0 )
98              {
99                  percentVal = percent( nbItInfPercent, checkstyleReportBean.getNbTotal() );
100                 ( (DefaultPieDataset) this.defaultdataset ).setValue(
101                                                                       this.bundle.getString( "chart.checkstyle.violations.others.label" )
102                                                                                       + " = " + percentVal + "%",
103                                                                       nbItInfPercent );
104             }
105         }
106 
107     }
108 
109 }