bug fix [ 1585369 ] CTable sorting is TOO LAZY

This commit is contained in:
teo_sarca 2007-01-29 08:36:26 +00:00
parent d32428739b
commit c7d5c58609
2 changed files with 37 additions and 6 deletions

View File

@ -41,7 +41,11 @@ public class CTable extends JTable
{
super(new DefaultTableModel());
setColumnSelectionAllowed(false);
/* ARHIPAC: TEO: BEGIN: ORIGINAL: @arhipac.tools.annotation.Bug(228) -------------------------------------------- *
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
/* ARHIPAC: TEO: BEGIN: MODIFIED: @arhipac.tools.annotation.Bug(228) ------------------------------------------- */
setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
/* ARHIPAC: TEO: BEGIN: END: @arhipac.tools.annotation.Bug(228) --------------------------------------------------- */
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
getTableHeader().addMouseListener(new CTableMouseListener());
setSurrendersFocusOnKeystroke(true);
@ -222,6 +226,7 @@ public class CTable extends JTable
DefaultTableModel model = (DefaultTableModel)getModel();
MSort sort = new MSort(0, null);
sort.setSortAsc(p_asc);
/* ARHIPAC: teo_sarca: BEGIN: ORIGINAL: @arhipac.tools.annotation.Bug(226) ----------------------------------- *
// while something to sort
sorting:
while (true)
@ -251,7 +256,24 @@ public class CTable extends JTable
// log.config("done");
break;
} // while something to sort
/* ARHIPAC: teo_sarca: MODIFIED: @arhipac.tools.annotation.Bug(226) -------------------------------------------- */
// This comparator is used to sort vectors of data
class ColumnSorter<T> implements Comparator<T> {
int colIndex;
MSort sort;
ColumnSorter(int colIndex, MSort sort) {
this.colIndex = colIndex;
this.sort = sort;
}
public int compare(Object o1, Object o2) {
Object item1 = ((Vector)o1).get(this.colIndex);
Object item2 = ((Vector)o2).get(this.colIndex);
return this.sort.compare(item1, item2);
}
};
Collections.sort(model.getDataVector(), new ColumnSorter<Object>(modelColumnIndex, sort));
/* ARHIPAC: teo_sarca: END: @arhipac.tools.annotation.Bug(226) ---------------------------------------------------- */
// selection
clearSelection();
if (selected != null)
@ -261,6 +283,7 @@ public class CTable extends JTable
if (selected.equals(getValueAt(r, selCol)))
{
setRowSelectionInterval(r,r);
scrollRectToVisible(getCellRect(r, modelColumnIndex, true)); // @arhipac.tools.annotation.Bug(226)
break;
}
}

View File

@ -70,7 +70,7 @@ public final class MSort implements Comparator, Serializable
public int compare (Object o1, Object o2)
{
// Get Objects to compare
Object cmp1 = null;
Object cmp1 = o1; // @arhipac.tools.annotation.Bug(226)
if (o1 instanceof MSort)
cmp1 = ((MSort)o1).data;
if (cmp1 instanceof NamePair)
@ -87,10 +87,10 @@ public final class MSort implements Comparator, Serializable
{
if (cmp2 == null)
return 0;
return -1;
return -1 * m_multiplier; // @arhipac.tools.annotation.Bug(226)
}
if (cmp2 == null)
return 1;
return 1 * m_multiplier; // @arhipac.tools.annotation.Bug(226)
/**
* compare different data types
@ -100,7 +100,7 @@ public final class MSort implements Comparator, Serializable
if (cmp1 instanceof String && cmp2 instanceof String)
{
String s = (String)cmp1;
return s.compareTo((String)cmp2) * m_multiplier;
return s.compareToIgnoreCase((String)cmp2) * m_multiplier; // @arhipac.tools.annotation.Bug(226)
}
// Date
else if (cmp1 instanceof Timestamp && cmp2 instanceof Timestamp)
@ -120,10 +120,18 @@ public final class MSort implements Comparator, Serializable
Integer d = (Integer)cmp1;
return d.compareTo((Integer)cmp2) * m_multiplier;
}
/* ARHIPAC: TEO: BEGIN: @arhipac.tools.annotation.Bug(226) ------------------------------ */
// Double
else if (cmp1 instanceof Double && cmp2 instanceof Double)
{
Double d = (Double)cmp1;
return d.compareTo((Double)cmp2) * m_multiplier;
}
/* ARHIPAC: TEO: END: @arhipac.tools.annotation.Bug(226) -------------------------------- */
// Convert to string value
String s = cmp1.toString();
return s.compareTo(cmp2.toString()) * m_multiplier;
return s.compareToIgnoreCase(cmp2.toString()) * m_multiplier; // @arhipac.tools.annotation.Bug(226)
} // compare
/**