view src/econnect/wp3_3/client/widgets/map/MapControl.java @ 3:cf06b77a8bbd

Committed branch of the e4D repos sti-gwt branch 16384. git-svn-id: http://dev.dariah.eu/svn/repos/eu.dariah.de/ap1/sti-gwt-dariah-geobrowser@36 f2b5be40-def6-11e0-8a09-b3c1cc336c6b
author StefanFunk <StefanFunk@f2b5be40-def6-11e0-8a09-b3c1cc336c6b>
date Tue, 17 Jul 2012 13:34:40 +0000
parents
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;
	}
	
}