blob: 6ad3b1af9d042270efd189348eafbe8f5fe81854 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 @test
26 @bug 6463545
27 @summary Tests java.awt.DefaultFocusTraversalPolicy functionality.
28 @author anton.tarasov area=awt.focus
29 @library ../../regtesthelpers
30 @build AbstractPolicyTest
31 @run main DefaultFTPTest
32*/
33
34import java.awt.*;
35import java.awt.event.*;
36import java.util.*;
37import test.java.awt.regtesthelpers.AbstractPolicyTest;
38
39/*
40
41Below are some notes about changes in DefaultFocusTraversalPolicy behaviour.
42
43container(root) [...] - focus traversal cycle with the <container> as the root.
44container(provider) [...] - focus traversal cycle with the <container> as the provider.
45container(..)(focusable) [...] - <container> is implicitly set focusable.
46comp[unfocusable] - <comp> is set unfocusable.
47
48
491. frame [ container(root)(focusable) [...] ]
50
51- getComponentAfter(<frame>, <container>) returns <container>.
52
53 If <container> is the default component to focus in its own cycle. * NO CHANGE *
54
55
563. frame [ comp1 container(root)(focusable) [ comp2 ] comp3 ]
57
58- getComponentBefore(<frame>, <comp3>) returns <comp2>. ** BEHAVIOUR CHANGE **
59
60 Previously <container> would be returned. This was a bug as it
61 wasn't according to the spec.
62
63- getComponentBefore(<container>, <comp2>) returns <container>. * NO CHANGE *
64
65- getComponentBefore(<frame>, <container>) returns <comp1>. * NO CHANGE *
66
67- getComponentBefore(<container>, <container>) returns <comp2>. * NO CHANGE *
68
69
704. frame [ container(provider) [...] comp ]
71
72- getComponentAfter(<frame>, <container>) returns <container>'s default. ** BEHAVIOUR CHANGE. SPEC ADDITION **
73
74 Previously <comp> would be returned. Not specified in the spec.
75
76- getComponentBefore(<frame>, <comp>) returns <container>'s last. ** SPEC CHANGE **
77
78 The spec says (incorrectly) that default should be returned.
79
80
815. frame [ container(provider)(focusable) [...] comp2 ]
82
83- getComponentBefore(<frame>, <comp2>) returns <container>'s last. ** BEHAVIOUR CHANGE. SPEC ADDITION **
84
85 Previously <container> would be returned. Not specified in the spec.
86
87
886. frame [ comp1 container(root) [...] comp2 ]
89
90- getComponentAfter(<frame>, <comp1>) returns <container>'s default. ** BEHAVIOUR CHANGE. SPEC ADDITION **
91
92 Previously <comp2> would be returned. It's just the fix for 6240842.
93 Not specified in the spec.
94
95
967. frame [ comp1 container(root) [...] comp2(unfocusable) comp3 ]
97
98- getComponentBefore(<frame>, <comp3>) returns <container>'s default. ** BEHAVIOUR CHANGE **
99
100 Previously <comp1> would be returned. This was a bug, because
101 in case if <comp2> is focusable getComponentBefore(<frame>, <comp2>) would
102 return <container>'s default.
103
104*/
105
106public class DefaultFTPTest {
107 final int TESTS_NUMBER = 10;
108
109 public static void main(String[] args) {
110 DefaultFTPTest app = new DefaultFTPTest();
111 app.start();
112 }
113
114 public void start() {
115 try {
116 Class clazz = null;
117 AbstractPolicyTest test = null;
118
119 for (int i = 1; i <= TESTS_NUMBER; i++) {
120 clazz = Class.forName("PolicyTest" + i);
121 if (clazz != null) {
122 test = (AbstractPolicyTest)clazz.newInstance();
123 System.out.print("Test " + i + " is in progress...");
124 test.testIt();
125 System.out.println(" passed.");
126 }
127 }
128 } catch (RuntimeException rte) {
129 throw rte;
130 } catch (Exception e) {
131 throw new RuntimeException("Error: unexpected exception cought!", e);
132 }
133 }
134}
135
136/*
137 * frame [ container1 [...] container2 [...] container3 [...] ]
138 * - verifies simple configuration.
139 */
140class PolicyTest1 extends AbstractPolicyTest {
141 protected Frame createFrame() {
142 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
143 frame.setLayout(new GridLayout(3, 1));
144
145 for (int i = 0; i < 3; i++) {
146 Container cont = (Container) registerComponent("panel" + i, new Panel());
147 for (int j = 0; j < 3; j++) {
148 cont.add(registerComponent("btn " + (j + i*100), new Button("button")));
149 }
150 frame.add(cont);
151 }
152 return frame;
153 }
154
155 protected void customizeHierarchy() {
156 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
157 }
158
159 protected Map<String, String> getForwardOrder() {
160 Map<String, String> order = new HashMap<String, String>();
161 order.put("btn 0", "btn 1");
162 order.put("btn 1", "btn 2");
163 order.put("btn 2", "btn 100");
164 order.put("btn 100", "btn 101");
165 order.put("btn 101", "btn 102");
166 order.put("btn 102", "btn 200");
167 order.put("btn 200", "btn 201");
168 order.put("btn 201", "btn 202");
169 order.put("btn 202", "btn 0");
170 order.put("panel0", "btn 0");
171 order.put("panel1", "btn 100");
172 order.put("panel2", "btn 200");
173 order.put("frame", "btn 0");
174 return order;
175 }
176
177 protected Map<String, String> getBackwardOrder() {
178 Map<String, String> order = new HashMap<String, String>();
179 order.put("btn 0", "btn 202");
180 order.put("btn 1", "btn 0");
181 order.put("btn 2", "btn 1");
182 order.put("btn 100", "btn 2");
183 order.put("btn 101", "btn 100");
184 order.put("btn 102", "btn 101");
185 order.put("btn 200", "btn 102");
186 order.put("btn 201", "btn 200");
187 order.put("btn 202", "btn 201");
188 order.put("panel0", "btn 202");
189 order.put("panel1", "btn 2");
190 order.put("panel2", "btn 102");
191 order.put("frame", "btn 202");
192 return order;
193 }
194
195 protected String[] getContainersToTest() {
196 return new String[] {"frame"};
197 }
198
199 protected String getDefaultComp(String focusCycleRoot_id) {
200 return "btn 0";
201 }
202
203 protected String getFirstComp(String focusCycleRoot_id) {
204 return "btn 0";
205 }
206
207 protected String getLastComp(String focusCycleRoot_id) {
208 return "btn 202";
209 }
210}
211
212/*
213 * frame [ comp container(provider) [...] comp ]
214 * - transfering focus through a provider.
215 */
216class PolicyTest2 extends AbstractPolicyTest {
217
218 protected Frame createFrame() {
219 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
220 frame.setLayout(new FlowLayout());
221
222 frame.add(registerComponent("btn 1", new Button("button")));
223
224 Container cont = (Container)registerComponent("panel", new Panel());
225 cont.add(registerComponent("btn 2", new Button("button")));
226 cont.add(registerComponent("btn 3", new Button("button")));
227 frame.add(cont);
228
229 frame.add(registerComponent("btn 4", new Button("button")));
230
231 return frame;
232 }
233
234 protected void customizeHierarchy() {
235 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
236 ((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);
237 }
238
239 protected Map<String, String> getForwardOrder() {
240 Map<String, String> order = new HashMap<String, String>();
241 order.put("frame", "btn 1");
242 order.put("btn 1", "btn 2");
243 order.put("btn 2", "btn 3");
244 order.put("btn 3", "btn 4");
245 order.put("btn 4", "btn 1");
246 order.put("panel", "btn 2");
247 return order;
248 }
249
250 protected Map<String, String> getBackwardOrder() {
251 Map<String, String> order = new HashMap<String, String>();
252 order.put("btn 4", "btn 3");
253 order.put("btn 3", "btn 2");
254 order.put("btn 2", "btn 1");
255 order.put("btn 1", "btn 4");
256 return order;
257 }
258
259 protected String[] getContainersToTest() {
260 return new String[] {"frame", "panel"};
261 }
262
263 protected String getDefaultComp(String focusCycleRoot_id) {
264 if ("frame".equals(focusCycleRoot_id)) {
265 return "btn 1";
266 } else if ("panel".equals(focusCycleRoot_id)) {
267 return "btn 2";
268 }
269 return null;
270 }
271
272 protected String getFirstComp(String focusCycleRoot_id) {
273 return getDefaultComp(focusCycleRoot_id);
274 }
275
276 protected String getLastComp(String focusCycleRoot_id) {
277 if ("frame".equals(focusCycleRoot_id)) {
278 return "btn 4";
279 } else if ("panel".equals(focusCycleRoot_id)) {
280 return "btn 3";
281 }
282 return null;
283 }
284}
285
286/*
287 * frame [ comp container(root) [...] comp ]
288 * - transfering focus through a root (includes the case reported in the CR 6240842).
289 */
290class PolicyTest3 extends AbstractPolicyTest {
291
292 protected Frame createFrame() {
293 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
294 frame.setLayout(new FlowLayout());
295
296 frame.add(registerComponent("btn 1", new Button("button")));
297
298 Container cont = (Container)registerComponent("panel", new Panel());
299 cont.add(registerComponent("btn 2", new Button("button")));
300 cont.add(registerComponent("btn 3", new Button("button")));
301 frame.add(cont);
302
303 frame.add(registerComponent("btn 4", new Button("button")));
304
305 return frame;
306 }
307
308 protected void customizeHierarchy() {
309 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
310 ((Container)getComponent("panel")).setFocusCycleRoot(true);
311 }
312
313 protected Map<String, String> getForwardOrder() {
314 Map<String, String> order = new HashMap<String, String>();
315 order.put("frame", "btn 1");
316 order.put("btn 1", "btn 2");
317 order.put("btn 2", "btn 3");
318 order.put("btn 3", "btn 2");
319 order.put("btn 4", "btn 1");
320 order.put("panel", "btn 2");
321 return order;
322 }
323
324 protected Map<String, String> getBackwardOrder() {
325 Map<String, String> order = new HashMap<String, String>();
326 order.put("btn 4", "btn 2");
327 order.put("btn 3", "btn 2");
328 order.put("btn 2", "btn 3");
329 order.put("btn 1", "btn 4");
330 return order;
331 }
332
333 protected String[] getContainersToTest() {
334 return new String[] {"frame", "panel"};
335 }
336
337 protected String getDefaultComp(String focusCycleRoot_id) {
338 if ("frame".equals(focusCycleRoot_id)) {
339 return "btn 1";
340 } else if ("panel".equals(focusCycleRoot_id)) {
341 return "btn 2";
342 }
343 return null;
344 }
345
346 protected String getFirstComp(String focusCycleRoot_id) {
347 return getDefaultComp(focusCycleRoot_id);
348 }
349
350 protected String getLastComp(String focusCycleRoot_id) {
351 if ("frame".equals(focusCycleRoot_id)) {
352 return "btn 4";
353 } else if ("panel".equals(focusCycleRoot_id)) {
354 return "btn 3";
355 }
356 return null;
357 }
358}
359
360/*
361 * frame [ container(provider) [...] comp1(unfocusable) comp2 ]
362 * - getComponentBefore(<frame>, <comp2>) should return <container>'s last.
363 */
364class PolicyTest4 extends AbstractPolicyTest {
365
366 protected Frame createFrame() {
367 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
368 frame.setLayout(new FlowLayout());
369
370 Container cont = (Container)registerComponent("panel", new Panel());
371 cont.add(registerComponent("btn 1", new Button("button")));
372 cont.add(registerComponent("btn 2", new Button("button")));
373 frame.add(cont);
374
375 frame.add(registerComponent("btn 3", new Button("button")));
376 frame.add(registerComponent("btn 4", new Button("button")));
377
378 return frame;
379 }
380
381 protected void customizeHierarchy() {
382 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
383 ((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);
384 ((Button)getComponent("btn 3")).setFocusable(false);
385 }
386
387 protected Map<String, String> getBackwardOrder() {
388 Map<String, String> order = new HashMap<String, String>();
389 order.put("btn 4", "btn 2");
390 order.put("btn 2", "btn 1");
391 order.put("btn 1", "btn 4");
392 return order;
393 }
394
395 // no testing
396 protected Map<String, String> getForwardOrder() {
397 return null;
398 }
399 protected String[] getContainersToTest() {
400 return null;
401 }
402 protected String getDefaultComp(String focusCycleRoot_id) {
403 return null;
404 }
405 protected String getFirstComp(String focusCycleRoot_id) {
406 return null;
407 }
408 protected String getLastComp(String focusCycleRoot_id) {
409 return null;
410 }
411}
412
413/*
414 * frame [ container(root) [...] comp1(unfocusable) comp2 ]
415 * - getComponentBefore(<frame>, <comp2>) should return <container>'s default.
416 */
417class PolicyTest5 extends AbstractPolicyTest {
418
419 protected Frame createFrame() {
420 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
421 frame.setLayout(new FlowLayout());
422
423 Container cont = (Container)registerComponent("panel", new Panel());
424 cont.add(registerComponent("btn 1", new Button("button")));
425 cont.add(registerComponent("btn 2", new Button("button")));
426 frame.add(cont);
427
428 frame.add(registerComponent("btn 3", new Button("button")));
429 frame.add(registerComponent("btn 4", new Button("button")));
430
431 return frame;
432 }
433
434 protected void customizeHierarchy() {
435 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
436 ((Container)getComponent("panel")).setFocusCycleRoot(true);
437 ((Button)getComponent("btn 3")).setFocusable(false);
438 }
439
440 protected Map<String, String> getBackwardOrder() {
441 Map<String, String> order = new HashMap<String, String>();
442 order.put("btn 4", "btn 1");
443 order.put("btn 2", "btn 1");
444 order.put("btn 1", "btn 2");
445 return order;
446 }
447
448 // no testing
449 protected Map<String, String> getForwardOrder() {
450 return null;
451 }
452 protected String[] getContainersToTest() {
453 return null;
454 }
455 protected String getDefaultComp(String focusCycleRoot_id) {
456 return null;
457 }
458 protected String getFirstComp(String focusCycleRoot_id) {
459 return null;
460 }
461 protected String getLastComp(String focusCycleRoot_id) {
462 return null;
463 }
464}
465
466/*
467 * frame [ comp container(provider)(focusable) [...] comp ]
468 * - transfering focus through a focusable provider.
469 */
470class PolicyTest6 extends AbstractPolicyTest {
471
472 protected Frame createFrame() {
473 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
474 frame.setLayout(new FlowLayout());
475
476 frame.add(registerComponent("btn 1", new Button("button")));
477
478 Container cont = (Container)registerComponent("panel", new Panel());
479 cont.add(registerComponent("btn 2", new Button("button")));
480 cont.add(registerComponent("btn 3", new Button("button")));
481 frame.add(cont);
482
483 frame.add(registerComponent("btn 4", new Button("button")));
484
485 return frame;
486 }
487
488 protected void customizeHierarchy() {
489 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
490 ((Container)getComponent("panel")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
491 public Component getDefaultComponent(Container aContainer) {
492 return getComponent("btn 2");
493 }
494 });
495 ((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);
496 ((Container)getComponent("panel")).setFocusable(true);
497 }
498
499 protected Map<String, String> getForwardOrder() {
500 Map<String, String> order = new HashMap<String, String>();
501 order.put("frame", "btn 1");
502 order.put("btn 1", "panel");
503 order.put("btn 2", "btn 3");
504 order.put("btn 3", "btn 4");
505 order.put("btn 4", "btn 1");
506 order.put("panel", "btn 2");
507 return order;
508 }
509
510 protected Map<String, String> getBackwardOrder() {
511 Map<String, String> order = new HashMap<String, String>();
512 order.put("btn 4", "btn 3");
513 order.put("btn 3", "btn 2");
514 order.put("btn 2", "panel");
515 order.put("btn 1", "btn 4");
516 order.put("panel", "btn 1");
517 return order;
518 }
519
520 protected String[] getContainersToTest() {
521 return new String[] {"panel"};
522 }
523
524 protected String getDefaultComp(String focusCycleRoot_id) {
525 return "btn 2";
526 }
527
528 protected String getFirstComp(String focusCycleRoot_id) {
529 return "panel";
530 }
531
532 protected String getLastComp(String focusCycleRoot_id) {
533 return "btn 3";
534 }
535}
536
537/*
538 * frame [ comp container(root)(focusable) [...] comp ]
539 * - transfering focus through a focusable root.
540 */
541class PolicyTest7 extends AbstractPolicyTest {
542
543 protected Frame createFrame() {
544 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
545 frame.setLayout(new FlowLayout());
546
547 frame.add(registerComponent("btn 1", new Button("button")));
548
549 Container cont = (Container)registerComponent("panel", new Panel());
550 cont.add(registerComponent("btn 2", new Button("button")));
551 cont.add(registerComponent("btn 3", new Button("button")));
552 frame.add(cont);
553
554 frame.add(registerComponent("btn 4", new Button("button")));
555
556 return frame;
557 }
558
559 protected void customizeHierarchy() {
560 ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
561 ((Container)getComponent("panel")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
562 public Component getDefaultComponent(Container aContainer) {
563 return getComponent("btn 2");
564 }
565 });
566 ((Container)getComponent("panel")).setFocusCycleRoot(true);
567 ((Container)getComponent("panel")).setFocusable(true);
568 }
569
570 protected Map<String, String> getForwardOrder() {
571 Map<String, String> order = new HashMap<String, String>();
572 order.put("frame", "btn 1");
573 order.put("btn 1", "panel");
574 order.put("btn 2", "btn 3");
575 order.put("btn 3", "panel");
576 order.put("btn 4", "btn 1");
577 order.put("panel", "btn 2");
578 return order;
579 }
580
581 protected Map<String, String> getBackwardOrder() {
582 Map<String, String> order = new HashMap<String, String>();
583 order.put("btn 4", "btn 2");
584 order.put("btn 3", "btn 2");
585 order.put("btn 2", "panel");
586 order.put("btn 1", "btn 4");
587 order.put("panel", "btn 1");
588 return order;
589 }
590
591 protected String[] getContainersToTest() {
592 return new String[] {"panel"};
593 }
594
595 protected String getDefaultComp(String focusCycleRoot_id) {
596 return "btn 2";
597 }
598
599 protected String getFirstComp(String focusCycleRoot_id) {
600 return "panel";
601 }
602
603 protected String getLastComp(String focusCycleRoot_id) {
604 return "btn 3";
605 }
606}
607
608/*
609 * frame [ comp1 comp2 container1(provider) [...] container2(root) [...] ]
610 * - verifies a case when a provider is followed by a root.
611 */
612class PolicyTest8 extends AbstractPolicyTest {
613
614 protected Frame createFrame() {
615 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
616 frame.setLayout(new FlowLayout());
617
618 frame.add(registerComponent("btn-1", new Button("button")));
619 frame.add(registerComponent("btn-2", new Button("button")));
620
621 Container cont1 = (Container)registerComponent("panel-1", new Panel());
622 cont1.add(registerComponent("btn-3", new Button("button")));
623 cont1.add(registerComponent("btn-4", new Button("button")));
624 cont1.add(registerComponent("btn-5", new Button("button")));
625
626 Container cont2 = (Container)registerComponent("panel-2", new Panel());
627 cont2.add(registerComponent("btn-6", new Button("button")));
628 cont2.add(registerComponent("btn-7", new Button("button")));
629 cont2.add(registerComponent("btn-8", new Button("button")));
630
631 frame.add(cont1);
632 frame.add(cont2);
633
634 return frame;
635 }
636
637 protected void customizeHierarchy() {
638 ((Container)getComponent("panel-1")).setFocusTraversalPolicyProvider(true);
639 ((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
640 public Component getDefaultComponent(Container aContainer) {
641 return getComponent("btn-4");
642 }
643 });
644
645 ((Container)getComponent("panel-2")).setFocusCycleRoot(true);
646 ((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
647 public Component getDefaultComponent(Container aContainer) {
648 return getComponent("btn-7");
649 }
650 });
651 }
652
653 protected Map<String, String> getForwardOrder() {
654 Map<String, String> order = new HashMap<String, String>();
655 order.put("frame", "btn-1");
656 order.put("btn-1", "btn-2");
657 order.put("btn-2", "btn-4");
658 order.put("btn-3", "btn-4");
659 order.put("btn-4", "btn-5");
660 order.put("btn-5", "btn-7");
661 order.put("btn-6", "btn-7");
662 order.put("btn-7", "btn-8");
663 order.put("btn-8", "btn-6");
664 order.put("panel-1", "btn-4");
665 order.put("panel-2", "btn-7");
666 return order;
667 }
668
669 protected Map<String, String> getBackwardOrder() {
670 Map<String, String> order = new HashMap<String, String>();
671 order.put("btn-1", "btn-5");
672 order.put("btn-2", "btn-1");
673 order.put("btn-3", "btn-2");
674 order.put("btn-4", "btn-3");
675 order.put("btn-5", "btn-4");
676 order.put("btn-6", "btn-8");
677 order.put("btn-7", "btn-6");
678 order.put("btn-8", "btn-7");
679 return order;
680 }
681
682 protected String[] getContainersToTest() {
683 return new String[] {"frame", "panel-1", "panel-2"};
684 }
685
686 protected String getDefaultComp(String focusCycleRoot_id) {
687 if ("frame".equals(focusCycleRoot_id)) {
688 return "btn-1";
689 } else if ("panel-1".equals(focusCycleRoot_id)) {
690 return "btn-4";
691 } else if ("panel-2".equals(focusCycleRoot_id)) {
692 return "btn-7";
693 }
694 return null;
695 }
696
697 protected String getFirstComp(String focusCycleRoot_id) {
698 if ("frame".equals(focusCycleRoot_id)) {
699 return "btn-1";
700 } else if ("panel-1".equals(focusCycleRoot_id)) {
701 return "btn-3";
702 } else if ("panel-2".equals(focusCycleRoot_id)) {
703 return "btn-6";
704 }
705 return null;
706 }
707
708 protected String getLastComp(String focusCycleRoot_id) {
709 if ("frame".equals(focusCycleRoot_id)) {
710 return "btn-5";
711 } else if ("panel-1".equals(focusCycleRoot_id)) {
712 return "btn-5";
713 } else if ("panel-2".equals(focusCycleRoot_id)) {
714 return "btn-8";
715 }
716 return null;
717 }
718}
719
720/*
721 * frame [ comp1 comp2 container1(root) [...] container2(provider) [...] ]
722 * - verifies a case when a root is followed by a provider.
723 */
724class PolicyTest9 extends AbstractPolicyTest {
725
726 protected Frame createFrame() {
727 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
728 frame.setLayout(new FlowLayout());
729
730 frame.add(registerComponent("btn-1", new Button("button")));
731 frame.add(registerComponent("btn-2", new Button("button")));
732
733 Container cont1 = (Container)registerComponent("panel-1", new Panel());
734 cont1.add(registerComponent("btn-3", new Button("button")));
735 cont1.add(registerComponent("btn-4", new Button("button")));
736 cont1.add(registerComponent("btn-5", new Button("button")));
737
738 Container cont2 = (Container)registerComponent("panel-2", new Panel());
739 cont2.add(registerComponent("btn-6", new Button("button")));
740 cont2.add(registerComponent("btn-7", new Button("button")));
741 cont2.add(registerComponent("btn-8", new Button("button")));
742
743 frame.add(cont1);
744 frame.add(cont2);
745
746 return frame;
747 }
748
749 protected void customizeHierarchy() {
750 ((Container)getComponent("panel-1")).setFocusCycleRoot(true);
751 ((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
752 public Component getDefaultComponent(Container aContainer) {
753 return getComponent("btn-4");
754 }
755 });
756
757 ((Container)getComponent("panel-2")).setFocusTraversalPolicyProvider(true);
758 ((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
759 public Component getDefaultComponent(Container aContainer) {
760 return getComponent("btn-7");
761 }
762 });
763 }
764
765 protected Map<String, String> getForwardOrder() {
766 Map<String, String> order = new HashMap<String, String>();
767 order.put("frame", "btn-1");
768 order.put("btn-1", "btn-2");
769 order.put("btn-2", "btn-4");
770 order.put("btn-3", "btn-4");
771 order.put("btn-4", "btn-5");
772 order.put("btn-5", "btn-3");
773 order.put("btn-6", "btn-7");
774 order.put("btn-7", "btn-8");
775 order.put("btn-8", "btn-1");
776 order.put("panel-1", "btn-4");
777 order.put("panel-2", "btn-7");
778 return order;
779 }
780
781 protected Map<String, String> getBackwardOrder() {
782 Map<String, String> order = new HashMap<String, String>();
783 order.put("btn-1", "btn-8");
784 order.put("btn-2", "btn-1");
785 order.put("btn-3", "btn-5");
786 order.put("btn-4", "btn-3");
787 order.put("btn-5", "btn-4");
788 order.put("btn-6", "btn-4");
789 order.put("btn-7", "btn-6");
790 order.put("btn-8", "btn-7");
791 return order;
792 }
793
794 protected String[] getContainersToTest() {
795 return new String[] {"frame", "panel-1", "panel-2"};
796 }
797
798 protected String getDefaultComp(String focusCycleRoot_id) {
799 if ("frame".equals(focusCycleRoot_id)) {
800 return "btn-1";
801 } else if ("panel-1".equals(focusCycleRoot_id)) {
802 return "btn-4";
803 } else if ("panel-2".equals(focusCycleRoot_id)) {
804 return "btn-7";
805 }
806 return null;
807 }
808
809 protected String getFirstComp(String focusCycleRoot_id) {
810 if ("frame".equals(focusCycleRoot_id)) {
811 return "btn-1";
812 } else if ("panel-1".equals(focusCycleRoot_id)) {
813 return "btn-3";
814 } else if ("panel-2".equals(focusCycleRoot_id)) {
815 return "btn-6";
816 }
817 return null;
818 }
819
820 protected String getLastComp(String focusCycleRoot_id) {
821 if ("frame".equals(focusCycleRoot_id)) {
822 return "btn-8";
823 } else if ("panel-1".equals(focusCycleRoot_id)) {
824 return "btn-5";
825 } else if ("panel-2".equals(focusCycleRoot_id)) {
826 return "btn-8";
827 }
828 return null;
829 }
830}
831
832/*
833 * frame [ container0 [...] container1(root) [ comp1 comp2 container2(provider) [...] ] ]
834 * - verifies a case when a provider is nested in a root.
835 */
836class PolicyTest10 extends AbstractPolicyTest {
837
838 protected Frame createFrame() {
839 Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
840 frame.setLayout(new GridLayout(2, 1));
841
842 Container cont0 = new Panel();
843 cont0.add(registerComponent("btn-1", new Button("button")));
844 cont0.add(registerComponent("btn-2", new Button("button")));
845
846 Container cont1 = (Container)registerComponent("panel-1", new Panel());
847 cont1.add(registerComponent("btn-3", new Button("button")));
848 cont1.add(registerComponent("btn-4", new Button("button")));
849
850 Container cont2 = (Container)registerComponent("panel-2", new Panel());
851 cont2.add(registerComponent("btn-5", new Button("button")));
852 cont2.add(registerComponent("btn-6", new Button("button")));
853
854 cont1.add(cont2);
855 frame.add(cont0);
856 frame.add(cont1);
857
858 return frame;
859 }
860
861 protected void customizeHierarchy() {
862 ((Container)getComponent("panel-1")).setFocusCycleRoot(true);
863 ((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {
864 public Component getDefaultComponent(Container aContainer) {
865 return getComponent("panel-2");
866 }
867 });
868 ((Container)getComponent("panel-2")).setFocusTraversalPolicyProvider(true);
869 ((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
870 }
871
872 protected Map<String, String> getForwardOrder() {
873 Map<String, String> order = new HashMap<String, String>();
874 order.put("frame", "btn-1");
875 order.put("btn-1", "btn-2");
876 order.put("btn-2", "panel-2");
877 order.put("btn-3", "btn-4");
878 order.put("btn-4", "btn-5");
879 order.put("btn-5", "btn-6");
880 order.put("btn-6", "btn-3");
881 order.put("panel-1", "panel-2");
882 order.put("panel-2", "btn-5");
883 return order;
884 }
885
886 protected Map<String, String> getBackwardOrder() {
887 Map<String, String> order = new HashMap<String, String>();
888 order.put("btn-1", "btn-2");
889 order.put("btn-2", "btn-1");
890 order.put("btn-3", "btn-6");
891 order.put("btn-4", "btn-3");
892 order.put("btn-5", "btn-4");
893 order.put("btn-6", "btn-5");
894 return order;
895 }
896
897 protected String[] getContainersToTest() {
898 return new String[] {"frame", "panel-1", "panel-2"};
899 }
900
901 protected String getDefaultComp(String focusCycleRoot_id) {
902 if ("frame".equals(focusCycleRoot_id)) {
903 return "btn-1";
904 } else if ("panel-1".equals(focusCycleRoot_id)) {
905 return "panel-2";
906 } else if ("panel-2".equals(focusCycleRoot_id)) {
907 return "btn-5";
908 }
909 return null;
910 }
911
912 protected String getFirstComp(String focusCycleRoot_id) {
913 if ("frame".equals(focusCycleRoot_id)) {
914 return "btn-1";
915 } else if ("panel-1".equals(focusCycleRoot_id)) {
916 return "btn-3";
917 } else if ("panel-2".equals(focusCycleRoot_id)) {
918 return "btn-5";
919 }
920 return null;
921 }
922
923 protected String getLastComp(String focusCycleRoot_id) {
924 if ("frame".equals(focusCycleRoot_id)) {
925 return "btn-2";
926 } else {
927 return "btn-6";
928 }
929 }
930}