KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > event > ListDataEvent


1 /*
2  * @(#)ListDataEvent.java 1.18 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.swing.event;
9
10 import java.util.EventObject JavaDoc;
11
12
13 /**
14  * Defines an event that encapsulates changes to a list.
15  * <p>
16  * <strong>Warning:</strong>
17  * Serialized objects of this class will not be compatible with
18  * future Swing releases. The current serialization support is
19  * appropriate for short term storage or RMI between applications running
20  * the same version of Swing. As of 1.4, support for long term storage
21  * of all JavaBeans<sup><font size="-2">TM</font></sup>
22  * has been added to the <code>java.beans</code> package.
23  * Please see {@link java.beans.XMLEncoder}.
24  *
25  * @version 1.18 12/19/03
26  * @author Hans Muller
27  */

28 public class ListDataEvent extends EventObject JavaDoc
29 {
30     /** Identifies one or more changes in the lists contents. */
31     public static final int CONTENTS_CHANGED = 0;
32     /** Identifies the addition of one or more contiguous items to the list */
33     public static final int INTERVAL_ADDED = 1;
34     /** Identifies the removal of one or more contiguous items from the list */
35     public static final int INTERVAL_REMOVED = 2;
36
37     private int type;
38     private int index0;
39     private int index1;
40
41     /**
42      * Returns the event type. The possible values are:
43      * <ul>
44      * <li> {@link #CONTENTS_CHANGED}
45      * <li> {@link #INTERVAL_ADDED}
46      * <li> {@link #INTERVAL_REMOVED}
47      * </ul>
48      *
49      * @return an int representing the type value
50      */

51     public int getType() { return type; }
52
53     /**
54      * Returns the lower index of the range. For a single
55      * element, this value is the same as that returned by {@link #getIndex1}.
56
57      *
58      * @return an int representing the lower index value
59      */

60     public int getIndex0() { return index0; }
61     /**
62      * Returns the upper index of the range. For a single
63      * element, this value is the same as that returned by {@link #getIndex0}.
64      *
65      * @return an int representing the upper index value
66      */

67     public int getIndex1() { return index1; }
68
69     /**
70      * Constructs a ListDataEvent object. If index0 is >
71      * index1, index0 and index1 will be swapped such that
72      * index0 will always be <= index1.
73      *
74      * @param source the source Object (typically <code>this</code>)
75      * @param type an int specifying {@link #CONTENTS_CHANGED},
76      * {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}
77      * @param index0 one end of the new interval
78      * @param index1 the other end of the new interval
79      */

80     public ListDataEvent(Object JavaDoc source, int type, int index0, int index1) {
81         super(source);
82     this.type = type;
83     this.index0 = Math.min(index0, index1);
84     this.index1 = Math.max(index0, index1);
85     }
86
87     /**
88      * Returns a string representation of this ListDataEvent. This method
89      * is intended to be used only for debugging purposes, and the
90      * content and format of the returned string may vary between
91      * implementations. The returned string may be empty but may not
92      * be <code>null</code>.
93      *
94      * @since 1.4
95      * @return a string representation of this ListDataEvent.
96      */

97     public String JavaDoc toString() {
98         return getClass().getName() +
99         "[type=" + type +
100         ",index0=" + index0 +
101         ",index1=" + index1 + "]";
102     }
103 }
104
105
106
107
Popular Tags