}
private void testSingle(TestHarness harness)
{
harness.checkPoint("SINGLE_SELECTION");
DefaultListSelectionModel m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m.addListSelectionListener(this);
harness.checkPoint("SINGLE_SELECTION (1)");
m.setSelectionInterval(6, 7);
harness.check(m.isSelectedIndex(6), false);
harness.check(m.isSelectedIndex(7), true);
harness.check(m.getAnchorSelectionIndex(), 7);
harness.check(m.getLeadSelectionIndex(), 7);
ListSelectionEvent lastEvent = (ListSelectionEvent) events.get(0);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 7);
harness.check(lastEvent.getLastIndex(), 7);
// no event is generated if we update the same again
events.clear();
harness.checkPoint("SINGLE_SELECTION (2)");
m.setSelectionInterval(6, 7);
harness.check(events.size(), 0);
// now if we set another selection, the event range should cover the old
// index too
events.clear();
harness.checkPoint("SINGLE_SELECTION (3)");
m.setSelectionInterval(3, 3);
harness.check(m.isSelectedIndex(3), true);
harness.check(m.isSelectedIndex(7), false);
lastEvent = (ListSelectionEvent) events.get(0);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 3);
harness.check(lastEvent.getLastIndex(), 7);
// the anchor can move around independently of the selection, is it
// included in the event range? YES
harness.checkPoint("SINGLE_SELECTION (4)");
m.setAnchorSelectionIndex(5);
events.clear();
m.setSelectionInterval(4, 4);
lastEvent = (ListSelectionEvent) events.get(0);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 3);
harness.check(lastEvent.getLastIndex(), 5);
// try -2 for the initial index
harness.checkPoint("SINGLE_SELECTION (5)");
m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m.setSelectionInterval(2, 2);
m.addListSelectionListener(this);
events.clear();
m.setSelectionInterval(-2, 0);
lastEvent = (ListSelectionEvent) events.get(0);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 0);
harness.check(lastEvent.getLastIndex(), 2);
harness.check(m.getLeadSelectionIndex(), 0);
harness.check(m.getAnchorSelectionIndex(), 0);
// try -1 for the initial index
harness.checkPoint("SINGLE_SELECTION (6)");
m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m.setSelectionInterval(2, 2);
m.addListSelectionListener(this);
events.clear();
m.setSelectionInterval(-1, 0);
harness.check(events.size(), 0);
// try -2 for the second index
harness.checkPoint("SINGLE_SELECTION (7)");
m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m.setSelectionInterval(2, 2);
m.addListSelectionListener(this);
events.clear();
boolean pass = false;
try
{
m.setSelectionInterval(0, -2);
}
catch (IndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// try -1 for the second index
harness.checkPoint("SINGLE_SELECTION (8)");
m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m.setSelectionInterval(2, 2);
m.addListSelectionListener(this);
events.clear();
m.setSelectionInterval(0, -1);
harness.check(events.size(), 0);
}