PageRenderTime 38ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/com/foxr/display/components/List.as

http://github.com/jfox015/FoxR
ActionScript | 720 lines | 314 code | 49 blank | 357 comment | 131 complexity | 1e05d1fc8dc51b2f6b16f5801d32061c MD5 | raw file
  1. package com.foxr.display.components
  2. {
  3. //import external classes
  4. import com.foxr.display.*;
  5. import com.foxr.event.CascadingMenuEvent;
  6. import flash.events.*;
  7. import flash.text.TextFormat;
  8. import flash.utils.getQualifiedClassName;
  9. import flash.display.Sprite;
  10. /**
  11. * The list object is a simple container that can be used to either group and display
  12. * either FoxR ListItem objects or groupings of other objects as well.
  13. * <p />
  14. * <h3>Using List with ListItems</h3>
  15. * <p>
  16. * To display a list of text based ListItem objects in a list, create and pass a
  17. * FoxR <b>DataProvider</b> object as it's source. The list will be rendered
  18. * according to the data as well as any CSS properties that are assgined to it.
  19. * </p>
  20. * This class is meant to serve as a base class for custom implementations
  21. * of different kinds of organized lists including but not limited to Combo Boxes
  22. * and Cascading Menus.
  23. *
  24. * @langversion ActionScript 3.0
  25. * @playerversion Flash 9
  26. * @author Jeff Fox
  27. * @version 3.1.1
  28. *
  29. * Copyright (c) 2009 Jeff Fox. Licensed under the MIT License.
  30. *
  31. */
  32. public class List extends ScrollPane {
  33. /*--------------------------------------
  34. / VARIABLES
  35. /-------------------------------------*/
  36. /* CONSTANTS */
  37. /**
  38. * Width Proportional Const
  39. * @const WIDTH_PROPORTIONAL:String
  40. */
  41. public static const WIDTH_PROPORTIONAL:String = 'proportional';
  42. /**
  43. * Width Fixed Const
  44. * @const WIDTH_FIXED:String
  45. */
  46. public static const WIDTH_FIXED:String = 'fixed';
  47. /**
  48. * Width Size To List Const
  49. * @const WIDTH_SIZETOLIST:String
  50. */
  51. public static const WIDTH_SIZETOLIST:String = 'sizeToList';
  52. /**
  53. * Width Fixed Const
  54. * @const HEIGHT_FIXED:String
  55. */
  56. public static const HEIGHT_FIXED:String = 'fixed';
  57. /**
  58. * Height - Size To List Const
  59. * @const HEIGHT_SIZETOLIST:String
  60. */
  61. public static const HEIGHT_SIZETOLIST:String = 'sizeToList';
  62. /**
  63. * Left open menu
  64. * @const MENU_DIRECTION_LEFT:String
  65. */
  66. public static const COLUMNS_MULTIPLE:String = 'multiple';
  67. /**
  68. * bottom open menu
  69. * @const MENU_DIRECTION_TOP:String
  70. */
  71. public static const COLUMNS_SINGLE:String = 'single';
  72. /**
  73. * Left open menu
  74. * @const MENU_DIRECTION_LEFT:String
  75. */
  76. public static const MENU_DIRECTION_LEFT:String = 'left';
  77. /**
  78. * bottom open menu
  79. * @const MENU_DIRECTION_TOP:String
  80. */
  81. public static const MENU_DIRECTION_BOTTOM:String = 'bottom';
  82. /* List Object vars */
  83. /**
  84. * Data List
  85. * @var _dataList:ComponentDataList
  86. */
  87. private var _dataList:ComponentDataList = null;
  88. /**
  89. * Height Type
  90. * @var _heightType:String
  91. */
  92. private var _heightType:String = HEIGHT_SIZETOLIST;
  93. /**
  94. * Width Type
  95. * @var _widthType:String
  96. */
  97. private var _widthType:String = WIDTH_SIZETOLIST;
  98. /**
  99. * Maximum Items to Display
  100. * @var _maxItemsToDisplay:Number
  101. */
  102. private var _maxItemsToDisplay:Number;
  103. private var listItemArr:Array = null;
  104. /* CHILD ITEM VARS */
  105. /**
  106. * Item Style
  107. * @var _itemStyle:Object
  108. */
  109. private var _itemStyle:Object = null;
  110. /**
  111. * Item Text Style
  112. * @var _itemTextStyle:TextFormat
  113. */
  114. private var _itemTextStyle:TextFormat = null;
  115. /**
  116. * Header Style
  117. * @var _headerStyle:Object
  118. */
  119. private var _headerStyle:Object = null;
  120. /**
  121. * Header Text Style
  122. * @var _headerTextStyle:TextFormat
  123. */
  124. private var _headerTextStyle:TextFormat = null;
  125. /**
  126. * Header Text Style
  127. * @var _headerTextStyle:TextFormat
  128. */
  129. private var _headerDividerLine:String = '';
  130. /* INTERACTION VARS */
  131. private var _selectedItem:ListItem = null;
  132. private var _selectedIndex:Number = -1;
  133. private var _highlightedIndex:Number = -1;
  134. /* MULTI COLUMN VARS */
  135. private var _multiColumn:Boolean = false;
  136. private var _maxColumnCount:Number = 100;
  137. private var _multiColumnWidth:Number = -1;
  138. private var _columnSpacing:Number =_padding;
  139. private var _maxItemsPerColumn:Number = -1;
  140. /* Cascading Menu properties */
  141. private var _parentList:Object = null;
  142. private var _menuDirection:String = MENU_DIRECTION_LEFT;
  143. /*--------------------------------------
  144. / CONSTRUCTOR
  145. /-------------------------------------*/
  146. /**
  147. * Construct a new List instance
  148. *
  149. */
  150. public function List() {
  151. super();
  152. _dataList = new ComponentDataList();
  153. } // END function
  154. /*--------------------------------------
  155. / SET/GET FUNCTIONS
  156. /-------------------------------------*/
  157. public override function get className():Class { return List; }
  158. /**
  159. * Assigns a data list object as the source for the lists items.
  160. * @param dl A ComponentDataList object
  161. * @since 1.0
  162. *
  163. */
  164. public function set dataList(dl:ComponentDataList):void {
  165. _dataList = dl;
  166. if (parentObj != null) setItems();
  167. }
  168. /**
  169. * Enabls or disabled the list control. Setting this proeprty to false will unselect
  170. * any selected items.
  171. * @param Boolean e TRUE or FALSE
  172. * @return Boolean TRUE or FALSE
  173. * @since 1.0
  174. *
  175. */
  176. public override function set enabled(e:Boolean):void {
  177. super.enabled = e;
  178. var listSize:Number = this.size;
  179. if (listSize > 0) {
  180. for (var i:Number = 0; i < listSize; i++) {
  181. var item:ListItem = ListItem(content_elem.getChildAt(i));
  182. if (item != _selectedItem) item.enabled = e; // END if
  183. } // END for
  184. } // END if
  185. }
  186. /**
  187. * Sets a global background color that will be applied to all options by default. To overdide
  188. * the background color for individual options, add backgroundColor attribute to the
  189. * customStyle property.
  190. * @param c Color in 0x000000 format
  191. * @since 1.0
  192. *
  193. */
  194. public function set itemBackgroundColor(c:Number):void { _itemStyle.backgroundColor = c; }
  195. /**
  196. * Applies the maximum number of items that should be displayed. If the multicolumn
  197. * property is set to TRUE, this property determines the maximum number of items to display
  198. * in a column before it spills over into the next one.
  199. * @param m TRUE or FALSE
  200. * @return TRUE or FALSE
  201. * @since 1.0
  202. */
  203. public function get maxItemsToDisplay():Number { return _maxItemsToDisplay; }
  204. public function set maxItemsToDisplay(m:Number):void { _maxItemsToDisplay = m; }
  205. /**
  206. * Set if the list should be single column (default) or multi column
  207. * @param m The column type - single or multicolumn
  208. * @return The current column type value
  209. * @since 1.0
  210. */
  211. public function get columnType():String { return (_multiColumn == true) ? COLUMNS_MULTIPLE: COLUMNS_SINGLE; }
  212. public function set columnType(t:String):void { _multiColumn = (t == COLUMNS_MULTIPLE) ? true : false; }
  213. /**
  214. * If <i>multiColumn</i> is set to TRUE, this setting restricts the list to display only the
  215. * specified number of columns. Bt default, the list will display as many columns as needed based on the
  216. * <i>maxItemsPerColumn</i> setting. With a max column setting, any additional list items will not
  217. * be displayed.
  218. * @param m Max number of columns
  219. * @return Max number of columns
  220. * @since 1.0
  221. */
  222. public function get maxColumnCount():Number { return _maxColumnCount; }
  223. public function set maxColumnCount(m:Number):void { _maxColumnCount = m; }
  224. /**
  225. * If the <i> multicolumn</i> property is set to TRUE, this property determines the maximum number
  226. * of items to display in a column before it spills over into the next one.
  227. * @param m The number of items to display per column
  228. * @return The number of items per column setting
  229. * @since 1.0
  230. */
  231. public function get maxItemsPerColumn():Number { return _maxItemsPerColumn; }
  232. public function set maxItemsPerColumn(m:Number):void { _maxItemsPerColumn = m; }
  233. /**
  234. * Sets a strict column width. By default, columns are autosized by their contents, but this forces
  235. * a consistent width. If the items contained in the list exceed this number, the column will still
  236. * stretch to fit it's contents.
  237. * @param w Column width in pixels
  238. * @return Column width in pixels
  239. * @since 1.0
  240. */
  241. public function get multiColumnWidth():Number { return _multiColumnWidth; }
  242. public function set multiColumnWidth(w:Number):void { _multiColumnWidth = w; }
  243. /**
  244. * Sets the space between columns. Default is 8 pixels.
  245. * @param s Column spacing in pixels
  246. * @return Column spacing in pixels
  247. * @since 1.0
  248. */
  249. public function get columnSpacing():Number { return _columnSpacing; }
  250. public function set columnSpacing(s:Number):void { _columnSpacing = s; }
  251. /**
  252. * Sets or returns a parent list object if this list is used as a child of CsascadingMenu.
  253. * @param listParent Parent list object
  254. * @return Parent list object
  255. * @since 1.0
  256. */
  257. public function get parentList():Object { return _parentList; }
  258. public function set parentList(listParent:Object):void { _parentList = listParent; }
  259. /**
  260. * Sets and returns the selected index of the list. This property works in
  261. * conjunction with the <i> highlightedIndex</i> property, but it is seperate,
  262. * meaning that an option may be selected, but may not necesarily be highlighted.
  263. * @param Number i The index of an item to select
  264. * @return Number The index of the currently selected item
  265. * @since 1.0
  266. *
  267. */
  268. public function get selectedIndex():Number { return _selectedIndex }
  269. public function set selectedIndex(i:Number):void {
  270. _selectedIndex = i;
  271. if (_selectedItem != null) _selectedItem.selected(false);
  272. // MAKE SURE THE INDEX IS A VLAID NUMBER
  273. if (i != -1) {
  274. _selectedItem = ListItem(content_elem.getChildAt(i));
  275. _selectedItem.selected(true);
  276. value = _selectedItem.value;
  277. dispatchEvent(new Event(Event.SELECT));
  278. } else {
  279. throw(new Error("The index specified is not a valid value for this list."));
  280. } // END if
  281. }
  282. /**
  283. * Returns the text value of a selected list item object.
  284. * @return The objects text value.
  285. * @since 1.0
  286. *
  287. */
  288. public function get textValue():String {
  289. var rtnStr:String = '';
  290. if (_selectedItem != null)
  291. rtnStr = _selectedItem.text;
  292. return rtnStr;
  293. }
  294. /**
  295. * Returns the number of items in the current list.
  296. * @return The number of items in the list
  297. * @since 1.0
  298. *
  299. */
  300. public function get size():Number { return _dataList.length; }
  301. /**
  302. * Sets and returns the highlighted index of the list. This property works in
  303. * conjunction with the selectedIndex property, but it is seperate, meaning that
  304. * an option may be highlighted, but not necesarily selected.
  305. * @param i The index of an item to highlight
  306. * @return The index of the currently highlighted item
  307. * @since 1.0
  308. *
  309. */
  310. public function get highlightedIndex():Number { return _highlightedIndex }
  311. public function set highlightedIndex(i:Number):void {
  312. _highlightedIndex = i;
  313. for (var j:Number = 0; j < content_elem.numChildren; j++) {
  314. if (j != _selectedIndex) {
  315. try {
  316. var tmpListItem:ListItem = ListItem(content_elem.getChildAt(j));
  317. if (j == i) {
  318. tmpListItem.highlight(true);
  319. if (tmpListItem.action == ListItem.ACTION_OPEN_MENU) {
  320. switch (_menuDirection) {
  321. case MENU_DIRECTION_BOTTOM:
  322. CascadingMenu(parentObj.parent).showMenu(tmpListItem.value, (this.x - 1), (this.height + 1));
  323. break;
  324. case MENU_DIRECTION_LEFT:
  325. default:
  326. CascadingMenu(parentObj.parent).showMenu(tmpListItem.value, ((this.x + this.width) - 1), ((this.y + tmpListItem.y) - 1));
  327. break;
  328. } // END switch
  329. } // END if
  330. } else {
  331. tmpListItem.highlight(false);
  332. } // END if
  333. } catch (e:Error) {
  334. gpm.log.error("List -> highlightedIndex error occured, error = " + e);
  335. } // END try/catch
  336. } // END if
  337. } // END for
  338. }
  339. /**
  340. * Applies a properties object for the list items. This is a global style setting that can be overridden
  341. * per list item if necessary.
  342. * @param s Style properties object
  343. * @since 1.0
  344. *
  345. */
  346. public function set itemStyle(s:Object):void { _itemStyle = s; }
  347. /**
  348. * Applies a properties object for the list items. This is a global style setting that can be overridden
  349. * per list item if necessary.
  350. * @param s Style properties object
  351. * @since 1.0
  352. *
  353. */
  354. public function set itemTextStyle(s:TextFormat):void { _itemTextStyle = s; }
  355. /**
  356. * Applies a properties object for the lists header(s). Headers sit above list items and can have
  357. * seperate
  358. * @param s Style properties object
  359. * @since 1.0
  360. *
  361. */
  362. public function set headerStyle(s:Object):void { _headerStyle = s; }
  363. /**
  364. * Applies a TextFormat to the lists header item(s).
  365. * @param s TextFormat object
  366. * @since 1.0
  367. *
  368. */
  369. public function set headerTextStyle(s:TextFormat):void { _headerTextStyle = s; }
  370. /**
  371. * Applies a TextFormat to the lists header item(s).
  372. * @param s TextFormat object
  373. * @since 1.0
  374. *
  375. */
  376. public function set headerDividerLine(dl:String):void { _headerDividerLine = dl;}
  377. /**
  378. * Applies the type of height setting to the object. Setting a height to fixed will prevent
  379. * the background from mathcing the size of the list. Setting the object overflow property to
  380. * "hidden" will hide the remaining items. Setting overflow to "scroll" or "auto" will eneabled
  381. * scrollbars.
  382. * @param t The height type
  383. * @since 1.0
  384. */
  385. public function set heightType(t:String):void { _heightType = t; }
  386. /**
  387. * Applies the type of width sizing attribute to the object. Setting a width to fixed keeps the list
  388. * a fixed size despite the width of any child elements. Size to list or Proporational will resize
  389. * the list to accomidate the widest ListItem.
  390. * @param t The width type
  391. * @since 1.0
  392. */
  393. public function get widthType():String { return _widthType; }
  394. public function set widthType(t:String):void { _widthType = t; }
  395. /*--------------------------------------
  396. / PUBLIC FUNCTIONS
  397. /-------------------------------------*/
  398. /**
  399. * Returns the value of the specified index..
  400. * @param index The number of the item of which value is to be returned
  401. * @return The items value
  402. * @since 1.0
  403. *
  404. */
  405. public function getItemValueAt(index:Number):* { return _dataList.getItemAt(index).value; }
  406. /**
  407. * Resets the object to it's inital state.
  408. * @since 1.0
  409. */
  410. public function reset():void {
  411. while (content_elem.numChildren > 0) {
  412. content_elem.removeChildAt(0);
  413. } // END while
  414. }
  415. /**
  416. * Set a new global list width based on the size of child items. This mehotd only accepts values that
  417. * are larger than the current value and only if widthType is not set to WIDTH_FIXED.
  418. * @param w Width in pixels
  419. * @since 1.0
  420. */
  421. public function updateListWidth(w:Number):void {
  422. if (widthType != WIDTH_FIXED && w > width) {
  423. super.width = content_elem.width = w;
  424. refresh();
  425. for (var i:Number = 0; i < content_elem.numChildren; i++) {
  426. ListItem(content_elem.getChildAt(i)).width = w;
  427. } // END while
  428. } // END if
  429. }
  430. /**
  431. * Resets the Data list property.
  432. * @since 1.0
  433. */
  434. public function resetDataList():void {
  435. if (_dataList != null) _dataList = null; // END if
  436. }
  437. /**
  438. * Placeholder method for child objects to execute once they have been added to the movie
  439. * stage. This helps with acessing global variable from Main and parent objects.
  440. * @since 1.0
  441. *
  442. */
  443. public override function objReady(e:Event):void {
  444. reset();
  445. setItems();
  446. } // END function
  447. /**
  448. * Resets the order of items in the list based on their order in the COmponent
  449. * Data List.
  450. * @since 3.0
  451. */
  452. public function repositionItems():void{
  453. if (listItemArr != null) {
  454. this.reset();
  455. for(var i:Number = 0; i<listItemArr.length; i++){
  456. _dataList.addItem(listItemArr[i]);
  457. }
  458. }
  459. setItems();
  460. }
  461. /*------------------------
  462. / PRIVATE FUNCTIONS
  463. /-----------------------*/
  464. /**
  465. * Applies items to the list.
  466. * Applies items to the list.
  467. * @since 1.0
  468. */
  469. public function setItems():void {
  470. listItemArr = new Array();
  471. if (_dataList != null) {
  472. try {
  473. var tmpHeight:Number = 0;
  474. var visibleHeight:Number = 0;
  475. var tmpWidth:Number = 0;
  476. var len:Number = _dataList.length;
  477. //_childOffset = this.numChildren;
  478. var currItem:ListItem = null;
  479. var dividerCount:int = 0;
  480. // Begin multicolumn set-up
  481. var colTmpWidth:Number = 0, colTmpHeight:Number = 0;
  482. var optX:Number = 0, optY:Number = 0;
  483. var colItemsDrawn:Number = 0, totalItemsDrawn:Number = 0, columnCount:Number = 1;
  484. var columnSizes:Array = [], itemsPerColumn:Number = 0, useHeight:Number = 0;
  485. // SET UP NUMBER OF ITEMSPERCOLUMN
  486. // CHECK ONE, NO ITEMS PER COLUMN LIMIT SET
  487. // MAX COLUMS DEFINED BUT NO LIMT OF OPTIONS PER COLUMN
  488. if (_maxColumnCount != 0 && _maxItemsPerColumn == -1) itemsPerColumn = Math.round(len / _maxColumnCount);
  489. // MAX COLUMNS DEFINED WITH A LIMT OF OPTIONS PER COLUMN
  490. // If the number of options to be displayed is more than can be displayed within the dictated
  491. // limits, override the number of items per column to be equal between all.
  492. else if (_maxColumnCount != 0 && _maxItemsPerColumn != -1) {
  493. if ((Math.round(_maxItemsPerColumn * _maxColumnCount)) < len) itemsPerColumn = Math.round(len / _maxColumnCount);
  494. else itemsPerColumn = _maxItemsPerColumn;
  495. } else if (_maxColumnCount != 0) itemsPerColumn = _maxItemsPerColumn;
  496. //gpm.log.debug(
  497. //gpm.log.debug(this.name + " multicolumn set? " + _multiColumn);
  498. for (var i:Number = 0; i < len; i++) {
  499. // EDIT 1.9 - JF - Added multi column support
  500. if (_multiColumn) {
  501. // If we've reach the max number of items for the current column, start
  502. // a new column and reset our local column vars
  503. if (colItemsDrawn == itemsPerColumn) {
  504. // Update item widths for the preceeding column
  505. // get starting index for last columns top item
  506. var startIdx:int = totalItemsDrawn - (colItemsDrawn * columnCount);
  507. var endIdx:int = startIdx + colItemsDrawn;
  508. for (var c:Number = startIdx; c < endIdx; c++)
  509. content_elem.getChildAt(c).width = colTmpWidth; // END for
  510. columnCount++;
  511. if (_multiColumnWidth != -1 || _multiColumnWidth < colTmpWidth)
  512. optX = tmpWidth += colTmpWidth + _columnSpacing;
  513. else
  514. optX = tmpWidth += _multiColumnWidth + _columnSpacing; // END if
  515. colItemsDrawn = 0;
  516. colTmpWidth = 0;
  517. colTmpHeight = 0;
  518. optY = 0;
  519. } // END if
  520. // If we've reached our column limit, stop looping
  521. if (columnCount > _maxColumnCount) break;
  522. } // END if
  523. /* ADD THE NEW ITEM */
  524. currItem = ListItem(content_elem.addElement('item_'+i,ListItem,{x:optX}));
  525. listItemArr.push(_dataList.getItemAt(i));
  526. currItem.widthType = _widthType;
  527. currItem.heightType = _heightType;
  528. try {
  529. if (_dataList.getItemAt(i).header != null) {
  530. // DRAW HEADER ITEM
  531. if (_headerStyle != null) currItem.applyProperties(_headerStyle); // END if
  532. if (_headerTextStyle != null) currItem.textStyle = _headerTextStyle; // END if
  533. // DRAW DIVIDER LINE
  534. if (_headerDividerLine != '') currItem.dividerLine = _headerDividerLine;
  535. } else {
  536. // DRAW NORMAL ITEM
  537. if (_itemStyle != null) currItem.applyProperties(_itemStyle); // END if
  538. if (_itemTextStyle != null) currItem.textStyle = _itemTextStyle; // END if
  539. } // END if
  540. } catch (e:Error) { } // END try/catch
  541. // EMEDDED ITEM OBJECT SUPPORT
  542. if (_dataList.getItemAt(i).toString() != '[object Object]'){
  543. var cl:Class;
  544. cl = _dataList.getItemAt(i).constructor;
  545. currItem.addChild(cl(_dataList.getItemAt(i)));
  546. currItem.height = _dataList.getItemAt(i).height;
  547. currItem.width = _dataList.getItemAt(i).width;
  548. } else {
  549. // Normal ListItem element, SET ITEM PROPERTIES
  550. /**** CASCADING MENU SUPPORT ****/
  551. // NOT SUPPORTED FOR CUSTOM OBJECT ITEMS
  552. // TEST IF THIS OBJECT HAS A CHILD MENU SPECIFIED
  553. // IF SO, extract menu specific data and apply to child item
  554. var dataItem:Object = _dataList.getItemAt(i);
  555. if (dataItem != null && (dataItem.childMenu != undefined && dataItem.childMenu != null)) {
  556. // HAS A CHILD MENU, SET IT UP AND ATTACH IT IN THE _childMenus OBJECT
  557. CascadingMenu(parentObj.parent).buildMenu(dataItem.id,dataItem.childMenu,this.name);
  558. currItem.action = ListItem.ACTION_OPEN_MENU;
  559. currItem.applyProperties( { pointerStyle:{direction:'right',size:6,color:0xCC0000}, pointerDisplay:ListItem.POINTER_DISPLAY_ALWAYS,pointerType:ListItem.POINTER_TYPE_ARROW } );
  560. currItem.value = dataItem.id;
  561. //currItem.addEventListener(CascadingMenuEvent.MENU_CLOSE, onMenuClose);
  562. } // END if
  563. currItem.addEventListener(CascadingMenuEvent.MENU_CUSTOM_EVENT, onCustomEvent);
  564. //for (var prop:String in dataItem) {
  565. // if (prop != 'childMenu' && prop != 'id')
  566. // currItem[prop] = dataItem[prop];
  567. //} // END for
  568. currItem.applyProperties(_dataList.getItemAt(i));
  569. } // END if
  570. currItem.y = optY;
  571. currItem.enabled = true;
  572. optY += currItem.height + _padding;
  573. // count options drawn to list
  574. colItemsDrawn++;
  575. totalItemsDrawn++;
  576. // INCREMENT WIDTH and HEIGHT VARS
  577. if (_multiColumn) {
  578. if (currItem.width > colTmpWidth) colTmpWidth = currItem.width;
  579. // For multicolumn, increment the colTmpHeight var until we reach the
  580. // end if the coilumn
  581. colTmpHeight += currItem.height + _padding;
  582. if (_maxItemsPerColumn != -1 && colItemsDrawn == _maxItemsPerColumn) {
  583. // if we've reached the end of a column and the individual column height
  584. // is greater than any preceeding column, use it
  585. if (colTmpHeight > tmpHeight)
  586. tmpHeight = colTmpHeight; // END if
  587. } // END if
  588. } else {
  589. if (currItem.width > tmpWidth) tmpWidth = currItem.width; // END if
  590. // For single column, simply imcrement the list height
  591. tmpHeight += currItem.height + _padding;
  592. } // END if
  593. // if we are in the first column, but have drawn all options, set maxLen to the
  594. // width of colMaxLen
  595. if (_multiColumn && columnCount == 1 && totalItemsDrawn == len) {
  596. tmpWidth = colTmpWidth; useHeight = tmpHeight;
  597. } else if (_multiColumn && totalItemsDrawn == len) {
  598. tmpWidth += colTmpWidth;
  599. } else if (_multiColumn && (_maxItemsPerColumn != -1 && colItemsDrawn == _maxItemsPerColumn)) {
  600. useHeight = tmpHeight;
  601. } // END if
  602. } // END for
  603. /** DONE DRAWING ITEMS **/
  604. // Select appropriate width to use for the list based on the _widthType property
  605. var useWidth:Number = 0;
  606. switch (_widthType) {
  607. case WIDTH_PROPORTIONAL:
  608. case WIDTH_SIZETOLIST:
  609. useWidth = tmpWidth;
  610. break;
  611. case WIDTH_FIXED:
  612. useWidth = width;
  613. break;
  614. default:
  615. break;
  616. } // END switch
  617. // For single column lists, assure that each items width matches the width of
  618. // the list itself
  619. if (!_multiColumn) {
  620. for (var d:Number = 0; d < content_elem.numChildren; d++)
  621. content_elem.getChildAt(d).width = useWidth; // END for
  622. } // END if
  623. // Update both the content_elem object and List objects widths
  624. content_elem.width = width = useWidth;
  625. if (useHeight == 0) useHeight = tmpHeight; // END if
  626. content_elem.height = useHeight;
  627. if (this.height < useHeight) {
  628. if (_heightType == HEIGHT_SIZETOLIST) {
  629. if (this._overflow == Element.OVERFLOW_VISIBLE) {
  630. this.height = useHeight;
  631. } else {
  632. if (_maxItemsToDisplay != -1 && visibleHeight == 0) {
  633. this.height = (currItem.height * this._maxItemsToDisplay);
  634. } else {
  635. this.height = visibleHeight;
  636. } // END if
  637. } // END if
  638. } // END if
  639. } else {
  640. if (_heightType == HEIGHT_FIXED && _maxItemsToDisplay != -1 &&
  641. visibleHeight > 0) {
  642. this.height = visibleHeight;
  643. } // END if
  644. } // END if
  645. setOverflow(content_elem);
  646. dispatchEvent(new Event(Event.COMPLETE));
  647. } catch (e:Error) {
  648. gpm.log.error("List -> Error is setItems(). Error for item " + currItem.name + " = " + e);
  649. } // END try/catch
  650. } // END if
  651. } // END function
  652. /*-----------------------------------
  653. / Cascading Menu Event handlers
  654. /----------------------------------*/
  655. public function closeMenus():void {
  656. trace("closeMenus");
  657. trace("parentObj.parent = " + parentObj.parent);
  658. if (parentObj.parent.toString().toLowerCase().indexOf('cascadingmenu') != -1) {
  659. trace("onMenuClose");
  660. CascadingMenu(parentObj.parent).showMenu('none');
  661. } // END if
  662. }
  663. private function onChangeChild(e:Event):void { }
  664. private function onCustomEvent(e:Event):void {
  665. trace("List, onCustomEvent");
  666. if (parentObj.parent.toString().toLowerCase().indexOf('cascadingmenu') != -1) {
  667. CascadingMenu(parentObj.parent).onCustomEvent(ListItem(e.currentTarget).value);
  668. } // END if
  669. }
  670. } // END class
  671. } // END package