[Tynstep-svn] r11 - in trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client: . timeline timeline/data

ChrisBurrell at crosswire.org ChrisBurrell at crosswire.org
Tue Nov 3 15:32:02 MST 2009


Author: ChrisBurrell
Date: 2009-11-03 15:32:02 -0700 (Tue, 03 Nov 2009)
New Revision: 11

Added:
   trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/
   trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/
   trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/CommandLoadDataset.java
   trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/DatasetHandler.java
   trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/StonehengeRender.java
Log:


Added: trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/CommandLoadDataset.java
===================================================================
--- trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/CommandLoadDataset.java	                        (rev 0)
+++ trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/CommandLoadDataset.java	2009-11-03 22:32:02 UTC (rev 11)
@@ -0,0 +1,27 @@
+package com.tyndalehouse.step.web.client.timeline.data;
+
+import com.google.gwt.user.client.Command;
+import com.tyndalehouse.step.web.client.widgets.timeline.TimeLineWidget;
+import com.tyndalehouse.step.web.client.widgets.timeline.TimelineXMLHandler;
+
+
+public class CommandLoadDataset implements Command
+{
+	private TimelineXMLHandler handler = null;
+    private TimeLineWidget timeline = null;
+    private String dataSet = "";
+
+    public CommandLoadDataset(TimelineXMLHandler handler, TimeLineWidget timeline, String dataSet)
+    {
+        this.handler = handler;
+        this.timeline = timeline;
+        this.dataSet = dataSet;
+    }
+
+    public void execute()
+    {
+    	timeline.load(dataSet, handler);
+    	timeline.getTimeLine().addOnScrollEvent(0, handler);
+    }
+    
+}

Added: trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/DatasetHandler.java
===================================================================
--- trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/DatasetHandler.java	                        (rev 0)
+++ trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/DatasetHandler.java	2009-11-03 22:32:02 UTC (rev 11)
@@ -0,0 +1,170 @@
+package com.tyndalehouse.step.web.client.timeline.data;
+
+import java.util.Date;
+
+import com.allen_sauer.gwt.log.client.Log;
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.user.client.DeferredCommand;
+import com.tyndalehouse.step.web.client.widgets.timeline.TimeLineWidget;
+import com.tyndalehouse.step.web.client.widgets.timeline.TimelineXMLHandler;
+
+
+/**
+ * This class handles requesting and processing the data.
+ *  
+ * @author ajr
+ *
+ */
+public class DatasetHandler implements TimelineXMLHandler
+{
+	// Instance
+    private static DatasetHandler instance = null;
+
+    private TimeLineWidget widget;
+    
+    // 'Busy' popup display
+//    private BusyPopup popupBusy = null;
+    
+    
+    /**
+     * DatasetHandler
+     *
+     */
+    public DatasetHandler()
+    {
+        // Popup
+  //      popupBusy = new BusyPopup();
+    }
+
+    /**
+     * Singleton instance function
+     * 
+     * @return instance of Handler
+     */
+    public static DatasetHandler getInstance()
+    {
+        if (instance == null)
+        {
+            instance = new DatasetHandler();
+        }
+
+        return instance;
+    }
+
+    /**
+     * initialise
+     *
+     * <p>This function is called from the main app EntryPoint as it relies on
+     * graphical elements being instantiated prior to it's execution.</p>
+     * @param context
+     */
+    public void initialise(TimeLineWidget widget, String dataSet)
+    {
+    	
+    	this.widget = widget;
+    	
+        // ---------------------------------------------------------------
+        // Do async fetch
+        // ---------------------------------------------------------------
+        loadDataset(dataSet);
+    }
+
+    /**
+     * onCompletion
+     *
+     * @param responseText
+     * @param url
+     */
+	public void onCompletion(JavaScriptObject xml, String url) 
+	{
+        // ---------------------------------------------------------------
+        // Hide busy popup
+        // ---------------------------------------------------------------
+//        popupBusy.hide();
+        
+        // ---------------------------------------------------------------
+        // Process xml
+        // ---------------------------------------------------------------
+        processSimileData(xml, url);
+    }
+
+	public void onScroll(String minDate, String maxDate) {
+		Log.info("WOW! I was called! Amazing!" + minDate + " " + maxDate);
+		
+		//so the process will be
+		//1. determine whether the timeline has changed significantly
+		
+		//2. get the new data from the database if required
+		
+		//3. ensure that the data gets pushed back to the page, perhaps without duplicates!
+		
+		
+	}
+	
+    
+    /**
+     * Load xml data into eventsource for timeline
+     * 
+     * @param urlText
+     */
+    private void processTextData(String text)
+    {
+        // Load eventsource with returned xml
+        widget.getEventSource().loadXMLText(text);
+        
+        // We need to send a resize message to 'fix' the display window size.
+//        TimeLine.getMainPanel().onWindowResized(Window.getClientWidth(), Window.getClientHeight());
+    }
+	
+    /**
+     * Load xml data into eventsource for timeline
+     * 
+     * @param urlText
+     */
+    private void processSimileData(JavaScriptObject xml, String url)
+    {
+        // Load eventsource with returned xml
+        widget.getEventSource().load(xml, url);
+        
+        // We need to send a resize message to 'fix' the display window size.
+        //TODO: fix the display window size?
+        
+        //TimeLineTest.getMainPanel().onWindowResized(Window.getClientWidth(), Window.getClientHeight());
+    }
+    
+
+    /**
+     * Load dataset function
+     * 
+     * @param url
+     */
+    public void loadDataset(String url)
+    {
+    	// ---------------------------------------------------------------
+    	// This is an example of how to load text directly into timeline
+    	// event source
+    	// ---------------------------------------------------------------
+//    	String text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> <data> <event start=\"4000 BC\" end=\"3200 BC\" isDuration=\"true\" title=\"Winterbourne Stoke Long Barrow\" icon=\"../image/green-circle.png\" image=\"../image/Timeline_Logo_Thumb.png\"> </event> </data>";	
+//    	processTextData(text);
+    	
+        // ---------------------------------------------------------------
+    	// NOTE: You could check dataset cache at this point if you were
+    	// having to switch between lots of differents sets. The data
+    	// could be fetched from the cache instead of fetched through the
+    	// ajax mechanism.
+        // ---------------------------------------------------------------
+    	
+        // ---------------------------------------------------------------
+        // Open busy popup
+        // ---------------------------------------------------------------
+//        popupBusy.show();
+        
+        // ---------------------------------------------------------------
+        // Got to get ref to widget 
+        // ---------------------------------------------------------------
+        TimeLineWidget tline = widget;
+        
+        CommandLoadDataset command = new CommandLoadDataset(this, tline, url);
+        DeferredCommand.addCommand(command);
+    }
+}

