001: // OBSOLETE
002: // Just to keep to old rife gui code running
003:
004: /*
005: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
006: * Distributed under the terms of either:
007: * - the common development and distribution license (CDDL), v1.0; or
008: * - the GNU Lesser General Public License, v2.1 or later
009: * $Id: DynamicMenuBuilder.java 3634 2007-01-08 21:42:24Z gbevin $
010: */
011: package com.uwyn.rife.gui.old;
012:
013: import javax.swing.*;
014:
015: import java.awt.MenuContainer;
016: import java.awt.event.ActionEvent;
017: import java.awt.event.ActionListener;
018:
019: public class DynamicMenuBuilder implements ActionListener {
020: public JMenu addMenu(MenuContainer parentMenu, String menuLabel) {
021: return addMenu(parentMenu, menuLabel, (char) 0);
022: }
023:
024: public JMenu addMenu(MenuContainer parentMenu, String menuLabel,
025: Character mnemonic) {
026: return addMenu(parentMenu, menuLabel, mnemonic.charValue());
027: }
028:
029: public JMenu addMenu(MenuContainer parentMenu, String menuLabel,
030: char mnemonic) {
031: JMenu menu = new JMenu(menuLabel);
032: if (0 != mnemonic) {
033: menu.setMnemonic(mnemonic);
034: }
035: if (null != parentMenu) {
036: ((JComponent) parentMenu).add(menu);
037: }
038:
039: return menu;
040: }
041:
042: public JMenuItem addMenuItem(MenuContainer parentMenu,
043: String menuLabel, DynamicMenuAction action) {
044: return addMenuItem(parentMenu, menuLabel, action, (char) 0,
045: null);
046: }
047:
048: public JMenuItem addMenuItem(MenuContainer parentMenu,
049: String menuLabel, DynamicMenuAction action,
050: Character mnemonic) {
051: return addMenuItem(parentMenu, menuLabel, action, mnemonic
052: .charValue(), null);
053: }
054:
055: public JMenuItem addMenuItem(MenuContainer parentMenu,
056: String menuLabel, DynamicMenuAction action,
057: Character mnemonic, KeyStroke accelerator) {
058: return addMenuItem(parentMenu, menuLabel, action, mnemonic
059: .charValue(), accelerator);
060: }
061:
062: public JMenuItem addMenuItem(MenuContainer parentMenu,
063: String menuLabel, DynamicMenuAction action, char mnemonic) {
064: return addMenuItem(parentMenu, menuLabel, action, mnemonic,
065: null);
066: }
067:
068: public JMenuItem addMenuItem(MenuContainer parentMenu,
069: String menuLabel, DynamicMenuAction action, char mnemonic,
070: KeyStroke accelerator) {
071: return processMenuItem(new JMenuItem(menuLabel), parentMenu,
072: action, mnemonic, accelerator);
073: }
074:
075: public JCheckBoxMenuItem addCheckBoxMenuItem(
076: MenuContainer parentMenu, String menuLabel,
077: DynamicMenuAction action) {
078: return addCheckBoxMenuItem(parentMenu, menuLabel, action,
079: (char) 0, null);
080: }
081:
082: public JCheckBoxMenuItem addCheckBoxMenuItem(
083: MenuContainer parentMenu, String menuLabel,
084: DynamicMenuAction action, Character mnemonic) {
085: return addCheckBoxMenuItem(parentMenu, menuLabel, action,
086: mnemonic.charValue(), null);
087: }
088:
089: public JCheckBoxMenuItem addCheckBoxMenuItem(
090: MenuContainer parentMenu, String menuLabel,
091: DynamicMenuAction action, Character mnemonic,
092: KeyStroke accelerator) {
093: return addCheckBoxMenuItem(parentMenu, menuLabel, action,
094: mnemonic.charValue(), accelerator);
095: }
096:
097: public JCheckBoxMenuItem addCheckBoxMenuItem(
098: MenuContainer parentMenu, String menuLabel,
099: DynamicMenuAction action, char mnemonic) {
100: return addCheckBoxMenuItem(parentMenu, menuLabel, action,
101: mnemonic, null);
102: }
103:
104: public JCheckBoxMenuItem addCheckBoxMenuItem(
105: MenuContainer parentMenu, String menuLabel,
106: DynamicMenuAction action, char mnemonic,
107: KeyStroke accelerator) {
108: return (JCheckBoxMenuItem) processMenuItem(
109: new JCheckBoxMenuItem(menuLabel), parentMenu, action,
110: mnemonic, accelerator);
111: }
112:
113: public JRadioButtonMenuItem addRadioButtonMenuItem(
114: MenuContainer parentMenu, String menuLabel,
115: DynamicMenuAction action) {
116: return addRadioButtonMenuItem(parentMenu, menuLabel, action,
117: (char) 0, null);
118: }
119:
120: public JRadioButtonMenuItem addRadioButtonMenuItem(
121: MenuContainer parentMenu, String menuLabel,
122: DynamicMenuAction action, Character mnemonic) {
123: return addRadioButtonMenuItem(parentMenu, menuLabel, action,
124: mnemonic.charValue(), null);
125: }
126:
127: public JRadioButtonMenuItem addRadioButtonMenuItem(
128: MenuContainer parentMenu, String menuLabel,
129: DynamicMenuAction action, Character mnemonic,
130: KeyStroke accelerator) {
131: return addRadioButtonMenuItem(parentMenu, menuLabel, action,
132: mnemonic.charValue(), accelerator);
133: }
134:
135: public JRadioButtonMenuItem addRadioButtonMenuItem(
136: MenuContainer parentMenu, String menuLabel,
137: DynamicMenuAction action, char mnemonic) {
138: return addRadioButtonMenuItem(parentMenu, menuLabel, action,
139: mnemonic, null);
140: }
141:
142: public JRadioButtonMenuItem addRadioButtonMenuItem(
143: MenuContainer parentMenu, String menuLabel,
144: DynamicMenuAction action, char mnemonic,
145: KeyStroke accelerator) {
146: return (JRadioButtonMenuItem) processMenuItem(
147: new JRadioButtonMenuItem(menuLabel), parentMenu,
148: action, mnemonic, accelerator);
149: }
150:
151: private JMenuItem processMenuItem(JMenuItem menuItem,
152: MenuContainer parentMenu, DynamicMenuAction action,
153: char mnemonic, KeyStroke accelerator) {
154: menuItem.addActionListener(this );
155: menuItem.putClientProperty("DYNAMICMENUACTION", action);
156: if (0 != mnemonic) {
157: menuItem.setMnemonic(mnemonic);
158: }
159: if (null != accelerator) {
160: menuItem.setAccelerator(accelerator);
161: }
162: if (null != parentMenu) {
163: ((JComponent) parentMenu).add(menuItem);
164: }
165:
166: return menuItem;
167: }
168:
169: public void actionPerformed(ActionEvent e) {
170: Object source = e.getSource();
171: if (source instanceof JMenuItem) {
172: DynamicMenuAction action = (DynamicMenuAction) ((JMenuItem) source)
173: .getClientProperty("DYNAMICMENUACTION");
174: if (null != action) {
175: action.execute((JMenuItem) source);
176: }
177: }
178: }
179: }
|