List

A List object represents a list of items that the user can select. The List class is derived from BaseList, which is a subclass of BaseFormItem. The class hierarchy for List is shown in Figure 2.15

Figure 2.15. The class hierarchy for List


Tables 2.12 and 2.13 present the attributes of the BaseList and List classes, respectively.

Table 2.12. The attributes defined in the BaseList class
NameUsageTypeDefaultAccessibility
dataoptionTag and JSstringnoneread-write
 Description. One of “lazy”, “resize”, “pooling”, and “none”.
defaultselectionTag and JSObjectnullread-write
 Description. The index of the default selected item.
itemclassnameTag and JSstring read-write
 Description. The name of the class to instantiate when the addItem method is invoked.
multiselectTag and JSbooleanfalseread-write
 Description. Indicates if multiple selection is allowed.
toggleselectedTag and JSbooleanfalseread-write
 Description. Indicates whether or not a click toggles a selection.

Table 2.13. The attributes defined in the List class
NameUsageTypeDefaultAccessibility
autoscrollbarTag and JSbooleantrueread-write
 Description. Indicates whether or not a scroll bar should be displayed when there are more items than the value of the shownitems attribute.
border_bottomTag and JSnumber read-write
 Description. The size of the bottom border in pixels.
border_leftTag and JSnumbernoneread-write
 Description. The size of the left border in pixels.
border_rightTag and JSnumber read-write
 Description. The size of the right border in pixels.
border_topTag and JSnumber read-write
 Description. The size of the top border in pixels.
bordersizeTag and JSnumber1read-write
 Description. The border size for this list in pixels.
minheightTag and JSnumber24read-write
 Description. The minimum height of the list in pixels.
scrollableTag and JSbooleanfalseread-write
 Description. Indicates if this List is scrollable.
shownitemsTag and JSnumber-1read-write
 Description. The number of items shown at a time.
spacingTag and JSnumber0read-write
 Description. The spacing between items in the popup list in pixels.
trackingTag and JSbooleanfalseread-write
 Description. Indicates if mousedown tracking is enabled.

Both BaseList and List define new methods. Here are methods defined by BaseList.

addItem(text, value)

Adds the specified text/value pair. The text argument is of type string and the value argument is of type Object.

clearSelection()

Clear the selection list.

getItem(value)

Return the specified value as Object; returns null if the combo box does not contain the specified value.

getItemAt(index)

Returns the item at the specified index.

getNumItems()

Returns the number of items in the list.

getSelection()

Returns the current selection.

getText()

Returns the displayed text.

getValue()

Returns the value for the list.

moveSelection(direction)

Moves the selection to the next view if direction is -1, or to the previous view if direction is 1.

removeItem(value)

Removes the specified item.

removeItemAt(index)

Removes the item at the specified index.

select(item)

Selects the specified item.

selectItem(value)

Selects an item by value.

selectItemAt(index)

Selects the item at the specified index.

selectNext()

Select the next item.

selectPrev()

Select the previous item.

setHilite(view)

Highlights the specified view.

The following are methods added in the List class:

ensureItemInView(item)

Scrolls the list so that the specified item will appear at the top of the list.

select(view)

Selects the specified view.

Listing 2.12 shows an LZX application that uses a List object.

Listing 2.12. Using list (listTest1.lzx)
<canvas height="150">
    <list shownitems="3">
        <textlistitem>Jazz</textlistitem>
        <textlistitem>Pop</textlistitem>
        <textlistitem>Heavy Metal</textlistitem>
        <textlistitem>Fusion</textlistitem>
        <textlistitem>Rock</textlistitem>
    </list>
</canvas>

Use this URL to compile and run the LZX application in Listing 2.12.

http://localhost:8080/lps-4.0.x/app02/listTest1.lzx

Figure 2.16 shows the generated application.

Figure 2.16. A list


Note that the list in Figure 2.16 has five items but is only showing three items because the showitems attribute of the list was given the value of 3.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset