Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyStrokeMappings.java49
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout.java17
-rw-r--r--org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout_en.java139
3 files changed, 205 insertions, 0 deletions
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyStrokeMappings.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyStrokeMappings.java
new file mode 100644
index 00000000..1af3149f
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyStrokeMappings.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Ketan Padegaonkar and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ketan Padegaonkar - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swtbot.swt.finder.keyboard;
+
+import static java.awt.event.KeyEvent.*;
+import static org.eclipse.swtbot.swt.finder.keyboard.KeyStrokeMapping.mapping;
+import static org.eclipse.swtbot.swt.finder.keyboard.KeyStrokeMapping.Modifier.NO_MASK;
+import static org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.*;
+import static org.eclipse.swtbot.swt.finder.utils.OS.isWindows;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Provides for default mappings for the whitespace (\r, \n, \b, SPACE, \t) characters.
+ *
+ * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
+ */
+final class KeyStrokeMappings {
+
+ static Collection<KeyStrokeMapping> createMappings() {
+ Set<KeyStrokeMapping> mappings = new HashSet<KeyStrokeMapping>();
+
+ mappings.add(mapping(LF, VK_ENTER, NO_MASK));
+ if (isWindows())
+ mappings.add(mapping(CR, VK_ENTER, NO_MASK));
+
+ mappings.add(mapping(TAB, VK_TAB, NO_MASK));
+
+ mappings.add(mapping(BKSP, VK_BACK_SPACE, NO_MASK));
+ mappings.add(mapping(DELETE, VK_DELETE, NO_MASK));
+
+ mappings.add(mapping(ESC, VK_ESCAPE, NO_MASK));
+
+ mappings.add(mapping(SPACE, VK_SPACE, NO_MASK));
+
+ return mappings;
+ }
+
+}
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout.java
new file mode 100644
index 00000000..731f3a3a
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout.java
@@ -0,0 +1,17 @@
+package org.eclipse.swtbot.swt.finder.keyboard;
+
+import java.util.Collection;
+
+public interface KeyboardLayout {
+
+ public static final char TAB = '\t';
+ public static final char LF = '\n';
+ public static final char CR = '\r';
+ public static final char BKSP = '\b';
+ public static final char SPACE = ' ';
+
+ public static final char DELETE = 0x7F;
+ public static final char ESC = 0x1B;
+
+ Collection<KeyStrokeMapping> layout();
+}
diff --git a/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout_en.java b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout_en.java
new file mode 100644
index 00000000..ffb17e21
--- /dev/null
+++ b/org.eclipse.swtbot.swt.finder/src/org/eclipse/swtbot/swt/finder/keyboard/KeyboardLayout_en.java
@@ -0,0 +1,139 @@
+package org.eclipse.swtbot.swt.finder.keyboard;
+
+import static java.awt.event.InputEvent.SHIFT_MASK;
+import static java.awt.event.KeyEvent.*;
+import static org.eclipse.swtbot.swt.finder.keyboard.KeyStrokeMapping.mapping;
+import static org.eclipse.swtbot.swt.finder.keyboard.KeyStrokeMapping.Modifier.NO_MASK;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+public class KeyboardLayout_en implements KeyboardLayout {
+
+ private static final Collection<KeyStrokeMapping> mappings = Collections.unmodifiableCollection(createMappings());
+
+ public Collection<KeyStrokeMapping> layout() {
+ return mappings;
+ }
+
+ private static Collection<KeyStrokeMapping> createMappings() {
+ Set<KeyStrokeMapping> mappings = new HashSet<KeyStrokeMapping>();
+ mappings.addAll(KeyStrokeMappings.createMappings());
+
+ // numbers 0-9
+ mappings.add(mapping('0', VK_0, NO_MASK));
+ mappings.add(mapping('1', VK_1, NO_MASK));
+ mappings.add(mapping('2', VK_2, NO_MASK));
+ mappings.add(mapping('3', VK_3, NO_MASK));
+ mappings.add(mapping('4', VK_4, NO_MASK));
+ mappings.add(mapping('5', VK_5, NO_MASK));
+ mappings.add(mapping('6', VK_6, NO_MASK));
+ mappings.add(mapping('7', VK_7, NO_MASK));
+ mappings.add(mapping('8', VK_8, NO_MASK));
+ mappings.add(mapping('9', VK_9, NO_MASK));
+
+ // symbols corresponding to 0-9
+ mappings.add(mapping(')', VK_0, SHIFT_MASK));
+ mappings.add(mapping('!', VK_1, SHIFT_MASK));
+ mappings.add(mapping('@', VK_2, SHIFT_MASK));
+ mappings.add(mapping('#', VK_3, SHIFT_MASK));
+ mappings.add(mapping('$', VK_4, SHIFT_MASK));
+ mappings.add(mapping('%', VK_5, SHIFT_MASK));
+ mappings.add(mapping('^', VK_6, SHIFT_MASK));
+ mappings.add(mapping('&', VK_7, SHIFT_MASK));
+ mappings.add(mapping('*', VK_8, SHIFT_MASK));
+ mappings.add(mapping('(', VK_9, SHIFT_MASK));
+
+ // a-z small
+ mappings.add(mapping('a', VK_A, NO_MASK));
+ mappings.add(mapping('b', VK_B, NO_MASK));
+ mappings.add(mapping('c', VK_C, NO_MASK));
+ mappings.add(mapping('d', VK_D, NO_MASK));
+ mappings.add(mapping('e', VK_E, NO_MASK));
+ mappings.add(mapping('f', VK_F, NO_MASK));
+ mappings.add(mapping('g', VK_G, NO_MASK));
+ mappings.add(mapping('h', VK_H, NO_MASK));
+ mappings.add(mapping('i', VK_I, NO_MASK));
+ mappings.add(mapping('j', VK_J, NO_MASK));
+ mappings.add(mapping('k', VK_K, NO_MASK));
+ mappings.add(mapping('l', VK_L, NO_MASK));
+ mappings.add(mapping('m', VK_M, NO_MASK));
+ mappings.add(mapping('n', VK_N, NO_MASK));
+ mappings.add(mapping('o', VK_O, NO_MASK));
+ mappings.add(mapping('p', VK_P, NO_MASK));
+ mappings.add(mapping('q', VK_Q, NO_MASK));
+ mappings.add(mapping('r', VK_R, NO_MASK));
+ mappings.add(mapping('s', VK_S, NO_MASK));
+ mappings.add(mapping('t', VK_T, NO_MASK));
+ mappings.add(mapping('u', VK_U, NO_MASK));
+ mappings.add(mapping('v', VK_V, NO_MASK));
+ mappings.add(mapping('w', VK_W, NO_MASK));
+ mappings.add(mapping('x', VK_X, NO_MASK));
+ mappings.add(mapping('y', VK_Y, NO_MASK));
+ mappings.add(mapping('z', VK_Z, NO_MASK));
+
+ // a-z capital
+ mappings.add(mapping('A', VK_A, SHIFT_MASK));
+ mappings.add(mapping('B', VK_B, SHIFT_MASK));
+ mappings.add(mapping('C', VK_C, SHIFT_MASK));
+ mappings.add(mapping('D', VK_D, SHIFT_MASK));
+ mappings.add(mapping('E', VK_E, SHIFT_MASK));
+ mappings.add(mapping('F', VK_F, SHIFT_MASK));
+ mappings.add(mapping('G', VK_G, SHIFT_MASK));
+ mappings.add(mapping('H', VK_H, SHIFT_MASK));
+ mappings.add(mapping('I', VK_I, SHIFT_MASK));
+ mappings.add(mapping('J', VK_J, SHIFT_MASK));
+ mappings.add(mapping('K', VK_K, SHIFT_MASK));
+ mappings.add(mapping('L', VK_L, SHIFT_MASK));
+ mappings.add(mapping('M', VK_M, SHIFT_MASK));
+ mappings.add(mapping('N', VK_N, SHIFT_MASK));
+ mappings.add(mapping('O', VK_O, SHIFT_MASK));
+ mappings.add(mapping('P', VK_P, SHIFT_MASK));
+ mappings.add(mapping('Q', VK_Q, SHIFT_MASK));
+ mappings.add(mapping('R', VK_R, SHIFT_MASK));
+ mappings.add(mapping('S', VK_S, SHIFT_MASK));
+ mappings.add(mapping('T', VK_T, SHIFT_MASK));
+ mappings.add(mapping('U', VK_U, SHIFT_MASK));
+ mappings.add(mapping('V', VK_V, SHIFT_MASK));
+ mappings.add(mapping('W', VK_W, SHIFT_MASK));
+ mappings.add(mapping('X', VK_X, SHIFT_MASK));
+ mappings.add(mapping('Y', VK_Y, SHIFT_MASK));
+ mappings.add(mapping('Z', VK_Z, SHIFT_MASK));
+
+ // special characters
+ mappings.add(mapping('`', VK_BACK_QUOTE, NO_MASK));
+ mappings.add(mapping('-', VK_MINUS, NO_MASK));
+ mappings.add(mapping('=', VK_EQUALS, NO_MASK));
+
+ mappings.add(mapping('[', VK_OPEN_BRACKET, NO_MASK));
+ mappings.add(mapping(']', VK_CLOSE_BRACKET, NO_MASK));
+ mappings.add(mapping('\\', VK_BACK_SLASH, NO_MASK));
+
+ mappings.add(mapping(';', VK_SEMICOLON, NO_MASK));
+ mappings.add(mapping('\'', VK_QUOTE, NO_MASK));
+
+ mappings.add(mapping(',', VK_COMMA, NO_MASK));
+ mappings.add(mapping('.', VK_PERIOD, NO_MASK));
+ mappings.add(mapping('/', VK_SLASH, NO_MASK));
+
+ // special characters (with SHIFT key)
+ mappings.add(mapping('~', VK_BACK_QUOTE, SHIFT_MASK));
+ mappings.add(mapping('_', VK_MINUS, SHIFT_MASK));
+ mappings.add(mapping('+', VK_EQUALS, SHIFT_MASK));
+
+ mappings.add(mapping('{', VK_OPEN_BRACKET, SHIFT_MASK));
+ mappings.add(mapping('}', VK_CLOSE_BRACKET, SHIFT_MASK));
+ mappings.add(mapping('|', VK_BACK_SLASH, SHIFT_MASK));
+
+ mappings.add(mapping(':', VK_SEMICOLON, SHIFT_MASK));
+ mappings.add(mapping('"', VK_QUOTE, SHIFT_MASK));
+
+ mappings.add(mapping('<', VK_COMMA, SHIFT_MASK));
+ mappings.add(mapping('>', VK_PERIOD, SHIFT_MASK));
+ mappings.add(mapping('?', VK_SLASH, SHIFT_MASK));
+
+ return mappings;
+ }
+}

Back to the top