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