Changeset 23906 for gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/GS3MapLibrary.java
- Timestamp:
- 2011-04-15T13:38:25+12:00 (13 years ago)
- Location:
- gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas
- Files:
-
- 1 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
gs3-extensions/atlas-src/trunk/src/org/greenstone/atlas/client/GS3MapLibrary.java
r22278 r23906 52 52 import com.google.gwt.user.client.ui.FlowPanel; 53 53 import com.google.gwt.user.client.ui.FormPanel; 54 import com.google.gwt.user.client.ui.Frame;55 54 import com.google.gwt.user.client.ui.HTML; 56 55 import com.google.gwt.user.client.ui.Hidden; … … 61 60 import com.google.gwt.user.client.ui.VerticalPanel; 62 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; 63 64 import com.google.gwt.dom.client.FormElement; 64 65 import com.google.gwt.dom.client.InputElement; 65 66 import com.google.gwt.dom.client.NativeEvent; 67 import com.google.gwt.dom.client.Node; 66 68 import com.google.gwt.dom.client.NodeCollection; 67 69 import com.google.gwt.dom.client.NodeList; … … 82 84 protected HorizontalPanel _viewPanel = new HorizontalPanel(); 83 85 84 protected Frame _gsTempFrame = new Frame(); 85 86 protected StatusBar _statusBar = new StatusBar(); 86 protected StatusBar _statusBar = null; 87 87 88 88 protected HTML _gsPanel = new HTML(); … … 120 120 protected ArrayList<String> _highlightedPlaces = new ArrayList<String>(); 121 121 protected ArrayList<String> _highlightedTextPlaces = new ArrayList<String>(); 122 protected ArrayList<com.google.gwt.dom.client.Element> _mainLinks = new ArrayList<com.google.gwt.dom.client.Element>();123 protected ArrayList<com.google.gwt.dom.client.Element> _mainScripts = new ArrayList<com.google.gwt.dom.client.Element>();124 122 protected ArrayList<Boolean> _visiblePlaceSets = new ArrayList<Boolean>(); 125 123 protected ArrayList<LatLng> _areaPoints = new ArrayList<LatLng>(); 126 124 protected ArrayList<String> _removedPlaces = new ArrayList<String>(); 125 127 126 protected ArrayList<ArrayList<Place>> _currentMultiPlaces = null; 128 protected ArrayList<String> _removedPlaces = new ArrayList<String>();129 127 130 128 protected HashMap<String, Place> _chosenPlaces = new HashMap<String, Place>(); … … 160 158 protected String _currentCollection = ""; 161 159 protected String _currentURL = ""; 162 protected final String _GREENSTONEURL = "http://localhost:8080/greenstone3"; 160 protected final String _GREENSTONEURL = "http://taniwha.resnet.scms.waikato.ac.nz:8080/greenstone3"; 161 //protected final String _GREENSTONEURL = "http://www.nzdl.org/atlasgreenstone3"; 163 162 protected final String _GREENSTONEDEVURL = _GREENSTONEURL + "/dev"; 164 163 164 protected com.google.gwt.xml.client.Document _currentNewPageDoc; 165 165 166 /** 166 167 * GWT module entry point … … 168 169 public void onModuleLoad() 169 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 170 175 //Get a Google geocoder to help find places that the Gazetteer does not know the coordinates for 171 176 _geocoder = new Geocoder(); 172 177 173 ((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://localhost:8080/GS3MapLibrary/gs3maplibrary/findPlace"); 174 178 ((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://taniwha.resnet.scms.waikato.ac.nz:8080/ATLAS/findPlace"); 179 //((ServiceDefTarget) _findPlaceService).setServiceEntryPoint("http://www.nzdl.org/ATLAS/findPlace"); 180 175 181 //Setup native Javascript functions 176 182 setUpLoadPageFromUrl(this); 177 183 setUpLoadPageFromForm(this); 178 184 setUpLoadSpatialSearchPage(this); 179 185 180 186 //Setup the map 181 187 setUpMap(); 182 188 183 //Make the Firebug console so that browsers that don't have it don't break184 setUpConsole();185 186 //Set up the invisible frame that temporarily stores pages as they load187 setUpTempFrame();188 189 189 //Set up the list box that stores the text view options 190 190 setUpTextViewSelector(); 191 191 192 192 //Load the Greenstone home page 193 loadPageFromUrl(_GREENSTONEDEVURL); 194 } 195 196 /** 197 * Sets up the invisible frame that temporarily stores pages as they load 198 */ 199 public void setUpTempFrame() 200 { 201 //Get the frame for the web page 202 _gsTempFrame.getElement().setId("tempFrame"); 203 204 //Make the frame have no size 205 _gsTempFrame.setSize("0px", "0px"); 206 207 //Make the frame have no border 208 _gsTempFrame.getElement().getStyle().setProperty("border", "0px"); 209 210 //Add the frame to the main frame 211 RootPanel.get("mainFrame").add(_gsTempFrame); 193 loadPageFromUrl("http://taniwha.resnet.scms.waikato.ac.nz:8080/greenstone3/dev?a=p&sa=home"); 212 194 } 213 195 … … 226 208 * @param url is the url to load 227 209 */ 228 public void loadPageFromUrl( finalString url)210 public void loadPageFromUrl(String url) 229 211 { 230 212 //Make sure a url was given … … 261 243 if (url.contains("&c=")) 262 244 { 263 //logToConsole("url contains collection");264 245 //Store the collection name 265 246 _currentCollection = getCollectionFromURL(url); … … 268 249 //Add the "Page loading" update to the status bar" 269 250 _statusBar.addUpdate("Loading new page", "LoadPage"); 270 271 //Start loading the given url 272 _gsTempFrame.setUrl(url); 273 274 //Create and start the timer that checks if the page is loaded 275 Timer _checkLoadedTimer = getLoadedTimer(); 276 _checkLoadedTimer.scheduleRepeating(500); 251 252 getNewPage(url); 277 253 } 278 254 … … 293 269 //Add the "Page loading" update to the status bar" 294 270 _statusBar.addUpdate("Loading new page", "LoadPage"); 295 296 //Create and start the timer that checks if the page is loaded 297 Timer _checkLoadedTimer = getLoadedTimer(); 298 _checkLoadedTimer.scheduleRepeating(500); 271 } 272 273 public void getNewPage(String url) 274 { 275 RequestBuilder newPageRequest = new RequestBuilder(RequestBuilder.GET, url.contains("?") ? (url + "&excerpttag=body") : (url + "?excerpttag=body")); 276 try{ 277 newPageRequest.sendRequest(null, new RequestCallback() 278 { 279 public void onResponseReceived(Request request, Response response) 280 { 281 if(response.getStatusCode() == Response.SC_OK) 282 { 283 HTML newPage = new HTML(response.getText()); 284 newPage.getElement().setId("newpage"); 285 Element oldNewPage = (Element) Document.get().getElementById("newpage"); 286 if(oldNewPage != null) 287 { 288 oldNewPage.removeFromParent(); 289 } 290 getElementsByTagName("body").get(0).appendChild(newPage.getElement()); 291 newPage.setVisible(false); 292 293 showLoadedPage(); 294 } 295 } 296 297 public void onError(Request request, Throwable exception) 298 { 299 alert("Problem loading new page -> " + exception.getMessage()); 300 } 301 }); 302 } 303 catch(Exception ex) 304 { 305 alert("Exception while creating the new page request -> " + ex.getMessage()); 306 } 299 307 } 300 308 … … 357 365 _spatialSearchClickHandler = null; 358 366 } 359 }360 361 /**362 * Gets the timer than checks for when the pages is loaded and then loads the page363 * @param url is the url being loaded364 * @return the timer365 */366 public Timer getLoadedTimer()367 {368 return new Timer()369 {370 int timercount = 0;371 372 public void run()373 {374 //Check to see if we should timeout yet375 if (timercount++ > 50)376 {377 logToConsole("Failed to load page after 50 attempts");378 this.cancel();379 return;380 }381 382 //Check to see if the page is loaded383 if (tempFrameGetElementById("banner") != null && tempFrameGetElementById("content") != null && tempFrameGetElementById("footer") != null)384 {385 this.cancel();386 showLoadedPage();387 }388 }389 };390 367 } 391 368 … … 398 375 if (!_initialised) 399 376 { 377 //Fix webpage elements so that they point to the correct address 378 fixForms(); 379 fixAnchors(); 380 fixImages(); 381 382 initialiseATLAS(); 383 384 //Add <link> and <script> elements to <head> 385 //changeCSSLinksAndScripts(); 386 } 387 else 388 { 389 //Add <link> and <script> elements to <head> 390 //changeCSSLinksAndScripts(); 391 400 392 //Fix webpage elements so that they point to the correct address 401 393 fixForms(); … … 403 395 fixImages(); 404 396 405 initialiseATLAS(); 397 Element newPageElem = getElementById("newpage"); 398 NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div"); 406 399 407 //Add <link> and <script> elements to <head> 408 changeCSSLinksAndScripts(); 409 } 410 else 411 { 412 //Add <link> and <script> elements to <head> 413 changeCSSLinksAndScripts(); 414 415 //Fix webpage elements so that they point to the correct address 416 fixForms(); 417 fixAnchors(); 418 fixImages(); 400 Element newBanner = null; 401 Element newContent = null; 402 403 for(int i = 0; i < divs.getLength(); i++) 404 { 405 if(divs.getItem(i).getId().equals("gs_banner")) 406 { 407 newBanner = (Element) divs.getItem(i); 408 } 409 else if(divs.getItem(i).getId().equals("gs_content")) 410 { 411 newContent = (Element) divs.getItem(i); 412 } 413 } 419 414 420 415 //Swap the current banner with the new banner 421 Element oldBanner = getElementById("banner"); 422 Element newBanner = tempFrameGetElementById("banner"); 416 Element oldBanner = getElementById("gs_banner"); 423 417 oldBanner.getParentElement().removeChild(oldBanner); 424 418 _headerDiv.insert(HTML.wrap(newBanner), 0); … … 433 427 434 428 //Swap the current Greenstone content with the new Greenstone content 435 _gsPanel.setHTML(HTML.wrap( tempFrameGetElementById("content")).getHTML());429 _gsPanel.setHTML(HTML.wrap(newContent).getHTML()); 436 430 } 437 431 … … 444 438 //The page has now finished being updated 445 439 _statusBar.removeUpdate("LoadPage"); 446 447 //Do an initial resize of the page elements448 Timer tempResizeTimer = new Timer()449 {450 public void run()451 {452 resizeElements();453 }454 };455 tempResizeTimer.schedule(500);456 440 457 441 //Check the document's text for places … … 499 483 */ 500 484 public void initialiseATLAS() 501 { 502 //Get the head section of the HTML page 503 Element head = getDocumentHead(); 504 505 //Get all of the <link> elements from the HTML header 506 logToConsole("Saving links"); 507 NodeList<com.google.gwt.dom.client.Element> linksToSave = head.getElementsByTagName("link"); 508 509 for(int i = 0; i < linksToSave.getLength(); i++) 510 { 511 logToConsole("Link save = " + linksToSave.getItem(i).getAttribute("href")); 512 _mainLinks.add(linksToSave.getItem(i)); 513 } 514 515 //Get all of the <script> elements from the HTML header 516 logToConsole("Saving scripts"); 517 NodeList<com.google.gwt.dom.client.Element> scriptsToSave = head.getElementsByTagName("script"); 518 519 for(int i = 0; i < scriptsToSave.getLength(); i++) 520 { 521 logToConsole("Script save = " + scriptsToSave.getItem(i).getAttribute("src")); 522 _mainScripts.add(scriptsToSave.getItem(i)); 523 } 524 485 { 525 486 //Reload the page when the view type is changed 526 487 _textViewSelector.addChangeHandler(new ChangeHandler() … … 530 491 if (getDocTextElement() != null) 531 492 { 532 loadPageFromUrl(_ gsTempFrame.getUrl());493 loadPageFromUrl(_currentURL); 533 494 } 534 495 } … … 544 505 _viewPanel.add(_textViewSelector); 545 506 _viewPanel.setVisible(false); 507 508 Element newPageElem = getElementById("newpage"); 509 NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div"); 510 511 Element headerElem = null; 512 Element bodyElem = null; 513 Element footerElem = null; 514 515 for(int i = 0; i < divs.getLength(); i++) 516 { 517 if(divs.getItem(i).getId().equals("gs_banner")) 518 { 519 headerElem = (Element) divs.getItem(i); 520 } 521 else if(divs.getItem(i).getId().equals("gs_content")) 522 { 523 bodyElem = (Element) divs.getItem(i); 524 } 525 else if(divs.getItem(i).getId().equals("gs_footer")) 526 { 527 footerElem = (Element) divs.getItem(i); 528 } 529 } 530 531 if(headerElem == null) 532 { 533 alert("header is null"); 534 } 535 if(bodyElem == null) 536 { 537 alert("body is null"); 538 } 539 if(footerElem == null) 540 { 541 alert("footer is null"); 542 } 546 543 547 544 // Add header 548 _headerDiv.add(HTML.wrap(tempFrameGetElementById("banner"))); 545 //Node newHeader = importNode(newPage, tempFrameGetElementById("banner"), true); 546 _headerDiv.add(HTML.wrap(headerElem)); 549 547 _headerDiv.add(_viewPanel); 550 548 _headerDiv.setWidth("100%"); … … 558 556 559 557 // Add content 560 Element contentElement = tempFrameGetElementById("content");561 _gsPanel = HTML.wrap( contentElement);558 //Node newContent = importNode(Document.get(), tempFrameGetElementById("content"), true); 559 _gsPanel = HTML.wrap(bodyElem); 562 560 _contentDiv.add(_gsPanel); 563 561 _contentDiv.add(_map); 564 562 565 563 // Add footer 566 _footerDiv.add(HTML.wrap(tempFrameGetElementById("footer"))); 564 //Node newFooter = importNode(Document.get(), tempFrameGetElementById("footer"), true); 565 _footerDiv.add(HTML.wrap(footerElem)); 567 566 _footerDiv.setWidth("100%"); 568 567 _footerDiv.getElement().setId("GSFooter"); … … 622 621 //Get the response text 623 622 String text = response.getText(); 624 623 625 624 //Get the hash codes for the documents 626 ArrayList<String> docURLs = getDocURLsFromResponse(text); 627 628 TemporaryFrame.setCurrentFrameIndex(getNumberOfFrames() - 1); 629 //Load each search result in a temporary frame 630 final ArrayList<TemporaryFrame> tempFrames = new ArrayList<TemporaryFrame>(); 631 for (int j = 0; j < docURLs.size(); j++) 632 { 633 //Create the url of the search result 634 String url = _GREENSTONEURL + "/" + docURLs.get(j); 635 636 //Create the temporary frame 637 TemporaryFrame currentFrame = new TemporaryFrame(url); 638 639 //Add the frame to the footer of the page 640 _footerDiv.add(currentFrame.getFrame()); 641 642 //Begin loading the page 643 currentFrame.loadPage(); 644 645 //Store the frame 646 tempFrames.add(currentFrame); 647 } 648 649 //Create a timer that periodically checks if all the frames have finished loading 650 Timer docsReadyTimer = new Timer() 651 { 652 public void run() 653 { 654 //Check to see if all of the frames have finished loading 655 boolean allDone = true; 656 for (int i = 0; i < tempFrames.size(); i++) 657 { 658 if (!tempFrames.get(i).isFinishedLoading()) 625 final ArrayList<String> docURLs = getDocURLsFromResponse(text); 626 final String[] texts = new String[docURLs.size()]; 627 628 for(int i = 0; i < texts.length; i++) 629 { 630 texts[i] = null; 631 } 632 633 for(int i = 0; i < docURLs.size(); i++) 634 { 635 String url = docURLs.get(i); 636 RequestBuilder xmlRequest = new RequestBuilder(RequestBuilder.GET, _GREENSTONEURL + "/" + (url.contains("?") ? (url + "&excerptid=gs-document-text") : (url + "?excerptid=gs-document-text"))); 637 try 638 { 639 final int index = i; 640 xmlRequest.sendRequest(null, new RequestCallback() 641 { 642 public void onResponseReceived(Request request, Response response) 659 643 { 660 logToConsole(i + " has NOT finished loading"); 661 allDone = false; 662 } 663 else 664 { 665 logToConsole(i + " has finished loading"); 666 } 667 } 668 669 //If all the frames have finished loading 670 if (allDone && _gazetteerLoaded) 671 { 672 this.cancel(); 673 674 //Get all of the texts from the frames 675 ArrayList<String> texts = new ArrayList<String>(); 676 while (tempFrames.size() > 0) 677 { 678 texts.add(tempFrames.get(0).getText()); 679 tempFrames.get(0).removeFromParent(); 680 tempFrames.remove(0); 644 if(response.getStatusCode() == Response.SC_OK) 645 { 646 texts[index] = response.getText(); 647 } 681 648 } 682 649 650 public void onError(Request request, Throwable exception) 651 { 652 alert("Exception requesting new page -> " + exception.getMessage()); 653 texts[index] = ""; 654 } 655 }); 656 } 657 catch(Exception ex) 658 { 659 alert("Exception requesting " + url + " -> " + ex.getMessage()); 660 } 661 } 662 663 Timer checkDoneTimer = new Timer() 664 { 665 int _count = 0; 666 667 public void run() 668 { 669 boolean done = true; 670 if(_count < 20) 671 { 672 for(int i = 0; i < texts.length; i++) 673 { 674 if(texts[i] == null) 675 { 676 done = false; 677 break; 678 } 679 } 680 } 681 _count++; 682 683 if(done) 684 { 685 this.cancel(); 683 686 findPlacesInTexts(texts); 684 687 } 685 else686 {687 logToConsole("Still getting doc text...");688 }689 688 } 690 689 }; 691 docsReadyTimer.scheduleRepeating(2000);690 checkDoneTimer.scheduleRepeating(500); 692 691 } 693 692 … … 696 695 * @param texts is a list of texts from different documents 697 696 */ 698 private void findPlacesInTexts( ArrayList<String>texts)697 private void findPlacesInTexts(String[] texts) 699 698 { 700 699 logToConsole("Finished gettings doc text and gazetteer loaded!"); … … 785 784 786 785 //If this is not the first point then add a line between this and the previous point 787 logToConsole("Points array size = " + _areaPoints.size());788 786 if (_areaPoints.size() > 1) 789 787 { … … 792 790 793 791 Polyline line = new Polyline(new LatLng[] { point, _areaPoints.get(_areaPoints.size() - 2) }, "#FFFFFF", 3, 1, po); 794 logToConsole("Adding line");795 792 _map.addOverlay(line); 796 793 } … … 879 876 */ 880 877 public void changeCSSLinksAndScripts() 881 { 878 { 882 879 //Get the head section of the HTML page 883 880 Element head = getDocumentHead(); … … 888 885 //Get all of the <script> elements from the HTML header 889 886 NodeList<com.google.gwt.dom.client.Element> currentScripts = head.getElementsByTagName("script"); 890 891 //Remove all of the old links on the page 892 for(int i = 0; i < currentLinks.getLength(); i++) 893 { 894 currentLinks.getItem(i).getParentElement().removeChild(currentLinks.getItem(i)); 895 } 896 897 //Remove all of the old scripts on the page 898 for(int i = 0; i < currentScripts.getLength(); i++) 899 { 900 currentScripts.getItem(i).getParentElement().removeChild(currentScripts.getItem(i)); 901 } 902 903 //Add the links present in every page 904 for (int i = 0; i < _mainLinks.size(); i++) 905 { 906 Element e = (Element) _mainLinks.get(i); 907 if(!e.getAttribute("href").startsWith("http://")) 887 888 //Add the new links 889 com.google.gwt.xml.client.NodeList newLinks = _currentNewPageDoc.getElementsByTagName("link"); 890 for (int i = 0; i < newLinks.getLength(); i++) 891 { 892 com.google.gwt.xml.client.Element e = (com.google.gwt.xml.client.Element) newLinks.item(i); 893 boolean found = false; 894 for(int j = 0; j < currentLinks.getLength(); j++) 895 { 896 Element elem = (Element) currentLinks.getItem(j); 897 if(e.getAttribute("href").equals(elem.getAttribute("href")) 898 && e.getAttribute("type").equals(elem.getAttribute("type")) 899 && e.getAttribute("rel").equals(elem.getAttribute("rel"))) 900 { 901 found = true; 902 } 903 } 904 905 if(!found) 906 { 907 Element newElem = DOM.createElement("link"); 908 909 NamedNodeMap map = e.getAttributes(); 910 for(int k = 0; k < e.getAttributes().getLength(); k++) 911 { 912 newElem.setAttribute(map.item(k).getNodeName(), map.item(k).getNodeValue()); 913 } 914 915 if(!newElem.getAttribute("href").startsWith("http://")) 916 { 917 newElem.setAttribute("href", _GREENSTONEURL + "/" + newElem.getAttribute("href")); 918 } 919 head.appendChild(newElem); 920 } 921 } 922 923 //Add the new scripts on the page 924 com.google.gwt.xml.client.NodeList newScripts = _currentNewPageDoc.getElementsByTagName("script"); 925 for (int i = 0; i < newScripts.getLength(); i++) 926 { 927 com.google.gwt.xml.client.Element e = (com.google.gwt.xml.client.Element) newScripts.item(i); 928 boolean found = false; 929 for(int j = 0; j < currentScripts.getLength(); j++) 930 { 931 Element elem = (Element) currentLinks.getItem(j); 932 if(e.getAttribute("src").equals(elem.getAttribute("src")) 933 && e.getAttribute("type").equals(elem.getAttribute("type")) 934 && e.getAttribute("charset").equals(elem.getAttribute("charset"))) 935 { 936 found = true; 937 } 938 } 939 940 if(!found) 941 { 942 Element newElem = DOM.createElement("link"); 943 944 NamedNodeMap map = e.getAttributes(); 945 for(int k = 0; k < e.getAttributes().getLength(); k++) 946 { 947 newElem.setAttribute(map.item(k).getNodeName(), map.item(k).getNodeValue()); 948 } 949 950 951 if(!e.getAttribute("src").startsWith("http://")) 952 { 953 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); 954 } 955 head.appendChild(newElem); 956 } 957 } 958 } 959 960 /** 961 * Go through each form on the page and add a javascript function in place of its action attribute 962 */ 963 public void fixForms() 964 { 965 NodeList<com.google.gwt.dom.client.Element> forms = getElementById("newpage").getElementsByTagName("form"); 966 for (int i = 0; i < forms.getLength(); i++) 967 { 968 Element e = (Element)forms.getItem(i); 969 e.setAttribute("id", "form" + i); 970 971 if(e.getAttribute("action").isEmpty()) 972 { 973 continue; 974 } 975 if (!e.getAttribute("action").startsWith("http://") && !e.getAttribute("action").startsWith("/")) 976 { 977 e.setAttribute("action", "javascript:loadPageFromFormJS(document.getElementById('form" + i + "'))"); 978 } 979 } 980 } 981 982 /** 983 * Go through each anchor on the page and add a javascript function in place of the href attribute 984 */ 985 public void fixAnchors() 986 { 987 NodeList<com.google.gwt.dom.client.Element> anchors = getElementById("newpage").getElementsByTagName("a"); 988 for (int i = 0; i < anchors.getLength(); i++) 989 { 990 Element e = (Element)anchors.getItem(i); 991 if(e.getAttribute("href").isEmpty()) 992 { 993 continue; 994 } 995 if (!e.getAttribute("href").startsWith("http://") && !e.getAttribute("href").startsWith("/")) 908 996 { 909 997 e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href")); 910 998 } 911 head.appendChild(e); 912 } 913 914 //Add the scripts present in every page 915 for (int i = 0; i < _mainScripts.size(); i++) 916 { 917 Element e = (Element) _mainScripts.get(i); 918 if(!e.getAttribute("src").startsWith("http://")) 919 { 920 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); 921 } 922 head.appendChild(e); 923 } 924 925 //Add the new links 926 JsArray<Element> newLinks = tempFrameGetElementsByTagName("link"); 927 for (int i = 0; i < newLinks.length(); i++) 928 { 929 Element e = newLinks.get(i); 930 if(!e.getAttribute("href").startsWith("http://")) 931 { 932 e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href")); 933 } 934 head.appendChild(e); 935 } 936 937 //Add the new scripts on the page 938 JsArray<Element> scripts = tempFrameGetElementsByTagName("script"); 939 for (int i = 0; i < scripts.length(); i++) 940 { 941 Element e = scripts.get(i); 942 if(!e.getAttribute("src").startsWith("http://")) 943 { 944 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); 945 } 946 head.appendChild(e); 947 } 948 } 949 950 /** 951 * Go through each form on the page and add a javascript function in place of its action attribute 952 */ 953 public void fixForms() 954 { 955 JsArray<Element> forms = tempFrameGetElementsByTagName("form"); 956 for (int i = 0; i < forms.length(); i++) 957 { 958 Element e = forms.get(i); 959 e.setAttribute("id", "form" + i); 960 961 if (!e.getAttribute("action").startsWith("http://")) 962 { 963 e.setAttribute("action", "javascript:loadPageFromFormJS(document.getElementById('form" + i + "'))"); 964 } 965 } 966 } 967 968 /** 969 * Go through each anchor on the page and add a javascript function in place of the href attribute 970 */ 971 public void fixAnchors() 972 { 973 JsArray<Element> anchors = tempFrameGetElementsByTagName("a"); 974 for (int i = 0; i < anchors.length(); i++) 975 { 976 Element e = anchors.get(i); 977 978 if (!e.getAttribute("href").startsWith("http://")) 979 { 980 e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href")); 981 e.setAttribute("onClick", "loadPageFromUrlJS('" + e.getAttribute("href") + "'); return false;"); 982 } 999 //e.setAttribute("onClick", "loadPageFromUrlJS('" + e.getAttribute("href") + "'); return false;"); 1000 e.setAttribute("href", "javascript:loadPageFromUrlJS('" + e.getAttribute("href") + "');"); 983 1001 } 984 1002 } … … 989 1007 public void fixImages() 990 1008 { 991 JsArray<Element> images = tempFrameGetElementsByTagName("img"); 992 for (int i = 0; i < images.length(); i++) 993 { 994 Element e = images.get(i); 995 if (!e.getAttribute("src").startsWith("http://")) 1009 NodeList<com.google.gwt.dom.client.Element> images = getElementById("newpage").getElementsByTagName("img"); 1010 for (int i = 0; i < images.getLength(); i++) 1011 { 1012 Element e = (Element)images.getItem(i); 1013 1014 if(e.getAttribute("src").isEmpty()) 1015 { 1016 continue; 1017 } 1018 1019 if (!e.getAttribute("src").startsWith("http://") && !e.getAttribute("src").startsWith("/")) 996 1020 { 997 1021 e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src")); … … 1101 1125 1102 1126 /** 1127 * Prints a given message to screen in a window 1128 * @param msg is the message to print 1129 */ 1130 public static native void alert(String msg) 1131 /*-{ 1132 alert(msg); 1133 }-*/; 1134 1135 /** 1103 1136 * Prints a given message to the Firebug console 1104 1137 * @param msg is the message to print … … 1106 1139 public static native void logToConsole(String msg) 1107 1140 /*-{ 1108 console.log(msg); 1141 //alert(msg); 1142 //console.log(msg); 1109 1143 }-*/; 1110 1144 … … 1117 1151 return $doc.getElementsByTagName("head")[0]; 1118 1152 }-*/; 1153 1154 /** 1155 * Patch GWT Document.importNode, which fails to return the imported nodes 1156 */ 1157 public static final native Node importNode(Document doc, Node node, boolean deep) /*-{ 1158 return doc.importNode(node, deep); 1159 }-*/; 1160 1119 1161 1120 1162 /** … … 1184 1226 //Get the width and height we want to use for the content div 1185 1227 int cwidth = Window.getClientWidth() - 45; 1186 int cheight = (int) (Window.getClientHeight() - _headerDiv.getOffsetHeight() - _footerDiv.getOffsetHeight() - 70);1228 int cheight = (int) (Window.getClientHeight() - _headerDiv.getOffsetHeight() - _footerDiv.getOffsetHeight() - _statusBar.getStatusBarDiv().getOffsetHeight() - 50); 1187 1229 1188 1230 //If the height is less than 300 then set it to 300 1189 if (cheight < 300)1190 { 1191 cheight = 300;1231 if (cheight < 200) 1232 { 1233 cheight = 200; 1192 1234 } 1193 1235 … … 1197 1239 1198 1240 //Set the size of the content div 1199 _contentDiv.setSize(cwidth + "px", (cheight + 50)+ "px");1241 _contentDiv.setSize(cwidth + "px", cheight + "px"); 1200 1242 1201 1243 //Set up the style of the Greenstone panel … … 1210 1252 if (_mapVisible && _gsVisible) 1211 1253 { 1212 _map.setSize((cwidth / 2 - 60) + "px", cheight+ "px");1254 _map.setSize((cwidth / 2 - 60) + "px", (cheight - 25) + "px"); 1213 1255 _map.getElement().getStyle().setProperty("left", (cwidth / 2 + 50) + "px"); 1214 _gsPanel.setSize((cwidth / 2) + "px", cheight+ "px");1256 _gsPanel.setSize((cwidth / 2) + "px", (cheight - 25) + "px"); 1215 1257 } 1216 1258 … … 1317 1359 1318 1360 //Work out the size of the new marker based on the current zoom level 1319 double size = 4.0 / (_map.getZoomLevel() * (_map.getZoomLevel() / 2)); 1320 1361 double zoomLevel = _map.getZoomLevel(); 1362 double size = (8.0 * Math.pow(2.0, -zoomLevel)) + (0.05 * (zoomLevel / 20.0)); 1363 1364 //Work out the transparency of the new marker based on the current zoom level 1365 double transparency = 0.8 * ((20.0 - zoomLevel) / 20.0); 1366 1321 1367 //Create the corner of the polygon 1322 1368 LatLng tl = LatLng.newInstance(lat - size, lng + size); … … 1329 1375 if (_highlightedPlaces.contains(p.getName())) 1330 1376 { 1331 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF 0000", 0.75);1377 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF7F27", transparency); 1332 1378 } 1333 1379 //Otherwise make it the normal colour 1334 1380 else 1335 1381 { 1336 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, fillColour, 0.75);1382 newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, fillColour, transparency); 1337 1383 } 1338 1384 … … 1749 1795 public void onFailure(Throwable caught) 1750 1796 { 1751 logToConsole("Find multi places fail" + caught.getMessage());1797 alert("Find multi places fail" + caught.getMessage()); 1752 1798 } 1753 1799 … … 1757 1803 _statusBar.addUpdate("Displaying places", "DisPlaces"); 1758 1804 1759 logToConsole("Find multi places success");1760 1805 _currentMultiPlaces = places; 1761 1806 _visiblePlaceSets = new ArrayList<Boolean>(); … … 1919 1964 for (int j = 0; j < textPlaces.length(); j++) 1920 1965 { 1921 logToConsole("Attempting to match " + textPlaces.get(j).getAttribute("class") + " with place");1922 1966 if (textPlaces.get(j).getAttribute("class").equals("place")) 1923 1967 { … … 2031 2075 logToConsole("Adding columns to panel"); 2032 2076 2033 if (_contentDiv.getWidget(0).getElement().getId() == " content")2077 if (_contentDiv.getWidget(0).getElement().getId() == "gs_content") 2034 2078 { 2035 2079 VerticalPanel newDocTextPanel = new VerticalPanel(); … … 2129 2173 if (event.getY() < 125) 2130 2174 { 2131 logToConsole("1");2132 2175 _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() + 25) + "px"); 2133 2176 } 2134 2177 else 2135 2178 { 2136 logToConsole("2");2137 2179 _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() - 125) + "px"); 2138 2180 } … … 2839 2881 form.setWidget(tempForm); 2840 2882 2841 tempFrameGetElementsByTagName("body").get(0).appendChild(form.getElement());2883 getElementsByTagName("body").get(0).appendChild(form.getElement()); 2842 2884 2843 2885 logToConsole("Adding hidden form elements");
Note:
See TracChangeset
for help on using the changeset viewer.