395 }
396
397 /**
398 * Implemented to be a <code>MenuElement</code> -- does nothing.
399 *
400 * @see #getSubElements
401 */
402 public void menuSelectionChanged(boolean isIncluded) {
403 }
404
405 /**
406 * Implemented to be a <code>MenuElement</code> -- returns the
407 * menus in this menu bar.
408 * This is the reason for implementing the <code>MenuElement</code>
409 * interface -- so that the menu bar can be treated the same as
410 * other menu elements.
411 * @return an array of menu items in the menu bar.
412 */
413 public MenuElement[] getSubElements() {
414 MenuElement result[];
415 Vector tmp = new Vector();
416 int c = getComponentCount();
417 int i;
418 Component m;
419
420 for(i=0 ; i < c ; i++) {
421 m = getComponent(i);
422 if(m instanceof MenuElement)
423 tmp.addElement(m);
424 }
425
426 result = new MenuElement[tmp.size()];
427 for(i=0,c=tmp.size() ; i < c ; i++)
428 result[i] = (MenuElement) tmp.elementAt(i);
429 return result;
430 }
431
432 /**
433 * Implemented to be a <code>MenuElement</code>. Returns this object.
434 *
435 * @return the current <code>Component</code> (this)
436 * @see #getSubElements
437 */
438 public Component getComponent() {
439 return this;
440 }
441
442
443 /**
444 * Returns a string representation of this <code>JMenuBar</code>.
445 * This method
446 * is intended to be used only for debugging purposes, and the
447 * content and format of the returned string may vary between
448 * implementations. The returned string may be empty but may not
645 /**
646 * Normally causes every selected item in the object to be selected
647 * if the object supports multiple selections. This method
648 * makes no sense in a menu bar, and so does nothing.
649 */
650 public void selectAllAccessibleSelection() {
651 }
652 } // internal class AccessibleJMenuBar
653
654
655 /**
656 * Subclassed to check all the child menus.
657 * @since 1.3
658 */
659 protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
660 int condition, boolean pressed) {
661 // See if we have a local binding.
662 boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
663 if (!retValue) {
664 MenuElement[] subElements = getSubElements();
665 for (int i=0; i<subElements.length; i++) {
666 if (processBindingForKeyStrokeRecursive(
667 subElements[i], ks, e, condition, pressed)) {
668 return true;
669 }
670 }
671 }
672 return retValue;
673 }
674
675 static boolean processBindingForKeyStrokeRecursive(MenuElement elem,
676 KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
677 if (elem == null) {
678 return false;
679 }
680
681 Component c = elem.getComponent();
682
683 if ( !(c.isVisible() || (c instanceof JPopupMenu)) || !c.isEnabled() ) {
684 return false;
685 }
686
687 if (c != null && c instanceof JComponent &&
688 ((JComponent)c).processKeyBinding(ks, e, condition, pressed)) {
689
690 return true;
691 }
692
693 MenuElement[] subElements = elem.getSubElements();
694 for(int i=0; i<subElements.length; i++) {
695 if (processBindingForKeyStrokeRecursive(subElements[i], ks, e,
696 condition, pressed)) {
697 return true;
698 // We don't, pass along to children JMenu's
699 }
700 }
701 return false;
702 }
703
704 /**
705 * Overrides <code>JComponent.addNotify</code> to register this
706 * menu bar with the current keyboard manager.
707 */
708 public void addNotify() {
709 super.addNotify();
710 KeyboardManager.getCurrentManager().registerMenuBar(this);
711 }
712
713 /**
714 * Overrides <code>JComponent.removeNotify</code> to unregister this
715 * menu bar with the current keyboard manager.
716 */
|
395 }
396
397 /**
398 * Implemented to be a <code>MenuElement</code> -- does nothing.
399 *
400 * @see #getSubElements
401 */
402 public void menuSelectionChanged(boolean isIncluded) {
403 }
404
405 /**
406 * Implemented to be a <code>MenuElement</code> -- returns the
407 * menus in this menu bar.
408 * This is the reason for implementing the <code>MenuElement</code>
409 * interface -- so that the menu bar can be treated the same as
410 * other menu elements.
411 * @return an array of menu items in the menu bar.
412 */
413 public MenuElement[] getSubElements() {
414 MenuElement result[];
415 Vector<MenuElement> tmp = new Vector<MenuElement>();
416 int c = getComponentCount();
417 int i;
418 Component m;
419
420 for(i=0 ; i < c ; i++) {
421 m = getComponent(i);
422 if(m instanceof MenuElement)
423 tmp.addElement((MenuElement) m);
424 }
425
426 result = new MenuElement[tmp.size()];
427 for(i=0,c=tmp.size() ; i < c ; i++)
428 result[i] = tmp.elementAt(i);
429 return result;
430 }
431
432 /**
433 * Implemented to be a <code>MenuElement</code>. Returns this object.
434 *
435 * @return the current <code>Component</code> (this)
436 * @see #getSubElements
437 */
438 public Component getComponent() {
439 return this;
440 }
441
442
443 /**
444 * Returns a string representation of this <code>JMenuBar</code>.
445 * This method
446 * is intended to be used only for debugging purposes, and the
447 * content and format of the returned string may vary between
448 * implementations. The returned string may be empty but may not
645 /**
646 * Normally causes every selected item in the object to be selected
647 * if the object supports multiple selections. This method
648 * makes no sense in a menu bar, and so does nothing.
649 */
650 public void selectAllAccessibleSelection() {
651 }
652 } // internal class AccessibleJMenuBar
653
654
655 /**
656 * Subclassed to check all the child menus.
657 * @since 1.3
658 */
659 protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,
660 int condition, boolean pressed) {
661 // See if we have a local binding.
662 boolean retValue = super.processKeyBinding(ks, e, condition, pressed);
663 if (!retValue) {
664 MenuElement[] subElements = getSubElements();
665 for (MenuElement subElement : subElements) {
666 if (processBindingForKeyStrokeRecursive(
667 subElement, ks, e, condition, pressed)) {
668 return true;
669 }
670 }
671 }
672 return retValue;
673 }
674
675 static boolean processBindingForKeyStrokeRecursive(MenuElement elem,
676 KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
677 if (elem == null) {
678 return false;
679 }
680
681 Component c = elem.getComponent();
682
683 if ( !(c.isVisible() || (c instanceof JPopupMenu)) || !c.isEnabled() ) {
684 return false;
685 }
686
687 if (c != null && c instanceof JComponent &&
688 ((JComponent)c).processKeyBinding(ks, e, condition, pressed)) {
689
690 return true;
691 }
692
693 MenuElement[] subElements = elem.getSubElements();
694 for (MenuElement subElement : subElements) {
695 if (processBindingForKeyStrokeRecursive(subElement, ks, e, condition, pressed)) {
696 return true;
697 // We don't, pass along to children JMenu's
698 }
699 }
700 return false;
701 }
702
703 /**
704 * Overrides <code>JComponent.addNotify</code> to register this
705 * menu bar with the current keyboard manager.
706 */
707 public void addNotify() {
708 super.addNotify();
709 KeyboardManager.getCurrentManager().registerMenuBar(this);
710 }
711
712 /**
713 * Overrides <code>JComponent.removeNotify</code> to unregister this
714 * menu bar with the current keyboard manager.
715 */
|