changeset 2364:dfbafd7a337a

merge
author Martin Sladecek <martin.sladecek@oracle.com>
date Wed, 23 Jan 2013 16:18:56 +0100
parents a471d1c4e9bf 91aa6bcfb3c1
children dbdc1ecd6e86
files
diffstat 12 files changed, 90 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/com/sun/javafx/scene/KeyboardShortcutsHandler.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/src/com/sun/javafx/scene/KeyboardShortcutsHandler.java	Wed Jan 23 16:18:56 2013 +0100
@@ -227,7 +227,7 @@
                     KeyEvent fakeEvent = new KeyEvent(null, event.getTarget(), KeyEvent.KEY_PRESSED,
                                                                 event.getCharacter(),
                                                                 event.getText(),
-                                                                ((KeyCode)event.getCode()).impl_getCode(),
+                                                                event.getCode(),
                                                                 event.isShiftDown(),
                                                                 event.isControlDown(),
                                                                 true,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/javafx-ui-common/src/com/sun/javafx/scene/input/KeyCodeMap.java	Wed Jan 23 16:18:56 2013 +0100
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ * 
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ * 
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ * 
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.sun.javafx.scene.input;
+
+import java.util.HashMap;
+import java.util.Map;
+import javafx.scene.input.KeyCode;
+
+/**
+ * Map from int codes to KeyCode.
+ * Should be removed once RT-20448 is fixed.
+ */
+public final class KeyCodeMap {
+
+    KeyCodeMap() {
+    }
+    
+    private static final Map<Integer, KeyCode> charMap;
+
+    static {
+        charMap = new HashMap<Integer, KeyCode>(KeyCode.values().length);
+
+        for (KeyCode c : KeyCode.values()) {
+            charMap.put(c.impl_getCode(), c);
+        }
+    }
+
+    public static KeyCode valueOf(int code) {
+        return charMap.get(code);
+    }
+}
--- a/javafx-ui-common/src/javafx/scene/Scene.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/src/javafx/scene/Scene.java	Wed Jan 23 16:18:56 2013 +0100
@@ -131,6 +131,7 @@
 
 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGING_ENABLED;
 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGER;
+import com.sun.javafx.scene.input.KeyCodeMap;
 import javafx.geometry.NodeOrientation;
 
 /**
@@ -2292,7 +2293,7 @@
         {
             String chars = new String(cs);
             String text = chars; // TODO: this must be a text like "HOME", "F1", or "A"
-            KeyEvent keyEvent = new KeyEvent(type, chars, text, key,
+            KeyEvent keyEvent = new KeyEvent(type, chars, text, KeyCodeMap.valueOf(key),
                     shiftDown, controlDown, altDown, metaDown);
             impl_processKeyEvent(keyEvent);
         }
--- a/javafx-ui-common/src/javafx/scene/input/KeyCode.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/src/javafx/scene/input/KeyCode.java	Wed Jan 23 16:18:56 2013 +0100
@@ -1312,21 +1312,16 @@
         return code;
     }
 
-    private static final Map<Integer, KeyCode> charMap;
+   
     private static final Map<String, KeyCode> nameMap;
     static {
-        charMap = new HashMap<Integer, KeyCode>(KeyCode.values().length);
+        
         nameMap = new HashMap<String, KeyCode>(KeyCode.values().length);
         for (KeyCode c : KeyCode.values()) {
-            charMap.put(c.code, c);
             nameMap.put(c.name, c);
         }
     }
 
-    static KeyCode valueOf(int code) {
-        return charMap.get(code);
-    }
-
     /**
      * Parses textual representation of a key.
      * @param name Textual representation of the key
--- a/javafx-ui-common/src/javafx/scene/input/KeyEvent.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/src/javafx/scene/input/KeyEvent.java	Wed Jan 23 16:18:56 2013 +0100
@@ -32,6 +32,7 @@
 
 import com.sun.javafx.robot.impl.FXRobotHelper;
 import com.sun.javafx.robot.impl.FXRobotHelper.FXRobotInputAccessor;
+import com.sun.javafx.scene.input.KeyCodeMap;
 import javafx.event.Event;
 import javafx.scene.input.ScrollEvent.HorizontalTextScrollUnits;
 import javafx.scene.input.ScrollEvent.VerticalTextScrollUnits;
@@ -117,7 +118,7 @@
                 return keyCode.code;
             }
             @Override public KeyCode getKeyCodeForCode(int code) {
-                return KeyCode.valueOf(code);
+                return KeyCodeMap.valueOf(code);
             }
             @Override public KeyEvent createKeyEvent(
                 EventType<? extends KeyEvent> eventType,
@@ -171,26 +172,8 @@
         FXRobotHelper.setInputAccessor(a);
     }
 
-
     /**
-     * Constructs new KeyEvent event with null source and target.
-     * @param eventType The type of the event.
-     * @param character The character or sequence of characters associated with the event
-     * @param text A String describing the key code
-     * @param code The integer key code
-     * @param shiftDown true if shift modifier was pressed.
-     * @param controlDown true if control modifier was pressed.
-     * @param altDown true if alt modifier was pressed.
-     * @param metaDown true if meta modifier was pressed.
-     */
-    public KeyEvent(EventType<KeyEvent> eventType, String character,
-            String text, int code, boolean shiftDown, boolean controlDown,
-            boolean altDown, boolean metaDown) {
-        this(null, null, eventType, character, text, code, shiftDown, controlDown, altDown, metaDown);
-    }
-
-    /**
-     * Constructs new KeyEvent event.
+     * Constructs new KeyEvent event with null source and target and KeyCode object directly specified.
      * @param source the source of the event. Can be null.
      * @param target the target of the event. Can be null.
      * @param eventType The type of the event.
@@ -203,14 +186,14 @@
      * @param metaDown true if meta modifier was pressed.
      */
     public KeyEvent(Object source, EventTarget target, EventType<KeyEvent> eventType, String character,
-            String text, int code, boolean shiftDown, boolean controlDown,
+            String text, KeyCode code, boolean shiftDown, boolean controlDown,
             boolean altDown, boolean metaDown) {
         super(source, target, eventType);
         boolean isKeyTyped = eventType == KEY_TYPED;
 
         this.character = isKeyTyped ? character : KeyEvent.CHAR_UNDEFINED;
         this.text = isKeyTyped ? "" : text;
-        this.code = isKeyTyped ? KeyCode.UNDEFINED : KeyCode.valueOf(code);
+        this.code = isKeyTyped ? KeyCode.UNDEFINED : code;
         this.shiftDown = shiftDown;
         this.controlDown = controlDown;
         this.altDown = altDown;
--- a/javafx-ui-common/test/unit/javafx/scene/Scenegraph_eventHandlers_Test.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/test/unit/javafx/scene/Scenegraph_eventHandlers_Test.java	Wed Jan 23 16:18:56 2013 +0100
@@ -340,7 +340,7 @@
         }
 
         return new KeyEvent(keyEventType, character, text,
-                                      keyCode.impl_getCode(),
+                                      keyCode,
                                       false, false, false, false);
     }
 
