下面列出了javax.swing.RowSorter.SortKey#getSortOrder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private boolean isSameSorter(List<? extends SortKey> sortKeys1,
List<? extends SortKey> sortKeys2) {
int size1 = (sortKeys1 == null) ? 0 : sortKeys1.size();
int size2 = (sortKeys2 == null) ? 0 : sortKeys2.size();
if ((size1 == 0) && (size2 == 0)) {
return true;
}
if ((sortKeys1 == null) && (sortKeys2 == null))
return true;
if ((sortKeys1 == null) || (sortKeys2 == null))
return false;
if (size1 != size2)
return false;
for (int i = 0; i < size1; i++) {
SortKey sortKey1 = sortKeys1.get(i);
SortKey sortKey2 = sortKeys2.get(i);
if ((sortKey1.getColumn() != sortKey2.getColumn())
|| (sortKey1.getSortOrder() != sortKey2.getSortOrder())) {
return false;
}
}
return true;
}
@Override
public void valueChanged(final ListSelectionEvent e) {
// fix for issue 478 - no animations when sorter has changed
List<? extends SortKey> sortKeys = (table.getRowSorter() == null) ? null
: table.getRowSorter().getSortKeys();
boolean isDifferentSorter = !isSameSorter(sortKeys, oldSortKeys);
if (e.getValueIsAdjusting() && isDifferentSorter)
return;
if (sortKeys == null) {
oldSortKeys = null;
} else {
oldSortKeys = new ArrayList<>();
for (SortKey sortKey : sortKeys) {
SortKey copy = new SortKey(sortKey.getColumn(), sortKey.getSortOrder());
oldSortKeys.add(copy);
}
}
syncSelection(isDifferentSorter);
}
@Override
public Icon getIcon() {
int modelCol = header.getTable().convertColumnIndexToModel(curCol);
TableModel model = header.getTable().getModel();
if (model instanceof ExtendedJTableSorterModel) {
ExtendedJTableSorterModel sortModel = (ExtendedJTableSorterModel) model;
switch (sortModel.getSortingStatus(modelCol)) {
case ExtendedJTableSorterModel.ASCENDING:
return UIManager.getIcon("Table.ascendingSortIcon");
case ExtendedJTableSorterModel.DESCENDING:
return UIManager.getIcon("Table.descendingSortIcon");
case ExtendedJTableSorterModel.NOT_SORTED:
default:
return null;
}
} else {
SortKey sortKey = getSortKey(header.getTable().getRowSorter(), modelCol);
SortOrder sortOrder = sortKey != null ? sortKey.getSortOrder() : SortOrder.UNSORTED;
switch (sortOrder) {
case ASCENDING:
return UIManager.getIcon("Table.ascendingSortIcon");
case DESCENDING:
return UIManager.getIcon("Table.descendingSortIcon");
case UNSORTED:
default:
return null;
}
}
}
/**
* Overloaded to return an icon suitable to the primary sorted column, or null if
* the column is not the primary sort key.
*
* @param table the <code>JTable</code>.
* @param column the column index.
* @return the sort icon, or null if the column is unsorted.
*/
protected Icon getIcon(JTable table, int column) {
SortKey sortKey = getSortKey(table, column);
if (sortKey != null && table.convertColumnIndexToView(sortKey.getColumn()) == column) {
switch (sortKey.getSortOrder()) {
case ASCENDING:
return UIManager.getIcon("Table.ascendingSortIcon");
case DESCENDING:
return UIManager.getIcon("Table.descendingSortIcon");
}
}
return null;
}