diff src/econnect/wp3_3/client/widgets/timeplot/Timeplot.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 diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/econnect/wp3_3/client/widgets/timeplot/Timeplot.java	Tue Jul 17 13:34:40 2012 +0000
@@ -0,0 +1,181 @@
+package econnect.wp3_3.client.widgets.timeplot;
+
+import com.google.gwt.user.client.ui.AbsolutePanel;
+import com.google.gwt.user.client.ui.Grid;
+import com.google.gwt.user.client.ui.Image;
+import com.google.gwt.user.client.ui.SimplePanel;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.DivElement;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+
+import econnect.wp3_3.client.slider.Slider;
+import econnect.wp3_3.client.core.ApplicationConstants;
+import econnect.wp3_3.client.core.StiConstants;
+import econnect.wp3_3.client.core.StiCore;
+import econnect.wp3_3.client.widgets.timeplot.StiTimeplot;
+
+/**
+ * Implementation of the Java component of the timeplot widget
+*/
+public class Timeplot {
+
+	/**
+     * The Javascript timeplot object 
+    */
+	private StiTimeplot jsTimeplot;
+
+	/**
+     * The slider component of the timeplot controls 
+    */
+	private Slider zoomSlider;
+	
+	/**
+     * The animation control image container 
+    */
+	private Image animation;
+
+	/**
+     * If animation is possible (selected time range)
+    */
+	private boolean enableAnimation = false;
+
+	/**
+     * Constructor for the timeplot widget java component
+     *
+     * @param core object to allow interaction with all javascript components
+     * @param window id of the window to embed the timeplot widget
+     * @param container id of the container, the window will be added
+    */
+	public Timeplot( StiCore core, String window, String container ){
+		this.jsTimeplot = StiTimeplot.createStiTimeplot(core, window, container);	    
+	}
+	
+    /**
+     * initializes the controls needed for timeplot interaction
+     *
+     * @return a grid of control elements
+    */
+	public Grid initPlotControls(){
+	    	    
+		final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class);
+		final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class);		
+
+		this.animation = new Image();
+		this.animation.setTitle(textConstants.animation0());
+		this.animation.setUrl(constants.playDisabled());
+		this.animation.addClickHandler(new ClickHandler() {
+		      public void onClick(ClickEvent event) {
+		    	  if( enableAnimation ){
+		    		  if( jsTimeplot.paused() ){
+			    		  jsTimeplot.play();
+		    		  }
+		    		  else {
+			    		  jsTimeplot.pause();
+		    		  }
+		    	  }
+		      }
+		    });
+		    
+	    final Grid controlGrid = new Grid(2,1);
+	    controlGrid.setWidget(0, 0, this.animation);
+
+	    DivElement zoomDiv = Document.get().createDivElement();
+	    zoomSlider = new Slider(zoomDiv,"vertical");
+	    zoomSlider.getSlider().setMaximum(100);
+	    zoomSlider.getSlider().setValue(0);
+	    zoomSlider.getSlider().addChangeListener(jsTimeplot,Document.get(),false);
+	    
+	    Image zoomIn = new Image(constants.zoomInImage());
+	    zoomIn.addClickHandler(new ClickHandler() {
+		      public void onClick(ClickEvent event) {
+			        jsTimeplot.zoom(1);
+			      }
+			    });
+	    Image zoomOut = new Image(constants.zoomOutImage());
+	    zoomOut.addClickHandler(new ClickHandler() {
+		      public void onClick(ClickEvent event) {
+			        jsTimeplot.zoom(-1);
+			      }
+			    });
+	    
+	    SimplePanel zoom = new SimplePanel();
+	    zoom.getElement().appendChild(zoomDiv);
+	    
+	    AbsolutePanel zoomPanel = new AbsolutePanel();	    
+	    zoomPanel.addStyleName("sliderStyle");
+	    zoomPanel.addStyleName("cellStyle");
+	    zoomPanel.addStyleName("center");
+	    zoomPanel.add(zoomIn,2,0);
+	    zoomPanel.add(zoom,0,10);
+	    zoomPanel.add(zoomOut,2,84);
+	    zoomIn.addStyleName("zHigh");
+	    zoomOut.addStyleName("zHigh");
+	    zoomPanel.setTitle(textConstants.plotZoom());
+	    
+	    controlGrid.setWidget(1, 0, zoomPanel);
+	    return controlGrid;
+		
+	}
+
+    /**
+     * changes images of animation controls
+    */
+	public void animationImage( boolean enable ){
+		final ApplicationConstants constants = (ApplicationConstants) GWT.create(ApplicationConstants.class);
+		final StiConstants textConstants = (StiConstants) GWT.create(StiConstants.class);
+		this.enableAnimation = enable;
+		if( enable ){
+			if( jsTimeplot.paused() ){
+	    		animation.setUrl(constants.playEnabled());
+	    		animation.setTitle(textConstants.animation1());
+	    	}
+			else {
+				animation.setUrl(constants.pauseEnabled());
+	    		animation.setTitle(textConstants.animation2());
+	    	}			
+		}
+		else {
+			animation.setUrl(constants.playDisabled());
+    		animation.setTitle(textConstants.animation0());
+		}
+	}
+	
+    /**
+     * sets zoom levels of corresponding zoom slider
+     *
+     * @param levels number of zoom levels
+    */
+	public void setZoomLevels( int levels ){
+	    zoomSlider.getSlider().setMaximum(levels);		
+	}
+	
+    /**
+     * sets value of corresponding zoom slider
+     *
+     * @param value value to set
+    */
+	public void setValue( int value ){
+	    zoomSlider.getSlider().setValue(value);		
+	}
+
+    /**
+     * Getter for the value of corresponding zoom slider
+     *
+     * @return actual zoom slider value
+    */
+	public int getValue(){
+	    return zoomSlider.getSlider().getValue();		
+	}
+
+    /**
+     * Getter for the corresponding Javascript component of the Timeplot
+     *
+     * @return the Javascript component of the Timeplot
+    */
+	public StiTimeplot getJsTimeplot(){
+		return this.jsTimeplot;
+	}
+
+}
\ No newline at end of file