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.JButton;
27: import javax.swing.JPopupMenu;
28: import javax.swing.JSeparator;
29: import javax.swing.JToolBar;
30:
31: import org.beryl.gui.GUIException;
32: import org.beryl.gui.Widget;
33: import org.beryl.gui.WidgetInfo;
34:
35: public class ToolBar extends Widget {
36: protected static WidgetInfo toolBarInfo = null;
37: private JToolBar toolBar = null;
38:
39: static {
40: toolBarInfo = new WidgetInfo(ToolBar.class, widgetInfo);
41: toolBarInfo.addProperty("borderPainted", "bool", Boolean.TRUE);
42: toolBarInfo.addProperty("floatable", "bool", Boolean.TRUE);
43: toolBarInfo.addProperty("rollover", "bool", Boolean.FALSE);
44: }
45:
46: public ToolBar(Widget parent, String name) throws GUIException {
47: super (parent, name);
48: toolBar = new JToolBar();
49: }
50:
51: public void addChild(Widget widget, Object constraint)
52: throws GUIException {
53: if (widget instanceof Button) {
54: toolBar.add((JButton) widget.getWidget());
55: addChild(widget);
56: } else if (widget instanceof Separator) {
57: Separator separator = (Separator) widget;
58: separator.menuSeparator = new JPopupMenu.Separator();
59: if (toolBar.getOrientation() == JToolBar.VERTICAL)
60: separator.menuSeparator
61: .setOrientation(JSeparator.HORIZONTAL);
62: else
63: separator.menuSeparator
64: .setOrientation(JSeparator.VERTICAL);
65: toolBar.add(separator.menuSeparator);
66: addChild(widget);
67: } else {
68: throw new GUIException(
69: "Only Button and Separator children allowed");
70: }
71: }
72:
73: public void removeChildWidget(Widget widget) throws GUIException {
74: if (widget instanceof Button)
75: toolBar.remove((JButton) widget.getWidget());
76: else if (widget instanceof Separator)
77: toolBar.remove(((Separator) widget).menuSeparator);
78: super .removeChildWidget(widget);
79: }
80:
81: public Component getWidget() {
82: return toolBar;
83: }
84:
85: public WidgetInfo getWidgetInfo() {
86: return super.getWidgetInfo();
87: }
88: }
|