--- a/javafx-ui-common/test/unit/javafx/scene/input/KeyCodeTest.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/test/unit/javafx/scene/input/KeyCodeTest.java	Wed Jan 23 16:18:56 2013 +0100
@@ -25,6 +25,7 @@
 
 package javafx.scene.input;
 
+import com.sun.javafx.scene.input.KeyCodeMap;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
@@ -45,7 +46,7 @@
     @Test
     public void shouldFindCorrectCode() {
         for (KeyCode code : KeyCode.values()) {
-            assertSame(code, KeyCode.valueOf(code.impl_getCode()));
+            assertSame(code, KeyCodeMap.valueOf(code.impl_getCode()));
         }
     }
 }
--- a/javafx-ui-common/test/unit/javafx/scene/input/KeyCombinationTest.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/test/unit/javafx/scene/input/KeyCombinationTest.java	Wed Jan 23 16:18:56 2013 +0100
@@ -45,39 +45,40 @@
 import org.junit.Test;
 
 import com.sun.javafx.pgstub.StubToolkit;
+import com.sun.javafx.scene.input.KeyCodeMap;
 import com.sun.javafx.tk.Toolkit;
 
 
 public class KeyCombinationTest {
     final KeyEvent ctrlAltQEvent = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "q", null, 0x51, false, true, true, false);
