// Copyright (c) 2009 Cloud.tv // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. package cloudtv.components { import mx.controls.Tree; public class IconTree extends Tree { public function IconTree() { super(); } /** * @private */ override public function itemToIcon(item:Object):Class { if (item == null) { return null; } var icon:*; var open:Boolean = isItemOpen(item); var branch:Boolean = isBranch(item); var uid:String = itemToUID(item); //first lets check the component var iconClass:Class = itemIcons && itemIcons[uid] ? itemIcons[uid][open ? "iconID2" : "iconID"] : null; // put precident of object and xml over if (item is XML){ try{ if(item[iconField].length() != 0){ icon = String(item[iconField]); } } catch(e:Error) {} }else if (item is Object){ try{ if(iconField && item[iconField]){ icon = item[iconField]; } else if(item.icon){ icon = item.icon; } } catch(e:Error) {} } if(icon == null){ if (iconClass){ return iconClass; }else if (iconFunction != null){ return iconFunction(item) }else if (branch){ return getStyle(open ? "folderOpenIcon" : "folderClosedIcon"); } else { /* xml object check used to bed here */ } } //set default leaf icon if nothing else was found if (icon == null) icon = getStyle("defaultLeafIcon"); //convert to the correct type and class if (icon is Class){ return icon; } else if (icon is String){ iconClass = Class(systemManager.getDefinitionByName(String(icon))); if (iconClass) return iconClass; return document[icon]; } else{ return Class(icon); } } /** * @private * Returns true if the specified item is a branch item. The Tree * control delegates to the IDataDescriptor to determine if an item is a branch. * @param item Item to inspect. * @return True if a branch, false if not. * */ private function isBranch(item:Object):Boolean { if (item != null) return this.dataDescriptor.isBranch(item, iterator.view); return false; } } }