提交 54e0c63e 编写于 作者: A ant

4788402: SortingFocusTraversalPolicy: prob with non-focusable focus Cycle Root as first

Reviewed-by: dcherepanov
上级 f6599e7f
...@@ -425,15 +425,13 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy ...@@ -425,15 +425,13 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
} }
if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle); if (log.isLoggable(Level.FINE)) log.fine("### Cycle is " + cycle);
for (int i = 0; i < cycle.size(); i++) { for (Component comp : cycle) {
Component comp = cycle.get(i);
if (accept(comp)) { if (accept(comp)) {
return comp; return comp;
} else if (comp instanceof Container && comp != aContainer) { } else if (comp != aContainer &&
Container cont = (Container)comp; (comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null)
if (cont.isFocusTraversalPolicyProvider()) { {
return cont.getFocusTraversalPolicy().getDefaultComponent(cont); return comp;
}
} }
} }
} }
......
...@@ -444,11 +444,10 @@ public class SortingFocusTraversalPolicy ...@@ -444,11 +444,10 @@ public class SortingFocusTraversalPolicy
for (Component comp : cycle) { for (Component comp : cycle) {
if (accept(comp)) { if (accept(comp)) {
return comp; return comp;
} else if (comp instanceof Container && comp != aContainer) { } else if (comp != aContainer &&
Container cont = (Container)comp; (comp = getComponentDownCycle(comp, FORWARD_TRAVERSAL)) != null)
if (cont.isFocusTraversalPolicyProvider()) { {
return cont.getFocusTraversalPolicy().getDefaultComponent(cont); return comp;
}
} }
} }
return null; return null;
......
...@@ -104,7 +104,7 @@ comp[unfocusable] - <comp> is set unfocusable. ...@@ -104,7 +104,7 @@ comp[unfocusable] - <comp> is set unfocusable.
*/ */
public class DefaultFTPTest { public class DefaultFTPTest {
final int TESTS_NUMBER = 10; final int TESTS_NUMBER = 11;
public static void main(String[] args) { public static void main(String[] args) {
DefaultFTPTest app = new DefaultFTPTest(); DefaultFTPTest app = new DefaultFTPTest();
...@@ -928,3 +928,63 @@ class PolicyTest10 extends AbstractPolicyTest { ...@@ -928,3 +928,63 @@ class PolicyTest10 extends AbstractPolicyTest {
} }
} }
} }
/*
* 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";
}
}
...@@ -105,7 +105,7 @@ comp[unfocusable] - <comp> is set unfocusable. ...@@ -105,7 +105,7 @@ comp[unfocusable] - <comp> is set unfocusable.
*/ */
public class LayoutFTPTest { public class LayoutFTPTest {
final int TESTS_NUMBER = 10; final int TESTS_NUMBER = 11;
public static void main(String[] args) { public static void main(String[] args) {
LayoutFTPTest app = new LayoutFTPTest(); LayoutFTPTest app = new LayoutFTPTest();
...@@ -929,3 +929,63 @@ class PolicyTest10 extends AbstractPolicyTest { ...@@ -929,3 +929,63 @@ class PolicyTest10 extends AbstractPolicyTest {
} }
} }
} }
/*
* 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";
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册