Search in sources :

Example 1 with SortKey

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;
}
Also used : RowSorter(javax.swing.RowSorter) List(java.util.List) SortKey(javax.swing.RowSorter.SortKey)

Example 2 with SortKey

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);
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) IntStream(java.util.stream.IntStream) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) SortKey(javax.swing.RowSorter.SortKey) CoreMatchers.not(org.hamcrest.CoreMatchers.not) HashMap(java.util.HashMap) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) Arrays.asList(java.util.Arrays.asList) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) ExpectedException(org.junit.rules.ExpectedException) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Before(org.junit.Before) Functor(org.apache.jorphan.reflect.Functor) Collections.emptyList(java.util.Collections.emptyList) Test(org.junit.Test) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) ErrorCollector(org.junit.rules.ErrorCollector) SortOrder(javax.swing.SortOrder) AbstractMap(java.util.AbstractMap) List(java.util.List) Rule(org.junit.Rule) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) SortKey(javax.swing.RowSorter.SortKey) Test(org.junit.Test)

Example 3 with SortKey

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);
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) SortKey(javax.swing.RowSorter.SortKey) Test(org.junit.Test)

Example 4 with SortKey

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);
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) SortKey(javax.swing.RowSorter.SortKey) Test(org.junit.Test)

Example 5 with SortKey

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);
}
Also used : SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) SortKey(javax.swing.RowSorter.SortKey) Test(org.junit.Test)

Aggregations

SortKey (javax.swing.RowSorter.SortKey)16 Test (org.junit.Test)10 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)9 ArrayList (java.util.ArrayList)6 List (java.util.List)4 RowSorter (javax.swing.RowSorter)3 SortOrder (javax.swing.SortOrder)3 HashMap (java.util.HashMap)2 RowSorterEvent (javax.swing.event.RowSorterEvent)2 RowSorterListener (javax.swing.event.RowSorterListener)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 String.format (java.lang.String.format)1 AbstractMap (java.util.AbstractMap)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Comparator (java.util.Comparator)1