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:
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 }
|
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} 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:
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})
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}.
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 }
|