Ignore:
Timestamp:
2011-04-15T13:38:25+12:00 (13 years ago)
Author:
sjm84
Message:

Committing most recent version of ATLAS

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  
    5252import com.google.gwt.user.client.ui.FlowPanel;
    5353import com.google.gwt.user.client.ui.FormPanel;
    54 import com.google.gwt.user.client.ui.Frame;
    5554import com.google.gwt.user.client.ui.HTML;
    5655import com.google.gwt.user.client.ui.Hidden;
     
    6160import com.google.gwt.user.client.ui.VerticalPanel;
    6261import com.google.gwt.user.client.ui.Widget;
     62import com.google.gwt.xml.client.NamedNodeMap;
     63import com.google.gwt.dom.client.Document;
    6364import com.google.gwt.dom.client.FormElement;
    6465import com.google.gwt.dom.client.InputElement;
    6566import com.google.gwt.dom.client.NativeEvent;
     67import com.google.gwt.dom.client.Node;
    6668import com.google.gwt.dom.client.NodeCollection;
    6769import com.google.gwt.dom.client.NodeList;
     
    8284    protected HorizontalPanel _viewPanel = new HorizontalPanel();
    8385
    84     protected Frame _gsTempFrame = new Frame();
    85 
    86     protected StatusBar _statusBar = new StatusBar();
     86    protected StatusBar _statusBar = null;
    8787
    8888    protected HTML _gsPanel = new HTML();
     
    120120    protected ArrayList<String> _highlightedPlaces = new ArrayList<String>();
    121121    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>();
    124122    protected ArrayList<Boolean> _visiblePlaceSets = new ArrayList<Boolean>();
    125123    protected ArrayList<LatLng> _areaPoints = new ArrayList<LatLng>();
    126 
     124    protected ArrayList<String> _removedPlaces = new ArrayList<String>();
     125   
    127126    protected ArrayList<ArrayList<Place>> _currentMultiPlaces = null;
    128     protected ArrayList<String> _removedPlaces = new ArrayList<String>();
    129127   
    130128    protected HashMap<String, Place> _chosenPlaces = new HashMap<String, Place>(); 
     
    160158    protected String _currentCollection = "";
    161159    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";
    163162    protected final String _GREENSTONEDEVURL = _GREENSTONEURL + "/dev";
    164163
     164    protected com.google.gwt.xml.client.Document _currentNewPageDoc;
     165
    165166    /**
    166167     * GWT module entry point
     
    168169    public void onModuleLoad()
    169170    {
     171        _statusBar = new StatusBar(this);
     172        //Make the Firebug console so that browsers that don't have it don't break
     173        setUpConsole();
     174       
    170175        //Get a Google geocoder to help find places that the Gazetteer does not know the coordinates for
    171176        _geocoder = new Geocoder();
    172177
    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       
    175181        //Setup native Javascript functions
    176182        setUpLoadPageFromUrl(this);
    177183        setUpLoadPageFromForm(this);
    178184        setUpLoadSpatialSearchPage(this);
    179 
     185       
    180186        //Setup the map
    181187        setUpMap();
    182188       
    183         //Make the Firebug console so that browsers that don't have it don't break
    184         setUpConsole();
    185 
    186         //Set up the invisible frame that temporarily stores pages as they load
    187         setUpTempFrame();
    188        
    189189        //Set up the list box that stores the text view options
    190190        setUpTextViewSelector();
    191191
    192192        //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");
    212194    }
    213195
     
    226208     * @param url is the url to load
    227209     */
    228     public void loadPageFromUrl(final String url)
     210    public void loadPageFromUrl(String url)
    229211    {
    230212        //Make sure a url was given
     
    261243        if (url.contains("&c="))
    262244        {
    263             //logToConsole("url contains collection");
    264245            //Store the collection name
    265246            _currentCollection = getCollectionFromURL(url);
     
    268249        //Add the "Page loading" update to the status bar"     
    269250        _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);
    277253    }
    278254   
     
    293269        //Add the "Page loading" update to the status bar"     
    294270        _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        }
    299307    }
    300308   
     
    357365            _spatialSearchClickHandler = null;
    358366        }
    359     }
    360    
    361     /**
    362      * Gets the timer than checks for when the pages is loaded and then loads the page
    363      * @param url is the url being loaded
    364      * @return the timer
    365      */
    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 yet
    375                 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 loaded
    383                 if (tempFrameGetElementById("banner") != null && tempFrameGetElementById("content") != null && tempFrameGetElementById("footer") != null)
    384                 {
    385                     this.cancel();
    386                     showLoadedPage();
    387                 }   
    388             }
    389         };
    390367    }
    391368   
     
    398375        if (!_initialised)
    399376        {
     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
    400392            //Fix webpage elements so that they point to the correct address
    401393            fixForms();
     
    403395            fixImages();
    404396           
    405             initialiseATLAS();
     397            Element newPageElem = getElementById("newpage");
     398            NodeList<com.google.gwt.dom.client.Element> divs = newPageElem.getElementsByTagName("div");
    406399           
    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            }
    419414           
    420415            //Swap the current banner with the new banner
    421             Element oldBanner = getElementById("banner");
    422             Element newBanner = tempFrameGetElementById("banner");
     416            Element oldBanner = getElementById("gs_banner");
    423417            oldBanner.getParentElement().removeChild(oldBanner);
    424418            _headerDiv.insert(HTML.wrap(newBanner), 0);
     
    433427
    434428            //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());
    436430        }
    437431
     
    444438        //The page has now finished being updated
    445439        _statusBar.removeUpdate("LoadPage");
    446 
    447         //Do an initial resize of the page elements
    448         Timer tempResizeTimer = new Timer()
    449         {
    450             public void run()
    451             {
    452                 resizeElements();
    453             }
    454         };
    455         tempResizeTimer.schedule(500);
    456440
    457441        //Check the document's text for places
     
    499483     */
    500484    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    {       
    525486        //Reload the page when the view type is changed
    526487        _textViewSelector.addChangeHandler(new ChangeHandler()
     
    530491                if (getDocTextElement() != null)
    531492                {
    532                     loadPageFromUrl(_gsTempFrame.getUrl());
     493                    loadPageFromUrl(_currentURL);
    533494                }
    534495            }
     
    544505        _viewPanel.add(_textViewSelector);
    545506        _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        }
    546543
    547544        // Add header
    548         _headerDiv.add(HTML.wrap(tempFrameGetElementById("banner")));
     545        //Node newHeader = importNode(newPage, tempFrameGetElementById("banner"), true);
     546        _headerDiv.add(HTML.wrap(headerElem));
    549547        _headerDiv.add(_viewPanel);
    550548        _headerDiv.setWidth("100%");
     
    558556
    559557        // 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);
    562560        _contentDiv.add(_gsPanel);
    563561        _contentDiv.add(_map);
    564562
    565563        // Add footer
    566         _footerDiv.add(HTML.wrap(tempFrameGetElementById("footer")));
     564        //Node newFooter = importNode(Document.get(), tempFrameGetElementById("footer"), true);
     565        _footerDiv.add(HTML.wrap(footerElem));
    567566        _footerDiv.setWidth("100%");
    568567        _footerDiv.getElement().setId("GSFooter");
     
    622621        //Get the response text
    623622        String text = response.getText();
    624 
     623       
    625624        //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)
    659643                    {
    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                        }
    681648                    }
    682649                   
     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();
    683686                    findPlacesInTexts(texts);
    684687                }
    685                 else
    686                 {
    687                     logToConsole("Still getting doc text...");
    688                 }
    689688            }
    690689        };
    691         docsReadyTimer.scheduleRepeating(2000);
     690        checkDoneTimer.scheduleRepeating(500);
    692691    }
    693692   
     
    696695     * @param texts is a list of texts from different documents
    697696     */
    698     private void findPlacesInTexts(ArrayList<String> texts)
     697    private void findPlacesInTexts(String[] texts)
    699698    {
    700699        logToConsole("Finished gettings doc text and gazetteer loaded!");
     
    785784
    786785                    //If this is not the first point then add a line between this and the previous point
    787                     logToConsole("Points array size = " + _areaPoints.size());
    788786                    if (_areaPoints.size() > 1)
    789787                    {
     
    792790
    793791                        Polyline line = new Polyline(new LatLng[] { point, _areaPoints.get(_areaPoints.size() - 2) }, "#FFFFFF", 3, 1, po);
    794                         logToConsole("Adding line");
    795792                        _map.addOverlay(line);
    796793                    }
     
    879876     */
    880877    public void changeCSSLinksAndScripts()
    881     {
     878    {       
    882879        //Get the head section of the HTML page
    883880        Element head = getDocumentHead();
     
    888885        //Get all of the <script> elements from the HTML header
    889886        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("/"))
    908996            {
    909997                e.setAttribute("href", _GREENSTONEURL + "/" + e.getAttribute("href"));
    910998            }
    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") + "');");
    9831001        }
    9841002    }
     
    9891007    public void fixImages()
    9901008    {
    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("/"))
    9961020            {
    9971021                e.setAttribute("src", _GREENSTONEURL + "/" + e.getAttribute("src"));
     
    11011125
    11021126    /**
     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    /**
    11031136     * Prints a given message to the Firebug console
    11041137     * @param msg is the message to print
     
    11061139    public static native void logToConsole(String msg)
    11071140    /*-{
    1108         console.log(msg);
     1141        //alert(msg);
     1142        //console.log(msg);
    11091143    }-*/;
    11101144
     
    11171151        return $doc.getElementsByTagName("head")[0];
    11181152    }-*/;
     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
    11191161
    11201162    /**
     
    11841226        //Get the width and height we want to use for the content div
    11851227        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);
    11871229
    11881230        //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;
    11921234        }
    11931235
     
    11971239       
    11981240        //Set the size of the content div
    1199         _contentDiv.setSize(cwidth + "px", (cheight + 50) + "px");
     1241        _contentDiv.setSize(cwidth + "px", cheight + "px");
    12001242       
    12011243        //Set up the style of the Greenstone panel
     
    12101252        if (_mapVisible && _gsVisible)
    12111253        {
    1212             _map.setSize((cwidth / 2 - 60) + "px", cheight + "px");
     1254            _map.setSize((cwidth / 2 - 60) + "px", (cheight - 25) + "px");
    12131255            _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");
    12151257        }
    12161258
     
    13171359
    13181360        //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       
    13211367        //Create the corner of the polygon
    13221368        LatLng tl = LatLng.newInstance(lat - size, lng + size);
     
    13291375        if (_highlightedPlaces.contains(p.getName()))
    13301376        {
    1331             newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF0000", 0.75);
     1377            newMarker = new Polygon(new LatLng[] { tl, tr, br, bl, tl }, borderColour, 1, 1, "#FF7F27", transparency);
    13321378        }
    13331379        //Otherwise make it the normal colour
    13341380        else
    13351381        {
    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);
    13371383        }
    13381384
     
    17491795            public void onFailure(Throwable caught)
    17501796            {
    1751                 logToConsole("Find multi places fail" + caught.getMessage());
     1797                alert("Find multi places fail" + caught.getMessage());
    17521798            }
    17531799
     
    17571803                _statusBar.addUpdate("Displaying places", "DisPlaces");
    17581804
    1759                 logToConsole("Find multi places success");
    17601805                _currentMultiPlaces = places;
    17611806                _visiblePlaceSets = new ArrayList<Boolean>();
     
    19191964                for (int j = 0; j < textPlaces.length(); j++)
    19201965                {
    1921                     logToConsole("Attempting to match " + textPlaces.get(j).getAttribute("class") + " with place");
    19221966                    if (textPlaces.get(j).getAttribute("class").equals("place"))
    19231967                    {
     
    20312075        logToConsole("Adding columns to panel");
    20322076
    2033         if (_contentDiv.getWidget(0).getElement().getId() == "content")
     2077        if (_contentDiv.getWidget(0).getElement().getId() == "gs_content")
    20342078        {
    20352079            VerticalPanel newDocTextPanel = new VerticalPanel();
     
    21292173            if (event.getY() < 125)
    21302174            {
    2131                 logToConsole("1");
    21322175                _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() + 25) + "px");
    21332176            }
    21342177            else
    21352178            {
    2136                 logToConsole("2");
    21372179                _columnViewBox.getElement().getStyle().setProperty("top", (event.getY() + _label.getAbsoluteTop() - 125) + "px");
    21382180            }
     
    28392881                    form.setWidget(tempForm);
    28402882
    2841                     tempFrameGetElementsByTagName("body").get(0).appendChild(form.getElement());
     2883                    getElementsByTagName("body").get(0).appendChild(form.getElement());
    28422884
    28432885                    logToConsole("Adding hidden form elements");
Note: See TracChangeset for help on using the changeset viewer.