Java Code Examples for javax.swing.RowSorter.SortKey#getColumn()

The following examples show how to use javax.swing.RowSorter.SortKey#getColumn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SubstanceTableUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example 2
Source File: SubstanceTableUI.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
}
 
Example 3
Source File: SortableTableHeaderRenderer.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    c.setBackground(Constants.DS_BACK);
    DefaultTableCellRenderer r = ((DefaultTableCellRenderer) c);
    r.setText("<html><b>" + r.getText() + "</b></html>");
    try {
        List<? extends SortKey> sortKeys = table.getRowSorter().getSortKeys();
        SortKey key = sortKeys.get(0);
        if (column == key.getColumn()) {
            r.setIcon(key.getSortOrder() == SortOrder.ASCENDING ? ascIcon : descIcon);
        } else {
            r.setIcon(null);
        }
    } catch (Exception e) {
        r.setIcon(null);
    }
    return r;
}
 
Example 4
Source File: TableHeaderUI.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Tries to return the sort key for the given column.
 *
 * @param sorter
 * @param column
 * @return the sort key or {@code null}
 */
private SortKey getSortKey(RowSorter<? extends TableModel> sorter, int column) {
	if (sorter == null) {
		return null;
	}

	for (Object sortObj : sorter.getSortKeys()) {
		SortKey key = (SortKey) sortObj;
		if (key.getColumn() == column) {
			return key;
		}
	}
	return null;
}