|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
JListMouseEventData.java | 75% | 88.4% | 83.3% | 85.2% |
|
1 |
package junit.extensions.jfcunit.eventdata;
|
|
2 |
|
|
3 |
import junit.extensions.jfcunit.JFCTestCase;
|
|
4 |
import junit.extensions.jfcunit.xml.JFCXMLConstants;
|
|
5 |
|
|
6 |
import org.w3c.dom.Element;
|
|
7 |
|
|
8 |
import java.awt.AWTEvent;
|
|
9 |
import java.awt.Component;
|
|
10 |
import java.awt.Point;
|
|
11 |
import java.awt.Rectangle;
|
|
12 |
import java.awt.event.MouseEvent;
|
|
13 |
|
|
14 |
import javax.swing.JList;
|
|
15 |
|
|
16 |
|
|
17 |
/**
|
|
18 |
* Data container class that holds all the data necessary for jfcUnit to fire mouse events.
|
|
19 |
* This class is specific to events on a JList.
|
|
20 |
*
|
|
21 |
* @author <a href="mailto:vraravam@thoughtworks.com">Vijay Aravamudhan : ThoughtWorks Inc.</a>
|
|
22 |
*/
|
|
23 |
public class JListMouseEventData extends AbstractMouseEventData { |
|
24 |
/**
|
|
25 |
* The JList on which to trigger the event.
|
|
26 |
*/
|
|
27 |
private JList m_list;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* The zero-based index of the specific element on which to trigger the event.
|
|
31 |
*/
|
|
32 |
private int m_elementIndex; |
|
33 |
|
|
34 |
/**
|
|
35 |
* Constructor.
|
|
36 |
*/
|
|
37 | 6 |
public JListMouseEventData() {
|
38 | 6 |
super();
|
39 | 6 |
setValid(false);
|
40 |
} |
|
41 |
|
|
42 |
/**
|
|
43 |
* Constructor.
|
|
44 |
*
|
|
45 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
46 |
* @param list The JList on which to trigger the event.
|
|
47 |
* @param element The specific element on which to trigger the event.
|
|
48 |
* @param numberOfClicks
|
|
49 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
50 |
*/
|
|
51 | 6 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
52 |
final Object element, final int numberOfClicks) {
|
|
53 | 6 |
this(testCase, list, element, numberOfClicks, DEFAULT_SLEEPTIME);
|
54 |
} |
|
55 |
|
|
56 |
/**
|
|
57 |
* Constructor.
|
|
58 |
*
|
|
59 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
60 |
* @param list The JList on which to trigger the event.
|
|
61 |
* @param element The specific element on which to trigger the event.
|
|
62 |
* @param numberOfClicks
|
|
63 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
64 |
* @param sleepTime
|
|
65 |
* The wait time in ms between each event.
|
|
66 |
*/
|
|
67 | 6 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
68 |
final Object element, final int numberOfClicks, final long sleepTime) { |
|
69 | 6 |
this(testCase, list, element, numberOfClicks, DEFAULT_ISPOPUPTRIGGER,
|
70 |
sleepTime); |
|
71 |
} |
|
72 |
|
|
73 |
/**
|
|
74 |
* Constructor.
|
|
75 |
*
|
|
76 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
77 |
* @param list The JList on which to trigger the event.
|
|
78 |
* @param element The specific element on which to trigger the event.
|
|
79 |
* @param numberOfClicks
|
|
80 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
81 |
* @param isPopupTrigger
|
|
82 |
* boolean specifying whether this event will show a popup.
|
|
83 |
*/
|
|
84 | 0 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
85 |
final Object element, final int numberOfClicks,
|
|
86 |
final boolean isPopupTrigger) {
|
|
87 | 0 |
this(testCase, list, element, numberOfClicks,
|
88 |
getDefaultModifiers(isPopupTrigger), isPopupTrigger, |
|
89 |
DEFAULT_SLEEPTIME); |
|
90 |
} |
|
91 |
|
|
92 |
/**
|
|
93 |
* Constructor.
|
|
94 |
*
|
|
95 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
96 |
* @param list The JList on which to trigger the event.
|
|
97 |
* @param element The specific element on which to trigger the event.
|
|
98 |
* @param numberOfClicks
|
|
99 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
100 |
* @param isPopupTrigger
|
|
101 |
* boolean specifying whether this event will show a popup.
|
|
102 |
* @param sleepTime
|
|
103 |
* The wait time in ms between each event.
|
|
104 |
*/
|
|
105 | 6 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
106 |
final Object element, final int numberOfClicks,
|
|
107 |
final boolean isPopupTrigger, final long sleepTime) { |
|
108 | 6 |
this(testCase, list, element, numberOfClicks,
|
109 |
getDefaultModifiers(isPopupTrigger), isPopupTrigger, sleepTime); |
|
110 |
} |
|
111 |
|
|
112 |
/**
|
|
113 |
* Constructor.
|
|
114 |
*
|
|
115 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
116 |
* @param list The JList on which to trigger the event.
|
|
117 |
* @param element The specific element on which to trigger the event.
|
|
118 |
* @param numberOfClicks
|
|
119 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
120 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
121 |
* @param isPopupTrigger
|
|
122 |
* boolean specifying whether this event will show a popup.
|
|
123 |
* @param sleepTime
|
|
124 |
* The wait time in ms between each event.
|
|
125 |
*/
|
|
126 | 6 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
127 |
final Object element, final int numberOfClicks, final int modifiers, |
|
128 |
final boolean isPopupTrigger, final long sleepTime) { |
|
129 | 6 |
this(testCase, list, element, numberOfClicks, modifiers,
|
130 |
isPopupTrigger, sleepTime, DEFAULT_POSITION, null);
|
|
131 |
} |
|
132 |
|
|
133 |
/**
|
|
134 |
* Constructor.
|
|
135 |
*
|
|
136 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
137 |
* @param list The JList on which to trigger the event.
|
|
138 |
* @param element The specific element on which to trigger the event.
|
|
139 |
* @param numberOfClicks
|
|
140 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
141 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
142 |
* @param isPopupTrigger
|
|
143 |
* boolean specifying whether this event will show a popup.
|
|
144 |
* @param sleepTime
|
|
145 |
* The wait time in ms between each event.
|
|
146 |
* @param position The relative mouse position within the cell.
|
|
147 |
*/
|
|
148 | 0 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
149 |
final Object element, final int numberOfClicks, final int modifiers, |
|
150 |
final boolean isPopupTrigger, final long sleepTime, final int position) { |
|
151 | 0 |
this(testCase, list, element, numberOfClicks, modifiers,
|
152 |
isPopupTrigger, sleepTime, position, null);
|
|
153 |
} |
|
154 |
|
|
155 |
/**
|
|
156 |
* Constructor.
|
|
157 |
*
|
|
158 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
159 |
* @param list The JList on which to trigger the event.
|
|
160 |
* @param element The specific element on which to trigger the event.
|
|
161 |
* @param numberOfClicks
|
|
162 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
163 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
164 |
* @param isPopupTrigger
|
|
165 |
* boolean specifying whether this event will show a popup.
|
|
166 |
* @param sleepTime
|
|
167 |
* The wait time in ms between each event.
|
|
168 |
* @param referencePoint
|
|
169 |
* The CUSTOM mouse position within the cell.
|
|
170 |
*/
|
|
171 | 0 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
172 |
final Object element, final int numberOfClicks, final int modifiers, |
|
173 |
final boolean isPopupTrigger, final long sleepTime, |
|
174 |
final Point referencePoint) { |
|
175 | 0 |
this(testCase, list, element, numberOfClicks, modifiers,
|
176 |
isPopupTrigger, sleepTime, CUSTOM, referencePoint); |
|
177 |
} |
|
178 |
|
|
179 |
/**
|
|
180 |
* Constructor.
|
|
181 |
*
|
|
182 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
183 |
* @param list The JList on which to trigger the event.
|
|
184 |
* @param element The specific element on which to trigger the event.
|
|
185 |
* @param numberOfClicks
|
|
186 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
187 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
188 |
* @param isPopupTrigger
|
|
189 |
* boolean specifying whether this event will show a popup.
|
|
190 |
* @param sleepTime
|
|
191 |
* The wait time in ms between each event.
|
|
192 |
* @param position The relative mouse position within the cell.
|
|
193 |
* @param referencePoint
|
|
194 |
* If position is CUSTOM then the point is a offset from
|
|
195 |
* the location of the component. If the position is PERCENT
|
|
196 |
* then the location is a percentage offset of the hight and width.
|
|
197 |
* Otherwise, the referencePoint is unused.
|
|
198 |
*/
|
|
199 | 6 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
200 |
final Object element, final int numberOfClicks, final int modifiers, |
|
201 |
final boolean isPopupTrigger, final long sleepTime, final int position, |
|
202 |
final Point referencePoint) { |
|
203 | 6 |
this(testCase, list,
|
204 |
getIndexOf(list, element), numberOfClicks, modifiers, |
|
205 |
isPopupTrigger, sleepTime, position, referencePoint); |
|
206 |
} |
|
207 |
|
|
208 |
/**
|
|
209 |
* Constructor.
|
|
210 |
*
|
|
211 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
212 |
* @param list The JList on which to trigger the event.
|
|
213 |
* @param elementIndex
|
|
214 |
* The zero-based index of the specific element on which to trigger the event.
|
|
215 |
* @param numberOfClicks
|
|
216 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
217 |
*/
|
|
218 | 122 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
219 |
final int elementIndex, final int numberOfClicks) { |
|
220 | 122 |
this(testCase, list, elementIndex, numberOfClicks, DEFAULT_SLEEPTIME);
|
221 |
} |
|
222 |
|
|
223 |
/**
|
|
224 |
* Constructor.
|
|
225 |
*
|
|
226 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
227 |
* @param list The JList on which to trigger the event.
|
|
228 |
* @param elementIndex
|
|
229 |
* The zero-based index of the specific element on which to trigger the event.
|
|
230 |
* @param numberOfClicks
|
|
231 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
232 |
* @param sleepTime
|
|
233 |
* The wait time in ms between each event.
|
|
234 |
*/
|
|
235 | 124 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
236 |
final int elementIndex, final int numberOfClicks, final long sleepTime) { |
|
237 | 124 |
this(testCase, list, elementIndex, numberOfClicks,
|
238 |
DEFAULT_ISPOPUPTRIGGER, sleepTime); |
|
239 |
} |
|
240 |
|
|
241 |
/**
|
|
242 |
* Constructor.
|
|
243 |
*
|
|
244 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
245 |
* @param list The JList on which to trigger the event.
|
|
246 |
* @param elementIndex
|
|
247 |
* The zero-based index of the specific element on which to trigger the event.
|
|
248 |
* @param numberOfClicks
|
|
249 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
250 |
* @param isPopupTrigger
|
|
251 |
* boolean specifying whether this event will show a popup.
|
|
252 |
*/
|
|
253 | 2 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
254 |
final int elementIndex, final int numberOfClicks, |
|
255 |
final boolean isPopupTrigger) {
|
|
256 | 2 |
this(testCase, list, elementIndex, numberOfClicks,
|
257 |
getDefaultModifiers(isPopupTrigger), isPopupTrigger, |
|
258 |
DEFAULT_SLEEPTIME); |
|
259 |
} |
|
260 |
|
|
261 |
/**
|
|
262 |
* Constructor.
|
|
263 |
*
|
|
264 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
265 |
* @param list The JList on which to trigger the event.
|
|
266 |
* @param elementIndex
|
|
267 |
* The zero-based index of the specific element on which to trigger the event.
|
|
268 |
* @param numberOfClicks
|
|
269 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
270 |
* @param isPopupTrigger
|
|
271 |
* boolean specifying whether this event will show a popup.
|
|
272 |
* @param sleepTime
|
|
273 |
* The wait time in ms between each event.
|
|
274 |
*/
|
|
275 | 126 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
276 |
final int elementIndex, final int numberOfClicks, |
|
277 |
final boolean isPopupTrigger, final long sleepTime) { |
|
278 | 126 |
this(testCase, list, elementIndex, numberOfClicks,
|
279 |
getDefaultModifiers(isPopupTrigger), isPopupTrigger, sleepTime); |
|
280 |
} |
|
281 |
|
|
282 |
/**
|
|
283 |
* Constructor.
|
|
284 |
*
|
|
285 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
286 |
* @param list The JList on which to trigger the event.
|
|
287 |
* @param elementIndex
|
|
288 |
* The zero-based index of the specific element on which to trigger the event.
|
|
289 |
* @param numberOfClicks
|
|
290 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
291 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
292 |
* @param isPopupTrigger
|
|
293 |
* boolean specifying whether this event will show a popup.
|
|
294 |
* @param sleepTime
|
|
295 |
* The wait time in ms between each event.
|
|
296 |
*/
|
|
297 | 130 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
298 |
final int elementIndex, final int numberOfClicks, final int modifiers, |
|
299 |
final boolean isPopupTrigger, final long sleepTime) { |
|
300 | 130 |
this(testCase, list, elementIndex, numberOfClicks, modifiers,
|
301 |
isPopupTrigger, sleepTime, DEFAULT_POSITION, null);
|
|
302 |
} |
|
303 |
|
|
304 |
/**
|
|
305 |
* Constructor.
|
|
306 |
*
|
|
307 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
308 |
* @param list The JList on which to trigger the event.
|
|
309 |
* @param elementIndex
|
|
310 |
* The zero-based index of the specific element on which to trigger the event.
|
|
311 |
* @param numberOfClicks
|
|
312 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
313 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
314 |
* @param isPopupTrigger
|
|
315 |
* boolean specifying whether this event will show a popup.
|
|
316 |
* @param sleepTime
|
|
317 |
* The wait time in ms between each event.
|
|
318 |
* @param position The relative mouse position within the cell.
|
|
319 |
*/
|
|
320 | 2 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
321 |
final int elementIndex, final int numberOfClicks, final int modifiers, |
|
322 |
final boolean isPopupTrigger, final long sleepTime, final int position) { |
|
323 | 2 |
this(testCase, list, elementIndex, numberOfClicks, modifiers,
|
324 |
isPopupTrigger, sleepTime, position, null);
|
|
325 |
} |
|
326 |
|
|
327 |
/**
|
|
328 |
* Constructor.
|
|
329 |
*
|
|
330 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
331 |
* @param list The JList on which to trigger the event.
|
|
332 |
* @param elementIndex
|
|
333 |
* The zero-based index of the specific element on which to trigger the event.
|
|
334 |
* @param numberOfClicks
|
|
335 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
336 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
337 |
* @param isPopupTrigger
|
|
338 |
* boolean specifying whether this event will show a popup.
|
|
339 |
* @param sleepTime
|
|
340 |
* The wait time in ms between each event.
|
|
341 |
* @param referencePoint
|
|
342 |
* The CUSTOM mouse position within the cell.
|
|
343 |
*/
|
|
344 | 2 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
345 |
final int elementIndex, final int numberOfClicks, final int modifiers, |
|
346 |
final boolean isPopupTrigger, final long sleepTime, |
|
347 |
final Point referencePoint) { |
|
348 | 2 |
this(testCase, list, elementIndex, numberOfClicks, modifiers,
|
349 |
isPopupTrigger, sleepTime, CUSTOM, referencePoint); |
|
350 |
} |
|
351 |
|
|
352 |
/**
|
|
353 |
* Constructor.
|
|
354 |
*
|
|
355 |
* @param testCase The JFCTestCase on whose thread <code>awtSleep()</code> has to be invoked.
|
|
356 |
* @param list The JList on which to trigger the event.
|
|
357 |
* @param elementIndex
|
|
358 |
* The zero-based index of the specific element on which to trigger the event.
|
|
359 |
* @param numberOfClicks
|
|
360 |
* Number of clicks in the MouseEvent (1 for single-click, 2 for double clicks)
|
|
361 |
* @param modifiers The modifier key values that need to be passed onto the event.
|
|
362 |
* @param isPopupTrigger
|
|
363 |
* boolean specifying whether this event will show a popup.
|
|
364 |
* @param sleepTime
|
|
365 |
* The wait time in ms between each event.
|
|
366 |
* @param position The relative mouse position within the cell.
|
|
367 |
* @param referencePoint
|
|
368 |
* If position is CUSTOM then the point is a offset from
|
|
369 |
* the location of the component. If the position is PERCENT
|
|
370 |
* then the location is a percentage offset of the hight and width.
|
|
371 |
* Otherwise, the referencePoint is unused.
|
|
372 |
*/
|
|
373 | 172 |
public JListMouseEventData(final JFCTestCase testCase, final JList list,
|
374 |
final int elementIndex, final int numberOfClicks, final int modifiers, |
|
375 |
final boolean isPopupTrigger, final long sleepTime, final int position, |
|
376 |
final Point referencePoint) { |
|
377 | 172 |
setTestCase(testCase); |
378 | 172 |
setSource(list); |
379 | 172 |
setNumberOfClicks(numberOfClicks); |
380 | 172 |
setModifiers(modifiers); |
381 | 172 |
setPopupTrigger(isPopupTrigger); |
382 | 172 |
setElementIndex(elementIndex); |
383 | 172 |
setSleepTime(sleepTime); |
384 | 172 |
setPosition(position); |
385 | 172 |
setReferencePoint(referencePoint); |
386 | 172 |
setValid(true);
|
387 |
} |
|
388 |
|
|
389 |
/**
|
|
390 |
* The component on which the event has to be fired.
|
|
391 |
*
|
|
392 |
* @return The component
|
|
393 |
*/
|
|
394 | 212 |
public Component getComponent() {
|
395 |
// by default, the component is the same as the source
|
|
396 | 212 |
return getSource();
|
397 |
} |
|
398 |
|
|
399 |
/**
|
|
400 |
* Set the attribute value.
|
|
401 |
*
|
|
402 |
* @param elementIndex The new value of the attribute
|
|
403 |
*/
|
|
404 | 190 |
public void setElementIndex(final int elementIndex) { |
405 | 190 |
m_elementIndex = elementIndex; |
406 |
} |
|
407 |
|
|
408 |
/**
|
|
409 |
* Get the attribute value.
|
|
410 |
*
|
|
411 |
* @return int The value of the attribute
|
|
412 |
*/
|
|
413 | 38 |
public int getElementIndex() { |
414 | 38 |
return m_elementIndex;
|
415 |
} |
|
416 |
|
|
417 |
/**
|
|
418 |
* Set the attribute value.
|
|
419 |
*
|
|
420 |
* @param list The new value of the attribute.
|
|
421 |
*/
|
|
422 | 190 |
public void setSource(final JList list) { |
423 | 190 |
m_list = list; |
424 |
} |
|
425 |
|
|
426 |
/**
|
|
427 |
* Get the attribute value.
|
|
428 |
*
|
|
429 |
* @return JList The value of the attribute.
|
|
430 |
*/
|
|
431 | 375 |
public JList getSource() {
|
432 | 375 |
return m_list;
|
433 |
} |
|
434 |
|
|
435 |
/**
|
|
436 |
* Check if this event can consume the event given.
|
|
437 |
* @param ae AWTEvent to be consumed.
|
|
438 |
* @return true if the event may be consumed.
|
|
439 |
*/
|
|
440 | 20 |
public boolean canConsume(final AWTEvent ae) { |
441 | 20 |
if (!super.canConsume(ae) |
442 |
|| !(ae.getSource() instanceof JList)
|
|
443 |
|| !sameSource(ae)) { |
|
444 | 0 |
return false; |
445 |
} |
|
446 |
|
|
447 | 20 |
if (isValid()) {
|
448 | 14 |
JList source = (JList) ae.getSource(); |
449 | 14 |
int index = source.locationToIndex(
|
450 |
new Point(
|
|
451 |
((MouseEvent) ae).getX(), |
|
452 |
((MouseEvent) ae).getY())); |
|
453 |
|
|
454 | 14 |
if (index != getElementIndex()) {
|
455 | 0 |
return false; |
456 |
} |
|
457 |
} |
|
458 |
|
|
459 | 20 |
return true; |
460 |
} |
|
461 |
|
|
462 |
/**
|
|
463 |
* Consume the event.
|
|
464 |
* @param ae AWTEvent to be consumed.
|
|
465 |
* @return boolean true if the event was consumed.
|
|
466 |
*/
|
|
467 | 20 |
public boolean consume(final AWTEvent ae) { |
468 | 20 |
if (super.consume(ae)) { |
469 | 2 |
return true; |
470 |
} |
|
471 |
|
|
472 | 18 |
MouseEvent me = (MouseEvent) ae; |
473 | 18 |
JList source = (JList) me.getSource(); |
474 | 18 |
setSource(source); |
475 | 18 |
setModifiers(me.getModifiers()); |
476 | 18 |
setNumberOfClicks(me.getClickCount()); |
477 | 18 |
setPopupTrigger(me.isPopupTrigger()); |
478 |
|
|
479 | 18 |
Point p = new Point(
|
480 |
me.getX(), |
|
481 |
me.getY()); |
|
482 | 18 |
Point screen = source.getLocationOnScreen(); |
483 | 18 |
screen.translate(p.x, p.y); |
484 | 18 |
setLocationOnScreen(screen); |
485 | 18 |
setSleepTime(getDefaultSleepTime()); |
486 |
|
|
487 | 18 |
int index = m_list.locationToIndex(new Point( |
488 |
me.getX(), |
|
489 |
me.getY())); |
|
490 | 18 |
setElementIndex(index); |
491 |
|
|
492 | 18 |
setPosition(CENTER); |
493 | 18 |
setReferencePoint(null);
|
494 |
|
|
495 | 18 |
setValid(true);
|
496 |
|
|
497 | 18 |
return true; |
498 |
} |
|
499 |
|
|
500 |
/**
|
|
501 |
* Compare to event datas and deterime if they are equal.
|
|
502 |
*
|
|
503 |
* @param o Object to be compared.
|
|
504 |
* @return true if the events are the same.
|
|
505 |
*/
|
|
506 | 11 |
public boolean equals(final Object o) { |
507 | 11 |
if (!super.equals(o)) { |
508 | 9 |
return false; |
509 |
} |
|
510 |
|
|
511 | 2 |
JListMouseEventData data = (JListMouseEventData) o; |
512 |
|
|
513 | 2 |
return (data.getElementIndex() == getElementIndex());
|
514 |
} |
|
515 |
|
|
516 |
/**
|
|
517 |
* Get the hashCode.
|
|
518 |
* @return hashCode for this object.
|
|
519 |
*/
|
|
520 | 0 |
public int hashCode() { |
521 | 0 |
return super.hashCode() + this.m_elementIndex; |
522 |
} |
|
523 |
|
|
524 |
/**
|
|
525 |
* Populate the XML Element.
|
|
526 |
* @param e element to be populated.
|
|
527 |
*/
|
|
528 | 0 |
public void populate(final Element e) { |
529 | 0 |
super.populate(e);
|
530 | 0 |
e.setAttribute(JFCXMLConstants.TYPE, "JListMouseEventData");
|
531 | 0 |
e.setAttribute(JFCXMLConstants.INDEX, "" + getElementIndex());
|
532 |
} |
|
533 |
|
|
534 |
/**
|
|
535 |
* Prepare the component to receive the event.
|
|
536 |
*
|
|
537 |
* @return true if the component is ready to receive the event.
|
|
538 |
*/
|
|
539 | 147 |
public boolean prepareComponent() { |
540 | 147 |
if (!isValidForProcessing(getSource())) {
|
541 | 1 |
return false; |
542 |
} |
|
543 |
|
|
544 | 146 |
m_list.ensureIndexIsVisible(m_elementIndex); |
545 |
|
|
546 | 146 |
JFCTestCase testCase = getTestCase(); |
547 |
|
|
548 | 146 |
if (testCase != null) { |
549 |
// try to clear the event queue
|
|
550 | 146 |
testCase.flushAWT(); |
551 |
} |
|
552 |
|
|
553 | 146 |
Rectangle cellRect = m_list.getCellBounds(m_elementIndex, m_elementIndex); |
554 |
|
|
555 | 146 |
if (testCase != null) { |
556 |
// try to clear the event queue
|
|
557 | 146 |
testCase.pauseAWT(); |
558 |
} |
|
559 |
|
|
560 | 146 |
Point p = calculatePoint(cellRect); |
561 |
|
|
562 | 146 |
if (!m_list.getVisibleRect().contains(p)) {
|
563 | 1 |
Rectangle vis = m_list.getVisibleRect(); |
564 | 1 |
Rectangle newView = new Rectangle(p.x - (int) (vis.width / 2), |
565 |
p.y - (int) (vis.height / 2), vis.width, vis.height);
|
|
566 | 1 |
m_list.scrollRectToVisible(newView); |
567 |
} |
|
568 |
|
|
569 | 146 |
Point screen = m_list.getLocationOnScreen(); |
570 | 146 |
screen.translate(p.x, p.y); |
571 | 146 |
setLocationOnScreen(screen); |
572 |
|
|
573 | 146 |
return true; |
574 |
} |
|
575 |
|
|
576 |
/**
|
|
577 |
* Get string description of event.
|
|
578 |
* @return String description of event.
|
|
579 |
*/
|
|
580 | 4 |
public String toString() {
|
581 | 4 |
if (!isValid()) {
|
582 | 0 |
return super.toString(); |
583 |
} |
|
584 |
|
|
585 | 4 |
StringBuffer buf = new StringBuffer(1000);
|
586 | 4 |
buf.append(super.toString());
|
587 | 4 |
buf.append(" index: " + getElementIndex());
|
588 |
|
|
589 | 4 |
return buf.toString();
|
590 |
} |
|
591 |
|
|
592 |
/**
|
|
593 |
* Finds the index of the element passed in from the JComboBox.
|
|
594 |
*
|
|
595 |
* @param list The JList which holds the elements.
|
|
596 |
* @param element The element whose index has to be found out.
|
|
597 |
* @return int The zero-based index where the element occurs
|
|
598 |
* (-1 is returned if not found)
|
|
599 |
*/
|
|
600 | 6 |
private static int getIndexOf(final JList list, final Object element) { |
601 | 15 |
for (int i = 0; i < list.getModel().getSize(); i++) { |
602 | 15 |
if ((list.getModel().getElementAt(i) != null) |
603 |
&& list.getModel().getElementAt(i).equals(element)) { |
|
604 | 6 |
return i;
|
605 |
} |
|
606 |
} |
|
607 |
|
|
608 | 0 |
return -1;
|
609 |
} |
|
610 |
} |
|
611 |
|
|