src/share/classes/sun/tools/jconsole/inspector/TableSorter.java

Print this page




 129         // It's this new editor that wil be cancelled here, if needed.
 130         //
 131         if (attrs != null && attrs.isEditing())
 132             attrs.cancelCellEditing();
 133 
 134         // remove registered listeners
 135         removeListeners();
 136         // do the sort
 137 
 138         if (JConsole.isDebug()) {
 139             System.err.println("sorting table against column="+column
 140                     +" ascending="+isAscending);
 141         }
 142         quickSort(0,getRowCount()-1,column,isAscending);
 143         // restore registered listeners
 144         restoreListeners();
 145 
 146         // update row heights in XMBeanAttributes (required by expandable cells)
 147         if (attrs != null) {
 148             for (int i = 0; i < getRowCount(); i++) {
 149                 Vector<?> data = (Vector) dataVector.elementAt(i);
 150                 attrs.updateRowHeight(data.elementAt(1), i);
 151             }
 152         }
 153     }
 154 
 155     private boolean compareS(Object s1, Object s2, boolean isAscending) {
 156         if (isAscending)
 157             return (compare(s1,s2) > 0);
 158         else
 159             return (compare(s1,s2) < 0);
 160     }
 161 
 162     private boolean compareG(Object s1, Object s2, boolean isAscending) {
 163         if (isAscending)
 164             return (compare(s1,s2) < 0);
 165         else
 166             return (compare(s1,s2) > 0);
 167     }
 168 
 169     private void quickSort(int lo0,int hi0, int key, boolean isAscending) {


 200                                 --hi;
 201                             }
 202                     }
 203 
 204                                 /* If the right index has not reached the
 205                                  * left side of array
 206                                  * must now sort the left partition.
 207                                  */
 208                 if( lo0 < hi )
 209                     quickSort(lo0, hi , key, isAscending);
 210 
 211                                 /* If the left index has not reached the right
 212                                  * side of array
 213                                  * must now sort the right partition.
 214                                  */
 215                 if( lo <= hi0 )
 216                     quickSort(lo, hi0 , key, isAscending);
 217             }
 218     }
 219 

 220     private Vector<Object> getRow(int row) {
 221         return dataVector.elementAt(row);
 222     }
 223 
 224     @SuppressWarnings("unchecked")
 225     private void setRow(Vector<Object> data, int row) {
 226         dataVector.setElementAt(data,row);
 227     }
 228 
 229     private void swap(int i, int j, int column) {
 230         Vector<Object> data = getRow(i);
 231         setRow(getRow(j),i);
 232         setRow(data,j);
 233 
 234         int a = invertedIndex[i];
 235         invertedIndex[i] = invertedIndex[j];
 236         invertedIndex[j] = a;
 237     }
 238 
 239     public void sortByColumn(int column) {




 129         // It's this new editor that wil be cancelled here, if needed.
 130         //
 131         if (attrs != null && attrs.isEditing())
 132             attrs.cancelCellEditing();
 133 
 134         // remove registered listeners
 135         removeListeners();
 136         // do the sort
 137 
 138         if (JConsole.isDebug()) {
 139             System.err.println("sorting table against column="+column
 140                     +" ascending="+isAscending);
 141         }
 142         quickSort(0,getRowCount()-1,column,isAscending);
 143         // restore registered listeners
 144         restoreListeners();
 145 
 146         // update row heights in XMBeanAttributes (required by expandable cells)
 147         if (attrs != null) {
 148             for (int i = 0; i < getRowCount(); i++) {
 149                 Vector<?> data = dataVector.elementAt(i);
 150                 attrs.updateRowHeight(data.elementAt(1), i);
 151             }
 152         }
 153     }
 154 
 155     private boolean compareS(Object s1, Object s2, boolean isAscending) {
 156         if (isAscending)
 157             return (compare(s1,s2) > 0);
 158         else
 159             return (compare(s1,s2) < 0);
 160     }
 161 
 162     private boolean compareG(Object s1, Object s2, boolean isAscending) {
 163         if (isAscending)
 164             return (compare(s1,s2) < 0);
 165         else
 166             return (compare(s1,s2) > 0);
 167     }
 168 
 169     private void quickSort(int lo0,int hi0, int key, boolean isAscending) {


 200                                 --hi;
 201                             }
 202                     }
 203 
 204                                 /* If the right index has not reached the
 205                                  * left side of array
 206                                  * must now sort the left partition.
 207                                  */
 208                 if( lo0 < hi )
 209                     quickSort(lo0, hi , key, isAscending);
 210 
 211                                 /* If the left index has not reached the right
 212                                  * side of array
 213                                  * must now sort the right partition.
 214                                  */
 215                 if( lo <= hi0 )
 216                     quickSort(lo, hi0 , key, isAscending);
 217             }
 218     }
 219 
 220     @SuppressWarnings("unchecked")
 221     private Vector<Object> getRow(int row) {
 222         return dataVector.elementAt(row);
 223     }
 224 
 225     @SuppressWarnings("unchecked")
 226     private void setRow(Vector<Object> data, int row) {
 227         dataVector.setElementAt(data,row);
 228     }
 229 
 230     private void swap(int i, int j, int column) {
 231         Vector<Object> data = getRow(i);
 232         setRow(getRow(j),i);
 233         setRow(data,j);
 234 
 235         int a = invertedIndex[i];
 236         invertedIndex[i] = invertedIndex[j];
 237         invertedIndex[j] = a;
 238     }
 239 
 240     public void sortByColumn(int column) {