KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > base > CMenuItem


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
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 JavaDoc;
19 import javax.swing.ImageIcon JavaDoc;
20 import javax.swing.JMenuItem JavaDoc;
21
22 import org.columba.core.gui.action.AbstractColumbaAction;
23 import org.columba.core.help.HelpManager;
24
25
26 /**
27  * Default MenuItem which automatically sets a JavaHelp topic ID
28  * based on the AbstractAction name attribute.
29  * <p>
30  * This is necessary to provide a complete context-specific help.
31  *
32  *
33  * @author fdietz
34  */

35
36 public class CMenuItem extends JMenuItem JavaDoc {
37     /**
38      * Creates a menu item with a given action attached.
39      * <br>
40      * If JavaHelp topic ID is defined for the action, help is enabled
41      * for the menu.
42      * <br>
43      * If the name of the action contains &, the next character is used as
44      * mnemonic. If not, the fall-back solution is to use default behaviour,
45      * i.e. the mnemonic defined using setMnemonic on the action.
46      *
47      * @param action The action to attach to the menu item
48      */

49     public CMenuItem(Action JavaDoc action) {
50         super(action);
51
52         // Enable JavaHelp support if topic id is defined
53
String JavaDoc topicID = (String JavaDoc) action.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,
61             (String JavaDoc) action.getValue(Action.NAME));
62
63         // apply transparent icon
64
ImageIcon JavaDoc icon = (ImageIcon JavaDoc) 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 JavaDoc text) {
82         super();
83         MnemonicSetter.setTextWithMnemonic(this, text);
84     }
85 }
86
Popular Tags