1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.adapters;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import com.cosylab.gui.displayers.CommonDisplayer;
26 import com.cosylab.gui.displayers.DoubleConsumer;
27
28
29
30
31
32
33
34
35
36
37 public class PotentialConverter extends SimpleConverterSupport implements
38 DoubleConsumer {
39
40 private static final long serialVersionUID = 3449182777513744784L;
41
42 public static final String SHORT_NAME = "Potential";
43
44 private double exponent = 1;
45
46
47
48
49
50 public PotentialConverter() {
51 this(1);
52 }
53
54
55
56
57
58
59 public PotentialConverter(double exponent){
60 setExponent(exponent);
61 }
62
63
64
65
66
67 @Override
68 protected double inverseTransform(double value) {
69 return Math.pow(value, 1.0 / getExponent());
70 }
71
72
73
74
75
76
77 public double getExponent() {
78 return exponent;
79 }
80
81
82
83
84
85 @Override
86 protected double transform(double value) {
87 return Math.pow(value, getExponent());
88 }
89
90
91
92
93
94
95 public void setExponent(double exponent){
96 if (exponent <= 0) this.exponent = 1;
97 else this.exponent = exponent;
98 }
99
100
101
102
103
104 public String getName(){
105 return SHORT_NAME;
106 }
107
108
109
110
111
112 public String toString(){
113 return SHORT_NAME + ": " + getExponent();
114 }
115
116
117
118
119
120 public void setCharacteristics(Map characteristics)
121 {
122
123
124 cacheLastCharacteristics(characteristics);
125
126 HashMap map = new HashMap(characteristics);
127
128 double min;
129 double max;
130
131
132 if (map.containsKey(CommonDisplayer.C_GRAPH_MIN)
133 && map.containsKey(CommonDisplayer.C_GRAPH_MAX)) {
134 min = ((Number)map.get(CommonDisplayer.C_GRAPH_MIN)).doubleValue();
135 max = ((Number)map.get(CommonDisplayer.C_GRAPH_MAX)).doubleValue();
136
137 map.put(CommonDisplayer.C_GRAPH_MIN,
138 new Double(transform(min)));
139 map.put(CommonDisplayer.C_GRAPH_MAX,
140 new Double(transform(max)));
141 }
142
143
144 if (map.containsKey(CommonDisplayer.C_MINIMUM)
145 && map.containsKey(CommonDisplayer.C_MAXIMUM)) {
146 min = ((Number)map.get(CommonDisplayer.C_MINIMUM)).doubleValue();
147 max = ((Number)map.get(CommonDisplayer.C_MAXIMUM)).doubleValue();
148
149 map.put(CommonDisplayer.C_MINIMUM,
150 new Double(transform(min)));
151 map.put(CommonDisplayer.C_MAXIMUM,
152 new Double(transform(max)));
153 }
154
155
156 map.put(CommonDisplayer.C_UNITS,
157 map.get(CommonDisplayer.C_UNITS) +"^1/"+getExponent());
158
159 super.setCharacteristics(map);
160 }
161
162
163
164
165
166 @Override
167 public boolean equals(Object obj) {
168 if (!(obj instanceof PotentialConverter)) return false;
169 PotentialConverter c = (PotentialConverter)obj;
170 return c.getExponent() == exponent;
171 }
172 }