1 27 28 package swingwt.awt.event; 29 30 import swingwt.awt.*; 31 32 import org.eclipse.swt.*; 33 34 public abstract class InputEvent extends ComponentEvent { 35 36 public static final int SHIFT_MASK = 1 << 0; 37 public static final int CTRL_MASK = 1 << 2; 38 public static final int META_MASK = 1 << 3; 39 public static final int ALT_MASK = 1 << 4; 40 public static final int ALT_GRAPH_MASK = 1 << 5; 41 public static final int BUTTON1_MASK = 1 << 4; 42 public static final int BUTTON2_MASK = ALT_MASK; 43 public static final int BUTTON3_MASK = META_MASK; 44 public static final int SHIFT_DOWN_MASK = 1 << 6; 45 public static final int CTRL_DOWN_MASK = 1 << 7; 46 public static final int META_DOWN_MASK = 1 << 8; 47 public static final int ALT_DOWN_MASK = 1 << 9; 48 public static final int BUTTON1_DOWN_MASK = 1 << 10; 49 public static final int BUTTON2_DOWN_MASK = 1 << 11; 50 public static final int BUTTON3_DOWN_MASK = 1 << 12; 51 public static final int ALT_GRAPH_DOWN_MASK = 1 << 13; 52 53 private long when; 54 int modifiers = 0; 55 56 InputEvent(Component source, int id, long when, int modifiers) { 57 super(source, id); 58 this.when = when; 59 this.modifiers = modifiers; 60 } 61 62 public InputEvent(Component source) { super(source); } 63 public InputEvent(Component source, int id) { super(source, id); } 64 65 public int getModifiers() { return modifiers; } 66 public boolean isAltDown() { return ( modifiers & ALT_MASK ) != 0; } 67 public boolean isAltGraphDown() { return ( modifiers & ALT_GRAPH_MASK ) != 0; } 68 public boolean isShiftDown() { return ( modifiers & SHIFT_MASK ) != 0; } 69 public boolean isControlDown() { return ( modifiers & CTRL_MASK ) != 0; } 70 public boolean isMetaDown() { return ( modifiers & META_MASK ) != 0; } 71 72 73 public static int translateSWTModifiers(int swtModifiers) { 74 int awtModifiers = 0; 75 if ((swtModifiers & SWT.CTRL) > 0) 76 awtModifiers = awtModifiers | CTRL_MASK; 77 if ((swtModifiers & SWT.SHIFT) > 0) 78 awtModifiers = awtModifiers | SHIFT_MASK; 79 if ((swtModifiers & SWT.ALT) > 0) 80 awtModifiers = awtModifiers | ALT_MASK; 81 if ((swtModifiers & SWT.BUTTON1) > 0) 82 awtModifiers = awtModifiers | BUTTON1_DOWN_MASK; 83 if ((swtModifiers & SWT.BUTTON2) > 0) 84 awtModifiers = awtModifiers | BUTTON2_DOWN_MASK; 85 if ((swtModifiers & SWT.BUTTON3) > 0) 86 awtModifiers = awtModifiers | BUTTON3_DOWN_MASK; 87 return awtModifiers; 88 } 89 90 91 public static int translateAWTModifiers(int awtModifiers) { 92 int swtModifiers = 0; 93 if ((awtModifiers & CTRL_MASK) > 0) 94 swtModifiers = swtModifiers | SWT.CTRL; 95 if ((awtModifiers & SHIFT_MASK) > 0) 96 swtModifiers = swtModifiers | SWT.SHIFT; 97 if ((awtModifiers & ALT_MASK) > 0) 98 swtModifiers = swtModifiers | SWT.ALT; 99 if ((awtModifiers & BUTTON1_DOWN_MASK) > 0) 100 swtModifiers = swtModifiers | SWT.BUTTON1; 101 if ((awtModifiers & BUTTON2_DOWN_MASK) > 0) 102 swtModifiers = swtModifiers | SWT.BUTTON2; 103 if ((awtModifiers & BUTTON3_DOWN_MASK) > 0) 104 swtModifiers = swtModifiers | SWT.BUTTON3; 105 return swtModifiers; 106 } 107 108 } 109 | Popular Tags |