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

File StrokeChartParam.java

 

Coverage histogram

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

Code metrics

0
27
7
1
98
67
12
0.44
3.86
7
1.71

Classes

Class Line # Actions
StrokeChartParam 30 27 0% 12 34
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.BasicStroke;
23    import java.awt.Stroke;
24    import java.util.HashMap;
25    import java.util.Map;
26   
27    import com.xpn.xwiki.plugin.charts.exceptions.InvalidParamException;
28    import com.xpn.xwiki.plugin.charts.exceptions.ParamException;
29   
 
30    public class StrokeChartParam extends AbstractChartParam
31    {
32    private Map capChoices = new HashMap();
33   
34    private Map joinChoices = new HashMap();
35   
 
36  0 toggle public StrokeChartParam(String name)
37    {
38  0 super(name);
39  0 init();
40    }
41   
 
42  0 toggle public StrokeChartParam(String name, boolean optional)
43    {
44  0 super(name, optional);
45  0 init();
46    }
47   
 
48  0 toggle @Override
49    public Class getType()
50    {
51  0 return Stroke.class;
52    }
53   
 
54  0 toggle public void init()
55    {
56  0 capChoices.put("butt", BasicStroke.CAP_BUTT);
57  0 capChoices.put("round", BasicStroke.CAP_ROUND);
58  0 capChoices.put("square", BasicStroke.CAP_SQUARE);
59   
60  0 joinChoices.put("miter", BasicStroke.JOIN_MITER);
61  0 joinChoices.put("round", BasicStroke.JOIN_ROUND);
62  0 joinChoices.put("bevel", BasicStroke.JOIN_BEVEL);
63    }
64   
 
65  0 toggle @Override
66    public Object convert(String value) throws ParamException
67    {
68  0 Map map = parseMap(value);
69  0 switch (map.size()) {
70  0 case 0:
71  0 return new BasicStroke();
72  0 case 1:
73  0 return new BasicStroke(getFloatArg(map, "width"));
74  0 case 3:
75  0 return new BasicStroke(getFloatArg(map, "width"), getCapParam(map, "cap"), getJoinParam(map, "join"));
76  0 case 4:
77  0 return new BasicStroke(getFloatArg(map, "width"), getCapParam(map, "cap"), getJoinParam(map, "join"),
78    getFloatArg(map, "miterlimit"));
79  0 case 6:
80  0 return new BasicStroke(getFloatArg(map, "width"), getCapParam(map, "cap"), getJoinParam(map, "join"),
81    getFloatArg(map, "miterlimit"), toFloatArray(getListArg(map, "dash")), getFloatArg(map,
82    "dash_phase"));
83  0 default:
84  0 throw new InvalidParamException("Invalid value for the parameter " + getName()
85    + ": Invalid number of arguments: " + map.size());
86    }
87    }
88   
 
89  0 toggle private int getCapParam(Map map, String name) throws ParamException
90    {
91  0 return ((Integer) getChoiceArg(map, name, capChoices)).intValue();
92    }
93   
 
94  0 toggle private int getJoinParam(Map map, String name) throws ParamException
95    {
96  0 return ((Integer) getChoiceArg(map, name, joinChoices)).intValue();
97    }
98    }