src/macosx/classes/sun/lwawt/macosx/NSEvent.java

Print this page




  30 /**
  31  * A class representing Cocoa NSEvent class with the fields only necessary for
  32  * JDK functionality.
  33  */
  34 final class NSEvent {
  35     private int type;
  36     private int modifierFlags;
  37 
  38     // Mouse event information
  39     private int clickCount;
  40     private int buttonNumber;
  41     private int x;
  42     private int y;
  43     private double scrollDeltaY;
  44     private double scrollDeltaX;
  45     private int absX;
  46     private int absY;
  47 
  48     // Key event information
  49     private short keyCode;

  50     private String charactersIgnoringModifiers;
  51 
  52     // Called from native
  53     NSEvent(int type, int modifierFlags, short keyCode, String charactersIgnoringModifiers) {
  54         this.type = type;
  55         this.modifierFlags = modifierFlags;
  56         this.keyCode = keyCode;

  57         this.charactersIgnoringModifiers = charactersIgnoringModifiers;
  58     }
  59 
  60     // Called from native
  61     NSEvent(int type, int modifierFlags, int clickCount, int buttonNumber,
  62                    int x, int y, int absX, int absY,
  63                    double scrollDeltaY, double scrollDeltaX) {
  64         this.type = type;
  65         this.modifierFlags = modifierFlags;
  66         this.clickCount = clickCount;
  67         this.buttonNumber = buttonNumber;
  68         this.x = x;
  69         this.y = y;
  70         this.absX = absX;
  71         this.absY = absY;
  72         this.scrollDeltaY = scrollDeltaY;
  73         this.scrollDeltaX = scrollDeltaX;
  74     }
  75 
  76     int getType() {


 104     double getScrollDeltaX() {
 105         return scrollDeltaX;
 106     }
 107 
 108     int getAbsX() {
 109         return absX;
 110     }
 111 
 112     int getAbsY() {
 113         return absY;
 114     }
 115 
 116     short getKeyCode() {
 117         return keyCode;
 118     }
 119 
 120     String getCharactersIgnoringModifiers() {
 121         return charactersIgnoringModifiers;
 122     }
 123 




 124     @Override
 125     public String toString() {
 126         return "NSEvent[" + getType() + " ," + getModifierFlags() + " ,"
 127                 + getClickCount() + " ," + getButtonNumber() + " ," + getX() + " ,"
 128                 + getY() + " ," + getAbsX() + " ," + getAbsY()+ " ," + getKeyCode() + " ,"
 129                 + getCharactersIgnoringModifiers() + "]";
 130     }
 131 
 132     /*
 133      * Converts an NSEvent button number to a MouseEvent constant.
 134      */
 135     static int nsToJavaButton(int buttonNumber) {
 136         int jbuttonNumber = buttonNumber + 1;
 137         switch (buttonNumber) {
 138             case CocoaConstants.kCGMouseButtonLeft:
 139                 jbuttonNumber = MouseEvent.BUTTON1;
 140                 break;
 141             case CocoaConstants.kCGMouseButtonRight:
 142                 jbuttonNumber = MouseEvent.BUTTON3;
 143                 break;
 144             case CocoaConstants.kCGMouseButtonCenter:
 145                 jbuttonNumber = MouseEvent.BUTTON2;
 146                 break;
 147         }
 148         return jbuttonNumber;
 149     }




  30 /**
  31  * A class representing Cocoa NSEvent class with the fields only necessary for
  32  * JDK functionality.
  33  */
  34 final class NSEvent {
  35     private int type;
  36     private int modifierFlags;
  37 
  38     // Mouse event information
  39     private int clickCount;
  40     private int buttonNumber;
  41     private int x;
  42     private int y;
  43     private double scrollDeltaY;
  44     private double scrollDeltaX;
  45     private int absX;
  46     private int absY;
  47 
  48     // Key event information
  49     private short keyCode;
  50     private String characters;
  51     private String charactersIgnoringModifiers;
  52 
  53     // Called from native
  54     NSEvent(int type, int modifierFlags, short keyCode, String characters, String charactersIgnoringModifiers) {
  55         this.type = type;
  56         this.modifierFlags = modifierFlags;
  57         this.keyCode = keyCode;
  58         this.characters = characters;
  59         this.charactersIgnoringModifiers = charactersIgnoringModifiers;
  60     }
  61 
  62     // Called from native
  63     NSEvent(int type, int modifierFlags, int clickCount, int buttonNumber,
  64                    int x, int y, int absX, int absY,
  65                    double scrollDeltaY, double scrollDeltaX) {
  66         this.type = type;
  67         this.modifierFlags = modifierFlags;
  68         this.clickCount = clickCount;
  69         this.buttonNumber = buttonNumber;
  70         this.x = x;
  71         this.y = y;
  72         this.absX = absX;
  73         this.absY = absY;
  74         this.scrollDeltaY = scrollDeltaY;
  75         this.scrollDeltaX = scrollDeltaX;
  76     }
  77 
  78     int getType() {


 106     double getScrollDeltaX() {
 107         return scrollDeltaX;
 108     }
 109 
 110     int getAbsX() {
 111         return absX;
 112     }
 113 
 114     int getAbsY() {
 115         return absY;
 116     }
 117 
 118     short getKeyCode() {
 119         return keyCode;
 120     }
 121 
 122     String getCharactersIgnoringModifiers() {
 123         return charactersIgnoringModifiers;
 124     }
 125 
 126     String getCharacters() {
 127         return characters;
 128     }
 129 
 130     @Override
 131     public String toString() {
 132         return "NSEvent[" + getType() + " ," + getModifierFlags() + " ,"
 133                 + getClickCount() + " ," + getButtonNumber() + " ," + getX() + " ,"
 134                 + getY() + " ," + getAbsX() + " ," + getAbsY()+ " ," + getKeyCode() + " ,"
 135                 + getCharacters() + " ," + getCharactersIgnoringModifiers() + "]";
 136     }
 137 
 138     /*
 139      * Converts an NSEvent button number to a MouseEvent constant.
 140      */
 141     static int nsToJavaButton(int buttonNumber) {
 142         int jbuttonNumber = buttonNumber + 1;
 143         switch (buttonNumber) {
 144             case CocoaConstants.kCGMouseButtonLeft:
 145                 jbuttonNumber = MouseEvent.BUTTON1;
 146                 break;
 147             case CocoaConstants.kCGMouseButtonRight:
 148                 jbuttonNumber = MouseEvent.BUTTON3;
 149                 break;
 150             case CocoaConstants.kCGMouseButtonCenter:
 151                 jbuttonNumber = MouseEvent.BUTTON2;
 152                 break;
 153         }
 154         return jbuttonNumber;
 155     }