Package totalcross.ui

Class MenuBarDropDown


  • public class MenuBarDropDown
    extends Window
    Constructs a MenuBarDropDown with the given items. This class is used in conjunction with the MenuBar. However, you can also use it to create a stand alone "right click" menu. Here is an example of how to build the MenuBarDropDown for the DateBook:
     MenuItem col1[] = // note that the first String is always skipped
     {
       new MenuItem("Record"),
       new MenuItem("NewEvent"),
       new MenuItem("Delete Note..."),
       new MenuItem("Purge..."),
       new MenuItem(),           // create a dotted line
       new MenuItem("Beam Event"),
     };
     MenuBarDropDown pop = new MenuBarDropDown(10,10,col1);
     pop.popupNonBlocking();
     // a PRESSED event is generated when a item is selected. The Window
     // is closed when the user clicks outside or selects an item. Use the getSelectedIndex
     // method to discover the index of the MenuItem array that was selected (-1 if none).
     
    Note: the menu items must fit on screen. No clipping is applied. Also, the font and colors can be changed if desired.
    • Constructor Detail

      • MenuBarDropDown

        public MenuBarDropDown​(int x,
                               int y,
                               MenuItem[] items)
        Constructs a MenuBarDropDown that will show at the given x,y position the given items.
    • Method Detail

      • strings2items

        public static MenuItem[] strings2items​(java.lang.String[] strings)
        Converts an old Menu format into the new one.
      • onFontChanged

        protected void onFontChanged()
        Change the font and recompute some parameters
        Overrides:
        onFontChanged in class Control
      • screenResized

        public void screenResized()
        Description copied from class: Window
        Called when the screen is resized, probably caused by a rotation. ATTENTION: THIS CALL CANNOT BE BLOCKED OR THE SYSTEM WILL LOCK!
        Overrides:
        screenResized in class Window
      • setSelectedIndex

        public int setSelectedIndex​(int index)
        Selects the given index.
      • getYPos

        public int getYPos​(int index)
      • getSelectedIndex

        public int getSelectedIndex()
        Returns the selected index when this window was closed or -1 if non was selected
      • onPopup

        protected void onPopup()
        Setup some important variables
        Overrides:
        onPopup in class Window
      • postPopup

        protected void postPopup()
        Description copied from class: Window
        Placeholder called after the popup is done and after the repaint of this window. The default implementation does nothing.
        Overrides:
        postPopup in class Window
      • postUnpop

        protected void postUnpop()
        Description copied from class: Window
        Placeholder called after the unpop is done and after the repaint of the other window. The default implementation does nothing.
        Overrides:
        postUnpop in class Window
      • onClickedOutside

        protected boolean onClickedOutside​(PenEvent event)
        Close the popup list with a click outside its bounds
        Overrides:
        onClickedOutside in class Window
      • loadBehind

        protected void loadBehind()
        Description copied from class: Window
        This method repaints all windows from bottom to top. It is automaticaly used in the unpop method.
        Overrides:
        loadBehind in class Window
      • onEvent

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • setCursorColor

        public void setCursorColor​(int c)
        Sets the cursor color. By default, it is based in the background color
      • onColorsChanged

        protected void onColorsChanged​(boolean colorsChanged)
        Description copied from class: Control
        Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
        Overrides:
        onColorsChanged in class Container
      • onPaint

        public void onPaint​(Graphics g)
        Description copied from class: Container
        Draws the border (if any). If you override this method, be sure to call super.onPaint(g);, or the border will not be drawn.
        Overrides:
        onPaint in class Container
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • handleFocusChangeKeys

        protected boolean handleFocusChangeKeys​(KeyEvent ke)
        Description copied from class: Window
        Called by the main event handler to handle the focus change keys. Only called when Settings.keyboardFocusNavigation is true.
        Overrides:
        handleFocusChangeKeys in class Window
      • handleGeographicalFocusChangeKeys

        public Control handleGeographicalFocusChangeKeys​(KeyEvent ke)
        Description copied from class: Control
        Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
        Overrides:
        handleGeographicalFocusChangeKeys in class Control
        Parameters:
        ke - The KeyEvent to be processed
        Returns:
        The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
        See Also:
        Settings.geographicalFocus
      • getNextSelectionIndex

        protected int getNextSelectionIndex​(KeyEvent ke)
        Returns the index of the next menu item that is to be selected based on the direction of the KeyEvent.
        Parameters:
        ke - The key event
        Returns:
        The index of the next menu item based on the direction of the key event.