1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.eclipse.swtbot.swt.finder.utils; |
12 | |
|
13 | |
import java.util.Map.Entry; |
14 | |
|
15 | |
import org.eclipse.swt.SWT; |
16 | |
import org.eclipse.swt.events.ArmEvent; |
17 | |
import org.eclipse.swt.events.ControlEvent; |
18 | |
import org.eclipse.swt.events.DisposeEvent; |
19 | |
import org.eclipse.swt.events.FocusEvent; |
20 | |
import org.eclipse.swt.events.HelpEvent; |
21 | |
import org.eclipse.swt.events.KeyEvent; |
22 | |
import org.eclipse.swt.events.MenuEvent; |
23 | |
import org.eclipse.swt.events.ModifyEvent; |
24 | |
import org.eclipse.swt.events.MouseEvent; |
25 | |
import org.eclipse.swt.events.PaintEvent; |
26 | |
import org.eclipse.swt.events.SelectionEvent; |
27 | |
import org.eclipse.swt.events.ShellEvent; |
28 | |
import org.eclipse.swt.events.TraverseEvent; |
29 | |
import org.eclipse.swt.events.TreeEvent; |
30 | |
import org.eclipse.swt.events.VerifyEvent; |
31 | |
import org.eclipse.swt.widgets.Event; |
32 | |
import org.eclipse.swt.widgets.Menu; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | 1 | public abstract class SWTBotEvents { |
41 | |
|
42 | 1 | private static final BidiMap<String, Integer> EVENTS = new BidiMap<String, Integer>(); |
43 | |
static { |
44 | 1 | EVENTS.put("Activate", SWT.Activate); |
45 | 1 | EVENTS.put("Arm", SWT.Arm); |
46 | 1 | EVENTS.put("Close", SWT.Close); |
47 | 1 | EVENTS.put("Collapse", SWT.Collapse); |
48 | 1 | EVENTS.put("Deactivate", SWT.Deactivate); |
49 | 1 | EVENTS.put("DefaultSelection", SWT.DefaultSelection); |
50 | 1 | EVENTS.put("Deiconify", SWT.Deiconify); |
51 | 1 | EVENTS.put("Dispose", SWT.Dispose); |
52 | 1 | EVENTS.put("DragDetect", SWT.DragDetect); |
53 | 1 | EVENTS.put("EraseItem", SWT.EraseItem); |
54 | 1 | EVENTS.put("Expand", SWT.Expand); |
55 | 1 | EVENTS.put("FocusIn", SWT.FocusIn); |
56 | 1 | EVENTS.put("FocusOut", SWT.FocusOut); |
57 | 1 | EVENTS.put("HardKeyDown", SWT.HardKeyDown); |
58 | 1 | EVENTS.put("HardKeyUp", SWT.HardKeyUp); |
59 | 1 | EVENTS.put("Help", SWT.Help); |
60 | 1 | EVENTS.put("Hide", SWT.Hide); |
61 | 1 | EVENTS.put("Iconify", SWT.Iconify); |
62 | 1 | EVENTS.put("KeyDown", SWT.KeyDown); |
63 | 1 | EVENTS.put("KeyUp", SWT.KeyUp); |
64 | 1 | EVENTS.put("MeasureItem", SWT.MeasureItem); |
65 | 1 | EVENTS.put("MenuDetect", SWT.MenuDetect); |
66 | 1 | EVENTS.put("Modify", SWT.Modify); |
67 | 1 | EVENTS.put("MouseDoubleClick", SWT.MouseDoubleClick); |
68 | 1 | EVENTS.put("MouseDown", SWT.MouseDown); |
69 | 1 | EVENTS.put("MouseEnter", SWT.MouseEnter); |
70 | 1 | EVENTS.put("MouseExit", SWT.MouseExit); |
71 | 1 | EVENTS.put("MouseHover", SWT.MouseHover); |
72 | 1 | EVENTS.put("MouseMove", SWT.MouseMove); |
73 | 1 | EVENTS.put("MouseUp", SWT.MouseUp); |
74 | 1 | EVENTS.put("MouseWheel", SWT.MouseWheel); |
75 | 1 | EVENTS.put("Move", SWT.Move); |
76 | 1 | EVENTS.put("Paint", SWT.Paint); |
77 | 1 | EVENTS.put("PaintItem", SWT.PaintItem); |
78 | 1 | EVENTS.put("Resize", SWT.Resize); |
79 | 1 | EVENTS.put("Selection", SWT.Selection); |
80 | 1 | EVENTS.put("SetData", SWT.SetData); |
81 | 1 | EVENTS.put("Settings", SWT.Settings); |
82 | 1 | EVENTS.put("Show", SWT.Show); |
83 | 1 | EVENTS.put("Traverse", SWT.Traverse); |
84 | 1 | EVENTS.put("Verify", SWT.Verify); |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public static String toString(int event) { |
94 | 6571 | return EVENTS.getKey(event); |
95 | |
} |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public static int[] events() { |
103 | 0 | int[] events = new int[EVENTS.size()]; |
104 | 0 | int i = 0; |
105 | |
|
106 | 0 | for (Entry<String, Integer> entry : EVENTS) { |
107 | 0 | events[i++] = entry.getValue(); |
108 | |
} |
109 | |
|
110 | 0 | return events; |
111 | |
} |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
public static String toString(Event event) { |
118 | 6571 | String toString = toString(event.type) + " [" + event.type + "]: "; |
119 | 6571 | switch (event.type) { |
120 | |
case SWT.KeyDown: |
121 | |
case SWT.KeyUp: |
122 | 0 | toString += new KeyEvent(event).toString(); |
123 | 0 | break; |
124 | |
case SWT.MouseDown: |
125 | |
case SWT.MouseUp: |
126 | |
case SWT.MouseMove: |
127 | |
case SWT.MouseEnter: |
128 | |
case SWT.MouseExit: |
129 | |
case SWT.MouseDoubleClick: |
130 | |
case SWT.MouseWheel: |
131 | |
case SWT.MouseHover: |
132 | 3532 | toString += new MouseEvent(event).toString(); |
133 | 3532 | break; |
134 | |
case SWT.Paint: |
135 | 0 | toString += new PaintEvent(event).toString(); |
136 | 0 | break; |
137 | |
case SWT.Move: |
138 | |
case SWT.Resize: |
139 | 0 | toString += new ControlEvent(event).toString(); |
140 | 0 | break; |
141 | |
case SWT.Dispose: |
142 | 0 | toString += new DisposeEvent(event).toString(); |
143 | 0 | break; |
144 | |
case SWT.Selection: |
145 | |
case SWT.DefaultSelection: |
146 | 853 | toString += new SelectionEvent(event).toString(); |
147 | 853 | break; |
148 | |
case SWT.FocusIn: |
149 | |
case SWT.FocusOut: |
150 | 1005 | toString += new FocusEvent(event).toString(); |
151 | 1005 | break; |
152 | |
case SWT.Expand: |
153 | |
case SWT.Collapse: |
154 | 28 | toString += new TreeEvent(event).toString(); |
155 | 28 | break; |
156 | |
case SWT.Iconify: |
157 | |
case SWT.Deiconify: |
158 | |
case SWT.Close: |
159 | |
case SWT.Activate: |
160 | |
case SWT.Deactivate: |
161 | 1119 | toString += new ShellEvent(event).toString(); |
162 | 1119 | break; |
163 | |
case SWT.Show: |
164 | |
case SWT.Hide: |
165 | 0 | toString += event.widget instanceof Menu ? new MenuEvent(event).toString() : event.toString(); |
166 | 0 | break; |
167 | |
case SWT.Modify: |
168 | 4 | toString += new ModifyEvent(event).toString(); |
169 | 4 | break; |
170 | |
case SWT.Verify: |
171 | 0 | toString += new VerifyEvent(event).toString(); |
172 | 0 | break; |
173 | |
case SWT.Help: |
174 | 0 | toString += new HelpEvent(event).toString(); |
175 | 0 | break; |
176 | |
case SWT.Arm: |
177 | 0 | toString += new ArmEvent(event).toString(); |
178 | 0 | break; |
179 | |
case SWT.Traverse: |
180 | 0 | toString += new TraverseEvent(event).toString(); |
181 | 0 | break; |
182 | |
case SWT.HardKeyDown: |
183 | |
case SWT.HardKeyUp: |
184 | |
case SWT.DragDetect: |
185 | |
case SWT.MenuDetect: |
186 | |
case SWT.SetData: |
187 | |
default: |
188 | 30 | toString += event.toString(); |
189 | |
} |
190 | 6571 | return toString; |
191 | |
} |
192 | |
} |