1
/* ========================================================================
2
* JCommon : a free general purpose class library for the Java(tm) platform
3
* ========================================================================
5
* (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
7
* Project Info: http://www.jfree.org/jcommon/index.html
9
* This library is free software; you can redistribute it and/or modify it
10
* under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This library is distributed in the hope that it will be useful, but
15
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
* License for more details.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25
* in the United States and other countries.]
27
* -----------------------
28
* SortableTableModel.java
29
* -----------------------
30
* (C) Copyright 2000-2005, by Object Refinery Limited;
32
* Original Author: David Gilbert (for Object Refinery Limited);
35
* $Id: SortableTableModel.java,v 1.5 2005/11/16 15:58:41 taqua Exp $
37
* Changes (from 26-Oct-2001)
38
* --------------------------
39
* 26-Oct-2001 : Changed package to com.jrefinery.ui.* (DG);
40
* 20-Nov-2001 : Made constructor protected (DG);
41
* 14-Oct-2002 : Fixed errors reported by Checkstyle (DG);
47
import javax.swing.table.AbstractTableModel;
50
* The base class for a sortable table model.
52
* @author David Gilbert
54
public abstract class SortableTableModel extends AbstractTableModel {
56
/** The column on which the data is sorted (-1 for no sorting). */
57
private int sortingColumn;
59
/** Indicates ascending (true) or descending (false) order. */
60
private boolean ascending;
63
* Constructs a sortable table model.
65
public SortableTableModel() {
66
this.sortingColumn = -1;
67
this.ascending = true;
71
* Returns the index of the sorting column, or -1 if the data is not sorted
74
* @return the column used for sorting.
76
public int getSortingColumn() {
77
return this.sortingColumn;
81
* Returns <code>true</code> if the data is sorted in ascending order, and
82
* <code>false</code> otherwise.
84
* @return <code>true</code> if the data is sorted in ascending order, and
85
* <code>false</code> otherwise.
87
public boolean isAscending() {
92
* Sets the flag that determines whether the sort order is ascending or
95
* @param flag the flag.
97
public void setAscending(final boolean flag) {
98
this.ascending = flag;
104
* @param column the column to sort on (zero-based index).
105
* @param ascending a flag to indicate ascending order or descending order.
107
public void sortByColumn(final int column, final boolean ascending) {
108
if (isSortable(column)) {
109
this.sortingColumn = column;
114
* Returns a flag indicating whether or not a column is sortable.
116
* @param column the column (zero-based index).
120
public boolean isSortable(final int column) {