All pastes #404556 Raw Edit

jwopitz pod

public text v1 · immutable
·published 2007-03-21 02:28 UTC
rendered paste body
package com.jwopitz.containers {
   
    import flash.events.MouseEvent;
   
    import mx.containers.Panel;
    import mx.controls.Button;
    import mx.core.EventPriority;
    import mx.core.IFlexDisplayObject ;
    import mx.core.UIComponent;
   
    [Bindable]
    public class Pod extends Panel {
       
        protected var _btns:Array = [];
       
        override protected function layoutChrome (unscaledWidth:Number, unscaledHeight:Number):void {
            super.layoutChrome(unscaledWidth, unscaledHeight);
           
            repositionButtons();
        }
       
        protected function repositionButtons ():void {
           
            var btn:Button;
            var tx:Number = 0; //target x value
            var px:Number = 0; //previous x value
            var ty:Number = 0; //target y value
           
            var i:int = 0;
            var l:int = _btns.length;
            if (l == 0)
                return;
           
            for (i; i < l; i++){
                btn = _btns[i] as Button;
                btn.setActualSize (btn.getExplicitOrMeasuredWidth(), btn.getExplicitOrMeasuredHeight());
               
                if (i == 0){
                    tx = unscaledWidth - borderMetrics.right - btn.getExplicitOrMeasuredWidth() - 10;
                } else {
                    tx = px - btn.getExplicitOrMeasuredWidth() - 5;
                }
               
                ty = (getHeaderHeight() - btn.getExplicitOrMeasuredHeight()) / 2;
               
                if (btn.x != tx || btn.y != ty)
                    btn.move(tx, ty);
               
                px = tx;
            }
        }
       
        public function addTitleBarButton (value:Button = null):Button {
            if (!value)
                value = new Button();
           
            value.addEventListener(MouseEvent.CLICK, onClick_titleBarButton, false, EventPriority.DEFAULT_HANDLER);
           
            _btns.push(value);
            titleBar.addChild(value);
           
            return value;
        }
       
        /**
         * TitleBar by default is setup to handle events as possible drag initiators while in popup modes. 
         * In order to override that default behavior, the evt must stop propogation and be handled in a different manner so as not to
         * trigger a possible drag action.
         */
        protected function onClick_titleBarButton (evt:MouseEvent):void {
            evt.stopPropagation();
        }
               
        public function get headerHeight ():Number {
            return getHeaderHeight();
        }
    }
}