changeset 1336:49e7d22262a9

4788402: SortingFocusTraversalPolicy: prob with non-focusable focus Cycle Root as first Reviewed-by: dcherepanov
author ant
date Thu, 18 Jun 2009 11:28:54 +0400
parents 2a526ccd12e8
children 06f35d090a5e
files src/share/classes/java/awt/ContainerOrderFocusTraversalPolicy.java src/share/classes/javax/swing/SortingFocusTraversalPolicy.java test/java/awt/Focus/FocusTraversalPolicy/DefaultFTPTest.java test/java/awt/Focus/FocusTraversalPolicy/LayoutFTPTest.java
diffstat 4 files changed, 131 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/awt/ContainerOrderFocusTraversalPolicy.java	Wed Jun 17 21:13:04 2009 +0100
+++ b/src/share/classes/java/awt/ContainerOrderFocusTraversalPolicy.java	Thu Jun 18 11:28:54 2009 +0400
@@ -425,15 +425,13 @@
             }
             if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle);
 
-            for (int i = 0; i < cycle.size(); i++) {
-                Component comp = cycle.get(i);
+            for (Component comp : cycle) {
                 if (accept(comp)) {
                     return comp;
-                } else if (comp instanceof Container && comp != aContainer) {
-                    Container cont = (Container)comp;
-                    if (cont.isFocusTraversalPolicyProvider()) {
-                        return cont.getFocusTraversalPolicy().getDefaultComponent(cont);
-                    }
+                } else if (comp != aContainer &&
+                           (comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null)
+                {
+                    return comp;
                 }
             }
         }
--- a/src/share/classes/javax/swing/SortingFocusTraversalPolicy.java	Wed Jun 17 21:13:04 2009 +0100
+++ b/src/share/classes/javax/swing/SortingFocusTraversalPolicy.java	Thu Jun 18 11:28:54 2009 +0400
@@ -444,11 +444,10 @@
         for (Component comp : cycle) {
             if (accept(comp)) {
                 return comp;
-            } else if (comp instanceof Container && comp != aContainer) {
-                Container cont = (Container)comp;
-                if (cont.isFocusTraversalPolicyProvider()) {
-                    return cont.getFocusTraversalPolicy().getDefaultComponent(cont);
-                }
+            } else if (comp != aContainer &&
+                       (comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null)
+            {
+                return comp;
             }
         }
         return null;
--- a/test/java/awt/Focus/FocusTraversalPolicy/DefaultFTPTest.java	Wed Jun 17 21:13:04 2009 +0100
+++ b/test/java/awt/Focus/FocusTraversalPolicy/DefaultFTPTest.java	Thu Jun 18 11:28:54 2009 +0400
@@ -104,7 +104,7 @@
 */
 
 public class DefaultFTPTest {
-    final int TESTS_NUMBER = 10;
+    final int TESTS_NUMBER = 11;
 
     public static void main(String[] args) {
         DefaultFTPTest app = new DefaultFTPTest();
@@ -928,3 +928,63 @@
         }
     }
 }
+
+/*
+ * frame [ container(root) [...] comp ]
+ * - getDefaultComponent(<frame>) should implicitly down-cycle into the <container>.
+ * - getFirstComponent(<frame>) should implicitly down-cycle into the <container>.
+ */
+class PolicyTest11 extends AbstractPolicyTest {
+    protected Frame createFrame() {
+        Frame frame = (Frame) registerComponent("frame", new Frame("Test Frame"));
+        frame.setLayout(new FlowLayout());
+
+        Container cont = (Container)registerComponent("panel", new Panel());
+        cont.add(registerComponent("btn-1", new Button("button")));
+        cont.add(registerComponent("btn-2", new Button("button")));
+
+        frame.add(cont);
+        frame.add(registerComponent("btn-3", new Button("button")));
+
+        return frame;
+    }
+
+    protected void customizeHierarchy() {
+        ((Container)getComponent("frame")).setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());
+        ((Container)getComponent("panel")).setFocusCycleRoot(true);
+    }
+
+    protected Map<String, String> getForwardOrder() {
+        Map<String, String> order = new HashMap<String, String>();
+        order.put("frame", "btn-1");
+        order.put("btn-1", "btn-2");
+        order.put("btn-2", "btn-1");
+        order.put("btn-3", "btn-1");
+        return order;
+    }
+
+    protected Map<String, String> getBackwardOrder() {
+        Map<String, String> order = new HashMap<String, String>();
+        order.put("btn-3", "btn-1");
+        order.put("btn-2", "btn-1");
+        order.put("btn-1", "btn-2");
+        order.put("frame", "btn-3");
+        return order;
+    }
+
+    protected String[] getContainersToTest() {
+        return new String[] {"frame"};
+    }
+
+    protected String getDefaultComp(String focusCycleRoot_id) {
+        return "btn-1";
+    }
+
+    protected String getFirstComp(String focusCycleRoot_id) {
+        return "btn-1";
+    }
+
+    protected String getLastComp(String focusCycleRoot_id) {
+        return "btn-3";
+    }
+}
--- a/test/java/awt/Focus/FocusTraversalPolicy/LayoutFTPTest.java	Wed Jun 17 21:13:04 2009 +0100
+++ b/test/java/awt/Focus/FocusTraversalPolicy/LayoutFTPTest.java	Thu Jun 18 11:28:54 2009 +0400
@@ -105,7 +105,7 @@
 */
 
 public class LayoutFTPTest {
-    final int TESTS_NUMBER = 10;
+    final int TESTS_NUMBER = 11;
 
     public static void main(String[] args) {
         LayoutFTPTest app = new LayoutFTPTest();
@@ -929,3 +929,63 @@
         }
     }
 }
