Skip to main content
summaryrefslogtreecommitdiffstats
blob: 93e4abb61d0f68f23d71c433c8aa4bd7afd13056 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/*******************************************************************************
 * Copyright (c) 2008, 2017 Ketan Padegaonkar and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Ketan Padegaonkar - initial API and implementation
 *******************************************************************************/
package org.eclipse.swtbot.swt.finder.utils;

import java.util.Map.Entry;

import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.events.ArmEvent;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.HelpEvent;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.events.TraverseEvent;
import org.eclipse.swt.events.TreeEvent;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Menu;

/**
 * This maps SWT events to the Strings.
 *
 * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 * @version $Id$
 */
public abstract class SWTBotEvents {

	private static final BidiMap<String, Integer>	EVENTS	= new BidiMap<String, Integer>();
	static {
		EVENTS.put("Activate", SWT.Activate); //$NON-NLS-1$
		EVENTS.put("Arm", SWT.Arm); //$NON-NLS-1$
		EVENTS.put("Close", SWT.Close); //$NON-NLS-1$
		EVENTS.put("Collapse", SWT.Collapse); //$NON-NLS-1$
		EVENTS.put("Deactivate", SWT.Deactivate); //$NON-NLS-1$
		EVENTS.put("DefaultSelection", SWT.DefaultSelection); //$NON-NLS-1$
		EVENTS.put("Deiconify", SWT.Deiconify); //$NON-NLS-1$
		EVENTS.put("Dispose", SWT.Dispose); //$NON-NLS-1$
		EVENTS.put("DragDetect", SWT.DragDetect); //$NON-NLS-1$
		EVENTS.put("EraseItem", SWT.EraseItem); //$NON-NLS-1$
		EVENTS.put("Expand", SWT.Expand); //$NON-NLS-1$
		EVENTS.put("FocusIn", SWT.FocusIn); //$NON-NLS-1$
		EVENTS.put("FocusOut", SWT.FocusOut); //$NON-NLS-1$
		EVENTS.put("HardKeyDown", SWT.HardKeyDown); //$NON-NLS-1$
		EVENTS.put("HardKeyUp", SWT.HardKeyUp); //$NON-NLS-1$
		EVENTS.put("Help", SWT.Help); //$NON-NLS-1$
		EVENTS.put("Hide", SWT.Hide); //$NON-NLS-1$
		EVENTS.put("Iconify", SWT.Iconify); //$NON-NLS-1$
		EVENTS.put("KeyDown", SWT.KeyDown); //$NON-NLS-1$
		EVENTS.put("KeyUp", SWT.KeyUp); //$NON-NLS-1$
		EVENTS.put("MeasureItem", SWT.MeasureItem); //$NON-NLS-1$
		EVENTS.put("MenuDetect", SWT.MenuDetect); //$NON-NLS-1$
		EVENTS.put("Modify", SWT.Modify); //$NON-NLS-1$
		EVENTS.put("MouseDoubleClick", SWT.MouseDoubleClick); //$NON-NLS-1$
		EVENTS.put("MouseDown", SWT.MouseDown); //$NON-NLS-1$
		EVENTS.put("MouseEnter", SWT.MouseEnter); //$NON-NLS-1$
		EVENTS.put("MouseExit", SWT.MouseExit); //$NON-NLS-1$
		EVENTS.put("MouseHover", SWT.MouseHover); //$NON-NLS-1$
		EVENTS.put("MouseMove", SWT.MouseMove); //$NON-NLS-1$
		EVENTS.put("MouseUp", SWT.MouseUp); //$NON-NLS-1$
		EVENTS.put("MouseWheel", SWT.MouseWheel); //$NON-NLS-1$
		EVENTS.put("Move", SWT.Move); //$NON-NLS-1$
		EVENTS.put("Paint", SWT.Paint); //$NON-NLS-1$
		EVENTS.put("PaintItem", SWT.PaintItem); //$NON-NLS-1$
		EVENTS.put("Resize", SWT.Resize); //$NON-NLS-1$
		EVENTS.put("Selection", SWT.Selection); //$NON-NLS-1$
		EVENTS.put("SetData", SWT.SetData); //$NON-NLS-1$
		EVENTS.put("Settings", SWT.Settings); // note: this event only goes to Display //$NON-NLS-1$
		EVENTS.put("Show", SWT.Show); //$NON-NLS-1$
		EVENTS.put("Traverse", SWT.Traverse); //$NON-NLS-1$
		EVENTS.put("Verify", SWT.Verify); //$NON-NLS-1$
		EVENTS.put("DND.DragEnd", DND.DragEnd); //$NON-NLS-1$
		EVENTS.put("DND.DragSetData", DND.DragSetData); //$NON-NLS-1$
		EVENTS.put("DND.DragEnter", DND.DragEnter); //$NON-NLS-1$
		EVENTS.put("DND.DragLeave", DND.DragLeave); //$NON-NLS-1$
		EVENTS.put("DND.DragOver", DND.DragOver); //$NON-NLS-1$
		EVENTS.put("DND.DragOperationChanged", DND.DragOperationChanged); //$NON-NLS-1$
		EVENTS.put("DND.Drop", DND.Drop); //$NON-NLS-1$
		EVENTS.put("DND.DropAccept", DND.DropAccept); //$NON-NLS-1$
		EVENTS.put("DND.DragStart", DND.DragStart); //$NON-NLS-1$
	}

