package sun.lwawt.macosx;
import java.awt.event.*;
final class NSEvent {
static final int SCROLL_PHASE_UNSUPPORTED = 1;
static final int SCROLL_PHASE_BEGAN = 2;
static final int SCROLL_PHASE_CONTINUED = 3;
static final int SCROLL_PHASE_MOMENTUM_BEGAN = 4;
static final int SCROLL_PHASE_ENDED = 5;
private int type;
private int modifierFlags;
private int clickCount;
private int buttonNumber;
private int x;
private int y;
private double scrollDeltaY;
private double scrollDeltaX;
private int scrollPhase;
private int absX;
private int absY;
private short keyCode;
private String characters;
private String charactersIgnoringModifiers;
NSEvent(int type, int modifierFlags, short keyCode, String characters, String charactersIgnoringModifiers) {
this.type = type;
this.modifierFlags = modifierFlags;
this.keyCode = keyCode;
this.characters = characters;
this.charactersIgnoringModifiers = charactersIgnoringModifiers;
}
NSEvent(int type, int modifierFlags, int clickCount, int buttonNumber,
int x, int y, int absX, int absY,
double scrollDeltaY, double scrollDeltaX, int scrollPhase) {
this.type = type;
this.modifierFlags = modifierFlags;
this.clickCount = clickCount;
this.buttonNumber = buttonNumber;
this.x = x;
this.y = y;
this.absX = absX;
this.absY = absY;
this.scrollDeltaY = scrollDeltaY;
this.scrollDeltaX = scrollDeltaX;
this.scrollPhase = scrollPhase;
}
int getType() {
return type;
}
int getModifierFlags() {
return modifierFlags;
}
int getClickCount() {
return clickCount;
}
int getButtonNumber() {
return buttonNumber;
}
int getX() {
return x;
}
int getY() {
return y;
}
double getScrollDeltaY() {
return scrollDeltaY;
}
double getScrollDeltaX() {
return scrollDeltaX;
}
int getScrollPhase() {
return scrollPhase;
}
int getAbsX() {
return absX;
}
int getAbsY() {
return absY;
}
short getKeyCode() {
return keyCode;
}
String getCharactersIgnoringModifiers() {
return charactersIgnoringModifiers;
}
String getCharacters() {
return characters;
}
@Override
public String toString() {
return "NSEvent[" + getType() + " ," + getModifierFlags() + " ,"
+ getClickCount() + " ," + getButtonNumber() + " ," + getX() + " ,"
+ getY() + " ," + getAbsX() + " ," + getAbsY()+ " ," + getKeyCode() + " ,"
+ getCharacters() + " ," + getCharactersIgnoringModifiers() + "]";
}
static int nsToJavaButton(int buttonNumber) {
int jbuttonNumber = buttonNumber + 1;
switch (buttonNumber) {
case CocoaConstants.kCGMouseButtonLeft:
jbuttonNumber = MouseEvent.BUTTON1;
break;
case CocoaConstants.kCGMouseButtonRight:
jbuttonNumber = MouseEvent.BUTTON3;
break;
case CocoaConstants.kCGMouseButtonCenter:
jbuttonNumber = MouseEvent.BUTTON2;
break;
}
return jbuttonNumber;
}
static int npToJavaEventType(int npEventType) {
int jeventType = 0;
switch (npEventType) {
case CocoaConstants.NPCocoaEventMouseDown:
jeventType = MouseEvent.MOUSE_PRESSED;
break;
case CocoaConstants.NPCocoaEventMouseUp:
jeventType = MouseEvent.MOUSE_RELEASED;
break;
case CocoaConstants.NPCocoaEventMouseMoved:
jeventType = MouseEvent.MOUSE_MOVED;
break;
case CocoaConstants.NPCocoaEventMouseEntered:
jeventType = MouseEvent.MOUSE_ENTERED;
break;
case CocoaConstants.NPCocoaEventMouseExited:
jeventType = MouseEvent.MOUSE_EXITED;
break;
case CocoaConstants.NPCocoaEventMouseDragged:
jeventType = MouseEvent.MOUSE_DRAGGED;
break;
case CocoaConstants.NPCocoaEventKeyDown:
jeventType = KeyEvent.KEY_PRESSED;
break;
case CocoaConstants.NPCocoaEventKeyUp:
jeventType = KeyEvent.KEY_RELEASED;
break;
}
return jeventType;
}
static int nsToJavaEventType(int nsEventType) {
int jeventType = 0;
switch (nsEventType) {
case CocoaConstants.NSLeftMouseDown:
case CocoaConstants.NSRightMouseDown:
case CocoaConstants.NSOtherMouseDown:
jeventType = MouseEvent.MOUSE_PRESSED;
break;
case CocoaConstants.NSLeftMouseUp:
case CocoaConstants.NSRightMouseUp:
case CocoaConstants.NSOtherMouseUp:
jeventType = MouseEvent.MOUSE_RELEASED;
break;
case CocoaConstants.NSMouseMoved:
jeventType = MouseEvent.MOUSE_MOVED;
break;
case CocoaConstants.NSLeftMouseDragged:
case CocoaConstants.NSRightMouseDragged:
case CocoaConstants.NSOtherMouseDragged:
jeventType = MouseEvent.MOUSE_DRAGGED;
break;
case CocoaConstants.NSMouseEntered:
jeventType = MouseEvent.MOUSE_ENTERED;
break;
case CocoaConstants.NSMouseExited:
jeventType = MouseEvent.MOUSE_EXITED;
break;
case CocoaConstants.NSScrollWheel:
jeventType = MouseEvent.MOUSE_WHEEL;
break;
case CocoaConstants.NSKeyDown:
jeventType = KeyEvent.KEY_PRESSED;
break;
case CocoaConstants.NSKeyUp:
jeventType = KeyEvent.KEY_RELEASED;
break;
}
return jeventType;
}
static native int nsToJavaModifiers(int modifierFlags);
static native boolean nsToJavaKeyInfo(int[] in, int[] out);
static native void nsKeyModifiersToJavaKeyInfo(int[] in, int[] out);
static native char nsToJavaChar(char nsChar, int modifierFlags, boolean spaceKeyTyped);
static boolean (int jmodifiers) {
final boolean isRightButtonDown = ((jmodifiers & InputEvent.BUTTON3_DOWN_MASK) != 0);
final boolean isLeftButtonDown = ((jmodifiers & InputEvent.BUTTON1_DOWN_MASK) != 0);
final boolean isControlDown = ((jmodifiers & InputEvent.CTRL_DOWN_MASK) != 0);
return isRightButtonDown || (isControlDown && isLeftButtonDown);
}
}