view src/econnect/wp3_3/client/core/ApplicationGrid.java @ 86:ed444173aef0 trimmed_data

local CSV loading
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Thu, 07 Mar 2013 14:47:36 +0100
parents 050331208ad7
children 0327cffe65ec
line wrap: on
line source

package econnect.wp3_3.client.core;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.OptGroupElement;
import com.google.gwt.dom.client.OptionElement;
import com.google.gwt.dom.client.SelectElement;
import com.google.gwt.dom.client.Style.Position;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.VerticalAlign;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.RootPanel;

import econnect.wp3_3.client.widgets.map.Map;
import econnect.wp3_3.client.widgets.table.StiTable;
import econnect.wp3_3.client.widgets.timeplot.Timeplot;

/**
 * Implementation of the Main Grid of the application where all widgets except tables will be embedded
*/
public class ApplicationGrid extends Grid {
	
	/**
     * The Java map object 
    */
	private Map map;

	/**
     * The Java timeplot object 
    */
	private Timeplot plot;

	/**
     * The Javascript core object 
    */
	private StiCore core;

	/**
     * The Object that holds the history bar 
    */
	private MenuBar history;

	/**
     * The actual history index
    */
	private int historyIndex;

	/**
     * The list of history items
    */
	private ArrayList<MenuItem> historyItems;

	/**
     * The image representing the back button
    */
	private Image back;

	/**
     * The image representing the forward button 
    */
	private Image forward;
	
	/**
     * The logo image 
    */
	private Image logo;
	
	/**
     * The label image for the history 
    */
	private Image historyLabel;
	
	private int width;
	private Grid links;
	
