PageRenderTime 43ms CodeModel.GetById 36ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/sample/src/main/java/ca/nanometrics/gflot/sample/client/GFlotSample.java

http://gflot2.googlecode.com/
Java | 95 lines | 75 code | 16 blank | 4 comment | 2 complexity | 15e541b45f1bd0720ffabf34d3f0905a MD5 | raw file
 1package ca.nanometrics.gflot.sample.client;
 2
 3import java.util.ArrayList;
 4import java.util.List;
 5
 6import com.google.gwt.core.client.EntryPoint;
 7import com.google.gwt.core.client.Scheduler;
 8import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 9import com.google.gwt.dom.client.Style.Unit;
10import com.google.gwt.event.logical.shared.SelectionEvent;
11import com.google.gwt.event.logical.shared.SelectionHandler;
12import com.google.gwt.user.client.DOM;
13import com.google.gwt.user.client.ui.RootLayoutPanel;
14import com.google.gwt.user.client.ui.SimpleLayoutPanel;
15import com.google.gwt.user.client.ui.TabLayoutPanel;
16import com.google.gwt.user.client.ui.Widget;
17
18public class GFlotSample
19    implements EntryPoint
20{
21    private TabLayoutPanel tabPanel;
22
23    private List<SimpleLayoutPanel> panels;
24
25    private List<GFlotExample> samples;
26
27    private void addExamples()
28    {
29        panels = new ArrayList<SimpleLayoutPanel>();
30        samples = new ArrayList<GFlotExample>();
31
32        addExample( new SimplePlotExample() );
33        addExample( new BarChartExample() );
34        addExample( new PlotWithInteractiveLegendExample() );
35        addExample( new PlotWithOverviewExample() );
36        addExample( new HoverExample() );
37        addExample( new SlidingWindowExample() );
38        addExample( new DecimationExample() );
39        addExample( new MarkingsExample() );
40        addExample( new ImageExample() );
41    }
42
43    private void addExample( GFlotExample example )
44    {
45        SimpleLayoutPanel panel = new SimpleLayoutPanel();
46        tabPanel.add( panel, example.getName() );
47        panels.add( panel );
48        samples.add( example );
49    }
50
51    public void onModuleLoad()
52    {
53        tabPanel = new TabLayoutPanel( 30, Unit.PX );
54
55        addExamples();
56
57        tabPanel.addSelectionHandler( new SelectionHandler<Integer>()
58        {
59            @Override
60            public void onSelection( SelectionEvent<Integer> event )
61            {
62                initSample( event.getSelectedItem() );
63            }
64        } );
65
66        RootLayoutPanel.get().add( tabPanel );
67
68        // selected by default
69        initSample( 0 );
70    }
71
72    private void initSample( final int index )
73    {
74        // deferred to prevent a bug where the axis are not correctly drawn
75        Scheduler.get().scheduleDeferred( new ScheduledCommand()
76        {
77            @Override
78            public void execute()
79            {
80                SimpleLayoutPanel panel = panels.get( index );
81                if ( null == panel.getWidget() )
82                {
83                    Widget sample = samples.get( index ).createExample();
84                    DOM.setStyleAttribute( sample.getElement(), "marginTop", "10px" );
85                    panel.setWidget( sample );
86
87                    // setting size to 100% to avoid a bug on IE6 and IE7 where the panel don't take all the space
88                    // available
89                    panel.setSize( "100%", "100%" );
90                }
91            }
92        } );
93    }
94
95}