Java Code Examples for javax.swing.RowSorter#getSortKeys()
The following examples show how to use
javax.swing.RowSorter#getSortKeys() .
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: TableState.java From constellation with Apache License 2.0 | 6 votes |
public static TableState createMetaState(final JTable table, final boolean selectedOnly) { final TableState state = new TableState(table, selectedOnly); final GraphTableModel tm = (GraphTableModel) table.getModel(); for (int i = 0; i < table.getColumnCount(); i++) { final TableColumn tc = table.getColumnModel().getColumn(i); final int modelIndex = tc.getModelIndex(); final Attribute attr = tm.getAttribute(modelIndex); final String label = attr.getName(); final ColumnState cs = new ColumnState(label, tm.getSegment(modelIndex), tc.getWidth()); state.columns.add(cs); } final RowSorter<? extends TableModel> sorter = table.getRowSorter(); for (final RowSorter.SortKey sk : sorter.getSortKeys()) { // TODO: should really store the column label + segment here. state.sortOrder.add(String.format("%d,%s", sk.getColumn(), sk.getSortOrder())); } return state; }
Example 2
Source File: TableHeaderUI.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
/** * 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; }
Example 3
Source File: DefaultTableHeaderCellRenderer.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * 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 */ protected SortKey getSortKey(JTable table, int column) { RowSorter<?> rowSorter = table.getRowSorter(); if (rowSorter == null) { return null; } List<?> sortedColumns = rowSorter.getSortKeys(); if (sortedColumns.size() > 0) { return (SortKey) sortedColumns.get(0); } return null; }
Example 4
Source File: SeaGlassTableHeaderUI.java From seaglass with Apache License 2.0 | 4 votes |
/** * @see com.seaglasslookandfeel.ui.SeaGlassTableHeaderUI$DefaultTableCellHeaderRenderer#getTableCellRendererComponent(javax.swing.JTable, * java.lang.Object, boolean, boolean, int, int) */ @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { boolean hasRollover = false; // (column == getRolloverColumn()); if (isSelected || hasRollover || hasFocus) { SeaGlassLookAndFeel.setSelectedUI((SeaGlassLabelUI) SeaGlassLookAndFeel.getUIOfType(getUI(), SeaGlassLabelUI.class), isSelected, hasFocus, table.isEnabled(), hasRollover); } else { SeaGlassLookAndFeel.resetSelectedUI(); } // Stuff a variable into the client property of this renderer // indicating the sort order, so that different rendering can be // done for the header based on sorted state. RowSorter rs = table == null ? null : table.getRowSorter(); java.util.List<? extends RowSorter.SortKey> sortKeys = rs == null ? null : rs.getSortKeys(); if (sortKeys != null && sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: putClientProperty("Table.sortOrder", "ASCENDING"); break; case DESCENDING: putClientProperty("Table.sortOrder", "DESCENDING"); break; case UNSORTED: putClientProperty("Table.sortOrder", "UNSORTED"); break; default: throw new AssertionError("Cannot happen"); } } else { putClientProperty("Table.sortOrder", "UNSORTED"); } super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); return this; }