	/**
     * Constructor for the main grid of the application
     *
     * @param core object to allow interaction with all javascript components
    */
	public ApplicationGrid( StiCore stiCore, StiTable table ){
		
		int minWidth = 800;
		int minHeight = 600;
		int ph = 112;
		
		int docWidth = Document.get().getClientWidth();
		
		int height = (new Double(Document.get().getClientHeight()*0.5+ph)).intValue();
		int width = (new Double(height*4/3)).intValue();
		
		if( height < minHeight ){
			height = minHeight;
			width = minWidth;
		}
		
		this.width = width;
		
		this.core = stiCore;
		this.historyItems = new ArrayList<MenuItem>();
		this.resize(5,2);
		this.setCellSpacing(0);
		this.setCellPadding(0);
		//this.getElement().getStyle().setPosition(Position.ABSOLUTE);
		//this.getElement().getStyle().setPropertyPx("left", (docWidth-width)/2);
		//this.getElement().getStyle().setPropertyPx("top", 120-39);
		//this.getElement().getStyle().setZIndex(1);
		this.getCellFormatter().getElement(2,1).setClassName("cellStyleTop");
		this.getCellFormatter().getElement(3,0).setClassName("cellStyleLeft");
		RootPanel.get("mainContainer").add(this);
		
		final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class);
		final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class);		

		final Grid headerGrid = new Grid(1,2);
		headerGrid.setWidth("100%");
				
		ArrayList<String> kmlLabels = new ArrayList<String>();
		ArrayList<Integer> kmlSources = new ArrayList<Integer>();
		ArrayList<Integer> kmlCategories = new ArrayList<Integer>();
		ArrayList<Integer> kmlLocations = new ArrayList<Integer>();
		
		//skruse: Fix for null values of kml* parameters
		//TODO: This should allow an unlimited number of kmls and not an arbitrary limited set!
		
		if( !(Window.Location.getParameter("kml1") == null) && !Window.Location.getParameter("kml1").equals("undefined") ){
			kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml1")));
			kmlSources.add(new Integer(Window.Location.getParameter("source1")));
			kmlCategories.add(new Integer(-1));
			kmlLocations.add(new Integer(-1));
		}
		if( !(Window.Location.getParameter("kml2") == null) && !Window.Location.getParameter("kml2").equals("undefined") ){
			kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml2")));
			kmlSources.add(new Integer(Window.Location.getParameter("source2")));
			kmlCategories.add(new Integer(-1));
			kmlLocations.add(new Integer(-1));
		}
		if( !(Window.Location.getParameter("kml3") == null) && !Window.Location.getParameter("kml3").equals("undefined") ){
			kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml3")));
			kmlSources.add(new Integer(Window.Location.getParameter("source3")));
			kmlCategories.add(new Integer(-1));
			kmlLocations.add(new Integer(-1));
		}
		if( !(Window.Location.getParameter("kml4") == null) && !Window.Location.getParameter("kml4").equals("undefined") ){
			kmlLabels.add(core.hexToAscii(Window.Location.getParameter("kml4")));
			kmlSources.add(new Integer(Window.Location.getParameter("source4")));
			kmlCategories.add(new Integer(-1));
			kmlLocations.add(new Integer(-1));
		}
		int sources = core.getDatasources();
		if( sources > 0 ){
			final TextBox searchField = new TextBox();
			final Image openButton = new Image(constants.openImage());
			openButton.getElement().addClassName("vCenter");
			final ListBox datasource = new ListBox(false);		
			final List<ListBox> staticListBoxes = new ArrayList<ListBox>();		
			final ArrayList<ArrayList<int[]>> entries = new ArrayList<ArrayList<int[]>>();
			final FileUpload uploadKML = new FileUpload();
			//skruse: The element will be accessed by its ID in the JS code
			//either don't change this name, or change it also in STICore.js
			uploadKML.getElement().setId("localKMLFileChooser");
			final FileUpload uploadCSV = new FileUpload();
			//skruse: The element will be accessed by its ID in the JS code
			//either don't change this name, or change it also in STICore.js
			uploadCSV.getElement().setId("localCSVFileChooser");
			for( int i=0; i<sources; i++ ){
				try {
					if( core.hasItems(i) ){
						try {
					        ListBox staticData = new ListBox();
					        SelectElement select = staticData.getElement().cast();
					        OptionElement blank = Document.get().createOptionElement();
			                blank.setInnerText("select set ...");
   					        select.appendChild(blank);
					        int categories = core.getCategories(i);
				        	ArrayList<int[]> values = new ArrayList<int[]>();
					        for( int j=0; j<categories; j++ ){
					        	try {
						            OptGroupElement group = Document.get().createOptGroupElement();
						            group.setLabel(core.getCategory(i,j));
						            for (int k=0; k<core.getItemCount(i,j); k++) {
						                OptionElement optElement = Document.get().createOptionElement();
						                optElement.setInnerText(core.getLabel(i,j,k));
						                for( int l=0; l<kmlLabels.size(); l++ ){
						                	if( kmlLabels.get(l).equals(core.getLabel(i,j,k)) ){
						                		kmlCategories.set(l,new Integer(j));
						                		kmlLocations.set(l,new Integer(k));
						                	}
						                }
						                group.appendChild(optElement);
						                int[] pair = {j,k};
						                values.add(pair);
						            }	
						            select.appendChild(group);				        		
					        	}
					        	catch( Exception e ){
					        		continue;
					        	}
					        }
					        entries.add(values);
					        staticListBoxes.add(staticData);					
						}
						catch( Exception e ){
							continue;
						}
					}
					else {
				        entries.add(null);
				        staticListBoxes.add(null);					
					}
					datasource.addItem(core.getDatasourceLabel(i));					
				}
				catch( Exception e ){
					continue;
				}
			}

		    if( datasource.getItemCount() > 0 ){
				final Grid openPanel = new Grid(1,3);
			    openPanel.setWidget(0, 0, datasource);
			    if( staticListBoxes.get(0) == null ){
		    		  openPanel.setWidget(0, 1, searchField);
			    }
			    else {
		    		  openPanel.setWidget(0, 1, staticListBoxes.get(0));
			    }
			    openPanel.setWidget(0, 2, openButton);
			    openPanel.addStyleName("center");
			    headerGrid.setWidget(0, 0, openPanel);

			    datasource.addChangeHandler(new ChangeHandler() {
				      public void onChange(ChangeEvent event) {
							int ds = datasource.getSelectedIndex();
							String label = datasource.getItemText(ds);
							
							if( ds == -1 ){
								return;
							}
							//skruse: test for local KML loading (e.g. useful for the downloaded KMLs)
							//TODO: if this remains in the code, the check below has
							//to be improved (some constant somewhere)
							if( label.equals("local KML") ){
								openPanel.setWidget(0, 1, uploadKML);
							}
							//skruse: test for local CSV loading
							//TODO: if this remains in the code, the check below has
							//to be improved (some constant somewhere)
							if( label.equals("local CSV") ){
								openPanel.setWidget(0, 1, uploadCSV);
							}
							else if( staticListBoxes.get(ds) == null ){
					    		  openPanel.setWidget(0, 1, searchField);
						    }
						    else {
					    		  openPanel.setWidget(0, 1, staticListBoxes.get(ds));
						    }
				      }
			    });
			    
			    class LoadDataHandler implements ClickHandler, KeyUpHandler {
					public void onClick(ClickEvent event) {
						openButton.setUrl(constants.openDisabledImage());
						loadData();
					}
					public void onKeyUp(KeyUpEvent event) {
						if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
							openButton.setUrl(constants.openDisabledImage());
							loadData();
						}
					}
					private void loadData() {
						int ds = datasource.getSelectedIndex();
						String label = datasource.getItemText(ds);

						if( core.isMaximumReached() ){
							core.alert(textConstants.maxDatasources());
						}
						else if( staticListBoxes.get(ds) != null ){
							if( staticListBoxes.get(ds).getSelectedIndex() > 0 ){
								int[] pair = entries.get(ds).get(staticListBoxes.get(ds).getSelectedIndex() - 1);
								core.openStaticKml(ds,pair[0],pair[1]);							
							}
						}
						//skruse: test for local KML loading (e.g. useful for the downloaded KMLs)
						//TODO: if this remains in the code, the check below has
						//to be improved (some constant somewhere)
						else if( (label.equals("local KML")) && (uploadKML.getFilename() != "") ){
							String fileName = uploadKML.getFilename();
							core.openLocalKml( ds, fileName );
						}
						//skruse: test for local CSV loading
						//TODO: if this remains in the code, the check below has
						//to be improved (some constant somewhere)
						else if( (label.equals("local CSV")) && (uploadCSV.getFilename() != "") ){
							String fileName = uploadCSV.getFilename();
							core.openLocalCsv( ds, fileName );
						}
						else if( !searchField.getText().equals("") ){
							core.openDynamicKml( ds, searchField.getText() );
						}
						openButton.setUrl(constants.openImage());
					}
				}

			    LoadDataHandler handler = new LoadDataHandler();
				openButton.addClickHandler(handler);
				searchField.addKeyUpHandler(handler);			
		    }
		    
		}		
				
		Grid historyGrid = new Grid(1,3);
		historyLabel = new Image(constants.historyImage());
		
		history = new MenuBar(true);
		history.setAnimationEnabled(true);
	    history.addStyleName("zHigh");	    
	    addHistoryItem(0);
	    historyGrid.setWidget(0, 1, historyLabel);
	    headerGrid.setWidget(0, 1, historyGrid);
	    		
		historyLabel.setTitle(textConstants.history());
		historyLabel.addClickHandler(new ClickHandler() {
		      public void onClick(ClickEvent event) {
		    	  if( !RootPanel.get("mainContainer").remove(history) ){
		    		  RootPanel.get("mainContainer").add(history,0,0);
		    		  historyLabel.setUrl(constants.historyOverImage());
		    		  int left = historyLabel.getAbsoluteLeft() + historyLabel.getOffsetWidth()/2 - history.getOffsetWidth()/2;
		    		  int top = historyLabel.getAbsoluteTop() + historyLabel.getOffsetHeight();		    		  
		    		  RootPanel.get("mainContainer").setWidgetPosition(history,left,top);
		    	  }
		    	  else {
		    		  historyLabel.setUrl(constants.historyImage());		    		  
		    	  }
		      }
		    });
		historyLabel.getElement().addClassName("vCenter");
		
		headerGrid.getCellFormatter().setHorizontalAlignment(0,0,HasHorizontalAlignment.ALIGN_LEFT);
		headerGrid.getCellFormatter().setHorizontalAlignment(0,1,HasHorizontalAlignment.ALIGN_RIGHT);
			    
	    back = new Image(constants.backwardDisabledImage());
	    back.getElement().addClassName("vCenter");
	    back.setTitle(textConstants.back());
	    forward = new Image(constants.forwardDisabledImage());
	    forward.getElement().addClassName("vCenter");
	    forward.setTitle(textConstants.forward());
	    historyGrid.setWidget(0, 0, back);		
	    historyGrid.setWidget(0, 2, forward);
	    
		back.addClickHandler(new ClickHandler() {
		      public void onClick(ClickEvent event) {
		      	if( historyIndex > 0 ){
		    	  core.switchThroughHistory(historyIndex-1);
		    	  historyIndex--;
		    	  setHistoryStyle(historyIndex+1,historyIndex);
		      	}
		      }
		    });		    	    

		forward.addClickHandler(new ClickHandler() {
		      public void onClick(ClickEvent event) {
		      	if( historyIndex < core.getHistoryLength()-1 ){
		    	  core.switchThroughHistory(historyIndex+1);
		    	  historyIndex++;
		    	  setHistoryStyle(historyIndex-1,historyIndex);
		      	}
		      }
		    });
	    
		this.setWidget(2, 1, headerGrid);
		
		Grid widgets = new Grid(2,1);
		this.setWidget(3, 1, widgets);
		widgets.setCellPadding(0);
		widgets.setCellSpacing(0);
		
		DivElement mapWindow = Document.get().createDivElement();
		mapWindow.setId("mapWindow");
		mapWindow.setClassName("mapWindow");
		mapWindow.getStyle().setPropertyPx("height", height-ph);
		mapWindow.getStyle().setPropertyPx("width", width);
		mapWindow.getStyle().setProperty("position", "relative");
		DivElement mapDiv = Document.get().createDivElement();
		mapDiv.setId("map");
		mapDiv.getStyle().setPropertyPx("height", height-ph);
		mapDiv.getStyle().setPropertyPx("width", width);
		//mapDiv.getStyle().setProperty("position", "absolute");
		mapWindow.appendChild(mapDiv);
		widgets.getCellFormatter().getElement(0,0).setInnerHTML(mapWindow.getString());
		this.map = new Map(core,"mapWindow","map");		
		
		DivElement plotWindow = Document.get().createDivElement();
		plotWindow.setId("plotWindow");
		plotWindow.getStyle().setPropertyPx("width", width);
		plotWindow.getStyle().setPropertyPx("height", ph);
		DivElement plotDiv = Document.get().createDivElement();
		plotDiv.setId("plot");
		plotDiv.getStyle().setPropertyPx("width", width);
		plotWindow.appendChild(plotDiv);
		widgets.getCellFormatter().getElement(1,0).setInnerHTML(plotWindow.getString());
		this.plot = new Timeplot(core,"plotWindow","plot");

		final Grid controls = new Grid(4,1);
		controls.setCellSpacing(0);
		controls.setCellPadding(0);
		controls.setWidth("100%");

		final Image mapControl = new Image(constants.globeImage());
		mapControl.setTitle(textConstants.mapControls());
		controls.setWidget(0, 0, mapControl);
		
		final Image plotControl = new Image(constants.timeImage());
		plotControl.setTitle(textConstants.plotControls());
		controls.setWidget(3, 0, plotControl);
		
		final Grid plotControls = this.plot.initPlotControls();
		final Grid mapControls = this.map.initMapControls();

		controls.setWidget(1, 0, mapControls);
		controls.setWidget(2, 0, plotControls);

		controls.getCellFormatter().getElement(0,0).getStyle().setHeight(25,Unit.PX);
		controls.getCellFormatter().getElement(1,0).getStyle().setVerticalAlign(VerticalAlign.TOP);
		controls.getCellFormatter().getElement(2,0).getStyle().setVerticalAlign(VerticalAlign.BOTTOM);
		controls.getCellFormatter().getElement(3,0).getStyle().setHeight(25,Unit.PX);
		this.getCellFormatter().setHorizontalAlignment(2,0,HasHorizontalAlignment.ALIGN_RIGHT);

		
		this.setWidget(3,0,controls);
		controls.setSize("100%",height+"px");

		// Increased to 8 by DARIAH-DE SUBGOE sfu
		Grid linkList = new Grid(1,8);

		this.logo = new Image(constants.logoImage());
		this.logo.addStyleName("logo");
		this.setWidget(0,0,this.logo);
		
		this.getCellFormatter().getElement(0,0).setAttribute("colspan", "2");
		this.getCellFormatter().getElement(0,1).removeFromParent();

		HTML informationLink = new HTML("&nbsp;e4D&nbsp;&ndash;&nbsp;Info");
		informationLink.setTitle("e4D&nbsp;-&nbsp;Info");
		informationLink.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=2", "_blank", "");
			}
		});
		informationLink.setStyleName("headerLink");
		linkList.setWidget(0, 0, informationLink);
		
		HTML helpLink = new HTML("&nbsp;Help");
		helpLink.setTitle("Help");
		helpLink.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=23", "_blank", "");
			}
		});
		helpLink.setStyleName("headerLink");
		
		
		HTML contactLink = new HTML("&nbsp;Contact");
		contactLink.setTitle("Contact");
		contactLink.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=4", "_blank", "");
			}
		});
		contactLink.setStyleName("headerLink");
		linkList.setWidget(0, 1, contactLink);
		
		HTML clearLink = new HTML("&nbsp;Clear Data");
		clearLink.setTitle("Clear Data");
		clearLink.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				// Changed to root URL for DARIAH-EU SUBGOE sfu
				// Window.Location.assign(Window.Location.getHref());
				Window.open("http://dev2.dariah.eu/e4d/", "_self", "");
			}
		});
		clearLink.setStyleName("headerLink");
		linkList.setWidget(0, 2, clearLink);
		
		HTML uploadLink = new HTML("&nbsp;Upload Data");
		uploadLink.setTitle("Upload Data");
		uploadLink.setStyleName("headerLink");
		uploadLink.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Window.open("http://wp1187670.wp212.webpack.hosteurope.de/e4d/?page_id=11", "_blank", "");
			}
		});
		linkList.setWidget(0, 3, uploadLink);

		// Newly inserted by DARIAH-DE SUBGOE sfu
		HTML dataSheetLink = new HTML("&nbsp;Data Editor");
		dataSheetLink.setTitle("Data Editor");
		dataSheetLink.addClickHandler(new ClickHandler(){
			public void onClick(ClickEvent event) {
				Window.open("http://ref.dariah.eu/workflow/", "_blank", "");
			}
		});
		dataSheetLink.setStyleName("headerLink");
		linkList.setWidget(0, 4, dataSheetLink);

		ClickHandler magneticClick = new ClickHandler(){
			public void onClick(ClickEvent event) {
				if( core.getDataSets().length() > 0 ){
					String link = Window.Location.getHref() + "?";
					for( int i=0; i<core.getDataSets().length(); i++ ){
						if( i>0 ){
							link += "\n&";
						}
						String name = core.getDataSets().get(i).getTermIdentifier();
						link += "kml"+(i+1)+"="+core.asciiToHex(name);
						link += "&source"+(i+1)+"="+core.getDataSets().get(i).getSource();
					}
					link += "\n&minTime=" + plot.getJsTimeplot().minTime();
					link += "&maxTime=" + plot.getJsTimeplot().maxTime();
					if( plot.getJsTimeplot().minSelTime() != null ){
						link += "\n&minSelTime=" + plot.getJsTimeplot().minSelTime();
						link += "&maxSelTime=" + plot.getJsTimeplot().maxSelTime();
					}
					link += "\n&mapId=" + map.getJsMap().baseLayerIndex();
					link += "&zoom=" + map.getJsMap().getZoom();
					link += "&centerLon=" + map.getJsMap().centerLon();
					link += "&centerLat=" + map.getJsMap().centerLat();
					link += "&connections=" + map.getJsMap().getConnections();
					Window.open(link,"_blank","");
					core.alert("e4D Magnetic Link opened in new tab!\n(Currently considered are: loaded datasets, map settings, temporal range, temporal selection)\n\n"+link);					
				}
				else {
					core.alert("Link could not be created; no datasets available.");
				}
			}			
		};

		HTML magneticLink = new HTML("&nbsp;Magnetic Link");
		magneticLink.setStyleName("headerLink");
		magneticLink.addClickHandler(magneticClick);
		linkList.setWidget(0, 5, magneticLink);
		
		Image link = new Image(constants.linkImage());
		link.addStyleName("link");
		link.setTitle("Create Magnetic Link");
		linkList.setWidget(0, 6, link);
		
		linkList.getElement().getStyle().setPosition(Position.ABSOLUTE);
		linkList.getElement().getStyle().setPropertyPx("right", 0);
		linkList.getElement().setPropertyString("align", "right");
		linkList.getElement().getStyle().setPropertyPx("top", 0);
		RootPanel.get("mainContainer").add(linkList);

		this.setWidget(1,1,linkList);
		this.links = linkList;
		
		link.addClickHandler(magneticClick);
		
		core.setElements( this.getMap().getJsMap(), this.getPlot().getJsTimeplot() );
		StiCore.exportStaticMethods(table,this,this.getPlot(),this.getMap());

		//table.setTop( 40 );
		table.setWidth("100%");
		
		for( int i=0; i<kmlLabels.size(); i++ ){
			if( kmlSources.get(i).intValue() == 0 && kmlCategories.get(i) > -1 ){
				core.openStaticKml(kmlSources.get(i), kmlCategories.get(i), kmlLocations.get(i));
			}
			else if( kmlSources.get(i).intValue() < 4 ){
				core.openDynamicKml(kmlSources.get(i),kmlLabels.get(i));
			}
			else {
				core.alert("Unable to load \""+kmlLabels.get(i)+"\"!");
			}
		}

		RootPanel.get("tableWindow").add(table);
		
		/*
		this.setWidget(4, 0, table);
		this.getCellFormatter().getElement(4,0).setAttribute("colspan", "2");
		this.getCellFormatter().getElement(4,1).removeFromParent();
		*/
	}
	
	public void setDefinedBounds(){
		int zoom = 0;
		float cLon = 0, cLat = 0;
		int mapId = 0;
		if( (Window.Location.getParameter("zoom") != null) && !Window.Location.getParameter("zoom").equals("undefined") ){
			zoom = new Integer(Window.Location.getParameter("zoom")).intValue();
		}
		if( (Window.Location.getParameter("centerLon") != null) && !Window.Location.getParameter("centerLon").equals("undefined") ){
			cLon = new Float(Window.Location.getParameter("centerLon")).floatValue();
		}
		if( (Window.Location.getParameter("centerLat") != null) && !Window.Location.getParameter("centerLat").equals("undefined") ){
			cLat = new Float(Window.Location.getParameter("centerLat")).floatValue();
		}
		if( (Window.Location.getParameter("mapId") != null) && !Window.Location.getParameter("mapId").equals("undefined") ){
			mapId = new Integer(Window.Location.getParameter("mapId")).intValue();
		}
		if( zoom != 0 || cLon != 0 || cLat != 0 || mapId != 0 ){
			this.getMap().getJsMap().configure(zoom, cLon, cLat, mapId);
		}
		String minSelTime = null, maxSelTime = null;
		if( (Window.Location.getParameter("minSelTime") != null) && !Window.Location.getParameter("minSelTime").equals("undefined") ){
			minSelTime = Window.Location.getParameter("minSelTime");
		}
		if( (Window.Location.getParameter("maxSelTime") != null) && !Window.Location.getParameter("maxSelTime").equals("undefined") ){
			maxSelTime = Window.Location.getParameter("maxSelTime");
		}
		if( minSelTime != null && maxSelTime != null ){
			this.getPlot().getJsTimeplot().selectTimerange(minSelTime,maxSelTime);
		}
		if( (Window.Location.getParameter("connections") != null) && !Window.Location.getParameter("connections").equals("undefined") ){
			int connections = new Integer(Window.Location.getParameter("connections")).intValue();
			if( connections == 1 ){
				this.getMap().getJsMap().setConnections(connections);
				this.getMap().setConImage(true);
			}
		}
		String minTime = null, maxTime = null;
		if( (Window.Location.getParameter("minTime") != null) && !Window.Location.getParameter("minTime").equals("undefined") ){
			minTime = Window.Location.getParameter("minTime");
		}
		if( (Window.Location.getParameter("maxTime") != null) && !Window.Location.getParameter("maxTime").equals("undefined") ){
			maxTime = Window.Location.getParameter("maxTime");
		}
		if( minTime != null && maxTime != null ){
			this.core.refineByTime(minTime,maxTime);
		}
	}
	/*
	public String asciiToHex(String text){
		String[] ascii = { "!","#","$","%","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]", " " };
		String[] hex = { "%21","%23","%24","$","%26","%27","%28","%29","%2a","%2b","%2c","%2f","%3a","%3b","%3d","%3f","%40","%5b","%5d","%20"};
		for( int i=0; i<ascii.length; i++ ){
			text = text.replaceAll(ascii[i],hex[i]);
		}
		text = text.replaceAll("$","%25");
		return text;
	}

	public String hexToAscii(String text){
		String[] ascii = { "!","#","$","%","&","'","(",")","*","+",",","/",":",";","=","?","@","[","]", " " };
		String[] hex = { "%21","%23","%24","%25","%26","%27","%28","%29","%2a","%2b","%2c","%2f","%3a","%3b","%3d","%3f","%40","%5b","%5d","%20"};
		for( int i=0; i<ascii.length; i++ ){
			text = text.replaceAll(hex[i],ascii[i]);
		}
		return text;
	}
	*/
	public void resize(){
		/*
		int w = Document.get().getClientWidth();
		RootPanel.get("mainContainer").setWidgetPosition(this.logo,(w-width)/2-40,8);		
		RootPanel.get("mainContainer").setWidgetPosition(this,(w-width)/2,120-39);
		int left = this.getElement().getOffsetLeft() + this.getElement().getOffsetWidth() - this.links.getElement().getOffsetWidth();
		RootPanel.get("mainContainer").setWidgetPosition(this.links,left,0);
		*/
	}
	
    /**
     * Sets the style of the history panel
     *
     * @param oldIndex last active history entry
     * @param newIndex actual active history entry
    */
	public void setHistoryStyle( int oldIndex, int newIndex ){
		final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class);
		if( oldIndex == -1 ){
			oldIndex = historyIndex;
		}
   	  	if( newIndex == core.getHistoryLength()-1 ){
		  	forward.setUrl(constants.forwardDisabledImage());
		}
		else {
		  	forward.setUrl(constants.forwardImage());
		}
		if( newIndex == 0 ){
		  	back.setUrl(constants.backwardDisabledImage());
	  	}
	  	else {
		  	back.setUrl(constants.backwardImage());
	  	}
		MenuItem oldItem = (MenuItem) historyItems.get(oldIndex);
		oldItem.setHTML( oldItem.getHTML().replaceFirst("bold","normal") ); 
		MenuItem newItem = (MenuItem) historyItems.get(newIndex);
		newItem.setHTML( newItem.getHTML().replaceFirst("normal","bold") ); 
	}

    /**
     * Adds an item to the history panel
     *
     * @param index index in the corresponding javascript array source
    */
	public void addHistoryItem( final int index ){
		final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class);		
		for( int i=historyItems.size(); i>index; i-- ){
			this.history.removeItem( (MenuItem) historyItems.get(i-1) );
			this.historyItems.remove(i-1);
		}
		String text = "<span style='font-weight:bold;'>";
		JsArray<DataSet> sets = core.getHistoryDataSets(index); 
		for( int j=0; j<sets.length(); j++ ){
			DataSet set = sets.get(j);
			text += set.getTermIdentifier();
			if( j+1 < sets.length() ){
				text += ", ";
			}
		}
		if( text.equals("<span style='font-weight:bold;'>") ){
			text += "empty";
		}
		else {
			text += " ("+(new Date()).toString()+")";
		}
		text += "</span>";
		MenuItem item = new MenuItem(text,true,new Command() {
		      public void execute() {
		    	  core.switchThroughHistory(index);
		    	  setHistoryStyle(-1,index);
		    	  historyIndex = index;
		    	  RootPanel.get("mainContainer").remove(history);
		    	  historyLabel.setUrl(constants.historyImage());
		      }
		});
		historyItems.add(item);
		this.history.addItem(item);
		historyIndex = index;
		if( index > 0 ){
			setHistoryStyle(index-1,index);
		}
	}
	
    /**
     * Getter for the Java timeplot element 
     *
     * @return the Java timeplot element
    */
	public Timeplot getPlot(){
		return this.plot;
	}	
	
    /**
     * Getter for the Java map element 
     *
     * @return the Java map element
    */
	public Map getMap(){
		return this.map;
	}

}