01: /*
02: * Beryl - A web platform based on XML, XSLT and Java
03: * This file is part of the Beryl XML GUI
04: *
05: * Copyright (C) 2004 Wenzel Jakob <wazlaf@tigris.org>
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11:
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-3107 USA
20: */
21:
22: package org.beryl.gui.widgets;
23:
24: import java.awt.Component;
25:
26: import javax.swing.JMenu;
27: import javax.swing.JMenuBar;
28:
29: import org.beryl.gui.GUIException;
30: import org.beryl.gui.Widget;
31: import org.beryl.gui.WidgetInfo;
32:
33: public class MenuBar extends Widget {
34: protected static WidgetInfo menuBarInfo = null;
35: private JMenuBar menuBar = null;
36:
37: static {
38: menuBarInfo = new WidgetInfo(MenuBar.class);
39: menuBarInfo.setSupportsAnchor(false);
40: };
41:
42: public MenuBar(Widget parent, String name) throws GUIException {
43: super (parent, name);
44: menuBar = new JMenuBar();
45: }
46:
47: public void addChild(Widget widget, Object constraint)
48: throws GUIException {
49: if (widget instanceof Menu) {
50: menuBar.add((JMenu) widget.getWidget());
51: addChild(widget);
52: } else if (widget instanceof Spacer) {
53: menuBar.add(widget.getWidget());
54: addChild(widget);
55: } else {
56: throw new GUIException(
57: "Only Menu and Spacer children allowed");
58: }
59: }
60:
61: public void removeChildWidget(Widget widget) throws GUIException {
62: if (widget instanceof Menu)
63: menuBar.remove((JMenu) widget.getWidget());
64: else if (widget instanceof Spacer)
65: menuBar.remove(widget.getWidget());
66: super .removeChildWidget(widget);
67: }
68:
69: public Component getWidget() {
70: return menuBar;
71: }
72:
73: public WidgetInfo getWidgetInfo() {
74: return menuBarInfo;
75: }
76: }
|