Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/awt/Focus/FocusTraversalPolicy/DefaultFTPTest.java
48795 views
/*1* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 646354526@summary Tests java.awt.DefaultFocusTraversalPolicy functionality.27@author anton.tarasov area=awt.focus28@library ../../regtesthelpers29@build AbstractPolicyTest30@run main DefaultFTPTest31*/3233import java.awt.*;34import java.awt.event.*;35import java.util.*;36import test.java.awt.regtesthelpers.AbstractPolicyTest;3738/*3940Below are some notes about changes in DefaultFocusTraversalPolicy behaviour.4142container(root) [...] - focus traversal cycle with the <container> as the root.43container(provider) [...] - focus traversal cycle with the <container> as the provider.44container(..)(focusable) [...] - <container> is implicitly set focusable.45comp[unfocusable] - <comp> is set unfocusable.4647481. frame [ container(root)(focusable) [...] ]4950- getComponentAfter(<frame>, <container>) returns <container>.5152If <container> is the default component to focus in its own cycle. * NO CHANGE *5354553. frame [ comp1 container(root)(focusable) [ comp2 ] comp3 ]5657- getComponentBefore(<frame>, <comp3>) returns <comp2>. ** BEHAVIOUR CHANGE **5859Previously <container> would be returned. This was a bug as it60wasn't according to the spec.6162- getComponentBefore(<container>, <comp2>) returns <container>. * NO CHANGE *6364- getComponentBefore(<frame>, <container>) returns <comp1>. * NO CHANGE *6566- getComponentBefore(<container>, <container>) returns <comp2>. * NO CHANGE *6768694. frame [ container(provider) [...] comp ]7071- getComponentAfter(<frame>, <container>) returns <container>'s default. ** BEHAVIOUR CHANGE. SPEC ADDITION **7273Previously <comp> would be returned. Not specified in the spec.7475- getComponentBefore(<frame>, <comp>) returns <container>'s last. ** SPEC CHANGE **7677The spec says (incorrectly) that default should be returned.7879805. frame [ container(provider)(focusable) [...] comp2 ]8182- getComponentBefore(<frame>, <comp2>) returns <container>'s last. ** BEHAVIOUR CHANGE. SPEC ADDITION **8384Previously <container> would be returned. Not specified in the spec.8586876. frame [ comp1 container(root) [...] comp2 ]8889- getComponentAfter(<frame>, <comp1>) returns <container>'s default. ** BEHAVIOUR CHANGE. SPEC ADDITION **9091Previously <comp2> would be returned. It's just the fix for 6240842.92Not specified in the spec.9394957. frame [ comp1 container(root) [...] comp2(unfocusable) comp3 ]9697- getComponentBefore(<frame>, <comp3>) returns <container>'s default. ** BEHAVIOUR CHANGE **9899Previously <comp1> would be returned. This was a bug, because100in case if <comp2> is focusable getComponentBefore(<frame>, <comp2>) would101return <container>'s default.102103*/104105public class DefaultFTPTest {106final int TESTS_NUMBER = 11;107108public static void main(String[] args) {109DefaultFTPTest app = new DefaultFTPTest();110app.start();111}112113public void start() {114try {115Class clazz = null;116AbstractPolicyTest test = null;117118for (int i = 1; i <= TESTS_NUMBER; i++) {119clazz = Class.forName("PolicyTest" + i);120if (clazz != null) {121test = (AbstractPolicyTest)clazz.newInstance();122System.out.print("Test " + i + " is in progress...");123test.testIt();124System.out.println(" passed.");125}126}127} catch (RuntimeException rte) {128throw rte;129} catch (Exception e) {130throw new RuntimeException("Error: unexpected exception cought!", e);131}132}133}134135/*136* frame [ container1 [...] container2 [...] container3 [...] ]137* - verifies simple configuration.138*/139class PolicyTest1 extends AbstractPolicyTest {140protected Frame createFrame() {141Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));142frame.setLayout(new GridLayout(3, 1));143144for (int i = 0; i < 3; i++) {145Container cont = (Container) registerComponent("panel" + i, new Panel());146for (int j = 0; j < 3; j++) {147cont.add(registerComponent("btn " + (j + i*100), new Button("button")));148}149frame.add(cont);150}151return frame;152}153154protected void customizeHierarchy() {155((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());156}157158protected Map<String, String> getForwardOrder() {159Map<String, String> order = new HashMap<String, String>();160order.put("btn 0", "btn 1");161order.put("btn 1", "btn 2");162order.put("btn 2", "btn 100");163order.put("btn 100", "btn 101");164order.put("btn 101", "btn 102");165order.put("btn 102", "btn 200");166order.put("btn 200", "btn 201");167order.put("btn 201", "btn 202");168order.put("btn 202", "btn 0");169order.put("panel0", "btn 0");170order.put("panel1", "btn 100");171order.put("panel2", "btn 200");172order.put("frame", "btn 0");173return order;174}175176protected Map<String, String> getBackwardOrder() {177Map<String, String> order = new HashMap<String, String>();178order.put("btn 0", "btn 202");179order.put("btn 1", "btn 0");180order.put("btn 2", "btn 1");181order.put("btn 100", "btn 2");182order.put("btn 101", "btn 100");183order.put("btn 102", "btn 101");184order.put("btn 200", "btn 102");185order.put("btn 201", "btn 200");186order.put("btn 202", "btn 201");187order.put("panel0", "btn 202");188order.put("panel1", "btn 2");189order.put("panel2", "btn 102");190order.put("frame", "btn 202");191return order;192}193194protected String[] getContainersToTest() {195return new String[] {"frame"};196}197198protected String getDefaultComp(String focusCycleRoot_id) {199return "btn 0";200}201202protected String getFirstComp(String focusCycleRoot_id) {203return "btn 0";204}205206protected String getLastComp(String focusCycleRoot_id) {207return "btn 202";208}209}210211/*212* frame [ comp container(provider) [...] comp ]213* - transfering focus through a provider.214*/215class PolicyTest2 extends AbstractPolicyTest {216217protected Frame createFrame() {218Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));219frame.setLayout(new FlowLayout());220221frame.add(registerComponent("btn 1", new Button("button")));222223Container cont = (Container)registerComponent("panel", new Panel());224cont.add(registerComponent("btn 2", new Button("button")));225cont.add(registerComponent("btn 3", new Button("button")));226frame.add(cont);227228frame.add(registerComponent("btn 4", new Button("button")));229230return frame;231}232233protected void customizeHierarchy() {234((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());235((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);236}237238protected Map<String, String> getForwardOrder() {239Map<String, String> order = new HashMap<String, String>();240order.put("frame", "btn 1");241order.put("btn 1", "btn 2");242order.put("btn 2", "btn 3");243order.put("btn 3", "btn 4");244order.put("btn 4", "btn 1");245order.put("panel", "btn 2");246return order;247}248249protected Map<String, String> getBackwardOrder() {250Map<String, String> order = new HashMap<String, String>();251order.put("btn 4", "btn 3");252order.put("btn 3", "btn 2");253order.put("btn 2", "btn 1");254order.put("btn 1", "btn 4");255return order;256}257258protected String[] getContainersToTest() {259return new String[] {"frame", "panel"};260}261262protected String getDefaultComp(String focusCycleRoot_id) {263if ("frame".equals(focusCycleRoot_id)) {264return "btn 1";265} else if ("panel".equals(focusCycleRoot_id)) {266return "btn 2";267}268return null;269}270271protected String getFirstComp(String focusCycleRoot_id) {272return getDefaultComp(focusCycleRoot_id);273}274275protected String getLastComp(String focusCycleRoot_id) {276if ("frame".equals(focusCycleRoot_id)) {277return "btn 4";278} else if ("panel".equals(focusCycleRoot_id)) {279return "btn 3";280}281return null;282}283}284285/*286* frame [ comp container(root) [...] comp ]287* - transfering focus through a root (includes the case reported in the CR 6240842).288*/289class PolicyTest3 extends AbstractPolicyTest {290291protected Frame createFrame() {292Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));293frame.setLayout(new FlowLayout());294295frame.add(registerComponent("btn 1", new Button("button")));296297Container cont = (Container)registerComponent("panel", new Panel());298cont.add(registerComponent("btn 2", new Button("button")));299cont.add(registerComponent("btn 3", new Button("button")));300frame.add(cont);301302frame.add(registerComponent("btn 4", new Button("button")));303304return frame;305}306307protected void customizeHierarchy() {308((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());309((Container)getComponent("panel")).setFocusCycleRoot(true);310}311312protected Map<String, String> getForwardOrder() {313Map<String, String> order = new HashMap<String, String>();314order.put("frame", "btn 1");315order.put("btn 1", "btn 2");316order.put("btn 2", "btn 3");317order.put("btn 3", "btn 2");318order.put("btn 4", "btn 1");319order.put("panel", "btn 2");320return order;321}322323protected Map<String, String> getBackwardOrder() {324Map<String, String> order = new HashMap<String, String>();325order.put("btn 4", "btn 2");326order.put("btn 3", "btn 2");327order.put("btn 2", "btn 3");328order.put("btn 1", "btn 4");329return order;330}331332protected String[] getContainersToTest() {333return new String[] {"frame", "panel"};334}335336protected String getDefaultComp(String focusCycleRoot_id) {337if ("frame".equals(focusCycleRoot_id)) {338return "btn 1";339} else if ("panel".equals(focusCycleRoot_id)) {340return "btn 2";341}342return null;343}344345protected String getFirstComp(String focusCycleRoot_id) {346return getDefaultComp(focusCycleRoot_id);347}348349protected String getLastComp(String focusCycleRoot_id) {350if ("frame".equals(focusCycleRoot_id)) {351return "btn 4";352} else if ("panel".equals(focusCycleRoot_id)) {353return "btn 3";354}355return null;356}357}358359/*360* frame [ container(provider) [...] comp1(unfocusable) comp2 ]361* - getComponentBefore(<frame>, <comp2>) should return <container>'s last.362*/363class PolicyTest4 extends AbstractPolicyTest {364365protected Frame createFrame() {366Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));367frame.setLayout(new FlowLayout());368369Container cont = (Container)registerComponent("panel", new Panel());370cont.add(registerComponent("btn 1", new Button("button")));371cont.add(registerComponent("btn 2", new Button("button")));372frame.add(cont);373374frame.add(registerComponent("btn 3", new Button("button")));375frame.add(registerComponent("btn 4", new Button("button")));376377return frame;378}379380protected void customizeHierarchy() {381((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());382((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);383((Button)getComponent("btn 3")).setFocusable(false);384}385386protected Map<String, String> getBackwardOrder() {387Map<String, String> order = new HashMap<String, String>();388order.put("btn 4", "btn 2");389order.put("btn 2", "btn 1");390order.put("btn 1", "btn 4");391return order;392}393394// no testing395protected Map<String, String> getForwardOrder() {396return null;397}398protected String[] getContainersToTest() {399return null;400}401protected String getDefaultComp(String focusCycleRoot_id) {402return null;403}404protected String getFirstComp(String focusCycleRoot_id) {405return null;406}407protected String getLastComp(String focusCycleRoot_id) {408return null;409}410}411412/*413* frame [ container(root) [...] comp1(unfocusable) comp2 ]414* - getComponentBefore(<frame>, <comp2>) should return <container>'s default.415*/416class PolicyTest5 extends AbstractPolicyTest {417418protected Frame createFrame() {419Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));420frame.setLayout(new FlowLayout());421422Container cont = (Container)registerComponent("panel", new Panel());423cont.add(registerComponent("btn 1", new Button("button")));424cont.add(registerComponent("btn 2", new Button("button")));425frame.add(cont);426427frame.add(registerComponent("btn 3", new Button("button")));428frame.add(registerComponent("btn 4", new Button("button")));429430return frame;431}432433protected void customizeHierarchy() {434((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());435((Container)getComponent("panel")).setFocusCycleRoot(true);436((Button)getComponent("btn 3")).setFocusable(false);437}438439protected Map<String, String> getBackwardOrder() {440Map<String, String> order = new HashMap<String, String>();441order.put("btn 4", "btn 1");442order.put("btn 2", "btn 1");443order.put("btn 1", "btn 2");444return order;445}446447// no testing448protected Map<String, String> getForwardOrder() {449return null;450}451protected String[] getContainersToTest() {452return null;453}454protected String getDefaultComp(String focusCycleRoot_id) {455return null;456}457protected String getFirstComp(String focusCycleRoot_id) {458return null;459}460protected String getLastComp(String focusCycleRoot_id) {461return null;462}463}464465/*466* frame [ comp container(provider)(focusable) [...] comp ]467* - transfering focus through a focusable provider.468*/469class PolicyTest6 extends AbstractPolicyTest {470471protected Frame createFrame() {472Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));473frame.setLayout(new FlowLayout());474475frame.add(registerComponent("btn 1", new Button("button")));476477Container cont = (Container)registerComponent("panel", new Panel());478cont.add(registerComponent("btn 2", new Button("button")));479cont.add(registerComponent("btn 3", new Button("button")));480frame.add(cont);481482frame.add(registerComponent("btn 4", new Button("button")));483484return frame;485}486487protected void customizeHierarchy() {488((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());489((Container)getComponent("panel")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {490public Component getDefaultComponent(Container aContainer) {491return getComponent("btn 2");492}493});494((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);495((Container)getComponent("panel")).setFocusable(true);496}497498protected Map<String, String> getForwardOrder() {499Map<String, String> order = new HashMap<String, String>();500order.put("frame", "btn 1");501order.put("btn 1", "panel");502order.put("btn 2", "btn 3");503order.put("btn 3", "btn 4");504order.put("btn 4", "btn 1");505order.put("panel", "btn 2");506return order;507}508509protected Map<String, String> getBackwardOrder() {510Map<String, String> order = new HashMap<String, String>();511order.put("btn 4", "btn 3");512order.put("btn 3", "btn 2");513order.put("btn 2", "panel");514order.put("btn 1", "btn 4");515order.put("panel", "btn 1");516return order;517}518519protected String[] getContainersToTest() {520return new String[] {"panel"};521}522523protected String getDefaultComp(String focusCycleRoot_id) {524return "btn 2";525}526527protected String getFirstComp(String focusCycleRoot_id) {528return "panel";529}530531protected String getLastComp(String focusCycleRoot_id) {532return "btn 3";533}534}535536/*537* frame [ comp container(root)(focusable) [...] comp ]538* - transfering focus through a focusable root.539*/540class PolicyTest7 extends AbstractPolicyTest {541542protected Frame createFrame() {543Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));544frame.setLayout(new FlowLayout());545546frame.add(registerComponent("btn 1", new Button("button")));547548Container cont = (Container)registerComponent("panel", new Panel());549cont.add(registerComponent("btn 2", new Button("button")));550cont.add(registerComponent("btn 3", new Button("button")));551frame.add(cont);552553frame.add(registerComponent("btn 4", new Button("button")));554555return frame;556}557558protected void customizeHierarchy() {559((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());560((Container)getComponent("panel")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {561public Component getDefaultComponent(Container aContainer) {562return getComponent("btn 2");563}564});565((Container)getComponent("panel")).setFocusCycleRoot(true);566((Container)getComponent("panel")).setFocusable(true);567}568569protected Map<String, String> getForwardOrder() {570Map<String, String> order = new HashMap<String, String>();571order.put("frame", "btn 1");572order.put("btn 1", "panel");573order.put("btn 2", "btn 3");574order.put("btn 3", "panel");575order.put("btn 4", "btn 1");576order.put("panel", "btn 2");577return order;578}579580protected Map<String, String> getBackwardOrder() {581Map<String, String> order = new HashMap<String, String>();582order.put("btn 4", "btn 2");583order.put("btn 3", "btn 2");584order.put("btn 2", "panel");585order.put("btn 1", "btn 4");586order.put("panel", "btn 1");587return order;588}589590protected String[] getContainersToTest() {591return new String[] {"panel"};592}593594protected String getDefaultComp(String focusCycleRoot_id) {595return "btn 2";596}597598protected String getFirstComp(String focusCycleRoot_id) {599return "panel";600}601602protected String getLastComp(String focusCycleRoot_id) {603return "btn 3";604}605}606607/*608* frame [ comp1 comp2 container1(provider) [...] container2(root) [...] ]609* - verifies a case when a provider is followed by a root.610*/611class PolicyTest8 extends AbstractPolicyTest {612613protected Frame createFrame() {614Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));615frame.setLayout(new FlowLayout());616617frame.add(registerComponent("btn-1", new Button("button")));618frame.add(registerComponent("btn-2", new Button("button")));619620Container cont1 = (Container)registerComponent("panel-1", new Panel());621cont1.add(registerComponent("btn-3", new Button("button")));622cont1.add(registerComponent("btn-4", new Button("button")));623cont1.add(registerComponent("btn-5", new Button("button")));624625Container cont2 = (Container)registerComponent("panel-2", new Panel());626cont2.add(registerComponent("btn-6", new Button("button")));627cont2.add(registerComponent("btn-7", new Button("button")));628cont2.add(registerComponent("btn-8", new Button("button")));629630frame.add(cont1);631frame.add(cont2);632633return frame;634}635636protected void customizeHierarchy() {637((Container)getComponent("panel-1")).setFocusTraversalPolicyProvider(true);638((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {639public Component getDefaultComponent(Container aContainer) {640return getComponent("btn-4");641}642});643644((Container)getComponent("panel-2")).setFocusCycleRoot(true);645((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {646public Component getDefaultComponent(Container aContainer) {647return getComponent("btn-7");648}649});650}651652protected Map<String, String> getForwardOrder() {653Map<String, String> order = new HashMap<String, String>();654order.put("frame", "btn-1");655order.put("btn-1", "btn-2");656order.put("btn-2", "btn-4");657order.put("btn-3", "btn-4");658order.put("btn-4", "btn-5");659order.put("btn-5", "btn-7");660order.put("btn-6", "btn-7");661order.put("btn-7", "btn-8");662order.put("btn-8", "btn-6");663order.put("panel-1", "btn-4");664order.put("panel-2", "btn-7");665return order;666}667668protected Map<String, String> getBackwardOrder() {669Map<String, String> order = new HashMap<String, String>();670order.put("btn-1", "btn-5");671order.put("btn-2", "btn-1");672order.put("btn-3", "btn-2");673order.put("btn-4", "btn-3");674order.put("btn-5", "btn-4");675order.put("btn-6", "btn-8");676order.put("btn-7", "btn-6");677order.put("btn-8", "btn-7");678return order;679}680681protected String[] getContainersToTest() {682return new String[] {"frame", "panel-1", "panel-2"};683}684685protected String getDefaultComp(String focusCycleRoot_id) {686if ("frame".equals(focusCycleRoot_id)) {687return "btn-1";688} else if ("panel-1".equals(focusCycleRoot_id)) {689return "btn-4";690} else if ("panel-2".equals(focusCycleRoot_id)) {691return "btn-7";692}693return null;694}695696protected String getFirstComp(String focusCycleRoot_id) {697if ("frame".equals(focusCycleRoot_id)) {698return "btn-1";699} else if ("panel-1".equals(focusCycleRoot_id)) {700return "btn-3";701} else if ("panel-2".equals(focusCycleRoot_id)) {702return "btn-6";703}704return null;705}706707protected String getLastComp(String focusCycleRoot_id) {708if ("frame".equals(focusCycleRoot_id)) {709return "btn-5";710} else if ("panel-1".equals(focusCycleRoot_id)) {711return "btn-5";712} else if ("panel-2".equals(focusCycleRoot_id)) {713return "btn-8";714}715return null;716}717}718719/*720* frame [ comp1 comp2 container1(root) [...] container2(provider) [...] ]721* - verifies a case when a root is followed by a provider.722*/723class PolicyTest9 extends AbstractPolicyTest {724725protected Frame createFrame() {726Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));727frame.setLayout(new FlowLayout());728729frame.add(registerComponent("btn-1", new Button("button")));730frame.add(registerComponent("btn-2", new Button("button")));731732Container cont1 = (Container)registerComponent("panel-1", new Panel());733cont1.add(registerComponent("btn-3", new Button("button")));734cont1.add(registerComponent("btn-4", new Button("button")));735cont1.add(registerComponent("btn-5", new Button("button")));736737Container cont2 = (Container)registerComponent("panel-2", new Panel());738cont2.add(registerComponent("btn-6", new Button("button")));739cont2.add(registerComponent("btn-7", new Button("button")));740cont2.add(registerComponent("btn-8", new Button("button")));741742frame.add(cont1);743frame.add(cont2);744745return frame;746}747748protected void customizeHierarchy() {749((Container)getComponent("panel-1")).setFocusCycleRoot(true);750((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {751public Component getDefaultComponent(Container aContainer) {752return getComponent("btn-4");753}754});755756((Container)getComponent("panel-2")).setFocusTraversalPolicyProvider(true);757((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {758public Component getDefaultComponent(Container aContainer) {759return getComponent("btn-7");760}761});762}763764protected Map<String, String> getForwardOrder() {765Map<String, String> order = new HashMap<String, String>();766order.put("frame", "btn-1");767order.put("btn-1", "btn-2");768order.put("btn-2", "btn-4");769order.put("btn-3", "btn-4");770order.put("btn-4", "btn-5");771order.put("btn-5", "btn-3");772order.put("btn-6", "btn-7");773order.put("btn-7", "btn-8");774order.put("btn-8", "btn-1");775order.put("panel-1", "btn-4");776order.put("panel-2", "btn-7");777return order;778}779780protected Map<String, String> getBackwardOrder() {781Map<String, String> order = new HashMap<String, String>();782order.put("btn-1", "btn-8");783order.put("btn-2", "btn-1");784order.put("btn-3", "btn-5");785order.put("btn-4", "btn-3");786order.put("btn-5", "btn-4");787order.put("btn-6", "btn-4");788order.put("btn-7", "btn-6");789order.put("btn-8", "btn-7");790return order;791}792793protected String[] getContainersToTest() {794return new String[] {"frame", "panel-1", "panel-2"};795}796797protected String getDefaultComp(String focusCycleRoot_id) {798if ("frame".equals(focusCycleRoot_id)) {799return "btn-1";800} else if ("panel-1".equals(focusCycleRoot_id)) {801return "btn-4";802} else if ("panel-2".equals(focusCycleRoot_id)) {803return "btn-7";804}805return null;806}807808protected String getFirstComp(String focusCycleRoot_id) {809if ("frame".equals(focusCycleRoot_id)) {810return "btn-1";811} else if ("panel-1".equals(focusCycleRoot_id)) {812return "btn-3";813} else if ("panel-2".equals(focusCycleRoot_id)) {814return "btn-6";815}816return null;817}818819protected String getLastComp(String focusCycleRoot_id) {820if ("frame".equals(focusCycleRoot_id)) {821return "btn-8";822} else if ("panel-1".equals(focusCycleRoot_id)) {823return "btn-5";824} else if ("panel-2".equals(focusCycleRoot_id)) {825return "btn-8";826}827return null;828}829}830831/*832* frame [ container0 [...] container1(root) [ comp1 comp2 container2(provider) [...] ] ]833* - verifies a case when a provider is nested in a root.834*/835class PolicyTest10 extends AbstractPolicyTest {836837protected Frame createFrame() {838Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));839frame.setLayout(new GridLayout(2, 1));840841Container cont0 = new Panel();842cont0.add(registerComponent("btn-1", new Button("button")));843cont0.add(registerComponent("btn-2", new Button("button")));844845Container cont1 = (Container)registerComponent("panel-1", new Panel());846cont1.add(registerComponent("btn-3", new Button("button")));847cont1.add(registerComponent("btn-4", new Button("button")));848849Container cont2 = (Container)registerComponent("panel-2", new Panel());850cont2.add(registerComponent("btn-5", new Button("button")));851cont2.add(registerComponent("btn-6", new Button("button")));852853cont1.add(cont2);854frame.add(cont0);855frame.add(cont1);856857return frame;858}859860protected void customizeHierarchy() {861((Container)getComponent("panel-1")).setFocusCycleRoot(true);862((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {863public Component getDefaultComponent(Container aContainer) {864return getComponent("panel-2");865}866});867((Container)getComponent("panel-2")).setFocusTraversalPolicyProvider(true);868((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());869}870871protected Map<String, String> getForwardOrder() {872Map<String, String> order = new HashMap<String, String>();873order.put("frame", "btn-1");874order.put("btn-1", "btn-2");875order.put("btn-2", "panel-2");876order.put("btn-3", "btn-4");877order.put("btn-4", "btn-5");878order.put("btn-5", "btn-6");879order.put("btn-6", "btn-3");880order.put("panel-1", "panel-2");881order.put("panel-2", "btn-5");882return order;883}884885protected Map<String, String> getBackwardOrder() {886Map<String, String> order = new HashMap<String, String>();887order.put("btn-1", "btn-2");888order.put("btn-2", "btn-1");889order.put("btn-3", "btn-6");890order.put("btn-4", "btn-3");891order.put("btn-5", "btn-4");892order.put("btn-6", "btn-5");893return order;894}895896protected String[] getContainersToTest() {897return new String[] {"frame", "panel-1", "panel-2"};898}899900protected String getDefaultComp(String focusCycleRoot_id) {901if ("frame".equals(focusCycleRoot_id)) {902return "btn-1";903} else if ("panel-1".equals(focusCycleRoot_id)) {904return "panel-2";905} else if ("panel-2".equals(focusCycleRoot_id)) {906return "btn-5";907}908return null;909}910911protected String getFirstComp(String focusCycleRoot_id) {912if ("frame".equals(focusCycleRoot_id)) {913return "btn-1";914} else if ("panel-1".equals(focusCycleRoot_id)) {915return "btn-3";916} else if ("panel-2".equals(focusCycleRoot_id)) {917return "btn-5";918}919return null;920}921922protected String getLastComp(String focusCycleRoot_id) {923if ("frame".equals(focusCycleRoot_id)) {924return "btn-2";925} else {926return "btn-6";927}928}929}930931/*932* frame [ container(root) [...] comp ]933* - getDefaultComponent(<frame>) should implicitly down-cycle into the <container>.934* - getFirstComponent(<frame>) should implicitly down-cycle into the <container>.935*/936class PolicyTest11 extends AbstractPolicyTest {937protected Frame createFrame() {938Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));939frame.setLayout(new FlowLayout());940941Container cont = (Container)registerComponent("panel", new Panel());942cont.add(registerComponent("btn-1", new Button("button")));943cont.add(registerComponent("btn-2", new Button("button")));944945frame.add(cont);946frame.add(registerComponent("btn-3", new Button("button")));947948return frame;949}950951protected void customizeHierarchy() {952((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());953((Container)getComponent("panel")).setFocusCycleRoot(true);954}955956protected Map<String, String> getForwardOrder() {957Map<String, String> order = new HashMap<String, String>();958order.put("frame", "btn-1");959order.put("btn-1", "btn-2");960order.put("btn-2", "btn-1");961order.put("btn-3", "btn-1");962return order;963}964965protected Map<String, String> getBackwardOrder() {966Map<String, String> order = new HashMap<String, String>();967order.put("btn-3", "btn-1");968order.put("btn-2", "btn-1");969order.put("btn-1", "btn-2");970order.put("frame", "btn-3");971return order;972}973974protected String[] getContainersToTest() {975return new String[] {"frame"};976}977978protected String getDefaultComp(String focusCycleRoot_id) {979return "btn-1";980}981982protected String getFirstComp(String focusCycleRoot_id) {983return "btn-1";984}985986protected String getLastComp(String focusCycleRoot_id) {987return "btn-3";988}989}990991992