KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwt > awt > event > InputEvent


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: InputEvent.java,v $
11    Revision 1.7 2004/05/06 12:35:21 bobintetley
12    Parity with Swing constants for Binary Compatibility + fixes to JDesktopPane
13
14    Revision 1.6 2004/05/05 12:43:19 bobintetley
15    Patches/new files from Laurent Martell
16
17    Revision 1.5 2004/04/16 10:19:06 dannaab
18    Misc bug fixes, InputMap implementation, preliminary undo support
19
20    Revision 1.4 2004/03/30 10:42:44 bobintetley
21    Many minor bug fixes, event improvements by Dan Naab. Full swing.Icon support
22
23    Revision 1.3 2003/12/14 09:13:38 bobintetley
24    Added CVS log to source headers
25
26 */

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     /** For given SWT key and mouse modifiers, translates to AWT */
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     /** For given AWT key and mouse modifiers, translates to SWT */
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