//-----------------------------------------------------------------------//
//                                                                       //
//                         D y n a m i c M e n u                         //
//                                                                       //
//  Copyright (C) Herve Bitteur 2000-2005. All rights reserved.          //
//  This software is released under the terms of the GNU General Public  //
//  License. Please contact the author at herve.bitteur@laposte.net      //
//  to report bugs & suggestions.                                        //
//-----------------------------------------------------------------------//

package omr.ui;

import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

/**
 * Class <code>DynamicMenu</code> simplifies the definition of a menu, whose
 * content needs to be updated on-the-fly when the menu is being selected.
 *
 * @author Herv&eacute Bitteur
 * @version $Id$
 */
public abstract class DynamicMenu
        extends JMenu
{
    //~ Constructors ------------------------------------------------------

    //-------------//
    // DynamicMenu //
    //-------------//

    /**
     * Create the dynamic menu
     *
     * @param menuLabel the label to be used for the menu
     */
    public DynamicMenu (String menuLabel)
    {
        super(menuLabel);

        // Listener to menu selection, to modify content on-the-fly
        addMenuListener(new MenuListener()
        {
            public void menuCanceled (MenuEvent e)
            {
            }

            public void menuDeselected (MenuEvent e)
            {
            }

            public void menuSelected (MenuEvent e)
            {
                // Clean up the whole menu
                removeAll();

                // Rebuild the whole list of menu items on the fly
                buildItems();
            }
        });
    }

    //~ Methods -----------------------------------------------------------

    //------------//
    // buildItems //
    //------------//

    /**
     * This is the method that is called whenever the menu is selected, so
     * this is the method which must be implemented in a subclass.
     */
    protected abstract void buildItems ();
}

@@ -871,17 +871,17 @@
 enu,
+%0A *
  whose
-%0A *
  con
@@ -938,16 +938,19 @@
 is being
+%0A *
  selecte
@@ -1045,31 +1045,145 @@
 enu%0A
+%7B%0A
     
-    extends JMenu%0A%7B
+//~ Instance variables ------------------------------------------------%0A%0A    // The concrete UI menu%0A    private final JMenu menu;%0A
 %0A   
@@ -1314,33 +1314,32 @@
 -------------//%0A
-%0A
     /**%0A     * C
@@ -1494,13 +1494,24 @@
     
-super
+menu = new JMenu
 (men
@@ -1596,16 +1596,21 @@
         
+menu.
 addMenuL
@@ -1932,16 +1932,21 @@
         
+menu.
 removeAl
@@ -2150,32 +2150,226 @@
 --------------%0A%0A
+    //---------//%0A    // getMenu //%0A    //---------//%0A    /**%0A     * Report the concrete menu%0A     * @return the usable menu%0A     */%0A    public JMenu getMenu()%0A    %7B%0A        return menu;%0A    %7D%0A%0A
     //----------
@@ -2415,17 +2415,16 @@
 -----//%0A
-%0A
     /**%0A

use of an inner component