+
+/*
+ * frame [ container(root) [...] comp ]
+ * - getDefaultComponent(<frame>) should implicitly down-cycle into the <container>.
+ * - getFirstComponent(<frame>) should implicitly down-cycle into the <container>.
+ */
+class PolicyTest11 extends AbstractPolicyTest {
+    protected Frame createFrame() {
+        JFrame jframe = (JFrame) registerComponent("jframe", new JFrame("Test Frame"));
+        jframe.setLayout(new FlowLayout());
+
+        Container cont = (Container)registerComponent("jpanel", new JPanel());
+        cont.add(registerComponent("btn-1", new JButton("jbutton")));
+        cont.add(registerComponent("btn-2", new JButton("jbutton")));
+
+        jframe.add(cont);
+        jframe.add(registerComponent("btn-3", new JButton("jbutton")));
+
+        return jframe;
+    }
+
+    protected void customizeHierarchy() {
+        ((Container)getComponent("jframe")).setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
+        ((Container)getComponent("jpanel")).setFocusCycleRoot(true);
+    }
+
+    protected Map<String, String> getForwardOrder() {
+        Map<String, String> order = new HashMap<String, String>();
+        order.put("jframe", "btn-1");
+        order.put("btn-1", "btn-2");
+        order.put("btn-2", "btn-1");
+        order.put("btn-3", "btn-1");
+        return order;
+    }
+
+    protected Map<String, String> getBackwardOrder() {
+        Map<String, String> order = new HashMap<String, String>();
+        order.put("btn-3", "btn-1");
+        order.put("btn-2", "btn-1");
+        order.put("btn-1", "btn-2");
+        order.put("jframe", "btn-3");
+        return order;
+    }
+
+    protected String[] getContainersToTest() {
+        return new String[] {"jframe"};
+    }
+
+    protected String getDefaultComp(String focusCycleRoot_id) {
+        return "btn-1";
+    }
+
+    protected String getFirstComp(String focusCycleRoot_id) {
+        return "btn-1";
+    }
+
+    protected String getLastComp(String focusCycleRoot_id) {
+        return "btn-3";
+    }
+}