View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.chart;
2   
3   /*
4    * Copyright 2007 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.Map;
22  import java.util.ResourceBundle;
23  
24  import org.codehaus.mojo.dashboard.report.plugin.beans.FindBugsReportBean;
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   * Findbugs priorities dataset strategy class.
32   * @author <a href="dvicente72@gmail.com">David Vicente</a>
33   */
34  public class FindbugsPrioritiesPieChartStrategy extends AbstractPieChartStrategy
35  {
36  
37      /**
38       * Default constructor
39       *
40       * @param bundle
41       * @param title
42       * @param dashboardReport
43       */
44      public FindbugsPrioritiesPieChartStrategy( ResourceBundle bundle, String title, IDashBoardReportBean dashboardReport )
45      {
46          super( bundle, title, dashboardReport );
47      }
48  
49      /**
50       *
51       */
52      public Paint[] getPaintColor()
53      {
54          return new Paint[] { ChartUtils.BLUE_LIGHT, ChartColor.RED, ChartUtils.YELLOW_LIGHT };
55      }
56  
57      /**
58       * give the percentage of iteration compared to the total error count
59       */
60      private float percent( int nbIteration, int nbTotal )
61      {
62          float percent = nbIteration * 100f / nbTotal;
63          percent *= 1000;
64          percent = (int) ( percent + .5 );
65          percent /= 1000;
66          return percent;
67      }
68  
69      public void fillDataset()
70      {
71          if ( mDashboardReport instanceof FindBugsReportBean )
72          {
73              float percentVal = 0;
74              FindBugsReportBean findBugsReportBean = (FindBugsReportBean) mDashboardReport;
75  
76              Map priorities = findBugsReportBean.getPriorities();
77              Iterator iterator = priorities.keySet().iterator();
78  
79              while ( iterator.hasNext() )
80              {
81                  String priority = (String) iterator.next();
82                  Integer value = (Integer) priorities.get( priority );
83                  percentVal = percent( value.intValue(), findBugsReportBean.getNbBugs() );
84  
85                  ( (DefaultPieDataset) this.defaultdataset ).setValue( priority + " = " + percentVal + "%", value.intValue() );
86              }
87          }
88  
89      }
90  
91  }