Mercurial > hg > de.mpg.mpiwg.itgroup.digilib.core
comparison src/de/mpg/mpiwg/itgroup/digilib/digiImage/TextGridDigiImage.java @ 27:ee955cf6c9c5
first commit
author | dwinter |
---|---|
date | Fri, 17 Jun 2011 14:24:34 +0200 |
parents | |
children | fbcf122a6a24 |
comparison
equal
deleted
inserted
replaced
26:183c3e96f6c3 | 27:ee955cf6c9c5 |
---|---|
1 package de.mpg.mpiwg.itgroup.digilib.digiImage; | |
2 | |
3 import info.textgrid.namespaces.middleware.digilib.services.digilibservice.DigilibService; | |
4 import info.textgrid.namespaces.middleware.digilib.services.digilibservice.DigilibServicePortType; | |
5 | |
6 import java.io.ByteArrayInputStream; | |
7 import java.io.IOException; | |
8 import java.io.InputStream; | |
9 import java.net.MalformedURLException; | |
10 import java.net.URL; | |
11 import java.util.ArrayList; | |
12 import java.util.Arrays; | |
13 import java.util.List; | |
14 import java.util.Map; | |
15 | |
16 import javax.xml.ws.Holder; | |
17 | |
18 import org.apache.commons.lang.StringUtils; | |
19 import org.eclipse.jface.viewers.ISelection; | |
20 import org.eclipse.jface.viewers.ISelectionChangedListener; | |
21 import org.eclipse.jface.viewers.SelectionChangedEvent; | |
22 import org.eclipse.jface.viewers.StructuredSelection; | |
23 import org.eclipse.swt.graphics.Image; | |
24 import org.eclipse.swt.widgets.Composite; | |
25 import org.eclipse.swt.widgets.Label; | |
26 | |
27 import de.mpg.mpiwg.itgroup.digilib.manipulator.extensions.ZoomAreaRectangleListener; | |
28 import de.mpg.mpiwg.itgroup.digilib.plugin.editors.DigilibLinkEditorObservable; | |
29 | |
30 public class TextGridDigiImage implements IDigiImage { | |
31 //private URL url; | |
32 private Composite parent; | |
33 | |
34 private DigiImageParameter dp; | |
35 | |
36 private String baseUrl; | |
37 | |
38 private Label label; | |
39 | |
40 private ZoomAreaRectangleListener rectangleListener=null; | |
41 | |
42 private List<ISelectionChangedListener> selectionChangeListener = new ArrayList<ISelectionChangedListener>(); | |
43 | |
44 private DigilibService service; | |
45 | |
46 private DigilibServicePortType port; | |
47 | |
48 /* some parameters should not occur in the URL constructed by {@link #createUrlFromParameter(DigiImageParameter)} if set to negative values. | |
49 * | |
50 */ | |
51 private static String[] omitIfNegativeArray = {"dw","dh","ddpi","ddpix","ddpiy"}; | |
52 private static List<String> omitIfNegative = Arrays.asList(omitIfNegativeArray); | |
53 | |
54 String logParam = null; | |
55 // Holder for return data | |
56 Holder<String> mimeType = new Holder<String>(); | |
57 Holder<byte[]> imageData = new Holder<byte[]>(); | |
58 Holder<Integer> width = new Holder<Integer>(); | |
59 Holder<Integer> height = new Holder<Integer>(); | |
60 | |
61 private String sid; | |
62 | |
63 public TextGridDigiImage(Composite parent, int style, | |
64 DigiImageParameter dp, String sid) { | |
65 label = new Label(parent, style); | |
66 this.parent = parent; | |
67 this.dp=dp; | |
68 try { | |
69 service = new DigilibService(new URL("http://localhost:8080/digilibservice-service/service?wsdl")); | |
70 } catch (MalformedURLException e) { | |
71 // TODO Auto-generated catch block | |
72 e.printStackTrace(); | |
73 } | |
74 port = service.getDigilibServicePort(); | |
75 this.sid=sid; | |
76 this.dp=dp; | |
77 try { | |
78 createNewImage(createQueryFromParameter(dp)); | |
79 } catch (MalformedURLException e) { | |
80 // TODO Auto-generated catch block | |
81 e.printStackTrace(); | |
82 } | |
83 // TODO Auto-generated constructor stub | |
84 } | |
85 | |
86 public void addSelectionChangedListener(ISelectionChangedListener listener) { | |
87 selectionChangeListener.add(listener); | |
88 | |
89 } | |
90 | |
91 public ISelection getSelection() { | |
92 return new StructuredSelection(this); | |
93 } | |
94 | |
95 public void removeSelectionChangedListener( | |
96 ISelectionChangedListener listener) { | |
97 selectionChangeListener.remove(listener); | |
98 | |
99 } | |
100 | |
101 public void setSelection(ISelection selection) { | |
102 for (ISelectionChangedListener sl: selectionChangeListener){ | |
103 SelectionChangedEvent event = new SelectionChangedEvent(this, selection); | |
104 sl.selectionChanged(event); | |
105 | |
106 } | |
107 } | |
108 | |
109 public DigiImageParameter getParameter() { | |
110 | |
111 return dp; | |
112 } | |
113 | |
114 public void setParameter(DigiImageParameter dp) { | |
115 this.dp=dp; | |
116 | |
117 } | |
118 | |
119 public void redraw() { | |
120 try { | |
121 createNewImage(createQueryFromParameter(dp)); | |
122 setSelection(new StructuredSelection(this)); | |
123 DigilibLinkEditorObservable.INSTANCE.imageHasChanged(this); | |
124 | |
125 } catch (MalformedURLException e) { | |
126 // TODO Auto-generated catch block | |
127 e.printStackTrace(); | |
128 } | |
129 } | |
130 private void createNewImage(String query) { | |
131 | |
132 port.getScaledImage(sid,dp.fn, query, logParam, mimeType, imageData, width, height); | |
133 | |
134 Image img = new Image(parent.getDisplay(),new ByteArrayInputStream(imageData.value)) | |
135 ; | |
136 //Label label = new Label(parent, SWT.None); | |
137 label.setImage(img); | |
138 | |
139 label.setVisible(true); | |
140 | |
141 } | |
142 | |
143 private String createQueryFromParameter(DigiImageParameter dp) throws MalformedURLException { | |
144 Map<String, String> qa = dp.createMapFromParameters(omitIfNegative); | |
145 | |
146 List<String> queryArray = new ArrayList<String>(); | |
147 for(String key:qa.keySet()){ | |
148 queryArray.add(key+"="+qa.get(key)); | |
149 } | |
150 String queryString = StringUtils.join(queryArray,"&"); | |
151 | |
152 String stringUrl=queryString; | |
153 | |
154 return stringUrl; | |
155 } | |
156 | |
157 public Label getLabel() { | |
158 return label; | |
159 | |
160 } | |
161 | |
162 public void setLabel(Label label) { | |
163 this.label = label; | |
164 | |
165 } | |
166 | |
167 public ZoomAreaRectangleListener getRectangleListener() { | |
168 return rectangleListener; | |
169 } | |
170 | |
171 public void setRectangleListener(ZoomAreaRectangleListener rectangleListener) { | |
172 this.rectangleListener = rectangleListener; | |
173 } | |
174 | |
175 public Composite getParent() { | |
176 return parent; | |
177 } | |
178 | |
179 } |