1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| package com.jeantessier.dependencyfinder.gui; |
34 |
| |
35 |
| import java.util.*; |
36 |
| import javax.swing.table.*; |
37 |
| |
38 |
| import com.jeantessier.metrics.*; |
39 |
| |
40 |
| public class OOMetricsTableModel extends AbstractTableModel { |
41 |
| private static final Integer LOCAL_DISPOSE_IGNORE = StatisticalMeasurement.DISPOSE_IGNORE; |
42 |
| private static final Integer LOCAL_DISPOSE_MINIMUM = StatisticalMeasurement.DISPOSE_MINIMUM; |
43 |
| private static final Integer LOCAL_DISPOSE_MEDIAN = StatisticalMeasurement.DISPOSE_MEDIAN; |
44 |
| private static final Integer LOCAL_DISPOSE_AVERAGE = StatisticalMeasurement.DISPOSE_AVERAGE; |
45 |
| private static final Integer LOCAL_DISPOSE_STANDARD_DEVIATION = StatisticalMeasurement.DISPOSE_STANDARD_DEVIATION; |
46 |
| private static final Integer LOCAL_DISPOSE_MAXIMUM = StatisticalMeasurement.DISPOSE_MAXIMUM; |
47 |
| private static final Integer LOCAL_DISPOSE_SUM = StatisticalMeasurement.DISPOSE_SUM; |
48 |
| |
49 |
| |
50 |
| private List<MeasurementDescriptor> descriptors; |
51 |
| private List<Metrics> metricsList; |
52 |
| |
53 |
| private String[] measurementNames; |
54 |
| private MeasurementDescriptor[] measurementDescriptors; |
55 |
| private int[] measurementDispose; |
56 |
| private Object[][] measurementValues; |
57 |
| |
58 |
| private MetricsComparator comparator = new MetricsComparator("name"); |
59 |
| |
60 |
0
| public OOMetricsTableModel(List<MeasurementDescriptor> descriptors) {
|
61 |
0
| this.descriptors = descriptors;
|
62 |
| |
63 |
0
| buildMetricNames();
|
64 |
0
| buildMetricValues();
|
65 |
| } |
66 |
| |
67 |
0
| public void setMetrics(Collection<Metrics> metricsList) {
|
68 |
0
| this.metricsList = new ArrayList<Metrics>(metricsList);
|
69 |
| |
70 |
0
| if (metricsList.isEmpty()) {
|
71 |
0
| buildMetricValues();
|
72 |
| } else { |
73 |
0
| Collections.sort(this.metricsList, comparator);
|
74 |
0
| buildMetricValues(this.metricsList);
|
75 |
| } |
76 |
| |
77 |
0
| fireTableStructureChanged();
|
78 |
| } |
79 |
| |
80 |
0
| public MeasurementDescriptor getColumnDescriptor(int column) {
|
81 |
0
| return measurementDescriptors[column];
|
82 |
| } |
83 |
| |
84 |
0
| public void updateMetrics(Collection<Metrics> metricsList) {
|
85 |
0
| this.metricsList = new ArrayList<Metrics>(metricsList);
|
86 |
| |
87 |
0
| if (metricsList.isEmpty()) {
|
88 |
0
| buildMetricValues();
|
89 |
| } else { |
90 |
0
| Collections.sort(this.metricsList, comparator);
|
91 |
0
| buildMetricValues(this.metricsList);
|
92 |
| } |
93 |
| |
94 |
0
| fireTableDataChanged();
|
95 |
| } |
96 |
| |
97 |
0
| public void sortOn(String name, int dispose) {
|
98 |
0
| comparator.sortOn(name, dispose);
|
99 |
| |
100 |
0
| Collections.sort(metricsList, comparator);
|
101 |
0
| buildMetricValues(metricsList);
|
102 |
| |
103 |
0
| fireTableDataChanged();
|
104 |
| } |
105 |
| |
106 |
0
| private void buildMetricNames() {
|
107 |
0
| List<String> names = new LinkedList<String>();
|
108 |
0
| names.add("name");
|
109 |
| |
110 |
0
| List<MeasurementDescriptor> columnDescriptors = new LinkedList<MeasurementDescriptor>();
|
111 |
0
| columnDescriptors.add(null);
|
112 |
| |
113 |
0
| List<Integer> dispose = new LinkedList<Integer>();
|
114 |
0
| dispose.add(LOCAL_DISPOSE_IGNORE);
|
115 |
| |
116 |
0
| for (MeasurementDescriptor descriptor : descriptors) {
|
117 |
0
| if (descriptor.isVisible()) {
|
118 |
0
| if (descriptor.getClassFor().equals(StatisticalMeasurement.class)) {
|
119 |
0
| names.add(descriptor.getShortName());
|
120 |
0
| columnDescriptors.add(descriptor);
|
121 |
0
| dispose.add(LOCAL_DISPOSE_MINIMUM);
|
122 |
0
| names.add(descriptor.getShortName());
|
123 |
0
| columnDescriptors.add(descriptor);
|
124 |
0
| dispose.add(LOCAL_DISPOSE_MEDIAN);
|
125 |
0
| names.add(descriptor.getShortName());
|
126 |
0
| columnDescriptors.add(descriptor);
|
127 |
0
| dispose.add(LOCAL_DISPOSE_AVERAGE);
|
128 |
0
| names.add(descriptor.getShortName());
|
129 |
0
| columnDescriptors.add(descriptor);
|
130 |
0
| dispose.add(LOCAL_DISPOSE_STANDARD_DEVIATION);
|
131 |
0
| names.add(descriptor.getShortName());
|
132 |
0
| columnDescriptors.add(descriptor);
|
133 |
0
| dispose.add(LOCAL_DISPOSE_MAXIMUM);
|
134 |
0
| names.add(descriptor.getShortName());
|
135 |
0
| columnDescriptors.add(descriptor);
|
136 |
0
| dispose.add(LOCAL_DISPOSE_SUM);
|
137 |
| } else { |
138 |
0
| names.add(descriptor.getShortName());
|
139 |
0
| columnDescriptors.add(descriptor);
|
140 |
0
| dispose.add(LOCAL_DISPOSE_IGNORE);
|
141 |
| } |
142 |
| } |
143 |
| } |
144 |
| |
145 |
0
| measurementNames = names.toArray(new String[0]);
|
146 |
0
| measurementDescriptors = columnDescriptors.toArray(new MeasurementDescriptor[0]);
|
147 |
0
| measurementDispose = new int[dispose.size()];
|
148 |
0
| for (int j=0; j<dispose.size(); j++) {
|
149 |
0
| measurementDispose[j] = dispose.get(j);
|
150 |
| } |
151 |
| } |
152 |
| |
153 |
0
| private void buildMetricValues() {
|
154 |
0
| measurementValues = new Object[0][];
|
155 |
| } |
156 |
| |
157 |
0
| private void buildMetricValues(Collection<Metrics> metricsList) {
|
158 |
0
| measurementValues = new Object[metricsList.size()][];
|
159 |
| |
160 |
0
| int i = 0;
|
161 |
0
| for (Metrics currentMetrics : metricsList) {
|
162 |
0
| List<Measurement> measurements = new ArrayList<Measurement>(measurementNames.length);
|
163 |
0
| for (MeasurementDescriptor descriptor : descriptors) {
|
164 |
0
| if (descriptor.isVisible()) {
|
165 |
0
| Measurement measurement = currentMetrics.getMeasurement(descriptor.getShortName());
|
166 |
| |
167 |
0
| if (measurement instanceof StatisticalMeasurement) {
|
168 |
0
| measurements.add(measurement);
|
169 |
0
| measurements.add(measurement);
|
170 |
0
| measurements.add(measurement);
|
171 |
0
| measurements.add(measurement);
|
172 |
0
| measurements.add(measurement);
|
173 |
0
| measurements.add(measurement);
|
174 |
| } else { |
175 |
0
| measurements.add(measurement);
|
176 |
| } |
177 |
| } |
178 |
| } |
179 |
| |
180 |
0
| measurementValues[i] = new Object[measurements.size() + 1];
|
181 |
| |
182 |
0
| int j = 0;
|
183 |
0
| measurementValues[i][j++] = currentMetrics.getName();
|
184 |
0
| for (Measurement measurement : measurements) {
|
185 |
0
| measurementValues[i][j++] = measurement;
|
186 |
| } |
187 |
| |
188 |
0
| i++;
|
189 |
| } |
190 |
| } |
191 |
| |
192 |
0
| public int getColumnCount() {
|
193 |
0
| return measurementNames.length;
|
194 |
| } |
195 |
| |
196 |
0
| public int getRowCount() {
|
197 |
0
| return measurementValues.length;
|
198 |
| } |
199 |
| |
200 |
0
| public Object getValueAt(int rowIndex, int columnIndex) {
|
201 |
0
| return measurementValues[rowIndex][columnIndex];
|
202 |
| } |
203 |
| |
204 |
0
| public String getRawColumnName(int column) {
|
205 |
0
| return measurementNames[column];
|
206 |
| } |
207 |
| |
208 |
0
| public int getRawColumnDispose(int column) {
|
209 |
0
| return measurementDispose[column];
|
210 |
| } |
211 |
| |
212 |
0
| public String getColumnName(int column) {
|
213 |
0
| String result = getRawColumnName(column);
|
214 |
| |
215 |
0
| switch (getRawColumnDispose(column)) {
|
216 |
0
| case StatisticalMeasurement.DISPOSE_MINIMUM:
|
217 |
0
| case StatisticalMeasurement.DISPOSE_MEDIAN:
|
218 |
0
| case StatisticalMeasurement.DISPOSE_AVERAGE:
|
219 |
0
| case StatisticalMeasurement.DISPOSE_STANDARD_DEVIATION:
|
220 |
0
| case StatisticalMeasurement.DISPOSE_MAXIMUM:
|
221 |
0
| case StatisticalMeasurement.DISPOSE_SUM:
|
222 |
0
| result += " (" + StatisticalMeasurement.getDisposeAbbreviation(getRawColumnDispose(column)) + ")";
|
223 |
0
| break;
|
224 |
0
| case StatisticalMeasurement.DISPOSE_IGNORE:
|
225 |
0
| case StatisticalMeasurement.DISPOSE_NB_DATA_POINTS:
|
226 |
0
| default:
|
227 |
| |
228 |
0
| break;
|
229 |
| } |
230 |
| |
231 |
0
| return result;
|
232 |
| } |
233 |
| } |