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

Print this page




 913         NativeLibLoader.loadLibraries();
 914         if (!GraphicsEnvironment.isHeadless()) {
 915             initIDs();
 916         }
 917 
 918         AWTAccessor.setKeyEventAccessor(
 919             new AWTAccessor.KeyEventAccessor() {
 920                 public void setRawCode(KeyEvent ev, long rawCode) {
 921                     ev.rawCode = rawCode;
 922                 }
 923 
 924                 public void setPrimaryLevelUnicode(KeyEvent ev,
 925                                                    long primaryLevelUnicode) {
 926                     ev.primaryLevelUnicode = primaryLevelUnicode;
 927                 }
 928 
 929                 public void setExtendedKeyCode(KeyEvent ev,
 930                                                long extendedKeyCode) {
 931                     ev.extendedKeyCode = extendedKeyCode;
 932                 }




 933             });
 934     }
 935 
 936     /**
 937      * Initialize JNI field and method IDs for fields that may be
 938      * accessed from C.
 939      */
 940     private static native void initIDs();
 941 








 942     private KeyEvent(Component source, int id, long when, int modifiers,
 943                     int keyCode, char keyChar, int keyLocation, boolean isProxyActive) {
 944         this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
 945         this.isProxyActive = isProxyActive;
 946     }
 947 
 948     /**
 949      * Constructs a <code>KeyEvent</code> object.
 950      * <p>This method throws an
 951      * <code>IllegalArgumentException</code> if <code>source</code>
 952      * is <code>null</code>.
 953      *
 954      * @param source    The <code>Component</code> that originated the event
 955      * @param id              An integer indicating the type of event.
 956      *                  For information on allowable values, see
 957      *                  the class description for {@link KeyEvent}
 958      * @param when      A long integer that specifies the time the event
 959      *                  occurred.
 960      *                     Passing negative or zero value
 961      *                     is not recommended


1006                 throw new IllegalArgumentException("invalid keyCode");
1007             }
1008             if (keyLocation != KEY_LOCATION_UNKNOWN) {
1009                 throw new IllegalArgumentException("invalid keyLocation");
1010             }
1011         }
1012 
1013         this.keyCode = keyCode;
1014         this.keyChar = keyChar;
1015 
1016         if ((keyLocation < KEY_LOCATION_UNKNOWN) ||
1017             (keyLocation > KEY_LOCATION_NUMPAD)) {
1018             throw new IllegalArgumentException("invalid keyLocation");
1019         }
1020         this.keyLocation = keyLocation;
1021         if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
1022             setNewModifiers();
1023         } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
1024             setOldModifiers();
1025         }

1026     }
1027 
1028     /**
1029      * Constructs a <code>KeyEvent</code> object.
1030      * <p> This method throws an
1031      * <code>IllegalArgumentException</code> if <code>source</code>
1032      * is <code>null</code>.
1033      *
1034      * @param source    The <code>Component</code> that originated the event
1035      * @param id              An integer indicating the type of event.
1036      *                  For information on allowable values, see
1037      *                  the class description for {@link KeyEvent}
1038      * @param when      A long integer that specifies the time the event
1039      *                  occurred.
1040      *                     Passing negative or zero value
1041      *                     is not recommended
1042      * @param modifiers The modifier keys down during event (shift, ctrl,
1043      *                  alt, meta).
1044      *                     Passing negative value
1045      *                     is not recommended.




 913         NativeLibLoader.loadLibraries();
 914         if (!GraphicsEnvironment.isHeadless()) {
 915             initIDs();
 916         }
 917 
 918         AWTAccessor.setKeyEventAccessor(
 919             new AWTAccessor.KeyEventAccessor() {
 920                 public void setRawCode(KeyEvent ev, long rawCode) {
 921                     ev.rawCode = rawCode;
 922                 }
 923 
 924                 public void setPrimaryLevelUnicode(KeyEvent ev,
 925                                                    long primaryLevelUnicode) {
 926                     ev.primaryLevelUnicode = primaryLevelUnicode;
 927                 }
 928 
 929                 public void setExtendedKeyCode(KeyEvent ev,
 930                                                long extendedKeyCode) {
 931                     ev.extendedKeyCode = extendedKeyCode;
 932                 }
 933 
 934                 public Component getOriginalSource( KeyEvent ev ) {
 935                     return ev.originalSource;
 936                 }
 937             });
 938     }
 939 
 940     /**
 941      * Initialize JNI field and method IDs for fields that may be
 942      * accessed from C.
 943      */
 944     private static native void initIDs();
 945 
 946     /**
 947      * The original event source.
 948      *
 949      * Event source can be changed during processing, but in some cases
 950      * we need to be able to obtain original source.
 951      */
 952     private Component originalSource;
 953 
 954     private KeyEvent(Component source, int id, long when, int modifiers,
 955                     int keyCode, char keyChar, int keyLocation, boolean isProxyActive) {
 956         this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
 957         this.isProxyActive = isProxyActive;
 958     }
 959 
 960     /**
 961      * Constructs a <code>KeyEvent</code> object.
 962      * <p>This method throws an
 963      * <code>IllegalArgumentException</code> if <code>source</code>
 964      * is <code>null</code>.
 965      *
 966      * @param source    The <code>Component</code> that originated the event
 967      * @param id              An integer indicating the type of event.
 968      *                  For information on allowable values, see
 969      *                  the class description for {@link KeyEvent}
 970      * @param when      A long integer that specifies the time the event
 971      *                  occurred.
 972      *                     Passing negative or zero value
 973      *                     is not recommended


1018                 throw new IllegalArgumentException("invalid keyCode");
1019             }
1020             if (keyLocation != KEY_LOCATION_UNKNOWN) {
1021                 throw new IllegalArgumentException("invalid keyLocation");
1022             }
1023         }
1024 
1025         this.keyCode = keyCode;
1026         this.keyChar = keyChar;
1027 
1028         if ((keyLocation < KEY_LOCATION_UNKNOWN) ||
1029             (keyLocation > KEY_LOCATION_NUMPAD)) {
1030             throw new IllegalArgumentException("invalid keyLocation");
1031         }
1032         this.keyLocation = keyLocation;
1033         if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
1034             setNewModifiers();
1035         } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
1036             setOldModifiers();
1037         }
1038         originalSource = source;
1039     }
1040 
1041     /**
1042      * Constructs a <code>KeyEvent</code> object.
1043      * <p> This method throws an
1044      * <code>IllegalArgumentException</code> if <code>source</code>
1045      * is <code>null</code>.
1046      *
1047      * @param source    The <code>Component</code> that originated the event
1048      * @param id              An integer indicating the type of event.
1049      *                  For information on allowable values, see
1050      *                  the class description for {@link KeyEvent}
1051      * @param when      A long integer that specifies the time the event
1052      *                  occurred.
1053      *                     Passing negative or zero value
1054      *                     is not recommended
1055      * @param modifiers The modifier keys down during event (shift, ctrl,
1056      *                  alt, meta).
1057      *                     Passing negative value
1058      *                     is not recommended.