FileDocCategorySizeDatePackage
DropdownSelectionListener.javaAPI DocAndroid 1.5 API2623Wed May 06 22:41:08 BST 2009com.android.ddms

DropdownSelectionListener

public class DropdownSelectionListener extends org.eclipse.swt.events.SelectionAdapter
Helper class for drop-down menus in toolbars.

Fields Summary
private org.eclipse.swt.widgets.Menu
mMenu
private org.eclipse.swt.widgets.ToolItem
mDropdown
Constructors Summary
public DropdownSelectionListener(org.eclipse.swt.widgets.ToolItem item)
Basic constructor. Creates an empty Menu to hold items.

        mDropdown = item;
        mMenu = new Menu(item.getParent().getShell(), SWT.POP_UP);
    
Methods Summary
public voidadd(java.lang.String label)
Add an item to the dropdown menu.

        MenuItem item = new MenuItem(mMenu, SWT.NONE);
        item.setText(label);
        item.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                // update the dropdown's text to match the selection
                MenuItem sel = (MenuItem) e.widget;
                mDropdown.setText(sel.getText());
            }
        });
    
public voidwidgetSelected(org.eclipse.swt.events.SelectionEvent e)
Invoked when dropdown or neighboring arrow is clicked.

        if (e.detail == SWT.ARROW) {
            // arrow clicked, show menu
            ToolItem item = (ToolItem) e.widget;
            Rectangle rect = item.getBounds();
            Point pt = item.getParent().toDisplay(new Point(rect.x, rect.y));
            mMenu.setLocation(pt.x, pt.y + rect.height);
            mMenu.setVisible(true);
        } else {
            // button clicked
            Log.i("ddms", mDropdown.getText() + " Pressed");
        }