1   package com.stateofflow.eclipse.metrics.export.html.histogram;
2   
3   import java.io.IOException;
4   
5   import com.stateofflow.eclipse.metrics.collator.MetricsCollator;
6   import com.stateofflow.eclipse.metrics.collator.MetricsCollatorSet;
7   import com.stateofflow.eclipse.metrics.metric.MetricId;
8   import com.stateofflow.eclipse.metrics.util.ProgressMonitor;
9   
10  public final class HistogramWriter {
11      private final HistogramFactory factory;
12  
13      public HistogramWriter(final HistogramFactory factory) {
14          this.factory = factory;
15      }
16  
17      private void createImages(final MetricsCollator collator, final String level, final ProgressMonitor progressMonitor) throws IOException {
18          final MetricId[] metricIds = collator.getMetricIds();
19          progressMonitor.beginTask("Creating images for " + level + " metrics", metricIds.length);
20          final JpegProducer producer = factory.createJpegProducer();
21          for (int i = 0; i < metricIds.length; i++) {
22              producer.produce(factory.getImageFile(metricIds[i]), collator, metricIds[i]);
23              progressMonitor.worked(1);
24          }
25      }
26  
27      public void write(final MetricsCollatorSet collatorSet, final ProgressMonitor progressMonitor) throws IOException {
28          progressMonitor.beginTask("Creating Images", 2);
29          createImages(collatorSet.getMethodMetrics(), "method", progressMonitor.newChild(1));
30          createImages(collatorSet.getTypeMetrics(), "type", progressMonitor.newChild(1));
31      }
32  }
33