 
 public class ColumnHeaderBarLayout extends LayoutBase
 {
-    //--------------------------------------------------------------------------
-    //
-    //  Constructor
-    //
-    //--------------------------------------------------------------------------
-    
     /**
      *  Constructor. 
      *  

    
    /**
     *  @private
     */
    private function get columnGap():Number
    {
        return gridDimensions ? gridDimensions.columnGap : 0;
    }
    
    /**
     *  @private
     *  The GridDimensions associated with this CHB.
     */
    private function get gridDimensions():GridDimensions
    {        
        return gridLayout ? gridLayout.gridDimensions : null;       
    }

    //---------------------------------------------------------------
    //
    //  Class methods
    //
    //---------------------------------------------------------------
    
    /**
     *  @private
     *  Used to connect this layout with the grid layout and to
     *  signal to this layout that it needs to update.
     */
    public function updateLayout(layout:GridLayout):void
    {
        gridLayout = layout;
            
        const layoutTarget:GroupBase = target;
        if (layoutTarget)
            layoutTarget.invalidateDisplayList();
    }
    
    //---------------------------------------------------------------
    //
    //  Overridden methods
    //
    //---------------------------------------------------------------

    /**
     *  @private
     */
    override public function measure():void
    {
        var totalWidth:Number = 0;
        var totalHeight:Number = 0;

        // loop through the elements
        var layoutTarget:GroupBase = target;
        if (!layoutTarget)
            return;
        
        var count:int = layoutTarget.numElements;
        for (var i:int = 0; i < count; i++)
        {
            var element:ILayoutElement = layoutTarget.getVirtualElementAt(i);
            
            // The element returned could still be null. Look at the typical 
            // element instead.
            if (!element)
                element = typicalLayoutElement;

            // Find the preferred sizes    
            var elementWidth:Number = element.getPreferredBoundsWidth();
            var elementHeight:Number = element.getPreferredBoundsHeight();
            
            totalWidth += elementWidth;
            totalHeight = Math.max(totalHeight, elementHeight);
        }
        if (count > 0)
            totalWidth += (count - 1) * columnGap;
        
        layoutTarget.measuredWidth = totalWidth;
        layoutTarget.measuredHeight = totalHeight;
        
        // Since we really can't fit the content in space any
        // smaller than this, set the measured minimum size
        // to be the same as the measured size.
        // If the container is clipping and scrolling, it will
        // ignore these limits and will still be able to 
        // shrink below them.
        layoutTarget.measuredMinWidth = totalWidth;
        layoutTarget.measuredMinHeight = totalHeight; 
        
        //trace("CHB.measure", totalWidth, totalHeight);
    }

    /**
     *  @private
     */
    override public function updateDisplayList(unscaledWidth:Number,
                                               unscaledHeight:Number):void
    {
        var maxHeight:Number = 0;
        
        var layoutTarget:GroupBase = target;
        if (!layoutTarget || !gridLayout)
            return;
        
        //trace("CHB.udl", unscaledWidth, unscaledHeight);
        
        oldVisibleColumnIndices = visibleColumnIndices;
        visibleColumnIndices = gridLayout.getVisibleColumnIndices();
        
        for each (var columnIndex:int in visibleColumnIndices)
        {
            var element:ILayoutElement = 
                layoutTarget.getVirtualElementAt(columnIndex);
            
            var gridColumn:GridColumn = 
                DataGroup(target).dataProvider.getItemAt(columnIndex) as GridColumn;

            var elementWidth:Number;
            var elementHeight:Number;            

            // FIXME (klin): hack here to force the borders of each header to overlap.
            elementWidth = gridDimensions.getColumnWidth(columnIndex) + 1;
            elementHeight = element.getPreferredBoundsHeight();
            
            element.setLayoutBoundsSize(elementWidth, elementHeight);
            
            // Position the element.
            // FIXME: can this be calculated from the width of each element
            // plus the columnGap? (but there is not a columnGap property)
            element.setLayoutBoundsPosition(gridDimensions.getCellX(0, columnIndex), 0);
            
            // Find maximum element extents.
            maxHeight = Math.max(maxHeight, elementHeight);
        }
                
        // Scrolling support - update the content size
        layoutTarget.setContentSize(gridDimensions.getContentWidth(), maxHeight);
        
        // ToDo(cframpto): refactor these methods so both GridLayout and
        // this layout can use them.
                
        // Now layout the separators between the headers.
     /*   visibleHeaderSeparators = gridLayout.layoutColumnHeaderSeparators(
                                                oldVisibleColumnIndices, 
                                                visibleColumnIndices, 
                                                visibleHeaderSeparators);*/
        
        oldVisibleColumnIndices.length = 0;
    }
    
}
}
    
    //--------------------------------------------------------------------------
    //
    //  Internal variables
    //
    //--------------------------------------------------------------------------
    
    /**
     *  @private
     *  Cached header renderer heights maintained by the measure() method.
     */
    private const rendererHeights:Array = new Array();
    
    /**
     *  @private
     *  Bounds of all currently visible header renderers.
     */
    private const visibleRenderersBounds:Rectangle = new Rectangle();
    
    /**
     *  @private
     *  The elements available for reuse aka the "free list".   Maps from an IFactory 
     *  to a list of the elements that have been allocated by that factory and then freed.   
     *  The list is represented by a Vector.<IVisualElement>.
     */
    private var freeElementMap:Dictionary = new Dictionary(); 
    
    /**
     *  @private
     *  Records the IFactory used to allocate a Element so that freeVisualElement()
     *  can find it again.
     */
    private var elementToFactoryMap:Dictionary = new Dictionary();
    
    //---------------------------------------------------------------
    //
    //  Overridden methods
    //
    //---------------------------------------------------------------
    
    /**
     *  @private
     */
