01: package net.xoetrope.swing;
02:
03: import javax.swing.JMenu;
04: import javax.swing.JMenuBar;
05: import javax.swing.JMenuItem;
06:
07: import net.xoetrope.xui.XAppender;
08:
09: /**
10: * A wrapper for menus
11: * <p>Copyright (c) Xoetrope Ltd., 1998-2004<br>
12: * @version 1.0
13: */
14: public class XMenuBar extends JMenuBar implements XAppender {
15: public XMenuBar() {
16: super ();
17: }
18:
19: /**
20: * Do any final setup needed
21: */
22: public void setup() {
23: net.xoetrope.swing.XApplet.setMenuBar(this );
24: }
25:
26: /**
27: * Appends the object o to this item
28: * @param o the appended item
29: * @param name
30: */
31: public void append(Object o, String name) {
32: ((JMenu) o).setName(name);
33: add((JMenu) o);
34: }
35:
36: /**
37: * Get a child object by name
38: * @param name
39: * @return the child
40: */
41: public Object getObject(String name) {
42: int menuCount = getMenuCount();
43: for (int i = 0; i < menuCount; i++) {
44: JMenu menu = getMenu(i);
45: int itemCount = menu.getItemCount();
46: for (int j = 0; j < itemCount; j++) {
47: JMenuItem item = menu.getItem(j);
48: if (item.getName().compareTo(name) == 0)
49: return item;
50: }
51: }
52: return null;
53: }
54: }
|