2
|
1 |
/*
|
|
2 |
* Copyright 1997-2003 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any 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<sup><font size="-2">TM</font></sup>
|
|
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 |
public class ListDataEvent extends EventObject
|
|
46 |
{
|
|
47 |
/** Identifies one or more changes in the lists contents. */
|
|
48 |
public static final int CONTENTS_CHANGED = 0;
|
|
49 |
/** Identifies the addition of one or more contiguous items to the list */
|
|
50 |
public static final int INTERVAL_ADDED = 1;
|
|
51 |
/** Identifies the removal of one or more contiguous items from the list */
|
|
52 |
public static final int INTERVAL_REMOVED = 2;
|
|
53 |
|
|
54 |
private int type;
|
|
55 |
private int index0;
|
|
56 |
private int index1;
|
|
57 |
|
|
58 |
/**
|
|
59 |
* Returns the event type. The possible values are:
|
|
60 |
* <ul>
|
|
61 |
* <li> {@link #CONTENTS_CHANGED}
|
|
62 |
* <li> {@link #INTERVAL_ADDED}
|
|
63 |
* <li> {@link #INTERVAL_REMOVED}
|
|
64 |
* </ul>
|
|
65 |
*
|
|
66 |
* @return an int representing the type value
|
|
67 |
*/
|
|
68 |
public int getType() { return type; }
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Returns the lower index of the range. For a single
|
|
72 |
* element, this value is the same as that returned by {@link #getIndex1}.
|
|
73 |
|
|
74 |
*
|
|
75 |
* @return an int representing the lower index value
|
|
76 |
*/
|
|
77 |
public int getIndex0() { return index0; }
|
|
78 |
/**
|
|
79 |
* Returns the upper index of the range. For a single
|
|
80 |
* element, this value is the same as that returned by {@link #getIndex0}.
|
|
81 |
*
|
|
82 |
* @return an int representing the upper index value
|
|
83 |
*/
|
|
84 |
public int getIndex1() { return index1; }
|
|
85 |
|
|
86 |
/**
|
|
87 |
* Constructs a ListDataEvent object. If index0 is >
|
|
88 |
* index1, index0 and index1 will be swapped such that
|
|
89 |
* index0 will always be <= index1.
|
|
90 |
*
|
|
91 |
* @param source the source Object (typically <code>this</code>)
|
|
92 |
* @param type an int specifying {@link #CONTENTS_CHANGED},
|
|
93 |
* {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}
|
|
94 |
* @param index0 one end of the new interval
|
|
95 |
* @param index1 the other end of the new interval
|
|
96 |
*/
|
|
97 |
public ListDataEvent(Object source, int type, int index0, int index1) {
|
|
98 |
super(source);
|
|
99 |
this.type = type;
|
|
100 |
this.index0 = Math.min(index0, index1);
|
|
101 |
this.index1 = Math.max(index0, index1);
|
|
102 |
}
|
|
103 |
|
|
104 |
/**
|
|
105 |
* Returns a string representation of this ListDataEvent. This method
|
|
106 |
* is intended to be used only for debugging purposes, and the
|
|
107 |
* content and format of the returned string may vary between
|
|
108 |
* implementations. The returned string may be empty but may not
|
|
109 |
* be <code>null</code>.
|
|
110 |
*
|
|
111 |
* @since 1.4
|
|
112 |
* @return a string representation of this ListDataEvent.
|
|
113 |
*/
|
|
114 |
public String toString() {
|
|
115 |
return getClass().getName() +
|
|
116 |
"[type=" + type +
|
|
117 |
",index0=" + index0 +
|
|
118 |
",index1=" + index1 + "]";
|
|
119 |
}
|
|
120 |
}
|