<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" styleName="plain" name="flex_amf3" viewSourceURL="srcview/index.html">
  
  <mx:Script>
    private var startRequestTime:Number;
    private var startRenderTime:Number;
    private var requestTime:Number = 0;
    private var renderTime:Number = 0;
  </mx:Script>
  
  <mx:RemoteObject id="ro" destination="census-ro" endpoint="http://www.jamesward.com/census/messagebroker/amf?id=flex_amf3&amp;gzip=true">
    <mx:result>
      startRenderTime = new Date().time;
      requestTime = startRenderTime - startRequestTime;
      dg.dataProvider = event.result;
    </mx:result>
  </mx:RemoteObject>
  
  <mx:Style>
    ScrollBar {
      upArrowSkin: ClassReference("WideScrollArrowSkin");
      downArrowSkin: ClassReference("WideScrollArrowSkin");
      thumbSkin: ClassReference("WideScrollThumbSkin");
      trackSkin: ClassReference("WideScrollTrackSkin");
    }
    
    ButtonBar {  
      buttonStyleName: "ButtonStyle";
    }
  
    .ButtonStyle {
      cornerRadius: 0;
    }
  </mx:Style>
  
  <mx:ToggleButtonBar id="bb" width="100%" fontSize="30" selectedIndex="-1">
    <mx:dataProvider>
      <mx:Array>
        <mx:Object label="2000 rows" data="2000"/>
        <mx:Object label="5000 rows" data="5000"/>
        <mx:Object label="20000 rows" data="20000"/>
      </mx:Array>
    </mx:dataProvider>
    <mx:itemClick>
      requestTime = 0;
      renderTime = 0;
      
      l.text = "Test Running...";
      
      dg.dataProvider = [];
    
      startRequestTime = new Date().time;
      ro.getElements(0, event.item.data);
    </mx:itemClick>
  </mx:ToggleButtonBar>
    
  <mx:Label id="l" fontSize="30"/>

  <mx:DataGrid id="dg" width="100%" height="100%" fontSize="20" headerHeight="50" rowHeight="30" liveScrolling="false" draggableColumns="false">
    <mx:updateComplete>
    <![CDATA[
      var now:Number = new Date().time;
      
      if ((requestTime != 0) && (renderTime == 0))
      {
        renderTime = now - startRenderTime;
        
        l.text = "Request Time = " + requestTime + "ms | Render Time = " + renderTime + "ms";
      }
    ]]>
    </mx:updateComplete>
    <mx:columns>
      <mx:DataGridColumn dataField="id"/>
      <mx:DataGridColumn dataField="age"/>
      <mx:DataGridColumn dataField="classOfWorker"/>
      <mx:DataGridColumn dataField="education"/>
      <mx:DataGridColumn dataField="maritalStatus"/>
      <mx:DataGridColumn dataField="race"/>
      <mx:DataGridColumn dataField="sex"/>
    </mx:columns>
  </mx:DataGrid>
  
</mx:Application>