1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.chart.internal

File DrawingSupplierFactory.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

4
17
1
1
81
41
3
0.18
17
1
3

Classes

Class Line # Actions
DrawingSupplierFactory 37 17 0% 3 15
0.318181831.8%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.chart.internal;
21   
22    import java.awt.Color;
23    import java.awt.Paint;
24    import java.util.ArrayList;
25    import java.util.List;
26    import java.util.Map;
27   
28    import org.jfree.chart.plot.DefaultDrawingSupplier;
29    import org.jfree.chart.plot.DrawingSupplier;
30   
31    /**
32    * Allows user to provide custom colors.
33    *
34    * @version $Id: 3cd4149afd76a04f18f61be3cce59b3f53024d66 $
35    * @since 4.1M2
36    */
 
37    public class DrawingSupplierFactory
38    {
39    /**
40    * Color parameter identifier. The format is {@code color1,color2,...,colorN} where each color is specified as
41    * a 6 characters string, the first 2 representing in hexadecimal the red percentage, the next two the green
42    * percentage and the last 2 the blue percentage. For example {@code FF0000,00FF00,0000FF} for red, green, blue.
43    */
44    private static final String COLORS_PARAM = "colors";
45   
46    /**
47    * @param parameters the user-defined parameters, containing {@link #COLORS_PARAM} if the user wants custom colors
48    * @return the Drawing Supplier to use
49    */
 
50  15 toggle public DrawingSupplier createDrawingSupplier(Map<String, String> parameters)
51    {
52  15 DrawingSupplier supplier;
53   
54  15 String colorParam = parameters.get(COLORS_PARAM);
55  15 if (colorParam != null) {
56  0 List<Color> colors = new ArrayList<Color>();
57  0 for (String colorAsString : colorParam.split(",")) {
58  0 if (colorAsString.length() == 6) {
59  0 int red = Integer.parseInt(colorAsString.substring(0, 2), 16);
60  0 int green = Integer.parseInt(colorAsString.substring(2, 4), 16);
61  0 int blue = Integer.parseInt(colorAsString.substring(4, 6), 16);
62  0 colors.add(new Color(red, green, blue));
63    }
64    }
65  0 Paint[] paint = new Paint[colors.size()];
66  0 int i = 0;
67  0 for (Color color : colors) {
68  0 paint[i++] = color;
69    }
70  0 supplier = new DefaultDrawingSupplier(paint,
71    DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
72    DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
73    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
74    DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
75    } else {
76  15 supplier = new DefaultDrawingSupplier();
77    }
78   
79  15 return supplier;
80    }
81    }