	/**
	 * Converts the event to a string for display.
	 *
	 * @param event the event.
	 * @return the string representation of the display.
	 */
	public static String toString(int event) {
		return EVENTS.getKey(event);
	}

	/**
	 * Lists all the events.
	 *
	 * @return all the events.
	 */
	public static int[] events() {
		int[] events = new int[EVENTS.size()];
		int i = 0;

		for (Entry<String, Integer> entry : EVENTS) {
			events[i++] = entry.getValue();
		}

		return events;
	}

	/**
	 * @param event the event to be converted to a string.
	 * @return the typed event corresponding to the <code>event</code>.
	 */
	public static String toString(Event event) {
		String toString = toString(event.type) + " [" + event.type + "]: "; //$NON-NLS-1$ //$NON-NLS-2$
		switch (event.type) {
		case SWT.KeyDown:
		case SWT.KeyUp:
			toString += new KeyEvent(event).toString();
			break;
		case SWT.MouseDown:
		case SWT.MouseUp:
		case SWT.MouseMove:
		case SWT.MouseEnter:
		case SWT.MouseExit:
		case SWT.MouseDoubleClick:
		case SWT.MouseWheel:
		case SWT.MouseHover:
			toString += new MouseEvent(event).toString();
			break;
		case SWT.Paint:
			toString += new PaintEvent(event).toString();
			break;
		case SWT.Move:
		case SWT.Resize:
			toString += new ControlEvent(event).toString();
			break;
		case SWT.Dispose:
			toString += new DisposeEvent(event).toString();
			break;
		case SWT.Selection:
		case SWT.DefaultSelection:
			toString += new SelectionEvent(event).toString();
			break;
		case SWT.FocusIn:
		case SWT.FocusOut:
			toString += new FocusEvent(event).toString();
			break;
		case SWT.Expand:
		case SWT.Collapse:
			toString += new TreeEvent(event).toString();
			break;
		case SWT.Iconify:
		case SWT.Deiconify:
		case SWT.Close:
		case SWT.Activate:
		case SWT.Deactivate:
			toString += new ShellEvent(event).toString();
			break;
		case SWT.Show:
		case SWT.Hide:
			toString += event.widget instanceof Menu ? new MenuEvent(event).toString() : event.toString();
			break;
		case SWT.Modify:
			toString += new ModifyEvent(event).toString();
			break;
		case SWT.Verify:
			toString += new VerifyEvent(event).toString();
			break;
		case SWT.Help:
			toString += new HelpEvent(event).toString();
			break;
		case SWT.Arm:
			toString += new ArmEvent(event).toString();
			break;
		case SWT.Traverse:
			toString += new TraverseEvent(event).toString();
			break;
		case SWT.HardKeyDown:
		case SWT.HardKeyUp:
		case SWT.DragDetect:
		case SWT.MenuDetect:
		case SWT.SetData:
		default:
			toString += event.toString();
		}
		return toString;
	}
}

Back to the top