1
|
1 package de.mpg.mpiwg.itgroup.digilib.digiImage;
|
|
2
|
20
|
3 import java.lang.reflect.Field;
|
|
4 import java.util.HashMap;
|
|
5 import java.util.List;
|
|
6 import java.util.Map;
|
|
7
|
9
|
8 /**
|
|
9 * Parameter which describe the state of an Digilib-Image,
|
|
10 * settings and parameter names are described in @see {@link http://developer.berlios.de/docman/?group_id=251}
|
|
11 * @author dwinter
|
|
12 *
|
|
13 */
|
1
|
14 public class DigiImageParameter {
|
|
15
|
20
|
16 public String fn;
|
1
|
17
|
20
|
18 public int pn=1;
|
1
|
19
|
20
|
20 public int dw=-1;
|
|
21 public int dh=-1;
|
1
|
22
|
20
|
23 public float wx=0;
|
|
24 public float wy=0;
|
1
|
25
|
20
|
26 public float ww=1;
|
|
27 public float wh=1;
|
|
28 public float ws=1;
|
1
|
29
|
20
|
30 public String mo="fit";
|
1
|
31
|
20
|
32 public float cont=0;
|
|
33 public float brgt=0;
|
1
|
34
|
20
|
35 public float rot=0;
|
1
|
36
|
20
|
37 public String rgbm="0/0/0";
|
|
38 public String rgba="0/0/0";
|
1
|
39
|
20
|
40 public int ddpi=-1;
|
|
41 public int ddpix=-1;
|
|
42 public int ddpiy=-1;
|
1
|
43
|
|
44 public DigiImageParameter(String fn){
|
|
45 this.fn = fn;
|
|
46 }
|
20
|
47
|
|
48 public DigiImageParameter(Map<String,String> params){
|
|
49
|
|
50 for(String key: params.keySet()){
|
|
51 Field f;
|
|
52 try {
|
|
53 f = this.getClass().getField(key);
|
|
54 } catch (SecurityException e) {
|
|
55 continue;
|
|
56 } catch (NoSuchFieldException e) {
|
|
57 continue;
|
|
58 }
|
|
59 if (f!=null){
|
|
60 try {
|
|
61 Class<?> T = f.getType();
|
|
62 String name= T.getName();
|
|
63 String valueString = params.get(key);
|
|
64 Object value = valueString;
|
|
65 if (name.equals("float")){
|
|
66 value = Float.valueOf(valueString);
|
|
67 } else if (name.equals("double")){
|
|
68 value = Double.valueOf(valueString);
|
|
69 } else if (name.equals("int")){
|
|
70 value = Integer.valueOf(valueString);
|
|
71 } else if (name.equals("Float")){
|
|
72 value = Float.valueOf(valueString);
|
|
73 } else if (name.equals("Double")){
|
|
74 value = Double.valueOf(valueString);
|
|
75 } else if (name.equals("Integer")){
|
|
76 value = Integer.valueOf(valueString);
|
|
77 }
|
|
78
|
|
79
|
|
80 f.set(this, value);
|
|
81
|
|
82 } catch (IllegalArgumentException e) {
|
|
83 // TODO Auto-generated catch block
|
|
84 e.printStackTrace();
|
|
85 continue;
|
|
86 } catch (IllegalAccessException e) {
|
|
87 // TODO Auto-generated catch block
|
|
88 e.printStackTrace();
|
|
89 continue;
|
|
90
|
|
91 }
|
|
92 }
|
|
93 }
|
|
94 }
|
|
95
|
|
96
|
1
|
97 public String getFn() {
|
|
98 return fn;
|
|
99 }
|
|
100 public void setFn(String fn) {
|
|
101 this.fn = fn;
|
|
102 }
|
|
103 public int getPn() {
|
|
104 return pn;
|
|
105 }
|
|
106 public void setPn(int pn) {
|
|
107 this.pn = pn;
|
|
108 }
|
|
109 public int getDw() {
|
|
110 return dw;
|
|
111 }
|
|
112 public void setDw(int dw) {
|
|
113 this.dw = dw;
|
|
114 }
|
|
115 public int getDh() {
|
|
116 return dh;
|
|
117 }
|
|
118 public void setDh(int dh) {
|
|
119 this.dh = dh;
|
|
120 }
|
|
121 public float getWx() {
|
|
122 return wx;
|
|
123 }
|
|
124 public void setWx(float wx) {
|
|
125 this.wx = wx;
|
|
126 }
|
|
127 public float getWy() {
|
|
128 return wy;
|
|
129 }
|
|
130 public void setWy(float wy) {
|
|
131 this.wy = wy;
|
|
132 }
|
|
133 public float getWw() {
|
|
134 return ww;
|
|
135 }
|
|
136 public void setWw(float ww) {
|
|
137 this.ww = ww;
|
|
138 }
|
|
139 public float getWh() {
|
|
140 return wh;
|
|
141 }
|
|
142 public void setWh(float wh) {
|
|
143 this.wh = wh;
|
|
144 }
|
|
145 public float getWs() {
|
|
146 return ws;
|
|
147 }
|
|
148 public void setWs(float ws) {
|
|
149 this.ws = ws;
|
|
150 }
|
|
151 public String getMo() {
|
|
152 return mo;
|
|
153 }
|
|
154 public void setMo(String mo) {
|
|
155 this.mo = mo;
|
|
156 }
|
|
157 public float getCont() {
|
|
158 return cont;
|
|
159 }
|
|
160 public void setCont(float cont) {
|
|
161 this.cont = cont;
|
|
162 }
|
|
163 public float getBrgt() {
|
|
164 return brgt;
|
|
165 }
|
|
166 public void setBrgt(float brgt) {
|
|
167 this.brgt = brgt;
|
|
168 }
|
|
169 public float getRot() {
|
|
170 return rot;
|
|
171 }
|
|
172 public void setRot(float rot) {
|
|
173 this.rot = rot;
|
|
174 }
|
|
175 public String getRgbm() {
|
|
176 return rgbm;
|
|
177 }
|
|
178 public void setRgbm(String rgbm) {
|
|
179 this.rgbm = rgbm;
|
|
180 }
|
|
181 public String getRgba() {
|
|
182 return rgba;
|
|
183 }
|
|
184 public void setRgba(String rgba) {
|
|
185 this.rgba = rgba;
|
|
186 }
|
|
187 public int getDdpi() {
|
|
188 return ddpi;
|
|
189 }
|
|
190 public void setDdpi(int ddpi) {
|
|
191 this.ddpi = ddpi;
|
|
192 }
|
|
193 public int getDdpix() {
|
|
194 return ddpix;
|
|
195 }
|
|
196 public void setDdpix(int ddpix) {
|
|
197 this.ddpix = ddpix;
|
|
198 }
|
|
199 public int getDdpiy() {
|
|
200 return ddpiy;
|
|
201 }
|
|
202 public void setDdpiy(int ddpiy) {
|
|
203 this.ddpiy = ddpiy;
|
|
204 }
|
|
205
|
|
206
|
|
207
|
21
|
208 /**
|
|
209 * Converts the parameters in to map.
|
|
210 * @param omitIfNegative list of parameters not to be included in the map if negative
|
|
211 * @return Map with parameter names and values.
|
|
212 */
|
20
|
213 public Map<String, String> createMapFromParameters(List<String> omitIfNegative) {
|
|
214
|
|
215
|
|
216 Map<String,String> qa= new HashMap<String,String>();
|
|
217
|
|
218 setPm(qa,"fn",getFn(),omitIfNegative);
|
|
219 setPm(qa,"pn",getPn(),omitIfNegative);
|
|
220
|
|
221 setPm(qa,"dw",getDw(),omitIfNegative);
|
|
222 setPm(qa,"dh",getDh(),omitIfNegative);
|
|
223
|
|
224 setPm(qa,"wx",getWx(),omitIfNegative);
|
|
225 setPm(qa,"wy",getWy(),omitIfNegative);
|
|
226 setPm(qa,"ws",getWs(),omitIfNegative);
|
|
227 setPm(qa,"ww",getWw(),omitIfNegative);
|
|
228 setPm(qa,"wh",getWh(),omitIfNegative);
|
|
229
|
|
230
|
|
231 setPm(qa,"mo",getMo(),omitIfNegative);
|
|
232
|
|
233 setPm(qa,"cont",getCont(),omitIfNegative);
|
|
234 setPm(qa,"brgt",getBrgt(),omitIfNegative);
|
|
235
|
|
236 setPm(qa,"rot",getRot(),omitIfNegative);
|
|
237
|
|
238 setPm(qa,"rgba",getRgba(),omitIfNegative);
|
|
239 setPm(qa,"rgbm",getRgbm(),omitIfNegative);
|
|
240
|
|
241 setPm(qa,"ddpi",getDdpi(),omitIfNegative);
|
|
242 setPm(qa,"ddpix",getDdpix(),omitIfNegative);
|
|
243 setPm(qa,"ddpiy",getDdpiy(),omitIfNegative);
|
|
244 return qa;
|
|
245 }
|
|
246
|
|
247
|
|
248
|
|
249
|
|
250 /**
|
21
|
251 * Puts the parameter as key-value into the map respecting the setting omitIfNegative.
|
|
252 * @param qa Map to be filled
|
20
|
253 * @param key
|
|
254 * @param value
|
21
|
255 * @param omitIfNegative list of parameters not to be included in the map if negative
|
20
|
256 */
|
|
257 private void setPm(Map<String, String> qa, String key, Object value, List<String> omitIfNegative){
|
|
258 String v;
|
|
259
|
|
260 if (omitIfNegative==null){
|
|
261 qa.put(key, String.valueOf(value));
|
|
262 return;
|
|
263 }
|
|
264 if (String.class.isInstance(value)){
|
|
265 v=(String)value;
|
|
266 qa.put(key, v);
|
|
267 } else if (Integer.class.isInstance(value)){
|
|
268 if (!((Integer)value==-1 & omitIfNegative.indexOf(key)>-1)) { // nicht vernachlaessigen
|
|
269 v=String.valueOf(value);
|
|
270 qa.put(key, v);
|
|
271 }
|
|
272 } else {
|
|
273 v=String.valueOf(value);
|
|
274 qa.put(key, v);
|
|
275 }
|
|
276
|
|
277 }
|
27
|
278
|
|
279 public void setType(int type) {
|
|
280 // TODO Auto-generated method stub
|
|
281
|
|
282 }
|
1
|
283
|
|
284
|
|
285
|
|
286 }
|