Mercurial > hg > de.mpg.mpiwg.itgroup.digilib.plugin
comparison src/de/mpg/mpiwg/itgroup/digilib/digiImage/DigiImage.java @ 9:e63a64652f4d
added comments
author | dwinter |
---|---|
date | Mon, 03 Jan 2011 16:53:48 +0100 |
parents | 83c58ea33792 |
children | 2f47c136b8a6 |
comparison
equal
deleted
inserted
replaced
8:52023cf79d86 | 9:e63a64652f4d |
---|---|
8 import java.util.Arrays; | 8 import java.util.Arrays; |
9 import java.util.HashMap; | 9 import java.util.HashMap; |
10 import java.util.List; | 10 import java.util.List; |
11 import java.util.Map; | 11 import java.util.Map; |
12 | 12 |
13 import org.apache.axiom.om.OMOutputFormat; | |
14 import org.apache.axis2.databinding.types.soapencoding.Array; | |
15 import org.apache.commons.lang.StringUtils; | 13 import org.apache.commons.lang.StringUtils; |
16 import org.eclipse.swt.SWT; | |
17 import org.eclipse.swt.graphics.Image; | 14 import org.eclipse.swt.graphics.Image; |
18 import org.eclipse.swt.graphics.Point; | |
19 import org.eclipse.swt.widgets.Composite; | 15 import org.eclipse.swt.widgets.Composite; |
20 import org.eclipse.swt.widgets.Label; | 16 import org.eclipse.swt.widgets.Label; |
21 | 17 |
22 import de.mpg.mpiwg.itgroup.digilib.manipulator.extensions.RectangleListener; | 18 import de.mpg.mpiwg.itgroup.digilib.manipulator.extensions.ZoomAreaRectangleListener; |
23 | 19 |
24 | 20 |
25 | 21 |
26 | 22 |
23 /** | |
24 * Refers to an Digilib-Scaler Object either an image or an folder. The object contains an swt-label object, so that it can be embedded e.g. in Eclipse. | |
25 * @author dwinter | |
26 * | |
27 */ | |
27 public class DigiImage implements IDigiImage { | 28 public class DigiImage implements IDigiImage { |
28 | 29 |
29 private static String[] omitIfNegativeArray = {"dw","dh","ddpi","ddpix","ddpiy"}; | 30 /** |
31 * Implemens a connection to Digilib. | |
32 */ | |
33 | |
34 | |
35 /* some parameters should not occur in the URL constructed by {@link #createUrlFromParameter(DigiImageParameter)} if set to negative values. | |
36 * | |
37 */ | |
38 private static String[] omitIfNegativeArray = {"dw","dh","ddpi","ddpix","ddpiy"}; | |
30 private static List<String> omitIfNegative = Arrays.asList(omitIfNegativeArray); | 39 private static List<String> omitIfNegative = Arrays.asList(omitIfNegativeArray); |
31 | 40 |
41 | |
42 private String baseUrl="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler"; | |
43 | |
44 /** | |
45 * Get the Url of the digilib scaler, set to http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler, if not changed. | |
46 * TODO should be part of a configuration/preference file | |
47 * @return | |
48 */ | |
49 public String getBaseUrl() { | |
50 return baseUrl; | |
51 } | |
52 | |
53 /** | |
54 * Setze die Basis url des Digilib-Scalers | |
55 * @param baseUrl | |
56 */ | |
57 public void setBaseUrl(String baseUrl) { | |
58 this.baseUrl = baseUrl; | |
59 } | |
60 | |
32 private Label label; | 61 private Label label; |
62 | |
63 /* (non-Javadoc) | |
64 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getLabel() | |
65 */ | |
33 public Label getLabel() { | 66 public Label getLabel() { |
34 return label; | 67 return label; |
35 } | 68 } |
36 | 69 |
70 /* (non-Javadoc) | |
71 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#setLabel(org.eclipse.swt.widgets.Label) | |
72 */ | |
37 public void setLabel(Label label) { | 73 public void setLabel(Label label) { |
38 this.label = label; | 74 this.label = label; |
39 } | 75 } |
40 | 76 |
41 private URL url; | 77 //private URL url; |
42 private Composite parent; | 78 private Composite parent; |
43 private String baseUrl="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler"; | 79 |
44 private DigiImageParameter dp; | 80 private DigiImageParameter dp; |
45 | 81 |
46 | 82 |
83 /** | |
84 * | |
85 * @param parent Composite where the image should be become a child of. | |
86 * @param style SWT Style how to display the image as a composite. For more the the style parameter at @see import org.eclipse.swt.widgets.Label | |
87 * @param dp Set of Parameters which define how the image should be displayed. | |
88 */ | |
47 public DigiImage(Composite parent, int style, DigiImageParameter dp) { | 89 public DigiImage(Composite parent, int style, DigiImageParameter dp) { |
48 //super(parent,style); | 90 //super(parent,style); |
49 label = new Label(parent, style); | 91 label = new Label(parent, style); |
50 this.parent = parent; | 92 this.parent = parent; |
51 this.dp=dp; | 93 this.dp=dp; |
56 e.printStackTrace(); | 98 e.printStackTrace(); |
57 } | 99 } |
58 | 100 |
59 } | 101 } |
60 | 102 |
103 /** | |
104 * Sets the complete URL of the manipulated image and changes the image object in the composite. | |
105 * @param url | |
106 */ | |
61 private void setNewURL(URL url) { | 107 private void setNewURL(URL url) { |
62 this.url = url; | 108 //this.url = url; |
63 // TODO Auto-generated constructor stub | 109 |
64 | 110 |
65 InputStream is; | 111 InputStream is; |
66 try { | 112 try { |
67 is = url.openStream(); | 113 is = url.openStream(); |
68 } catch (IOException e) { | 114 } catch (IOException e) { |
76 | 122 |
77 label.setVisible(true); | 123 label.setVisible(true); |
78 } | 124 } |
79 | 125 |
80 | 126 |
127 /* (non-Javadoc) | |
128 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getParent() | |
129 */ | |
81 public Composite getParent() { | 130 public Composite getParent() { |
82 return parent; | 131 return parent; |
83 } | 132 } |
84 | 133 |
85 | 134 |
135 /** | |
136 * Creates the URL to digilib from the given parameter set. For the documentation @see {@link http://developer.berlios.de/docman/display_doc.php?docid=106&group_id=251}. | |
137 * @param dp | |
138 * @return | |
139 * @throws MalformedURLException | |
140 */ | |
86 private URL createUrlFromParameter(DigiImageParameter dp) throws MalformedURLException{ | 141 private URL createUrlFromParameter(DigiImageParameter dp) throws MalformedURLException{ |
87 URL url; | 142 |
88 Map<String,String> qa= new HashMap<String,String>(); | 143 Map<String,String> qa= new HashMap<String,String>(); |
89 | 144 |
90 setPm(qa,"fn",dp.getFn()); | 145 setPm(qa,"fn",dp.getFn()); |
91 setPm(qa,"pn",dp.getPn()); | 146 setPm(qa,"pn",dp.getPn()); |
92 | 147 |
122 | 177 |
123 String stringUrl=baseUrl+"?"+queryString; | 178 String stringUrl=baseUrl+"?"+queryString; |
124 return new URL(stringUrl); | 179 return new URL(stringUrl); |
125 } | 180 } |
126 | 181 |
182 /** | |
183 * Puts the parameter as key-value into the map repecting the setting in @see {@link #omitIfNegativeArray}. | |
184 * @param qa | |
185 * @param key | |
186 * @param value | |
187 */ | |
127 private void setPm(Map<String, String> qa, String key, Object value){ | 188 private void setPm(Map<String, String> qa, String key, Object value){ |
128 String v; | 189 String v; |
129 if (String.class.isInstance(value)){ | 190 if (String.class.isInstance(value)){ |
130 v=(String)value; | 191 v=(String)value; |
131 qa.put(key, v); | 192 qa.put(key, v); |
139 qa.put(key, v); | 200 qa.put(key, v); |
140 } | 201 } |
141 | 202 |
142 } | 203 } |
143 | 204 |
205 /* (non-Javadoc) | |
206 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getParameter() | |
207 */ | |
144 public DigiImageParameter getParameter() { | 208 public DigiImageParameter getParameter() { |
145 | 209 |
146 return dp; | 210 return dp; |
147 } | 211 } |
148 | 212 |
213 /* (non-Javadoc) | |
214 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#setParameter(de.mpg.mpiwg.itgroup.digilib.digiImage.DigiImageParameter) | |
215 */ | |
149 public void setParameter(DigiImageParameter dp) { | 216 public void setParameter(DigiImageParameter dp) { |
150 this.dp=dp; | 217 this.dp=dp; |
151 | 218 |
152 } | 219 } |
153 | 220 |
221 /* (non-Javadoc) | |
222 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#redraw() | |
223 */ | |
154 public void redraw(){ | 224 public void redraw(){ |
155 try { | 225 try { |
156 setNewURL(createUrlFromParameter(dp)); | 226 setNewURL(createUrlFromParameter(dp)); |
157 } catch (MalformedURLException e) { | 227 } catch (MalformedURLException e) { |
158 // TODO Auto-generated catch block | 228 // TODO Auto-generated catch block |
159 e.printStackTrace(); | 229 e.printStackTrace(); |
160 } | 230 } |
161 } | 231 } |
162 | 232 |
163 private RectangleListener rectangleListener=null; | 233 |
164 | 234 private ZoomAreaRectangleListener rectangleListener=null; |
165 public RectangleListener getRectangleListener() { | 235 |
166 // TODO Auto-generated method stub | 236 /* (non-Javadoc) |
237 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#getRectangleListener() | |
238 */ | |
239 public ZoomAreaRectangleListener getRectangleListener() { | |
240 | |
167 return rectangleListener; | 241 return rectangleListener; |
168 } | 242 } |
169 | 243 |
170 public void setRectangleListener(RectangleListener rectangleListener) { | 244 /* (non-Javadoc) |
245 * @see de.mpg.mpiwg.itgroup.digilib.digiImage.IDigiImage#setRectangleListener(de.mpg.mpiwg.itgroup.digilib.manipulator.extensions.RectangleListener) | |
246 */ | |
247 public void setRectangleListener(ZoomAreaRectangleListener rectangleListener) { | |
171 this.rectangleListener = rectangleListener; | 248 this.rectangleListener = rectangleListener; |
172 } | 249 } |
173 | 250 |
174 } | 251 } |
175 | 252 |