1 | package org.greenstone.atlas.client;
|
---|
2 |
|
---|
3 | import com.google.gwt.core.client.EntryPoint;
|
---|
4 | import com.google.gwt.core.client.GWT;
|
---|
5 | import com.google.gwt.core.client.JsArray;
|
---|
6 | import com.google.gwt.user.client.DOM;
|
---|
7 | import com.google.gwt.user.client.Element;
|
---|
8 | import com.google.gwt.user.client.Window;
|
---|
9 | import com.google.gwt.event.dom.client.ChangeEvent;
|
---|
10 | import com.google.gwt.event.dom.client.ChangeHandler;
|
---|
11 | import com.google.gwt.event.dom.client.ClickEvent;
|
---|
12 | import com.google.gwt.event.dom.client.ClickHandler;
|
---|
13 | import com.google.gwt.event.dom.client.MouseMoveEvent;
|
---|
14 | import com.google.gwt.event.dom.client.MouseMoveHandler;
|
---|
15 | import com.google.gwt.event.dom.client.MouseOutEvent;
|
---|
16 | import com.google.gwt.event.dom.client.MouseOutHandler;
|
---|
17 | import com.google.gwt.event.dom.client.MouseOverEvent;
|
---|
18 | import com.google.gwt.event.dom.client.MouseOverHandler;
|
---|
19 | import com.google.gwt.event.dom.client.MouseUpEvent;
|
---|
20 | import com.google.gwt.event.dom.client.MouseUpHandler;
|
---|
21 | import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
---|
22 | import com.google.gwt.event.logical.shared.ValueChangeHandler;
|
---|
23 | import com.google.gwt.event.shared.HandlerRegistration;
|
---|
24 | import com.google.gwt.http.client.Request;
|
---|
25 | import com.google.gwt.http.client.Response;
|
---|
26 | import com.google.gwt.http.client.RequestBuilder;
|
---|
27 | import com.google.gwt.http.client.RequestCallback;
|
---|
28 | import com.google.gwt.maps.client.InfoWindow;
|
---|
29 | import com.google.gwt.maps.client.InfoWindowContent;
|
---|
30 | import com.google.gwt.maps.client.MapWidget;
|
---|
31 | import com.google.gwt.maps.client.control.ControlAnchor;
|
---|
32 | import com.google.gwt.maps.client.control.ControlPosition;
|
---|
33 | import com.google.gwt.maps.client.control.LargeMapControl;
|
---|
34 | import com.google.gwt.maps.client.control.MapTypeControl;
|
---|
35 | import com.google.gwt.maps.client.control.Control.CustomControl;
|
---|
36 | import com.google.gwt.maps.client.event.MapClickHandler;
|
---|
37 | import com.google.gwt.maps.client.event.MapMoveHandler;
|
---|
38 | import com.google.gwt.maps.client.event.PolygonClickHandler;
|
---|
39 | import com.google.gwt.maps.client.geocode.Geocoder;
|
---|
40 | import com.google.gwt.maps.client.geocode.LatLngCallback;
|
---|
41 | import com.google.gwt.maps.client.geom.LatLng;
|
---|
42 | import com.google.gwt.maps.client.overlay.Marker;
|
---|
43 | import com.google.gwt.maps.client.overlay.MarkerOptions;
|
---|
44 | import com.google.gwt.maps.client.overlay.Polygon;
|
---|
45 | import com.google.gwt.maps.client.overlay.Polyline;
|
---|
46 | import com.google.gwt.maps.client.overlay.PolylineOptions;
|
---|
47 | import com.google.gwt.user.client.Timer;
|
---|
48 | import com.google.gwt.user.client.rpc.AsyncCallback;
|
---|
49 | import com.google.gwt.user.client.rpc.ServiceDefTarget;
|
---|
50 | import com.google.gwt.user.client.ui.Button;
|
---|
51 | import com.google.gwt.user.client.ui.CheckBox;
|
---|
52 | import com.google.gwt.user.client.ui.FlowPanel;
|
---|
53 | import com.google.gwt.user.client.ui.FormPanel;
|
---|
54 | import com.google.gwt.user.client.ui.HTML;
|
---|
55 | import com.google.gwt.user.client.ui.Hidden;
|
---|
56 | import com.google.gwt.user.client.ui.HorizontalPanel;
|
---|
57 | import com.google.gwt.user.client.ui.Label;
|
---|
58 | import com.google.gwt.user.client.ui.ListBox;
|
---|
59 | import com.google.gwt.user.client.ui.RootPanel;
|
---|
60 | import com.google.gwt.user.client.ui.VerticalPanel;
|
---|
61 | import com.google.gwt.user.client.ui.Widget;
|
---|
62 | import com.google.gwt.xml.client.NamedNodeMap;
|
---|
63 | import com.google.gwt.dom.client.Document;
|
---|
64 | import com.google.gwt.dom.client.FormElement;
|
---|
65 | import com.google.gwt.dom.client.InputElement;
|
---|
66 | import com.google.gwt.dom.client.NativeEvent;
|
---|
67 | import com.google.gwt.dom.client.Node;
|
---|
68 | import com.google.gwt.dom.client.NodeCollection;
|
---|
69 | import com.google.gwt.dom.client.NodeList;
|
---|
70 | import com.google.gwt.dom.client.OptionElement;
|
---|
71 | import com.google.gwt.dom.client.SelectElement;
|
---|
72 | import com.google.gwt.dom.client.TextAreaElement;
|
---|
73 |
|
---|
74 | import java.util.ArrayList;
|
---|
75 | import java.util.HashMap;
|
---|
76 |
|
---|
77 | public class GS3MapLibrary implements EntryPoint
|
---|
78 | {
|
---|
79 | protected MapWidget _map;
|
---|
80 |
|
---|
81 | protected VerticalPanel _containerPanel = new VerticalPanel();
|
---|
82 | protected VerticalPanel _scoreAdjustPanel = new VerticalPanel();
|
---|
83 | protected VerticalPanel _headerDiv = new VerticalPanel();
|
---|
84 | protected HorizontalPanel _viewPanel = new HorizontalPanel();
|
---|
85 |
|
---|
86 | protected StatusBar _statusBar = null;
|
---|
87 |
|
---|
88 | protected HTML _gsPanel = new HTML();
|
---|
89 | protected HTML _columnViewBox = new HTML();
|
---|
90 |
|
---|
91 | protected HorizontalPanel _contentDiv = new HorizontalPanel();
|
---|
92 | protected HorizontalPanel _footerDiv = new HorizontalPanel();
|
---|
93 |
|
---|
94 | protected Menu _currentDocumentMenu = null;
|
---|
95 | protected Menu _lastCreatedPlaceMenu = null;
|
---|
96 |
|
---|
97 | protected FlowPanel _radioPanel = new FlowPanel();
|
---|
98 | protected FlowPanel _checkBoxPanel = new FlowPanel();
|
---|
99 |
|
---|
100 | protected Label _loadingBox = new Label("");
|
---|
101 | protected Label _mapLoadingLabel = new Label("Loading map content");
|
---|
102 |
|
---|
103 | protected ListBox _textViewSelector = new ListBox();
|
---|
104 |
|
---|
105 | protected Button _geoQueryButton = new Button("Specify Search Square");
|
---|
106 |
|
---|
107 | protected Timer _loadingTimer = null;
|
---|
108 | protected Timer _resizeCheckTimer = null;
|
---|
109 | protected Timer _scrollCheckTimer = null;
|
---|
110 | protected Timer _placeMouseOverTimer = null;
|
---|
111 | protected Timer _documentMouseOverTimer = null;
|
---|
112 | protected Timer _menuOverTimer = null;
|
---|
113 | protected Timer _menuOutTimer = null;
|
---|
114 |
|
---|
115 | protected Geocoder _geocoder = null;
|
---|
116 |
|
---|
117 | protected static FindPlaceServiceAsync _findPlaceService = GWT.create(FindPlaceService.class);
|
---|
118 |
|
---|
119 | protected ArrayList<Place> _currentPlaces = null;
|
---|
120 | protected ArrayList<String> _highlightedPlaces = new ArrayList<String>();
|
---|
121 | protected ArrayList<String> _highlightedTextPlaces = new ArrayList<String>();
|
---|
122 | protected ArrayList<Boolean> _visiblePlaceSets = new ArrayList<Boolean>();
|
---|
123 | protected ArrayList<LatLng> _areaPoints = new ArrayList<LatLng>();
|
---|
124 | protected ArrayList<String> _removedPlaces = new ArrayList<String>();
|
---|
125 |
|
---|
126 | protected ArrayList<ArrayList<Place>> _currentMultiPlaces = null;
|
---|
127 |
|
---|
128 | protected HashMap<String, Place> _chosenPlaces = new HashMap<String, Place>();
|
---|
129 |
|
---|
130 | protected HandlerRegistration _fishEyeHandlerReg = null;
|
---|
131 | protected HandlerRegistration _columnViewHandlerReg = null;
|
---|
132 |
|
---|
133 | protected MapMoveHandler _mapMoveHandler = null;
|
---|
134 | protected MapClickHandler _spatialSearchClickHandler = null;
|
---|
135 | protected SpatialSearchControls _searchControls = null;
|
---|
136 |
|
---|
137 | protected final int _MAXVISIBLEMARKERS = 500;
|
---|
138 | protected int _currentZoomLevel = 2;
|
---|
139 | protected int _loadingCount = 0;
|
---|
140 | protected int _currentBrowserPixelWidth = 0;
|
---|
141 | protected int _currentBrowserPixelHeight = 0;
|
---|
142 | protected int _currentScrollTopValue = 0;
|
---|
143 |
|
---|
144 | protected boolean _updatingMap = false;
|
---|
145 | protected boolean _gazetteerLoaded = false;
|
---|
146 | protected boolean _redraw = false;
|
---|
147 | protected boolean _resize = false;
|
---|
148 | protected boolean _mapVisible = false;
|
---|
149 | protected boolean _gsVisible = true;
|
---|
150 | protected boolean _frameLoaded = false;
|
---|
151 | protected boolean _initialised = false;
|
---|
152 | protected boolean _showAllPlaces = false;
|
---|
153 | protected boolean _mouseEventPause = false;
|
---|
154 | protected boolean _mapMoveHandlerOn = true;
|
---|
155 | protected boolean _searchResultsPage = false;
|
---|
156 |
|
---|
157 | protected String _selectedPlaceName = "";
|
---|
158 | protected String _currentCollection = "";
|
---|
159 | protected String _currentURL = "";
|
---|
160 | protected final String _GREENSTONEURL = "http://localhost:8486/greenstone3";
|
---|
161 | //protected final String _GREENSTONEURL = "http://www.nzdl.org/atlasgreenstone3";
|
---|
162 | protected final String _GREENSTONEDEVURL = _GREENSTONEURL + "/dev";
|
---|
163 |
|
---|
164 | protected com.google.gwt.xml.client.Document _currentNewPageDoc;
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * GWT module entry point
|
---|
168 | */
|
---|
169 | public void onModuleLoad()
|
---|
170 | {
|
---|
171 | _statusBar = new StatusBar(this);
|
---|
172 | //Make the Firebug console so that browsers that don't have it don't break
|
---|
173 | setUpConsole();
|
---|
174 |
|
---|
175 | //Get a Google geocoder to help find places that the Gazetteer does not know the coordinates for
|
---|
176 | _geocoder = new Geocoder();
|
---|
177 |
|
---|
178 | ((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://localhost:8486/ATLAS/findPlace");
|
---|
179 | //((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://www.nzdl.org/ATLAS/findPlace");
|
---|
180 |
|
---|
181 | //Setup native Javascript functions
|
---|
182 | setUpLoadPageFromUrl(this);
|
---|
183 | setUpLoadPageFromForm(this);
|
---|
184 | setUpLoadSpatialSearchPage(this);
|
---|
185 |
|
---|
186 | //Setup the map
|
---|
187 | setUpMap();
|
---|
188 |
|
---|
189 | //Set up the list box that stores the text view options
|
---|
190 | setUpTextViewSelector();
|
---|
191 |
|
---|
192 | //Load the Greenstone home page
|
---|
193 | loadPageFromUrl(_GREENSTONEDEVURL + "?a=p&sa=home");
|
---|
194 | }
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Adds the three options to the text view selector
|
---|
198 | */
|
---|
199 | public void setUpTextViewSelector()
|
---|
200 | {
|
---|
201 | _textViewSelector.addItem("Normal");
|
---|
202 | _textViewSelector.addItem("Fisheye");
|
---|
203 | _textViewSelector.addItem("Column");
|
---|
204 | }
|
---|
205 |
|
---|
206 | /**
|
---|
207 | * Loads the page at the given URL
|
---|
208 | * @param url is the url to load
|
---|
209 | */
|
---|
210 | public void loadPageFromUrl(String url)
|
---|
211 | {
|
---|
212 | //Make sure a url was given
|
---|
213 | if(url == null)
|
---|
214 | {
|
---|
215 | return;
|
---|
216 | }
|
---|
217 |
|
---|
218 | //Save the given url for later use
|
---|
219 | _currentURL = url;
|
---|
220 |
|
---|
221 | //Set Greenstone to be visible
|
---|
222 | _gsVisible = true;
|
---|
223 |
|
---|
224 | //Clear the map
|
---|
225 | _map.clearOverlays();
|
---|
226 |
|
---|
227 | updateHandlers();
|
---|
228 | clearStatusUpdates();
|
---|
229 |
|
---|
230 | //Check if the page being loaded is a search page
|
---|
231 | if (url.contains("s1.query="))
|
---|
232 | {
|
---|
233 | //Load the search page
|
---|
234 | loadSearchPageFromUrl(url);
|
---|
235 | }
|
---|
236 | else
|
---|
237 | {
|
---|
238 | //This page is not a search page
|
---|
239 | _searchResultsPage = false;
|
---|
240 | }
|
---|
241 |
|
---|
242 | //If the url contains a collection name
|
---|
243 | if (url.contains("&c="))
|
---|
244 | {
|
---|
245 | //Store the collection name
|
---|
246 | _currentCollection = getCollectionFromURL(url);
|
---|
247 | }
|
---|
248 |
|
---|
249 | //Add the "Page loading" update to the status bar"
|
---|
250 | _statusBar.addUpdate("Loading new page", "LoadPage");
|
---|
251 |
|
---|
252 | getNewPage(url.contains("?") ? (url + "&excerpttag=body") : (url + "?excerpttag=body"),
|
---|
253 | new ResponseFunction(){
|
---|
254 | public void function(String response){
|
---|
255 | HTML newPage = new HTML(response);
|
---|
256 | newPage.getElement().setId("newpage");
|
---|
257 | Element oldNewPage = (Element) Document.get().getElementById("newpage");
|
---|
258 | if(oldNewPage != null)
|
---|
259 | {
|
---|
260 | oldNewPage.removeFromParent();
|
---|
261 | }
|
---|
262 | getElementsByTagName("body").get(0).appendChild(newPage.getElement());
|
---|
263 | newPage.setVisible(false);
|
---|
264 |
|
---|
265 | showLoadedPage();
|
---|
266 | }
|
---|
267 | }
|
---|
268 | );
|
---|
269 | }
|
---|
270 |
|
---|
271 | public void loadPageWithoutUrl()
|
---|
272 | {
|
---|
273 | //Set the current url to be empty
|
---|
274 | _currentURL = "";
|
---|
275 |
|
---|
276 | //Set Greenstone to be visible
|
---|
277 | _gsVisible = true;
|
---|
278 |
|
---|
279 | //Clear the map
|
---|
280 | _map.clearOverlays();
|
---|
281 |
|
---|
282 | updateHandlers();
|
---|
283 | clearStatusUpdates();
|
---|
284 |
|
---|
285 | //Add the "Page loading" update to the status bar"
|
---|
286 | _statusBar.addUpdate("Loading new page", "LoadPage");
|
---|
287 | }
|
---|
288 |
|
---|
289 | public void getNewPage(String url, final ResponseFunction responseFunc)
|
---|
290 | {
|
---|
291 | RequestBuilder newPageRequest = new RequestBuilder(RequestBuilder.GET, url);
|
---|
292 | try{
|
---|
293 | newPageRequest.sendRequest(null, new RequestCallback()
|
---|
294 | {
|
---|
295 | public void onResponseReceived(Request request, Response response)
|
---|
296 | {
|
---|
297 | if(response.getStatusCode() == Response.SC_OK)
|
---|
298 | {
|
---|
299 | responseFunc.function(response.getText());
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | public void onError(Request request, Throwable exception)
|
---|
304 | {
|
---|
305 | alert("Problem loading new page -> " + exception.getMessage());
|
---|
306 | }
|
---|
307 | });
|
---|
308 | }
|
---|
309 | catch(Exception ex)
|
---|
310 | {
|
---|
311 | alert("Exception while creating the new page request -> " + ex.getMessage());
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * Clears several of the status updates that should not persist across pages
|
---|
317 | */
|
---|
318 | public void clearStatusUpdates()
|
---|
319 | {
|
---|
320 | _statusBar.removeUpdate("DisPlaces");
|
---|
321 | _statusBar.removeUpdate("SearchLoad");
|
---|
322 | _statusBar.removeUpdate("TextSearch");
|
---|
323 | }
|
---|
324 |
|
---|
325 | /**
|
---|
326 | * Gets a collection name from a given url
|
---|
327 | * @param url the url to search for a collection in
|
---|
328 | * @return the collection name
|
---|
329 | */
|
---|
330 | public String getCollectionFromURL(String url)
|
---|
331 | {
|
---|
332 | int start = (url.indexOf("&c=") + 3);
|
---|
333 | int end = -1;
|
---|
334 | if (url.indexOf("&", (url.indexOf("&c=") + 1)) == -1)
|
---|
335 | {
|
---|
336 | end = url.length();
|
---|
337 | }
|
---|
338 | else
|
---|
339 | {
|
---|
340 | end = url.indexOf("&", (url.indexOf("&c=") + 1));
|
---|
341 | }
|
---|
342 | return url.substring(start, end);
|
---|
343 | }
|
---|
344 |
|
---|
345 | /**
|
---|
346 | * Sets up various handlers for a new page
|
---|
347 | */
|
---|
348 | public void updateHandlers()
|
---|
349 | {
|
---|
350 | if (_fishEyeHandlerReg != null)
|
---|
351 | {
|
---|
352 | _fishEyeHandlerReg.removeHandler();
|
---|
353 | _fishEyeHandlerReg = null;
|
---|
354 | }
|
---|
355 |
|
---|
356 | if (!_mapMoveHandlerOn)
|
---|
357 | {
|
---|
358 | _mapMoveHandlerOn = true;
|
---|
359 | _map.addMapMoveHandler(_mapMoveHandler);
|
---|
360 | }
|
---|
361 |
|
---|
362 | if (_searchControls != null)
|
---|
363 | {
|
---|
364 | _map.removeControl(_searchControls);
|
---|
365 | _searchControls = null;
|
---|
366 | }
|
---|
367 |
|
---|
368 | if (_spatialSearchClickHandler != null)
|
---|
369 | {
|
---|
370 | _map.removeMapClickHandler(_spatialSearchClickHandler);
|
---|
371 | _spatialSearchClickHandler = null;
|
---|
372 | }
|
---|
373 | }
|
---|
374 |
|
---|
375 | /**
|
---|
376 | * Moves the loaded page from the temporary frame to the main page
|
---|
377 | */
|
---|
378 | private void showLoadedPage()
|
---|
379 | {
|
---|
380 | //If ATLAS has not yet been initialised then do so
|
---|
381 | if (!_initialised)
|
---|
382 | {
|
---|
383 | //Fix webpage elements so that they point to the correct address
|
---|
384 | fixForms();
|
---|
385 | fixAnchors();
|
---|
386 | fixImages();
|
---|
387 |
|
---|
388 | initialiseATLAS();
|
---|
389 |
|
---|
390 | //Add <link> and <script> elements to <head>
|
---|
391 | getNewPage(_currentURL.contains("?") ? (_currentURL + "&excerpttag=head") : (_currentURL + "?excerpttag=head"),
|
---|
392 | new ResponseFunction(){
|
---|
393 | public void function(String response){
|
---|
394 | HTML newPage = new HTML(response);
|
---|
395 | changeCSSLinksAndScripts(newPage.getElement());
|
---|
396 | }
|
---|
397 | }
|
---|
398 | );
|
---|
399 | }
|
---|
400 | else
|
---|
401 | {
|
---|
402 | //Add <link> and <script> elements to <head>
|
---|
403 | getNewPage(_currentURL.contains("?") ? (_currentURL + "&excerpttag=head") : (_currentURL + "?excerpttag=head"),
|
---|
404 | new ResponseFunction(){
|
---|
405 | public void function(String response){
|
---|
406 | HTML newPage = new HTML(response);
|
---|
407 | changeCSSLinksAndScripts(newPage.getElement());
|
---|
408 | }
|
---|
409 | }
|
---|
410 | );
|
---|
411 |
|
---|
412 | //Fix webpage elements so that they point to the correct address
|
---|
413 | fixForms();
|
---|
414 | fixAnchors();
|
---|
415 | fixImages();
|
---|
416 |
|
---|
417 | Element newPageElem = getElementById("newpage");
|
---|
418 | NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div");
|
---|
419 |
|
---|
420 | Element newBanner = null;
|
---|
421 | Element newContent = null;
|
---|
422 |
|
---|
423 | for(int i = 0; i < divs.getLength(); i++)
|
---|
424 | {
|
---|
425 | if(divs.getItem(i).getId().equals("gs_banner"))
|
---|
426 | {
|
---|
427 | newBanner = (Element) divs.getItem(i);
|
---|
428 | }
|
---|
429 | else if(divs.getItem(i).getId().equals("gs_content"))
|
---|
430 | {
|
---|
431 | newContent = (Element) divs.getItem(i);
|
---|
432 | }
|
---|
433 | }
|
---|
434 |
|
---|
435 | //Swap the current banner with the new banner
|
---|
436 | Element oldBanner = getElementById("gs_banner");
|
---|
437 | oldBanner.getParentElement().removeChild(oldBanner);
|
---|
438 | _headerDiv.insert(HTML.wrap(newBanner), 0);
|
---|
439 |
|
---|
440 | //If the content div was in column view mode then reset it
|
---|
441 | if (_contentDiv.getWidget(0).getElement().getId().equals("columnBox"))
|
---|
442 | {
|
---|
443 | _contentDiv.clear();
|
---|
444 | _contentDiv.add(_gsPanel);
|
---|
445 | _contentDiv.add(_map);
|
---|
446 | }
|
---|
447 |
|
---|
448 | //Swap the current Greenstone content with the new Greenstone content
|
---|
449 | _gsPanel.setHTML(HTML.wrap(newContent).getHTML());
|
---|
450 | }
|
---|
451 |
|
---|
452 | //If the page is a collection home page then add spatial search to the list of options
|
---|
453 | if (_currentURL.contains("sa=about"))
|
---|
454 | {
|
---|
455 | addSpatialSearchLinkToAboutPage();
|
---|
456 | }
|
---|
457 |
|
---|
458 | //The page has now finished being updated
|
---|
459 | _statusBar.removeUpdate("LoadPage");
|
---|
460 |
|
---|
461 | //Check the document's text for places
|
---|
462 | checkDocText();
|
---|
463 | }
|
---|
464 |
|
---|
465 | /**
|
---|
466 | * Add a link to spatial searching on the current page
|
---|
467 | */
|
---|
468 | private void addSpatialSearchLinkToAboutPage()
|
---|
469 | {
|
---|
470 | //Get the list to add the link to
|
---|
471 | Element list = getElementById("servicelist");
|
---|
472 |
|
---|
473 | //If the list does not exist then stop
|
---|
474 | if(list == null)
|
---|
475 | {
|
---|
476 | return;
|
---|
477 | }
|
---|
478 |
|
---|
479 | //Create the div for the link and explanation
|
---|
480 | Element linkLabel = DOM.createDiv();
|
---|
481 | list.appendChild(linkLabel);
|
---|
482 | linkLabel.setClassName("paramLabel");
|
---|
483 |
|
---|
484 | //Create the link and append it to the div
|
---|
485 | Element spatialLink = DOM.createAnchor();
|
---|
486 | linkLabel.appendChild(spatialLink);
|
---|
487 | spatialLink.setAttribute("href", "javascript:loadSpatialSearchPageJS()");
|
---|
488 | spatialLink.setInnerText("Spatial Search");
|
---|
489 |
|
---|
490 | //Create the explanation div and add to the parent div
|
---|
491 | Element explainationDiv = DOM.createDiv();
|
---|
492 | list.appendChild(explainationDiv);
|
---|
493 | explainationDiv.setClassName("paramLabel");
|
---|
494 | explainationDiv.setInnerText("Search for documents mentioning places from a certain area");
|
---|
495 |
|
---|
496 | Element br = DOM.createElement("br");
|
---|
497 | list.appendChild(br);
|
---|
498 | br.setClassName("clear");
|
---|
499 | }
|
---|
500 |
|
---|
501 | /**
|
---|
502 | * Initialise the webpage elements for ATLAS
|
---|
503 | */
|
---|
504 | public void initialiseATLAS()
|
---|
505 | {
|
---|
506 | //Reload the page when the view type is changed
|
---|
507 | _textViewSelector.addChangeHandler(new ChangeHandler()
|
---|
508 | {
|
---|
509 | public void onChange(ChangeEvent event)
|
---|
510 | {
|
---|
511 | if (getDocTextElement() != null)
|
---|
512 | {
|
---|
513 | loadPageFromUrl(_currentURL);
|
---|
514 | }
|
---|
515 | }
|
---|
516 | });
|
---|
517 |
|
---|
518 | //Set up content
|
---|
519 | _containerPanel.add(_headerDiv);
|
---|
520 | _containerPanel.add(_statusBar.getStatusBarDiv());
|
---|
521 | _containerPanel.add(_contentDiv);
|
---|
522 | _containerPanel.add(_footerDiv);
|
---|
523 |
|
---|
524 | _viewPanel.add(new Label("View: "));
|
---|
525 | _viewPanel.add(_textViewSelector);
|
---|
526 | _viewPanel.setVisible(false);
|
---|
527 |
|
---|
528 | Element newPageElem = getElementById("newpage");
|
---|
529 | NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div");
|
---|
530 |
|
---|
531 | Element headerElem = null;
|
---|
532 | Element bodyElem = null;
|
---|
533 | Element footerElem = null;
|
---|
534 |
|
---|
535 | for(int i = 0; i < divs.getLength(); i++)
|
---|
536 | {
|
---|
537 | if(divs.getItem(i).getId().equals("gs_banner"))
|
---|
538 | {
|
---|
539 | headerElem = (Element) divs.getItem(i);
|
---|
540 | }
|
---|
541 | else if(divs.getItem(i).getId().equals("gs_content"))
|
---|
542 | {
|
---|
543 | bodyElem = (Element) divs.getItem(i);
|
---|
544 | }
|
---|
545 | else if(divs.getItem(i).getId().equals("gs_footer"))
|
---|
546 | {
|
---|
547 | footerElem = (Element) divs.getItem(i);
|
---|
548 | }
|
---|
549 | }
|
---|
550 |
|
---|
551 | if(headerElem == null){alert("header is null");}
|
---|
552 | if(bodyElem == null){alert("body is null");}
|
---|
553 | if(footerElem == null){alert("footer is null");}
|
---|
554 |
|
---|
555 | // Add header
|
---|
556 | //Node newHeader = importNode(newPage, tempFrameGetElementById("banner"), true);
|
---|
557 | _headerDiv.add(HTML.wrap(headerElem));
|
---|
558 | _headerDiv.add(_viewPanel);
|
---|
559 | _headerDiv.setWidth("100%");
|
---|
560 | _headerDiv.getElement().setId("GSHeader");
|
---|
561 |
|
---|
562 | _gsPanel.getElement().getStyle().setProperty("overflow", "auto");
|
---|
563 |
|
---|
564 | _contentDiv.setWidth("100%");
|
---|
565 | _contentDiv.getElement().getStyle().setProperty("backgroundColor", "#FFFFFF");
|
---|
566 | _contentDiv.getElement().setId("GSContent");
|
---|
567 |
|
---|
568 | // Add content
|
---|
569 | //Node newContent = importNode(Document.get(), tempFrameGetElementById("content"), true);
|
---|
570 | _gsPanel = HTML.wrap(bodyElem);
|
---|
571 | _contentDiv.add(_gsPanel);
|
---|
572 | _contentDiv.add(_map);
|
---|
573 |
|
---|
574 | // Add footer
|
---|
575 | //Node newFooter = importNode(Document.get(), tempFrameGetElementById("footer"), true);
|
---|
576 | _footerDiv.add(HTML.wrap(footerElem));
|
---|
577 | _footerDiv.setWidth("100%");
|
---|
578 | _footerDiv.getElement().setId("GSFooter");
|
---|
579 |
|
---|
580 | RootPanel.get("mainFrame").add(_containerPanel);
|
---|
581 |
|
---|
582 | setUpBrowserResizeCheckTimer();
|
---|
583 |
|
---|
584 | // Make the call to check if the Gazetteer is loaded
|
---|
585 | _findPlaceService.isGazetteerLoaded(setUpCheckGazetteerCallback());
|
---|
586 | _initialised = true;
|
---|
587 | }
|
---|
588 |
|
---|
589 | /**
|
---|
590 | * Loads a Greenstone search page from a url
|
---|
591 | * @param url is the url to load
|
---|
592 | */
|
---|
593 | public void loadSearchPageFromUrl(String url)
|
---|
594 | {
|
---|
595 | _searchResultsPage = true;
|
---|
596 |
|
---|
597 | //Set up the request to get returned documents from the xml
|
---|
598 | RequestBuilder xmlRequest = new RequestBuilder(RequestBuilder.GET, url);
|
---|
599 | try
|
---|
600 | {
|
---|
601 | //Make the request
|
---|
602 | xmlRequest.sendRequest(null, new RequestCallback()
|
---|
603 | {
|
---|
604 | public void onError(Request request, Throwable exception)
|
---|
605 | {
|
---|
606 | logToConsole("xml Request Error -> " + exception.getMessage());
|
---|
607 | }
|
---|
608 |
|
---|
609 | public void onResponseReceived(Request request, Response response)
|
---|
610 | {
|
---|
611 | processResponse(response);
|
---|
612 | }
|
---|
613 | });
|
---|
614 | }
|
---|
615 | catch (Exception ex)
|
---|
616 | {
|
---|
617 | ex.printStackTrace();
|
---|
618 | }
|
---|
619 | }
|
---|
620 |
|
---|
621 | public void processResponse(Response response)
|
---|
622 | {
|
---|
623 | //If the status code is not the page loaded code then stop
|
---|
624 | if(response.getStatusCode() != 200)
|
---|
625 | {
|
---|
626 | return;
|
---|
627 | }
|
---|
628 |
|
---|
629 | //Add the status update that indicates that the system is searching for places in the result document
|
---|
630 | _statusBar.addUpdate("Finding places in result documents", "SearchLoad");
|
---|
631 |
|
---|
632 | //Get the response text
|
---|
633 | String text = response.getText();
|
---|
634 |
|
---|
635 | //Get the hash codes for the documents
|
---|
636 | final ArrayList<String> docURLs = getDocURLsFromResponse(text);
|
---|
637 | final String[] texts = new String[docURLs.size()];
|
---|
638 |
|
---|
639 | for(int i = 0; i < texts.length; i++)
|
---|
640 | {
|
---|
641 | texts[i] = null;
|
---|
642 | }
|
---|
643 |
|
---|
644 | for(int i = 0; i < docURLs.size(); i++)
|
---|
645 | {
|
---|
646 | String url = docURLs.get(i);
|
---|
647 | RequestBuilder xmlRequest = new RequestBuilder(RequestBuilder.GET, _GREENSTONEURL + "/" + (url.contains("?") ? (url + "&excerptid=gs-document-text") : (url + "?excerptid=gs-document-text")));
|
---|
648 | try
|
---|
649 | {
|
---|
650 | final int index = i;
|
---|
651 | xmlRequest.sendRequest(null, new RequestCallback()
|
---|
652 | {
|
---|
653 | public void onResponseReceived(Request request, Response response)
|
---|
654 | {
|
---|
655 | if(response.getStatusCode() == Response.SC_OK)
|
---|
656 | {
|
---|
657 | texts[index] = response.getText();
|
---|
658 | }
|
---|
659 | }
|
---|
660 |
|
---|
661 | public void onError(Request request, Throwable exception)
|
---|
662 | {
|
---|
663 | alert("Exception requesting new page -> " + exception.getMessage());
|
---|
664 | texts[index] = "";
|
---|
665 | }
|
---|
666 | });
|
---|
667 | }
|
---|
668 | catch(Exception ex)
|
---|
669 | {
|
---|
670 | alert("Exception requesting " + url + " -> " + ex.getMessage());
|
---|
671 | }
|
---|
672 | }
|
---|
673 |
|
---|
674 | Timer checkDoneTimer = new Timer()
|
---|
675 | {
|
---|
676 | int _count = 0;
|
---|
677 |
|
---|
678 | public void run()
|
---|
679 | {
|
---|
680 | boolean done = true;
|
---|
681 | if(_count < 20)
|
---|
682 | {
|
---|
683 | for(int i = 0; i < texts.length; i++)
|
---|
684 | {
|
---|
685 | if(texts[i] == null)
|
---|
686 | {
|
---|
687 | done = false;
|
---|
688 | break;
|
---|
689 | }
|
---|
690 | }
|
---|
691 | }
|
---|
692 | _count++;
|
---|
693 |
|
---|
694 | if(done)
|
---|
695 | {
|
---|
696 | this.cancel();
|
---|
697 | findPlacesInTexts(texts);
|
---|
698 | }
|
---|
699 | }
|
---|
700 | };
|
---|
701 | checkDoneTimer.scheduleRepeating(500);
|
---|
702 | }
|
---|
703 |
|
---|
704 | /**
|
---|
705 | * Makes a call to the server to look through multiple places for places
|
---|
706 | * @param texts is a list of texts from different documents
|
---|
707 | */
|
---|
708 | private void findPlacesInTexts(String[] texts)
|
---|
709 | {
|
---|
710 | logToConsole("Finished gettings doc text and gazetteer loaded!");
|
---|
711 |
|
---|
712 | //Make the call to the server that finds the places
|
---|
713 | _findPlaceService.findPlacesInMultipleTexts(texts, setUpFindMultiplePlacesCallback());
|
---|
714 |
|
---|
715 | //Set up the map for viewing multiple places
|
---|
716 | _map.clearOverlays();
|
---|
717 | _mapVisible = true;
|
---|
718 | _map.setVisible(true);
|
---|
719 | _contentDiv.add(_mapLoadingLabel);
|
---|
720 |
|
---|
721 | _mapLoadingLabel.getElement().getStyle().setProperty("left", ((int) (_headerDiv.getOffsetWidth() * (3.0 / 4.0) - _mapLoadingLabel.getOffsetWidth() / 2)) + "px");
|
---|
722 | _mapLoadingLabel.getElement().getStyle().setProperty("top", (_headerDiv.getOffsetHeight() + _contentDiv.getOffsetHeight() / 3) + "px");
|
---|
723 |
|
---|
724 | _map.getElement().getStyle().setProperty("left", (Window.getClientWidth() / 2 + 8) + "px");
|
---|
725 | _map.getElement().getStyle().setProperty("top", (_headerDiv.getOffsetHeight() + 28 + Window.getScrollTop()) + "px");
|
---|
726 |
|
---|
727 | _resize = true;
|
---|
728 | }
|
---|
729 |
|
---|
730 | /**
|
---|
731 | * Takes Greenstone search response xml text and extracts the document hashes from it
|
---|
732 | * @param text is the xml to use
|
---|
733 | * @return a list of document hashes
|
---|
734 | */
|
---|
735 | private ArrayList<String> getDocURLsFromResponse(String text)
|
---|
736 | {
|
---|
737 | ArrayList<String> docURLs = new ArrayList<String>();
|
---|
738 |
|
---|
739 | int index = text.indexOf("<ul id=\"results\"");
|
---|
740 | int endIndex = text.indexOf("</ul>", index);
|
---|
741 | while ((index = text.indexOf("<a href=\"", index)) != -1 && index < endIndex)
|
---|
742 | {
|
---|
743 | int urlStart = index + "<a href=\"".length();
|
---|
744 | int urlEnd = text.indexOf("\"", urlStart + 1);
|
---|
745 |
|
---|
746 | docURLs.add(text.substring(urlStart, urlEnd));
|
---|
747 |
|
---|
748 | index++;
|
---|
749 | }
|
---|
750 |
|
---|
751 | return docURLs;
|
---|
752 | }
|
---|
753 |
|
---|
754 | /**
|
---|
755 | * Creates and shows a spatial search page
|
---|
756 | */
|
---|
757 | public void loadSpatialSearchPage()
|
---|
758 | {
|
---|
759 | //Clear the Greenstone panel
|
---|
760 | _gsPanel.setHTML((new HTML()).getHTML());
|
---|
761 |
|
---|
762 | //Turn off the map move handler if it is on
|
---|
763 | if (_mapMoveHandlerOn)
|
---|
764 | {
|
---|
765 | _mapMoveHandlerOn = false;
|
---|
766 | _map.removeMapMoveHandler(_mapMoveHandler);
|
---|
767 | }
|
---|
768 |
|
---|
769 | //Set up the page
|
---|
770 | _map.clearOverlays();
|
---|
771 | _mapVisible = true;
|
---|
772 | _gsVisible = false;
|
---|
773 | _map.setVisible(true);
|
---|
774 |
|
---|
775 | //Create a new list that will store the points that the user clicks on
|
---|
776 | _areaPoints = new ArrayList<LatLng>();
|
---|
777 |
|
---|
778 | //If the map does not currently have a spatial search handler
|
---|
779 | if (_spatialSearchClickHandler == null)
|
---|
780 | {
|
---|
781 | //Create a new map spatial search handler
|
---|
782 | _spatialSearchClickHandler = new MapClickHandler()
|
---|
783 | {
|
---|
784 | public void onClick(MapClickEvent event)
|
---|
785 | {
|
---|
786 | //Take the point that has been clicked and add it to the list
|
---|
787 | LatLng point = event.getLatLng();
|
---|
788 | _areaPoints.add(point);
|
---|
789 |
|
---|
790 | //Create a marker at the clicked point
|
---|
791 | MarkerOptions mo = MarkerOptions.newInstance();
|
---|
792 | mo.setClickable(false);
|
---|
793 | Marker marker = new Marker(point, mo);
|
---|
794 | _map.addOverlay(marker);
|
---|
795 |
|
---|
796 | //If this is not the first point then add a line between this and the previous point
|
---|
797 | if (_areaPoints.size() > 1)
|
---|
798 | {
|
---|
799 | PolylineOptions po = PolylineOptions.newInstance();
|
---|
800 | po.setClickable(false);
|
---|
801 |
|
---|
802 | Polyline line = new Polyline(new LatLng[] { point, _areaPoints.get(_areaPoints.size() - 2) }, "#FFFFFF", 3, 1, po);
|
---|
803 | _map.addOverlay(line);
|
---|
804 | }
|
---|
805 | }
|
---|
806 | };
|
---|
807 | }
|
---|
808 | _map.addMapClickHandler(_spatialSearchClickHandler);
|
---|
809 |
|
---|
810 | //If the map does not have search controls then add them
|
---|
811 | if (_searchControls == null)
|
---|
812 | {
|
---|
813 | _searchControls = new SpatialSearchControls(new ControlPosition(ControlAnchor.BOTTOM_RIGHT, 0, 0));
|
---|
814 | }
|
---|
815 | _map.addControl(_searchControls);
|
---|
816 |
|
---|
817 | _resize = true;
|
---|
818 | }
|
---|
819 |
|
---|
820 | /**
|
---|
821 | * Takes an HTML form element and loads a page using its content
|
---|
822 | * @param form is the form to use
|
---|
823 | */
|
---|
824 | public void loadPageFromForm(Element form)
|
---|
825 | {
|
---|
826 | //Get the top level url
|
---|
827 | StringBuilder url = new StringBuilder(_GREENSTONEDEVURL);
|
---|
828 |
|
---|
829 | //Get the elements from the form
|
---|
830 | FormElement formElement = FormElement.as(form);
|
---|
831 | NodeCollection<com.google.gwt.dom.client.Element> elements = formElement.getElements();
|
---|
832 |
|
---|
833 | //Go through each element
|
---|
834 | for (int i = 0; i < elements.getLength(); i++)
|
---|
835 | {
|
---|
836 | Element currentItem = (Element) elements.getItem(i);
|
---|
837 |
|
---|
838 | //If the element is an input element
|
---|
839 | if (currentItem.getTagName().equals("INPUT"))
|
---|
840 | {
|
---|
841 | InputElement input = InputElement.as(currentItem);
|
---|
842 |
|
---|
843 | //If the element is a text or hidden element
|
---|
844 | if (input.getType().equals("text") || input.getType().equals("hidden"))
|
---|
845 | {
|
---|
846 | //Append the name and value of this element to the url
|
---|
847 | url.append("&" + input.getName() + "=" + input.getValue());
|
---|
848 | }
|
---|
849 | //If the element is a radio or checkbox element
|
---|
850 | else if (input.getType().equals("radio") || input.getType().equals("checkbox"))
|
---|
851 | {
|
---|
852 | //If the element has been checked
|
---|
853 | if (input.isChecked())
|
---|
854 | {
|
---|
855 | //Append the name and value of this element to the url
|
---|
856 | url.append("&" + input.getName() + "=" + input.getAttribute("value"));
|
---|
857 | }
|
---|
858 | }
|
---|
859 | }
|
---|
860 | //If the element is a select element (drop down box)
|
---|
861 | else if (currentItem.getTagName().equals("SELECT"))
|
---|
862 | {
|
---|
863 | SelectElement select = SelectElement.as(currentItem);
|
---|
864 | NodeList<OptionElement> options = select.getOptions();
|
---|
865 |
|
---|
866 | //Append the name of the element and the value of the currently selected index to the url
|
---|
867 | url.append("&" + select.getName() + "=" + options.getItem(select.getSelectedIndex()).getAttribute("value"));
|
---|
868 | }
|
---|
869 | //If the element is a text area element
|
---|
870 | else if (currentItem.getTagName().equals("TEXTAREA"))
|
---|
871 | {
|
---|
872 | TextAreaElement text = TextAreaElement.as(currentItem);
|
---|
873 |
|
---|
874 | //Append the name and value of the text area to the url
|
---|
875 | url.append("&" + text.getName() + "=" + text.getValue());
|
---|
876 | }
|
---|
877 | }
|
---|
878 | //Replace the first & with a ?
|
---|
879 | url.replace(url.indexOf("&"), url.indexOf("&") + 1, "?");
|
---|
880 |
|
---|
881 | //Load the page with the created url
|
---|
882 | loadPageFromUrl(url.toString());
|
---|
883 | }
|
---|
884 |
|
---|
885 | /**
|
---|
886 | * Remove old CSS links from the page and add new ones, the href attributes are also corrected
|
---|
887 | */
|
---|
888 | public void changeCSSLinksAndScripts(Element newHead)
|
---|
889 | {
|
---|
890 | Element head = getDocumentHead();
|
---|
891 |
|
---|
892 | //Get all of the <link> elements from the HTML header
|
---|
893 | NodeList<com.google.gwt.dom.client.Element> currentLinks = head.getElementsByTagName("link");
|
---|
894 |
|
---|
895 | //Get all of the <script> elements from the HTML header
|
---|
896 | NodeList<com.google.gwt.dom.client.Element> currentScripts = head.getElementsByTagName("script");
|
---|
897 |
|
---|
898 | //Add the new links
|
---|
899 | NodeList<com.google.gwt.dom.client.Element> newLinks = newHead.getElementsByTagName("link");
|
---|
900 | for (int i = 0; i < newLinks.getLength(); i++)
|
---|
901 | {
|
---|
902 | com.google.gwt.dom.client.Element e = newLinks.getItem(i);
|
---|
903 | boolean found = false;
|
---|
904 |
|
---|
905 | for(int j = 0; j < currentLinks.getLength(); j++)
|
---|
906 | {
|
---|
907 | Element elem = (Element) currentLinks.getItem(j);
|
---|
908 | if(e.getAttribute("href").equals(elem.getAttribute("href"))
|
---|
909 | && e.getAttribute("type").equals(elem.getAttribute("type"))
|
---|
910 | && e.getAttribute("rel").equals(elem.getAttribute("rel")))
|
---|
911 | {
|
---|
912 | found = true;
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | if(!found)
|
---|
917 | {
|
---|
918 | Element newElem = DOM.createElement("link");
|
---|
919 | newElem.setAttribute("href", e.getAttribute("href"));
|
---|
920 | newElem.setAttribute("type", e.getAttribute("type"));
|
---|
921 | newElem.setAttribute("rel", e.getAttribute("rel"));
|
---|
922 |
|
---|
923 | if(!newElem.getAttribute("href").startsWith("http://"))
|
---|
924 | {
|
---|
925 | newElem.setAttribute("href", _GREENSTONEURL + "/" + newElem.getAttribute("href"));
|
---|
926 | }
|
---|
927 | head.appendChild(newElem);
|
---|
928 | }
|
---|
929 | }
|
---|
930 |
|
---|
931 | //Add the new scripts on the page
|
---|
932 | NodeList<com.google.gwt.dom.client.Element> newScripts = newHead.getElementsByTagName("script");
|
---|
933 | for (int i = 0; i < newScripts.getLength(); i++)
|
---|
934 | {
|
---|
935 | com.google.gwt.dom.client.Element e = newScripts.getItem(i);
|
---|
936 | boolean found = false;
|
---|
937 | for(int j = 0; j < currentScripts.getLength(); j++)
|
---|
938 | {
|
---|
939 | Element elem = (Element) currentLinks.getItem(j);
|
---|
940 | if(e.getAttribute("src").equals(elem.getAttribute("src"))
|
---|
941 | && e.getAttribute("type").equals(elem.getAttribute("type")))
|
---|
942 | {
|
---|
943 | found = true;
|
---|
944 | }
|
---|
945 | }
|
---|
946 |
|
---|
947 | if(!found)
|
---|
948 | {
|
---|
949 | Element newElem = DOM.createElement("script");
|
---|
950 | newElem.setAttribute("src", e.getAttribute("src"));
|
---|
951 | newElem.setAttribute("type", e.getAttribute("type"));
|
---|
952 |
|
---|
953 | if(!e.getAttribute("src").startsWith("http://"))
|
---|
954 | {
|
---|
955 | e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src"));
|
---|
956 | }
|
---|
957 | head.appendChild(newElem);
|
---|
958 | }
|
---|
959 | }
|
---|
960 | }
|
---|
961 |
|
---|
962 | /**
|
---|
963 | * Go through each form on the page and add a javascript function in place of its action attribute
|
---|
964 | */
|
---|
965 | public void fixForms()
|
---|
966 | {
|
---|
967 | NodeList<com.google.gwt.dom.client.Element> forms = getElementById("newpage").getElementsByTagName("form");
|
---|
968 | for (int i = 0; i < forms.getLength(); i++)
|
---|
969 | {
|
---|
970 | Element e = (Element)forms.getItem(i);
|
---|
971 | e.setAttribute("id", "form" + i);
|
---|
972 |
|
---|
973 | if(e.getAttribute("action").isEmpty())
|
---|
974 | {
|
---|
975 | continue;
|
---|
976 | }
|
---|
977 | if (!e.getAttribute("action").startsWith("http://") && !e.getAttribute("action").startsWith("/"))
|
---|
978 | {
|
---|
979 | e.setAttribute("action", "javascript:loadPageFromFormJS(document.getElementById('form" + i + "'))");
|
---|
980 | }
|
---|
981 | }
|
---|
982 | }
|
---|
983 |
|
---|
984 | /**
|
---|
985 | * Go through each anchor on the page and add a javascript function in place of the href attribute
|
---|
986 | */
|
---|
987 | public void fixAnchors()
|
---|
988 | {
|
---|
989 | NodeList<com.google.gwt.dom.client.Element> anchors = getElementById("newpage").getElementsByTagName("a");
|
---|
990 | for (int i = 0; i < anchors.getLength(); i++)
|
---|
991 | {
|
---|
992 | Element e = (Element)anchors.getItem(i);
|
---|
993 | if(e.getAttribute("href").isEmpty())
|
---|
994 | {
|
---|
995 | continue;
|
---|
996 | }
|
---|
997 |
|
---|
998 | if(e.getAttribute("href").startsWith("javascript:"))
|
---|
999 | {
|
---|
1000 | continue;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | if (!e.getAttribute("href").startsWith("http://") && !e.getAttribute("href").startsWith("/"))
|
---|
1004 | {
|
---|
1005 | e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href"));
|
---|
1006 | }
|
---|
1007 | //e.setAttribute("onClick", "loadPageFromUrlJS('" + e.getAttribute("href") + "'); return false;");
|
---|
1008 | e.setAttribute("href", "javascript:loadPageFromUrlJS('" + e.getAttribute("href") + "');");
|
---|
1009 | }
|
---|
1010 | }
|
---|
1011 |
|
---|
1012 | /**
|
---|
1013 | * Go through each image on the page and correct its src attribute
|
---|
1014 | */
|
---|
1015 | public void fixImages()
|
---|
1016 | {
|
---|
1017 | NodeList<com.google.gwt.dom.client.Element> images = getElementById("newpage").getElementsByTagName("img");
|
---|
1018 | for (int i = 0; i < images.getLength(); i++)
|
---|
1019 | {
|
---|
1020 | Element e = (Element)images.getItem(i);
|
---|
1021 |
|
---|
1022 | if(e.getAttribute("src").isEmpty())
|
---|
1023 | {
|
---|
1024 | continue;
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | if (!e.getAttribute("src").startsWith("http://") && !e.getAttribute("src").startsWith("/"))
|
---|
1028 | {
|
---|
1029 | e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src"));
|
---|
1030 | }
|
---|
1031 | }
|
---|
1032 | }
|
---|
1033 |
|
---|
1034 | /**
|
---|
1035 | * Makes calls to console.log harmless on browsers that do not have Firebug
|
---|
1036 | */
|
---|
1037 | public static native void setUpConsole()
|
---|
1038 | /*-{
|
---|
1039 | if (! ("console" in $wnd) || !("firebug" in console))
|
---|
1040 | {
|
---|
1041 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
|
---|
1042 | $wnd.console = {};
|
---|
1043 | for (var i = 0; i < names.length; ++i) $wnd.console[names[i]] = function() {};
|
---|
1044 | }
|
---|
1045 | }-*/;
|
---|
1046 |
|
---|
1047 | /**
|
---|
1048 | * Creates the javascript function that calls the loadPageFromForm GWT function
|
---|
1049 | * @param ml is the instance of the GS3MapLibrary class that you wish to attach this function to
|
---|
1050 | */
|
---|
1051 | public static native void setUpLoadPageFromForm(GS3MapLibrary ml)
|
---|
1052 | /*-{
|
---|
1053 | $wnd.loadPageFromFormJS = function(form)
|
---|
1054 | {
|
---|
1055 | [email protected]::loadPageFromForm(Lcom/google/gwt/user/client/Element;) (form);
|
---|
1056 | };
|
---|
1057 | }-*/;
|
---|
1058 |
|
---|
1059 | /**
|
---|
1060 | * Creates the javascript function that calls the loadPageFromURL GWT function
|
---|
1061 | * @param ml is the instance of the GS3MapLibrary class that you wish to attach this function to
|
---|
1062 | */
|
---|
1063 | public static native void setUpLoadPageFromUrl(GS3MapLibrary ml)
|
---|
1064 | /*-{
|
---|
1065 | $wnd.loadPageFromUrlJS = function(url)
|
---|
1066 | {
|
---|
1067 | [email protected]::loadPageFromUrl(Ljava/lang/String;) (url);
|
---|
1068 | };
|
---|
1069 | }-*/;
|
---|
1070 |
|
---|
1071 | /**
|
---|
1072 | * Creates the javascript function that calls the loadSpatialSearchPage GWT function
|
---|
1073 | * @param ml is the instance of the GS3MapLibrary class that you wish to attach this function to
|
---|
1074 | */
|
---|
1075 | public static native void setUpLoadSpatialSearchPage(GS3MapLibrary ml)
|
---|
1076 | /*-{
|
---|
1077 | $wnd.loadSpatialSearchPageJS = function()
|
---|
1078 | {
|
---|
1079 | [email protected]::loadSpatialSearchPage() ();
|
---|
1080 | };
|
---|
1081 | }-*/;
|
---|
1082 |
|
---|
1083 | /**
|
---|
1084 | * Gets all of the specified type of element in the given frame
|
---|
1085 | * @param frameIndex is the index of the frame to search in
|
---|
1086 | * @param tagname is the specific tag type to get
|
---|
1087 | * @return the list of elements with that tag name
|
---|
1088 | */
|
---|
1089 | public static native JsArray<Element> tempFrameGetElementsByTagName(int frameIndex, String tagname)
|
---|
1090 | /*-{
|
---|
1091 | return $wnd.frames[frameIndex].document.getElementsByTagName(tagname);
|
---|
1092 | }-*/;
|
---|
1093 |
|
---|
1094 | /**
|
---|
1095 | * Gets a element specifed by a given id in the specified frame
|
---|
1096 | * @param frameIndex is the index of the frame to search in
|
---|
1097 | * @param id is the id of the element to find
|
---|
1098 | * @return the specified element
|
---|
1099 | */
|
---|
1100 | public static native Element tempFrameGetElementById(int frameIndex, String id)
|
---|
1101 | /*-{
|
---|
1102 | return $wnd.frames[frameIndex].document.getElementById(id);
|
---|
1103 | }-*/;
|
---|
1104 |
|
---|
1105 | /**
|
---|
1106 | * Gets the total number of frames in the webpage
|
---|
1107 | * @return the total number of frames
|
---|
1108 | */
|
---|
1109 | public static native int getNumberOfFrames()
|
---|
1110 | /*-{
|
---|
1111 | return $wnd.frames.length;
|
---|
1112 | }-*/;
|
---|
1113 |
|
---|
1114 | /**
|
---|
1115 | * Gets an element specified the given id in the intermediate frame
|
---|
1116 | * @param id is the id of the element to find
|
---|
1117 | * @return the specified element
|
---|
1118 | */
|
---|
1119 | public static native Element tempFrameGetElementById(String id)
|
---|
1120 | /*-{
|
---|
1121 | return $wnd.frames[2].document.getElementById(id);
|
---|
1122 | }-*/;
|
---|
1123 |
|
---|
1124 | /**
|
---|
1125 | * Gets all of the specified type of element in the intermediate frame
|
---|
1126 | * @param tagname is the specific tag type to get
|
---|
1127 | * @return the list of elements with that tag name
|
---|
1128 | */
|
---|
1129 | public static native JsArray<Element> tempFrameGetElementsByTagName(String tagname)
|
---|
1130 | /*-{
|
---|
1131 | return $wnd.frames[2].document.getElementsByTagName(tagname);
|
---|
1132 | }-*/;
|
---|
1133 |
|
---|
1134 | /**
|
---|
1135 | * Prints a given message to screen in a window
|
---|
1136 | * @param msg is the message to print
|
---|
1137 | */
|
---|
1138 | public static native void alert(String msg)
|
---|
1139 | /*-{
|
---|
1140 | alert(msg);
|
---|
1141 | }-*/;
|
---|
1142 |
|
---|
1143 | /**
|
---|
1144 | * Prints a given message to the Firebug console
|
---|
1145 | * @param msg is the message to print
|
---|
1146 | */
|
---|
1147 | public static native void logToConsole(String msg)
|
---|
1148 | /*-{
|
---|
1149 | //alert(msg);
|
---|
1150 | //console.log(msg);
|
---|
1151 | }-*/;
|
---|
1152 |
|
---|
1153 | /**
|
---|
1154 | * Gets the <head> element of the <html>
|
---|
1155 | * @return the head element
|
---|
1156 | */
|
---|
1157 | public static native Element getDocumentHead()
|
---|
1158 | /*-{
|
---|
1159 | return $doc.getElementsByTagName("head")[0];
|
---|
1160 | }-*/;
|
---|
1161 |
|
---|
1162 | /**
|
---|
1163 | * Patch GWT Document.importNode, which fails to return the imported nodes
|
---|
1164 | */
|
---|
1165 | public static final native Node importNode(Document doc, Node node, boolean deep) /*-{
|
---|
1166 | return doc.importNode(node, deep);
|
---|
1167 | }-*/;
|
---|
1168 |
|
---|
1169 |
|
---|
1170 | /**
|
---|
1171 | * Gets an element specified by the given id in the document
|
---|
1172 | * @param id the id of the element to find
|
---|
1173 | * @return the specified element
|
---|
1174 | */
|
---|
1175 | public static native Element getElementById(String id)
|
---|
1176 | /*-{
|
---|
1177 | return $doc.getElementById(id);
|
---|
1178 | }-*/;
|
---|
1179 |
|
---|
1180 | /**
|
---|
1181 | * Gets all of the elements specified by the given tag name
|
---|
1182 | * @param tagName is the tag name of the elements to find
|
---|
1183 | * @return the list of elements specified by the given tag name
|
---|
1184 | */
|
---|
1185 | public static native JsArray<Element> getElementsByTagName(String tagName)
|
---|
1186 | /*-{
|
---|
1187 | return $doc.getElementsByTagName(tagName);
|
---|
1188 | }-*/;
|
---|
1189 |
|
---|
1190 | /**
|
---|
1191 | * Calls the method the initialises the fisheye viewing
|
---|
1192 | */
|
---|
1193 | public static native void setUpFishEye()
|
---|
1194 | /*-{
|
---|
1195 | console.log("Fish eye set up");
|
---|
1196 | $wnd.fishEyeSetUp();
|
---|
1197 | }-*/;
|
---|
1198 |
|
---|
1199 | /**
|
---|
1200 | * Passes the mouse y coordinates from the GWT handler to the fisheye handler
|
---|
1201 | * @param y is the mouse y coordinate
|
---|
1202 | */
|
---|
1203 | public static native void passMouseCoordsToFishEye(int y)
|
---|
1204 | /*-{
|
---|
1205 | $wnd.checkMousePos(y);
|
---|
1206 | }-*/;
|
---|
1207 |
|
---|
1208 | /**
|
---|
1209 | * Sets up the timer that checks periodically whether or not the elements in the page need to be resized
|
---|
1210 | */
|
---|
1211 | public void setUpBrowserResizeCheckTimer()
|
---|
1212 | {
|
---|
1213 | _resizeCheckTimer = new Timer()
|
---|
1214 | {
|
---|
1215 | public void run()
|
---|
1216 | {
|
---|
1217 | if (_currentBrowserPixelHeight != Window.getClientHeight() || _currentBrowserPixelWidth != Window.getClientWidth() || _resize)
|
---|
1218 | {
|
---|
1219 | _resize = false;
|
---|
1220 | resizeElements();
|
---|
1221 | _currentBrowserPixelHeight = Window.getClientHeight();
|
---|
1222 | _currentBrowserPixelWidth = Window.getClientWidth();
|
---|
1223 | }
|
---|
1224 | }
|
---|
1225 | };
|
---|
1226 | _resizeCheckTimer.scheduleRepeating(500);
|
---|
1227 | }
|
---|
1228 |
|
---|
1229 | /**
|
---|
1230 | * Resizes elements based on the current width and height of the browser window
|
---|
1231 | */
|
---|
1232 | public void resizeElements()
|
---|
1233 | {
|
---|
1234 | //Get the width and height we want to use for the content div
|
---|
1235 | int cwidth = Window.getClientWidth() - 45;
|
---|
1236 | int cheight = (int) (Window.getClientHeight() - _headerDiv.getOffsetHeight() - _footerDiv.getOffsetHeight() - _statusBar.getStatusBarDiv().getOffsetHeight() - 50);
|
---|
1237 |
|
---|
1238 | //If the height is less than 300 then set it to 300
|
---|
1239 | if (cheight < 200)
|
---|
1240 | {
|
---|
1241 | cheight = 200;
|
---|
1242 | }
|
---|
1243 |
|
---|
1244 | //Set the widths of the header and footer divs
|
---|
1245 | _headerDiv.setWidth(cwidth + "px");
|
---|
1246 | _footerDiv.setWidth(cwidth + "px");
|
---|
1247 |
|
---|
1248 | //Set the size of the content div
|
---|
1249 | _contentDiv.setSize(cwidth + "px", cheight + "px");
|
---|
1250 |
|
---|
1251 | //Set up the style of the Greenstone panel
|
---|
1252 | _gsPanel.getElement().getStyle().setProperty("position", "absolute");
|
---|
1253 | _gsPanel.getElement().getStyle().setProperty("overflow", "auto");
|
---|
1254 |
|
---|
1255 | //Set up the style of the Map panel
|
---|
1256 | _map.getElement().getStyle().setProperty("position", "absolute");
|
---|
1257 | _map.getElement().getStyle().setProperty("top", _contentDiv.getAbsoluteTop() + "px");
|
---|
1258 |
|
---|
1259 | //If the map is visible and the Greenstone panel is visible
|
---|
1260 | if (_mapVisible && _gsVisible)
|
---|
1261 | {
|
---|
1262 | _map.setSize((cwidth / 2 - 60) + "px", (cheight - 25) + "px");
|
---|
1263 | _map.getElement().getStyle().setProperty("left", (cwidth / 2 + 50) + "px");
|
---|
1264 | _gsPanel.setSize((cwidth / 2) + "px", (cheight - 25) + "px");
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 | //If the map is visible and the Greenstone panel is not visible
|
---|
1268 | if (_mapVisible && !_gsVisible)
|
---|
1269 | {
|
---|
1270 | _gsPanel.setSize("0px", "0px");
|
---|
1271 | _map.setSize((cwidth - 40) + "px", cheight + "px");
|
---|
1272 | _map.getElement().getStyle().setProperty("left", _gsPanel.getAbsoluteLeft() + "px");
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | //If the map is not visible and the Greenstone panel is visible
|
---|
1276 | if (!_mapVisible && _gsVisible)
|
---|
1277 | {
|
---|
1278 | _gsPanel.setSize(cwidth + "px", cheight + "px");
|
---|
1279 | _map.setSize("0px", "0px");
|
---|
1280 | }
|
---|
1281 |
|
---|
1282 | //If neither panel is visible
|
---|
1283 | if (!_mapVisible && !_gsVisible)
|
---|
1284 | {
|
---|
1285 | _gsPanel.setSize("0px", "0px");
|
---|
1286 | _map.setSize("0px", "0px");
|
---|
1287 | }
|
---|
1288 | }
|
---|
1289 |
|
---|
1290 | /**
|
---|
1291 | * Initialises the Google Map view
|
---|
1292 | */
|
---|
1293 | public void setUpMap()
|
---|
1294 | {
|
---|
1295 | //Set up the map size, style, starting point and zoom level
|
---|
1296 | LatLng startPoint = LatLng.newInstance(0, 0);
|
---|
1297 | _map = new MapWidget(startPoint, _currentZoomLevel);
|
---|
1298 | _map.setSize(Window.getClientWidth() / 2 + "px", "600px");
|
---|
1299 | _map.getElement().getStyle().setProperty("margin", "5px");
|
---|
1300 | _map.setStyleName("map");
|
---|
1301 |
|
---|
1302 | //Store the default map move handler
|
---|
1303 | _mapMoveHandler = new MapMoveHandler()
|
---|
1304 | {
|
---|
1305 | public void onMove(MapMoveEvent event)
|
---|
1306 | {
|
---|
1307 | if (_map.getZoomLevel() != _currentZoomLevel)
|
---|
1308 | {
|
---|
1309 | _currentZoomLevel = _map.getZoomLevel();
|
---|
1310 | _map.clearOverlays();
|
---|
1311 |
|
---|
1312 | //If this is not a search page then there is only one place set
|
---|
1313 | if(!_searchResultsPage)
|
---|
1314 | {
|
---|
1315 | addPlacesToMap(_currentPlaces, "#FFFFFF", "#00FF00", _searchResultsPage);
|
---|
1316 | }
|
---|
1317 | //If this is a search page then there are likely to be multiple place sets
|
---|
1318 | else
|
---|
1319 | {
|
---|
1320 | displayMultiplePlaceSets();
|
---|
1321 | }
|
---|
1322 | }
|
---|
1323 | }
|
---|
1324 | };
|
---|
1325 | _map.addMapMoveHandler(_mapMoveHandler);
|
---|
1326 |
|
---|
1327 | // Add some controls for the zoom level
|
---|
1328 | _map.addControl(new LargeMapControl());
|
---|
1329 | _map.addControl(new MapTypeControl());
|
---|
1330 |
|
---|
1331 | //Add the map loading label
|
---|
1332 | _mapLoadingLabel.setStyleName("mapLoadingLabel");
|
---|
1333 | _mapLoadingLabel.getElement().getStyle().setProperty("left", ((int) (_headerDiv.getOffsetWidth() * (3.0 / 4.0) - _mapLoadingLabel.getOffsetWidth() / 2)) + "px");
|
---|
1334 | _mapLoadingLabel.getElement().getStyle().setProperty("top", (_headerDiv.getOffsetHeight() + _contentDiv.getOffsetHeight() / 3) + "px");
|
---|
1335 |
|
---|
1336 | //Make the map initially invisible
|
---|
1337 | _map.setVisible(false);
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | /**
|
---|
1341 | * Creates a marker at the given point
|
---|
1342 | * @param p is the place to create a marker for
|
---|
1343 | * @param point is the point to place the marker at (if this is null the place will be used to provide the coordinates)
|
---|
1344 | * @param borderColour is the colour of the border to use
|
---|
1345 | * @param fillColour is the colour to use to fill the marker
|
---|
1346 | * @param colourInfo stores whether or not to show a coloured rectangle in the information box that is shown when the marker is clicked
|
---|
1347 | * @return the marker
|
---|
1348 | */
|
---|
1349 | public Polygon createMarkerAtPoint(Place p, LatLng point, String borderColour, String fillColour, Boolean colourInfo)
|
---|
1350 | {
|
---|
1351 | float lat = 0.0f;
|
---|
1352 | float lng = 0.0f;
|
---|
1353 |
|
---|
1354 | //Get the coordinates
|
---|
1355 | if (point == null)
|
---|
1356 | {
|
---|
1357 | lat = p.getLatitude();
|
---|
1358 | lng = p.getLongitude();
|
---|
1359 | }
|
---|
1360 | else
|
---|
1361 | {
|
---|
1362 | lat = (float) point.getLatitude();
|
---|
1363 | lng = (float) point.getLongitude();
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | LatLng newPoint = ((point == null) ? LatLng.newInstance(lat, lng) : point);
|
---|
1367 |
|
---|
1368 | //Work out the size of the new marker based on the current zoom level
|
---|
1369 | double zoomLevel = _map.getZoomLevel();
|
---|
1370 | double size = (8.0 * Math.pow(2.0, -zoomLevel)) + (0.05 * (zoomLevel / 20.0));
|
---|
1371 |
|
---|
1372 | //Work out the transparency of the new marker based on the current zoom level
|
---|
1373 | double transparency = 0.8 * ((20.0 - zoomLevel) / 20.0);
|
---|
1374 |
|
---|
1375 | //Create the corner of the polygon
|
---|
1376 | LatLng tl = LatLng.newInstance(lat - size, lng + size);
|
---|
1377 | LatLng tr = LatLng.newInstance(lat + size, lng + size);
|
---|
1378 | LatLng br = LatLng.newInstance(lat + size, lng - size);
|
---|
1379 | LatLng bl = LatLng.newInstance(lat - size, lng - size);
|
---|
1380 |
|
---|
1381 | //If the user has chosen to highlight this place then make the marker red
|
---|
1382 | Polygon newMarker = null;
|
---|
1383 | if (_highlightedPlaces.contains(p.getName()))
|
---|
1384 | {
|
---|
1385 | newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF7F27", transparency);
|
---|
1386 | }
|
---|
1387 | //Otherwise make it the normal colour
|
---|
1388 | else
|
---|
1389 | {
|
---|
1390 | newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, fillColour, transparency);
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | // When the marker is clicked it will show its address in a info box
|
---|
1394 | newMarker.addPolygonClickHandler(new MarkerClickHandler(fillColour, p, newPoint, colourInfo));
|
---|
1395 |
|
---|
1396 | return newMarker;
|
---|
1397 | }
|
---|
1398 |
|
---|
1399 | /**
|
---|
1400 | * Shows an info box above the marker when the marker is clicked
|
---|
1401 | */
|
---|
1402 | public class MarkerClickHandler implements PolygonClickHandler
|
---|
1403 | {
|
---|
1404 | String _fillColour = "";
|
---|
1405 | Boolean _colourInfo = false;
|
---|
1406 | LatLng _point = null;
|
---|
1407 | Place _place = null;
|
---|
1408 |
|
---|
1409 | public MarkerClickHandler(String fillColour, Place place, LatLng point, Boolean colourInfo)
|
---|
1410 | {
|
---|
1411 | _fillColour = fillColour;
|
---|
1412 | _place = place;
|
---|
1413 | _point = point;
|
---|
1414 | _colourInfo = colourInfo;
|
---|
1415 | }
|
---|
1416 |
|
---|
1417 | public void onClick(PolygonClickEvent event)
|
---|
1418 | {
|
---|
1419 | InfoWindow info = _map.getInfoWindow();
|
---|
1420 | if (_colourInfo)
|
---|
1421 | {
|
---|
1422 | info.open(_point, new InfoWindowContent(createPlaceInformationString(_place)));
|
---|
1423 | }
|
---|
1424 | else
|
---|
1425 | {
|
---|
1426 | info.open(_point, new InfoWindowContent("<span style=\"background: " + _fillColour + "; color: " + _fillColour + ";\">...</span> " + createPlaceInformationString(_place)));
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 | /**
|
---|
1432 | * Takes a place object and creates a string with information about that place
|
---|
1433 | * @param p is the place to make an information string from
|
---|
1434 | * @return the information string
|
---|
1435 | */
|
---|
1436 | public String createPlaceInformationString(Place p)
|
---|
1437 | {
|
---|
1438 | //If we do not have a valid place then stop
|
---|
1439 | if(p == null)
|
---|
1440 | {
|
---|
1441 | return null;
|
---|
1442 | }
|
---|
1443 |
|
---|
1444 | //Add the place name to the string
|
---|
1445 | StringBuilder s = new StringBuilder(p.getName());
|
---|
1446 |
|
---|
1447 | //Add the full parent name to the string
|
---|
1448 | if (p.getParentPlaceName() != null)
|
---|
1449 | {
|
---|
1450 | s.append(" in " + p.getParentPlaceName());
|
---|
1451 | }
|
---|
1452 |
|
---|
1453 | //If we have population information then add it to the string
|
---|
1454 | if (p.getPopulation() > 0)
|
---|
1455 | {
|
---|
1456 | StringBuilder pop = new StringBuilder(Long.toString(p.getPopulation()));
|
---|
1457 |
|
---|
1458 | //Insert commas into long numbers
|
---|
1459 | for (int i = pop.length() - 3; i > 0; i -= 3)
|
---|
1460 | {
|
---|
1461 | pop.insert(i, ',');
|
---|
1462 | }
|
---|
1463 |
|
---|
1464 | s.append("<br/>Population: " + pop);
|
---|
1465 | }
|
---|
1466 |
|
---|
1467 | //If we have coordinates then add those to the string as well
|
---|
1468 | if (p.getLongitude() != null && p.getLatitude() != null)
|
---|
1469 | {
|
---|
1470 | StringBuilder lat = new StringBuilder(Float.toString(p.getLatitude()));
|
---|
1471 | StringBuilder lng = new StringBuilder(Float.toString(p.getLongitude()));
|
---|
1472 |
|
---|
1473 | //Shorten coordinates to 3 decimal places
|
---|
1474 | int i = 0;
|
---|
1475 | while (lat.charAt(i++) != '.');
|
---|
1476 | int j = 0;
|
---|
1477 | while (lng.charAt(j++) != '.');
|
---|
1478 |
|
---|
1479 | if ((i + 3) < lat.length())
|
---|
1480 | {
|
---|
1481 | lat.delete(i + 3, lat.length());
|
---|
1482 | }
|
---|
1483 |
|
---|
1484 | if ((j + 3) < lng.length())
|
---|
1485 | {
|
---|
1486 | lng.delete(j + 3, lng.length());
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | s.append("<br/>Coordinates: " + lat + ", " + lng);
|
---|
1490 | }
|
---|
1491 |
|
---|
1492 | return s.toString();
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | /**
|
---|
1496 | * Make a call to the server that gets places that match the given criteria
|
---|
1497 | */
|
---|
1498 | public void updateCurrentPlaces()
|
---|
1499 | {
|
---|
1500 | _findPlaceService.getPlaces(0, 100, 0, true, true, true, _MAXVISIBLEMARKERS, setUpGetPlacesCallback());
|
---|
1501 | }
|
---|
1502 |
|
---|
1503 | /**
|
---|
1504 | * Displays all of the place sets created from a text search
|
---|
1505 | */
|
---|
1506 | public void displayMultiplePlaceSets()
|
---|
1507 | {
|
---|
1508 | //Clear the map
|
---|
1509 | _map.clearOverlays();
|
---|
1510 |
|
---|
1511 | //Go through each place set and if it has been marked visible then add it
|
---|
1512 | for (int j = 0; j < _currentMultiPlaces.size(); j++)
|
---|
1513 | {
|
---|
1514 | logToConsole("Adding set " + j + " to the map");
|
---|
1515 | if (_visiblePlaceSets.get(j))
|
---|
1516 | {
|
---|
1517 | addPlacesToMap(_currentMultiPlaces.get(j), "#FFFFFF", numToColour(j, _currentMultiPlaces.size(), 100, 255), true);
|
---|
1518 | }
|
---|
1519 | }
|
---|
1520 | _statusBar.removeUpdate("DisPlaces");
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | /**
|
---|
1524 | * Creates a colour from the given parameters
|
---|
1525 | * @param num is the specified index
|
---|
1526 | * @param max is the total number of indexes
|
---|
1527 | * @param cmin is the minimum colour
|
---|
1528 | * @param cmax is the maximum colour
|
---|
1529 | * @return the colour string (e.g. #F35A22)
|
---|
1530 | */
|
---|
1531 | public String numToColour(int num, int max, int cmin, int cmax)
|
---|
1532 | {
|
---|
1533 | logToConsole("num = " + num + ", max = " + max + ", cmin = " + cmin + ", cmax = " + cmax);
|
---|
1534 | //Make sure num and max are good numbers
|
---|
1535 | if(num < 0){num = 0;}
|
---|
1536 | if(max <= 0){return "#000000";}
|
---|
1537 | if(max > 255){max = 255;}
|
---|
1538 | if(num > max){num = max;}
|
---|
1539 |
|
---|
1540 | //Work out where this colour will lie in the spectrum
|
---|
1541 | int colourNum = (int) ((((float) num) / ((float) max)) * ((cmax - cmin) * 8));
|
---|
1542 |
|
---|
1543 | String red = null;
|
---|
1544 | String green = null;
|
---|
1545 | String blue = null;
|
---|
1546 |
|
---|
1547 | //If the colour is in the first section then make it a mix between red and green
|
---|
1548 | if (colourNum <= (cmax - cmin) * 2)
|
---|
1549 | {
|
---|
1550 | if (colourNum <= (cmax - cmin))
|
---|
1551 | {
|
---|
1552 | red = Integer.toHexString(colourNum + cmin);
|
---|
1553 | green = "00";
|
---|
1554 | blue = "00";
|
---|
1555 | }
|
---|
1556 | else
|
---|
1557 | {
|
---|
1558 | colourNum -= (cmax - cmin);
|
---|
1559 | red = Integer.toHexString(cmax);
|
---|
1560 | green = Integer.toHexString(colourNum + cmin);
|
---|
1561 | blue = "00";
|
---|
1562 | }
|
---|
1563 | }
|
---|
1564 | //If the colour is in the second section then make it a mix between green and blue
|
---|
1565 | else if (colourNum <= (cmax - cmin) * 4)
|
---|
1566 | {
|
---|
1567 | colourNum -= ((cmax - cmin) * 2);
|
---|
1568 | if (colourNum <= (cmax - cmin))
|
---|
1569 | {
|
---|
1570 | red = "00";
|
---|
1571 | green = Integer.toHexString(colourNum + cmin);
|
---|
1572 | blue = "00";
|
---|
1573 | }
|
---|
1574 | else
|
---|
1575 | {
|
---|
1576 | colourNum -= (cmax - cmin);
|
---|
1577 | red = "00";
|
---|
1578 | green = Integer.toHexString(cmax);
|
---|
1579 | blue = Integer.toHexString(colourNum + cmin);
|
---|
1580 | }
|
---|
1581 | }
|
---|
1582 | //If the colour is in the third section then make it a mix between red and blue
|
---|
1583 | else if (colourNum <= (cmax - cmin) * 6)
|
---|
1584 | {
|
---|
1585 | colourNum -= ((cmax - cmin) * 4);
|
---|
1586 | if (colourNum <= (cmax - cmin))
|
---|
1587 | {
|
---|
1588 | red = "00";
|
---|
1589 | green = "00";
|
---|
1590 | blue = Integer.toHexString(colourNum + cmin);
|
---|
1591 | }
|
---|
1592 | else
|
---|
1593 | {
|
---|
1594 | colourNum -= (cmax - cmin);
|
---|
1595 | red = Integer.toHexString(colourNum + cmin);
|
---|
1596 | green = "00";
|
---|
1597 | blue = Integer.toHexString(cmax);
|
---|
1598 | }
|
---|
1599 | }
|
---|
1600 | //If the colour is in the fourth section then make it a mix between all colours
|
---|
1601 | else
|
---|
1602 | {
|
---|
1603 | colourNum -= ((cmax - cmin) * 6);
|
---|
1604 | colourNum /= 2;
|
---|
1605 |
|
---|
1606 | red = Integer.toHexString(colourNum + cmin);
|
---|
1607 | green = Integer.toHexString(colourNum + cmin);
|
---|
1608 | blue = Integer.toHexString(colourNum + cmin);
|
---|
1609 | }
|
---|
1610 |
|
---|
1611 | //If the hex strings are only one character long then add a zero the the front
|
---|
1612 | if (red.length() < 2){red = "0" + red;}
|
---|
1613 | if (green.length() < 2){green = "0" + green;}
|
---|
1614 | if (blue.length() < 2){blue = "0" + blue;}
|
---|
1615 |
|
---|
1616 | logToConsole("#" + red + green + blue);
|
---|
1617 | return "#" + red + green + blue;
|
---|
1618 | }
|
---|
1619 |
|
---|
1620 | /**
|
---|
1621 | * Takes an array of places and displays them on the map
|
---|
1622 | * @param places is the list of places to display
|
---|
1623 | * @param borderColour is the colour of the marker borders
|
---|
1624 | * @param fillColour is the main colour of the marker
|
---|
1625 | * @param colourInfo is whether or not to display a coloured box in the information box of the marker
|
---|
1626 | */
|
---|
1627 | public void addPlacesToMap(ArrayList<Place> places, String borderColour, String fillColour, boolean colourInfo)
|
---|
1628 | {
|
---|
1629 | //If we do not have a valid set of places then stop
|
---|
1630 | if(places == null || places.size() == 0)
|
---|
1631 | {
|
---|
1632 | return;
|
---|
1633 | }
|
---|
1634 |
|
---|
1635 | ArrayList<Place> placesSeen = new ArrayList<Place>();
|
---|
1636 |
|
---|
1637 | // Make the best places visible
|
---|
1638 | for (Place p : places)
|
---|
1639 | {
|
---|
1640 | if (!_showAllPlaces)
|
---|
1641 | {
|
---|
1642 | //If the place is not directly referenced then don't use it
|
---|
1643 | if (!p.isDirectlyReferenced())
|
---|
1644 | {
|
---|
1645 | continue;
|
---|
1646 | }
|
---|
1647 |
|
---|
1648 | //If a different place with this name has been chosen then don't use it
|
---|
1649 | if (_removedPlaces.contains(p.getName()) || (_chosenPlaces.containsKey(p.getName()) && !_chosenPlaces.get(p.getName()).equals(p)))
|
---|
1650 | {
|
---|
1651 | continue;
|
---|
1652 | }
|
---|
1653 |
|
---|
1654 | //Make sure we only add the place once
|
---|
1655 | boolean found = false;
|
---|
1656 | for (Place q : placesSeen)
|
---|
1657 | {
|
---|
1658 | if (p.getName().equals(q.getName()))
|
---|
1659 | {
|
---|
1660 | found = true;
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | if (found)
|
---|
1665 | {
|
---|
1666 | continue;
|
---|
1667 | }
|
---|
1668 | placesSeen.add(p);
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | // If there is no latitude and longitude provided for this place
|
---|
1672 | if (p.getLatitude() == null)
|
---|
1673 | {
|
---|
1674 | // Use Google's geocoder to find the place
|
---|
1675 | findAndMarkAddress(p, borderColour, fillColour, colourInfo);
|
---|
1676 | }
|
---|
1677 | // Latitude and longitude are provided in the address
|
---|
1678 | else
|
---|
1679 | {
|
---|
1680 | Polygon marker = createMarkerAtPoint(p, null, borderColour, fillColour, colourInfo);
|
---|
1681 | // Add the marker to the map
|
---|
1682 | _map.addOverlay(marker);
|
---|
1683 | }
|
---|
1684 | }
|
---|
1685 | }
|
---|
1686 |
|
---|
1687 | /**
|
---|
1688 | * Finds and puts a marker at the given address using Google's geocoder service
|
---|
1689 | * @param address is the address to find and mark (e.g. Hamilton, Waikato, New Zealand)
|
---|
1690 | * @param index is where in the list of place locations this is to be added
|
---|
1691 | */
|
---|
1692 | private void findAndMarkAddress(final Place place, final String borderColour, final String fillColour, final boolean colourInfo)
|
---|
1693 | {
|
---|
1694 | String address = null;
|
---|
1695 |
|
---|
1696 | if (place.getParentPlaceName() != null)
|
---|
1697 | {
|
---|
1698 | address = place.getName() + ", " + place.getParentPlaceName();
|
---|
1699 | }
|
---|
1700 | else
|
---|
1701 | {
|
---|
1702 | address = place.getName();
|
---|
1703 | }
|
---|
1704 |
|
---|
1705 | // Make the call to the geocoder service
|
---|
1706 | _geocoder.getLatLng(address, new LatLngCallback()
|
---|
1707 | {
|
---|
1708 | // Ignore the place if it is not valid
|
---|
1709 | public void onFailure()
|
---|
1710 | {
|
---|
1711 | // LogToConsole("Failed");
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | // If the geocoder service found the place
|
---|
1715 | public void onSuccess(final LatLng point)
|
---|
1716 | {
|
---|
1717 | // LogToConsole("Found");
|
---|
1718 | Polygon marker = createMarkerAtPoint(place, point, borderColour, fillColour, colourInfo);
|
---|
1719 |
|
---|
1720 | place.setLatitude((float) point.getLatitude());
|
---|
1721 | place.setLongitude((float) point.getLongitude());
|
---|
1722 |
|
---|
1723 | // Add the marker to the map
|
---|
1724 | _map.addOverlay(marker);
|
---|
1725 | }
|
---|
1726 | });
|
---|
1727 | }
|
---|
1728 |
|
---|
1729 | public AsyncCallback<ArrayList<Place>> setUpGetPlacesCallback()
|
---|
1730 | {
|
---|
1731 | AsyncCallback<ArrayList<Place>> callback = new AsyncCallback<ArrayList<Place>>()
|
---|
1732 | {
|
---|
1733 | public void onFailure(Throwable caught)
|
---|
1734 | {
|
---|
1735 | logToConsole("Get Places FAIL" + caught.getMessage());
|
---|
1736 | }
|
---|
1737 |
|
---|
1738 | // This is called when a successful call to findAllPlaces() is
|
---|
1739 | // completed
|
---|
1740 | public void onSuccess(ArrayList<Place> places)
|
---|
1741 | {
|
---|
1742 | logToConsole("Get Places Success!");
|
---|
1743 | _currentPlaces = places;
|
---|
1744 |
|
---|
1745 | addPlacesToMap(places, "#FFFFFF", "#00FF00", _searchResultsPage);
|
---|
1746 | _updatingMap = false;
|
---|
1747 | }
|
---|
1748 | };
|
---|
1749 |
|
---|
1750 | return callback;
|
---|
1751 | }
|
---|
1752 |
|
---|
1753 | /**
|
---|
1754 | * Creates the callback object that is used when the call to the server returns
|
---|
1755 | * @return the callback object
|
---|
1756 | */
|
---|
1757 | public AsyncCallback<Boolean> setUpFindPlacesCallback()
|
---|
1758 | {
|
---|
1759 | return new AsyncCallback<Boolean>()
|
---|
1760 | {
|
---|
1761 | /**
|
---|
1762 | * This is called when the call to the server fails
|
---|
1763 | */
|
---|
1764 | public void onFailure(Throwable caught)
|
---|
1765 | {
|
---|
1766 | _statusBar.removeUpdate("TextSearch");
|
---|
1767 | logToConsole("Find places fail" + caught.getMessage());
|
---|
1768 | }
|
---|
1769 |
|
---|
1770 | /**
|
---|
1771 | * This is called when the call to the server succeeds
|
---|
1772 | * @param result is a dummy variable that does not do anything
|
---|
1773 | */
|
---|
1774 | public void onSuccess(Boolean result)
|
---|
1775 | {
|
---|
1776 | //Remove the "searching for places" status bar message
|
---|
1777 | _statusBar.removeUpdate("TextSearch");
|
---|
1778 |
|
---|
1779 | logToConsole("Find Places success!");
|
---|
1780 |
|
---|
1781 | //Get the marked up text from the server
|
---|
1782 | _findPlaceService.getMarkedUpText(setUpGetMarkedUpTextCallback());
|
---|
1783 |
|
---|
1784 | //Get the found places from the server
|
---|
1785 | updateCurrentPlaces();
|
---|
1786 |
|
---|
1787 | //Clear the map
|
---|
1788 | _map.clearOverlays();
|
---|
1789 |
|
---|
1790 | //Add the new places to the map
|
---|
1791 | addPlacesToMap(_currentPlaces, "#FFFFFF", "#00FF00", _searchResultsPage);
|
---|
1792 |
|
---|
1793 | //Remove the "map loading" message from the map
|
---|
1794 | _mapLoadingLabel.removeFromParent();
|
---|
1795 | }
|
---|
1796 | };
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | public AsyncCallback<ArrayList<ArrayList<Place>>> setUpFindMultiplePlacesCallback()
|
---|
1800 | {
|
---|
1801 | AsyncCallback<ArrayList<ArrayList<Place>>> callback = new AsyncCallback<ArrayList<ArrayList<Place>>>()
|
---|
1802 | {
|
---|
1803 | public void onFailure(Throwable caught)
|
---|
1804 | {
|
---|
1805 | alert("Find multi places fail" + caught.getMessage());
|
---|
1806 | }
|
---|
1807 |
|
---|
1808 | public void onSuccess(ArrayList<ArrayList<Place>> places)
|
---|
1809 | {
|
---|
1810 | _statusBar.removeUpdate("SearchLoad");
|
---|
1811 | _statusBar.addUpdate("Displaying places", "DisPlaces");
|
---|
1812 |
|
---|
1813 | _currentMultiPlaces = places;
|
---|
1814 | _visiblePlaceSets = new ArrayList<Boolean>();
|
---|
1815 | for (int i = 0; i < _currentMultiPlaces.size(); i++)
|
---|
1816 | {
|
---|
1817 | _visiblePlaceSets.add(true);
|
---|
1818 | }
|
---|
1819 |
|
---|
1820 | _mapLoadingLabel.removeFromParent();
|
---|
1821 | displayMultiplePlaceSets();
|
---|
1822 | addElementsToSearchResults(places);
|
---|
1823 | }
|
---|
1824 | };
|
---|
1825 | return callback;
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | public AsyncCallback<Boolean> setUpCheckGazetteerCallback()
|
---|
1829 | {
|
---|
1830 | AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>()
|
---|
1831 | {
|
---|
1832 | public void onFailure(Throwable caught)
|
---|
1833 | {
|
---|
1834 | logToConsole("Check Gazetteer fail " + caught.getMessage());
|
---|
1835 | }
|
---|
1836 |
|
---|
1837 | public void onSuccess(Boolean result)
|
---|
1838 | {
|
---|
1839 | if (!result)
|
---|
1840 | {
|
---|
1841 | _statusBar.addUpdate("Server is loading gazetteer", "GazLoad");
|
---|
1842 |
|
---|
1843 | _findPlaceService.loadGazetteer(setUpLoadGazetteerCallback());
|
---|
1844 | }
|
---|
1845 | else
|
---|
1846 | {
|
---|
1847 | logToConsole("Gazetteer Already Loaded!");
|
---|
1848 | _gazetteerLoaded = true;
|
---|
1849 | }
|
---|
1850 | }
|
---|
1851 | };
|
---|
1852 | return callback;
|
---|
1853 | }
|
---|
1854 |
|
---|
1855 | /**
|
---|
1856 | * Checks to see if the current page has text from a document so that it can be checked for places
|
---|
1857 | */
|
---|
1858 | public void checkDocText()
|
---|
1859 | {
|
---|
1860 | //Get the document text element if it exists
|
---|
1861 | Element documentText = getDocTextElement();
|
---|
1862 |
|
---|
1863 | //If it does not exist then stop
|
---|
1864 | if (documentText == null)
|
---|
1865 | {
|
---|
1866 | logToConsole("document text div not found");
|
---|
1867 | if (_mapVisible)
|
---|
1868 | {
|
---|
1869 | _map.setVisible(false);
|
---|
1870 | _mapVisible = false;
|
---|
1871 | }
|
---|
1872 | _viewPanel.setVisible(false);
|
---|
1873 | return;
|
---|
1874 | }
|
---|
1875 |
|
---|
1876 | logToConsole("Document text found!");
|
---|
1877 |
|
---|
1878 | //Allow the user to change the method they wish to use view the text
|
---|
1879 | _viewPanel.setVisible(true);
|
---|
1880 |
|
---|
1881 | //If the view type is not set to normal then remove the TOC
|
---|
1882 | if (_textViewSelector.getSelectedIndex() > 0)
|
---|
1883 | {
|
---|
1884 | HTML.wrap(getElementById("rightSidebar")).setVisible(false);
|
---|
1885 | }
|
---|
1886 |
|
---|
1887 | //Create the document menu if we have not already done so
|
---|
1888 | if (_currentDocumentMenu == null)
|
---|
1889 | {
|
---|
1890 | createDocumentMenu();
|
---|
1891 | }
|
---|
1892 |
|
---|
1893 | //Create the timer that closes the document menu when it is not in focus
|
---|
1894 | _menuOutTimer = new Timer()
|
---|
1895 | {
|
---|
1896 | public void run()
|
---|
1897 | {
|
---|
1898 | _currentDocumentMenu.hideMenu();
|
---|
1899 | }
|
---|
1900 | };
|
---|
1901 |
|
---|
1902 | //Let the user know that the system is searching for places
|
---|
1903 | _statusBar.addUpdate("Searching text for places", "TextSearch");
|
---|
1904 |
|
---|
1905 | //Clear the map
|
---|
1906 | _map.clearOverlays();
|
---|
1907 |
|
---|
1908 | //Make the map visible
|
---|
1909 | _mapVisible = true;
|
---|
1910 | _map.setVisible(true);
|
---|
1911 |
|
---|
1912 | //Add the "Loading" message to the map
|
---|
1913 | _contentDiv.add(_mapLoadingLabel);
|
---|
1914 |
|
---|
1915 | _mapLoadingLabel.getElement().getStyle().setProperty("left", ((int) (_headerDiv.getOffsetWidth() * (3.0 / 4.0) - _mapLoadingLabel.getOffsetWidth() / 2)) + "px");
|
---|
1916 | _mapLoadingLabel.getElement().getStyle().setProperty("top", (_headerDiv.getOffsetHeight() + _contentDiv.getOffsetHeight() / 3) + "px");
|
---|
1917 |
|
---|
1918 | //Resize the page elemens
|
---|
1919 | _resize = true;
|
---|
1920 |
|
---|
1921 | //Send the document text to the server to be checked for places
|
---|
1922 | final Element finalDocumentText = documentText;
|
---|
1923 | Timer checkLoadTimer = new Timer()
|
---|
1924 | {
|
---|
1925 | public void run()
|
---|
1926 | {
|
---|
1927 | if (_gazetteerLoaded)
|
---|
1928 | {
|
---|
1929 | this.cancel();
|
---|
1930 | _findPlaceService.findPlacesInText(finalDocumentText.getInnerText(), finalDocumentText.getInnerHTML(), setUpFindPlacesCallback());
|
---|
1931 | }
|
---|
1932 | }
|
---|
1933 | };
|
---|
1934 | checkLoadTimer.scheduleRepeating(1000);
|
---|
1935 | }
|
---|
1936 |
|
---|
1937 | /**
|
---|
1938 | * Creates and returns the callback object used when the call to the server returns
|
---|
1939 | * @return the callback object
|
---|
1940 | */
|
---|
1941 | public AsyncCallback<String> setUpGetMarkedUpTextCallback()
|
---|
1942 | {
|
---|
1943 | return new AsyncCallback<String>()
|
---|
1944 | {
|
---|
1945 | /**
|
---|
1946 | * This is called when the call to the server fails
|
---|
1947 | */
|
---|
1948 | public void onFailure(Throwable caught)
|
---|
1949 | {
|
---|
1950 | logToConsole("Mark up text failed -> " + caught.getMessage());
|
---|
1951 | }
|
---|
1952 |
|
---|
1953 | /**
|
---|
1954 | * This is called when the call the to server succeeds
|
---|
1955 | * @param markedUpText is the text (marked up with place names) returned from the server
|
---|
1956 | */
|
---|
1957 | public void onSuccess(String markedUpText)
|
---|
1958 | {
|
---|
1959 | logToConsole("Mark up text success");
|
---|
1960 |
|
---|
1961 | //Get the unmodified document text element from the web page
|
---|
1962 | Element documentText = getDocTextElement();
|
---|
1963 |
|
---|
1964 | //Set the document text HTML to be the marked up text
|
---|
1965 | documentText.setInnerHTML(markedUpText);
|
---|
1966 |
|
---|
1967 | //Get the spans in the marked up text that are place names
|
---|
1968 | JsArray<Element> textPlaces = getElementsByTagName("span");
|
---|
1969 | ArrayList<Element> placeElements = new ArrayList<Element>();
|
---|
1970 |
|
---|
1971 | //Add the place spans to the array
|
---|
1972 | for (int j = 0; j < textPlaces.length(); j++)
|
---|
1973 | {
|
---|
1974 | if (textPlaces.get(j).getAttribute("class").equals("place"))
|
---|
1975 | {
|
---|
1976 | placeElements.add(textPlaces.get(j));
|
---|
1977 | }
|
---|
1978 | }
|
---|
1979 |
|
---|
1980 | logToConsole("Adding events to " + placeElements.size() + " place spans");
|
---|
1981 |
|
---|
1982 | //Add mouse over and mouse out handlers to each span
|
---|
1983 | for (Element e : placeElements)
|
---|
1984 | {
|
---|
1985 | Label newLabel = Label.wrap(e);
|
---|
1986 | newLabel.addMouseOverHandler(new PlaceMouseOverHandler());
|
---|
1987 | newLabel.addMouseOutHandler(new PlaceMouseOutHandler());
|
---|
1988 | newLabel.addMouseUpHandler(new PlaceMouseUpHandler());
|
---|
1989 | }
|
---|
1990 |
|
---|
1991 | //If Fisheye view is selected in the list box then use it
|
---|
1992 | if (_textViewSelector.getSelectedIndex() == 1)
|
---|
1993 | {
|
---|
1994 | _statusBar.addUpdate("Loading fisheye view", "FishLoad");
|
---|
1995 | setUpFishEye();
|
---|
1996 | _statusBar.removeUpdate("FishLoad");
|
---|
1997 | _fishEyeHandlerReg = _gsPanel.addMouseMoveHandler(new FishEyeMouseMoveHandler());
|
---|
1998 | }
|
---|
1999 |
|
---|
2000 | //If Column view is selected in the list box then use it
|
---|
2001 | if (_textViewSelector.getSelectedIndex() == 2)
|
---|
2002 | {
|
---|
2003 | setUpColumnView(documentText);
|
---|
2004 | }
|
---|
2005 | }
|
---|
2006 | };
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | public void setUpColumnView(Element documentText)
|
---|
2010 | {
|
---|
2011 | _statusBar.addUpdate("Loading column view", "ColLoad");
|
---|
2012 |
|
---|
2013 | logToConsole("Wrapping doc text");
|
---|
2014 | HTML docText = HTML.wrap(documentText);
|
---|
2015 | int width = docText.getOffsetWidth();
|
---|
2016 | String html = docText.getHTML();
|
---|
2017 | ArrayList<String> words = new ArrayList<String>();
|
---|
2018 |
|
---|
2019 | int inTag = 0;
|
---|
2020 | boolean inWord = false;
|
---|
2021 |
|
---|
2022 | StringBuilder currentWord = new StringBuilder();
|
---|
2023 |
|
---|
2024 | for (int i = 0; i < html.length(); i++)
|
---|
2025 | {
|
---|
2026 | boolean add = true;
|
---|
2027 | char c = html.charAt(i);
|
---|
2028 |
|
---|
2029 | if (inTag > 0 && c == '>')
|
---|
2030 | {
|
---|
2031 | inTag--;
|
---|
2032 |
|
---|
2033 | if (inTag == 0)
|
---|
2034 | {
|
---|
2035 | words.add(currentWord.toString() + ">");
|
---|
2036 | currentWord = new StringBuilder();
|
---|
2037 | add = false;
|
---|
2038 | }
|
---|
2039 | }
|
---|
2040 | else if (c == '<')
|
---|
2041 | {
|
---|
2042 | inTag++;
|
---|
2043 |
|
---|
2044 | if (inWord)
|
---|
2045 | {
|
---|
2046 | inWord = false;
|
---|
2047 | words.add(currentWord.toString());
|
---|
2048 | currentWord = new StringBuilder();
|
---|
2049 | }
|
---|
2050 | }
|
---|
2051 | else if (("" + c).matches("\\s"))
|
---|
2052 | {
|
---|
2053 | if (inTag == 0)
|
---|
2054 | {
|
---|
2055 | add = false;
|
---|
2056 | }
|
---|
2057 |
|
---|
2058 | if (inWord)
|
---|
2059 | {
|
---|
2060 | inWord = false;
|
---|
2061 | words.add(currentWord.toString());
|
---|
2062 | currentWord = new StringBuilder();
|
---|
2063 | }
|
---|
2064 | }
|
---|
2065 | else
|
---|
2066 | {
|
---|
2067 | if (inTag == 0 && !inWord)
|
---|
2068 | {
|
---|
2069 | inWord = true;
|
---|
2070 | }
|
---|
2071 | }
|
---|
2072 |
|
---|
2073 | if (add)
|
---|
2074 | {
|
---|
2075 | currentWord.append(c);
|
---|
2076 | }
|
---|
2077 | }
|
---|
2078 |
|
---|
2079 | docText.setHTML("");
|
---|
2080 |
|
---|
2081 | HorizontalPanel columns = new HorizontalPanel();
|
---|
2082 | ArrayList<Label> labels = new ArrayList<Label>();
|
---|
2083 | logToConsole("Adding columns to panel");
|
---|
2084 |
|
---|
2085 | if (_contentDiv.getWidget(0).getElement().getId() == "gs_content")
|
---|
2086 | {
|
---|
2087 | VerticalPanel newDocTextPanel = new VerticalPanel();
|
---|
2088 | newDocTextPanel.add(columns);
|
---|
2089 | newDocTextPanel.add(_contentDiv.getWidget(0));
|
---|
2090 | newDocTextPanel.getElement().setId("columnBox");
|
---|
2091 | _contentDiv.insert(newDocTextPanel, 0);
|
---|
2092 | }
|
---|
2093 | else
|
---|
2094 | {
|
---|
2095 | ((VerticalPanel) (_contentDiv.getWidget(0))).remove(0);
|
---|
2096 | ((VerticalPanel) (_contentDiv.getWidget(0))).insert(columns, 0);
|
---|
2097 | }
|
---|
2098 |
|
---|
2099 | float fontSize = 12;
|
---|
2100 | do
|
---|
2101 | {
|
---|
2102 | logToConsole("Looping");
|
---|
2103 | Label l = new Label();
|
---|
2104 | labels.add(l);
|
---|
2105 | columns.add(l);
|
---|
2106 |
|
---|
2107 | for (int j = 0; j < labels.size(); j++)
|
---|
2108 | {
|
---|
2109 | StringBuilder labelText = new StringBuilder();
|
---|
2110 | for (int i = (words.size() / labels.size()) * j; i < ((j < (labels.size() - 1)) ? (((words.size() / labels.size()) * (j + 1)) - 1) : (words.size())); i++)
|
---|
2111 | {
|
---|
2112 | labelText.append(words.get(i) + " ");
|
---|
2113 | }
|
---|
2114 |
|
---|
2115 | labels.get(j).getElement().setInnerHTML(labelText.toString());
|
---|
2116 | labels.get(j).setWidth((width / labels.size()) + "px");
|
---|
2117 | labels.get(j).getElement().getStyle().setProperty("fontSize", fontSize + "px");
|
---|
2118 | }
|
---|
2119 | fontSize *= 0.85;
|
---|
2120 |
|
---|
2121 | logToConsole("Font size = " + fontSize);
|
---|
2122 | } while (columns.getOffsetHeight() > (Window.getClientHeight() - _headerDiv.getOffsetHeight() - _footerDiv.getOffsetHeight() - 70));
|
---|
2123 |
|
---|
2124 | for (int i = 0; i < labels.size(); i++)
|
---|
2125 | {
|
---|
2126 | ArrayList<String> subList = new ArrayList<String>();
|
---|
2127 | for (int j = (words.size() / labels.size()) * i; j < ((i < (labels.size() - 1)) ? (((words.size() / labels.size()) * (i + 1)) - 1) : (words.size())); j++)
|
---|
2128 | {
|
---|
2129 | subList.add(words.get(j));
|
---|
2130 | }
|
---|
2131 | labels.get(i).addMouseMoveHandler(new ColumnViewMouseMoveHandler(labels.get(i), subList));
|
---|
2132 | }
|
---|
2133 |
|
---|
2134 | columns.add(_columnViewBox);
|
---|
2135 | _columnViewBox.getElement().getStyle().setProperty("position", "absolute");
|
---|
2136 | _columnViewBox.getElement().getStyle().setProperty("border", "2px solid");
|
---|
2137 | _columnViewBox.getElement().getStyle().setProperty("background", "#FFFFFF");
|
---|
2138 | _columnViewBox.getElement().getStyle().setProperty("fontSize", "10px");
|
---|
2139 | _columnViewBox.setPixelSize(250, 100);
|
---|
2140 | _columnViewBox.setVisible(false);
|
---|
2141 |
|
---|
2142 | _statusBar.removeUpdate("ColLoad");
|
---|
2143 | }
|
---|
2144 |
|
---|
2145 | class ColumnViewMouseMoveHandler implements MouseMoveHandler
|
---|
2146 | {
|
---|
2147 | Label _label = null;
|
---|
2148 | ArrayList<String> _words = null;
|
---|
2149 |
|
---|
2150 | public ColumnViewMouseMoveHandler(Label label, ArrayList<String> words)
|
---|
2151 | {
|
---|
2152 | _label = label;
|
---|
2153 | _words = words;
|
---|
2154 | }
|
---|
2155 |
|
---|
2156 | public void onMouseOut(MouseOutEvent event)
|
---|
2157 | {
|
---|
2158 | _columnViewBox.setVisible(false);
|
---|
2159 | }
|
---|
2160 |
|
---|
2161 | public void onMouseOver(MouseOverEvent event)
|
---|
2162 | {
|
---|
2163 | _columnViewBox.setVisible(true);
|
---|
2164 | }
|
---|
2165 |
|
---|
2166 | public void onMouseMove(MouseMoveEvent event)
|
---|
2167 | {
|
---|
2168 | _columnViewBox.setVisible(true);
|
---|
2169 |
|
---|
2170 | JsArray<Element> divs = getElementsByTagName("div");
|
---|
2171 | Element documentText = null;
|
---|
2172 | for (int i = 0; i < divs.length(); i++)
|
---|
2173 | {
|
---|
2174 | if (divs.get(i).getAttribute("class").equals("documenttext"))
|
---|
2175 | {
|
---|
2176 | documentText = divs.get(i);
|
---|
2177 | break;
|
---|
2178 | }
|
---|
2179 | }
|
---|
2180 |
|
---|
2181 | if (event.getY() < 125)
|
---|
2182 | {
|
---|
2183 | _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() + 25) + "px");
|
---|
2184 | }
|
---|
2185 | else
|
---|
2186 | {
|
---|
2187 | _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() - 125) + "px");
|
---|
2188 | }
|
---|
2189 |
|
---|
2190 | if (event.getX() + _label.getAbsoluteLeft() - 125 < documentText.getAbsoluteLeft())
|
---|
2191 | {
|
---|
2192 | _columnViewBox.getElement().getStyle().setProperty("left", documentText.getAbsoluteLeft() + "px");
|
---|
2193 | }
|
---|
2194 | else if (event.getX() + _label.getAbsoluteLeft() + 125 > documentText.getOffsetWidth() + documentText.getAbsoluteLeft())
|
---|
2195 | {
|
---|
2196 | _columnViewBox.getElement().getStyle().setProperty("left", documentText.getOffsetWidth() + documentText.getAbsoluteLeft() - 250 + "px");
|
---|
2197 | }
|
---|
2198 | else
|
---|
2199 | {
|
---|
2200 | _columnViewBox.getElement().getStyle().setProperty("left", (event.getX() + _label.getAbsoluteLeft() - 125) + "px");
|
---|
2201 | }
|
---|
2202 |
|
---|
2203 | int midWordIndex = (int) (((float) (event.getY()) / ((_label.getAbsoluteTop() + _label.getOffsetHeight()) - _label.getAbsoluteTop())) * _words.size());
|
---|
2204 | int topWord = midWordIndex - 25;
|
---|
2205 | int botWord = midWordIndex + 25;
|
---|
2206 |
|
---|
2207 | if (_words.size() < 50)
|
---|
2208 | {
|
---|
2209 | topWord = 0;
|
---|
2210 | botWord = _words.size();
|
---|
2211 | }
|
---|
2212 | else
|
---|
2213 | {
|
---|
2214 | if (topWord < 0)
|
---|
2215 | {
|
---|
2216 | topWord = 0;
|
---|
2217 | }
|
---|
2218 | else if (topWord > _words.size() - 50)
|
---|
2219 | {
|
---|
2220 | topWord = _words.size() - 50;
|
---|
2221 | }
|
---|
2222 |
|
---|
2223 | if (botWord > _words.size())
|
---|
2224 | {
|
---|
2225 | botWord = _words.size();
|
---|
2226 | }
|
---|
2227 | else if (botWord < 50)
|
---|
2228 | {
|
---|
2229 | botWord = 50;
|
---|
2230 | }
|
---|
2231 | }
|
---|
2232 |
|
---|
2233 | StringBuilder s = new StringBuilder();
|
---|
2234 |
|
---|
2235 | for (int i = topWord; i < botWord; i++)
|
---|
2236 | {
|
---|
2237 | s.append(_words.get(i) + " ");
|
---|
2238 | }
|
---|
2239 |
|
---|
2240 | _columnViewBox.getElement().setInnerHTML(s.toString());
|
---|
2241 | }
|
---|
2242 | }
|
---|
2243 |
|
---|
2244 | public AsyncCallback<Boolean> setUpLoadGazetteerCallback()
|
---|
2245 | {
|
---|
2246 | AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>()
|
---|
2247 | {
|
---|
2248 | public void onFailure(Throwable caught)
|
---|
2249 | {
|
---|
2250 | logToConsole("Loading Gazetteer failed ->" + caught.getMessage());
|
---|
2251 | }
|
---|
2252 |
|
---|
2253 | public void onSuccess(Boolean success)
|
---|
2254 | {
|
---|
2255 | logToConsole("Loading Gazetteer success!");
|
---|
2256 | _statusBar.removeUpdate("GazLoad");
|
---|
2257 | _gazetteerLoaded = true;
|
---|
2258 | }
|
---|
2259 | };
|
---|
2260 |
|
---|
2261 | return callback;
|
---|
2262 | }
|
---|
2263 |
|
---|
2264 | public void createDocumentMenu()
|
---|
2265 | {
|
---|
2266 | // Menu
|
---|
2267 | final Menu documentMenu = new Menu(_footerDiv.getElement(), new MouseOverHandler()
|
---|
2268 | {
|
---|
2269 | public void onMouseOver(MouseOverEvent event)
|
---|
2270 | {
|
---|
2271 | if(_menuOverTimer != null)
|
---|
2272 | {
|
---|
2273 | _menuOverTimer.cancel();
|
---|
2274 | _menuOverTimer = null;
|
---|
2275 | }
|
---|
2276 | Label item = (Label) event.getSource();
|
---|
2277 | item.getElement().getStyle().setProperty("background", "#0000FF");
|
---|
2278 | item.getElement().getStyle().setProperty("color", "#FFFFFF");
|
---|
2279 | item.getElement().getStyle().setProperty("border", "1px solid");
|
---|
2280 | if (_menuOutTimer != null)
|
---|
2281 | {
|
---|
2282 | _menuOutTimer.cancel();
|
---|
2283 | _menuOutTimer = null;
|
---|
2284 | }
|
---|
2285 | }
|
---|
2286 | }, new MouseOutHandler()
|
---|
2287 | {
|
---|
2288 | public void onMouseOut(MouseOutEvent event)
|
---|
2289 | {
|
---|
2290 | // logToConsole("MENU OUT!");
|
---|
2291 | Label item = (Label) event.getSource();
|
---|
2292 | item.getElement().getStyle().setProperty("background", "#FFFFFF");
|
---|
2293 | item.getElement().getStyle().setProperty("color", "#000000");
|
---|
2294 | item.getElement().getStyle().setProperty("border", "1px solid");
|
---|
2295 |
|
---|
2296 | _menuOutTimer = new Timer()
|
---|
2297 | {
|
---|
2298 | public void run()
|
---|
2299 | {
|
---|
2300 | _currentDocumentMenu.hideMenu();
|
---|
2301 | }
|
---|
2302 | };
|
---|
2303 |
|
---|
2304 | _menuOutTimer.schedule(500);
|
---|
2305 | }
|
---|
2306 | });
|
---|
2307 |
|
---|
2308 | // Menu items
|
---|
2309 | ArrayList<MenuItem> menuItems = new ArrayList<MenuItem>();
|
---|
2310 | menuItems.add(new MenuItem("Centre this place on the map", new ClickHandler()
|
---|
2311 | {
|
---|
2312 | public void onClick(ClickEvent event)
|
---|
2313 | {
|
---|
2314 | Place place = null;
|
---|
2315 |
|
---|
2316 | logToConsole("Center clicked, selected place name = " + _selectedPlaceName);
|
---|
2317 |
|
---|
2318 | if ((place = _chosenPlaces.get(_selectedPlaceName)) == null)
|
---|
2319 | {
|
---|
2320 | for (int i = 0; i < _currentPlaces.size(); i++)
|
---|
2321 | {
|
---|
2322 | if (_currentPlaces.get(i).getName().equals(_selectedPlaceName))
|
---|
2323 | {
|
---|
2324 | place = _currentPlaces.get(i);
|
---|
2325 | break;
|
---|
2326 | }
|
---|
2327 | }
|
---|
2328 | }
|
---|
2329 |
|
---|
2330 | if (place != null && place.getLatitude() != null && place.getLongitude() != null)
|
---|
2331 | {
|
---|
2332 | logToConsole("Centering map");
|
---|
2333 | _map.setCenter(LatLng.newInstance(place.getLatitude(), place.getLongitude()));
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | _currentDocumentMenu.hideMenu();
|
---|
2337 | }
|
---|
2338 | }));
|
---|
2339 |
|
---|
2340 | menuItems.add(new MenuItem("Highlight this place on the map", new ClickHandler()
|
---|
2341 | {
|
---|
2342 | public void onClick(ClickEvent event)
|
---|
2343 | {
|
---|
2344 | _highlightedPlaces.add(_selectedPlaceName);
|
---|
2345 | _map.clearOverlays();
|
---|
2346 | logToConsole("Overlays cleared");
|
---|
2347 | addPlacesToMap(_currentPlaces, "#FFFFFF", "#00FF00", false);
|
---|
2348 | logToConsole("Places added");
|
---|
2349 |
|
---|
2350 | _currentDocumentMenu.hideMenu();
|
---|
2351 | }
|
---|
2352 | }));
|
---|
2353 |
|
---|
2354 | menuItems.add(new MenuItem("Highlight this place in the text", new ClickHandler()
|
---|
2355 | {
|
---|
2356 | public void onClick(ClickEvent event)
|
---|
2357 | {
|
---|
2358 | _highlightedTextPlaces.add(_selectedPlaceName);
|
---|
2359 |
|
---|
2360 | JsArray<Element> places = getElementsByTagName("span");
|
---|
2361 |
|
---|
2362 | for (int i = 0; i < places.length(); i++)
|
---|
2363 | {
|
---|
2364 | Element e = places.get(i);
|
---|
2365 |
|
---|
2366 | if (e.getClassName() == "place" && e.getInnerText() == _selectedPlaceName)
|
---|
2367 | {
|
---|
2368 | e.getStyle().setProperty("background", "#FF0000");
|
---|
2369 | }
|
---|
2370 | }
|
---|
2371 |
|
---|
2372 | _currentDocumentMenu.hideMenu();
|
---|
2373 | }
|
---|
2374 | }));
|
---|
2375 |
|
---|
2376 | menuItems.add(new MenuItem("Remove all highlights", new ClickHandler()
|
---|
2377 | {
|
---|
2378 | public void onClick(ClickEvent event)
|
---|
2379 | {
|
---|
2380 | _highlightedPlaces.clear();
|
---|
2381 |
|
---|
2382 | _map.clearOverlays();
|
---|
2383 | addPlacesToMap(_currentPlaces, "#FFFFFF", "#00FF00", false);
|
---|
2384 |
|
---|
2385 | JsArray<Element> places = getElementsByTagName("span");
|
---|
2386 |
|
---|
2387 | for (int i = 0; i < places.length(); i++)
|
---|
2388 | {
|
---|
2389 | Element e = places.get(i);
|
---|
2390 |
|
---|
2391 | if (e.getClassName() == "place" && _highlightedTextPlaces.contains(e.getInnerText()))
|
---|
2392 | {
|
---|
2393 | e.getStyle().setProperty("background", "#FFFF00");
|
---|
2394 | }
|
---|
2395 | }
|
---|
2396 | _highlightedTextPlaces.clear();
|
---|
2397 |
|
---|
2398 | _currentDocumentMenu.hideMenu();
|
---|
2399 | }
|
---|
2400 | }));
|
---|
2401 |
|
---|
2402 | final MenuItem prevMenuItem = new MenuItem("Remove this place", new ClickHandler()
|
---|
2403 | {
|
---|
2404 | public void onClick(ClickEvent event)
|
---|
2405 | {
|
---|
2406 | _removedPlaces.add(_selectedPlaceName);
|
---|
2407 | _currentDocumentMenu.hideMenu();
|
---|
2408 |
|
---|
2409 | JsArray<Element> textPlaces = getElementsByTagName("span");
|
---|
2410 |
|
---|
2411 | //Add the place spans to the array
|
---|
2412 | for (int j = 0; j < textPlaces.length(); j++)
|
---|
2413 | {
|
---|
2414 | Element e = textPlaces.get(j);
|
---|
2415 | if (e.getAttribute("class").equals("place") && e.getInnerText().equals(_selectedPlaceName))
|
---|
2416 | {
|
---|
2417 | e.getParentElement().insertBefore(e.getFirstChild(), e);
|
---|
2418 | }
|
---|
2419 | }
|
---|
2420 |
|
---|
2421 | _map.clearOverlays();
|
---|
2422 | addPlacesToMap(_currentPlaces, "#FFFFFF", "#00FF00", false);
|
---|
2423 | }
|
---|
2424 | });
|
---|
2425 | menuItems.add(prevMenuItem);
|
---|
2426 |
|
---|
2427 | menuItems.add(new MenuItem("Choose correct place >", new ClickHandler()
|
---|
2428 | {
|
---|
2429 | public void onClick(ClickEvent event)
|
---|
2430 | {
|
---|
2431 | logToConsole("MARKER!");
|
---|
2432 | ArrayList<MenuItem> places = new ArrayList<MenuItem>();
|
---|
2433 |
|
---|
2434 | ArrayList<Place> matchingPlaces = new ArrayList<Place>();
|
---|
2435 |
|
---|
2436 | for (Place p : _currentPlaces)
|
---|
2437 | {
|
---|
2438 | if (p.getName().equals(_selectedPlaceName))
|
---|
2439 | {
|
---|
2440 | matchingPlaces.add(p);
|
---|
2441 | }
|
---|
2442 | }
|
---|
2443 |
|
---|
2444 | for (final Place p : matchingPlaces)
|
---|
2445 | {
|
---|
2446 | places.add(new MenuItem(p.getName() + ((p.getParentPlaceName() != null) ? (", " + p.getParentPlaceName()) : (" (Country)")), new ClickHandler()
|
---|
2447 | {
|
---|
2448 | public void onClick(ClickEvent e)
|
---|
2449 | {
|
---|
2450 | _chosenPlaces.put(_selectedPlaceName, p);
|
---|
2451 |
|
---|
2452 | _map.clearOverlays();
|
---|
2453 | logToConsole("Chose a new place!!!");
|
---|
2454 | addPlacesToMap(_currentPlaces, "#FFFFFF", "#00FF00", false);
|
---|
2455 | logToConsole("Places added!!!");
|
---|
2456 |
|
---|
2457 | _currentDocumentMenu.hideMenu();
|
---|
2458 | }
|
---|
2459 | }));
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | Menu placeMenu = new Menu(_footerDiv.getElement(), new MouseOverHandler()
|
---|
2463 | {
|
---|
2464 | public void onMouseOver(MouseOverEvent event)
|
---|
2465 | {
|
---|
2466 | Label item = (Label) event.getSource();
|
---|
2467 | item.getElement().getStyle().setProperty("background", "#0000FF");
|
---|
2468 | item.getElement().getStyle().setProperty("color", "#FFFFFF");
|
---|
2469 | if (_menuOutTimer != null)
|
---|
2470 | {
|
---|
2471 | _menuOutTimer.cancel();
|
---|
2472 | _menuOutTimer = null;
|
---|
2473 | }
|
---|
2474 | }
|
---|
2475 | }, new MouseOutHandler()
|
---|
2476 | {
|
---|
2477 | public void onMouseOut(MouseOutEvent event)
|
---|
2478 | {
|
---|
2479 | Label item = (Label) event.getSource();
|
---|
2480 | item.getElement().getStyle().setProperty("background", "#FFFFFF");
|
---|
2481 | item.getElement().getStyle().setProperty("color", "#000000");
|
---|
2482 |
|
---|
2483 | _menuOutTimer = new Timer()
|
---|
2484 | {
|
---|
2485 | public void run()
|
---|
2486 | {
|
---|
2487 | _currentDocumentMenu.hideMenu();
|
---|
2488 | }
|
---|
2489 | };
|
---|
2490 |
|
---|
2491 | _menuOutTimer.schedule(500);
|
---|
2492 | }
|
---|
2493 | });
|
---|
2494 |
|
---|
2495 | documentMenu.addChildMenu(placeMenu);
|
---|
2496 | placeMenu.addMenuItems(places);
|
---|
2497 | placeMenu.moveMenu(_currentDocumentMenu.getMenuDiv().getAbsoluteLeft() + _currentDocumentMenu.getMenuDiv().getOffsetWidth(), prevMenuItem.getMenuElement().getAbsoluteTop() + prevMenuItem.getMenuElement().getOffsetHeight() - 2);
|
---|
2498 | placeMenu.showMenu();
|
---|
2499 | }
|
---|
2500 | }){
|
---|
2501 | public boolean condition()
|
---|
2502 | {
|
---|
2503 | ArrayList<Place> matchingPlaces = new ArrayList<Place>();
|
---|
2504 |
|
---|
2505 | if(_currentPlaces == null || _currentPlaces.size() == 0)
|
---|
2506 | {
|
---|
2507 | return false;
|
---|
2508 | }
|
---|
2509 |
|
---|
2510 | for (Place p : _currentPlaces)
|
---|
2511 | {
|
---|
2512 | if (p.getName().equals(_selectedPlaceName))
|
---|
2513 | {
|
---|
2514 | matchingPlaces.add(p);
|
---|
2515 | }
|
---|
2516 | }
|
---|
2517 |
|
---|
2518 | if(matchingPlaces.size() > 1)
|
---|
2519 | {
|
---|
2520 | return true;
|
---|
2521 | }
|
---|
2522 | return false;
|
---|
2523 | }
|
---|
2524 | });
|
---|
2525 |
|
---|
2526 | documentMenu.addMenuItems(menuItems);
|
---|
2527 | documentMenu.hideMenu();
|
---|
2528 | _currentDocumentMenu = documentMenu;
|
---|
2529 | }
|
---|
2530 |
|
---|
2531 | public void startDocumentMouseOverTimer(final int x, final int y)
|
---|
2532 | {
|
---|
2533 | _documentMouseOverTimer = new Timer()
|
---|
2534 | {
|
---|
2535 | public void run()
|
---|
2536 | {
|
---|
2537 | _currentDocumentMenu.moveMenu(x, y);
|
---|
2538 | _currentDocumentMenu.showMenu();
|
---|
2539 |
|
---|
2540 | _documentMouseOverTimer = null;
|
---|
2541 | }
|
---|
2542 | };
|
---|
2543 |
|
---|
2544 | _documentMouseOverTimer.schedule(1000);
|
---|
2545 | }
|
---|
2546 |
|
---|
2547 | /**
|
---|
2548 | * Gets the document text element from the web page
|
---|
2549 | * @return the document text element
|
---|
2550 | */
|
---|
2551 | public Element getDocTextElement()
|
---|
2552 | {
|
---|
2553 | JsArray<Element> divs = getElementsByTagName("div");
|
---|
2554 |
|
---|
2555 | Element documentText = null;
|
---|
2556 | for (int i = 0; i < divs.length(); i++)
|
---|
2557 | {
|
---|
2558 | if (divs.get(i).getAttribute("class").equals("documenttext"))
|
---|
2559 | {
|
---|
2560 | documentText = divs.get(i);
|
---|
2561 | break;
|
---|
2562 | }
|
---|
2563 | }
|
---|
2564 |
|
---|
2565 | return documentText;
|
---|
2566 | }
|
---|
2567 |
|
---|
2568 | public void addElementsToSearchResults(ArrayList<ArrayList<Place>> places)
|
---|
2569 | {
|
---|
2570 | JsArray<Element> elements = getElementsByTagName("li");
|
---|
2571 | ArrayList<Element> listElements = new ArrayList<Element>();
|
---|
2572 |
|
---|
2573 | for (int i = 0; i < elements.length(); i++)
|
---|
2574 | {
|
---|
2575 | if (elements.get(i).getAttribute("class").equals("document"))
|
---|
2576 | {
|
---|
2577 | listElements.add(elements.get(i));
|
---|
2578 | }
|
---|
2579 | }
|
---|
2580 |
|
---|
2581 | for (int i = 0; i < listElements.size(); i++)
|
---|
2582 | {
|
---|
2583 | Element span = DOM.createSpan();
|
---|
2584 | listElements.get(i).insertBefore(span, listElements.get(i).getFirstChild());
|
---|
2585 | span.getStyle().setBackgroundColor(numToColour(i, listElements.size(), 100, 255));
|
---|
2586 | span.getStyle().setColor(numToColour(i, listElements.size(), 100, 255));
|
---|
2587 | span.setInnerText("...");
|
---|
2588 |
|
---|
2589 | Element checkBoxSpan = DOM.createSpan();
|
---|
2590 | listElements.get(i).insertBefore(checkBoxSpan, listElements.get(i).getFirstChild());
|
---|
2591 | checkBoxSpan.setId("Result" + i);
|
---|
2592 |
|
---|
2593 | CheckBox c = new CheckBox();
|
---|
2594 | c.setValue(true);
|
---|
2595 | c.addValueChangeHandler(new SearchResultsCheckBoxChangeHandler(i));
|
---|
2596 | RootPanel.get("Result" + i).add(c);
|
---|
2597 | }
|
---|
2598 | }
|
---|
2599 |
|
---|
2600 | public class SearchResultsCheckBoxChangeHandler implements ValueChangeHandler<Boolean>
|
---|
2601 | {
|
---|
2602 | int _index = -1;
|
---|
2603 |
|
---|
2604 | public SearchResultsCheckBoxChangeHandler(int index)
|
---|
2605 | {
|
---|
2606 | _index = index;
|
---|
2607 | }
|
---|
2608 |
|
---|
2609 | public void onValueChange(ValueChangeEvent<Boolean> event)
|
---|
2610 | {
|
---|
2611 | if (event.getValue())
|
---|
2612 | {
|
---|
2613 | _visiblePlaceSets.set(_index, true);
|
---|
2614 | }
|
---|
2615 | else
|
---|
2616 | {
|
---|
2617 | _visiblePlaceSets.set(_index, false);
|
---|
2618 | }
|
---|
2619 |
|
---|
2620 | _map.clearOverlays();
|
---|
2621 | displayMultiplePlaceSets();
|
---|
2622 | }
|
---|
2623 | }
|
---|
2624 |
|
---|
2625 | public class DocumentOverHandler implements MouseOverHandler
|
---|
2626 | {
|
---|
2627 | int _index = -1;
|
---|
2628 |
|
---|
2629 | public DocumentOverHandler(int index)
|
---|
2630 | {
|
---|
2631 | _index = index;
|
---|
2632 | }
|
---|
2633 |
|
---|
2634 | public void onMouseOver(MouseOverEvent event)
|
---|
2635 | {
|
---|
2636 | Label currentLabel = (Label) event.getSource();
|
---|
2637 | currentLabel.setStyleName("placeOver");
|
---|
2638 |
|
---|
2639 | startDocumentMouseOverTimer(event.getX() + currentLabel.getAbsoluteLeft(), event.getY() + currentLabel.getAbsoluteTop());
|
---|
2640 | }
|
---|
2641 | }
|
---|
2642 |
|
---|
2643 | public class PlaceMouseOverHandler implements MouseOverHandler
|
---|
2644 | {
|
---|
2645 | public void onMouseOver(MouseOverEvent event)
|
---|
2646 | {
|
---|
2647 | Label currentLabel = (Label) event.getSource();
|
---|
2648 | currentLabel.setStyleName("placeOver");
|
---|
2649 |
|
---|
2650 | _selectedPlaceName = currentLabel.getElement().getInnerText();
|
---|
2651 |
|
---|
2652 | startPlaceMouseOverTimer(event.getX() + currentLabel.getAbsoluteLeft(), event.getY() + currentLabel.getAbsoluteTop());
|
---|
2653 | }
|
---|
2654 | }
|
---|
2655 |
|
---|
2656 | public class PlaceMouseOutHandler implements MouseOutHandler
|
---|
2657 | {
|
---|
2658 | public void onMouseOut(MouseOutEvent event)
|
---|
2659 | {
|
---|
2660 | Label currentLabel = (Label) event.getSource();
|
---|
2661 | currentLabel.setStyleName("place");
|
---|
2662 |
|
---|
2663 | if (_placeMouseOverTimer != null)
|
---|
2664 | {
|
---|
2665 | _placeMouseOverTimer.cancel();
|
---|
2666 | _placeMouseOverTimer = null;
|
---|
2667 | }
|
---|
2668 | }
|
---|
2669 | }
|
---|
2670 |
|
---|
2671 | public class PlaceMouseUpHandler implements MouseUpHandler
|
---|
2672 | {
|
---|
2673 | public void onMouseUp(MouseUpEvent event)
|
---|
2674 | {
|
---|
2675 | Label currentLabel = (Label) event.getSource();
|
---|
2676 | currentLabel.setStyleName("place");
|
---|
2677 | if(event.getNativeButton() == NativeEvent.BUTTON_LEFT)
|
---|
2678 | {
|
---|
2679 | String placeName = currentLabel.getText();
|
---|
2680 | Place place = _chosenPlaces.get(placeName);
|
---|
2681 |
|
---|
2682 | if(place == null)
|
---|
2683 | {
|
---|
2684 | for(Place p : _currentPlaces)
|
---|
2685 | {
|
---|
2686 | if(p.getName().equals(placeName))
|
---|
2687 | {
|
---|
2688 | place = p;
|
---|
2689 | break;
|
---|
2690 | }
|
---|
2691 | }
|
---|
2692 | }
|
---|
2693 |
|
---|
2694 | if(place != null && place.getLatitude() != null && place.getLongitude() != null)
|
---|
2695 | {
|
---|
2696 | _map.setCenter(LatLng.newInstance(place.getLatitude(), place.getLongitude()));
|
---|
2697 | }
|
---|
2698 | }
|
---|
2699 | /*
|
---|
2700 | else if(event.getNativeButton() == NativeEvent.BUTTON_RIGHT)
|
---|
2701 | {
|
---|
2702 | _currentDocumentMenu.moveMenu(event.getX() + currentLabel.getAbsoluteLeft(), event.getY() + currentLabel.getAbsoluteTop());
|
---|
2703 | _currentDocumentMenu.showMenu();
|
---|
2704 | }
|
---|
2705 | */
|
---|
2706 | }
|
---|
2707 | }
|
---|
2708 |
|
---|
2709 | public void startPlaceMouseOverTimer(final int x, final int y)
|
---|
2710 | {
|
---|
2711 | _placeMouseOverTimer = new Timer()
|
---|
2712 | {
|
---|
2713 | public void run()
|
---|
2714 | {
|
---|
2715 | _currentDocumentMenu.refreshMenu();
|
---|
2716 | _currentDocumentMenu.moveMenu(x, y);
|
---|
2717 | _currentDocumentMenu.showMenu();
|
---|
2718 |
|
---|
2719 | _menuOverTimer = new Timer()
|
---|
2720 | {
|
---|
2721 | public void run()
|
---|
2722 | {
|
---|
2723 | _menuOverTimer = null;
|
---|
2724 | _currentDocumentMenu.hideMenu();
|
---|
2725 | }
|
---|
2726 | };
|
---|
2727 | _menuOverTimer.schedule(4000);
|
---|
2728 |
|
---|
2729 | _placeMouseOverTimer = null;
|
---|
2730 | }
|
---|
2731 | };
|
---|
2732 |
|
---|
2733 | _placeMouseOverTimer.schedule(1000);
|
---|
2734 | }
|
---|
2735 |
|
---|
2736 | public class FishEyeMouseMoveHandler implements MouseMoveHandler
|
---|
2737 | {
|
---|
2738 | public void onMouseMove(MouseMoveEvent e)
|
---|
2739 | {
|
---|
2740 | if (!_mouseEventPause)
|
---|
2741 | {
|
---|
2742 | _mouseEventPause = true;
|
---|
2743 | passMouseCoordsToFishEye(e.getY());
|
---|
2744 | Timer pauseTimer = new Timer()
|
---|
2745 | {
|
---|
2746 | public void run()
|
---|
2747 | {
|
---|
2748 | _mouseEventPause = false;
|
---|
2749 | }
|
---|
2750 | };
|
---|
2751 | pauseTimer.schedule(50);
|
---|
2752 | }
|
---|
2753 | }
|
---|
2754 | }
|
---|
2755 |
|
---|
2756 | /**
|
---|
2757 | * This class contains methods that initialise and control the spatial search controls present on the map during a spatial search
|
---|
2758 | */
|
---|
2759 | public class SpatialSearchControls extends CustomControl
|
---|
2760 | {
|
---|
2761 | /**
|
---|
2762 | * Inherited parent constructor
|
---|
2763 | */
|
---|
2764 | protected SpatialSearchControls(ControlPosition arg0)
|
---|
2765 | {
|
---|
2766 | super(arg0);
|
---|
2767 | }
|
---|
2768 |
|
---|
2769 | /**
|
---|
2770 | * Second inherited parent constructor
|
---|
2771 | */
|
---|
2772 | protected SpatialSearchControls(ControlPosition arg0, boolean arg1, boolean arg2)
|
---|
2773 | {
|
---|
2774 | super(arg0, arg1, arg2);
|
---|
2775 | }
|
---|
2776 |
|
---|
2777 | /**
|
---|
2778 | * Initialises the control buttons
|
---|
2779 | */
|
---|
2780 | protected Widget initialize(MapWidget map)
|
---|
2781 | {
|
---|
2782 | //Create the panel to store the buttons
|
---|
2783 | HorizontalPanel panel = new HorizontalPanel();
|
---|
2784 |
|
---|
2785 | //Create the button that clears the user's currently created points
|
---|
2786 | Button clearButton = new Button("Clear Points", new ClickHandler()
|
---|
2787 | {
|
---|
2788 | public void onClick(ClickEvent event)
|
---|
2789 | {
|
---|
2790 | _areaPoints.clear();
|
---|
2791 | _map.clearOverlays();
|
---|
2792 | }
|
---|
2793 | });
|
---|
2794 |
|
---|
2795 | //Create the button the performs the spatial search
|
---|
2796 | Button performSearch = new Button("Search Area", new ClickHandler()
|
---|
2797 | {
|
---|
2798 | public void onClick(ClickEvent event)
|
---|
2799 | {
|
---|
2800 | //If the users has marked less than 3 points on the map then we cannot perform a spatial search
|
---|
2801 | if (_areaPoints.size() < 3)
|
---|
2802 | {
|
---|
2803 | //Show an error message on the status bar
|
---|
2804 | _statusBar.removeUpdate("SpatialWarn");
|
---|
2805 | _statusBar.addUpdate("A minimum of 3 points is needed on the map to perform a spatial search", "SpatialWarn");
|
---|
2806 |
|
---|
2807 | //Remove the message after 5 seconds
|
---|
2808 | Timer warningRemoveTimer = new Timer()
|
---|
2809 | {
|
---|
2810 | public void run()
|
---|
2811 | {
|
---|
2812 | _statusBar.removeUpdate("SpatialWarn");
|
---|
2813 | }
|
---|
2814 | };
|
---|
2815 | warningRemoveTimer.schedule(5000);
|
---|
2816 |
|
---|
2817 | return;
|
---|
2818 | }
|
---|
2819 |
|
---|
2820 | ArrayList<Float[]> points = new ArrayList<Float[]>();
|
---|
2821 |
|
---|
2822 | //Turn the points into a list of float arrays
|
---|
2823 | for (LatLng point : _areaPoints)
|
---|
2824 | {
|
---|
2825 | points.add(new Float[] { (float) point.getLatitude(), (float) point.getLongitude() });
|
---|
2826 | }
|
---|
2827 |
|
---|
2828 | //Ask the server to perform the spatial search
|
---|
2829 | _findPlaceService.spatialSearch(points, getSpatialSearchCallback());
|
---|
2830 | }
|
---|
2831 | });
|
---|
2832 |
|
---|
2833 | //Add the two buttons to the panel
|
---|
2834 | panel.add(clearButton);
|
---|
2835 | panel.add(performSearch);
|
---|
2836 |
|
---|
2837 | return panel;
|
---|
2838 | }
|
---|
2839 |
|
---|
2840 | /**
|
---|
2841 | * Creates and returns the callback necessary to perform a spatial search on the server
|
---|
2842 | * @return the callback object
|
---|
2843 | */
|
---|
2844 | public AsyncCallback<ArrayList<String>> getSpatialSearchCallback()
|
---|
2845 | {
|
---|
2846 | return new AsyncCallback<ArrayList<String>>()
|
---|
2847 | {
|
---|
2848 | /**
|
---|
2849 | * If the call to the server failed then this is called
|
---|
2850 | * @see com.google.gwt.user.client.rpc.AsyncCallback#onFailure(java.lang.Throwable)
|
---|
2851 | */
|
---|
2852 | public void onFailure(Throwable arg0)
|
---|
2853 | {
|
---|
2854 | logToConsole("Spatial search FAIL!");
|
---|
2855 | }
|
---|
2856 |
|
---|
2857 | /**
|
---|
2858 | * If the call to the server succeeded then this is called
|
---|
2859 | * @param placeNames is the places found within the spatial search polygon
|
---|
2860 | */
|
---|
2861 | public void onSuccess(ArrayList<String> placeNames)
|
---|
2862 | {
|
---|
2863 | logToConsole("Spatial search Success!");
|
---|
2864 |
|
---|
2865 | //Create the query to pass to Greenstone
|
---|
2866 | StringBuffer query = new StringBuffer();
|
---|
2867 | for (int j = 0; j < placeNames.size() && j < 20; j++)
|
---|
2868 | {
|
---|
2869 | if (j == 0)
|
---|
2870 | {
|
---|
2871 | query.append(placeNames.get(j).replaceAll(" ", "+").replaceAll("-", "+"));
|
---|
2872 | }
|
---|
2873 | else
|
---|
2874 | {
|
---|
2875 | query.append("+" + placeNames.get(j).replaceAll(" ", "+").replaceAll("-", "+"));
|
---|
2876 | }
|
---|
2877 | }
|
---|
2878 |
|
---|
2879 | logToConsole("Query -> " + query);
|
---|
2880 | logToConsole("Collection -> " + _currentCollection);
|
---|
2881 |
|
---|
2882 | //Create an invisible form
|
---|
2883 | FormPanel form = new FormPanel();
|
---|
2884 | form.setAction(_GREENSTONEDEVURL);
|
---|
2885 | form.setMethod(FormPanel.METHOD_POST);
|
---|
2886 | form.getElement().setAttribute("target", "_self");
|
---|
2887 |
|
---|
2888 | VerticalPanel tempForm = new VerticalPanel();
|
---|
2889 | form.setWidget(tempForm);
|
---|
2890 |
|
---|
2891 | getElementsByTagName("body").get(0).appendChild(form.getElement());
|
---|
2892 |
|
---|
2893 | logToConsole("Adding hidden form elements");
|
---|
2894 |
|
---|
2895 | Hidden a = new Hidden("a", "q");
|
---|
2896 | tempForm.add(a);
|
---|
2897 | Hidden sa = new Hidden("sa");
|
---|
2898 | tempForm.add(sa);
|
---|
2899 | Hidden rt = new Hidden("rt", "rd");
|
---|
2900 | tempForm.add(rt);
|
---|
2901 | Hidden s = new Hidden("s", "TextQuery");
|
---|
2902 | tempForm.add(s);
|
---|
2903 | Hidden c = new Hidden("c", _currentCollection);
|
---|
2904 | tempForm.add(c);
|
---|
2905 | Hidden startPage = new Hidden("startPage", "1");
|
---|
2906 | tempForm.add(startPage);
|
---|
2907 | Hidden s1level = new Hidden("s1.level", "Sec");
|
---|
2908 | tempForm.add(s1level);
|
---|
2909 | Hidden s1case = new Hidden("s1.case", "1");
|
---|
2910 | tempForm.add(s1case);
|
---|
2911 | Hidden s1stem = new Hidden("s1.stem", "0");
|
---|
2912 | tempForm.add(s1stem);
|
---|
2913 | Hidden s1accent = new Hidden("s1.accent", "0");
|
---|
2914 | tempForm.add(s1accent);
|
---|
2915 | Hidden s1matchMode = new Hidden("s1.matchMode", "some");
|
---|
2916 | tempForm.add(s1matchMode);
|
---|
2917 | Hidden s1sort = new Hidden("s1.sortBy", "1");
|
---|
2918 | tempForm.add(s1sort);
|
---|
2919 | Hidden s1index = new Hidden("s1.index", "ZZ");
|
---|
2920 | tempForm.add(s1index);
|
---|
2921 | Hidden s1maxDocs = new Hidden("s1.maxDocs", "100");
|
---|
2922 | tempForm.add(s1maxDocs);
|
---|
2923 | Hidden s1query = new Hidden("s1.query", query.toString());
|
---|
2924 | tempForm.add(s1query);
|
---|
2925 |
|
---|
2926 | logToConsole("Submitting");
|
---|
2927 |
|
---|
2928 | form.submit();
|
---|
2929 |
|
---|
2930 | logToConsole("Loading results page");
|
---|
2931 |
|
---|
2932 | loadPageWithoutUrl();
|
---|
2933 | }
|
---|
2934 | };
|
---|
2935 | }
|
---|
2936 |
|
---|
2937 | public boolean isSelectable()
|
---|
2938 | {
|
---|
2939 | return false;
|
---|
2940 | }
|
---|
2941 | }
|
---|
2942 |
|
---|
2943 | public static FindPlaceServiceAsync getServerConnection()
|
---|
2944 | {
|
---|
2945 | return _findPlaceService;
|
---|
2946 | }
|
---|
2947 | } |
---|