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