1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.charts.params

File ColorChartParam.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

4
40
7
1
116
88
12
0.3
5.71
7
1.71

Classes

Class Line # Actions
ColorChartParam 29 40 0% 12 51
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 com.xpn.xwiki.plugin.charts.params;
21   
22    import java.awt.Color;
23    import java.awt.Shape;
24    import java.util.Map;
25   
26    import com.xpn.xwiki.plugin.charts.exceptions.InvalidParamException;
27    import com.xpn.xwiki.plugin.charts.exceptions.ParamException;
28   
 
29    public class ColorChartParam extends AbstractChartParam
30    {
31    private ChartParam colorChoice;
32   
 
33  0 toggle public ColorChartParam(String name)
34    {
35  0 super(name);
36  0 init();
37    }
38   
 
39  0 toggle public ColorChartParam(String name, boolean optional)
40    {
41  0 super(name, optional);
42  0 init();
43    }
44   
 
45  0 toggle @Override
46    public Class getType()
47    {
48  0 return Color.class;
49    }
50   
 
51  0 toggle public void init()
52    {
53  0 colorChoice = new ChoiceChartParam(getName())
54    {
 
55  0 toggle @Override
56    protected void init()
57    {
58  0 addChoice("black", new Color(0x000000));
59  0 addChoice("silver", new Color(0xC0C0C0));
60  0 addChoice("gray", new Color(0x808080));
61  0 addChoice("white", new Color(0xFFFFFF));
62  0 addChoice("maroon", new Color(0x800000));
63  0 addChoice("red", new Color(0xFF0000));
64  0 addChoice("purple", new Color(0x800080));
65  0 addChoice("fuchsia", new Color(0xFF00FF));
66  0 addChoice("green", new Color(0x008000));
67  0 addChoice("lime", new Color(0x00FF00));
68  0 addChoice("olive", new Color(0x808000));
69  0 addChoice("yellow", new Color(0xFFFF00));
70  0 addChoice("navy", new Color(0x000080));
71  0 addChoice("blue", new Color(0x0000FF));
72  0 addChoice("teal", new Color(0x008080));
73  0 addChoice("aqua", new Color(0x00FFFF));
74  0 addChoice("orange", new Color(0xFFA500));
75  0 addChoice("transparent", new Color(0, 0, 0, 0));
76    }
77   
 
78  0 toggle @Override
79    public Class getType()
80    {
81  0 return Shape.class;
82    }
83    };
84    }
85   
 
86  0 toggle @Override
87    public Object convert(String value) throws ParamException
88    {
89  0 try {
90  0 return colorChoice.convert(value);
91    } catch (ParamException e) {
92  0 if (value.length() == 0) {
93  0 throw new InvalidParamException("Empty color parameter " + getName());
94    }
95  0 if (value.charAt(0) == '#') {
96  0 value = value.substring(1);
97  0 int intValue;
98  0 try {
99  0 intValue = Integer.parseInt(value, 16);
100    } catch (NumberFormatException nfe) {
101  0 throw new InvalidParamException("Color parameter " + getName()
102    + " is not a valid hexadecimal number");
103    }
104  0 return new Color(intValue);
105    } else {
106  0 Map map = parseMap(value, 4);
107  0 try {
108  0 return new Color(getIntArg(map, "red"), getIntArg(map, "green"), getIntArg(map, "blue"), getIntArg(
109    map, "alpha"));
110    } catch (IllegalArgumentException iae) {
111  0 throw new InvalidParamException("Color component out of range (0-255)");
112    }
113    }
114    }
115    }
116    }