Path: blob/master/test/jdk/java/awt/Focus/FocusTraversalPolicy/DefaultFTPTest.java
41152 views
/*1* Copyright (c) 2007, 2016, 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@key headful26@bug 646354527@summary Tests java.awt.DefaultFocusTraversalPolicy functionality.28@author anton.tarasov area=awt.focus29@library ../../regtesthelpers30@build AbstractPolicyTest31@run main DefaultFTPTest32*/3334import java.awt.*;35import java.awt.event.*;36import java.util.*;37import test.java.awt.regtesthelpers.AbstractPolicyTest;3839/*4041Below are some notes about changes in DefaultFocusTraversalPolicy behaviour.4243container(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.4748491. frame [ container(root)(focusable) [...] ]5051- getComponentAfter(<frame>, <container>) returns <container>.5253If <container> is the default component to focus in its own cycle. * NO CHANGE *5455563. frame [ comp1 container(root)(focusable) [ comp2 ] comp3 ]5758- getComponentBefore(<frame>, <comp3>) returns <comp2>. ** BEHAVIOUR CHANGE **5960Previously <container> would be returned. This was a bug as it61wasn't according to the spec.6263- getComponentBefore(<container>, <comp2>) returns <container>. * NO CHANGE *6465- getComponentBefore(<frame>, <container>) returns <comp1>. * NO CHANGE *6667- getComponentBefore(<container>, <container>) returns <comp2>. * NO CHANGE *6869704. frame [ container(provider) [...] comp ]7172- getComponentAfter(<frame>, <container>) returns <container>'s default. ** BEHAVIOUR CHANGE. SPEC ADDITION **7374Previously <comp> would be returned. Not specified in the spec.7576- getComponentBefore(<frame>, <comp>) returns <container>'s last. ** SPEC CHANGE **7778The spec says (incorrectly) that default should be returned.7980815. frame [ container(provider)(focusable) [...] comp2 ]8283- getComponentBefore(<frame>, <comp2>) returns <container>'s last. ** BEHAVIOUR CHANGE. SPEC ADDITION **8485Previously <container> would be returned. Not specified in the spec.8687886. frame [ comp1 container(root) [...] comp2 ]8990- getComponentAfter(<frame>, <comp1>) returns <container>'s default. ** BEHAVIOUR CHANGE. SPEC ADDITION **9192Previously <comp2> would be returned. It's just the fix for 6240842.93Not specified in the spec.9495967. frame [ comp1 container(root) [...] comp2(unfocusable) comp3 ]9798- getComponentBefore(<frame>, <comp3>) returns <container>'s default. ** BEHAVIOUR CHANGE **99100Previously <comp1> would be returned. This was a bug, because101in case if <comp2> is focusable getComponentBefore(<frame>, <comp2>) would102return <container>'s default.103104*/105106public class DefaultFTPTest {107final int TESTS_NUMBER = 11;108109public static void main(String[] args) {110DefaultFTPTest app = new DefaultFTPTest();111app.start();112}113114public void start() {115try {116Class clazz = null;117AbstractPolicyTest test = null;118119for (int i = 1; i <= TESTS_NUMBER; i++) {120clazz = Class.forName("PolicyTest" + i);121if (clazz != null) {122test = (AbstractPolicyTest)clazz.newInstance();123System.out.print("Test " + i + " is in progress...");124test.testIt();125System.out.println(" passed.");126}127}128} catch (RuntimeException rte) {129throw rte;130} catch (Exception e) {131throw new RuntimeException("Error: unexpected exception cought!", e);132}133}134}135136/*137* frame [ container1 [...] container2 [...] container3 [...] ]138* - verifies simple configuration.139*/140class PolicyTest1 extends AbstractPolicyTest {141protected Frame createFrame() {142Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));143frame.setLayout(new GridLayout(3, 1));144145for (int i = 0; i < 3; i++) {146Container cont = (Container) registerComponent("panel" + i, new Panel());147for (int j = 0; j < 3; j++) {148cont.add(registerComponent("btn " + (j + i*100), new Button("button")));149}150frame.add(cont);151}152return frame;153}154155protected void customizeHierarchy() {156((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());157}158159protected Map<String, String> getForwardOrder() {160Map<String, String> order = new HashMap<String, String>();161order.put("btn 0", "btn 1");162order.put("btn 1", "btn 2");163order.put("btn 2", "btn 100");164order.put("btn 100", "btn 101");165order.put("btn 101", "btn 102");166order.put("btn 102", "btn 200");167order.put("btn 200", "btn 201");168order.put("btn 201", "btn 202");169order.put("btn 202", "btn 0");170order.put("panel0", "btn 0");171order.put("panel1", "btn 100");172order.put("panel2", "btn 200");173order.put("frame", "btn 0");174return order;175}176177protected Map<String, String> getBackwardOrder() {178Map<String, String> order = new HashMap<String, String>();179order.put("btn 0", "btn 202");180order.put("btn 1", "btn 0");181order.put("btn 2", "btn 1");182order.put("btn 100", "btn 2");183order.put("btn 101", "btn 100");184order.put("btn 102", "btn 101");185order.put("btn 200", "btn 102");186order.put("btn 201", "btn 200");187order.put("btn 202", "btn 201");188order.put("panel0", "btn 202");189order.put("panel1", "btn 2");190order.put("panel2", "btn 102");191order.put("frame", "btn 202");192return order;193}194195protected String[] getContainersToTest() {196return new String[] {"frame"};197}198199protected String getDefaultComp(String focusCycleRoot_id) {200return "btn 0";201}202203protected String getFirstComp(String focusCycleRoot_id) {204return "btn 0";205}206207protected String getLastComp(String focusCycleRoot_id) {208return "btn 202";209}210}211212/*213* frame [ comp container(provider) [...] comp ]214* - transfering focus through a provider.215*/216class PolicyTest2 extends AbstractPolicyTest {217218protected Frame createFrame() {219Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));220frame.setLayout(new FlowLayout());221222frame.add(registerComponent("btn 1", new Button("button")));223224Container cont = (Container)registerComponent("panel", new Panel());225cont.add(registerComponent("btn 2", new Button("button")));226cont.add(registerComponent("btn 3", new Button("button")));227frame.add(cont);228229frame.add(registerComponent("btn 4", new Button("button")));230231return frame;232}233234protected void customizeHierarchy() {235((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());236((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);237}238239protected Map<String, String> getForwardOrder() {240Map<String, String> order = new HashMap<String, String>();241order.put("frame", "btn 1");242order.put("btn 1", "btn 2");243order.put("btn 2", "btn 3");244order.put("btn 3", "btn 4");245order.put("btn 4", "btn 1");246order.put("panel", "btn 2");247return order;248}249250protected Map<String, String> getBackwardOrder() {251Map<String, String> order = new HashMap<String, String>();252order.put("btn 4", "btn 3");253order.put("btn 3", "btn 2");254order.put("btn 2", "btn 1");255order.put("btn 1", "btn 4");256return order;257}258259protected String[] getContainersToTest() {260return new String[] {"frame", "panel"};261}262263protected String getDefaultComp(String focusCycleRoot_id) {264if ("frame".equals(focusCycleRoot_id)) {265return "btn 1";266} else if ("panel".equals(focusCycleRoot_id)) {267return "btn 2";268}269return null;270}271272protected String getFirstComp(String focusCycleRoot_id) {273return getDefaultComp(focusCycleRoot_id);274}275276protected String getLastComp(String focusCycleRoot_id) {277if ("frame".equals(focusCycleRoot_id)) {278return "btn 4";279} else if ("panel".equals(focusCycleRoot_id)) {280return "btn 3";281}282return null;283}284}285286/*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 {291292protected Frame createFrame() {293Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));294frame.setLayout(new FlowLayout());295296frame.add(registerComponent("btn 1", new Button("button")));297298Container cont = (Container)registerComponent("panel", new Panel());299cont.add(registerComponent("btn 2", new Button("button")));300cont.add(registerComponent("btn 3", new Button("button")));301frame.add(cont);302303frame.add(registerComponent("btn 4", new Button("button")));304305return frame;306}307308protected void customizeHierarchy() {309((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());310((Container)getComponent("panel")).setFocusCycleRoot(true);311}312313protected Map<String, String> getForwardOrder() {314Map<String, String> order = new HashMap<String, String>();315order.put("frame", "btn 1");316order.put("btn 1", "btn 2");317order.put("btn 2", "btn 3");318order.put("btn 3", "btn 2");319order.put("btn 4", "btn 1");320order.put("panel", "btn 2");321return order;322}323324protected Map<String, String> getBackwardOrder() {325Map<String, String> order = new HashMap<String, String>();326order.put("btn 4", "btn 2");327order.put("btn 3", "btn 2");328order.put("btn 2", "btn 3");329order.put("btn 1", "btn 4");330return order;331}332333protected String[] getContainersToTest() {334return new String[] {"frame", "panel"};335}336337protected String getDefaultComp(String focusCycleRoot_id) {338if ("frame".equals(focusCycleRoot_id)) {339return "btn 1";340} else if ("panel".equals(focusCycleRoot_id)) {341return "btn 2";342}343return null;344}345346protected String getFirstComp(String focusCycleRoot_id) {347return getDefaultComp(focusCycleRoot_id);348}349350protected String getLastComp(String focusCycleRoot_id) {351if ("frame".equals(focusCycleRoot_id)) {352return "btn 4";353} else if ("panel".equals(focusCycleRoot_id)) {354return "btn 3";355}356return null;357}358}359360/*361* frame [ container(provider) [...] comp1(unfocusable) comp2 ]362* - getComponentBefore(<frame>, <comp2>) should return <container>'s last.363*/364class PolicyTest4 extends AbstractPolicyTest {365366protected Frame createFrame() {367Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));368frame.setLayout(new FlowLayout());369370Container cont = (Container)registerComponent("panel", new Panel());371cont.add(registerComponent("btn 1", new Button("button")));372cont.add(registerComponent("btn 2", new Button("button")));373frame.add(cont);374375frame.add(registerComponent("btn 3", new Button("button")));376frame.add(registerComponent("btn 4", new Button("button")));377378return frame;379}380381protected void customizeHierarchy() {382((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());383((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);384((Button)getComponent("btn 3")).setFocusable(false);385}386387protected Map<String, String> getBackwardOrder() {388Map<String, String> order = new HashMap<String, String>();389order.put("btn 4", "btn 2");390order.put("btn 2", "btn 1");391order.put("btn 1", "btn 4");392return order;393}394395// no testing396protected Map<String, String> getForwardOrder() {397return null;398}399protected String[] getContainersToTest() {400return null;401}402protected String getDefaultComp(String focusCycleRoot_id) {403return null;404}405protected String getFirstComp(String focusCycleRoot_id) {406return null;407}408protected String getLastComp(String focusCycleRoot_id) {409return null;410}411}412413/*414* frame [ container(root) [...] comp1(unfocusable) comp2 ]415* - getComponentBefore(<frame>, <comp2>) should return <container>'s default.416*/417class PolicyTest5 extends AbstractPolicyTest {418419protected Frame createFrame() {420Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));421frame.setLayout(new FlowLayout());422423Container cont = (Container)registerComponent("panel", new Panel());424cont.add(registerComponent("btn 1", new Button("button")));425cont.add(registerComponent("btn 2", new Button("button")));426frame.add(cont);427428frame.add(registerComponent("btn 3", new Button("button")));429frame.add(registerComponent("btn 4", new Button("button")));430431return frame;432}433434protected void customizeHierarchy() {435((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());436((Container)getComponent("panel")).setFocusCycleRoot(true);437((Button)getComponent("btn 3")).setFocusable(false);438}439440protected Map<String, String> getBackwardOrder() {441Map<String, String> order = new HashMap<String, String>();442order.put("btn 4", "btn 1");443order.put("btn 2", "btn 1");444order.put("btn 1", "btn 2");445return order;446}447448// no testing449protected Map<String, String> getForwardOrder() {450return null;451}452protected String[] getContainersToTest() {453return null;454}455protected String getDefaultComp(String focusCycleRoot_id) {456return null;457}458protected String getFirstComp(String focusCycleRoot_id) {459return null;460}461protected String getLastComp(String focusCycleRoot_id) {462return null;463}464}465466/*467* frame [ comp container(provider)(focusable) [...] comp ]468* - transfering focus through a focusable provider.469*/470class PolicyTest6 extends AbstractPolicyTest {471472protected Frame createFrame() {473Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));474frame.setLayout(new FlowLayout());475476frame.add(registerComponent("btn 1", new Button("button")));477478Container cont = (Container)registerComponent("panel", new Panel());479cont.add(registerComponent("btn 2", new Button("button")));480cont.add(registerComponent("btn 3", new Button("button")));481frame.add(cont);482483frame.add(registerComponent("btn 4", new Button("button")));484485return frame;486}487488protected void customizeHierarchy() {489((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());490((Container)getComponent("panel")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {491public Component getDefaultComponent(Container aContainer) {492return getComponent("btn 2");493}494});495((Container)getComponent("panel")).setFocusTraversalPolicyProvider(true);496((Container)getComponent("panel")).setFocusable(true);497}498499protected Map<String, String> getForwardOrder() {500Map<String, String> order = new HashMap<String, String>();501order.put("frame", "btn 1");502order.put("btn 1", "panel");503order.put("btn 2", "btn 3");504order.put("btn 3", "btn 4");505order.put("btn 4", "btn 1");506order.put("panel", "btn 2");507return order;508}509510protected Map<String, String> getBackwardOrder() {511Map<String, String> order = new HashMap<String, String>();512order.put("btn 4", "btn 3");513order.put("btn 3", "btn 2");514order.put("btn 2", "panel");515order.put("btn 1", "btn 4");516order.put("panel", "btn 1");517return order;518}519520protected String[] getContainersToTest() {521return new String[] {"panel"};522}523524protected String getDefaultComp(String focusCycleRoot_id) {525return "btn 2";526}527528protected String getFirstComp(String focusCycleRoot_id) {529return "panel";530}531532protected String getLastComp(String focusCycleRoot_id) {533return "btn 3";534}535}536537/*538* frame [ comp container(root)(focusable) [...] comp ]539* - transfering focus through a focusable root.540*/541class PolicyTest7 extends AbstractPolicyTest {542543protected Frame createFrame() {544Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));545frame.setLayout(new FlowLayout());546547frame.add(registerComponent("btn 1", new Button("button")));548549Container cont = (Container)registerComponent("panel", new Panel());550cont.add(registerComponent("btn 2", new Button("button")));551cont.add(registerComponent("btn 3", new Button("button")));552frame.add(cont);553554frame.add(registerComponent("btn 4", new Button("button")));555556return frame;557}558559protected void customizeHierarchy() {560((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());561((Container)getComponent("panel")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {562public Component getDefaultComponent(Container aContainer) {563return getComponent("btn 2");564}565});566((Container)getComponent("panel")).setFocusCycleRoot(true);567((Container)getComponent("panel")).setFocusable(true);568}569570protected Map<String, String> getForwardOrder() {571Map<String, String> order = new HashMap<String, String>();572order.put("frame", "btn 1");573order.put("btn 1", "panel");574order.put("btn 2", "btn 3");575order.put("btn 3", "panel");576order.put("btn 4", "btn 1");577order.put("panel", "btn 2");578return order;579}580581protected Map<String, String> getBackwardOrder() {582Map<String, String> order = new HashMap<String, String>();583order.put("btn 4", "btn 2");584order.put("btn 3", "btn 2");585order.put("btn 2", "panel");586order.put("btn 1", "btn 4");587order.put("panel", "btn 1");588return order;589}590591protected String[] getContainersToTest() {592return new String[] {"panel"};593}594595protected String getDefaultComp(String focusCycleRoot_id) {596return "btn 2";597}598599protected String getFirstComp(String focusCycleRoot_id) {600return "panel";601}602603protected String getLastComp(String focusCycleRoot_id) {604return "btn 3";605}606}607608/*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 {613614protected Frame createFrame() {615Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));616frame.setLayout(new FlowLayout());617618frame.add(registerComponent("btn-1", new Button("button")));619frame.add(registerComponent("btn-2", new Button("button")));620621Container cont1 = (Container)registerComponent("panel-1", new Panel());622cont1.add(registerComponent("btn-3", new Button("button")));623cont1.add(registerComponent("btn-4", new Button("button")));624cont1.add(registerComponent("btn-5", new Button("button")));625626Container cont2 = (Container)registerComponent("panel-2", new Panel());627cont2.add(registerComponent("btn-6", new Button("button")));628cont2.add(registerComponent("btn-7", new Button("button")));629cont2.add(registerComponent("btn-8", new Button("button")));630631frame.add(cont1);632frame.add(cont2);633634return frame;635}636637protected void customizeHierarchy() {638((Container)getComponent("panel-1")).setFocusTraversalPolicyProvider(true);639((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {640public Component getDefaultComponent(Container aContainer) {641return getComponent("btn-4");642}643});644645((Container)getComponent("panel-2")).setFocusCycleRoot(true);646((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {647public Component getDefaultComponent(Container aContainer) {648return getComponent("btn-7");649}650});651}652653protected Map<String, String> getForwardOrder() {654Map<String, String> order = new HashMap<String, String>();655order.put("frame", "btn-1");656order.put("btn-1", "btn-2");657order.put("btn-2", "btn-4");658order.put("btn-3", "btn-4");659order.put("btn-4", "btn-5");660order.put("btn-5", "btn-7");661order.put("btn-6", "btn-7");662order.put("btn-7", "btn-8");663order.put("btn-8", "btn-6");664order.put("panel-1", "btn-4");665order.put("panel-2", "btn-7");666return order;667}668669protected Map<String, String> getBackwardOrder() {670Map<String, String> order = new HashMap<String, String>();671order.put("btn-1", "btn-5");672order.put("btn-2", "btn-1");673order.put("btn-3", "btn-2");674order.put("btn-4", "btn-3");675order.put("btn-5", "btn-4");676order.put("btn-6", "btn-8");677order.put("btn-7", "btn-6");678order.put("btn-8", "btn-7");679return order;680}681682protected String[] getContainersToTest() {683return new String[] {"frame", "panel-1", "panel-2"};684}685686protected String getDefaultComp(String focusCycleRoot_id) {687if ("frame".equals(focusCycleRoot_id)) {688return "btn-1";689} else if ("panel-1".equals(focusCycleRoot_id)) {690return "btn-4";691} else if ("panel-2".equals(focusCycleRoot_id)) {692return "btn-7";693}694return null;695}696697protected String getFirstComp(String focusCycleRoot_id) {698if ("frame".equals(focusCycleRoot_id)) {699return "btn-1";700} else if ("panel-1".equals(focusCycleRoot_id)) {701return "btn-3";702} else if ("panel-2".equals(focusCycleRoot_id)) {703return "btn-6";704}705return null;706}707708protected String getLastComp(String focusCycleRoot_id) {709if ("frame".equals(focusCycleRoot_id)) {710return "btn-5";711} else if ("panel-1".equals(focusCycleRoot_id)) {712return "btn-5";713} else if ("panel-2".equals(focusCycleRoot_id)) {714return "btn-8";715}716return null;717}718}719720/*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 {725726protected Frame createFrame() {727Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));728frame.setLayout(new FlowLayout());729730frame.add(registerComponent("btn-1", new Button("button")));731frame.add(registerComponent("btn-2", new Button("button")));732733Container cont1 = (Container)registerComponent("panel-1", new Panel());734cont1.add(registerComponent("btn-3", new Button("button")));735cont1.add(registerComponent("btn-4", new Button("button")));736cont1.add(registerComponent("btn-5", new Button("button")));737738Container cont2 = (Container)registerComponent("panel-2", new Panel());739cont2.add(registerComponent("btn-6", new Button("button")));740cont2.add(registerComponent("btn-7", new Button("button")));741cont2.add(registerComponent("btn-8", new Button("button")));742743frame.add(cont1);744frame.add(cont2);745746return frame;747}748749protected void customizeHierarchy() {750((Container)getComponent("panel-1")).setFocusCycleRoot(true);751((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {752public Component getDefaultComponent(Container aContainer) {753return getComponent("btn-4");754}755});756757((Container)getComponent("panel-2")).setFocusTraversalPolicyProvider(true);758((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {759public Component getDefaultComponent(Container aContainer) {760return getComponent("btn-7");761}762});763}764765protected Map<String, String> getForwardOrder() {766Map<String, String> order = new HashMap<String, String>();767order.put("frame", "btn-1");768order.put("btn-1", "btn-2");769order.put("btn-2", "btn-4");770order.put("btn-3", "btn-4");771order.put("btn-4", "btn-5");772order.put("btn-5", "btn-3");773order.put("btn-6", "btn-7");774order.put("btn-7", "btn-8");775order.put("btn-8", "btn-1");776order.put("panel-1", "btn-4");777order.put("panel-2", "btn-7");778return order;779}780781protected Map<String, String> getBackwardOrder() {782Map<String, String> order = new HashMap<String, String>();783order.put("btn-1", "btn-8");784order.put("btn-2", "btn-1");785order.put("btn-3", "btn-5");786order.put("btn-4", "btn-3");787order.put("btn-5", "btn-4");788order.put("btn-6", "btn-4");789order.put("btn-7", "btn-6");790order.put("btn-8", "btn-7");791return order;792}793794protected String[] getContainersToTest() {795return new String[] {"frame", "panel-1", "panel-2"};796}797798protected String getDefaultComp(String focusCycleRoot_id) {799if ("frame".equals(focusCycleRoot_id)) {800return "btn-1";801} else if ("panel-1".equals(focusCycleRoot_id)) {802return "btn-4";803} else if ("panel-2".equals(focusCycleRoot_id)) {804return "btn-7";805}806return null;807}808809protected String getFirstComp(String focusCycleRoot_id) {810if ("frame".equals(focusCycleRoot_id)) {811return "btn-1";812} else if ("panel-1".equals(focusCycleRoot_id)) {813return "btn-3";814} else if ("panel-2".equals(focusCycleRoot_id)) {815return "btn-6";816}817return null;818}819820protected String getLastComp(String focusCycleRoot_id) {821if ("frame".equals(focusCycleRoot_id)) {822return "btn-8";823} else if ("panel-1".equals(focusCycleRoot_id)) {824return "btn-5";825} else if ("panel-2".equals(focusCycleRoot_id)) {826return "btn-8";827}828return null;829}830}831832/*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 {837838protected Frame createFrame() {839Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));840frame.setLayout(new GridLayout(2, 1));841842Container cont0 = new Panel();843cont0.add(registerComponent("btn-1", new Button("button")));844cont0.add(registerComponent("btn-2", new Button("button")));845846Container cont1 = (Container)registerComponent("panel-1", new Panel());847cont1.add(registerComponent("btn-3", new Button("button")));848cont1.add(registerComponent("btn-4", new Button("button")));849850Container cont2 = (Container)registerComponent("panel-2", new Panel());851cont2.add(registerComponent("btn-5", new Button("button")));852cont2.add(registerComponent("btn-6", new Button("button")));853854cont1.add(cont2);855frame.add(cont0);856frame.add(cont1);857858return frame;859}860861protected void customizeHierarchy() {862((Container)getComponent("panel-1")).setFocusCycleRoot(true);863((Container)getComponent("panel-1")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy() {864public Component getDefaultComponent(Container aContainer) {865return getComponent("panel-2");866}867});868((Container)getComponent("panel-2")).setFocusTraversalPolicyProvider(true);869((Container)getComponent("panel-2")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());870}871872protected Map<String, String> getForwardOrder() {873Map<String, String> order = new HashMap<String, String>();874order.put("frame", "btn-1");875order.put("btn-1", "btn-2");876order.put("btn-2", "panel-2");877order.put("btn-3", "btn-4");878order.put("btn-4", "btn-5");879order.put("btn-5", "btn-6");880order.put("btn-6", "btn-3");881order.put("panel-1", "panel-2");882order.put("panel-2", "btn-5");883return order;884}885886protected Map<String, String> getBackwardOrder() {887Map<String, String> order = new HashMap<String, String>();888order.put("btn-1", "btn-2");889order.put("btn-2", "btn-1");890order.put("btn-3", "btn-6");891order.put("btn-4", "btn-3");892order.put("btn-5", "btn-4");893order.put("btn-6", "btn-5");894return order;895}896897protected String[] getContainersToTest() {898return new String[] {"frame", "panel-1", "panel-2"};899}900901protected String getDefaultComp(String focusCycleRoot_id) {902if ("frame".equals(focusCycleRoot_id)) {903return "btn-1";904} else if ("panel-1".equals(focusCycleRoot_id)) {905return "panel-2";906} else if ("panel-2".equals(focusCycleRoot_id)) {907return "btn-5";908}909return null;910}911912protected String getFirstComp(String focusCycleRoot_id) {913if ("frame".equals(focusCycleRoot_id)) {914return "btn-1";915} else if ("panel-1".equals(focusCycleRoot_id)) {916return "btn-3";917} else if ("panel-2".equals(focusCycleRoot_id)) {918return "btn-5";919}920return null;921}922923protected String getLastComp(String focusCycleRoot_id) {924if ("frame".equals(focusCycleRoot_id)) {925return "btn-2";926} else {927return "btn-6";928}929}930}931932/*933* frame [ container(root) [...] comp ]934* - getDefaultComponent(<frame>) should implicitly down-cycle into the <container>.935* - getFirstComponent(<frame>) should implicitly down-cycle into the <container>.936*/937class PolicyTest11 extends AbstractPolicyTest {938protected Frame createFrame() {939Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));940frame.setLayout(new FlowLayout());941942Container cont = (Container)registerComponent("panel", new Panel());943cont.add(registerComponent("btn-1", new Button("button")));944cont.add(registerComponent("btn-2", new Button("button")));945946frame.add(cont);947frame.add(registerComponent("btn-3", new Button("button")));948949return frame;950}951952protected void customizeHierarchy() {953((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());954((Container)getComponent("panel")).setFocusCycleRoot(true);955}956957protected Map<String, String> getForwardOrder() {958Map<String, String> order = new HashMap<String, String>();959order.put("frame", "btn-1");960order.put("btn-1", "btn-2");961order.put("btn-2", "btn-1");962order.put("btn-3", "btn-1");963return order;964}965966protected Map<String, String> getBackwardOrder() {967Map<String, String> order = new HashMap<String, String>();968order.put("btn-3", "btn-1");969order.put("btn-2", "btn-1");970order.put("btn-1", "btn-2");971order.put("frame", "btn-3");972return order;973}974975protected String[] getContainersToTest() {976return new String[] {"frame"};977}978979protected String getDefaultComp(String focusCycleRoot_id) {980return "btn-1";981}982983protected String getFirstComp(String focusCycleRoot_id) {984return "btn-1";985}986987protected String getLastComp(String focusCycleRoot_id) {988return "btn-3";989}990}991992993