src/share/classes/java/awt/event/KeyEvent.java

Print this page

        

@@ -928,19 +928,31 @@
 
                 public void setExtendedKeyCode(KeyEvent ev,
                                                long extendedKeyCode) {
                     ev.extendedKeyCode = extendedKeyCode;
                 }
+
+                public Component getOriginalSource( KeyEvent ev ) {
+                    return ev.originalSource;
+                }
             });
     }
 
     /**
      * Initialize JNI field and method IDs for fields that may be
      * accessed from C.
      */
     private static native void initIDs();
 
+    /**
+     * The original event source.
+     *
+     * Event source can be changed during processing, but in some cases
+     * we need to be able to obtain original source.
+     */
+    private Component originalSource;
+
     private KeyEvent(Component source, int id, long when, int modifiers,
                     int keyCode, char keyChar, int keyLocation, boolean isProxyActive) {
         this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
         this.isProxyActive = isProxyActive;
     }

@@ -1021,10 +1033,11 @@
         if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
             setNewModifiers();
         } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
             setOldModifiers();
         }
+        originalSource = source;
     }
 
     /**
      * Constructs a <code>KeyEvent</code> object.
      * <p> This method throws an