Package javax.swing

Examples of javax.swing.DefaultListSelectionModel


  private void testMultipleIntervalSelection(TestHarness harness)
  {
    // check 1 : clearing an empty selection generates no event
    harness.checkPoint("MULTIPLE_INTERVAL_SELECTION (1)");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.MULTIPLE_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("MULTIPLE_INTERVAL_SELECTION (2)");
    m.addSelectionInterval(2, 3);
    m.addSelectionInterval(12, 13);
    lastEvent = null;
    m.clearSelection();
    harness.check(m.isSelectionEmpty(), true);
    harness.check(m.getAnchorSelectionIndex(), 12);
    harness.check(m.getLeadSelectionIndex(), 13);
    harness.check(m.getMinSelectionIndex(), -1);
    harness.check(m.getMaxSelectionIndex(), -1);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 2);
    harness.check(lastEvent.getLastIndex(), 13);
  }
View Full Code Here


    lastEvent = e;
  }

  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.addSelectionInterval(3, 5);
    m.addListSelectionListener(this);
    m.moveLeadSelectionIndex(7);
    harness.check(m.isSelectedIndex(5), true);
    harness.check(m.isSelectedIndex(6), false);
    harness.check(m.isSelectedIndex(7), false);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 5);
    harness.check(lastEvent.getLastIndex(), 7);
  }
View Full Code Here

    lastEvent = event;
  }

  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.addSelectionInterval(2, 4);
    harness.check(m.getAnchorSelectionIndex(), 2);
    harness.check(m.isLeadAnchorNotificationEnabled(), true);
    m.addListSelectionListener(this);
    m.setAnchorSelectionIndex(1);
    harness.check(m.getAnchorSelectionIndex(), 1);
    harness.check(m.isSelectedIndex(1), false);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 1);
    harness.check(lastEvent.getLastIndex(), 2);
   
    // setting the same index generates no event
    lastEvent = null;
    m.setAnchorSelectionIndex(1);
    harness.check(lastEvent, null);
   
    // try a negative value
    m.setAnchorSelectionIndex(-2);
    harness.check(m.getAnchorSelectionIndex(), -2);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), -2);
    harness.check(lastEvent.getLastIndex(), 1);
   
    // now try without notification
    m.setLeadAnchorNotificationEnabled(false);
    lastEvent = null;
    m.setAnchorSelectionIndex(2);
    harness.check(m.getAnchorSelectionIndex(), 2);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(lastEvent, null);
  }
View Full Code Here

   * anchor selection index is also -1.
   */
  private void testSetMinusOne(TestHarness harness)
  {
    harness.checkPoint("setMinusOne");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    // Set to some value. (works only if anchor selection index is >= 0).
    m.setAnchorSelectionIndex(1);
    m.setLeadSelectionIndex(1);
    harness.check(m.getLeadSelectionIndex(), 1);
    // This should have no effect.
    m.setLeadSelectionIndex(-1);
    harness.check(m.getLeadSelectionIndex(), 1);
    // Now set the anchor selection index to -1 and it will work with the
    // lead selection index too.
    m.setAnchorSelectionIndex(-1);
    m.setLeadSelectionIndex(-1);
    harness.check(m.getLeadSelectionIndex(), -1);
  }
View Full Code Here

   * is also >=.
   */
  private void testSetPositive(TestHarness harness)
  {
    harness.checkPoint("setPositive");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    // The lead and anchor selection index is -1 initially.
    harness.check(m.getLeadSelectionIndex(), -1);
    harness.check(m.getAnchorSelectionIndex(), -1);
    // This will not work unless the anchor selection index is != -1
    m.setLeadSelectionIndex(0);
    harness.check(m.getLeadSelectionIndex(), -1);
    // Now set the anchor to 0 and it will also work for the lead.
    m.setAnchorSelectionIndex(0);
    m.setLeadSelectionIndex(0);
    harness.check(m.getLeadSelectionIndex(), 0);
  }
View Full Code Here

  }
 
    private void testSingleSelection(TestHarness harness)
  {
    harness.checkPoint("SINGLE_SELECTION (1)");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m.setLeadAnchorNotificationEnabled(true);
    m.addListSelectionListener(this);
   
    // starting from an empty selection...
    m.setLeadSelectionIndex(2);
    harness.check(m.getLeadSelectionIndex(), -1);
    harness.check(m.getAnchorSelectionIndex(), -1);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(lastEvent, null);
   
    // starting from a selection
    harness.checkPoint("SINGLE_SELECTION (2)");
    m.setSelectionInterval(2, 2);
    lastEvent = null;
    m.setLeadSelectionIndex(1);
    harness.check(m.getLeadSelectionIndex(), 1);
    harness.check(m.getAnchorSelectionIndex(), 1);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 1);
    harness.check(lastEvent.getLastIndex(), 2);
   
    // set the lead selection to -1 is ignored
    harness.checkPoint("SINGLE_SELECTION (3)");
    lastEvent = null;
    m.setLeadSelectionIndex(-1);
    harness.check(m.getLeadSelectionIndex(), 1);
    harness.check(m.getAnchorSelectionIndex(), 1);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(lastEvent, null);
   
    // set the lead selection to -2
    harness.checkPoint("SINGLE_SELECTION (4)");
    boolean pass = false;
    try
      {
        m.setLeadSelectionIndex(-2);
      }
    catch (IndexOutOfBoundsException e)
      {
        pass = true
      }