Added: trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/StonehengeRender.java
===================================================================
--- trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/StonehengeRender.java	                        (rev 0)
+++ trunk/step-web-app/src/main/java/com/tyndalehouse/step/web/client/timeline/data/StonehengeRender.java	2009-11-03 22:32:02 UTC (rev 11)
@@ -0,0 +1,152 @@
+package com.tyndalehouse.step.web.client.timeline.data;
+
+import java.util.ArrayList;
+
+import com.tyndalehouse.step.web.client.widgets.timeline.BandInfo;
+import com.tyndalehouse.step.web.client.widgets.timeline.BandOptions;
+import com.tyndalehouse.step.web.client.widgets.timeline.DateTime;
+import com.tyndalehouse.step.web.client.widgets.timeline.EventSource;
+import com.tyndalehouse.step.web.client.widgets.timeline.HotZoneBandOptions;
+import com.tyndalehouse.step.web.client.widgets.timeline.ITimeLineRender;
+import com.tyndalehouse.step.web.client.widgets.timeline.PointHighlightDecorator;
+import com.tyndalehouse.step.web.client.widgets.timeline.PointHighlightDecoratorOptions;
+import com.tyndalehouse.step.web.client.widgets.timeline.SpanHighlightDecorator;
+import com.tyndalehouse.step.web.client.widgets.timeline.SpanHighlightDecoratorOptions;
+import com.tyndalehouse.step.web.client.widgets.timeline.Theme;
+import com.tyndalehouse.step.web.client.widgets.timeline.TimeLineWidget;
+
+
+/**
+ * Render timeline
+ * 
+ */
+public class StonehengeRender implements ITimeLineRender
+{
+    /**
+     * Create timeline custom elements.
+     * 
+     *@param widget Timeline rendered into this widget.
+     */
+    public void render(TimeLineWidget widget)
+    {
+    	ArrayList bandInfos = widget.getBandInfos();
+    	ArrayList bandHotZones = widget.getBandHotZones();
+    	ArrayList bandDecorators = widget.getBandDecorators();
+    	EventSource eventSource = widget.getEventSource();
+
+    	Theme theme = widget.getTheme();
+        theme.setEventLabelWidth(400);
+        
+        // ---------------------------------------------------------------
+        // HotZones, two events too close together so we are going to 
+        // 'stretch' the time along them to make the gap between them
+        // larger but still maintain the flow of time.
+        // ---------------------------------------------------------------
+        HotZoneBandOptions hotZone1Opts = HotZoneBandOptions.create();
+        hotZone1Opts.setStart("2280 BC");
+        hotZone1Opts.setEnd("1930 BC");
+        hotZone1Opts.setMagnify(2);
+        hotZone1Opts.setUnit(DateTime.CENTURY());
+        hotZone1Opts.setMultiple(2);
+        bandHotZones.add(hotZone1Opts);
+        
+        // ---------------------------------------------------------------
+        // Band Decorators
+        // ---------------------------------------------------------------
+        
+        // Phase 1
+        SpanHighlightDecoratorOptions phase1Opts = SpanHighlightDecoratorOptions.create();
+        phase1Opts.setStartDate("2900 BC");
+        phase1Opts.setEndDate("2700 BC");
+        phase1Opts.setColor("FFC080");
+        phase1Opts.setOpacity(50);
+        phase1Opts.setStartLabel("Phase");
+        phase1Opts.setEndLabel("");
+        phase1Opts.setTheme(theme);
+        SpanHighlightDecorator phase1decorator = SpanHighlightDecorator.create(phase1Opts);
+        bandDecorators.add(phase1decorator);        
+
+        // Phase 2
+        SpanHighlightDecoratorOptions phase2Opts = SpanHighlightDecoratorOptions.create();
+        phase2Opts.setStartDate("2900 BC");
+        phase2Opts.setEndDate("2400 BC");
+        phase2Opts.setColor("#FFC08F");
+        phase2Opts.setOpacity(50);
+        phase2Opts.setStartLabel("");
+        phase2Opts.setEndLabel("");
+        phase2Opts.setTheme(theme);
+        SpanHighlightDecorator phase2decorator = SpanHighlightDecorator.create(phase2Opts);
+        bandDecorators.add(phase2decorator);        
+
+        // Phase 3
+        SpanHighlightDecoratorOptions phase3Opts = SpanHighlightDecoratorOptions.create();
+        phase3Opts.setStartDate("2600 BC");
+        phase3Opts.setEndDate("1600 BC");
+        phase3Opts.setColor("#FFC000");
+        phase3Opts.setOpacity(50);
+        phase3Opts.setStartLabel("");
+        phase3Opts.setEndLabel("");
+        phase3Opts.setTheme(theme);
+        SpanHighlightDecorator phase3decorator = SpanHighlightDecorator.create(phase3Opts);
+        bandDecorators.add(phase3decorator);        
+        
+        PointHighlightDecoratorOptions startPointOpts = PointHighlightDecoratorOptions.create();
+        startPointOpts.setDate("4000 BC");
+        startPointOpts.setColor("#FFC080");
+        startPointOpts.setOpacity(50);
+        startPointOpts.setTheme(theme);
+        PointHighlightDecorator startPointDecorator = PointHighlightDecorator.create(startPointOpts); 
+        bandDecorators.add(startPointDecorator);
+        
+
+        PointHighlightDecoratorOptions endPointOpts = PointHighlightDecoratorOptions.create();
+        endPointOpts.setDate("1600 BC");
+        endPointOpts.setColor("#FFC080");
+        endPointOpts.setOpacity(50);
+        endPointOpts.setTheme(theme);
+        PointHighlightDecorator endPointDecorator = PointHighlightDecorator.create(endPointOpts); 
+        bandDecorators.add(endPointDecorator);
+        
+        // ---------------------------------------------------------------
+        // Bands
+        // ---------------------------------------------------------------
+        
+        BandOptions topOpts = BandOptions.create();
+        topOpts.setWidth("5%");
+        topOpts.setIntervalUnit(DateTime.CENTURY());
+        topOpts.setIntervalPixels(200);
+        topOpts.setShowEventText(false);
+        topOpts.setTheme(theme);
+        topOpts.setDate("3701 BC");
+
+        
+        BandInfo top = BandInfo.create(topOpts);
+        top.setDecorators(bandDecorators);
+        bandInfos.add(top);
+
+        // Bands
+        BandOptions bottomOpts = BandOptions.create();
+        bottomOpts.setWidth("95%");
+        bottomOpts.setTrackHeight(1.3f);
+        bottomOpts.setTrackGap(0.1f);
+        bottomOpts.setIntervalUnit(DateTime.CENTURY());
+        bottomOpts.setIntervalPixels(50);
+        bottomOpts.setShowEventText(true);
+        bottomOpts.setTheme(theme);
+        bottomOpts.setEventSource(eventSource);
+        bottomOpts.setDate("3701 BC");
+        bottomOpts.setZones(bandHotZones);
+        bottomOpts.setTimeZone(0);
+
+        BandInfo bottom = BandInfo.createHotZone(bottomOpts);
+        bottom.setDecorators(bandDecorators);
+        bandInfos.add(bottom);
+
+        bottom.setSyncWith(0);
+        bottom.setHighlight(true);
+        
+        
+    
+    }
+    
+}




More information about the Tynstep-svn mailing list