1 /* 2 * Copyright (c) 1997, 2013, 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 30 31 /** 32 * Defines an event that encapsulates changes to a list. 33 * <p> 34 * <strong>Warning:</strong> 35 * Serialized objects of this class will not be compatible with 36 * future Swing releases. The current serialization support is 37 * appropriate for short term storage or RMI between applications running 38 * the same version of Swing. As of 1.4, support for long term storage 39 * of all JavaBeans 40 * has been added to the <code>java.beans</code> package. 41 * Please see {@link java.beans.XMLEncoder}. 42 * 43 * @author Hans Muller 44 */ 45 @SuppressWarnings("serial") 46 public class ListDataEvent extends EventObject 47 { 48 /** Identifies one or more changes in the lists contents. */ 49 public static final int CONTENTS_CHANGED = 0; 50 /** Identifies the addition of one or more contiguous items to the list */ 51 public static final int INTERVAL_ADDED = 1; 52 /** Identifies the removal of one or more contiguous items from the list */ 53 public static final int INTERVAL_REMOVED = 2; 54 55 private int type; 56 private int index0; 57 private int index1; 58 59 /** 60 * Returns the event type. The possible values are: 61 * <ul> 62 * <li> {@link #CONTENTS_CHANGED} 63 * <li> {@link #INTERVAL_ADDED} 64 * <li> {@link #INTERVAL_REMOVED} 65 * </ul> 66 * 67 * @return an int representing the type value 68 */ 69 public int getType() { return type; } 70 71 /** 72 * Returns the lower index of the range. For a single 73 * element, this value is the same as that returned by {@link #getIndex1}. 74 75 * 76 * @return an int representing the lower index value 77 */ 78 public int getIndex0() { return index0; } 79 /** 80 * Returns the upper index of the range. For a single 81 * element, this value is the same as that returned by {@link #getIndex0}. 82 * 83 * @return an int representing the upper index value 84 */ 85 public int getIndex1() { return index1; } 86 87 /** 88 * Constructs a ListDataEvent object. If index0 is > 89 * index1, index0 and index1 will be swapped such that 90 * index0 will always be <= index1. 91 * 92 * @param source the source Object (typically <code>this</code>) 93 * @param type an int specifying {@link #CONTENTS_CHANGED}, 94 * {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED} 95 * @param index0 one end of the new interval 96 * @param index1 the other end of the new interval 97 */ 98 public ListDataEvent(Object source, int type, int index0, int index1) { 99 super(source); 100 this.type = type; 101 this.index0 = Math.min(index0, index1); 102 this.index1 = Math.max(index0, index1); 103 } 104 105 /** 106 * Returns a string representation of this ListDataEvent. This method 107 * is intended to be used only for debugging purposes, and the 108 * content and format of the returned string may vary between 109 * implementations. The returned string may be empty but may not 110 * be <code>null</code>. 111 * 112 * @since 1.4 113 * @return a string representation of this ListDataEvent. 114 */ 115 public String toString() { 116 return getClass().getName() + 117 "[type=" + type + 118 ",index0=" + index0 + 119 ",index1=" + index1 + "]"; 120 } 121 }