Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views In directory usw-pr-cvs1:/tmp/cvs-serv15127 Modified Files: TableClickSorter.java AllocTableClickSorter.java AllocHistogramTableModel.java AllocHistogramTable.java Log Message: sorting finished Index: TableClickSorter.java =================================================================== RCS file: /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views/TableClickSorter.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** TableClickSorter.java 17 Aug 2002 19:13:05 -0000 1.3 --- TableClickSorter.java 18 Aug 2002 19:38:56 -0000 1.4 *************** *** 51,58 **** */ public class TableClickSorter extends TableMap { ! private int indexes[] = null; ! private int usedCount = 0; //number uf used buckets in the indexes[] private final LinkedList sortingColumns = new LinkedList(); ! private boolean ascendColumns[] = null; /** Creates a new instance of TableClickSorter */ --- 51,60 ---- */ public class TableClickSorter extends TableMap { ! private int indexes[] = null; ! private int usedCount = 0; //number uf used buckets in the indexes[] private final LinkedList sortingColumns = new LinkedList(); ! private boolean ascendColumns[] = null; ! private int allwaysSortBy; ! private boolean allwaysSortAscend = true; /** Creates a new instance of TableClickSorter */ *************** *** 75,80 **** } - /** Attention when use this, you need care about synchronization. - */ public void setModel(TableModel model) { super.setModel(model); --- 77,80 ---- *************** *** 133,154 **** //---------------- SORTING ! public synchronized void sort() { ! //PENDING super.tableChanged( new TableModelEvent(this) ); } ! /**Comparator interface, it compares rows in the table. */ ! public int compare( Object v1, Object v2 ) { ! ! //PENDING return 0; } /** This method is used by compare() for comparsion of objects in the cells. ! * Override this to add comparsion for new class. */ ! public int compareObjs( Object o1, Object o2 ) { // If both values are null, return 0. --- 133,175 ---- //---------------- SORTING ! /**Sort table according actual sorting settings. Use <code> sortByColumn() </code> or ! * <code> setAllwaysSortBy()</code> to the settings. ! *@see #setAllwaysSortBy(int) ! *@see #sortByColumn(int) ! */ public synchronized void sort() { ! int[] aux = new int[indexes.length]; ! mergeSort( indexes, aux, 0, indexes.length - 1 ); super.tableChanged( new TableModelEvent(this) ); } ! /** Compares rows in the model. ! * use: compare( indexes[i], indexes[j] ) */ ! protected int compare( int row1, int row2 ) { ! int result, i; ! int col; ! Object o1, o2; ! ! for( i = 0; i<sortingColumns.size(); i++ ) { ! col = ((Integer) sortingColumns.get( i )).intValue(); ! o1 = model.getValueAt(row1, col); ! o2 = model.getValueAt(row2, col); ! result = compareObjs( o1, o2 ) * (ascendColumns[col] ? 1 :-1); ! if (result != 0) ! return result; ! } ! if ( allwaysSortBy != -1 ) { ! o1 = model.getValueAt(row1, allwaysSortBy); ! o2 = model.getValueAt(row2, allwaysSortBy); ! result = compareObjs( o1, o2 ) * (allwaysSortAscend ? 1 :-1); ! } return 0; } /** This method is used by compare() for comparsion of objects in the cells. ! * override this to add comparsion for new class. */ ! protected int compareObjs( Object o1, Object o2 ) { // If both values are null, return 0. *************** *** 210,217 **** } ! public void sortByColumn( int column ) { sortByColumn( column, ascendColumns[ column ] ); } public synchronized void sortByColumn( int column, boolean ascending ) { Integer col = new Integer( column ); --- 231,249 ---- } ! /** Sorts table by given column in stored order. Default order is asceding, this ! * could by changed by <code> SortByColumn(int, boolean) </code>. ! * ! *@see #sort() ! *@see #setAllwaysSortBy(int) ! */ ! public synchronized void sortByColumn( int column ) { sortByColumn( column, ascendColumns[ column ] ); } + /** Sorts table by given column in given order. + * + *@see #sort() + *@see #setAllwaysSortBy(int) + */ public synchronized void sortByColumn( int column, boolean ascending ) { Integer col = new Integer( column ); *************** *** 226,230 **** } ! //---------------- handling events from TableModel listener --- 258,310 ---- } ! ! /** Sets the column that will be used for distinction of rows if values in sorting column ! * equals. ! * ! *@see #sortByColumn(int) ! *@see #setAllwaysSortBy(int,boolean) ! */ ! public void setAllwaysSortBy( int column ) { ! allwaysSortBy = column; ! } ! ! /** Sets the column that will be used for distinction of rows if values in sorting column ! * equals. ! * ! *@see #sortByColumn(int) ! *@see #setAllwaysSortBy(int) ! */ ! public void setAllwaysSortBy( int column, boolean asceding ) { ! allwaysSortBy = column; ! allwaysSortAscend = asceding; ! } ! ! ! /**Gets the column that will be used for distinction of rows if values in sortin column ! * equals. ! * ! *@see #sortByColumn(int) ! *@see #setAllwaysSortBy(int) ! */ ! public int getAllwaysSortBy() { ! return allwaysSortBy; ! } ! ! /**Gets asceding for the column from <code> getAllwaysSortBy </code>*/ ! public boolean getAllwaysAscend() { ! return allwaysSortAscend; ! } ! ! /**Returns ascending order for given column. True = asceding, false = desceding. ! */ ! protected boolean getAscending( int column ) { ! return ascendColumns[column]; ! } ! ! /**Sets ascending order for given column. True = asceding, false = desceding. ! */ ! protected void setAscending( int column, boolean asceding ) { ! ascendColumns[column] = asceding; ! } //---------------- handling events from TableModel listener *************** *** 293,296 **** --- 373,418 ---- private synchronized int preferedArraySize( int size ) { return (int) Math.ceil( Math.pow( 2, Math.log(size)/Math.log(2) )); + } + + //-------- mergesort + //sorts src using aux + private synchronized void mergeSort( int[] src, int[] aux, int lo, int hi ) { + if( lo > hi ) + throw new RuntimeException("Mergesort: low index is grater than high index. lo: " + lo +" hi:" + hi); + int len = hi - lo + 1; + + if (len < 7 ) { //FIX + for (int i=lo; i<=hi; i++) + for (int j=i; j>lo && compare(src[j-1], src[j])>0; j--) { + int tmp = src[j]; + src[j] = src[j-1]; + src[j-1] = tmp; + } + return; + } + + int mid = (lo + hi) >> 1; + mergeSort( src, aux, lo, mid ); + mergeSort( src, aux, mid+1, hi ); + + //array is already sorted + if ( compare(src[mid], src[mid+1] ) <= 0) { + return; + } + + //merge + int a = lo, b = mid+1, c = lo; + while ((a <= mid) && (b <= hi)){ + if ( compare(src[a], src[b]) < 0 ) + aux[c++]=src[a++]; + else + aux[c++]=src[b++]; + } + while (a <= mid) + aux[c++]=src[a++]; + while (b <= hi) + aux[c++]=src[b++]; + + System.arraycopy(aux, lo, src, lo, len); } } Index: AllocTableClickSorter.java =================================================================== RCS file: /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views/AllocTableClickSorter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** AllocTableClickSorter.java 16 Aug 2002 13:09:27 -0000 1.2 --- AllocTableClickSorter.java 18 Aug 2002 19:38:56 -0000 1.3 *************** *** 28,32 **** * (Actually it sorts only indexes mapping to TableModel). The differnce is that * AllocTableClickSorter can sort AllocStat objects therefore you have to you use this with ! * AllocHistogramTable and AllocHistogramModel. * * --- 28,35 ---- * (Actually it sorts only indexes mapping to TableModel). The differnce is that * AllocTableClickSorter can sort AllocStat objects therefore you have to you use this with ! * AllocHistogramTable and AllocHistogramModel. ! * This class also changes default asceding order. ! * Columns with strings are sorted in asceding order other in desceding order. ! * Model is allways sorted by first column with string {@link TableClickSorter#setAllwaysSortBy(int) } * * *************** *** 39,45 **** public AllocTableClickSorter( TableModel model ) { super( model ); } ! public int compareObjs(Object o1, Object o2) { if (o1 == null && o2 == null) return 0; --- 42,56 ---- public AllocTableClickSorter( TableModel model ) { super( model ); + initSorting(); } ! ! public void setModel( TableModel model ) { ! super.setModel( model ); ! initSorting(); ! } ! /** Compares objects, it adds comparsion for instances of the classes that implement AllocStat interface ! */ ! protected int compareObjs(Object o1, Object o2) { if (o1 == null && o2 == null) return 0; *************** *** 61,64 **** --- 72,90 ---- return super.compareObjs( o1, o2 ); + } + + //--------------- private + private void initSorting() { + boolean first = true; + for (int i=0; i < getColumnCount(); i++ ) { + Class clazz = getColumnClass(i); + if ( clazz == String.class ) { + setAscending( i, true ); + if ( first ) + setAllwaysSortBy( i, true ); + } + else + setAscending( i, false ); + } } Index: AllocHistogramTableModel.java =================================================================== RCS file: /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views/AllocHistogramTableModel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -r1.7 -r1.8 *** AllocHistogramTableModel.java 17 Aug 2002 19:06:14 -0000 1.7 --- AllocHistogramTableModel.java 18 Aug 2002 19:38:56 -0000 1.8 *************** *** 27,31 **** /**Model for table that shows instances count and "histogram" of instances count. ! * Columns contains name_of_type, instaces_count, count_of_all_instances_ever_created_in_VM, * histogram_of_instances_count, size_of_instances, size_off_all_instances_ever_created_in_VM * --- 27,31 ---- /**Model for table that shows instances count and "histogram" of instances count. ! * Columns contain name_of_type, instaces_count, count_of_all_instances_ever_created_in_VM, * histogram_of_instances_count, size_of_instances, size_off_all_instances_ever_created_in_VM * *************** *** 173,177 **** //subcribing, unsubscribing ! protected void subscribeToJpi( List allocStats, HasChildren parent, int subscribeType ) { this.parent = parent; this.subscribeType = subscribeType; --- 173,177 ---- //subcribing, unsubscribing ! private void subscribeToJpi( List allocStats, HasChildren parent, int subscribeType ) { this.parent = parent; this.subscribeType = subscribeType; *************** *** 183,187 **** } ! protected void unsubscribeFromJpi() { parent.removeChildrenListener( subscribeType, childrenListener ); ListIterator iter = allocStats.listIterator(); --- 183,187 ---- } ! private void unsubscribeFromJpi() { parent.removeChildrenListener( subscribeType, childrenListener ); ListIterator iter = allocStats.listIterator(); Index: AllocHistogramTable.java =================================================================== RCS file: /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/views/AllocHistogramTable.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -r1.8 -r1.9 *** AllocHistogramTable.java 16 Aug 2002 13:06:39 -0000 1.8 --- AllocHistogramTable.java 18 Aug 2002 19:38:56 -0000 1.9 *************** *** 23,26 **** --- 23,27 ---- import java.awt.*; import javax.swing.*; + import javax.swing.event.*; import javax.swing.table.*; import javax.swing.border.*; *************** *** 74,78 **** super.setModel( dataModel ); } ! protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); --- 75,84 ---- super.setModel( dataModel ); } ! ! public void tableChanged( TableModelEvent e) { ! super.tableChanged(e); ! } ! //---------- renderers ! protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); *************** *** 201,204 **** } //end of Renderers ! } --- 207,210 ---- } //end of Renderers ! } |