← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5337: Codestyle mapgeneration module

 

------------------------------------------------------------
revno: 5337
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-12-09 11:29:57 +0100
message:
  Codestyle mapgeneration module
modified:
  dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMap.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapObject.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsPrimitiveFromJsonFactory.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMap.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Utilities.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapLayerTest.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapObjectTest.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapTest.java
  dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapGeneratorServiceTest.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml'
--- dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml	2011-12-09 00:02:59 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/pom.xml	2011-12-09 10:29:57 +0000
@@ -58,6 +58,10 @@
       <version>8.0-M3</version>
 	  <exclusions>
         <exclusion>
+          <groupId>xalan</groupId>
+          <artifactId>xalan</artifactId>
+        </exclusion>
+        <exclusion>
           <groupId>xerces</groupId>
           <artifactId>xercesImpl</artifactId>
         </exclusion>

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMap.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMap.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMap.java	2011-12-09 10:29:57 +0000
@@ -36,119 +36,141 @@
  * @author Kjetil Andresen <kjetand@xxxxxxxxxx>
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class GeoToolsMap extends InternalMap {
-
+public class GeoToolsMap
+    extends InternalMap
+{
     // The flat list of map objects in this map.
-    List<GeoToolsMapObject> mapObjects;
-    
+    private List<GeoToolsMapObject> mapObjects;
+
     /**
      * Creates an empty map.
      */
-    public GeoToolsMap() {
+    public GeoToolsMap()
+    {
         this.mapObjects = new LinkedList<GeoToolsMapObject>();
     }
 
     /**
      * Creates a map with the given initial map layer.
+     * 
      * @param layer the initial map layer
      */
-    public GeoToolsMap(InternalMapLayer layer) {
+    public GeoToolsMap( InternalMapLayer layer )
+    {
         this.mapObjects = new LinkedList<GeoToolsMapObject>();
-        this.addMapLayer(layer);
+        this.addMapLayer( layer );
     }
 
     /**
      * Creates a map with the given initial map layers.
+     * 
      * @param layers the list of initial map layers
      */
-    public GeoToolsMap(List<InternalMapLayer> layers) {
+    public GeoToolsMap( List<InternalMapLayer> layers )
+    {
         this.mapObjects = new LinkedList<GeoToolsMapObject>();
-        this.addAllMapLayers(layers);
+        this.addAllMapLayers( layers );
     }
 
     /**
      * Adds a map object to this map.
+     * 
      * @param mapObject the map object
      */
-    public void addMapObject(GeoToolsMapObject mapObject) {
-        this.mapObjects.add(mapObject);
+    public void addMapObject( GeoToolsMapObject mapObject )
+    {
+        this.mapObjects.add( mapObject );
     }
 
     /**
      * Adds all map objects contained in the list.
+     * 
      * @param mapObjects the list of map objects
      */
-    public void addMapObjects(List<GeoToolsMapObject> mapObjects) {
-        this.mapObjects.addAll(mapObjects);
+    public void addMapObjects( List<GeoToolsMapObject> mapObjects )
+    {
+        this.mapObjects.addAll( mapObjects );
     }
 
     // -------------------------------------------------------------------------
     // InternalMap implementation
     // -------------------------------------------------------------------------
 
-    public void addMapLayer(InternalMapLayer layer) {
-        for (InternalMapObject mapObject : layer.getAllMapObjects()) {
-            this.addMapObject((GeoToolsMapObject) mapObject);
+    public void addMapLayer( InternalMapLayer layer )
+    {
+        for ( InternalMapObject mapObject : layer.getAllMapObjects() )
+        {
+            this.addMapObject( (GeoToolsMapObject) mapObject );
         }
     }
 
-    public void addAllMapLayers(List<InternalMapLayer> layers) {
-        for (InternalMapLayer layer : layers) {
-            for (InternalMapObject mapObject : layer.getAllMapObjects()) {
-                this.addMapObject((GeoToolsMapObject) mapObject);
+    public void addAllMapLayers( List<InternalMapLayer> layers )
+    {
+        for ( InternalMapLayer layer : layers )
+        {
+            for ( InternalMapObject mapObject : layer.getAllMapObjects() )
+            {
+                this.addMapObject( (GeoToolsMapObject) mapObject );
             }
         }
     }
-    
-    public BufferedImage render() {
-        return render(DEFAULT_MAP_WIDTH);
+
+    public BufferedImage render()
+    {
+        return render( DEFAULT_MAP_WIDTH );
     }
 
-    public BufferedImage render(int imageWidth) {
+    public BufferedImage render( int imageWidth )
+    {
         MapContent map = new MapContent();
 
         // Convert map objects to features, and add them to the map
-        for (GeoToolsMapObject mapObject : mapObjects) {
-            try {
-                map.addLayer(createFeatureLayerFromMapObject(mapObject));
-            } catch (SchemaException ex) {
-                System.err.println("Could not add map object: " + mapObject.toString() + ": " + ex.getMessage());
+        for ( GeoToolsMapObject mapObject : mapObjects )
+        {
+            try
+            {
+                map.addLayer( createFeatureLayerFromMapObject( mapObject ) );
+            }
+            catch ( SchemaException ex )
+            {
+                System.err.println( "Could not add map object: " + mapObject.toString() + ": " + ex.getMessage() );
             }
         }
 
         // Create a renderer for this map
         GTRenderer renderer = new StreamingRenderer();
-        renderer.setMapContent(map);
+        renderer.setMapContent( map );
 
         // Calculate image height
         // TODO Might want to add a margin of say 25 pixels surrounding the map
         ReferencedEnvelope mapBounds = map.getMaxBounds();
-        double imageHeightFactor = mapBounds.getSpan(1) / mapBounds.getSpan(0);
-        Rectangle imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.ceil(imageWidth * imageHeightFactor));
+        double imageHeightFactor = mapBounds.getSpan( 1 ) / mapBounds.getSpan( 0 );
+        Rectangle imageBounds = new Rectangle( 0, 0, imageWidth, (int) Math.ceil( imageWidth * imageHeightFactor ) );
 
         // Create an image and get the graphics context from it
-        BufferedImage image = new BufferedImage(
-                imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_ARGB);
+        BufferedImage image = new BufferedImage( imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_ARGB );
         Graphics2D g = (Graphics2D) image.getGraphics();
 
         // Draw a background if the background color is specified
         // NOTE It will be transparent otherwise, which is desired
-        if (backgroundColor != null) {
-            g.setColor(backgroundColor);
-            g.fill(imageBounds);
+        if ( backgroundColor != null )
+        {
+            g.setColor( backgroundColor );
+            g.fill( imageBounds );
         }
 
         // Enable anti-aliasing if specified
-        if (isAntiAliasingEnabled) {
-            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-                    RenderingHints.VALUE_ANTIALIAS_ON);
-        } else {
-            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-                    RenderingHints.VALUE_ANTIALIAS_OFF);
+        if ( isAntiAliasingEnabled )
+        {
+            g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
+        }
+        else
+        {
+            g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF );
         }
 
         // Render the map
-        renderer.paint(g, imageBounds, mapBounds);
+        renderer.paint( g, imageBounds, mapBounds );
 
         return image;
     }
@@ -160,72 +182,86 @@
     /*
      * Creates a feature layer based on a map object.
      */
-    private Layer createFeatureLayerFromMapObject(GeoToolsMapObject mapObject) throws SchemaException {
+    private Layer createFeatureLayerFromMapObject( GeoToolsMapObject mapObject )
+        throws SchemaException
+    {
         SimpleFeatureType featureType;
         SimpleFeatureBuilder featureBuilder;
         SimpleFeature feature;
         SimpleFeatureCollection featureCollection;
         Style style = null;
 
-        featureType = createFeatureType(mapObject.getGeometry());
-        featureBuilder = new SimpleFeatureBuilder(featureType);
-        featureBuilder.add(mapObject.getGeometry());
-        feature = featureBuilder.buildFeature(null);
+        featureType = createFeatureType( mapObject.getGeometry() );
+        featureBuilder = new SimpleFeatureBuilder( featureType );
+        featureBuilder.add( mapObject.getGeometry() );
+        feature = featureBuilder.buildFeature( null );
 
         featureCollection = FeatureCollections.newCollection();
-        featureCollection.add(feature);
+        featureCollection.add( feature );
 
         // Create style for this map object
-        if (mapObject.getGeometry() instanceof Point) {
-            style = SLD.createPointStyle(null, mapObject.getStrokeColor(),
-                    mapObject.getFillColor(), mapObject.getFillOpacity(),
-                    mapObject.getRadius());
-        } else if (mapObject.getGeometry() instanceof Polygon
-                || mapObject.getGeometry() instanceof MultiPolygon) {
-            style = SLD.createPolygonStyle(mapObject.getStrokeColor(),
-                    mapObject.getFillColor(), mapObject.getFillOpacity());
-        } else {
-            style = SLD.createSimpleStyle(featureType);
-        }
-        
-        return new FeatureLayer(featureCollection, style);
+        if ( mapObject.getGeometry() instanceof Point )
+        {
+            style = SLD.createPointStyle( null, mapObject.getStrokeColor(), mapObject.getFillColor(),
+                mapObject.getFillOpacity(), mapObject.getRadius() );
+        }
+        else if ( mapObject.getGeometry() instanceof Polygon || mapObject.getGeometry() instanceof MultiPolygon )
+        {
+            style = SLD.createPolygonStyle( mapObject.getStrokeColor(), mapObject.getFillColor(),
+                mapObject.getFillOpacity() );
+        }
+        else
+        {
+            style = SLD.createSimpleStyle( featureType );
+        }
+
+        return new FeatureLayer( featureCollection, style );
     }
 
     /*
      * Creates a feature type for a GeoTools geometric primitive.
      */
-    private SimpleFeatureType createFeatureType(Geometry geom) throws SchemaException {
+    private SimpleFeatureType createFeatureType( Geometry geom )
+        throws SchemaException
+    {
         String type = "";
 
-        if (geom instanceof Point) {
+        if ( geom instanceof Point )
+        {
             type = "Point";
-        } else if (geom instanceof Polygon) {
+        }
+        else if ( geom instanceof Polygon )
+        {
             type = "Polygon";
-        } else if (geom instanceof MultiPolygon) {
+        }
+        else if ( geom instanceof MultiPolygon )
+        {
             type = "MultiPolygon";
-        } else {
+        }
+        else
+        {
             throw new IllegalArgumentException();
         }
 
-        return DataUtilities.createType(
-                "geometries", "geometry:" + type + ":srid=3785");
+        return DataUtilities.createType( "geometries", "geometry:" + type + ":srid=3785" );
     }
-    
+
     /*
-     * Creates an image with text indicating an error. 
+     * Creates an image with text indicating an error.
      */
-    @SuppressWarnings("unused")
-    private BufferedImage createErrorImage(String error) {
+    @SuppressWarnings( "unused" )
+    private BufferedImage createErrorImage( String error )
+    {
         String str = "Error creating map image: " + error;
-        BufferedImage image = new BufferedImage(500, 25, BufferedImage.TYPE_INT_RGB);
+        BufferedImage image = new BufferedImage( 500, 25, BufferedImage.TYPE_INT_RGB );
         Graphics2D g = (Graphics2D) image.createGraphics();
-        
-        g.setColor(Color.WHITE);
-        g.fill(new Rectangle(500, 25));
-        
-        g.setColor(Color.RED);
-        g.drawString(str, 1, 12);
-        
+
+        g.setColor( Color.WHITE );
+        g.fill( new Rectangle( 500, 25 ) );
+
+        g.setColor( Color.RED );
+        g.drawString( str, 1, 12 );
+
         return image;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java	2011-12-09 10:29:57 +0000
@@ -17,57 +17,62 @@
 import org.springframework.util.Assert;
 
 /**
- * An implementation of MapGenerationService that uses GeoTools to generate maps.
+ * An implementation of MapGenerationService that uses GeoTools to generate
+ * maps.
  * 
  * @author Kenneth Solbø Andersen <kennetsa@xxxxxxxxxx>
  * @author Kristin Simonsen <krissimo@xxxxxxxxxx>
  * @author Kjetil Andresen <kjetand@xxxxxxxxxx>
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class GeoToolsMapGenerationService implements MapGenerationService {
-
+public class GeoToolsMapGenerationService
+    implements MapGenerationService
+{
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
-    
-    OrganisationUnitService organisationUnitService;
-    
-    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) {
+
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
         this.organisationUnitService = organisationUnitService;
     }
-    
-    MappingService mappingService;
-    
-    public void setMappingService( MappingService mappingService ) {
+
+    private MappingService mappingService;
+
+    public void setMappingService( MappingService mappingService )
+    {
         this.mappingService = mappingService;
     }
 
     // -------------------------------------------------------------------------
     // MapGenerationService implementation
     // -------------------------------------------------------------------------
-    
-    public BufferedImage generateMapImage(Map map) {
-
-        Assert.isTrue(map != null);
-        Assert.isTrue(map.getMapViews() != null);
-        Assert.isTrue(map.getMapViews().size() > 0);
-        
+
+    public BufferedImage generateMapImage( Map map )
+    {
+        Assert.isTrue( map != null );
+        Assert.isTrue( map.getMapViews() != null );
+        Assert.isTrue( map.getMapViews().size() > 0 );
+
         int height = 512;
-        
+
         // Build internal map layer representation
-        List<InternalMapLayer> mapLayers = buildInternalMapLayers(map.getMapViews());
+        List<InternalMapLayer> mapLayers = buildInternalMapLayers( map.getMapViews() );
 
-        // Build internal representation of a map using GeoTools, then render it to an image
-        GeoToolsMap gtMap = new GeoToolsMap(mapLayers);
-        BufferedImage mapImage = gtMap.render(height);
+        // Build internal representation of a map using GeoTools, then render it
+        // to an image
+        GeoToolsMap gtMap = new GeoToolsMap( mapLayers );
+        BufferedImage mapImage = gtMap.render( height );
 
         // Build the legend set, then render it to an image
-        LegendSet legendSet = new LegendSet(mapLayers);
-        BufferedImage legendImage = legendSet.render(height);
-        
+        LegendSet legendSet = new LegendSet( mapLayers );
+        BufferedImage legendImage = legendSet.render( height );
+
         // Combine the legend image and the map image into one image
-        BufferedImage finalImage = combineLegendAndMapImages(legendImage, mapImage);
-        
+        BufferedImage finalImage = combineLegendAndMapImages( legendImage, mapImage );
+
         return finalImage;
     }
 
@@ -76,155 +81,178 @@
     // -------------------------------------------------------------------------
 
     private static final String DEFAULT_COLOR_HIGH = "#ff0000";
+
     private static final String DEFAULT_COLOR_LOW = "#ffff00";
+
     private static final float DEFAULT_OPACITY = 0.75f;
+
     private static final String DEFAULT_STROKE_COLOR = "#ffffff";
+
     private static final int DEFAULT_STROKE_WIDTH = 1;
+
     private static final int DEFAULT_RADIUS_HIGH = 35;
+
     private static final int DEFAULT_RADIUS_LOW = 15;
-    
-    private List<InternalMapLayer> buildInternalMapLayers(List<MapView> mapViews) {
-        
+
+    private List<InternalMapLayer> buildInternalMapLayers( List<MapView> mapViews )
+    {
         // Create the list of internal map layers
         List<InternalMapLayer> mapLayers = new LinkedList<InternalMapLayer>();
 
         // Build internal layers for each external layer
-        for (MapView mapView : mapViews) {
-            mapLayers.add(buildSingleInternalMapLayer(mapView));
+        for ( MapView mapView : mapViews )
+        {
+            mapLayers.add( buildSingleInternalMapLayer( mapView ) );
         }
 
         return mapLayers;
     }
 
-    private InternalMapLayer buildSingleInternalMapLayer(MapView mapView) {
-        
-        Assert.isTrue(mapView != null);
-        Assert.isTrue(mapView.getMapValueType() != null);
-        
-        boolean isIndicator = "indicator".equals(mapView.getMapValueType());
-        
+    private InternalMapLayer buildSingleInternalMapLayer( MapView mapView )
+    {
+
+        Assert.isTrue( mapView != null );
+        Assert.isTrue( mapView.getMapValueType() != null );
+
+        boolean isIndicator = "indicator".equals( mapView.getMapValueType() );
+
         // Get the name from the external layer
         String name = mapView.getName();
-        
+
         // Get the period
         Period period = mapView.getPeriod();
-        
+
         // Get the low and high radii
         int radiusLow = !isIndicator ? mapView.getRadiusLow() : DEFAULT_RADIUS_LOW;
         int radiusHigh = !isIndicator ? mapView.getRadiusHigh() : DEFAULT_RADIUS_HIGH;
-        
-        // Get the low and high colors, typically in hexadecimal form, e.g. '#ff3200' is an orange color
-        Color colorLow = Utilities.createColorFromString(
-                mapView.getColorLow() != null ? mapView.getColorLow() : DEFAULT_COLOR_LOW);
-        Color colorHigh = Utilities.createColorFromString(
-                mapView.getColorHigh() != null ? mapView.getColorHigh() : DEFAULT_COLOR_HIGH);
-        
+
+        // Get the low and high colors, typically in hexadecimal form, e.g.
+        // '#ff3200' is an orange color
+        Color colorLow = Utilities.createColorFromString( mapView.getColorLow() != null ? mapView.getColorLow()
+            : DEFAULT_COLOR_LOW );
+        Color colorHigh = Utilities.createColorFromString( mapView.getColorHigh() != null ? mapView.getColorHigh()
+            : DEFAULT_COLOR_HIGH );
+
         // TODO MapView should be extended to feature opacity
         float opacity = DEFAULT_OPACITY;
-        
+
         // TODO MapView should be extended to feature stroke color
-        Color strokeColor = Utilities.createColorFromString(DEFAULT_STROKE_COLOR);
-        
+        Color strokeColor = Utilities.createColorFromString( DEFAULT_STROKE_COLOR );
+
         // TODO MapView might be extended to feature stroke width
         int strokeWidth = DEFAULT_STROKE_WIDTH;
 
         // Create and setup an internal layer
         InternalMapLayer mapLayer = new InternalMapLayer();
-        mapLayer.setName(name);
-        mapLayer.setPeriod(period);
-        mapLayer.setRadiusLow(radiusLow);
-        mapLayer.setRadiusHigh(radiusHigh);
-        mapLayer.setColorLow(colorLow);
-        mapLayer.setColorHigh(colorHigh);
-        mapLayer.setOpacity(opacity);
-        mapLayer.setStrokeColor(strokeColor);
-        mapLayer.setStrokeWidth(strokeWidth);
-        
+        mapLayer.setName( name );
+        mapLayer.setPeriod( period );
+        mapLayer.setRadiusLow( radiusLow );
+        mapLayer.setRadiusHigh( radiusHigh );
+        mapLayer.setColorLow( colorLow );
+        mapLayer.setColorHigh( colorHigh );
+        mapLayer.setOpacity( opacity );
+        mapLayer.setStrokeColor( strokeColor );
+        mapLayer.setStrokeWidth( strokeWidth );
+
         // Get the aggregated map values
-        // TODO Might make version of getIndicatorMapValues that takes Indicator and 
-        // parent OrganisationUnit *directly*, i.e. not from ID-s, since we have them
-        // NOTE There is no need to provide startDate and endDate as period is set
+        // TODO Might make version of getIndicatorMapValues that takes Indicator
+        // and
+        // parent OrganisationUnit *directly*, i.e. not from ID-s, since we have
+        // them
+        // NOTE There is no need to provide startDate and endDate as period is
+        // set
         Collection<AggregatedMapValue> mapValues;
-        if (mapView.getMapValueType().equals("dataelement")) {
-            mapValues = mappingService.getDataElementMapValues(
-                    mapView.getDataElement().getId(), mapView.getPeriod().getId(),
-                    mapView.getParentOrganisationUnit().getId(),
-                    mapView.getOrganisationUnitLevel().getLevel());
-        } else {
-            mapValues = mappingService.getIndicatorMapValues(
-                    mapView.getIndicator().getId(), mapView.getPeriod().getId(), 
-                    mapView.getParentOrganisationUnit().getId(),
-                    mapView.getOrganisationUnitLevel().getLevel());
-        }
-        
+        if ( mapView.getMapValueType().equals( "dataelement" ) )
+        {
+            mapValues = mappingService.getDataElementMapValues( mapView.getDataElement().getId(), mapView.getPeriod()
+                .getId(), mapView.getParentOrganisationUnit().getId(), mapView.getOrganisationUnitLevel().getLevel() );
+        }
+        else
+        {
+            mapValues = mappingService.getIndicatorMapValues( mapView.getIndicator().getId(), mapView.getPeriod()
+                .getId(), mapView.getParentOrganisationUnit().getId(), mapView.getOrganisationUnitLevel().getLevel() );
+        }
+
         // Build and set the internal GeoTools map objects for the layer
-        buildGeoToolsMapObjectsForMapLayer(mapLayer, mapValues);
-        
-        // Create an interval set for this map layer that distributes its map objects into their respective intervals
+        buildGeoToolsMapObjectsForMapLayer( mapLayer, mapValues );
+
+        // Create an interval set for this map layer that distributes its map
+        // objects into their respective intervals
         // TODO Make interval length a parameter
-        IntervalSet.applyIntervalSetToMapLayer(DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer, 5);
-        
-        // Update the radius of each map object in this map layer according to its map object's highest and lowest values
-        if (!isIndicator) {
+        IntervalSet.applyIntervalSetToMapLayer( DistributionStrategy.STRATEGY_EQUAL_RANGE, mapLayer, 5 );
+
+        // Update the radius of each map object in this map layer according to
+        // its map object's highest and lowest values
+        if ( !isIndicator )
+        {
             mapLayer.applyInterpolatedRadii();
         }
-        
+
         return mapLayer;
     }
-    
-    private List<GeoToolsMapObject> buildGeoToolsMapObjectsForMapLayer(InternalMapLayer mapLayer, Collection<AggregatedMapValue> mapValues) {
-        
+
+    private List<GeoToolsMapObject> buildGeoToolsMapObjectsForMapLayer( InternalMapLayer mapLayer,
+        Collection<AggregatedMapValue> mapValues )
+    {
+
         // Create a list of map objects
         List<GeoToolsMapObject> mapObjects = new LinkedList<GeoToolsMapObject>();
-        
+
         // Build internal map objects for each map value
-        for (AggregatedMapValue mapValue : mapValues) {
-            mapObjects.add(buildSingleGeoToolsMapObjectForMapLayer(mapLayer, mapValue));
+        for ( AggregatedMapValue mapValue : mapValues )
+        {
+            mapObjects.add( buildSingleGeoToolsMapObjectForMapLayer( mapLayer, mapValue ) );
         }
-        
+
         return mapObjects;
     }
-    
-    private GeoToolsMapObject buildSingleGeoToolsMapObjectForMapLayer(InternalMapLayer mapLayer, AggregatedMapValue mapValue) {
-        
+
+    private GeoToolsMapObject buildSingleGeoToolsMapObjectForMapLayer( InternalMapLayer mapLayer,
+        AggregatedMapValue mapValue )
+    {
+
         // Get the org unit for this map value
-        OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit(mapValue.getOrganisationUnitId());
-        
+        OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( mapValue.getOrganisationUnitId() );
+
         // Create and setup an internal map object
         GeoToolsMapObject mapObject = new GeoToolsMapObject();
-        mapObject.setName(orgUnit.getName());
-        mapObject.setValue(mapValue.getValue());
-        mapObject.setFillOpacity(mapLayer.getOpacity());
-        mapObject.setStrokeColor(mapLayer.getStrokeColor());
-        mapObject.setStrokeWidth(mapLayer.getStrokeWidth());
-        
-        // Build and set the GeoTools-specific geometric primitive that outlines the org unit on the map
-        mapObject.buildAndApplyGeometryForOrganisationUnit(orgUnit);
-        
+        mapObject.setName( orgUnit.getName() );
+        mapObject.setValue( mapValue.getValue() );
+        mapObject.setFillOpacity( mapLayer.getOpacity() );
+        mapObject.setStrokeColor( mapLayer.getStrokeColor() );
+        mapObject.setStrokeWidth( mapLayer.getStrokeWidth() );
+
+        // Build and set the GeoTools-specific geometric primitive that outlines
+        // the org unit on the map
+        mapObject.buildAndApplyGeometryForOrganisationUnit( orgUnit );
+
         // Add the map object to the map layer
-        mapLayer.addMapObject(mapObject);
+        mapLayer.addMapObject( mapObject );
 
         // Set the map layer for the map object
-        mapObject.setMapLayer(mapLayer);
-        
+        mapObject.setMapLayer( mapLayer );
+
         return mapObject;
     }
-    
-    private BufferedImage combineLegendAndMapImages(BufferedImage legendImage, BufferedImage mapImage) {
-        
-        Assert.isTrue(legendImage != null);
-        Assert.isTrue(mapImage != null);
-        Assert.isTrue(legendImage.getType() == mapImage.getType());
-        
-        // Create a new image with dimension (legend.width + map.width, max(legend.height, map.height))
-        BufferedImage finalImage = new BufferedImage(
-                legendImage.getWidth() + mapImage.getWidth(), Math.max(mapImage.getHeight(), mapImage.getHeight()), mapImage.getType());
-        
-        // Draw the two images onto the final image with the legend to the left and the map to the right
+
+    private BufferedImage combineLegendAndMapImages( BufferedImage legendImage, BufferedImage mapImage )
+    {
+
+        Assert.isTrue( legendImage != null );
+        Assert.isTrue( mapImage != null );
+        Assert.isTrue( legendImage.getType() == mapImage.getType() );
+
+        // Create a new image with dimension (legend.width + map.width,
+        // max(legend.height, map.height))
+        BufferedImage finalImage = new BufferedImage( legendImage.getWidth() + mapImage.getWidth(), Math.max(
+            mapImage.getHeight(), mapImage.getHeight() ), mapImage.getType() );
+
+        // Draw the two images onto the final image with the legend to the left
+        // and the map to the right
         Graphics g = finalImage.getGraphics();
-        g.drawImage(legendImage, 0, 0, null);
-        g.drawImage(mapImage, legendImage.getWidth(), 0, null);
-        
+        g.drawImage( legendImage, 0, 0, null );
+        g.drawImage( mapImage, legendImage.getWidth(), 0, null );
+
         return finalImage;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapObject.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapObject.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapObject.java	2011-12-09 10:29:57 +0000
@@ -11,83 +11,84 @@
 
 import com.vividsolutions.jts.geom.Geometry;
 
-
 /**
- * This is an extension of InternalMapObject that describes map objects specific to the GeoTools platform.
+ * This is an extension of InternalMapObject that describes map objects specific
+ * to the GeoTools platform.
  * 
- * It encapsulates all the members of InternalMapObject with the extension to support addition of a 
- * single GeoTools geometric primitive that can be given to the GeoTools renderer directly to render 
- * the map, in addition to using the members of its superclass InternalMapObject.
+ * It encapsulates all the members of InternalMapObject with the extension to
+ * support addition of a single GeoTools geometric primitive that can be given
+ * to the GeoTools renderer directly to render the map, in addition to using the
+ * members of its superclass InternalMapObject.
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class GeoToolsMapObject extends InternalMapObject {
-
+public class GeoToolsMapObject
+    extends InternalMapObject
+{
     private Geometry geometry;
 
     /**
-     * Gets the geometry for this map object which is any of the GeoTools primitives.
+     * Gets the geometry for this map object which is any of the GeoTools
+     * primitives.
+     * 
      * @return the GeoTools geometric primitive
      */
-    public Geometry getGeometry() {
+    public Geometry getGeometry()
+    {
         return this.geometry;
     }
 
     /**
-     * Sets the geometry for this map object which is any of the GeoTools primitives.
+     * Sets the geometry for this map object which is any of the GeoTools
+     * primitives.
+     * 
      * @param geometry the GeoTools geometric primitive
      */
-    public void setGeometry(Geometry geometry) {
+    public void setGeometry( Geometry geometry )
+    {
         this.geometry = geometry;
     }
-    
+
     /**
-     * Builds the GeoTools geometric primitive for a given organisation unit and sets it for this map object.
+     * Builds the GeoTools geometric primitive for a given organisation unit and
+     * sets it for this map object.
      * 
      * Quick guide to how geometry is stored in DHIS:
      * 
-     * Geometry for org units is stored in the DB as [[[[0.32, -33.87], [23.99, -43.02], ...]]], 
-     * and may be retrieved by calling the getCoordinates method of OrganisationUnit.
-     * 
-     * The coordinates vary according to feature type, which can be found with a call to getFeatureType 
-     * of OrganisationUnit. It varies between the following structures (names are omitted in the actual 
-     * coordinates string):
-     * 
-     * multipolygon = [
-     *                 polygon0 = [
-     *                             shell0 = [
-     *                                       point0 = [0.32, -33.87],
-     *                                       point1 = [23.99, -43.02],
-     *                                       point2 = [...]],
-     *                             hole0 = [...],
-     *                             hole1 = [...]],
-     *                 polygon1 = [...]
-     *                 polygon2 = [...]]
-     * polygon = [
-     *            shell0 = [
-     *                      point0 = [0.32, -33.87],
-     *                      point1 = [23.99, -43.02]],
-     *            hole0 = [...],
-     *            hole1 = [...]]
+     * Geometry for org units is stored in the DB as [[[[0.32, -33.87], [23.99,
+     * -43.02], ...]]], and may be retrieved by calling the getCoordinates
+     * method of OrganisationUnit.
+     * 
+     * The coordinates vary according to feature type, which can be found with a
+     * call to getFeatureType of OrganisationUnit. It varies between the
+     * following structures (names are omitted in the actual coordinates
+     * string):
+     * 
+     * multipolygon = [ polygon0 = [ shell0 = [ point0 = [0.32, -33.87], point1
+     * = [23.99, -43.02], point2 = [...]], hole0 = [...], hole1 = [...]],
+     * polygon1 = [...] polygon2 = [...]] polygon = [ shell0 = [ point0 = [0.32,
+     * -33.87], point1 = [23.99, -43.02]], hole0 = [...], hole1 = [...]]
      * 
      * point = [0.32, -33.87]
      * 
-     * Multi-polygons are stored as an array of polygons. Polygons are stored as an array of 
-     * linear-rings, where the first linear-ring is the shell, and remaining linear-rings are 
-     * the holes in the polygon. Linear-rings are stored as an array of points, which in turn 
-     * is stored as an array of (two) components as a floating point type.
-     * 
-     * There are three types of geometry that may be stored in a DHIS org unit: point, 
-     * polygon, and multi-polygon. This method supports all three.
-     * 
-     * NOTE However, as of writing, there is a bug in DHIS OrganisationUnit where when 
-     * getFeatureType reports type Polygon, getCoordinates really returns coordinates in the 
-     * format of type MultiPolygon. 
+     * Multi-polygons are stored as an array of polygons. Polygons are stored as
+     * an array of linear-rings, where the first linear-ring is the shell, and
+     * remaining linear-rings are the holes in the polygon. Linear-rings are
+     * stored as an array of points, which in turn is stored as an array of
+     * (two) components as a floating point type.
+     * 
+     * There are three types of geometry that may be stored in a DHIS org unit:
+     * point, polygon, and multi-polygon. This method supports all three.
+     * 
+     * NOTE However, as of writing, there is a bug in DHIS OrganisationUnit
+     * where when getFeatureType reports type Polygon, getCoordinates really
+     * returns coordinates in the format of type MultiPolygon.
      * 
      * @param orgUnit the organisation unit
      */
-    public void buildAndApplyGeometryForOrganisationUnit(OrganisationUnit orgUnit) {
-        
+    public void buildAndApplyGeometryForOrganisationUnit( OrganisationUnit orgUnit )
+    {
+
         // The final GeoTools primitive
         Geometry primitive = null;
 
@@ -96,51 +97,62 @@
 
         // The json root that is parsed from the coordinate string
         JsonNode root = null;
-        
-        try {
+
+        try
+        {
             // Create a parser for the json and parse it into root
-            JsonParser parser = new ObjectMapper().getJsonFactory().createJsonParser(coords);
+            JsonParser parser = new ObjectMapper().getJsonFactory().createJsonParser( coords );
             root = parser.readValueAsTree();
-        } catch (JsonParseException ex) {
-            ex.printStackTrace();
-        } catch (JsonProcessingException ex) {
-            ex.printStackTrace();
-        } catch (IOException ex) {
+        }
+        catch ( JsonParseException ex )
+        {
+            ex.printStackTrace();
+        }
+        catch ( JsonProcessingException ex )
+        {
+            ex.printStackTrace();
+        }
+        catch ( IOException ex )
+        {
             ex.printStackTrace();
         }
 
         // Use the factory to build the correct type based on the feature type
-        // TODO There is a bug in MapView where Polygon really means MultiPolygon for some reason
-        if (OrganisationUnit.FEATURETYPE_POINT.equals(orgUnit.getFeatureType())) {
-            primitive = GeoToolsPrimitiveFromJsonFactory.createPointFromJson(root);
-        } else if (OrganisationUnit.FEATURETYPE_POLYGON.equals(orgUnit.getFeatureType())) {
-            primitive = GeoToolsPrimitiveFromJsonFactory.createMultiPolygonFromJson(root);          //< BUG, MUST CALL MULTIPOLYGON INSTEAD OF POLYGON
-        } else if (OrganisationUnit.FEATURETYPE_MULTIPOLYGON.equals(orgUnit.getFeatureType())) {
-            primitive = GeoToolsPrimitiveFromJsonFactory.createMultiPolygonFromJson(root);
-        } else {
-            throw new RuntimeException("Not sure what to do with the feature type '" + orgUnit.getFeatureType() + "'");
-        }
-        
+        // TODO There is a bug in MapView where Polygon really means
+        // MultiPolygon for some reason
+        if ( OrganisationUnit.FEATURETYPE_POINT.equals( orgUnit.getFeatureType() ) )
+        {
+            primitive = GeoToolsPrimitiveFromJsonFactory.createPointFromJson( root );
+        }
+        else if ( OrganisationUnit.FEATURETYPE_POLYGON.equals( orgUnit.getFeatureType() ) )
+        {
+            // < // BUG, MUST CALL MULTIPOLYGON INSTEAD OF POLYGON
+            primitive = GeoToolsPrimitiveFromJsonFactory.createMultiPolygonFromJson( root ); 
+        }
+        else if ( OrganisationUnit.FEATURETYPE_MULTIPOLYGON.equals( orgUnit.getFeatureType() ) )
+        {
+            primitive = GeoToolsPrimitiveFromJsonFactory.createMultiPolygonFromJson( root );
+        }
+        else
+        {
+            throw new RuntimeException( "Not sure what to do with the feature type '" + orgUnit.getFeatureType() + "'" );
+        }
+
         // Set the geometry for this map object
         this.geometry = primitive;
     }
-    
+
     /**
-     * Returns a string representing this object, e.g. "GeoToolsMapObject { name: 
-     * "Khambia", value: 34.22, radius: 1.00, fillColor: java.awt.Color(255, 
-     * 255, 255), fillOpacity: 0.75, strokeColor: java.awt.Color(0, 0, 0), 
-     * strokeWidth: 2, geometry: MULTIPOLYGON(((5.2 5.3)(8.2 9.5)(13.2 98.2))) }".
+     * Returns a string representing this object, e.g. "GeoToolsMapObject {
+     * name: "Khambia", value: 34.22, radius: 1.00, fillColor:
+     * java.awt.Color(255, 255, 255), fillOpacity: 0.75, strokeColor:
+     * java.awt.Color(0, 0, 0), strokeWidth: 2, geometry: MULTIPOLYGON(((5.2
+     * 5.3)(8.2 9.5)(13.2 98.2))) }".
      */
-    public String toString() {
-        return String.format("GeoToolsMapObject {" +
-                " name: \"%s\"," +
-                " value: %.2f," +
-                " radius: %d," +
-                " fillColor: %s," +
-                " fillOpacity: %.2f" +
-                " strokeColor: %s," +
-                " strokeWidth: %d" +
-                " geometry: %s" +
-                "}", name, value, radius, fillColor, fillOpacity, strokeColor, strokeWidth, geometry);
+    public String toString()
+    {
+        return String.format( "GeoToolsMapObject {" + " name: \"%s\"," + " value: %.2f," + " radius: %d,"
+            + " fillColor: %s," + " fillOpacity: %.2f" + " strokeColor: %s," + " strokeWidth: %d" + " geometry: %s"
+            + "}", name, value, radius, fillColor, fillOpacity, strokeColor, strokeWidth, geometry );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsPrimitiveFromJsonFactory.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsPrimitiveFromJsonFactory.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsPrimitiveFromJsonFactory.java	2011-12-09 10:29:57 +0000
@@ -17,53 +17,57 @@
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class GeoToolsPrimitiveFromJsonFactory {
-
+public class GeoToolsPrimitiveFromJsonFactory
+{
     // Factory creating GeoTools geometric primitives
-    private static final GeometryFactory factory = JTSFactoryFinder.getGeometryFactory(null);
-    
+    private static final GeometryFactory factory = JTSFactoryFinder.getGeometryFactory( null );
+
     /**
      * Create a GeoTools geometric point primitive from coordinates in json.
      * 
      * @param json the json array of components
      * @return the point
      */
-    public static Point createPointFromJson(JsonNode json) {
-        return factory.createPoint(createCoordinateFromJson(json));
+    public static Point createPointFromJson( JsonNode json )
+    {
+        return factory.createPoint( createCoordinateFromJson( json ) );
     }
 
     /**
-     * Create a GeoTools geometric coordinate primitive from coordinates in json.
+     * Create a GeoTools geometric coordinate primitive from coordinates in
+     * json.
      * 
      * @param json the json array of components
      * @return the coordinate
      */
-    public static Coordinate createCoordinateFromJson(JsonNode json) {
-        
+    public static Coordinate createCoordinateFromJson( JsonNode json )
+    {
+
         // Parse the double values from the json and create the coordinate
-        return new Coordinate(
-                json.get(0).getValueAsDouble(),
-                json.get(1).getValueAsDouble());
+        return new Coordinate( json.get( 0 ).getValueAsDouble(), json.get( 1 ).getValueAsDouble() );
     }
 
     /**
-     * Create a GeoTools geometric multi-polygon primitive from coordinates in json.
+     * Create a GeoTools geometric multi-polygon primitive from coordinates in
+     * json.
      * 
      * @param json the json array of polygons
      * @return the multi-polygon
      * @throws JSONException
      */
-    public static MultiPolygon createMultiPolygonFromJson(JsonNode json) {
+    public static MultiPolygon createMultiPolygonFromJson( JsonNode json )
+    {
         // Native array of polygons to pass to GeoFactory
         Polygon[] polygons = new Polygon[json.size()];
 
         // Read all the polygons from the json array
-        for (int i = 0; i < json.size(); i++) {
-            polygons[i] = createPolygonFromJson(json.get(i));
+        for ( int i = 0; i < json.size(); i++ )
+        {
+            polygons[i] = createPolygonFromJson( json.get( i ) );
         }
 
         // Create the multi-polygon from factory
-        return factory.createMultiPolygon(polygons);
+        return factory.createMultiPolygon( polygons );
     }
 
     /**
@@ -72,30 +76,33 @@
      * @param json the json array of linear ring
      * @return the polygon
      */
-    public static Polygon createPolygonFromJson(JsonNode json) {
-        
+    public static Polygon createPolygonFromJson( JsonNode json )
+    {
+
         // Get the json array of coordinates representing the shell and make a
         // linear-ring out of them
-        JsonNode shell = json.get(0);
-        LinearRing sh = createLinearRingFromJson(shell);
+        JsonNode shell = json.get( 0 );
+        LinearRing sh = createLinearRingFromJson( shell );
 
         // Native array of linear-ring holes to pass to GeoFactory
         LinearRing[] holes = null;
 
         // Get the linear-ring holes if the polygon has any holes
-        if (json.size() > 1) {
+        if ( json.size() > 1 )
+        {
             // Allocate memory for the holes, i.e. minus the shell
             holes = new LinearRing[shell.size() - 1];
 
             // Read the json array of linear-ring into holes
-            for (int i = 1; i < shell.size(); i++) {
-                JsonNode hole = json.get(i);
-                holes[i] = createLinearRingFromJson(hole);
+            for ( int i = 1; i < shell.size(); i++ )
+            {
+                JsonNode hole = json.get( i );
+                holes[i] = createLinearRingFromJson( hole );
             }
         }
 
         // Create the polygon from factory
-        return factory.createPolygon(sh, holes);
+        return factory.createPolygon( sh, holes );
     }
 
     /**
@@ -104,16 +111,18 @@
      * @param json the json array of coordinates
      * @return the linear-ring
      */
-    public static LinearRing createLinearRingFromJson(JsonNode json) {
+    public static LinearRing createLinearRingFromJson( JsonNode json )
+    {
         // Native array of coordinates to pass to GeoFactory
         Coordinate[] coords = new Coordinate[json.size()];
 
         // Read the json array of coordinates
-        for (int i = 0; i < json.size(); i++) {
-            coords[i] = createCoordinateFromJson(json.get(i));
+        for ( int i = 0; i < json.size(); i++ )
+        {
+            coords[i] = createCoordinateFromJson( json.get( i ) );
         }
 
         // Create the linear-ring from factory
-        return factory.createLinearRing(coords);
+        return factory.createLinearRing( coords );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMap.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMap.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMap.java	2011-12-09 10:29:57 +0000
@@ -7,17 +7,17 @@
 /**
  * An internal representation of a map.
  * 
- * It encapsulates all the information of a map built by adding layers to it. It may then create 
- * an image representing the map by a call to render.
+ * It encapsulates all the information of a map built by adding layers to it. It
+ * may then create an image representing the map by a call to render.
  * 
- * Finally, one should extend this class with an implementation that uses a specific 
- * platform, e.g. GeoTools to draw the map.
+ * Finally, one should extend this class with an implementation that uses a
+ * specific platform, e.g. GeoTools to draw the map.
  * 
  * @author Kjetil Andresen <kjetand@xxxxxxxxxx>
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public abstract class InternalMap {
-
+public abstract class InternalMap
+{
     // The background color used by this map.
     protected Color backgroundColor = null;
 
@@ -29,9 +29,11 @@
 
     /**
      * Gets the background color of this map.
+     * 
      * @return the background color, or null if not set
      */
-    public Color getBackgroundColor() {
+    public Color getBackgroundColor()
+    {
         return this.backgroundColor;
     }
 
@@ -39,52 +41,62 @@
      * Sets the background color of this map.
      * 
      * Setting this to null enables a transparent background.
+     * 
      * @param backgroundColor the background color
      */
-    public void setBackgroundColor(Color backgroundColor) {
+    public void setBackgroundColor( Color backgroundColor )
+    {
         this.backgroundColor = backgroundColor;
     }
 
     /**
      * Returns true if anti-aliasing is enabled for rendering, false otherwise.
+     * 
      * @return true if anti-aliasing is enabled, false otherwise
      */
-    public boolean isAntiAliasingEnabled() {
+    public boolean isAntiAliasingEnabled()
+    {
         return this.isAntiAliasingEnabled;
     }
 
     /**
      * Sets if anti-aliasing should be enabled for rendering.
+     * 
      * @param b true to enable anti-aliasing, false to disable
      */
-    public void setAntiAliasingEnabled(boolean b) {
+    public void setAntiAliasingEnabled( boolean b )
+    {
         this.isAntiAliasingEnabled = b;
     }
 
     /**
      * Adds a map layer to this map.
+     * 
      * @param layer the layer
      */
-    public abstract void addMapLayer(InternalMapLayer layer);
+    public abstract void addMapLayer( InternalMapLayer layer );
 
     /**
      * Adds all map layers contained in the list.
+     * 
      * @param layers the list of layers
      */
-    public abstract void addAllMapLayers(List<InternalMapLayer> layers);
+    public abstract void addAllMapLayers( List<InternalMapLayer> layers );
 
     /**
-     * Renders all map objects contained in this map to an image 
-     * with the default image width.
-     * @return the java.awt.image.BufferedImage representing this map 
+     * Renders all map objects contained in this map to an image with the
+     * default image width.
+     * 
+     * @return the java.awt.image.BufferedImage representing this map
      */
     public abstract BufferedImage render();
 
     /**
-     * Renders all map objects contained in this map to an image 
-     * with the specified width.
+     * Renders all map objects contained in this map to an image with the
+     * specified width.
+     * 
      * @param width the desired width of the map
      * @return the java.awt.image.BufferedImage representing this map
      */
-    public abstract BufferedImage render(int imageWidth);
+    public abstract BufferedImage render( int imageWidth );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapLayer.java	2011-12-09 10:29:57 +0000
@@ -10,168 +10,202 @@
 /**
  * An internal representation of a map layer in a map.
  * 
- * It encapsulates all the information of a layer on a map that should contain map objects associated 
- * with the same data-set. Thus, a map layer should represent grouped data from a data-set e.g. 'deaths 
- * from malaria' is one layer, 'anc coverage' is another layer, etc.
- * 
- * It is typically built using the properties of an external map layer (currently MapView) defined by the user.
- * 
- * Finally, one might extend this class with an implementation that uses a specific platform, if needed.
+ * It encapsulates all the information of a layer on a map that should contain
+ * map objects associated with the same data-set. Thus, a map layer should
+ * represent grouped data from a data-set e.g. 'deaths from malaria' is one
+ * layer, 'anc coverage' is another layer, etc.
+ * 
+ * It is typically built using the properties of an external map layer
+ * (currently MapView) defined by the user.
+ * 
+ * Finally, one might extend this class with an implementation that uses a
+ * specific platform, if needed.
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class InternalMapLayer {
-
+public class InternalMapLayer
+{
     protected String name;
-    
+
     protected Period period;
-    
+
     protected int radiusHigh;
-    
+
     protected int radiusLow;
-    
+
     protected Color colorHigh;
-    
+
     protected Color colorLow;
-    
+
     protected float opacity;
-    
+
     protected Color strokeColor;
-    
+
     protected int strokeWidth;
-    
+
     protected IntervalSet intervalSet;
-    
+
     protected Collection<InternalMapObject> mapObjects;
-    
+
     /**
      * Constructs a map layer with no initial map objects.
      */
-    public InternalMapLayer() {
-        
+    public InternalMapLayer()
+    {
+
         // Create a new list for the map objects in this map layer
         this.mapObjects = new ArrayList<InternalMapObject>();
     }
-    
+
     /**
-     * Interpolates the radii of this map layer's set of map objects according the highest and lowest values among them.
+     * Interpolates the radii of this map layer's set of map objects according
+     * the highest and lowest values among them.
      */
-    public void applyInterpolatedRadii() {
-        
-        Assert.isTrue(mapObjects != null);
-        Assert.isTrue(mapObjects.size() > 0);
-        
+    public void applyInterpolatedRadii()
+    {
+
+        Assert.isTrue( mapObjects != null );
+        Assert.isTrue( mapObjects.size() > 0 );
+
         InternalMapObject min = null, max = null;
-        
+
         // Determine the objects with the min and max values
-        for (InternalMapObject mapObject : mapObjects) {
-            if (min == null || mapObject.getValue() < min.getValue())
+        for ( InternalMapObject mapObject : mapObjects )
+        {
+            if ( min == null || mapObject.getValue() < min.getValue() )
                 min = mapObject;
-            if (max == null || mapObject.getValue() > max.getValue())
+            if ( max == null || mapObject.getValue() > max.getValue() )
                 max = mapObject;
         }
-        
-        // Determine and set the radius for each of the map objects according to its value
-        for (InternalMapObject mapObject : mapObjects) {
+
+        // Determine and set the radius for each of the map objects according to
+        // its value
+        for ( InternalMapObject mapObject : mapObjects )
+        {
             double factor = (mapObject.getValue() - min.getValue()) / (max.getValue() - min.getValue());
-            int radius = Utilities.lerp(radiusLow, radiusHigh, factor);
-            mapObject.setRadius(radius);
+            int radius = Utilities.lerp( radiusLow, radiusHigh, factor );
+            mapObject.setRadius( radius );
         }
     }
-    
+
     /**
      * Adds a map object to this map layer.
+     * 
      * @param mapObject the map object
      */
-    public void addMapObject(InternalMapObject mapObject) {
-        this.mapObjects.add(mapObject);
+    public void addMapObject( InternalMapObject mapObject )
+    {
+        this.mapObjects.add( mapObject );
     }
-    
+
     /**
-     * Gets the collection of all the map objects associated with this map layer.
+     * Gets the collection of all the map objects associated with this map
+     * layer.
+     * 
      * @return the list of map objects
      */
-    public Collection<InternalMapObject> getAllMapObjects() {
+    public Collection<InternalMapObject> getAllMapObjects()
+    {
         return this.mapObjects;
     }
-    
-    public String getName() {
+
+    public String getName()
+    {
         return this.name;
     }
-    
-    public void setName(String name) {
+
+    public void setName( String name )
+    {
         this.name = name;
     }
-    
-    public Period getPeriod() {
+
+    public Period getPeriod()
+    {
         return this.period;
     }
-    
-    public void setPeriod(Period period) {
+
+    public void setPeriod( Period period )
+    {
         this.period = period;
     }
-    
-    public int getRadiusHigh() {
+
+    public int getRadiusHigh()
+    {
         return this.radiusHigh;
     }
-    
-    public void setRadiusHigh(int radiusHigh) {
+
+    public void setRadiusHigh( int radiusHigh )
+    {
         this.radiusHigh = radiusHigh;
     }
-    
-    public int getRadiusLow() {
+
+    public int getRadiusLow()
+    {
         return this.radiusLow;
     }
-    
-    public void setRadiusLow(int radiusLow) {
+
+    public void setRadiusLow( int radiusLow )
+    {
         this.radiusLow = radiusLow;
     }
-    
-    public Color getColorHigh() {
+
+    public Color getColorHigh()
+    {
         return this.colorHigh;
     }
-    
-    public void setColorHigh(Color colorHigh) {
+
+    public void setColorHigh( Color colorHigh )
+    {
         this.colorHigh = colorHigh;
     }
-    
-    public Color getColorLow() {
+
+    public Color getColorLow()
+    {
         return this.colorLow;
     }
-    
-    public void setColorLow(Color colorLow) {
+
+    public void setColorLow( Color colorLow )
+    {
         this.colorLow = colorLow;
     }
-    
-    public float getOpacity() {
+
+    public float getOpacity()
+    {
         return this.opacity;
     }
-    
-    public void setOpacity(float opacity) {
+
+    public void setOpacity( float opacity )
+    {
         this.opacity = opacity;
     }
-    
-    public Color getStrokeColor() {
+
+    public Color getStrokeColor()
+    {
         return this.strokeColor;
     }
-    
-    public void setStrokeColor(Color strokeColor) {
+
+    public void setStrokeColor( Color strokeColor )
+    {
         this.strokeColor = strokeColor;
     }
-    
-    public int getStrokeWidth() {
+
+    public int getStrokeWidth()
+    {
         return this.strokeWidth;
     }
-    
-    public void setStrokeWidth(int strokeWidth) {
+
+    public void setStrokeWidth( int strokeWidth )
+    {
         this.strokeWidth = strokeWidth;
     }
-    
-    public IntervalSet getIntervalSet() {
+
+    public IntervalSet getIntervalSet()
+    {
         return this.intervalSet;
     }
-    
-    public void setIntervalSet(IntervalSet intervalSet) {
+
+    public void setIntervalSet( IntervalSet intervalSet )
+    {
         this.intervalSet = intervalSet;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/InternalMapObject.java	2011-12-09 10:29:57 +0000
@@ -5,198 +5,230 @@
 /**
  * An internal representation of a map object in a map layer.
  * 
- * It encapsulates all the information of an atomic object on a map, i.e. its 
- * name, value, fill color, fill opacity, stroke color, stroke width, and potentially 
- * its radius should it be represented as a point.
- * 
- * It may be the associated with an interval of an interval set and should be associated 
- * with a map layer.
- * 
- * Finally, one should extend this class with an implementation that uses a specific 
- * platform, e.g. GeoTools to draw the map.
+ * It encapsulates all the information of an atomic object on a map, i.e. its
+ * name, value, fill color, fill opacity, stroke color, stroke width, and
+ * potentially its radius should it be represented as a point.
+ * 
+ * It may be the associated with an interval of an interval set and should be
+ * associated with a map layer.
+ * 
+ * Finally, one should extend this class with an implementation that uses a
+ * specific platform, e.g. GeoTools to draw the map.
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public abstract class InternalMapObject {
-
+public abstract class InternalMapObject
+{
     protected String name;
 
     protected double value;
-    
+
     protected int radius;
-    
+
     protected Color fillColor;
-    
+
     protected float fillOpacity;
-    
+
     protected Color strokeColor;
-    
+
     protected int strokeWidth;
-    
+
     protected InternalMapLayer mapLayer;
-    
+
     protected Interval interval;
 
     /**
      * Gets the name of this map object.
+     * 
      * @return the name
      */
-    public String getName() {
+    public String getName()
+    {
         return this.name;
     }
 
     /**
      * Sets the name of this map object.
+     * 
      * @param name the name
      */
-    public void setName(String name) {
+    public void setName( String name )
+    {
         this.name = name;
     }
 
     /**
      * Gets the value for this map object.
+     * 
      * @return the value
      */
-    public double getValue() {
+    public double getValue()
+    {
         return this.value;
     }
 
     /**
      * Sets the value for this map object.
+     * 
      * @param value the value
      */
-    public void setValue(double value) {
+    public void setValue( double value )
+    {
         this.value = value;
     }
 
     /**
      * Gets the radius for this map object (if point).
+     * 
      * @return the radius
      */
-    public int getRadius() {
+    public int getRadius()
+    {
         return this.radius;
     }
-    
+
     /**
      * Sets the radius for this map object (if point).
+     * 
      * @param radius the fill color
      */
-    public void setRadius(int radius) {
+    public void setRadius( int radius )
+    {
         this.radius = radius;
     }
 
     /**
      * Gets the fill color for this map object.
+     * 
      * @return the fill color
      */
-    public Color getFillColor() {
+    public Color getFillColor()
+    {
         return this.fillColor;
     }
-    
+
     /**
      * Sets the fill color for this map object.
+     * 
      * @param fillColor the fill color
      */
-    public void setFillColor(Color fillColor) {
+    public void setFillColor( Color fillColor )
+    {
         this.fillColor = fillColor;
     }
 
     /**
      * Gets the fill opacity for this object.
+     * 
      * @return the fill opacity
      */
-    public float getFillOpacity() {
+    public float getFillOpacity()
+    {
         return this.fillOpacity;
     }
-    
+
     /**
      * Sets the fill opacity for this object.
+     * 
      * @param fillOpacity the fill opacity
      */
-    public void setFillOpacity(float fillOpacity) {
+    public void setFillOpacity( float fillOpacity )
+    {
         this.fillOpacity = fillOpacity;
     }
-    
+
     /**
      * Gets the stroke color for this map object.
+     * 
      * @return the stroke color
      */
-    public Color getStrokeColor() {
+    public Color getStrokeColor()
+    {
         return this.strokeColor;
     }
-    
+
     /**
      * Sets the stroke color for this map object.
+     * 
      * @param strokeColor the stroke color
      */
-    public void setStrokeColor(Color strokeColor) {
+    public void setStrokeColor( Color strokeColor )
+    {
         this.strokeColor = strokeColor;
     }
-    
+
     /**
      * Gets the stroke width for this map object.
+     * 
      * @return the stroke width
      */
-    public int getStrokeWidth() {
+    public int getStrokeWidth()
+    {
         return this.strokeWidth;
     }
-    
+
     /**
      * Sets the stroke width for this map object.
+     * 
      * @param strokeWidth
      */
-    public void setStrokeWidth(int strokeWidth) {
+    public void setStrokeWidth( int strokeWidth )
+    {
         this.strokeWidth = strokeWidth;
     }
-    
+
     /**
      * Gets the map layer this map object is associated with.
+     * 
      * @return the map layer
      */
-    public InternalMapLayer getMapLayer() {
+    public InternalMapLayer getMapLayer()
+    {
         return this.mapLayer;
     }
-    
+
     /**
      * Sets the map layer this object is associated with.
+     * 
      * @param mapLayer the map layer
      */
-    public void setMapLayer(InternalMapLayer mapLayer) {
+    public void setMapLayer( InternalMapLayer mapLayer )
+    {
         this.mapLayer = mapLayer;
     }
-    
+
     /**
      * Gets the interval this map object is associated with.
+     * 
      * @return the interval
      */
-    public Interval getInterval() {
+    public Interval getInterval()
+    {
         return this.interval;
     }
-    
+
     /**
-     * Sets the interval this map object is associated with and updates this map object 
-     * with the properties (e.g. fill color) from the given interval.
+     * Sets the interval this map object is associated with and updates this map
+     * object with the properties (e.g. fill color) from the given interval.
+     * 
      * @param interval the interval
      */
-    public void setInterval(Interval interval) {
+    public void setInterval( Interval interval )
+    {
         this.interval = interval;
         this.fillColor = interval.getColor();
     }
-    
+
     /**
-     * Returns a string representing this object, e.g. "InternalMapObject { name: 
-     * "Khambia", value: 34.22, radius: 1.00, fillColor: java.awt.Color(255, 
-     * 255, 255), fillOpacity: 0.75, strokeColor: java.awt.Color(0, 0, 0), strokeWidth: 2 }".
+     * Returns a string representing this object, e.g. "InternalMapObject {
+     * name: "Khambia", value: 34.22, radius: 1.00, fillColor:
+     * java.awt.Color(255, 255, 255), fillOpacity: 0.75, strokeColor:
+     * java.awt.Color(0, 0, 0), strokeWidth: 2 }".
      */
-    public String toString() {
-        return String.format("InternalMapObject {" +
-                " name: \"%s\"," +
-                " value: %.2f," +
-                " radius: %d," +
-                " fillColor: %s," +
-                " fillOpacity: %.2f" +
-                " strokeColor: %s," +
-                " strokeWidth: %d" +
-                " }", name, value, radius, fillColor, fillOpacity, strokeColor, strokeWidth);
+    public String toString()
+    {
+        return String.format( "InternalMapObject {" + " name: \"%s\"," + " value: %.2f," + " radius: %d,"
+            + " fillColor: %s," + " fillOpacity: %.2f" + " strokeColor: %s," + " strokeWidth: %d" + " }", name, value,
+            radius, fillColor, fillOpacity, strokeColor, strokeWidth );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Interval.java	2011-12-09 10:29:57 +0000
@@ -5,97 +5,117 @@
 import java.util.List;
 
 /**
- * An interval is a collection of map objects that have been distributed into this interval.
+ * An interval is a collection of map objects that have been distributed into
+ * this interval.
  * 
- * It contains all the map objects that have values that lie in the range of values this interval covers.
+ * It contains all the map objects that have values that lie in the range of
+ * values this interval covers.
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class Interval {
-    
+public class Interval
+{
     /**
      * The color value associated with this interval.
      */
     private Color color;
-    
+
     /**
      * The low and high boundaries of values this interval covers.
      */
     private double valueLow, valueHigh;
-    
+
     /**
      * The map object members that fall into this interval category.
      */
     private List<InternalMapObject> members;
-    
-    public Interval(double valueLow, double valueHigh) {
+
+    public Interval( double valueLow, double valueHigh )
+    {
         this.valueLow = valueLow;
         this.valueHigh = valueHigh;
-        
+
         this.members = new LinkedList<InternalMapObject>();
     }
-    
+
     /**
      * Gets the low value of this interval.
+     * 
      * @return the low value
      */
-    public double getValueLow() {
+    public double getValueLow()
+    {
         return this.valueLow;
     }
-    
+
     /**
      * Sets the low value of this interval.
+     * 
      * @param valueLow the low value
      */
-    public void setValueLow(double valueLow) {
+    public void setValueLow( double valueLow )
+    {
         this.valueLow = valueLow;
     }
-    
+
     /**
      * Gets the high value of this interval.
+     * 
      * @return the high value
      */
-    public double getValueHigh() {
+    public double getValueHigh()
+    {
         return this.valueHigh;
     }
-    
+
     /**
      * Sets the high value of this interval.
+     * 
      * @param valueHigh the high value
      */
-    public void setValueHigh(double valueHigh) {
+    public void setValueHigh( double valueHigh )
+    {
         this.valueHigh = valueHigh;
     }
-    
+
     /**
      * Gets the color this interval has on the map.
+     * 
      * @return the color
      */
-    public Color getColor() {
+    public Color getColor()
+    {
         return this.color;
     }
-    
+
     /**
      * Sets the color this interval has on the map.
+     * 
      * @param color the color
      */
-    public void setColor(Color color) {
+    public void setColor( Color color )
+    {
         this.color = color;
     }
-    
+
     /**
      * Adds a map object to this interval category.
+     * 
      * @param member the member to add
      */
-    public void addMember(InternalMapObject member) {     
-        this.members.add(member);
+    public void addMember( InternalMapObject member )
+    {
+        this.members.add( member );
     }
-    
+
     /**
-     * Returns a list of the members that have fallen into this interval category, or null if none.
+     * Returns a list of the members that have fallen into this interval
+     * category, or null if none.
+     * 
      * @return the list of members
      */
-    public List<InternalMapObject> getMembers() {
+    public List<InternalMapObject> getMembers()
+    {
         return this.members;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/IntervalSet.java	2011-12-09 10:29:57 +0000
@@ -7,195 +7,226 @@
 import org.springframework.util.Assert;
 
 /**
- * An interval set is a collection of map objects that are distributed into intervals according to their value.
+ * An interval set is a collection of map objects that are distributed into
+ * intervals according to their value.
  * 
- * The core functionality of this class is encapsulated into its method applyIntervalSetToMapLayer, which 
- * takes a map layer as input, creates an interval set for it, and distributes its map objects into intervals 
- * according to the given distribution strategy.
+ * The core functionality of this class is encapsulated into its method
+ * applyIntervalSetToMapLayer, which takes a map layer as input, creates an
+ * interval set for it, and distributes its map objects into intervals according
+ * to the given distribution strategy.
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class IntervalSet {
-    
+public class IntervalSet
+{
     // The intervals in this set
     private List<Interval> intervals;
-    
+
     // The map object in this interval set with the lowest and highest values
     private InternalMapObject objectLow, objectHigh;
-    
+
     // The interval distrubution strategies
-    public enum DistributionStrategy { STRATEGY_EQUAL_RANGE, STRATEGY_EQUAL_SIZE }
-    
+    public enum DistributionStrategy
+    {
+        STRATEGY_EQUAL_RANGE, STRATEGY_EQUAL_SIZE
+    }
+
     /**
      * Creates and applies a fixed length interval set to the given map layer.
      * 
-     * How map objects are distributed among intervals depends on the distribution strategy 
-     * that is used, which may be either 'equal range' or 'equal size'.
+     * How map objects are distributed among intervals depends on the
+     * distribution strategy that is used, which may be either 'equal range' or
+     * 'equal size'.
      * 
-     * The 'equal range' strategy is defined by passing 
-     * DistributionStrategy.STRATEGY_EQUAL_RANGE to this method. It creates and applies to 
-     * the given map layer a fixed length interval set distributing map objects into intervals 
-     * that has the same range.
+     * The 'equal range' strategy is defined by passing
+     * DistributionStrategy.STRATEGY_EQUAL_RANGE to this method. It creates and
+     * applies to the given map layer a fixed length interval set distributing
+     * map objects into intervals that has the same range.
      * 
      * The 'equal size' strategy is defined by passing
-     * DistributionStrategy.STRATEGY_EQUAL_SIZE to this method. It creates and applies to 
-     * the given map layer a fixed length interval set distributing map objects into intervals 
-     * that has (optimally) the same amount of map objects.
-     * 
-     * For example, given the map object collection of a map layer [a:3,b:2,c:5,d:18,e:0,f:50,g:22], where the objects 
-     * with the lowest and highest values are e:0 and f:50, this collection of map objects will distribute differently 
-     * into intervals depending on the distribution strategy chosen.
-     * 
-     * Strategy 'equal range' with length 5:
-     * interval [e:0,b:2,a:3,c:5] range 0-10 size 4
-     * interval [d:18] range 11-20 size 1
-     * interval [g:22] range 21-30 size 1
-     * interval [] range 31-40 size 0
-     * interval [f:50] range 41-50 size 1
-     * 
-     * Strategy 'equal size' with length 5:
-     * interval [e:0,b:2] range 0-2 size 2
-     * interval [a:3,c:5] range 3-5 size 2
-     * interval [d:18] range 5-18 size 1
-     * interval [g:22] range 18-22 size 1
-     * interval [f:50] range 22-50 size 1
+     * DistributionStrategy.STRATEGY_EQUAL_SIZE to this method. It creates and
+     * applies to the given map layer a fixed length interval set distributing
+     * map objects into intervals that has (optimally) the same amount of map
+     * objects.
+     * 
+     * For example, given the map object collection of a map layer
+     * [a:3,b:2,c:5,d:18,e:0,f:50,g:22], where the objects with the lowest and
+     * highest values are e:0 and f:50, this collection of map objects will
+     * distribute differently into intervals depending on the distribution
+     * strategy chosen.
+     * 
+     * Strategy 'equal range' with length 5: interval [e:0,b:2,a:3,c:5] range
+     * 0-10 size 4 interval [d:18] range 11-20 size 1 interval [g:22] range
+     * 21-30 size 1 interval [] range 31-40 size 0 interval [f:50] range 41-50
+     * size 1
+     * 
+     * Strategy 'equal size' with length 5: interval [e:0,b:2] range 0-2 size 2
+     * interval [a:3,c:5] range 3-5 size 2 interval [d:18] range 5-18 size 1
+     * interval [g:22] range 18-22 size 1 interval [f:50] range 22-50 size 1
      * 
      * @param strategy the desired distribution strategy
      * @param mapLayer the map layer whose map objects to distribute
      * @param length the number of intervals in the set
      * @return the created interval set that was applied to this map layer
      */
-    public static IntervalSet applyIntervalSetToMapLayer(DistributionStrategy strategy, InternalMapLayer mapLayer, int length) {
-        if (DistributionStrategy.STRATEGY_EQUAL_RANGE == strategy) {
-            return applyEqualRangeIntervalSetToMapLayer(mapLayer, length);
-        } else if (DistributionStrategy.STRATEGY_EQUAL_SIZE == strategy) {
-            return applyEqualSizeIntervalSetToMapLayer(mapLayer, length);
-        }
-        else {
-            throw new RuntimeException("The interval distribution strategy " + strategy + " is not implemented (yet)!");
+    public static IntervalSet applyIntervalSetToMapLayer( DistributionStrategy strategy, InternalMapLayer mapLayer,
+        int length )
+    {
+        if ( DistributionStrategy.STRATEGY_EQUAL_RANGE == strategy )
+        {
+            return applyEqualRangeIntervalSetToMapLayer( mapLayer, length );
+        }
+        else if ( DistributionStrategy.STRATEGY_EQUAL_SIZE == strategy )
+        {
+            return applyEqualSizeIntervalSetToMapLayer( mapLayer, length );
+        }
+        else
+        {
+            throw new RuntimeException( "The interval distribution strategy " + strategy + " is not implemented (yet)!" );
         }
     }
-    
+
     /**
-     * Creates and applies to the given map layer a fixed length interval set distributing map objects into 
-     * intervals that has the same range.
+     * Creates and applies to the given map layer a fixed length interval set
+     * distributing map objects into intervals that has the same range.
+     * 
      * @param mapLayer the map layer whose map objects to distribute
      * @param length the number of equal sized intervals
      * @return the created interval set that was applied to this map layer
      */
-    private static IntervalSet applyEqualRangeIntervalSetToMapLayer(InternalMapLayer mapLayer, int length) {
-        
-        Assert.isTrue(mapLayer != null);
-        Assert.isTrue(length > 0);
-        Assert.isTrue(mapLayer.getAllMapObjects() != null);
-        Assert.isTrue(mapLayer.getAllMapObjects().size() > 0);
-        
+    private static IntervalSet applyEqualRangeIntervalSetToMapLayer( InternalMapLayer mapLayer, int length )
+    {
+
+        Assert.isTrue( mapLayer != null );
+        Assert.isTrue( length > 0 );
+        Assert.isTrue( mapLayer.getAllMapObjects() != null );
+        Assert.isTrue( mapLayer.getAllMapObjects().size() > 0 );
+
         IntervalSet set = new IntervalSet();
         set.intervals = new LinkedList<Interval>();
-        
+
         set.objectLow = null;
         set.objectHigh = null;
-        
+
         // Determine the objects with the min and max values
-        for (InternalMapObject mapObject : mapLayer.getAllMapObjects()) {
-            if (set.objectLow == null || mapObject.getValue() < set.objectLow.getValue())
+        for ( InternalMapObject mapObject : mapLayer.getAllMapObjects() )
+        {
+            if ( set.objectLow == null || mapObject.getValue() < set.objectLow.getValue() )
                 set.objectLow = mapObject;
-            if (set.objectHigh == null || mapObject.getValue() > set.objectHigh.getValue())
+            if ( set.objectHigh == null || mapObject.getValue() > set.objectHigh.getValue() )
                 set.objectHigh = mapObject;
         }
-        
-        // Determine and set the color for each of the intervals according to the highest and lowest values
-        for (int i = 0; i < length; i++) {
+
+        // Determine and set the color for each of the intervals according to
+        // the highest and lowest values
+        for ( int i = 0; i < length; i++ )
+        {
             // Determine the boundaries the interval covers
-            double low = Utilities.lerp(set.objectLow.getValue(), set.objectHigh.getValue(), (i + 0.0) / length);
-            double high = Utilities.lerp(set.objectLow.getValue(), set.objectHigh.getValue(), (i + 1.0) / length);
-            
+            double low = Utilities.lerp( set.objectLow.getValue(), set.objectHigh.getValue(), (i + 0.0) / length );
+            double high = Utilities.lerp( set.objectLow.getValue(), set.objectHigh.getValue(), (i + 1.0) / length );
+
             // Determine the color of the interval
-            Color color = Utilities.lerp(mapLayer.getColorLow(), mapLayer.getColorHigh(), (i + 0.5) / length);
-            
+            Color color = Utilities.lerp( mapLayer.getColorLow(), mapLayer.getColorHigh(), (i + 0.5) / length );
+
             // Create and setup a new interval
-            Interval in = new Interval(low, high);
-            in.setColor(color);
-            
+            Interval in = new Interval( low, high );
+            in.setColor( color );
+
             // Add it to the set
-            set.intervals.add(in);
+            set.intervals.add( in );
         }
-        
+
         // Distribute this map layer's objects among the intervals in the set
-        distributeAndUpdateMapObjectsForMapLayer(mapLayer, set);
-        
+        distributeAndUpdateMapObjectsForMapLayer( mapLayer, set );
+
         // Set this interval set for the map layer
-        mapLayer.setIntervalSet(set);
-        
+        mapLayer.setIntervalSet( set );
+
         return set;
     }
-    
+
     /**
-     * Creates and applies to the given map layer a fixed length interval set distributing map objects into 
-     * intervals that has (optimally) the same amount of map objects.
-     * TODO Implement this method
+     * Creates and applies to the given map layer a fixed length interval set
+     * distributing map objects into intervals that has (optimally) the same
+     * amount of map objects. TODO Implement this method
+     * 
      * @param mapLayer the map layer whose map objects to distribute
      * @param length the number of equal sized intervals
      * @return the created interval set that was applied to this map layer
      */
-    private static IntervalSet applyEqualSizeIntervalSetToMapLayer(InternalMapLayer mapLayer, int length) {
-        
-        Assert.isTrue(mapLayer != null);
-        Assert.isTrue(length > 0);
-        Assert.isTrue(mapLayer.getAllMapObjects() != null);
-        Assert.isTrue(mapLayer.getAllMapObjects().size() > 0);
-        
-        throw new RuntimeException("This distribution strategy is not implemented yet!");
+    private static IntervalSet applyEqualSizeIntervalSetToMapLayer( InternalMapLayer mapLayer, int length )
+    {
+
+        Assert.isTrue( mapLayer != null );
+        Assert.isTrue( length > 0 );
+        Assert.isTrue( mapLayer.getAllMapObjects() != null );
+        Assert.isTrue( mapLayer.getAllMapObjects().size() > 0 );
+
+        throw new RuntimeException( "This distribution strategy is not implemented yet!" );
     }
-    
+
     /**
-     * Distribute a map layer's map objects into the given interval set and update each map object with its interval.
+     * Distribute a map layer's map objects into the given interval set and
+     * update each map object with its interval.
+     * 
      * @param mapLayer the map layer whose objects to distribute
      * @param set the interval set
      */
-    private static void distributeAndUpdateMapObjectsForMapLayer(InternalMapLayer mapLayer, IntervalSet set) {
-        
+    private static void distributeAndUpdateMapObjectsForMapLayer( InternalMapLayer mapLayer, IntervalSet set )
+    {
+
         // For each map object, determine in which interval it belongs
-        for (InternalMapObject obj : mapLayer.getAllMapObjects()) {
-            for (Interval in : set.intervals) {
-                
-                // If the map object's value is within this interval's boundaries, add it to this interval
-                if (obj.getValue() >= in.getValueLow() && obj.getValue() <= in.getValueHigh()) {
-                    
-                    // Add map object to interval and set interval for map object
-                    in.addMember(obj);
-                    obj.setInterval(in);
-                    
+        for ( InternalMapObject obj : mapLayer.getAllMapObjects() )
+        {
+            for ( Interval in : set.intervals )
+            {
+
+                // If the map object's value is within this interval's
+                // boundaries, add it to this interval
+                if ( obj.getValue() >= in.getValueLow() && obj.getValue() <= in.getValueHigh() )
+                {
+
+                    // Add map object to interval and set interval for map
+                    // object
+                    in.addMember( obj );
+                    obj.setInterval( in );
+
                     // Do not add to more than one interval
                     break;
                 }
             }
-            
-            Assert.isTrue(obj.getInterval() != null);
+
+            Assert.isTrue( obj.getInterval() != null );
         }
     }
-    
+
     /**
      * Returns all the intervals in this interval set.
+     * 
      * @return the list of intervals
      */
-    public List<Interval> getAllIntervals() {
+    public List<Interval> getAllIntervals()
+    {
         return this.intervals;
     }
-    
+
     /**
      * Gets the map object with the lowest value in this interval set.
+     * 
      * @return the object with the lowest value
      */
-    public InternalMapObject getObjectLow() {
+    public InternalMapObject getObjectLow()
+    {
         return this.objectLow;
     }
-    
+
     /**
-     * Gets the map object with the highest value in this interval set 
+     * Gets the map object with the highest value in this interval set
+     * 
      * @return the object with the highest value
      */
-    public InternalMapObject getObjectHigh() {
+    public InternalMapObject getObjectHigh()
+    {
         return this.objectHigh;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Legend.java	2011-12-09 10:29:57 +0000
@@ -15,55 +15,64 @@
  * @author Kristin Simonsen <krissimo@xxxxxxxxxx>
  * @author Kjetil Andresen <kjetil.andrese@xxxxxxxxx>
  */
-public class Legend {
-
-	public static final Font TITLE_FONT = new Font("title", Font.BOLD, 15);
-	public static final Font PLAIN_FONT = new Font("plain", Font.PLAIN, 13);
-
-	private InternalMapLayer mapLayer;
-	private List<LegendItem> legendItems;
-	
-	private static final int HEADER_HEIGHT = 50;
-	
-	public Legend(InternalMapLayer mapLayer) {
-		this.mapLayer = mapLayer;
-		this.legendItems = new LinkedList<LegendItem>();
-
-		for (Interval interval : mapLayer.getIntervalSet().getAllIntervals()) {
-			addLegendItem(new LegendItem(interval));
-		}
-	}
-
-	public void draw(Graphics2D g) {
-		g.setColor(Color.BLACK);
-		g.setFont(TITLE_FONT);
-		g.drawString(mapLayer.getName(), 0, 15);
-		g.setFont(PLAIN_FONT);
-		g.drawString(mapLayer.getPeriod().getStartDateString() + "", 0, 35);
-
-		g.translate(0, HEADER_HEIGHT);
-
-		for (LegendItem legendItem : legendItems) {
-			legendItem.draw(g);
-			g.translate(0, legendItem.getHeight());
-		}
-	}
-
-	public int getHeight() {
-		int height = 0;
-
-		for (LegendItem legendItem : legendItems) {
-			height += legendItem.getHeight();
-		}
-
-		return HEADER_HEIGHT + height;
-	}
-
-	public List<LegendItem> getLegendItems() {
-		return legendItems;
-	}
-
-	public void addLegendItem(LegendItem legendItem) {
-		legendItems.add(legendItem);
-	}
+public class Legend
+{
+    public static final Font TITLE_FONT = new Font( "title", Font.BOLD, 15 );
+    public static final Font PLAIN_FONT = new Font( "plain", Font.PLAIN, 13 );
+
+    private InternalMapLayer mapLayer;
+
+    private List<LegendItem> legendItems;
+
+    private static final int HEADER_HEIGHT = 50;
+
+    public Legend( InternalMapLayer mapLayer )
+    {
+        this.mapLayer = mapLayer;
+        this.legendItems = new LinkedList<LegendItem>();
+
+        for ( Interval interval : mapLayer.getIntervalSet().getAllIntervals() )
+        {
+            addLegendItem( new LegendItem( interval ) );
+        }
+    }
+
+    public void draw( Graphics2D g )
+    {
+        g.setColor( Color.BLACK );
+        g.setFont( TITLE_FONT );
+        g.drawString( mapLayer.getName(), 0, 15 );
+        g.setFont( PLAIN_FONT );
+        g.drawString( mapLayer.getPeriod().getStartDateString() + "", 0, 35 );
+
+        g.translate( 0, HEADER_HEIGHT );
+
+        for ( LegendItem legendItem : legendItems )
+        {
+            legendItem.draw( g );
+            g.translate( 0, legendItem.getHeight() );
+        }
+    }
+
+    public int getHeight()
+    {
+        int height = 0;
+
+        for ( LegendItem legendItem : legendItems )
+        {
+            height += legendItem.getHeight();
+        }
+
+        return HEADER_HEIGHT + height;
+    }
+
+    public List<LegendItem> getLegendItems()
+    {
+        return legendItems;
+    }
+
+    public void addLegendItem( LegendItem legendItem )
+    {
+        legendItems.add( legendItem );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendItem.java	2011-12-09 10:29:57 +0000
@@ -13,44 +13,49 @@
  * @author Kristin Simonsen <krissimo@xxxxxxxxxx>
  * @author Kjetil Andresen <kjetil.andrese@xxxxxxxxx>
  */
-public class LegendItem {
-
-	private Interval interval;
-
-	private static final int WIDTH = 25;
-	private static final int HEIGHT = 20;
-
-	public LegendItem(Interval interval) {
-		this.interval = interval;
-	}
-
-	public void draw(Graphics2D g) {
-		String label = String.format("%.2f - %.2f (%d)",
-				interval.getValueLow(), interval.getValueHigh(), interval
-						.getMembers().size());
-		Stroke s = new BasicStroke(1.0f);
-		Rectangle r = new Rectangle(0, 0, WIDTH, HEIGHT);
-
-		g.setColor(interval.getColor());
-		g.fill(r);
-		g.setPaint(Color.BLACK);
-		g.setStroke(s);
-		g.draw(r);
-
-		g.setColor(Color.BLACK);
-		g.setFont(Legend.PLAIN_FONT);
-		g.drawString(label, WIDTH + 15, HEIGHT - 5);
-	}
-
-	public int getHeight() {
-		return HEIGHT;
-	}
-
-	public Interval getInterval() {
-		return interval;
-	}
-
-	public void setInterval(Interval interval) {
-		this.interval = interval;
-	}
+public class LegendItem
+{
+    private Interval interval;
+
+    private static final int WIDTH = 25;
+
+    private static final int HEIGHT = 20;
+
+    public LegendItem( Interval interval )
+    {
+        this.interval = interval;
+    }
+
+    public void draw( Graphics2D g )
+    {
+        String label = String.format( "%.2f - %.2f (%d)", interval.getValueLow(), interval.getValueHigh(), interval
+            .getMembers().size() );
+        Stroke s = new BasicStroke( 1.0f );
+        Rectangle r = new Rectangle( 0, 0, WIDTH, HEIGHT );
+
+        g.setColor( interval.getColor() );
+        g.fill( r );
+        g.setPaint( Color.BLACK );
+        g.setStroke( s );
+        g.draw( r );
+
+        g.setColor( Color.BLACK );
+        g.setFont( Legend.PLAIN_FONT );
+        g.drawString( label, WIDTH + 15, HEIGHT - 5 );
+    }
+
+    public int getHeight()
+    {
+        return HEIGHT;
+    }
+
+    public Interval getInterval()
+    {
+        return interval;
+    }
+
+    public void setInterval( Interval interval )
+    {
+        this.interval = interval;
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/LegendSet.java	2011-12-09 10:29:57 +0000
@@ -16,142 +16,165 @@
  * @author Kristin Simonsen <krissimo@xxxxxxxxxx>
  * @author Kjetil Andresen <kjetil.andrese@xxxxxxxxx>
  */
-public class LegendSet {
-
-	private List<Legend> legends;
-	private Color backgroundColor = null;
-
-	private static final int LEGEND_WIDTH = 250;
-	private static final int LEGEND_MARGIN_LEFT = 5;
-	private static final int LEGEND_MARGIN_BOTTOM = 20;
-
-	public LegendSet() {
-		legends = new LinkedList<Legend>();
-	}
-
-	public LegendSet(InternalMapLayer mapLayer) {
-		legends = new LinkedList<Legend>();
-		addMapLayer(mapLayer);
-	}
-
-	public LegendSet(List<InternalMapLayer> mapLayers) {
-		legends = new LinkedList<Legend>();
-		addMapLayers(mapLayers);
-	}
-
-	/**
-	 * Render the legends contained in this set onto a image. The width of the
-	 * image returned may vary, depending on how many columns of legends that is
-	 * added. The image height can be decided by the user, but if the biggest
-	 * legend is higher than imageMaxHeight, the height will automatically be
-	 * set to the height of this legend.
-	 * 
-	 * @param imageMaxHeight
-	 * @return
-	 */
-	public BufferedImage render(int imageMaxHeight) {
-		Dimension imageDimensions = calculateImageWidthAndHeight(imageMaxHeight);
-		int imageWidth = (int) imageDimensions.getWidth();
-		int imageHeight = (int) imageDimensions.getHeight();
-		BufferedImage image = new BufferedImage(imageWidth, imageHeight,
-				BufferedImage.TYPE_INT_ARGB);
-		Graphics2D g = (Graphics2D) image.getGraphics();
-
-		// Overwrite if one of the legends is bigger than imageMaxHeight
-		if (imageDimensions.getHeight() > imageMaxHeight) {
-			imageMaxHeight = (int) imageDimensions.getHeight();
-		}
-
-		// Draw a background if the background color is specified
+public class LegendSet
+{
+    private List<Legend> legends;
+
+    private Color backgroundColor = null;
+
+    private static final int LEGEND_WIDTH = 250;
+
+    private static final int LEGEND_MARGIN_LEFT = 5;
+
+    private static final int LEGEND_MARGIN_BOTTOM = 20;
+
+    public LegendSet()
+    {
+        legends = new LinkedList<Legend>();
+    }
+
+    public LegendSet( InternalMapLayer mapLayer )
+    {
+        legends = new LinkedList<Legend>();
+        addMapLayer( mapLayer );
+    }
+
+    public LegendSet( List<InternalMapLayer> mapLayers )
+    {
+        legends = new LinkedList<Legend>();
+        addMapLayers( mapLayers );
+    }
+
+    /**
+     * Render the legends contained in this set onto a image. The width of the
+     * image returned may vary, depending on how many columns of legends that is
+     * added. The image height can be decided by the user, but if the biggest
+     * legend is higher than imageMaxHeight, the height will automatically be
+     * set to the height of this legend.
+     * 
+     * @param imageMaxHeight
+     * @return
+     */
+    public BufferedImage render( int imageMaxHeight )
+    {
+        Dimension imageDimensions = calculateImageWidthAndHeight( imageMaxHeight );
+        int imageWidth = (int) imageDimensions.getWidth();
+        int imageHeight = (int) imageDimensions.getHeight();
+        BufferedImage image = new BufferedImage( imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB );
+        Graphics2D g = (Graphics2D) image.getGraphics();
+
+        // Overwrite if one of the legends is bigger than imageMaxHeight
+        if ( imageDimensions.getHeight() > imageMaxHeight )
+        {
+            imageMaxHeight = (int) imageDimensions.getHeight();
+        }
+
+        // Draw a background if the background color is specified
         // NOTE It will be transparent otherwise, which is desired
-		if (backgroundColor != null) {
-        	g.setColor(backgroundColor);
-        	g.fill(new Rectangle(0, 0, imageWidth, imageHeight));
-		}
-
-		// Turn anti-aliasing on
-		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
-				RenderingHints.VALUE_ANTIALIAS_ON);
-
-		int y = 0;
-		int col = 0;
-		AffineTransform orginalTransform = g.getTransform();
-
-		g.translate(LEGEND_MARGIN_LEFT, 0);
-
-		// Draw legends
-		for (Legend legend : legends) {
-			if (y + legend.getHeight() >= imageMaxHeight) {
-				col++;
-				y = 0;
-				g.setTransform(orginalTransform);
-				g.translate(col * LEGEND_WIDTH, 0);
-			}
-
-			legend.draw(g);
-			g.translate(0, LEGEND_MARGIN_BOTTOM);
-
-			y += legend.getHeight() + LEGEND_MARGIN_BOTTOM;
-		}
-
-		return image;
-	}
-
-	public void addLegend(Legend legend) {
-		legends.add(legend);
-	}
-
-	public void addLegends(List<Legend> legends) {
-		for (Legend legend : legends) {
-			addLegend(legend);
-		}
-	}
-
-	public void addMapLayer(InternalMapLayer mapLayer) {
-		legends.add(new Legend(mapLayer));
-	}
-
-	public void addMapLayers(List<InternalMapLayer> mapLayers) {
-		for (InternalMapLayer mapLayer : mapLayers) {
-			addMapLayer(mapLayer);
-		}
-	}
-
-	public List<Legend> getLegends() {
-		return legends;
-	}
-
-	public Color getBackground() {
-		return backgroundColor;
-	}
-
-	public void setBackground(Color c) {
-		backgroundColor = c;
-	}
-
-	private Dimension calculateImageWidthAndHeight(int maxImageHeight) {
-		int imageWidth = LEGEND_WIDTH;
-		int imageHeight = maxImageHeight;
-
-		// Ensure that every legend fits the maxImageHeight
-		for (Legend legend : legends) {
-			if (legend.getHeight() + LEGEND_MARGIN_BOTTOM > imageHeight) {
-				imageHeight = legend.getHeight() + LEGEND_MARGIN_BOTTOM;
-			}
-		}
-
-		int y = 0;
-
-		// Calculate image width
-		for (Legend legend : legends) {
-			if (legend.getHeight() + LEGEND_MARGIN_BOTTOM + y >= imageHeight) {
-				imageWidth += LEGEND_WIDTH;
-				y = 0;
-			}
-
-			y += legend.getHeight() + LEGEND_MARGIN_BOTTOM;
-		}
-
-		return new Dimension(imageWidth, imageHeight);
-	}
+        if ( backgroundColor != null )
+        {
+            g.setColor( backgroundColor );
+            g.fill( new Rectangle( 0, 0, imageWidth, imageHeight ) );
+        }
+
+        // Turn anti-aliasing on
+        g.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
+
+        int y = 0;
+        int col = 0;
+        AffineTransform orginalTransform = g.getTransform();
+
+        g.translate( LEGEND_MARGIN_LEFT, 0 );
+
+        // Draw legends
+        for ( Legend legend : legends )
+        {
+            if ( y + legend.getHeight() >= imageMaxHeight )
+            {
+                col++;
+                y = 0;
+                g.setTransform( orginalTransform );
+                g.translate( col * LEGEND_WIDTH, 0 );
+            }
+
+            legend.draw( g );
+            g.translate( 0, LEGEND_MARGIN_BOTTOM );
+
+            y += legend.getHeight() + LEGEND_MARGIN_BOTTOM;
+        }
+
+        return image;
+    }
+
+    public void addLegend( Legend legend )
+    {
+        legends.add( legend );
+    }
+
+    public void addLegends( List<Legend> legends )
+    {
+        for ( Legend legend : legends )
+        {
+            addLegend( legend );
+        }
+    }
+
+    public void addMapLayer( InternalMapLayer mapLayer )
+    {
+        legends.add( new Legend( mapLayer ) );
+    }
+
+    public void addMapLayers( List<InternalMapLayer> mapLayers )
+    {
+        for ( InternalMapLayer mapLayer : mapLayers )
+        {
+            addMapLayer( mapLayer );
+        }
+    }
+
+    public List<Legend> getLegends()
+    {
+        return legends;
+    }
+
+    public Color getBackground()
+    {
+        return backgroundColor;
+    }
+
+    public void setBackground( Color c )
+    {
+        backgroundColor = c;
+    }
+
+    private Dimension calculateImageWidthAndHeight( int maxImageHeight )
+    {
+        int imageWidth = LEGEND_WIDTH;
+        int imageHeight = maxImageHeight;
+
+        // Ensure that every legend fits the maxImageHeight
+        for ( Legend legend : legends )
+        {
+            if ( legend.getHeight() + LEGEND_MARGIN_BOTTOM > imageHeight )
+            {
+                imageHeight = legend.getHeight() + LEGEND_MARGIN_BOTTOM;
+            }
+        }
+
+        int y = 0;
+
+        // Calculate image width
+        for ( Legend legend : legends )
+        {
+            if ( legend.getHeight() + LEGEND_MARGIN_BOTTOM + y >= imageHeight )
+            {
+                imageWidth += LEGEND_WIDTH;
+                y = 0;
+            }
+
+            y += legend.getHeight() + LEGEND_MARGIN_BOTTOM;
+        }
+
+        return new Dimension( imageWidth, imageHeight );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Utilities.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Utilities.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/Utilities.java	2011-12-09 10:29:57 +0000
@@ -7,51 +7,57 @@
  * 
  * @author Olai Solheim <olais@xxxxxxxxxx>
  */
-public class Utilities {
-    
+public class Utilities
+{
     /**
      * Linear interpolation of int.
+     * 
      * @param a from
      * @param b to
      * @param t factor, typically 0-1
      * @return the interpolated int
      */
-    public static int lerp(int a, int b, double t) {
+    public static int lerp( int a, int b, double t )
+    {
         return a + (int) ((b - a) * t);
     }
-    
+
     /**
      * Linear interpolation of double.
+     * 
      * @param a from
      * @param b to
      * @param t factor, typically 0-1
      * @return the interpolated double
      */
-    public static double lerp(double a, double b, double t) {
+    public static double lerp( double a, double b, double t )
+    {
         return a + (b - a) * t;
     }
-    
+
     /**
      * Linear interpolation of RGB colors.
+     * 
      * @param a from
      * @param b to
      * @param t interpolation factor, typically 0-1
      * @return the interpolated color
      */
-    public static Color lerp(Color a, Color b, double t) {
-        return new Color(
-                lerp(a.getRed(), b.getRed(), t),
-                lerp(a.getGreen(), b.getGreen(), t),
-                lerp(a.getBlue(), b.getBlue(), t),
-                lerp(a.getAlpha(), b.getAlpha(), t));
+    public static Color lerp( Color a, Color b, double t )
+    {
+        return new Color( lerp( a.getRed(), b.getRed(), t ), lerp( a.getGreen(), b.getGreen(), t ), lerp( a.getBlue(),
+            b.getBlue(), t ), lerp( a.getAlpha(), b.getAlpha(), t ) );
     }
-    
+
     /**
-     * Creates a java.awt.Color from a dhis style color string, e.g. '#ff3200' is an orange color.
+     * Creates a java.awt.Color from a dhis style color string, e.g. '#ff3200'
+     * is an orange color.
+     * 
      * @param str the color in string, e.g. '#ff3200'
      * @return the color
      */
-    public static Color createColorFromString(String str) {
-        return new Color(Integer.parseInt(str.substring(1), 16));
+    public static Color createColorFromString( String str )
+    {
+        return new Color( Integer.parseInt( str.substring( 1 ), 16 ) );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapLayerTest.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapLayerTest.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapLayerTest.java	2011-12-09 10:29:57 +0000
@@ -28,13 +28,14 @@
 /**
  * @author Kenneth Solbø Andersen <kennetsa@xxxxxxxxxx>
  */
-public class GeoToolsMapLayerTest extends DhisSpringTest {
-	
-	InternalMapLayer internalMapLayer;
-	
-	MappingService mappingService;
-	
-	private OrganisationUnit organisationUnit;
+public class GeoToolsMapLayerTest
+    extends DhisSpringTest
+{
+    private InternalMapLayer internalMapLayer;
+
+    private MappingService mappingService;
+
+    private OrganisationUnit organisationUnit;
 
     private OrganisationUnitLevel organisationUnitLevel;
 
@@ -53,20 +54,20 @@
     private Period period;
 
     private MapLegendSet mapLegendSet;
-	
+
     @Override
     public void setUpTest()
-	{
-		mappingService = (MappingService) getBean( MappingService.ID );
+    {
+        mappingService = (MappingService) getBean( MappingService.ID );
 
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
 
         indicatorService = (IndicatorService) getBean( IndicatorService.ID );
-        
+
         dataElementService = (DataElementService) getBean( DataElementService.ID );
 
         periodService = (PeriodService) getBean( PeriodService.ID );
-        
+
         organisationUnit = createOrganisationUnit( 'A' );
         organisationUnitLevel = new OrganisationUnitLevel( 1, "Level" );
 
@@ -95,83 +96,83 @@
 
         mapLegendSet = createMapLegendSet( 'A', indicator );
         mappingService.addMapLegendSet( mapLegendSet );
-        
+
         internalMapLayer = new InternalMapLayer();
-        internalMapLayer.setRadiusLow(15);
-        internalMapLayer.setRadiusHigh(35);
-        internalMapLayer.setColorLow(Color.YELLOW);
-        internalMapLayer.setColorHigh(Color.RED);
-        internalMapLayer.setOpacity(0.5f);
-	}
-	
-	@Test
-	@Ignore
-	public void testBuildGeometryForOrganisationUnit()
-	{
-		
-	}
-	
-	@Test
-	@Ignore
-	public void testGetAllMapObjects()
-	{
-		
-	}
-	
-	@Ignore
-	@Test
-	public void testSetGetRadiusHigh()
-	{
-		internalMapLayer.setRadiusHigh(45);
-		assertEquals(45.8F, internalMapLayer.getRadiusHigh(), 0.00001F);
-		internalMapLayer.setRadiusHigh(82);
-		assertEquals(82.023984F, internalMapLayer.getRadiusHigh(), 0.00001F);
-	}
-	
-	@Ignore
-	@Test
-	public void testSetGetRadiusLow()
-	{
-		internalMapLayer.setRadiusLow(45);
-		assertEquals(45.8F, internalMapLayer.getRadiusLow(), 0.00001F);
-		internalMapLayer.setRadiusLow(82);
-		assertEquals(82.023984F, internalMapLayer.getRadiusLow(), 0.00001F);
-	}
-	
-	@Ignore
-	@Test
-	public void testSetGetColorHigh()
-	{
-		internalMapLayer.setColorHigh(Color.YELLOW);
-		assertEquals(Color.YELLOW, internalMapLayer.getColorHigh());
-		internalMapLayer.setColorHigh(Color.BLUE);
-		assertEquals(Color.BLUE, internalMapLayer.getColorHigh());
-	}
-	
-	@Ignore
-	@Test
-	public void testSetGetColorLow()
-	{
-		internalMapLayer.setColorLow(Color.YELLOW);
-		assertEquals(Color.YELLOW, internalMapLayer.getColorLow());
-		internalMapLayer.setColorLow(Color.BLUE);
-		assertEquals(Color.BLUE, internalMapLayer.getColorLow());
-	}
-	
-	@Ignore
-	@Test
-	public void testSetGetOpacity()
-	{
-		internalMapLayer.setOpacity(34.8F);
-		assertEquals(34.8F, internalMapLayer.getOpacity(), 0.00001);
-		internalMapLayer.setOpacity(14.5F);
-		assertEquals(14.5F, internalMapLayer.getOpacity(), 0.00001);
-	}
-	
-	@Ignore
-	@Test
-	public void testGetIntervalSet()
-	{
-		
-	}
+        internalMapLayer.setRadiusLow( 15 );
+        internalMapLayer.setRadiusHigh( 35 );
+        internalMapLayer.setColorLow( Color.YELLOW );
+        internalMapLayer.setColorHigh( Color.RED );
+        internalMapLayer.setOpacity( 0.5f );
+    }
+
+    @Test
+    @Ignore
+    public void testBuildGeometryForOrganisationUnit()
+    {
+        //TODO
+    }
+
+    @Test
+    @Ignore
+    public void testGetAllMapObjects()
+    {
+        //TODO
+    }
+
+    @Ignore
+    @Test
+    public void testSetGetRadiusHigh()
+    {
+        internalMapLayer.setRadiusHigh( 45 );
+        assertEquals( 45.8F, internalMapLayer.getRadiusHigh(), 0.00001F );
+        internalMapLayer.setRadiusHigh( 82 );
+        assertEquals( 82.023984F, internalMapLayer.getRadiusHigh(), 0.00001F );
+    }
+
+    @Ignore
+    @Test
+    public void testSetGetRadiusLow()
+    {
+        internalMapLayer.setRadiusLow( 45 );
+        assertEquals( 45.8F, internalMapLayer.getRadiusLow(), 0.00001F );
+        internalMapLayer.setRadiusLow( 82 );
+        assertEquals( 82.023984F, internalMapLayer.getRadiusLow(), 0.00001F );
+    }
+
+    @Ignore
+    @Test
+    public void testSetGetColorHigh()
+    {
+        internalMapLayer.setColorHigh( Color.YELLOW );
+        assertEquals( Color.YELLOW, internalMapLayer.getColorHigh() );
+        internalMapLayer.setColorHigh( Color.BLUE );
+        assertEquals( Color.BLUE, internalMapLayer.getColorHigh() );
+    }
+
+    @Ignore
+    @Test
+    public void testSetGetColorLow()
+    {
+        internalMapLayer.setColorLow( Color.YELLOW );
+        assertEquals( Color.YELLOW, internalMapLayer.getColorLow() );
+        internalMapLayer.setColorLow( Color.BLUE );
+        assertEquals( Color.BLUE, internalMapLayer.getColorLow() );
+    }
+
+    @Ignore
+    @Test
+    public void testSetGetOpacity()
+    {
+        internalMapLayer.setOpacity( 34.8F );
+        assertEquals( 34.8F, internalMapLayer.getOpacity(), 0.00001 );
+        internalMapLayer.setOpacity( 14.5F );
+        assertEquals( 14.5F, internalMapLayer.getOpacity(), 0.00001 );
+    }
+
+    @Ignore
+    @Test
+    public void testGetIntervalSet()
+    {
+        //TODO
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapObjectTest.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapObjectTest.java	2011-12-03 10:51:46 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapObjectTest.java	2011-12-09 10:29:57 +0000
@@ -12,94 +12,96 @@
 /**
  * @author Kenneth Solbø Andersen <kennetsa@xxxxxxxxxx>
  */
-public class GeoToolsMapObjectTest extends DhisSpringTest {
-	
-	GeoToolsMapObject geoToolsMapObject;
-
-	@Override
-	public void setUpTest()
-	{
-		geoToolsMapObject = new GeoToolsMapObject();
-	}
-	
-	@Test
-	public void testSetGetName()
-	{
-		geoToolsMapObject.setName("Name1");
-		assertEquals("Name1", geoToolsMapObject.getName());
-		geoToolsMapObject.setName("Another name");
-		assertEquals("Another name", geoToolsMapObject.getName());
-	}
-	
-	@Test
-	public void testSetGetValue()
-	{
-		geoToolsMapObject.setValue(489.3);
-		assertEquals(489.3, geoToolsMapObject.getValue(), 0.00001);
-		geoToolsMapObject.setValue(41.423);
-		assertEquals(41.423, geoToolsMapObject.getValue(), 0.00001);
-	}
-	
-	@Test @Ignore
-	public void testSetGetRadius()
-	{
-		geoToolsMapObject.setRadius(32);
-		assertEquals(32.5264F, geoToolsMapObject.getRadius(), 0.00001);
-		geoToolsMapObject.setRadius(61);
-		assertEquals(61441.5F, geoToolsMapObject.getRadius(), 0.00001);
-	}
-	
-	@Test
-	public void testSetGetFillColor()
-	{
-		geoToolsMapObject.setFillColor(Color.BLUE);
-		assertEquals(Color.BLUE, geoToolsMapObject.getFillColor());
-		geoToolsMapObject.setFillColor(Color.CYAN);
-		assertEquals(Color.CYAN, geoToolsMapObject.getFillColor());
-	}
-	
-	@Test
-	public void testSetGetFillOpacity()
-	{
-		geoToolsMapObject.setFillOpacity(5.23F);
-		assertEquals(5.23F, geoToolsMapObject.getFillOpacity(), 0.00001);
-		geoToolsMapObject.setFillOpacity(594208420.134F);
-		assertEquals(594208420.134F, geoToolsMapObject.getFillOpacity(), 0.00001);
-	}
-	
-	@Test
-	public void testSetGetStrokeColor()
-	{
-		geoToolsMapObject.setStrokeColor(Color.GREEN);
-		assertEquals(Color.GREEN, geoToolsMapObject.getStrokeColor());
-		geoToolsMapObject.setStrokeColor(Color.WHITE);
-		assertEquals(Color.WHITE, geoToolsMapObject.getStrokeColor());
-	}
-	
-	@Test
-	public void testSetGetStrokeWidth()
-	{
-		geoToolsMapObject.setStrokeWidth(32);
-		assertEquals(32, geoToolsMapObject.getStrokeWidth());
-		geoToolsMapObject.setStrokeWidth(364114);
-		assertEquals(364114, geoToolsMapObject.getStrokeWidth());
-	}
-	
-	@Test
-	public void testSetGetMapLayer()
-	{
-		
-	}
-	
-	@Test
-	public void testSetGetInterval()
-	{
-		
-	}
-	
-	@Test
-	public void testToString()
-	{
-		
-	}
+public class GeoToolsMapObjectTest
+    extends DhisSpringTest
+{
+    private GeoToolsMapObject geoToolsMapObject;
+
+    @Override
+    public void setUpTest()
+    {
+        geoToolsMapObject = new GeoToolsMapObject();
+    }
+
+    @Test
+    public void testSetGetName()
+    {
+        geoToolsMapObject.setName( "Name1" );
+        assertEquals( "Name1", geoToolsMapObject.getName() );
+        geoToolsMapObject.setName( "Another name" );
+        assertEquals( "Another name", geoToolsMapObject.getName() );
+    }
+
+    @Test
+    public void testSetGetValue()
+    {
+        geoToolsMapObject.setValue( 489.3 );
+        assertEquals( 489.3, geoToolsMapObject.getValue(), 0.00001 );
+        geoToolsMapObject.setValue( 41.423 );
+        assertEquals( 41.423, geoToolsMapObject.getValue(), 0.00001 );
+    }
+
+    @Test
+    @Ignore
+    public void testSetGetRadius()
+    {
+        geoToolsMapObject.setRadius( 32 );
+        assertEquals( 32.5264F, geoToolsMapObject.getRadius(), 0.00001 );
+        geoToolsMapObject.setRadius( 61 );
+        assertEquals( 61441.5F, geoToolsMapObject.getRadius(), 0.00001 );
+    }
+
+    @Test
+    public void testSetGetFillColor()
+    {
+        geoToolsMapObject.setFillColor( Color.BLUE );
+        assertEquals( Color.BLUE, geoToolsMapObject.getFillColor() );
+        geoToolsMapObject.setFillColor( Color.CYAN );
+        assertEquals( Color.CYAN, geoToolsMapObject.getFillColor() );
+    }
+
+    @Test
+    public void testSetGetFillOpacity()
+    {
+        geoToolsMapObject.setFillOpacity( 5.23F );
+        assertEquals( 5.23F, geoToolsMapObject.getFillOpacity(), 0.00001 );
+        geoToolsMapObject.setFillOpacity( 594208420.134F );
+        assertEquals( 594208420.134F, geoToolsMapObject.getFillOpacity(), 0.00001 );
+    }
+
+    @Test
+    public void testSetGetStrokeColor()
+    {
+        geoToolsMapObject.setStrokeColor( Color.GREEN );
+        assertEquals( Color.GREEN, geoToolsMapObject.getStrokeColor() );
+        geoToolsMapObject.setStrokeColor( Color.WHITE );
+        assertEquals( Color.WHITE, geoToolsMapObject.getStrokeColor() );
+    }
+
+    @Test
+    public void testSetGetStrokeWidth()
+    {
+        geoToolsMapObject.setStrokeWidth( 32 );
+        assertEquals( 32, geoToolsMapObject.getStrokeWidth() );
+        geoToolsMapObject.setStrokeWidth( 364114 );
+        assertEquals( 364114, geoToolsMapObject.getStrokeWidth() );
+    }
+
+    @Test
+    public void testSetGetMapLayer()
+    {
+        //TODO
+    }
+
+    @Test
+    public void testSetGetInterval()
+    {
+        //TODO
+    }
+
+    @Test
+    public void testToString()
+    {
+        //TODO
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapTest.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapTest.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/GeoToolsMapTest.java	2011-12-09 10:29:57 +0000
@@ -14,36 +14,37 @@
 /**
  * @author Kenneth Solbø Andersen <kennetsa@xxxxxxxxxx>
  */
-public class GeoToolsMapTest extends DhisSpringTest {
-	
-	GeoToolsMap geoToolsMap;
-	
-	@Override
+public class GeoToolsMapTest
+    extends DhisSpringTest
+{
+    private GeoToolsMap geoToolsMap;
+
+    @Override
     public void setUpTest()
-	{
-		geoToolsMap = new GeoToolsMap();
-	}
-	
-	@Test
-	public void testSetGetBackground()
-	{
-		geoToolsMap.setBackgroundColor(Color.BLUE);
-		assertEquals(Color.BLUE, geoToolsMap.getBackgroundColor());
-	}
-	
-	@Test
-	public void testSetGetAntiAliasingEnabled()
-	{
-		geoToolsMap.setAntiAliasingEnabled(false);
-		assertFalse(geoToolsMap.isAntiAliasingEnabled());
-		geoToolsMap.setAntiAliasingEnabled(true);
-		assertTrue(geoToolsMap.isAntiAliasingEnabled());
-	}
-	
-	@Test
-	@Ignore
-	public void testRender()
-	{
-		
-	}
+    {
+        geoToolsMap = new GeoToolsMap();
+    }
+
+    @Test
+    public void testSetGetBackground()
+    {
+        geoToolsMap.setBackgroundColor( Color.BLUE );
+        assertEquals( Color.BLUE, geoToolsMap.getBackgroundColor() );
+    }
+
+    @Test
+    public void testSetGetAntiAliasingEnabled()
+    {
+        geoToolsMap.setAntiAliasingEnabled( false );
+        assertFalse( geoToolsMap.isAntiAliasingEnabled() );
+        geoToolsMap.setAntiAliasingEnabled( true );
+        assertTrue( geoToolsMap.isAntiAliasingEnabled() );
+    }
+
+    @Test
+    @Ignore
+    public void testRender()
+    {
+        //TODO
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapGeneratorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapGeneratorServiceTest.java	2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/test/java/org/hisp/dhis/mapgenerator/MapGeneratorServiceTest.java	2011-12-09 10:29:57 +0000
@@ -8,7 +8,6 @@
 import org.hisp.dhis.indicator.IndicatorGroup;
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.indicator.IndicatorType;
-import org.hisp.dhis.mapgeneration.MapGenerationService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -21,11 +20,10 @@
 /**
  * @author Kenneth Solbø Andersen <kennetsa@xxxxxxxxxx>
  */
-public class MapGeneratorServiceTest extends DhisSpringTest {
-	
-	MapGenerationService mapGeneratorService;
-	
-	private OrganisationUnit organisationUnit;
+public class MapGeneratorServiceTest
+    extends DhisSpringTest
+{
+    private OrganisationUnit organisationUnit;
 
     private OrganisationUnitLevel organisationUnitLevel;
 
@@ -42,20 +40,18 @@
     private PeriodType periodType;
 
     private Period period;
-	
-	@Override
-	public void setUpTest()
-	{
-		mapGeneratorService = (MapGenerationService) getBean(MapGenerationService.ID);
-		
-		organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
+
+    @Override
+    public void setUpTest()
+    {
+        organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
 
         indicatorService = (IndicatorService) getBean( IndicatorService.ID );
-        
+
         dataElementService = (DataElementService) getBean( DataElementService.ID );
-        
+
         periodService = (PeriodService) getBean( PeriodService.ID );
-        
+
         organisationUnit = createOrganisationUnit( 'A' );
         organisationUnitLevel = new OrganisationUnitLevel( 1, "Level" );
 
@@ -81,11 +77,11 @@
         periodType = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
         period = createPeriod( periodType, getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
         periodService.addPeriod( period );
-	}
-	
+    }
+
     @Test
     public void testGenerateMapImage()
     {
-    	
+        // TODO
     }
 }