001: /*
002: * Hammurapi
003: * Automated Java code review system.
004: * Copyright (C) 2004 Johannes Bellert
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.pavelvlasov.com/pv/content/menu.show?id=products.jtaste
021: * e-Mail: Johannes.Bellert@ercgroup.com
022: */
023: package org.hammurapi.inspectors.metrics.reporting;
024:
025: import java.io.File;
026: import java.io.FileOutputStream;
027: import java.io.OutputStream;
028:
029: import org.hammurapi.inspectors.metrics.CodeMetric;
030: import org.hammurapi.inspectors.metrics.statistics.IntVector;
031: import org.hammurapi.results.AnnotationContext;
032: import org.jfree.chart.ChartUtilities;
033: import org.jfree.chart.JFreeChart;
034:
035: public class LocReporter {
036:
037: private String projectBaseDir = "";
038: private JFreeChart jFreeChartClasses;
039: private JFreeChart jFreeChartFunctions;
040: private AnnotationContext.FileEntry fileEntry;
041: private File outFile;
042: private Integer classMaxLoc;
043: private Integer functionMaxLoc;
044: private Integer ncssReport;
045: private Integer chartDebugWindow;
046:
047: private AnnotationContext context;
048: private AnnotationContext.FileEntry jpgClassFileEntry;
049: private AnnotationContext.FileEntry jpgFunctionFileEntry;
050:
051: /**
052: * A sorted distribution list of class NCSS
053: *
054: */
055: private IntVector ncssClassList = new IntVector();
056:
057: /**
058: * A sorted distribution list of function NCSS
059: *
060: */
061: private IntVector ncssFunctionList = new IntVector();
062:
063: public LocReporter(AnnotationContext _context,
064: Integer _classMaxLoc, Integer _functionMaxLoc,
065: Integer _ncssReport, Integer _chartDebugWindow) {
066: super ();
067: context = _context;
068: // projectBaseDir=context.;
069: // outFile = _outFile ;
070: classMaxLoc = _classMaxLoc;
071: functionMaxLoc = _functionMaxLoc;
072: ncssReport = _ncssReport;
073: chartDebugWindow = _chartDebugWindow;
074: }
075:
076: public void doIt(CodeMetric projectMetric) {
077: //!! job: refactor to Visitor traversing
078: // packages
079: if (ncssReport.intValue() > 0) {
080: LocCharts locClassCharts = new LocCharts("NCSS: Classes",
081: classMaxLoc.intValue(), this .ncssClassList,
082: chartDebugWindow);
083: locClassCharts.setGraphicDimX(350);
084: locClassCharts.setGraphicDimY(250);
085: this .jFreeChartClasses = locClassCharts.generateChart();
086: LocCharts locFunctionCharts = new LocCharts(
087: "NCSS: Functions", functionMaxLoc.intValue(),
088: this .ncssFunctionList, chartDebugWindow);
089: locFunctionCharts.setGraphicDimX(350);
090: locFunctionCharts.setGraphicDimY(250);
091: this .jFreeChartFunctions = locFunctionCharts
092: .generateChart();
093: // writeToXml(projectMetric);
094:
095: try {
096:
097: jpgClassFileEntry = context.getNextFile("Class.jpg");
098: jpgFunctionFileEntry = context
099: .getNextFile("Function.jpg");
100: FileOutputStream out = new FileOutputStream(
101: jpgClassFileEntry.getFile());
102: ChartUtilities.writeChartAsJPEG((OutputStream) out,
103: this .jFreeChartClasses, 500, 300);
104: // outChartFile = new File(projectBaseDir, File.separatorChar +
105: // "FunctionCodeMetric" + ".jpg");
106: out = new FileOutputStream(jpgFunctionFileEntry
107: .getFile());
108: ChartUtilities.writeChartAsJPEG((OutputStream) out,
109: this .jFreeChartFunctions, 500, 300);
110: } catch (Exception e) {
111: e.printStackTrace();
112: }
113: }
114: }
115:
116: /**
117: * @return Returns the jpgClassFileEntry.
118: */
119: public AnnotationContext.FileEntry getJpgClassFileEntry() {
120: return jpgClassFileEntry;
121: }
122:
123: /**
124: * @return Returns the jpgFunctionFileEntry.
125: */
126: public AnnotationContext.FileEntry getJpgFunctionFileEntry() {
127: return jpgFunctionFileEntry;
128: }
129:
130: /**
131: * @return Returns the ncssClassList.
132: */
133: public IntVector getNcssClassList() {
134: return ncssClassList;
135: }
136:
137: /**
138: * @param ncssClassList The ncssClassList to set.
139: */
140: public void setNcssClassList(IntVector ncssClassList) {
141: this .ncssClassList = ncssClassList;
142: }
143:
144: /**
145: * @return Returns the ncssFunctionList.
146: */
147: public IntVector getNcssFunctionList() {
148: return ncssFunctionList;
149: }
150:
151: /**
152: * @param ncssFunctionList The ncssFunctionList to set.
153: */
154: public void setNcssFunctionList(IntVector ncssFunctionList) {
155: this.ncssFunctionList = ncssFunctionList;
156: }
157: }
|