0N/A/*
2362N/A * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing.event;
0N/A
0N/Aimport javax.swing.RowSorter;
0N/A
0N/A/**
0N/A * <code>RowSorterEvent</code> provides notification of changes to
0N/A * a <code>RowSorter</code>. Two types of notification are possible:
0N/A * <ul>
0N/A * <li><code>Type.SORT_ORDER_CHANGED</code>: indicates the sort order has
0N/A * changed. This is typically followed by a notification of:
0N/A * <li><code>Type.SORTED</code>: indicates the contents of the model have
0N/A * been transformed in some way. For example, the contents may have
0N/A * been sorted or filtered.
0N/A * </ul>
0N/A *
0N/A * @see javax.swing.RowSorter
0N/A * @since 1.6
0N/A */
0N/Apublic class RowSorterEvent extends java.util.EventObject {
0N/A private Type type;
0N/A private int[] oldViewToModel;
0N/A
0N/A /**
0N/A * Enumeration of the types of <code>RowSorterEvent</code>s.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A public enum Type {
0N/A /**
0N/A * Indicates the sort order has changed.
0N/A */
0N/A SORT_ORDER_CHANGED,
0N/A
0N/A /**
0N/A * Indicates the contents have been newly sorted or
0N/A * transformed in some way.
0N/A */
0N/A SORTED
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>RowSorterEvent</code> of type
0N/A * <code>SORT_ORDER_CHANGED</code>.
0N/A *
0N/A * @param source the source of the change
0N/A * @throws IllegalArgumentException if <code>source</code> is
0N/A * <code>null</code>
0N/A */
0N/A public RowSorterEvent(RowSorter source) {
0N/A this(source, Type.SORT_ORDER_CHANGED, null);
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>RowSorterEvent</code>.
0N/A *
0N/A * @param source the source of the change
0N/A * @param type the type of event
0N/A * @param previousRowIndexToModel the mapping from model indices to
0N/A * view indices prior to the sort, may be <code>null</code>
0N/A * @throws IllegalArgumentException if source or <code>type</code> is
0N/A * <code>null</code>
0N/A */
0N/A public RowSorterEvent(RowSorter source, Type type,
0N/A int[] previousRowIndexToModel) {
0N/A super(source);
0N/A if (type == null) {
0N/A throw new IllegalArgumentException("type must be non-null");
0N/A }
0N/A this.type = type;
0N/A this.oldViewToModel = previousRowIndexToModel;
0N/A }
0N/A
0N/A /**
0N/A * Returns the source of the event as a <code>RowSorter</code>.
0N/A *
0N/A * @return the source of the event as a <code>RowSorter</code>
0N/A */
0N/A public RowSorter getSource() {
0N/A return (RowSorter)super.getSource();
0N/A }
0N/A
0N/A /**
0N/A * Returns the type of event.
0N/A *
0N/A * @return the type of event
0N/A */
0N/A public Type getType() {
0N/A return type;
0N/A }
0N/A
0N/A /**
0N/A * Returns the location of <code>index</code> in terms of the
0N/A * model prior to the sort. This method is only useful for events
0N/A * of type <code>SORTED</code>. This method will return -1 if the
0N/A * index is not valid, or the locations prior to the sort have not
0N/A * been provided.
0N/A *
0N/A * @param index the index in terms of the view
0N/A * @return the index in terms of the model prior to the sort, or -1 if
0N/A * the location is not valid or the mapping was not provided.
0N/A */
0N/A public int convertPreviousRowIndexToModel(int index) {
0N/A if (oldViewToModel != null && index >= 0 &&
0N/A index < oldViewToModel.length) {
0N/A return oldViewToModel[index];
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of rows before the sort. This method is only
0N/A * useful for events of type <code>SORTED</code> and if the
0N/A * last locations have not been provided will return 0.
0N/A *
0N/A * @return the number of rows in terms of the view prior to the sort
0N/A */
0N/A public int getPreviousRowCount() {
0N/A return (oldViewToModel == null) ? 0 : oldViewToModel.length;
0N/A }
0N/A}