}
private void testSingleInterval(TestHarness harness)
{
harness.checkPoint("SINGLE_INTERVAL_SELECTION (1)");
DefaultListSelectionModel m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
m.setSelectionInterval(3, 3);
m.addListSelectionListener(this);
// here, we insert two new items in the list right before the selected item
// 3 (which moves up to position 5).
m.insertIndexInterval(3, 2, true);
harness.check(m.isSelectedIndex(3), true); // FIXME: surely wrong?
harness.check(m.isSelectedIndex(4), true); // FIXME: likewise?
harness.check(m.isSelectedIndex(5), true);
harness.check(m.isSelectedIndex(6), false);
harness.check(m.getAnchorSelectionIndex(), 5);
harness.check(m.getLeadSelectionIndex(), 5);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 3);
harness.check(lastEvent.getLastIndex(), 5);
harness.checkPoint("SINGLE_INTERVAL_SELECTION (2)");
m = new DefaultListSelectionModel();
m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
m.setSelectionInterval(3, 3);
m.addListSelectionListener(this);
lastEvent = null;
// here, we insert two new items in the list right AFTER the selected item
// 3
m.insertIndexInterval(3, 2, false);
harness.check(m.isSelectedIndex(3), true);
harness.check(m.isSelectedIndex(4), true); // FIXME: surely wrong?
harness.check(m.isSelectedIndex(5), true); // FIXME: likewise?
harness.check(m.isSelectedIndex(6), false);
harness.check(m.getAnchorSelectionIndex(), 3);
harness.check(m.getLeadSelectionIndex(), 3);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 4);
harness.check(lastEvent.getLastIndex(), 5);
// try negative index
boolean pass = false;
try
{
m.insertIndexInterval(-1, 1, true);
}
catch (IndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// try negative count
pass = false;
try
{
m.insertIndexInterval(0, -1, true);
}
catch (IndexOutOfBoundsException e)
{
pass = true;
}
harness.check(pass);
// try zero count
lastEvent = null;
m.insertIndexInterval(0, 0, true);
harness.check(lastEvent.getSource(), m);
harness.check(lastEvent.getFirstIndex(), 0);
harness.check(lastEvent.getLastIndex(), 6);
}