public function __construct($attributes = array())
    {
        $this->afExtjs = afExtjs::getInstance();
        /**
         * deferredRender & layoutOnTabChange, for creating the layout of each tab after the tab is clicked
         */
        $this->attributes['deferredRender'] = false;
        //$this->attributes['forceLayout'] = true;
        $ah = array('autoHeight' => isset($attributes['tabHeight']) && $attributes['tabHeight'] ? false : true);
        $this->attributes['defaults'] = $this->afExtjs->asAnonymousClass(array_merge(array('iconCls' => '', 'icon' => '', 'bodyStyle' => 'padding:10px;', 'hideMode' => 'offsets', 'autoWidth' => true), $ah));
        $this->attributes['listeners']['tabchange'] = $this->afExtjs->asMethod(array('parameters' => 'tabPanel,tab', 'source' => "tabPanel.doLayout();"));
        /**
         * Tabs cheats for Ext 3
         */
        if (afExtjsLayout::getInstance()->getExtjsVersion() == 3) {
            $this->attributes['deferredRender']['onTabChange'] = true;
            $this->attributes['listeners']['render'] = $this->afExtjs->asMethod(array('parameters' => 'tabPanel', 'source' => '	
							                	tabPanel.getEl().mask("Rendering UI").setStyle({backgroundColor:"#dfe8f6"}).setOpacity(1);
								                tabPanel.setActiveTab(0);
								                while(true){								                		          	      		
								                	var tp = tabPanel.getActiveTab().nextSibling();								                	
								                	if(!tp) break;
								                	tabPanel.activate(tp);
								                }
								                tabPanel.setActiveTab(0);
								                tabPanel.getEl().unmask();
								               
							         		'));
        }
        if (count($attributes) > 0) {
            $this->attributes = array_merge($this->attributes, $attributes);
        }
        $this->checkIfSetting($this->attributes);
    }
 public function __construct($containerObject, $attributes = array())
 {
     $this->afExtjs = afExtjs::getInstance();
     $this->containerObject = $containerObject;
     if (count($this->attributes) > 0) {
         $attributes = array_merge($this->attributes, $attributes);
     }
     if (isset($attributes['icon'])) {
         $this->attributes['cls'] = 'x-btn-text-icon';
     }
     //print_r($attributes);
     if (isset($attributes['icon']) && isset($attributes['iconPosition'])) {
         if ($attributes['iconPosition'] == 'right') {
             $this->attributes['cls'] = 'x-btn-text-icon-right';
         } elseif ($attributes['iconPosition'] == 'left') {
             $this->attributes['cls'] = 'x-btn-text-icon';
         }
     }
     if (isset($attributes['state'])) {
         switch ($attributes['state']) {
             case "disabled":
                 $this->attributes['disabled'] = true;
                 break;
         }
         unset($attributes['state']);
     }
     if (isset($attributes['label'])) {
         $this->attributes['text'] = $attributes['label'];
         unset($attributes['label']);
     }
     if (isset($attributes['handlers']) && $attributes['handlers'] != '') {
         if (isset($this->attributes['listeners'])) {
             foreach ($this->attributes['listeners'] as $type => $type_params) {
                 /**
                  * if listener function source is not an array then the string is used directly
                  */
                 if (isset($type_params['parameters']) && $type_params['parameters'] != '' && isset($type_params['source']) && !is_array($type_params['source'])) {
                     $this->attributes['listeners'][$type] = array('parameters' => $type_params['parameters'], 'source' => $type_params['source'] . $attributes['handlers'][$type]['source']);
                 }
             }
         } else {
             $this->attributes['listeners'] = $attributes['handlers'];
         }
         unset($attributes['handlers']);
     }
     if (count($attributes) > 0) {
         $this->attributes = array_merge($this->attributes, $attributes);
     }
     //add the button to the container
     //to a object container
     if (is_object($containerObject)) {
         if (method_exists($this->containerObject, 'addButton')) {
             $this->containerObject->addButton($this);
         }
     } else {
         afExtjsLayout::getInstance()->attributes['viewport'][$containerObject . '_panel']['tbar'][] = $this->afExtjs->asVar($this->end());
     }
 }