Package javax.swing

Examples of javax.swing.DefaultListSelectionModel$Segment


  }
 
  private void testMultipleInterval(TestHarness harness)
  {
    harness.checkPoint("MULTIPLE_INTERVAL_SELECTION (1)");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    m.addSelectionInterval(1, 1);
    m.addSelectionInterval(7, 7);
    m.addSelectionInterval(3, 5);
    m.addListSelectionListener(this);
    m.insertIndexInterval(2, 2, true);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(m.isSelectedIndex(3), false);
    harness.check(m.isSelectedIndex(4), false);
    harness.check(m.isSelectedIndex(5), true);
    harness.check(m.isSelectedIndex(6), true);
    harness.check(m.isSelectedIndex(7), true);
    harness.check(m.isSelectedIndex(8), false);
    harness.check(m.isSelectedIndex(9), true);
    harness.check(m.isSelectedIndex(10), false);
    harness.check(m.getAnchorSelectionIndex(), 5);
    harness.check(m.getLeadSelectionIndex(), 7);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 3);
    harness.check(lastEvent.getLastIndex(), 9);
   
    m.insertIndexInterval(1, 2, false);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(m.isSelectedIndex(3), true);
    harness.check(m.isSelectedIndex(4), false);
    harness.check(m.isSelectedIndex(5), false);
    harness.check(m.isSelectedIndex(6), false);
    harness.check(m.isSelectedIndex(7), true);
    harness.check(m.isSelectedIndex(8), true);
    harness.check(m.isSelectedIndex(9), true);
    harness.check(m.isSelectedIndex(10), false);
    harness.check(m.isSelectedIndex(11), true);
    harness.check(m.isSelectedIndex(12), false);
    harness.check(m.getAnchorSelectionIndex(), 7);
    harness.check(m.getLeadSelectionIndex(), 9);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 2);
    harness.check(lastEvent.getLastIndex(), 11)
  }
View Full Code Here


  }
 
  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);
  }
View Full Code Here

  }
 
  private void testSingleSelection(TestHarness harness)
  {
    harness.checkPoint("SINGLE_SELECTION");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.addListSelectionListener(this);
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.addSelectionInterval(1, 3);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), false);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(m.isSelectedIndex(3), true);
    harness.check(m.isSelectedIndex(4), false);
    harness.check(m.getAnchorSelectionIndex(), 3);
    harness.check(m.getLeadSelectionIndex(), 3);
    harness.check(m.getMaxSelectionIndex(), 3);
    harness.check(m.getMinSelectionIndex(), 3);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 3);
    harness.check(lastEvent.getLastIndex(), 3);
   
    m.clearSelection();
    m.addSelectionInterval(3, 1);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(m.isSelectedIndex(3), false);
    harness.check(m.isSelectedIndex(4), false);
    harness.check(m.getAnchorSelectionIndex(), 1);
    harness.check(m.getLeadSelectionIndex(), 1);
    harness.check(m.getMaxSelectionIndex(), 1);
    harness.check(m.getMinSelectionIndex(), 1);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 1);
    harness.check(lastEvent.getLastIndex(), 3);
  }
View Full Code Here

  }

  private void testMultipleIntervalSelection(TestHarness harness)
  {
    harness.checkPoint("MULTIPLE_INTERVAL_SELECTION");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.addSelectionInterval(1, 3);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(m.isSelectedIndex(3), true);
    harness.check(m.isSelectedIndex(4), false);
   
    m.clearSelection();
    m.addSelectionInterval(2, 1);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(m.isSelectedIndex(3), false);
   
    // check what happens for negative indices...
    m.clearSelection();
    m.addSelectionInterval(-1, 1);
    harness.check(m.isSelectedIndex(-2), false);
    harness.check(m.isSelectedIndex(-1), false);
    harness.check(m.isSelectedIndex(0), false);
    harness.check(m.isSelectedIndex(1), false);
    harness.check(m.isSelectedIndex(2), false);
  }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    DefaultTableColumnModel m1 = new DefaultTableColumnModel();
    ListSelectionModel lsm = new DefaultListSelectionModel();
    m1.setSelectionModel(lsm);
    harness.check(m1.getSelectionModel(), lsm);
  }
View Full Code Here

   * @param harness  the test harness (<code>null</code> not permitted).
   */
  public void test(TestHarness harness)     
  {
    DefaultTableColumnModel m1 = new DefaultTableColumnModel();
    DefaultListSelectionModel lsm = new DefaultListSelectionModel();
    m1.setSelectionModel(lsm);
    harness.check(m1.getSelectionModel(), lsm);
    ListSelectionListener[] listeners = lsm.getListSelectionListeners();
    harness.check(listeners[0], m1);
   
    DefaultListSelectionModel lsm2 = new DefaultListSelectionModel();
    m1.setSelectionModel(lsm2);
    harness.check(m1.getSelectionModel(), lsm2);
    listeners = lsm.getListSelectionListeners();
    harness.check(listeners.length, 0);
   
View Full Code Here

public class constructor implements Testlet
{
  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    harness.check(m.getSelectionMode(),
            ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    harness.check(m.isLeadAnchorNotificationEnabled(), true);
    harness.check(m.getAnchorSelectionIndex(), -1);
    harness.check(m.getLeadSelectionIndex(), -1);
    harness.check(m.getMaxSelectionIndex(), -1);
    harness.check(m.getMinSelectionIndex(), -1);
    harness.check(m.isSelectionEmpty(), true);
    harness.check(m.getValueIsAdjusting(), false);
  }
View Full Code Here

public class getSelectionMode implements Testlet
{
  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    harness.check(m.getSelectionMode(),
            ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    harness.check(m.getSelectionMode(),
            ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  }
View Full Code Here

 
  private void testSingleSelection(TestHarness harness)
  {
    // clearing an empty selection generates no event
    harness.checkPoint("SINGLE_SELECTION (1)");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.addListSelectionListener(this);
    m.clearSelection();
    harness.check(lastEvent, null);
   
    harness.checkPoint("SINGLE_SELECTION (2)");
    m.setSelectionInterval(3, 3);
    lastEvent = null;
    m.clearSelection();
    harness.check(m.isSelectionEmpty());
    harness.check(m.getAnchorSelectionIndex(), 3);
    harness.check(m.getLeadSelectionIndex(), 3);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 3);
    harness.check(lastEvent.getLastIndex(), 3);
  }
View Full Code Here

 
  private void testSingleIntervalSelection(TestHarness harness)
  {
    // check 1 : clearing an empty selection generates no event
    harness.checkPoint("SINGLE_INTERVAL_SELECTION (1)");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    m.addListSelectionListener(this);
    harness.check(m.isSelectionEmpty(), true);
    lastEvent = null;
    m.clearSelection();
    harness.check(m.isSelectionEmpty(), true);
    harness.check(lastEvent, null);
   
    // check 2 : clearing a selection generates an event with first and last
    // indices covering the former selection
    harness.checkPoint("SINGLE_INTERVAL_SELECTION (2)");
    m.addSelectionInterval(10, 20);
    lastEvent = null;
    m.clearSelection();
    harness.check(m.isSelectionEmpty(), true);
    harness.check(m.isSelectedIndex(10), false);
    harness.check(m.getAnchorSelectionIndex(), 10);
    harness.check(m.getLeadSelectionIndex(), 20);
    harness.check(m.getMinSelectionIndex(), -1);
    harness.check(m.getMaxSelectionIndex(), -1);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 10);
    harness.check(lastEvent.getLastIndex(), 20);
  }
View Full Code Here

TOP

Related Classes of javax.swing.DefaultListSelectionModel$Segment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.