1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.swing.event;
  27 
  28 import java.util.EventObject;
  29 import javax.swing.*;
  30 
  31 
  32 /**
  33  * An event that characterizes a change in selection. The change is limited to a
  34  * a single inclusive interval. The selection of at least one index within the
  35  * range will have changed. A decent {@code ListSelectionModel} implementation
  36  * will keep the range as small as possible. {@code ListSelectionListeners} will
  37  * generally query the source of the event for the new selected status of each
  38  * potentially changed row.
  39  * <p>
  40  * <strong>Warning:</strong>
  41  * Serialized objects of this class will not be compatible with
  42  * future Swing releases. The current serialization support is
  43  * appropriate for short term storage or RMI between applications running
  44  * the same version of Swing.  As of 1.4, support for long term storage
  45  * of all JavaBeans&trade;
  46  * has been added to the <code>java.beans</code> package.
  47  * Please see {@link java.beans.XMLEncoder}.
  48  *
  49  * @author Hans Muller
  50  * @author Ray Ryan
  51  * @see ListSelectionModel
  52  */
  53 @SuppressWarnings("serial") // Same-version serialization only
  54 public class ListSelectionEvent extends EventObject
  55 {
  56     private int firstIndex;
  57     private int lastIndex;
  58     private boolean isAdjusting;
  59 
  60     /**
  61      * Represents a change in selection status between {@code firstIndex} and
  62      * {@code lastIndex}, inclusive. {@code firstIndex} is less than or equal to
  63      * {@code lastIndex}. The selection of at least one index within the range will
  64      * have changed.
  65      *
  66      * @param source the {@code Object} on which the event initially occurred
  67      * @param firstIndex the first index in the range, &lt;= lastIndex
  68      * @param lastIndex the last index in the range, &gt;= firstIndex
  69      * @param isAdjusting whether or not this is one in a series of
  70      *        multiple events, where changes are still being made
  71      */
  72     public ListSelectionEvent(Object source, int firstIndex, int lastIndex,
  73                               boolean isAdjusting)
  74     {
  75         super(source);
  76         this.firstIndex = firstIndex;
  77         this.lastIndex = lastIndex;
  78         this.isAdjusting = isAdjusting;
  79     }
  80 
  81     /**
  82      * Returns the index of the first row whose selection may have changed.
  83      * {@code getFirstIndex() <= getLastIndex()}
  84      *
  85      * @return the first row whose selection value may have changed,
  86      *         where zero is the first row
  87      */
  88     public int getFirstIndex() { return firstIndex; }
  89 
  90     /**
  91      * Returns the index of the last row whose selection may have changed.
  92      * {@code getLastIndex() >= getFirstIndex()}
  93      *
  94      * @return the last row whose selection value may have changed,
  95      *         where zero is the first row
  96      */
  97     public int getLastIndex() { return lastIndex; }
  98 
  99     /**
 100      * Returns whether or not this is one in a series of multiple events,
 101      * where changes are still being made. See the documentation for
 102      * {@link javax.swing.ListSelectionModel#setValueIsAdjusting} for
 103      * more details on how this is used.
 104      *
 105      * @return {@code true} if this is one in a series of multiple events,
 106      *         where changes are still being made
 107      */
 108     public boolean getValueIsAdjusting() { return isAdjusting; }
 109 
 110     /**
 111      * Returns a {@code String} that displays and identifies this
 112      * object's properties.
 113      *
 114      * @return a String representation of this object
 115      */
 116     public String toString() {
 117         String properties =
 118             " source=" + getSource() +
 119             " firstIndex= " + firstIndex +
 120             " lastIndex= " + lastIndex +
 121             " isAdjusting= " + isAdjusting +
 122             " ";
 123         return getClass().getName() + "[" + properties + "]";
 124     }
 125 }