1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 12 |
Complexity Density: 0.3 |
|
29 |
|
public class ColorChartParam extends AbstractChartParam |
30 |
|
{ |
31 |
|
private ChartParam colorChoice; |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
33 |
0 |
public ColorChartParam(String name)... |
34 |
|
{ |
35 |
0 |
super(name); |
36 |
0 |
init(); |
37 |
|
} |
38 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
39 |
0 |
public ColorChartParam(String name, boolean optional)... |
40 |
|
{ |
41 |
0 |
super(name, optional); |
42 |
0 |
init(); |
43 |
|
} |
44 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
45 |
0 |
@Override... |
46 |
|
public Class getType() |
47 |
|
{ |
48 |
0 |
return Color.class; |
49 |
|
} |
50 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0 |
public void init()... |
52 |
|
{ |
53 |
0 |
colorChoice = new ChoiceChartParam(getName()) |
54 |
|
{ |
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 1 |
Complexity Density: 0.06 |
|
55 |
0 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
0 |
@Override... |
79 |
|
public Class getType() |
80 |
|
{ |
81 |
0 |
return Shape.class; |
82 |
|
} |
83 |
|
}; |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.4 |
|
86 |
0 |
@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 |
|
} |