01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.core.gui.base;
17:
18: import javax.swing.Action;
19: import javax.swing.ImageIcon;
20: import javax.swing.JMenuItem;
21:
22: import org.columba.core.gui.action.AbstractColumbaAction;
23: import org.columba.core.help.HelpManager;
24:
25: /**
26: * Default MenuItem which automatically sets a JavaHelp topic ID
27: * based on the AbstractAction name attribute.
28: * <p>
29: * This is necessary to provide a complete context-specific help.
30: *
31: *
32: * @author fdietz
33: */
34:
35: public class CMenuItem extends JMenuItem {
36: /**
37: * Creates a menu item with a given action attached.
38: * <br>
39: * If JavaHelp topic ID is defined for the action, help is enabled
40: * for the menu.
41: * <br>
42: * If the name of the action contains &, the next character is used as
43: * mnemonic. If not, the fall-back solution is to use default behaviour,
44: * i.e. the mnemonic defined using setMnemonic on the action.
45: *
46: * @param action The action to attach to the menu item
47: */
48: public CMenuItem(Action action) {
49: super (action);
50:
51: // Enable JavaHelp support if topic id is defined
52: String topicID = (String) action
53: .getValue(AbstractColumbaAction.TOPIC_ID);
54:
55: if (topicID != null) {
56: HelpManager.getInstance().enableHelpOnButton(this , topicID);
57: }
58:
59: // Set text, possibly with a mnemonic if defined using &
60: MnemonicSetter.setTextWithMnemonic(this , (String) action
61: .getValue(Action.NAME));
62:
63: // apply transparent icon
64: ImageIcon icon = (ImageIcon) action.getValue(Action.SMALL_ICON);
65:
66: if (icon != null) {
67: setDisabledIcon(ImageUtil.createTransparentIcon(icon));
68: }
69: }
70:
71: /**
72: * Creates a menu item with the specified text.
73: * <br>
74: * This does <i>not</i> enable JavaHelp support.
75: * <br>
76: * If the textcontains &, the next character is used as
77: * mnemonic. If not, no mnemonic is set.
78: *
79: * @param text Text of menu item
80: */
81: public CMenuItem(String text) {
82: super();
83: MnemonicSetter.setTextWithMnemonic(this, text);
84: }
85: }
|