jdk/src/java.desktop/share/classes/javax/swing/RowSorter.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 25859 3317bb8137f4
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.swing.SortOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <code>RowSorter</code> provides the basis for sorting and filtering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Beyond creating and installing a <code>RowSorter</code>, you very rarely
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * need to interact with one directly.  Refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * {@link javax.swing.table.TableRowSorter TableRowSorter} for a concrete
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * implementation of <code>RowSorter</code> for <code>JTable</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <code>RowSorter</code>'s primary role is to provide a mapping between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * two coordinate systems: that of the view (for example a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>JTable</code>) and that of the underlying data source, typically a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The view invokes the following methods on the <code>RowSorter</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <ul>
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 5506
diff changeset
    45
 * <li><code>toggleSortOrder</code> &#8212; The view invokes this when the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *     appropriate user gesture has occurred to trigger a sort.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     the user clicked a column header in a table.
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 5506
diff changeset
    48
 * <li>One of the model change methods &#8212; The view invokes a model
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     change method when the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     has changed.  There may be order dependencies in how the events are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     delivered, so a <code>RowSorter</code> should not update its mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     until one of these methods is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * Because the view makes extensive use of  the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>convertRowIndexToModel</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>convertRowIndexToView</code> and <code>getViewRowCount</code> methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * these methods need to be fast.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <code>RowSorter</code> provides notification of changes by way of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>RowSorterListener</code>.  Two types of notification are sent:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <ul>
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 5506
diff changeset
    62
 * <li><code>RowSorterEvent.Type.SORT_ORDER_CHANGED</code> &#8212; notifies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     listeners that the sort order has changed.  This is typically followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *     by a notification that the sort has changed.
