/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

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