1 /* 2 * Copyright (c) 1997, 2006, 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™ 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 public class ListSelectionEvent extends EventObject 54 { 55 private int firstIndex; 56 private int lastIndex; 57 private boolean isAdjusting; 58 59 /** 60 * Represents a change in selection status between {@code firstIndex} and 61 * {@code lastIndex}, inclusive. {@code firstIndex} is less than or equal to 62 * {@code lastIndex}. The selection of at least one index within the range will 63 * have changed. 64 * 65 * @param firstIndex the first index in the range, <= lastIndex 66 * @param lastIndex the last index in the range, >= firstIndex 67 * @param isAdjusting whether or not this is one in a series of 68 * multiple events, where changes are still being made 69 */ 70 public ListSelectionEvent(Object source, int firstIndex, int lastIndex, 71 boolean isAdjusting) 72 { 73 super(source); 74 this.firstIndex = firstIndex; 75 this.lastIndex = lastIndex; 76 this.isAdjusting = isAdjusting; 77 } 78 79 /** 80 * Returns the index of the first row whose selection may have changed. 81 * {@code getFirstIndex() <= getLastIndex()} 82 * 83 * @return the first row whose selection value may have changed, 84 * where zero is the first row 85 */ 86 public int getFirstIndex() { return firstIndex; } 87 88 /** 89 * Returns the index of the last row whose selection may have changed. 90 * {@code getLastIndex() >= getFirstIndex()} 91 * 92 * @return the last row whose selection value may have changed, 93 * where zero is the first row 94 */ 95 public int getLastIndex() { return lastIndex; } 96 97 /** 98 * Returns whether or not this is one in a series of multiple events, 99 * where changes are still being made. See the documentation for 100 * {@link javax.swing.ListSelectionModel#setValueIsAdjusting} for 101 * more details on how this is used. 102 * 103 * @return {@code true} if this is one in a series of multiple events, 104 * where changes are still being made 105 */ 106 public boolean getValueIsAdjusting() { return isAdjusting; } 107 108 /** 109 * Returns a {@code String} that displays and identifies this 110 * object's properties. 111 * 112 * @return a String representation of this object 113 */ 114 public String toString() { 115 String properties = 116 " source=" + getSource() + 117 " firstIndex= " + firstIndex + 118 " lastIndex= " + lastIndex + 119 " isAdjusting= " + isAdjusting + 120 " "; 121 return getClass().getName() + "[" + properties + "]"; 122 } 123 }