package
{
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    import net.hires.debug.Stats;
    
    import org.openPyro.aurora.AuroraScrollBarSkin;
    import org.openPyro.controls.ScrollBar;
    import org.openPyro.controls.events.ScrollEvent;
    import org.openPyro.core.ClassFactory;
    import org.openPyro.core.Direction;
    import org.openpyro.controls.DefaultRenderer;
    import org.openpyro.controls.OptimizedList;

    SWF"33")]
    public class EfficientList extends Sprite
    {
        public function EfficientList()
        {
            stage.scaleMode = "noScale"
            stage.align = "TL";
            
            // Create the data provider
            var dp:Array = new Array();
            for(var i:int = 0; i<200; i++){
                dp.push("data_"+i);
            }
            
            // Create a new List 
            var list:OptimizedList = new OptimizedList();
            list.dataProvider = dp;
            var rendererFactory:ClassFactory = new ClassFactory(DefaultRenderer);
            rendererFactory.properties = {width:240, height:50};
            list.itemRenderer = rendererFactory;
            
            // Create the scrollBar
            var scrollBar:ScrollBar = new ScrollBar(Direction.VERTICAL);
            scrollBar.height = 200;
            scrollBar.width = 15;
            addChild(scrollBar);
            var skin:AuroraScrollBarSkin = new AuroraScrollBarSkin();
            skin.direction = Direction.VERTICAL;
            scrollBar.skin = skin
            scrollBar.x = 300;
            scrollBar.y = 60;
            scrollBar.maximum = 1;
            
            // Set the Scrollbar as the verticalScrollbar for the list
            list.verticalScrollBar = scrollBar;
            
            // Create the Stats monitor
            var s:Stats = new Stats();
            addChild(s);
            s.x = scrollBar.x+40;
            s.y = scrollBar.y;
            
            // log window
            var txt:TextField = new TextField();
            txt.defaultTextFormat = new TextFormat("Arial", 12);
            addChild(txt);
            txt.width = 200;
            txt.height = 400;
            txt.x=scrollBar.x+40;
            txt.y = s.y+s.height+20;
            
            scrollBar.addEventListener(ScrollEvent.SCROLL, function(event:ScrollEvent):void{
                var s:String = "";
                s += "Scroll value: "+String(scrollBar.value)+"\n";
                s += "Free Renderers: "+String(list.rendererPool.availableObjects.length)+"\n";
                s += "Used Renderers: "+String(list.rendererPool.populatedObjects.length)+"\n";
                txt.text = s;
                
            })
            
            list.setSize(240, 320);
            addChild(list);
            list.x = 20;
            list.y = 60;
            
            
        }
    }
}