Link Here
|
1 |
/* |
2 |
* Sun Public License Notice |
3 |
* |
4 |
* The contents of this file are subject to the Sun Public License |
5 |
* Version 1.0 (the "License"). You may not use this file except in |
6 |
* compliance with the License. A copy of the License is available at |
7 |
* http://www.sun.com/ |
8 |
* |
9 |
* The Original Code is NetBeans. The Initial Developer of the Original |
10 |
* Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun |
11 |
* Microsystems, Inc. All Rights Reserved. |
12 |
*/ |
13 |
/* |
14 |
* SwapCtrlAltAction.java |
15 |
* |
16 |
* Created on October 1, 2004, 1:48 PM |
17 |
*/ |
18 |
|
19 |
package org.netbeans.modules.applemenu; |
20 |
|
21 |
import org.openide.awt.StatusDisplayer; |
22 |
import org.openide.util.HelpCtx; |
23 |
import org.openide.util.NbBundle; |
24 |
import org.openide.util.actions.BooleanStateAction; |
25 |
|
26 |
/** |
27 |
* Apple uses Alt- as the compose key on international keyboards. This causes |
28 |
* a bunch of conflicts with key bindings. There are low level patches in the |
29 |
* editor and window system to swap Ctrl- and Alt- if a system property is set |
30 |
* to true. |
31 |
* <p> |
32 |
* This action toggles the system property <code>nb.mac.swap.ctrl.and.alt</code>, |
33 |
* so that international keyboard users can switch between having alt bindings |
34 |
* and having full use of Alt as a compose key on the mac. |
35 |
* <p> |
36 |
* In a perfect world, we would simply not have any Alt- bindings on the mac, and |
37 |
* use Ctrl as an appropriate substitute. Currently, that is not a realistic |
38 |
* option, as there is no way to detect when an international keyboard is |
39 |
* present, and using Alt- for bindings on U.S. keyboards is very likely the |
40 |
* most intuitive choice (not to mention the docs issues it would cause). |
41 |
* |
42 |
* @author Tim Boudreau |
43 |
* @see org.netbeans.core.windows.ShortcutAndMenuKeyEventProcessor#dispatchKeyEvent |
44 |
* @see org.netbeans.editor.BaseKit.DefaultKeyTypedAction#actionPerformed |
45 |
*/ |
46 |
public class SwapCtrlAltAction extends BooleanStateAction { |
47 |
private static final String PROP_KEY = "nb.mac.swap.ctrl.and.alt"; //NOI18N |
48 |
|
49 |
/** Creates a new instance of SwapCtrlAltAction */ |
50 |
public SwapCtrlAltAction() { |
51 |
|
52 |
} |
53 |
|
54 |
public void actionPerformed (java.awt.event.ActionEvent ev) { |
55 |
super.actionPerformed (ev); |
56 |
boolean hasProp = propSet(); |
57 |
if (hasProp) { |
58 |
System.setProperty(PROP_KEY, "false"); //NOI18N |
59 |
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage( |
60 |
SwapCtrlAltAction.class, "MSG_NotSwapped")); //NOI18N |
61 |
} else { |
62 |
System.setProperty(PROP_KEY, "true"); //NOI18N |
63 |
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage( |
64 |
SwapCtrlAltAction.class, "MSG_Swapped")); //NOI18N |
65 |
} |
66 |
} |
67 |
|
68 |
private boolean propSet () { |
69 |
return Boolean.getBoolean (PROP_KEY); |
70 |
} |
71 |
|
72 |
protected void initialize () { |
73 |
super.initialize(); |
74 |
putProperty(PROP_BOOLEAN_STATE, propSet() ? Boolean.TRUE : Boolean.FALSE); |
75 |
} |
76 |
|
77 |
public HelpCtx getHelpCtx() { |
78 |
return HelpCtx.DEFAULT_HELP; |
79 |
} |
80 |
|
81 |
public String getName() { |
82 |
return NbBundle.getMessage (SwapCtrlAltAction.class, "LBL_SwapCtrlAlt"); //NOI18N |
83 |
} |
84 |
} |