import java.util.*;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.VisualizationUtils;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.AnnotatedTimeLine;
import com.google.gwt.visualization.client.visualizations.AnnotatedTimeLine.ScaleType;
import com.smartgwt.client.widgets.layout.VLayout;


public class FlashTest implements EntryPoint {
  public void onModuleLoad() {
    Runnable onLoadCallback = new Runnable() {
        public void run() {
          AnnotatedTimeLine timeline = new AnnotatedTimeLine(createTable(),
                                                             createOptions(),
                                                             "1024px",
                                                             "768px");
          // Using SmartGwt
          VLayout layout = new VLayout();
          layout.addMember(timeline);
          layout.setWidth100();
          layout.setHeight100();
          layout.draw();

          // Using GWT
          // Panel panel = RootPanel.get();
          // panel.add(timeline);
        }
      };

    VisualizationUtils.loadVisualizationApi(onLoadCallback, AnnotatedTimeLine.PACKAGE);
  }

  private AnnotatedTimeLine.Options createOptions() {
    AnnotatedTimeLine.Options mapOptions = AnnotatedTimeLine.Options.create();
    mapOptions.setDisplayAnnotations(true);
    mapOptions.setDisplayAnnotationsFilter(true);
    mapOptions.setDisplayZoomButtons(false);
    mapOptions.setAllowHtml(true);
    mapOptions.setScaleColumns(0, 1, 2);
    mapOptions.setScaleType(ScaleType.ALLFIXED);
    mapOptions.setWindowMode(AnnotatedTimeLine.WindowMode.TRANSPARENT);
    return mapOptions;
  }

  private DataTable createTable() {
    DataTable data = DataTable.create();
    data.addColumn(ColumnType.DATE, "Date");
    data.addColumn(ColumnType.NUMBER, "Sold Pencils");
    data.addColumn(ColumnType.STRING, "title1");
    data.addColumn(ColumnType.STRING, "text1");
    data.addColumn(ColumnType.NUMBER, "Sold Pens");
    data.addColumn(ColumnType.STRING, "title2");
    data.addColumn(ColumnType.STRING, "text2");
    data.addRows(6);

    data.setValue(0, 0, new Date(2008, 1, 1));
    data.setValue(0, 1, 30000);
    data.setValue(0, 4, 40645);

    data.setValue(1, 0, new Date(2008, 1, 2));
    data.setValue(1, 1, 14045);
    data.setValue(1, 4, 20374);

    data.setValue(2, 0, new Date(2008, 1, 3));
    data.setValue(2, 1, 55022);
    data.setValue(2, 4, 50766);

    data.setValue(3, 0, new Date(2008, 1, 4));
    data.setValue(3, 1, 75284);
    data.setValue(3, 4, 14334);
    data.setValue(3, 5, "Out of Stock");
    data.setValue(3, 6, "Ran out of stock on pens at 4pm");

    data.setValue(4, 0, new Date(2008, 1, 5));
    data.setValue(4, 1, 41476);
    data.setValue(4, 2, "Bought Pens");
    data.setValue(4, 3, "Bought 200k pens");
    data.setValue(4, 4, 66467);

    data.setValue(5, 0, new Date(2008, 1, 6));
    data.setValue(5, 1, 33322);
    data.setValue(5, 4, 39463);

    return data;
  }
}
