01: /*
02: * WbMenuItem.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import javax.swing.Action;
15: import javax.swing.Icon;
16: import javax.swing.JMenuItem;
17: import workbench.resource.ResourceMgr;
18:
19: /**
20: *
21: * @author support@sql-workbench.net
22: */
23: public class WbMenuItem extends JMenuItem {
24: public WbMenuItem() {
25: super ();
26: }
27:
28: public WbMenuItem(String aText) {
29: super (aText);
30: }
31:
32: public WbMenuItem(Action anAction) {
33: super (anAction);
34: }
35:
36: public WbMenuItem(String text, int mnemonic) {
37: super (text, mnemonic);
38: }
39:
40: public WbMenuItem(Icon icon) {
41: super (icon);
42: }
43:
44: public WbMenuItem(String text, Icon icon) {
45: super (text, icon);
46: }
47:
48: public void setMenuTextByKey(String key) {
49: this .setText(ResourceMgr.getString(key));
50: this .setToolTipText(ResourceMgr.getDescription(key));
51: }
52:
53: public void setText(String aText) {
54: if (aText == null)
55: return;
56: int pos = aText.indexOf('&');
57: if (pos > -1) {
58: char mnemonic = aText.charAt(pos + 1);
59: if (mnemonic != ' ') {
60: aText = aText.substring(0, pos)
61: + aText.substring(pos + 1);
62: }
63: super .setText(aText);
64: if (mnemonic != ' ' && mnemonic != '&') {
65: this .setMnemonic((int) mnemonic);
66: try {
67: this .setDisplayedMnemonicIndex(pos);
68: } catch (Exception e) {
69: }
70: }
71: } else {
72: super.setText(aText);
73: }
74: }
75:
76: }
|