jdk/src/share/classes/sun/tools/jconsole/inspector/TableSorter.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 55 5ecee29e98d8
child 1017 8d24d37ceed8
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 55
diff changeset
     2
 * Copyright 2004-2008 Sun Microsystems, Inc.  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
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
 */
55
5ecee29e98d8 6655515: MBeans tab: operation return values of type Component displayed as String
lmalvent
parents: 2
diff changeset
    25
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.tools.jconsole.inspector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.table.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
// Imports for picking up mouse events from the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.event.MouseAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.JTable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.table.JTableHeader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.table.TableColumnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
@SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class TableSorter extends DefaultTableModel implements MouseListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private boolean ascending = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private TableColumnModel columnModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    private JTable tableView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private Vector<TableModelListener> listenerList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private int sortColumn = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private int[] invertedIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public TableSorter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        listenerList = new Vector<TableModelListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public TableSorter(Object[] columnNames, int numRows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super(columnNames,numRows);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        listenerList = new Vector<TableModelListener>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public void newDataAvailable(TableModelEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        super.newDataAvailable(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        invertedIndex = new int[getRowCount()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        for (int i=0;i<invertedIndex.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            invertedIndex[i] = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        sort(this.sortColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public void addTableModelListener(TableModelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        listenerList.add(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super.addTableModelListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public void removeTableModelListener(TableModelListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        listenerList.remove(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        super.removeTableModelListener(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private void removeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        for(TableModelListener tnl : listenerList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            super.removeTableModelListener(tnl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private void restoreListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        for(TableModelListener tnl : listenerList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            super.addTableModelListener(tnl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    @SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public int compare(Object o1, Object o2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if (o1==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (o2==null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        //two object of the same class and that are comparable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        else if ((o1.getClass().equals(o2.getClass())) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                 (o1 instanceof Comparable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return (((Comparable) o1).compareTo(o2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            return o1.toString().compareTo(o2.toString());
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
    public void sort(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // remove registered listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        removeListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // do the sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        //n2sort(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        quickSort(0,getRowCount()-1,column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // restore registered listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        restoreListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this.sortColumn = column;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // update row heights in XMBeanAttributes (required by expandable cells)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (tableView instanceof XMBeanAttributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            XMBeanAttributes attrs = (XMBeanAttributes) tableView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            for (int i = 0; i < getRowCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                Vector data = (Vector) dataVector.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                attrs.updateRowHeight(data.elementAt(1), i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private synchronized boolean compareS(Object s1, Object s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        if (ascending)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            return (compare(s1,s2) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            return (compare(s1,s2) < 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private synchronized boolean compareG(Object s1, Object s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        if (ascending)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return (compare(s1,s2) < 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return (compare(s1,s2) > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private synchronized void quickSort(int lo0,int hi0, int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        int lo = lo0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        int hi = hi0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        Object mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if ( hi0 > lo0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                mid = getValueAt( ( lo0 + hi0 ) / 2 , key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                while( lo <= hi )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                        /* find the first element that is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                         * or equal to the partition element starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                         * from the left Index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        while( ( lo < hi0 ) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                               ( compareS(mid,getValueAt(lo,key)) ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                            ++lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                        /* find an element that is smaller than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                         * the partition element starting from the right Index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                        while( ( hi > lo0 ) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                               ( compareG(mid,getValueAt(hi,key)) ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                            --hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        // if the indexes have not crossed, swap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                        if( lo <= hi )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                                swap(lo, hi, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                ++lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                --hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                /* If the right index has not reached the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                 * left side of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                 * must now sort the left partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                if( lo0 < hi )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    quickSort(lo0, hi , key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                /* If the left index has not reached the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                 * side of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                 * must now sort the right partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if( lo <= hi0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    quickSort(lo, hi0 , key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public void n2sort(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        for (int i = 0; i < getRowCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            for (int j = i+1; j < getRowCount(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                if (compare(getValueAt(i,column),getValueAt(j,column)) == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    swap(i, j, column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private Vector getRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return (Vector) dataVector.elementAt(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    @SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    private void setRow(Vector data, int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        dataVector.setElementAt(data,row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public void swap(int i, int j, int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        Vector data = getRow(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        setRow(getRow(j),i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        setRow(data,j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        int a = invertedIndex[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        invertedIndex[i] = invertedIndex[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        invertedIndex[j] = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public void sortByColumn(int column) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        sortByColumn(column, !ascending);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public void sortByColumn(int column, boolean ascending) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        this.ascending = ascending;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        sort(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public int[] getInvertedIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return invertedIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    // Add a mouse listener to the Table to trigger a table sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    // when a column heading is clicked in the JTable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public void addMouseListenerToHeaderInTable(JTable table) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        tableView = table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        columnModel = tableView.getColumnModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        JTableHeader th = tableView.getTableHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        th.addMouseListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public void mouseClicked(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        int viewColumn = columnModel.getColumnIndexAtX(e.getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        int column = tableView.convertColumnIndexToModel(viewColumn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (e.getClickCount() == 1 && column != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            tableView.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            sortByColumn(column);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            tableView.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            tableView.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void mousePressed(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void mouseReleased(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
}