use of javax.swing.RowSorter.SortKey in project smile by haifengl.
the class DefaultTableHeaderCellRenderer method getSortKey.
/**
* Returns the current sort key, or null if the column is unsorted.
*
* @param table the table
* @param column the column index
* @return the SortKey, or null if the column is unsorted
*/
@SuppressWarnings("rawtypes")
protected SortKey getSortKey(JTable table, int column) {
RowSorter rowSorter = table.getRowSorter();
if (rowSorter == null) {
return null;
}
List sortedColumns = rowSorter.getSortKeys();
if (!sortedColumns.isEmpty()) {
return (SortKey) sortedColumns.get(0);
}
return null;
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method customKeyOrder.
@Test
public void customKeyOrder() {
HashMap<String, Integer> customKeyOrder = asList("a", "c", "b", "d").stream().reduce(new HashMap<String, Integer>(), (map, key) -> {
map.put(key, map.size());
return map;
}, (a, b) -> a);
Comparator<String> customKeyComparator = (a, b) -> customKeyOrder.get(a).compareTo(customKeyOrder.get(b));
sorter.setValueComparator(0, customKeyComparator).setSortKey(new SortKey(0, SortOrder.ASCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(a3(), c1(), b2(), d4());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method fixLastRowWithAscendingKey.
@Test
public void fixLastRowWithAscendingKey() {
sorter.fixLastRow().setSortKey(new SortKey(0, SortOrder.ASCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(a3(), b2(), d4(), c1());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method fixLastRowWithDescendingValue.
@Test
public void fixLastRowWithDescendingValue() {
sorter.fixLastRow().setSortKey(new SortKey(1, SortOrder.DESCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(d4(), a3(), b2(), c1());
assertRowOrderAndIndexes(expected);
}
use of javax.swing.RowSorter.SortKey in project jmeter by apache.
the class ObjectTableSorterTest method sortKeyDescending.
@Test
public void sortKeyDescending() {
sorter.setSortKey(new SortKey(0, SortOrder.DESCENDING));
List<SimpleImmutableEntry<String, Integer>> expected = asList(d4(), c1(), b2(), a3());
assertRowOrderAndIndexes(expected);
}
Aggregations