jdk/src/share/classes/javax/swing/event/RowSorterEvent.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 2005 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
package javax.swing.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.swing.RowSorter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * <code>RowSorterEvent</code> provides notification of changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * a <code>RowSorter</code>.  Two types of notification are possible:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <li><code>Type.SORT_ORDER_CHANGED</code>: indicates the sort order has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *     changed.  This is typically followed by a notification of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <li><code>Type.SORTED</code>: indicates the contents of the model have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *     been transformed in some way.  For example, the contents may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *     been sorted or filtered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see javax.swing.RowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class RowSorterEvent extends java.util.EventObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Type type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private int[] oldViewToModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Enumeration of the types of <code>RowSorterEvent</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public enum Type {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         * Indicates the sort order has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        SORT_ORDER_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         * Indicates the contents have been newly sorted or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * transformed in some way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        SORTED
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Creates a <code>RowSorterEvent</code> of type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * <code>SORT_ORDER_CHANGED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param source the source of the change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @throws IllegalArgumentException if <code>source</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public RowSorterEvent(RowSorter source) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this(source, Type.SORT_ORDER_CHANGED, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Creates a <code>RowSorterEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param source the source of the change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param type the type of event
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param previousRowIndexToModel the mapping from model indices to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *        view indices prior to the sort, may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws IllegalArgumentException if source or <code>type</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public RowSorterEvent(RowSorter source, Type type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                          int[] previousRowIndexToModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throw new IllegalArgumentException("type must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        this.oldViewToModel = previousRowIndexToModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Returns the source of the event as a <code>RowSorter</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @return the source of the event as a <code>RowSorter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public RowSorter getSource() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return (RowSorter)super.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Returns the type of event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return the type of event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public Type getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the location of <code>index</code> in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * model prior to the sort.  This method is only useful for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * of type <code>SORTED</code>.  This method will return -1 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * index is not valid, or the locations prior to the sort have not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * been provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param index the index in terms of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return the index in terms of the model prior to the sort, or -1 if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *         the location is not valid or the mapping was not provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public int convertPreviousRowIndexToModel(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (oldViewToModel != null && index >= 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                index < oldViewToModel.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return oldViewToModel[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns the number of rows before the sort.  This method is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * useful for events of type <code>SORTED</code> and if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * last locations have not been provided will return 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return the number of rows in terms of the view prior to the sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public int getPreviousRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return (oldViewToModel == null) ? 0 : oldViewToModel.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
}