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
27
28
29
30
31
32
33
34
35
36 public class ExponentialConverter extends SimpleConverterSupport {
37
38 private static final long serialVersionUID = -1789030566494308338L;
39
40 public static final String SHORT_NAME = "exponential";
41
42 private double base = Math.E, logBase = 1;
43
44
45
46
47
48
49 public ExponentialConverter() {
50 setBase(Math.E);
51 }
52
53
54
55
56
57
58 public ExponentialConverter(double base){
59 setBase(base);
60 }
61
62
63
64
65
66 @Override
67 protected double inverseTransform(double value) {
68 if (value <= 0) return 0;
69 return Math.log(value)/getLogBase();
70 }
71
72
73
74
75
76 @Override
77 protected double transform(double value) {
78 return Math.pow(getBase(), value);
79 }
80
81
82
83
84
85 public String getName(){
86 return SHORT_NAME;
87 }
88
89
90
91
92
93 public String toString(){
94 return SHORT_NAME + ": " + getBase();
95 }
96
97
98
99
100
101
102 public double getBase() {
103 return base;
104 }
105
106
107
108
109
110
111 public void setBase(double base) {
112 if (base <= 0) return;
113 this.base = base;
114 setLogBase(Math.log(base));
115 }
116
117 protected double getLogBase() {
118 return logBase;
119 }
120
121 protected void setLogBase(double logBase) {
122 this.logBase = logBase;
123 }
124
125 public void setCharacteristics(Map characteristics)
126 {
127
128
129 cacheLastCharacteristics(characteristics);
130
131 HashMap map = new HashMap(characteristics);
132
133 double min;
134 double max;
135
136
137 if (map.containsKey(CommonDisplayer.C_GRAPH_MIN)
138 && map.containsKey(CommonDisplayer.C_GRAPH_MAX)) {
139 min = ((Number)map.get(CommonDisplayer.C_GRAPH_MIN)).doubleValue();
140 max = ((Number)map.get(CommonDisplayer.C_GRAPH_MAX)).doubleValue();
141
142 map.put(CommonDisplayer.C_GRAPH_MIN,
143 new Double(transform(min)));
144 map.put(CommonDisplayer.C_GRAPH_MAX,
145 new Double(transform(max)));
146 }
147
148
149 if (map.containsKey(CommonDisplayer.C_MINIMUM)
150 && map.containsKey(CommonDisplayer.C_MAXIMUM)) {
151 min = ((Number)map.get(CommonDisplayer.C_MINIMUM)).doubleValue();
152 max = ((Number)map.get(CommonDisplayer.C_MAXIMUM)).doubleValue();
153
154 map.put(CommonDisplayer.C_MINIMUM,
155 new Double(transform(min)));
156 map.put(CommonDisplayer.C_MAXIMUM,
157 new Double(transform(max)));
158 }
159
160
161 map.put(CommonDisplayer.C_UNITS,
162 "log_"+getBase()+"("+ map.get(CommonDisplayer.C_UNITS)+")");
163
164 super.setCharacteristics(map);
165 }
166
167
168
169
170
171 @Override
172 public boolean equals(Object obj) {
173 if (!(obj instanceof ExponentialConverter)) return false;
174 ExponentialConverter c = (ExponentialConverter)obj;
175 return c.getBase() == getBase();
176 }
177 }