content: package gui;
  
  import javax.swing.ListSelectionModel;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  
  import common.Log;
  
  class SharedListSelectionHandler implements ListSelectionListener {
      public void valueChanged(ListSelectionEvent e) {
          ListSelectionModel lsm = (ListSelectionModel)e.getSource();
  
          int firstIndex = e.getFirstIndex();
          int lastIndex = e.getLastIndex();
          boolean isAdjusting = e.getValueIsAdjusting();
          Log.println("Event for indexes "
                        + firstIndex + " - " + lastIndex
                        + "; isAdjusting is " + isAdjusting
                        + "; selected indexes:");
  
          if (lsm.isSelectionEmpty()) {
              Log.println(" <none>");
          } else {
              // Find out which indexes are selected.
              int minIndex = lsm.getMinSelectionIndex();
              int maxIndex = lsm.getMaxSelectionIndex();
              for (int i = minIndex; i <= maxIndex; i++) {
                  if (lsm.isSelectedIndex(i)) {
                      Log.println(" " + i);
                  }
              }
          }
          Log.println("");
      }
  }