KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > metrics > reporting > LocReporter


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Johannes Bellert
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * URL: http://www.pavelvlasov.com/pv/content/menu.show?id=products.jtaste
21  * e-Mail: Johannes.Bellert@ercgroup.com
22  */

23 package org.hammurapi.inspectors.metrics.reporting;
24 import java.io.File JavaDoc;
25 import java.io.FileOutputStream JavaDoc;
26 import java.io.OutputStream JavaDoc;
27
28 import org.hammurapi.inspectors.metrics.CodeMetric;
29 import org.hammurapi.inspectors.metrics.statistics.IntVector;
30 import org.hammurapi.results.AnnotationContext;
31 import org.jfree.chart.ChartUtilities;
32 import org.jfree.chart.JFreeChart;
33
34 public class LocReporter {
35
36     private String JavaDoc projectBaseDir = "";
37     private JFreeChart jFreeChartClasses;
38     private JFreeChart jFreeChartFunctions;
39     private AnnotationContext.FileEntry fileEntry;
40     private File JavaDoc outFile;
41     private Integer JavaDoc classMaxLoc;
42     private Integer JavaDoc functionMaxLoc;
43     private Integer JavaDoc ncssReport;
44     private Integer JavaDoc chartDebugWindow;
45
46     private AnnotationContext context;
47     private AnnotationContext.FileEntry jpgClassFileEntry;
48     private AnnotationContext.FileEntry jpgFunctionFileEntry;
49
50
51     /**
52      * A sorted distribution list of class NCSS
53      *
54      */

55     private IntVector ncssClassList = new IntVector();
56
57     /**
58      * A sorted distribution list of function NCSS
59      *
60      */

61     private IntVector ncssFunctionList = new IntVector();
62
63
64
65     public LocReporter(AnnotationContext _context, Integer JavaDoc _classMaxLoc, Integer JavaDoc _functionMaxLoc, Integer JavaDoc _ncssReport, Integer JavaDoc _chartDebugWindow ) {
66         super();
67         context = _context;
68 // projectBaseDir=context.;
69
// outFile = _outFile ;
70
classMaxLoc = _classMaxLoc;
71         functionMaxLoc = _functionMaxLoc;
72         ncssReport = _ncssReport;
73         chartDebugWindow = _chartDebugWindow;
74     }
75
76
77     public void doIt(CodeMetric projectMetric) {
78         //!! job: refactor to Visitor traversing
79
// packages
80
if (ncssReport.intValue() > 0) {
81             LocCharts locClassCharts = new LocCharts("NCSS: Classes", classMaxLoc.intValue(), this.ncssClassList,
82                     chartDebugWindow);
83             locClassCharts.setGraphicDimX(350);
84             locClassCharts.setGraphicDimY(250);
85             this.jFreeChartClasses = locClassCharts.generateChart();
86             LocCharts locFunctionCharts = new LocCharts("NCSS: Functions", functionMaxLoc.intValue(),
87                     this.ncssFunctionList, chartDebugWindow);
88             locFunctionCharts.setGraphicDimX(350);
89             locFunctionCharts.setGraphicDimY(250);
90             this.jFreeChartFunctions = locFunctionCharts.generateChart();
91         // writeToXml(projectMetric);
92

93             try {
94
95                 jpgClassFileEntry = context.getNextFile("Class.jpg");
96                 jpgFunctionFileEntry = context.getNextFile("Function.jpg");
97                 FileOutputStream JavaDoc out = new FileOutputStream JavaDoc(jpgClassFileEntry.getFile());
98                 ChartUtilities.writeChartAsJPEG((OutputStream JavaDoc) out, this.jFreeChartClasses, 500, 300);
99                 // outChartFile = new File(projectBaseDir, File.separatorChar +
100
// "FunctionCodeMetric" + ".jpg");
101
out = new FileOutputStream JavaDoc(jpgFunctionFileEntry.getFile());
102                 ChartUtilities.writeChartAsJPEG((OutputStream JavaDoc) out, this.jFreeChartFunctions, 500, 300);
103             } catch (Exception JavaDoc e) {
104                 e.printStackTrace();
105             }
106         }
107     }
108     /**
109      * @return Returns the jpgClassFileEntry.
110      */

111     public AnnotationContext.FileEntry getJpgClassFileEntry() {
112         return jpgClassFileEntry;
113     }
114     /**
115      * @return Returns the jpgFunctionFileEntry.
116      */

117     public AnnotationContext.FileEntry getJpgFunctionFileEntry() {
118         return jpgFunctionFileEntry;
119     }
120     /**
121      * @return Returns the ncssClassList.
122      */

123     public IntVector getNcssClassList() {
124         return ncssClassList;
125     }
126     /**
127      * @param ncssClassList The ncssClassList to set.
128      */

129     public void setNcssClassList(IntVector ncssClassList) {
130         this.ncssClassList = ncssClassList;
131     }
132     /**
133      * @return Returns the ncssFunctionList.
134      */

135     public IntVector getNcssFunctionList() {
136         return ncssFunctionList;
137     }
138     /**
139      * @param ncssFunctionList The ncssFunctionList to set.
140      */

141     public void setNcssFunctionList(IntVector ncssFunctionList) {
142         this.ncssFunctionList = ncssFunctionList;
143     }
144 }
145
Popular Tags