23715
54ae9dd9df73 8039074: Tidy warnings cleanup for javax.swing
yan
parents: 5506
diff changeset
    65
 * <li><code>RowSorterEvent.Type.SORTED</code> &#8212; notifies listeners that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *     the mapping maintained by the <code>RowSorter</code> has changed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *     some way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <code>RowSorter</code> implementations typically don't have a one-to-one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * mapping with the underlying model, but they can.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * For example, if a database does the sorting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>toggleSortOrder</code> might call through to the database
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * (on a background thread), and override the mapping methods to return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * argument that is passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Concrete implementations of <code>RowSorter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * need to reference a model such as <code>TableModel</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <code>ListModel</code>.  The view classes, such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <code>JTable</code> and <code>JList</code>, will also have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * reference to the model.  To avoid ordering dependencies,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <code>RowSorter</code> implementations should not install a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * listener on the model.  Instead the view class will call into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <code>RowSorter</code> when the model changes.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * example, if a row is updated in a <code>TableModel</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <code>JTable</code> invokes <code>rowsUpdated</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * When the model changes, the view may call into any of the following methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <code>modelStructureChanged</code>, <code>allRowsChanged</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <code>rowsInserted</code>, <code>rowsDeleted</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>rowsUpdated</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * @param <M> the type of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * @see javax.swing.table.TableRowSorter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
public abstract class RowSorter<M> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private EventListenerList listenerList = new EventListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Creates a <code>RowSorter</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public RowSorter() {
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 the underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public abstract M getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Reverses the sort order of the specified column.  It is up to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * subclasses to provide the exact behavior when invoked.  Typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * this will reverse the sort order from ascending to descending (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * descending to ascending) if the specified column is already the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * primary sorted column; otherwise, makes the specified column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * the primary sorted column, with an ascending sort order.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * the specified column is not sortable, this method has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * If this results in changing the sort order and sorting, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * appropriate <code>RowSorterListener</code> notification will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param column the column to toggle the sort ordering of, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *        terms of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @throws IndexOutOfBoundsException if column is outside the range of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *         the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public abstract void toggleSortOrder(int column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * Returns the location of <code>index</code> in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * underlying model.  That is, for the row <code>index</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * the coordinates of the view this returns the row index in terms
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * of the underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param index the row index in terms of the underlying view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return row index in terms of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @throws IndexOutOfBoundsException if <code>index</code> is outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *         range of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public abstract int convertRowIndexToModel(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Returns the location of <code>index</code> in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * view.  That is, for the row <code>index</code> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * coordinates of the underlying model this returns the row index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * in terms of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param index the row index in terms of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return row index in terms of the view, or -1 if index has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *         filtered out of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @throws IndexOutOfBoundsException if <code>index</code> is outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *         the range of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public abstract int convertRowIndexToView(int index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Sets the current sort keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param keys the new <code>SortKeys</code>; <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *        is a shorthand for specifying an empty list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *        indicating that the view should be unsorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    public abstract void setSortKeys(List<? extends SortKey> keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Returns the current sort keys.  This must return a {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * non-null List} and may return an unmodifiable {@code List}. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * you need to change the sort keys, make a copy of the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * {@code List}, mutate the copy and invoke {@code setSortKeys}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * with the new list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return the current sort order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public abstract List<? extends SortKey> getSortKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Returns the number of rows in the view.  If the contents have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * been filtered this might differ from the row count of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return number of rows in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @see #getModelRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public abstract int getViewRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Returns the number of rows in the underlying model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return number of rows in the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @see #getViewRowCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public abstract int getModelRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Invoked when the underlying model structure has completely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * changed.  For example, if the number of columns in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * <code>TableModel</code> changed, this method would be invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * You normally do not call this method.  This method is public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * to allow view classes to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public abstract void modelStructureChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Invoked when the contents of the underlying model have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * completely changed. The structure of the table is the same,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * only the contents have changed. This is typically sent when it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * is too expensive to characterize the change in terms of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * other methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * You normally do not call this method.  This method is public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * to allow view classes to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public abstract void allRowsChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Invoked when rows have been inserted into the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * in the specified range (inclusive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * The arguments give the indices of the effected range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * The first argument is in terms of the model before the change, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * must be less than or equal to the size of the model before the change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * The second argument is in terms of the model after the change and must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * be less than the size of the model after the change. For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * if you have a 5-row model and add 3 items to the end of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * the indices are 5, 7.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * You normally do not call this method.  This method is public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * to allow view classes to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param firstRow the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param endRow the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @throws IndexOutOfBoundsException if either argument is invalid, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *         <code>firstRow</code> &gt; <code>endRow</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public abstract void rowsInserted(int firstRow, int endRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Invoked when rows have been deleted from the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * in the specified range (inclusive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * The arguments give the indices of the effected range and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * are in terms of the model <b>before</b> the change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * For example, if you have a 5-row model and delete 3 items from the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * of the model the indices are 2, 4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * You normally do not call this method.  This method is public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * to allow view classes to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param firstRow the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @param endRow the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @throws IndexOutOfBoundsException if either argument is outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *         the range of the model before the change, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *         <code>firstRow</code> &gt; <code>endRow</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public abstract void rowsDeleted(int firstRow, int endRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * Invoked when rows have been changed in the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * between the specified range (inclusive).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * You normally do not call this method.  This method is public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * to allow view classes to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param firstRow the first row, in terms of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param endRow the last row, in terms of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @throws IndexOutOfBoundsException if either argument is outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *         the range of the underlying model, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *         <code>firstRow</code> &gt; <code>endRow</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public abstract void rowsUpdated(int firstRow, int endRow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * Invoked when the column in the rows have been updated in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * the underlying model between the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * You normally do not call this method.  This method is public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * to allow view classes to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param firstRow the first row, in terms of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param endRow the last row, in terms of the underlying model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @param column the column that has changed, in terms of the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *        model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @throws IndexOutOfBoundsException if either argument is outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *         the range of the underlying model after the change,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *         <code>firstRow</code> &gt; <code>endRow</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *         <code>column</code> is outside the range of the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *          model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public abstract void rowsUpdated(int firstRow, int endRow, int column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * Adds a <code>RowSorterListener</code> to receive notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * about this <code>RowSorter</code>.  If the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * listener is added more than once it will receive multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * notifications.  If <code>l</code> is <code>null</code> nothing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param l the <code>RowSorterListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void addRowSorterListener(RowSorterListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        listenerList.add(RowSorterListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * Removes a <code>RowSorterListener</code>.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <code>l</code> is <code>null</code> nothing is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param l the <code>RowSorterListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public void removeRowSorterListener(RowSorterListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        listenerList.remove(RowSorterListener.class, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * Notifies listener that the sort order has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    protected void fireSortOrderChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        fireRowSorterChanged(new RowSorterEvent(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Notifies listener that the mapping has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param lastRowIndexToModel the mapping from model indices to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *        view indices prior to the sort, may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    protected void fireRowSorterChanged(int[] lastRowIndexToModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        fireRowSorterChanged(new RowSorterEvent(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                RowSorterEvent.Type.SORTED, lastRowIndexToModel));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    void fireRowSorterChanged(RowSorterEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        Object[] listeners = listenerList.getListenerList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            if (listeners[i] == RowSorterListener.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                ((RowSorterListener)listeners[i + 1]).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                        sorterChanged(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * SortKey describes the sort order for a particular column.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * column index is in terms of the underlying model, which may differ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * from that of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public static class SortKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        private int column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        private SortOrder sortOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         * Creates a <code>SortKey</code> for the specified column with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * the specified sort order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * @param column index of the column, in terms of the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * @param sortOrder the sorter order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         * @throws IllegalArgumentException if <code>sortOrder</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         *         <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        public SortKey(int column, SortOrder sortOrder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            if (sortOrder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                        "sort order must be non-null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            this.column = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            this.sortOrder = sortOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * Returns the index of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * @return index of column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        public final int getColumn() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         * Returns the sort order of the column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
         * @return the sort order of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        public final SortOrder getSortOrder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return sortOrder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         * Returns the hash code for this <code>SortKey</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * @return hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            int result = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            result = 37 * result + column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            result = 37 * result + sortOrder.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * Returns true if this object equals the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * If the specified object is a <code>SortKey</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * references the same column and sort order, the two objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
         * @param o the object to compare to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
         * @return true if <code>o</code> is equal to this <code>SortKey</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        public boolean equals(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (o == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            if (o instanceof SortKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                return (((SortKey)o).column == column &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        ((SortKey)o).sortOrder == sortOrder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
}