1999-03-24 08:59:05 +00:00
|
|
|
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Grendel mail/news client.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Giao Nguyen
|
|
|
|
* <grail@cafebabe.org>. Portions created by Giao Nguyen are Copyright
|
|
|
|
* (C) 1999 Giao Nguyen. All Rights Reserved.
|
1999-05-15 22:42:27 +00:00
|
|
|
*
|
|
|
|
* Contributors: Mauro Botelho <mabotelh@bellsouth.net>
|
1999-03-24 08:59:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package grendel.widgets;
|
|
|
|
|
1999-06-20 02:15:35 +00:00
|
|
|
import java.awt.Component;
|
|
|
|
|
1999-03-24 08:59:05 +00:00
|
|
|
import javax.swing.JMenuBar;
|
|
|
|
import javax.swing.JMenu;
|
|
|
|
import javax.swing.JMenuItem;
|
|
|
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
import java.util.Enumeration;
|
|
|
|
|
1999-06-18 03:48:43 +00:00
|
|
|
public class MenuCtrl extends JMenu implements Control {
|
1999-03-24 08:59:05 +00:00
|
|
|
protected Hashtable controls = new Hashtable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the control by its name.
|
|
|
|
* @param name the control's name
|
|
|
|
* @return the menu item
|
|
|
|
*/
|
|
|
|
public JMenuItem getItemByName(String name) {
|
1999-05-15 22:42:27 +00:00
|
|
|
JMenuItem item = (JMenuItem)(controls.get(name));
|
1999-03-24 08:59:05 +00:00
|
|
|
|
|
|
|
// if it's not a toplevel item, it must be in one of the submenus
|
1999-05-15 22:42:27 +00:00
|
|
|
if (item == null) {
|
1999-03-24 08:59:05 +00:00
|
|
|
Enumeration e = controls.elements();
|
|
|
|
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
Object o = e.nextElement();
|
|
|
|
|
|
|
|
if (o instanceof MenuCtrl) {
|
|
|
|
MenuCtrl c = (MenuCtrl)o;
|
1999-05-15 22:42:27 +00:00
|
|
|
item = (JMenuItem)(c.getItemByName(name));
|
1999-03-24 08:59:05 +00:00
|
|
|
if (item != null) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
1999-06-20 02:15:35 +00:00
|
|
|
|
|
|
|
public Component add(Component comp) {
|
|
|
|
if (comp instanceof JMenuItem) {
|
|
|
|
JMenuItem item = (JMenuItem)comp;
|
|
|
|
addItemByName(item.getActionCommand(), item);
|
|
|
|
} else {
|
|
|
|
super.add(comp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return comp;
|
|
|
|
}
|
1999-03-24 08:59:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a menu item to the menu.
|
|
|
|
* @param name the name of the menu
|
|
|
|
* @param component the menu item
|
|
|
|
*/
|
|
|
|
public void addItemByName(String name, JMenuItem component) {
|
|
|
|
controls.put(name, component);
|
1999-06-20 02:15:35 +00:00
|
|
|
super.add(component);
|
1999-03-24 08:59:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|