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

Reviewed-by: dcherepanov
This commit is contained in:
Anton Tarasov 2009-06-18 11:28:54 +04:00
parent fdff41f711
commit 48ed6852bf
4 changed files with 131 additions and 14 deletions

View File

@ -425,15 +425,13 @@ public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
}
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;
}
}
}

View File

@ -444,11 +444,10 @@ public class SortingFocusTraversalPolicy
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;

View File

@ -104,7 +104,7 @@ comp[unfocusable] - <comp> is set unfocusable.
*/
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 @@ 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";
}
}

View File

@ -105,7 +105,7 @@ comp[unfocusable] - <comp> is set unfocusable.
*/
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 @@ 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";
}
}