jdk/src/share/classes/javax/swing/event/ListDataEvent.java
author malenkov
Wed, 07 May 2008 23:20:32 +0400
changeset 466 6acd5ec503a8
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE Summary: Add the Transient annotation and support it (JSR-273) Reviewed-by: peterz, loneid
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.EventObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Defines an event that encapsulates changes to a list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Hans Muller
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class ListDataEvent extends EventObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /** Identifies one or more changes in the lists contents. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int CONTENTS_CHANGED = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /** Identifies the addition of one or more contiguous items to the list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int INTERVAL_ADDED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /** Identifies the removal of one or more contiguous items from the list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final int INTERVAL_REMOVED = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private int index0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private int index1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Returns the event type. The possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <li> {@link #CONTENTS_CHANGED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <li> {@link #INTERVAL_ADDED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * <li> {@link #INTERVAL_REMOVED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @return an int representing the type value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public int getType() { return type; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * Returns the lower index of the range. For a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * element, this value is the same as that returned by {@link #getIndex1}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @return an int representing the lower index value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public int getIndex0() { return index0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Returns the upper index of the range. For a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * element, this value is the same as that returned by {@link #getIndex0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @return an int representing the upper index value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public int getIndex1() { return index1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Constructs a ListDataEvent object. If index0 is >
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * index1, index0 and index1 will be swapped such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * index0 will always be <= index1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param source  the source Object (typically <code>this</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param type    an int specifying {@link #CONTENTS_CHANGED},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *                {@link #INTERVAL_ADDED}, or {@link #INTERVAL_REMOVED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param index0  one end of the new interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param index1  the other end of the new interval
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public ListDataEvent(Object source, int type, int index0, int index1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.index0 = Math.min(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.index1 = Math.max(index0, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Returns a string representation of this ListDataEvent. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return  a string representation of this ListDataEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        return getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        "[type=" + type +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        ",index0=" + index0 +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        ",index1=" + index1 + "]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
}