Package com.ms.ui Previous
Previous
Contents
Contents
Index
Index
Next
Next

Class UIMenuLauncher

Constructors , Methods

public abstract class UIMenuLauncher extends UIPanel implements IUIMenuLauncher 
{
  // Constructors
  public UIMenuLauncher(UIMenuList menu);
  public UIMenuLauncher(Component comp);
  public UIMenuLauncher(Component comp, UIMenuList menu);

  // Methods
  public UIMenuList getMenu();
  public void setMenu(UIMenuList menu);

  public void setFocus(boolean on);
  public void setHot(boolean on);
  public void setSelected(boolean on);

  public Rectangle getPlacement(Dimension size);
  public Rectangle fitToScreen(Rectangle exclude, Dimension size, 
                               boolean right);
  public void cancel();
  public void cancelled();
  public boolean isLaunched();
  public boolean launch();
  public void selected(Object obj);

}

An abstract class that manages a menu launcher control. UIMenuLauncher provides methods for launching and cancelling a pop-up menu. Each UIMenuLauncher object is associated with a UIMenuList control, which is used for the content of the pop-up menu.

Classes that extend UIMenuLauncher include UIMenuButton and UIMenuItem. The following example shows how to create a UIMenuButton object with an associated pop-up menu. This menu contains a UIMenuItem object, which launches a second pop-up menu.

// Construct the pop-up menu for the menu button.
UIMenuList myMenu = new UIMenuList();

// Add two text items to myMenu.
myMenu.add("Item 1");
myMenu.add("Item 2");

// Add a menu item to myMenu.
{
  // Construct the pop-up menu for the menu item and
  // add a text item to the menu.
  UIMenuList mySubMenu = new UIMenuList();
  mySubMenu.add("Sub Item 1");

  // Construct the menu item, using mySubMenu.
  UIMenuItem myItem = new UIMenuItem("Item 3", mySubMenu);

  // Add myItem to myMenu.
  myMenu.add(myItem);
}

// Now construct the menu button, using myMenu.	
UIMenuButton myButton = new UIMenuButton("Menu 1", myMenu);

// Add the button to the container.		
add(myButton);

When an item in the pop-up menu is clicked, an action event is generated. You can trap for these events by overriding the action method, as shown in the following example.

public boolean action(Event e, Object arg)
{
   if (e.target == myButton)
   {
      // Determine whether the first item in the
      // menu was selected.
      if (myButton.getMenu().getSelectedIndex() == 0)
      {
         // Do something.
      }
      return (true);
   }
}


Constructors


UIMenuLauncher

public UIMenuLauncher(UIMenuList menu);

Creates a menu launcher with the specified menu. The menu launcher has no content.

ParameterDescription
menu The UIMenuList object containing the content of the associated pop-up menu.


UIMenuLauncher

public UIMenuLauncher(Component comp);

Creates a menu launcher using the specified component for content.

ParameterDescription
comp The component to be displayed within the menu launcher.


UIMenuLauncher

public UIMenuLauncher(Component comp, UIMenuList menu);

Creates a menu launcher using the specified component for content and the specified menu.

ParameterDescription
comp The component to be displayed within the menu launcher.
menu The UIMenuList object containing the content of the associated pop-up menu.


Methods


cancel

public void cancel();

Cancels the menu launcher's associated pop-up menu.

Return Value:

No return value.

Remarks:

This method implements cancel in the IUIMenuLauncher interface.


cancelled

public void cancelled();

Called by the menu launcher's associated pop-up menu when the menu is cancelled.

Return Value:

No return value.

Remarks:

This method implements cancelled in the IUIMenuLauncher interface.


fitToScreen

public Rectangle fitToScreen(Rectangle exclude, Dimension size, boolean right);

Determines where the pop-up menu will be displayed on the screen.

Return Value:

Returns the bounding rectangle (in screen coordinates) of the pop-up menu.

ParameterDescription
exclude The rectangle identifying where the pop-up menu will be displayed when it is launched. The menu will not obscure this rectangle.
size A Dimension object containing the preferred size of the pop-up menu.
right If true, the pop-up menu will be displayed to the right of the exclude rectangle; otherwise, the pop-up menu will be displayed below the exclude rectangle.


getMenu

public UIMenuList getMenu();

Retrieves the menu controlled by the menu launcher.

Return Value:

Returns the UIMenuList object containing the associated pop-up menu's content.


getPlacement

public Rectangle getPlacement(Dimension size);

Called by the menu launcher's pop-up menu when the menu is to be positioned.

Return Value:

Returns the bounding rectangle (in screen coordinates) of the pop-up menu.

ParameterDescription
size A Dimension object containing the preferred size of the pop-up menu.

Remarks:

This method calls fitToScreen. By default, the pop-up menu is positioned to the right of the menu launcher.


isLaunched

public boolean isLaunched();

Determines the launched state of menu launcher's associated pop-up menu.

Return Value:

Returns true if the pop-up menu is in the launched state; otherwise, returns false.

Remarks:

This method implements isLaunched in the IUIMenuLauncher interface.


launch

public boolean launch();

Launches the menu launcher's associated pop-up menu.

Return Value:

Returns true if the pop-up menu was launched; otherwise, returns false.

Remarks:

This method implements launch in the IUIMenuLauncher interface.


selected

public void selected(Object obj);

Called by the menu launcher's associated pop-up menu when the menu is closed after an item is selected.

Return Value:

No return value.

ParameterDescription
obj The menu item that was selected.

Remarks:

This method implements selected in the IUIMenuLauncher interface by calling cancelled and generating an action event.


setFocus

public void setFocus(boolean on);

Sets or clears the focus state of the menu launcher.

Return Value:

No return value.

ParameterDescription
on If true, the focus state is set; otherwise, it is cleared.


setHot

public void setHot(boolean on);

Sets or clears the hot-tracked state of the menu launcher.

Return Value:

No return value.

ParameterDescription
on If true, the hot-tracked state is set; otherwise, it is cleared.


setMenu

public void setMenu(UIMenuList menu);

Sets the menu to be controlled by the menu launcher.

Return Value:

No return value.

ParameterDescription
menu The UIMenuList object associated with the menu launcher.


setSelected

public void setSelected(boolean on);

Sets or clears the selected state of the menu launcher.

Return Value:

No return value.

ParameterDescription
on If true, the selected state is set; otherwise, it is cleared.



Top© 1997 Microsoft Corporation. All rights reserved. Legal Notices.