01: /*
02: * Copyright (c) 2007, Your Corporation. All Rights Reserved.
03: */
04:
05: package org.pentaho.reportdesigner.lib.client.commands;
06:
07: import org.jetbrains.annotations.NotNull;
08: import org.jetbrains.annotations.Nullable;
09:
10: import javax.swing.*;
11: import java.awt.*;
12:
13: /**
14: * User: Martin
15: * Date: Oct 23, 2007
16: * Time: 9:43:29 PM
17: */
18: public class KeyStrokeUtil {
19: private KeyStrokeUtil() {
20: }
21:
22: @Nullable
23: public static KeyStroke getKeyStroke(@Nullable
24: String keyStroke) {
25: return getKeyStroke(keyStroke, true);
26: }
27:
28: @Nullable
29: public static KeyStroke getKeyStroke(@Nullable
30: String keyStroke, boolean enablePlatformHandling) {
31: if (enablePlatformHandling && keyStroke != null) {
32: String key = getMenuShortcutString();
33: if (!"ctrl".equals(key))//NON-NLS
34: {
35: return KeyStroke.getKeyStroke(keyStroke.replace("ctrl",
36: key));//NON-NLS
37: } else {
38: return KeyStroke.getKeyStroke(keyStroke);
39: }
40: } else {
41: return KeyStroke.getKeyStroke(keyStroke);
42: }
43: }
44:
45: @NotNull
46: private static String getMenuShortcutString() {
47: int keyMask = Toolkit.getDefaultToolkit()
48: .getMenuShortcutKeyMask();
49: if (keyMask == Event.META_MASK) {
50: return "meta";//NON-NLS
51: }
52: return "ctrl";//NON-NLS
53: }
54:
55: @Nullable
56: public static KeyStroke getKeyStroke(int keyCode, int modifiers) {
57: return KeyStroke.getKeyStroke(keyCode, modifiers);
58: }
59:
60: }
|