+            "q", null, KeyCodeMap.valueOf(0x51), false, true, true, false);
 
     final KeyEvent ctrlAltQUpEvent = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_RELEASED, 
-            "q", null, 0x51, false, true, true, false);
+            "q", null, KeyCodeMap.valueOf(0x51), false, true, true, false);
 
     final KeyEvent ctrlShiftQEvent = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "Q", null, 0x51, true, true, false, false);
+            "Q", null, KeyCodeMap.valueOf(0x51), true, true, false, false);
 
     final KeyEvent ctrlAltShiftQEvent = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "Q", null, 0x51, true, true, true, false);
+            "Q", null, KeyCodeMap.valueOf(0x51), true, true, true, false);
 
     final KeyEvent alt2Event = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "2", null, 0x32, false, false, true, false);
+            "2", null, KeyCodeMap.valueOf(0x32), false, false, true, false);
 
     final KeyEvent altShift2Event = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "@", null, 0x32, true, false, true, false);
+            "@", null, KeyCodeMap.valueOf(0x32), true, false, true, false);
 
     final KeyEvent altSoftkey0Event = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "~", null, 0x1000, false, false, true, false);
+            "~", null, KeyCodeMap.valueOf(0x1000), false, false, true, false);
 
     final KeyEvent altShiftSoftkey0Event = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "~", null, 0x1000, true, false, true, false);
+            "~", null, KeyCodeMap.valueOf(0x1000), true, false, true, false);
 
     final KeyEvent altShiftPlusEvent = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "~", null, 0x209, true, false, true, false);
