/[classpath]/classpath/javax/swing/JMenuBar.java
ViewVC logotype

Diff of /classpath/javax/swing/JMenuBar.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9.2.6 by gnu_andrew, Wed Nov 2 00:43:46 2005 UTC revision 1.9.2.7 by gnu_andrew, Sun Nov 27 21:00:37 2005 UTC
# Line 234  public class JMenuBar extends JComponent Line 234  public class JMenuBar extends JComponent
234     */     */
235    public void addNotify()    public void addNotify()
236    {    {
     // FIXME: Should register this menu bar with the keyboard manager      
237      super.addNotify();      super.addNotify();
238        KeyboardManager.getManager().registerJMenuBar(this);
239    }    }
240    
241    public AccessibleContext getAccessibleContext()    public AccessibleContext getAccessibleContext()
# Line 474  public class JMenuBar extends JComponent Line 474  public class JMenuBar extends JComponent
474    }    }
475    
476    /**    /**
477       * This method overrides JComponent.processKeyBinding to allow the
478       * JMenuBar to check all the child components (recursiveley) to see
479       * if they'll consume the event.
480       *
481       * @param ks the KeyStroke for the event
482       * @param e the KeyEvent for the event
483       * @param condition the focus condition for the binding
484       * @param pressed true if the key is pressed
485       */
486      protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition,
487                                          boolean pressed)
488      {
489        // See if the regular JComponent behavior consumes the event
490        if (super.processKeyBinding(ks, e, condition, pressed))
491          return true;
492        
493        // If not, have to recursively check all the child menu elements to see
494        // if they want it    
495        MenuElement[] children = getSubElements();
496        for (int i = 0; i < children.length; i++)
497          if (processKeyBindingHelper(children[i], ks, e, condition, pressed))
498            return true;
499        return false;
500      }
501      
502      /**
503       * This is a helper method to recursively check the children of this
504       * JMenuBar to see if they will consume a key event via key bindings.  
505       * This is used for menu accelerators.
506       * @param menuElement the menuElement to check (and check all its children)
507       * @param ks the KeyStroke for the event
508       * @param e the KeyEvent that may be consumed
509       * @param condition the focus condition for the binding
510       * @param pressed true if the key was pressed
511       * @return true <code>menuElement</code> or one of its children consume
512       * the event (processKeyBinding returns true for menuElement or one of
513       * its children).
514       */
515      static boolean processKeyBindingHelper(MenuElement menuElement, KeyStroke ks,
516                                             KeyEvent e, int condition,
517                                             boolean pressed)
518      {
519        // First check the menuElement itself, if it's a JComponent
520        if (menuElement instanceof JComponent
521            && ((JComponent) menuElement).processKeyBinding(ks, e, condition,
522                                                            pressed))
523          return true;
524        
525        // If that didn't consume it, check all the children recursively
526        MenuElement[] children = menuElement.getSubElements();
527        for (int i = 0; i < children.length; i++)
528          if (processKeyBindingHelper(children[i], ks, e, condition, pressed))
529            return true;
530        return false;
531      }
532      
533      /**
534     * Process mouse events forwarded from MenuSelectionManager. This method     * Process mouse events forwarded from MenuSelectionManager. This method
535     * doesn't do anything. It is here to conform to the MenuElement interface.     * doesn't do anything. It is here to conform to the MenuElement interface.
536     *     *
# Line 494  public class JMenuBar extends JComponent Line 551  public class JMenuBar extends JComponent
551     */     */
552    public void removeNotify()    public void removeNotify()
553    {    {
554      // Must unregister this menu bar with the current keyboard manager.      KeyboardManager.getManager().unregisterJMenuBar(this);
555      super.removeNotify();      super.removeNotify();
556    }    }
557    

Legend:
Removed from v.1.9.2.6  
changed lines
  Added in v.1.9.2.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26