1
|
1 package de.mpg.mpiwg.itgroup.digilib.digiImage;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.io.InputStream;
|
|
5 import java.net.MalformedURLException;
|
|
6 import java.net.URL;
|
|
7 import java.util.ArrayList;
|
|
8 import java.util.Arrays;
|
|
9 import java.util.HashMap;
|
|
10 import java.util.List;
|
|
11 import java.util.Map;
|
|
12
|
|
13 import org.apache.axiom.om.OMOutputFormat;
|
|
14 import org.apache.axis2.databinding.types.soapencoding.Array;
|
|
15 import org.apache.commons.lang.StringUtils;
|
|
16 import org.eclipse.swt.SWT;
|
|
17 import org.eclipse.swt.graphics.Image;
|
|
18 import org.eclipse.swt.graphics.Point;
|
|
19 import org.eclipse.swt.widgets.Composite;
|
|
20 import org.eclipse.swt.widgets.Label;
|
|
21
|
|
22 import de.mpg.mpiwg.itgroup.digilib.manipulator.extensions.RectangleListener;
|
|
23
|
|
24
|
|
25
|
|
26
|
|
27 public class DigiImage implements IDigiImage {
|
|
28
|
|
29 private static String[] omitIfNegativeArray = {"dw","dh","ddpi","ddpix","ddpiy"};
|
|
30 private static List<String> omitIfNegative = Arrays.asList(omitIfNegativeArray);
|
|
31
|
|
32 private Label label;
|
|
33 public Label getLabel() {
|
|
34 return label;
|
|
35 }
|
|
36
|
|
37 public void setLabel(Label label) {
|
|
38 this.label = label;
|
|
39 }
|
|
40
|
|
41 private URL url;
|
|
42 private Composite parent;
|
|
43 private String baseUrl="http://digilib.mpiwg-berlin.mpg.de/digitallibrary/servlet/Scaler";
|
|
44 private DigiImageParameter dp;
|
|
45
|
|
46
|
|
47 public DigiImage(Composite parent, int style, DigiImageParameter dp) {
|
|
48 //super(parent,style);
|
|
49 label = new Label(parent, style);
|
|
50 this.parent = parent;
|
|
51 this.dp=dp;
|
|
52 try {
|
|
53 setNewURL(createUrlFromParameter(dp));
|
|
54 } catch (MalformedURLException e) {
|
|
55 // TODO Auto-generated catch block
|
|
56 e.printStackTrace();
|
|
57 }
|
|
58
|
|
59 }
|
|
60
|
|
61 private void setNewURL(URL url) {
|
|
62 this.url = url;
|
|
63 // TODO Auto-generated constructor stub
|
|
64
|
|
65 InputStream is;
|
|
66 try {
|
|
67 is = url.openStream();
|
|
68 } catch (IOException e) {
|
|
69 // TODO Auto-generated catch block
|
|
70 e.printStackTrace();
|
|
71 return;
|
|
72 }
|
|
73 Image img = new Image(parent.getDisplay(),is);
|
|
74 //Label label = new Label(parent, SWT.None);
|
|
75 label.setImage(img);
|
|
76
|
|
77 label.setVisible(true);
|
|
78 }
|
|
79
|
|
80
|
|
81 public Composite getParent() {
|
|
82 return parent;
|
|
83 }
|
|
84
|
|
85
|
|
86 private URL createUrlFromParameter(DigiImageParameter dp) throws MalformedURLException{
|
|
87 URL url;
|
|
88 Map<String,String> qa= new HashMap<String,String>();
|
|
89
|
|
90 setPm(qa,"fn",dp.getFn());
|
|
91 setPm(qa,"pn",dp.getPn());
|
|
92
|
|
93 setPm(qa,"dw",dp.getDw());
|
|
94 setPm(qa,"dh",dp.getDh());
|
|
95
|
|
96 setPm(qa,"wx",dp.getWx());
|
|
97 setPm(qa,"wy",dp.getWy());
|
|
98 setPm(qa,"ws",dp.getWs());
|
|
99 setPm(qa,"ww",dp.getWw());
|
|
100 setPm(qa,"wh",dp.getWh());
|
|
101
|
|
102
|
|
103 setPm(qa,"mo",dp.getMo());
|
|
104
|
|
105 setPm(qa,"cont",dp.getCont());
|
|
106 setPm(qa,"brgt",dp.getBrgt());
|
|
107
|
|
108 setPm(qa,"rot",dp.getRot());
|
|
109
|
|
110 setPm(qa,"rgba",dp.getRgba());
|
|
111 setPm(qa,"rgbm",dp.getRgbm());
|
|
112
|
|
113 setPm(qa,"ddpi",dp.getDdpi());
|
|
114 setPm(qa,"ddpix",dp.getDdpix());
|
|
115 setPm(qa,"ddpiy",dp.getDdpiy());
|
|
116
|
|
117 List<String> queryArray = new ArrayList<String>();
|
|
118 for(String key:qa.keySet()){
|
|
119 queryArray.add(key+"="+qa.get(key));
|
|
120 }
|
|
121 String queryString = StringUtils.join(queryArray,"&");
|
|
122
|
|
123 String stringUrl=baseUrl+"?"+queryString;
|
|
124 return new URL(stringUrl);
|
|
125 }
|
|
126
|
|
127 private void setPm(Map<String, String> qa, String key, Object value){
|
|
128 String v;
|
|
129 if (String.class.isInstance(value)){
|
|
130 v=(String)value;
|
|
131 qa.put(key, v);
|
|
132 } else if (Integer.class.isInstance(value)){
|
|
133 if (!((Integer)value==-1 & omitIfNegative.indexOf(key)>-1)) { // nicht vernachlaessigen
|
|
134 v=String.valueOf(value);
|
|
135 qa.put(key, v);
|
|
136 }
|
|
137 } else {
|
|
138 v=String.valueOf(value);
|
|
139 qa.put(key, v);
|
|
140 }
|
|
141
|
|
142 }
|
|
143
|
|
144 public DigiImageParameter getParameter() {
|
|
145
|
|
146 return dp;
|
|
147 }
|
|
148
|
|
149 public void setParameter(DigiImageParameter dp) {
|
|
150 this.dp=dp;
|
|
151
|
|
152 }
|
|
153
|
|
154 public void redraw(){
|
|
155 try {
|
|
156 setNewURL(createUrlFromParameter(dp));
|
|
157 } catch (MalformedURLException e) {
|
|
158 // TODO Auto-generated catch block
|
|
159 e.printStackTrace();
|
|
160 }
|
|
161 }
|
|
162
|
|
163 private RectangleListener rectangleListener=null;
|
|
164
|
|
165 public RectangleListener getRectangleListener() {
|
|
166 // TODO Auto-generated method stub
|
|
167 return rectangleListener;
|
|
168 }
|
|
169
|
|
170 public void setRectangleListener(RectangleListener rectangleListener) {
|
|
171 this.rectangleListener = rectangleListener;
|
|
172 }
|
|
173
|
|
174 }
|
|
175
|
|
176
|