+            "~", null, KeyCodeMap.valueOf(0x209), true, false, true, false);
 
     final KeyEvent altShiftQuoteEvent = new KeyEvent(null, Event.NULL_SOURCE_TARGET, KeyEvent.KEY_PRESSED, 
-            "~", null, 0xDE, true, false, true, false);
+            "~", null, KeyCodeMap.valueOf(0xDE), true, false, true, false);
 
     @BeforeClass
     public static void setUpCharToKeyCodeMap() {
@@ -315,15 +316,15 @@
     public void testKeyCombinationWithShortcutModifier() {
         final KeyEvent ctrlC = new KeyEvent(
                                    KeyEvent.KEY_PRESSED,
-                                   "c", null, 0x43,
+                                   "c", null, KeyCodeMap.valueOf(0x43),
                                    false, true, false, false);
         final KeyEvent metaC = new KeyEvent(
                                    KeyEvent.KEY_PRESSED,
-                                   "c", null, 0x43,
+                                   "c", null, KeyCodeMap.valueOf(0x43),
                                    false, false, false, true);
         final KeyEvent metaAltC = new KeyEvent(
                                    KeyEvent.KEY_PRESSED,
-                                      "c", null, 0x43,
+                                      "c", null, KeyCodeMap.valueOf(0x43),
                                       false, false, true, true);
 
         final KeyCombination shortcutC =
--- a/javafx-ui-common/test/unit/javafx/scene/input/KeyEventTest.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/test/unit/javafx/scene/input/KeyEventTest.java	Wed Jan 23 16:18:56 2013 +0100
@@ -25,6 +25,7 @@
 
 package javafx.scene.input;
 
+import com.sun.javafx.scene.input.KeyCodeMap;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -41,12 +42,12 @@
     private final Node node2 = new TestNode();
     
     public KeyEvent testKeyEvent(EventTarget target, String character, KeyCode code, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown) {
-        return new KeyEvent(null, target, KeyEvent.KEY_PRESSED, character, null, code.impl_getCode(), shiftDown, controlDown, altDown, metaDown);
+        return new KeyEvent(null, target, KeyEvent.KEY_PRESSED, character, null, code, shiftDown, controlDown, altDown, metaDown);
     }
 
     @Test
     public void shouldCreateKeyTypedEvent() {
-        KeyEvent event = new KeyEvent(null, node1, KeyEvent.KEY_TYPED, "A", "A", 0x41, true,
+        KeyEvent event = new KeyEvent(null, node1, KeyEvent.KEY_TYPED, "A", "A", KeyCodeMap.valueOf(0x41), true,
                 false, false, false);
 
         assertSame(node1, event.getTarget());
@@ -62,7 +63,7 @@
 
     @Test
     public void shouldCreateKeyReleasedEvent() {
-        KeyEvent event = new KeyEvent(null, node1, KeyEvent.KEY_RELEASED, "A", "A", 0x41, true,
+        KeyEvent event = new KeyEvent(null, node1, KeyEvent.KEY_RELEASED, "A", "A", KeyCodeMap.valueOf(0x41), true,
                 false, false, false);
 
         assertSame(node1, event.getTarget());
@@ -78,7 +79,7 @@
 
     @Test
     public void shouldCopyKeyTypedEvent() {
-        KeyEvent original = new KeyEvent(null, node1, KeyEvent.KEY_TYPED, "A", "A", 0x41, true,
+        KeyEvent original = new KeyEvent(null, node1, KeyEvent.KEY_TYPED, "A", "A", KeyCodeMap.valueOf(0x41), true,
                 false, false, false);
         KeyEvent event = original.copyFor(null, node2);
 
--- a/javafx-ui-common/test/unit/javafx/stage/PopupTest.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-common/test/unit/javafx/stage/PopupTest.java	Wed Jan 23 16:18:56 2013 +0100
@@ -448,7 +448,7 @@
                             new KeyEvent(null, stage,
                                 KeyEvent.KEY_PRESSED, KeyEvent.CHAR_UNDEFINED,
                                 KeyCode.ESCAPE.getName(),
-                                KeyCode.ESCAPE.impl_getCode(),
+                                KeyCode.ESCAPE,
                                 false, false, false, false));
             assertEquals(0, keyEventCounter.getValue());
 
@@ -466,7 +466,7 @@
                                 KeyEvent.KEY_PRESSED,
                                 KeyEvent.CHAR_UNDEFINED,
                                 KeyCode.ESCAPE.getName(),
-                                KeyCode.ESCAPE.impl_getCode(),
+                                KeyCode.ESCAPE,
                                 false, false, false, false));
             assertEquals(1, keyEventCounter.getValue());
             
--- a/javafx-ui-controls/test/javafx/scene/control/KeyEventFirer.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-controls/test/javafx/scene/control/KeyEventFirer.java	Wed Jan 23 16:18:56 2013 +0100
@@ -61,7 +61,7 @@
                 evtType,  // eventType
                 null,     // Character (unused unless KeyCode == KEY_TYPED
                 null,     // text
-                keyCode.impl_getCode(), // KeyCode
+                keyCode, // KeyCode
                 ml.contains(KeyModifier.SHIFT),                                   // shiftDown
                 ml.contains(KeyModifier.CTRL),                                    // ctrlDown
                 ml.contains(KeyModifier.ALT),                                     // altDown
--- a/javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java	Wed Jan 23 10:23:26 2013 +0100
+++ b/javafx-ui-controls/test/javafx/scene/control/TabPaneTest.java	Wed Jan 23 16:18:56 2013 +0100
@@ -8,6 +8,7 @@
 import static javafx.scene.control.ControlTestUtils.*;
 import com.sun.javafx.pgstub.StubToolkit;
 import com.sun.javafx.scene.control.skin.TabPaneSkin;
+import com.sun.javafx.scene.input.KeyCodeMap;
 import com.sun.javafx.tk.Toolkit;
 import javafx.application.Platform;
 import javafx.beans.property.BooleanProperty;
@@ -817,7 +818,7 @@
         stage.show();
         stage.requestFocus();
 
-        final KeyEvent tabEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "", "", 0x09,
+        final KeyEvent tabEvent = new KeyEvent(KeyEvent.KEY_PRESSED, "", "", KeyCodeMap.valueOf(0x09),
                                                          false, false, false, false);
         Platform.runLater(new Runnable() {
             @Override public void run() {