View Full Code Here

    harness.check(pass);
  }

  private void testSingleIntervalSelection(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    m.addListSelectionListener(this);
   
    // starting from an empty selection...
    harness.checkPoint("SINGLE_INTERVAL_SELECTION (1)");
    m.setLeadSelectionIndex(2);
    harness.check(m.getLeadSelectionIndex(), -1);
    harness.check(m.getAnchorSelectionIndex(), -1);
    harness.check(m.isSelectedIndex(2), false);
    harness.check(lastEvent, null);
   
    // starting from a selection
    harness.checkPoint("SINGLE_INTERVAL_SELECTION (2)");
    m.setSelectionInterval(2, 4);
    lastEvent = null;
    m.setLeadSelectionIndex(1);
    harness.check(m.getLeadSelectionIndex(), 1);
    harness.check(m.getAnchorSelectionIndex(), 2);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(m.isSelectedIndex(3), false);
    harness.check(m.isSelectedIndex(4), false);
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 1);
    harness.check(lastEvent.getLastIndex(), 4);

    // setting the lead selection to -1 is ignored
    harness.checkPoint("SINGLE_INTERVAL_SELECTION (3)");
    lastEvent = null;
    m.setLeadSelectionIndex(-1);
    harness.check(m.getLeadSelectionIndex(), 1);
    harness.check(m.getAnchorSelectionIndex(), 2);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(lastEvent, null);
   
    // setting the lead selection to -2 fails
    harness.checkPoint("SINGLE_INTERVAL_SELECTION (4)");
    boolean pass = false;
    try
      {
        m.setLeadSelectionIndex(-2);
      }
    catch (IndexOutOfBoundsException e)
      {
        pass = true;
      }
View Full Code Here

public class getValueIsAdjusting implements Testlet
{
  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    harness.check(m.getValueIsAdjusting(), false);
    m.setValueIsAdjusting(true);
    harness.check(m.getValueIsAdjusting(), true);
  }
View Full Code Here

public class getLeadSelectionIndex implements Testlet
{
  public void test(TestHarness harness)
  {
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    harness.check(m.getLeadSelectionIndex(), -1);
    m.setAnchorSelectionIndex(1);
    m.setLeadSelectionIndex(3);
    harness.check(m.getLeadSelectionIndex(), 3);
   
    m.clearSelection();
    harness.check(m.getLeadSelectionIndex(), 3);
   
    m.addSelectionInterval(15, 11);
    harness.check(m.getLeadSelectionIndex(), 11);
  }
View Full Code Here

  }
 
  public void testSingleSelection(TestHarness harness)
  {
    harness.checkPoint("SINGLE_SELECTION");
    DefaultListSelectionModel m = new DefaultListSelectionModel();
    m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   
    // check 1 - the selected item is in the removed range
    m.addSelectionInterval(6, 7);
    harness.check(m.isSelectedIndex(6), false);
    harness.check(m.isSelectedIndex(7), true);
    harness.check(m.getAnchorSelectionIndex(), 7);
    harness.check(m.getLeadSelectionIndex(), 7);
    m.addListSelectionListener(this);
    m.removeIndexInterval(5, 7);
    harness.check(m.isSelectionEmpty(), true);
    harness.check(m.getAnchorSelectionIndex(), 4);
    harness.check(m.getLeadSelectionIndex(), 4);
   
    harness.check(lastEvent.getSource(), m);
    harness.check(lastEvent.getFirstIndex(), 4);
    harness.check(lastEvent.getLastIndex(), 7);
   
    // check 2 - the selected item is below the removed range
    m.setSelectionInterval(1, 1);
    lastEvent = null;
    m.removeIndexInterval(2, 4);
    harness.check(m.isSelectedIndex(1), true);
    harness.check(m.getAnchorSelectionIndex(), 1);
    harness.check(m.getLeadSelectionIndex(), 1);
    harness.check(lastEvent, null); // no event, because nothing changed
   
    // check 3 - the selected item is above the removed range
    m.setSelectionInterval(5, 5);
    lastEvent = null;
    m.removeIndexInterval(2, 4);
    harness.check(m.isSelectedIndex(2), true);
    harness.check(m.getAnchorSelectionIndex(), 2);
    harness.check(m.getLeadSelectionIndex(), 2);
    harness.check(lastEvent.getFirstIndex(), 2);
    harness.check(lastEvent.getLastIndex(), 5);
  }
View Full Code Here

TOP

Related Classes of javax.swing.DefaultListSelectionModel

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.