| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
package org.fest.swing.keystroke; |
| 16 |
|
|
| 17 |
|
import static java.awt.event.InputEvent.SHIFT_MASK; |
| 18 |
|
import static java.awt.event.KeyEvent.CHAR_UNDEFINED; |
| 19 |
|
import static org.fest.swing.util.Platform.osFamily; |
| 20 |
|
|
| 21 |
|
import java.util.Locale; |
| 22 |
|
|
| 23 |
|
import javax.swing.KeyStroke; |
| 24 |
|
|
| 25 |
|
import org.fest.util.VisibleForTesting; |
| 26 |
|
|
| 27 |
|
|
| 28 |
|
@link |
| 29 |
|
|
| 30 |
|
@author |
| 31 |
|
@author |
| 32 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 12 |
Complexity Density: 0.63 |
|
| 33 |
|
public class KeyStrokeMap { |
| 34 |
|
|
| 35 |
|
private static KeyStrokeMapCollection maps = new KeyStrokeMapCollection(); |
| 36 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 37 |
21
|
static {... |
| 38 |
21
|
reloadFromSystemSettings(); |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
@deprecated@link |
| 44 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 45 |
|
@Deprecated... |
| 46 |
|
public static void reloadFromLocale() { |
| 47 |
|
reloadFromSystemSettings(); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@since |
| 53 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 54 |
25
|
public static void reloadFromSystemSettings() {... |
| 55 |
25
|
KeyStrokeMappingProviderPicker picker = new KeyStrokeMappingProviderPicker(); |
| 56 |
25
|
maps.clear(); |
| 57 |
25
|
addKeyStrokesFrom(picker.providerFor(osFamily(), Locale.getDefault())); |
| 58 |
|
} |
| 59 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 60 |
6
|
@VisibleForTesting... |
| 61 |
|
static void updateKeyStrokeMapCollection(KeyStrokeMapCollection c) { |
| 62 |
6
|
maps = c; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
@link |
| 67 |
|
@link |
| 68 |
|
@param |
| 69 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 70 |
27
|
public static void addKeyStrokesFrom(KeyStrokeMappingProvider provider) {... |
| 71 |
27
|
for (KeyStrokeMapping entry : provider.keyStrokeMappings()) |
| 72 |
2527
|
add(entry.character(), entry.keyStroke()); |
| 73 |
|
} |
| 74 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 75 |
2527
|
private static void add(Character character, KeyStroke keyStroke) {... |
| 76 |
2527
|
maps.add(character, keyStroke); |
| 77 |
|
} |
| 78 |
|
|
| 79 |
|
|
| 80 |
|
@link |
| 81 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
4
|
public static void clearKeyStrokes() {... |
| 83 |
4
|
maps.clear(); |
| 84 |
|
} |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
@link |
| 88 |
|
@return |
| 89 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 90 |
4
|
public static boolean hasKeyStrokes() {... |
| 91 |
4
|
return !maps.isEmpty(); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
@link |
| 96 |
|
|
| 97 |
|
@param |
| 98 |
|
@return |
| 99 |
|
|
| 100 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 101 |
86
|
public static KeyStroke keyStrokeFor(char character) {... |
| 102 |
86
|
return maps.keyStrokeFor(character); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
|
| 106 |
|
@link |
| 107 |
|
|
| 108 |
|
@link |
| 109 |
|
@param |
| 110 |
|
@return |
| 111 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 112 |
3
|
public static char charFor(KeyStroke keyStroke) {... |
| 113 |
3
|
Character character = maps.charFor(keyStroke); |
| 114 |
|
|
| 115 |
2
|
if (character == null) character = charWithoutModifiersButShift(keyStroke); |
| 116 |
1
|
if (character == null) return CHAR_UNDEFINED; |
| 117 |
2
|
return character.charValue(); |
| 118 |
|
} |
| 119 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 120 |
2
|
private static Character charWithoutModifiersButShift(KeyStroke keyStroke) {... |
| 121 |
2
|
int mask = keyStroke.getModifiers() & ~SHIFT_MASK; |
| 122 |
2
|
return maps.charFor(KeyStroke.getKeyStroke(keyStroke.getKeyCode(), mask)); |
| 123 |
|
} |
| 124 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 125 |
|
private KeyStrokeMap() {}... |
| 126 |
|
} |