view src/econnect/wp3_3/client/widgets/map/MapControl.java @ 68:8b58d9bc0bb6 trimmed_data

add functionality for additional tabular data from the description field (work in progress)
author Sebastian Kruse <skruse@mpiwg-berlin.mpg.de>
date Thu, 03 Jan 2013 18:43:28 +0100
parents cf06b77a8bbd
children
line wrap: on
line source

package econnect.wp3_3.client.widgets.map;

import com.google.gwt.user.client.ui.Image;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;

import econnect.wp3_3.client.core.StiConstants;

/**
 * Implementation of the MapControl element
*/
public class MapControl {

	/**
     * The corresponding map object 
    */
	private Map map;
	
	/**
     * The url of the corresponding image of this control, if it is activated 
    */
	private String activeImageURL;

	/**
     * The url of the corresponding image of this control, if it is deactivated 
    */
	private String deactiveImageURL;

	/**
     * The id of this control 
    */
	private String id;

	/**
     * The button object of a control 
    */
	private Image button;
	
    /**
     * Constructor for the map control element
     *
     * @param map object The corresponding map object
     * @param activeImageURL The url of the corresponding image of this control, if it is activated
     * @param deactiveImageURL The url of the corresponding image of this control, if it is activated
     * @param id The id of this control
     * @param title The title text for the button element
    */
	public MapControl( final Map map, String activeImageURL, String deactiveImageURL, final String id, String title ){
		
		this.map = map;
		this.activeImageURL = activeImageURL;
		this.deactiveImageURL = deactiveImageURL;
		this.id = id;
		
		final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class);		
		final MapControl control = this;
		this.button = new Image( this.deactiveImageURL );
		this.button.setTitle(title);
		this.button.addClickHandler(new ClickHandler() {
		      public void onClick(ClickEvent event) {
		    	  if( map.getActiveControl() != control ){
		    		  if( id == "add" ){
		    			  if( map.core.isMaximumReached() && !map.core.individualSet() ){
								map.core.alert(textConstants.maxDatasources());
								return;
							}	    			  
		    		  }
		    		  map.getActiveControl().deactivate();
		    		  activate();
		    	  }
		      }
	    });
		
	}
	
    /**
     * deactivates this map control
    */
	public void deactivate(){
		this.button.setUrl(this.deactiveImageURL);
		this.map.getJsMap().deactivate(this.id);
	}
	
    /**
     * activates this map control
    */
	public void activate(){
		this.button.setUrl(this.activeImageURL);
		this.map.getJsMap().activate(this.id);
		this.map.setActiveControl(this);
	}
	
    /**
     * Getter for the button-image of this control
     *
     * @return the actual image element
    */
	public Image getButton(){
		return this.button;
	}
	
}