public void removeMenuItemByLabel(String text) {
   for (int i = 0; i < m_menuItems.size(); i++) {
     MenuItem m = (MenuItem) m_menuItems.elementAt(i);
     if (text.compareTo(m.toString()) == 0) {
       m_menuItems.removeElementAt(i);
     }
   }
 }
  /** @see net.rim.device.api.ui.container.MainScreen#makeMenu(Menu, int) */
  protected void makeMenu(final Menu menu, final int instance) {
    final StringBuffer buffer = new StringBuffer();

    if (_restrictedMapAction.isZoomingAllowed()) {
      buffer.append(Characters.CHECK_MARK).append(' ');
    }

    buffer.append("Allow Zooming");

    final MenuItem zoomItem = new MenuItem(new StringProvider(buffer.toString()), 0x230010, 0);
    zoomItem.setCommand(
        new Command(
            new CommandHandler() {
              /**
               * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
               *     Object)
               */
              public void execute(final ReadOnlyCommandMetadata metadata, final Object context) {
                _restrictedMapAction.toggleZooming();
              }
            }));
    menu.add(zoomItem);

    // Reset buffer
    buffer.setLength(0);

    if (_restrictedMapAction.isPanningAllowed()) {
      buffer.append(Characters.CHECK_MARK).append(' ');
    }

    buffer.append("Allow Panning");

    final MenuItem setCenterItem = new MenuItem(new StringProvider(buffer.toString()), 0x230020, 1);
    setCenterItem.setCommand(
        new Command(
            new CommandHandler() {
              /**
               * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
               *     Object)
               */
              public void execute(final ReadOnlyCommandMetadata metadata, final Object context) {
                _restrictedMapAction.togglePanning();
              }
            }));
    menu.add(setCenterItem);
  }
  public void addMenuItem(
      String text,
      int ordinal,
      int priority,
      final int wrapper_callback,
      final int callback,
      int push_at_start) {
    for (int i = 0; i < m_menuItems.size(); i++) {
      MenuItem m = (MenuItem) m_menuItems.elementAt(i);
      if (text.compareTo(m.toString()) == 0) {
        return; // item already exists, don't add.
      }
    }

    // System.out.println("***** addMenuItem *****");
    // System.out.println("text=" + text);

    MenuItem m =
        new MenuItem(text, ordinal, priority) {
          public void run() {
            try {
              int c_on_menuItem = CibylCallTable.getAddressByName("rim_on_menuItem");
              if (c_on_menuItem != 0) {
                UIWorker.addUIEvent(c_on_menuItem, wrapper_callback, callback, 0, 0, true);
              }
            } catch (Exception ex) {
              System.out.println("run (menuItem): " + ex);
            }
          }
        };

    // System.out.println("added item " + m.toString());

    if (push_at_start == 1) {
      m_menuItems.insertElementAt(m, 0);
    } else m_menuItems.addElement(m);
  }
  public void setMiniMenuItem(
      String text, int ordinal, final int wrapper_callback, final int callback) {
    if (callback != 0) {
      MenuItem menu_item = null;
      menu_item =
          new MenuItem(text, ordinal, 1) {
            public void run() {
              try {
                int c_on_menuItem = CibylCallTable.getAddressByName("rim_on_menuItem");
                if (c_on_menuItem != 0) {
                  UIWorker.addUIEvent(c_on_menuItem, wrapper_callback, callback, 0, 0, true);
                }
              } catch (Exception ex) {
                UIWorker.addUIEventLog("Exception run (menuMiniItem): " + ex.toString());
              }
            }
          };

      m_MiniMenuItems.setElementAt(menu_item, ordinal - 1);
    } else {
      m_menuItems.setElementAt(MenuItem.separator(ordinal - 1), ordinal - 1);
    }
  }
 public void addMenuItemSeparator(int ordinal) {
   m_menuItems.addElement(MenuItem.separator(ordinal));
 }