javax.swing.RowSorter Java Examples
The following examples show how to use
javax.swing.RowSorter.
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: ImportForm.java From azure-devops-intellij with MIT License | 6 votes |
public void setTeamProjectTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) { teamProjectTable.setModel(tableModel); teamProjectTable.setSelectionModel(selectionModel); // Setup table sorter final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); teamProjectTable.setRowSorter(sorter); // Attach an index converter to fix the indexes if the user sorts the list tableModel.setSelectionConverter(new TableModelSelectionConverter() { @Override public int convertRowIndexToModel(int viewRowIndex) { if (viewRowIndex >= 0) { return teamProjectTable.convertRowIndexToModel(viewRowIndex); } return viewRowIndex; } }); }
Example #2
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 #3
Source File: SeaGlassTableHeaderUI.java From seaglass with Apache License 2.0 | 6 votes |
/** * DOCUMENT ME! * * @param table DOCUMENT ME! * @param column DOCUMENT ME! * * @return DOCUMENT ME! */ public static SortOrder getColumnSortOrder(JTable table, int column) { SortOrder rv = null; if (table == null || table.getRowSorter() == null) { return rv; } java.util.List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { rv = sortKeys.get(0).getSortOrder(); } return rv; }
Example #4
Source File: CheckoutForm.java From azure-devops-intellij with MIT License | 6 votes |
public void setRepositoryTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) { repositoryTable.setModel(tableModel); repositoryTable.setSelectionModel(selectionModel); // Setup table sorter RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel); repositoryTable.setRowSorter(sorter); // Attach an index converter to fix the indexes if the user sorts the list tableModel.setSelectionConverter(new TableModelSelectionConverter() { @Override public int convertRowIndexToModel(int viewRowIndex) { if (viewRowIndex >= 0) { return repositoryTable.convertRowIndexToModel(viewRowIndex); } return viewRowIndex; } }); }
Example #5
Source File: KseFrame.java From keystore-explorer with GNU General Public License v3.0 | 6 votes |
/** * Re-draw all keystore tables * @param applicationSettings */ public void redrawKeyStores(ApplicationSettings applicationSettings) { if (keyStoreTables != null) { keyStoreTableColumns = applicationSettings.getKeyStoreTableColumns(); for (JTable keyStoreTable : keyStoreTables) { KeyStoreHistory history = ((KeyStoreTableModel) keyStoreTable.getModel()).getHistory(); KeyStoreTableModel ksModel = new KeyStoreTableModel(keyStoreTableColumns); try { ksModel.load(history); keyStoreTable.setModel(ksModel); RowSorter<KeyStoreTableModel> sorter = new TableRowSorter<>(ksModel); keyStoreTable.setRowSorter(sorter); setColumnsToIconSize(keyStoreTable, 0, 1, 2); colAdjust(keyStoreTable); } catch (GeneralSecurityException | CryptoException e) { DError.displayError(frame, e); } } } }
Example #6
Source File: PageableTable.java From jdal with Apache License 2.0 | 6 votes |
/** * Configure sort and order in page from sorter */ private void configurePage() { Page.Order order = Page.Order.ASC; String sortPropertyName = null; List<? extends SortKey> keys = sorter.getSortKeys(); // If sorting, get values to set in page if (keys.size() > 0) { RowSorter.SortKey key = sorter.getSortKeys().get(0); if (tableModel.isPropertyColumn(key.getColumn())) { sortPropertyName = tableModel.getSortPropertyName(key.getColumn()); order = converSortOrder(key); } } page.setSortName(sortPropertyName); page.setOrder(order); }
Example #7
Source File: SortableTableRowSorter.java From pcgen with GNU Lesser General Public License v2.1 | 6 votes |
private void sort() { SortableTableModel m = getModel(); if (m == null) { return; } int columnCount = m.getColumnCount(); Comparator<?>[] comparators = new Comparator[columnCount]; for (int i = 0; i < columnCount; i++) { comparators[i] = Comparators.getComparatorFor(m.getColumnClass(i)); } RowSorter.SortKey[] keys = sortKeys.toArray(new RowSorter.SortKey[0]); m.sortModel(new RowComparator(keys, comparators)); }
Example #8
Source File: ETable.java From netbeans with Apache License 2.0 | 5 votes |
/** * When ETable has ETableColumnModel set, only <code>null</code> sorter * is accepted, which turns off sorting. Otherwise UnsupportedOperationException is thrown. * RowSorter can be used when a different TableColumnModel is set. * * @param sorter {@inheritDoc} */ @Override public void setRowSorter(RowSorter<? extends TableModel> sorter) { if (getColumnModel() instanceof ETableColumnModel) { if (sorter == null) { sortable = false; ((ETableColumnModel) getColumnModel()).clearSortedColumns(); } else { throw new UnsupportedOperationException( "ETable with ETableColumnModel has it's own sorting mechanism. Use ETableColumnModel to define sorting, or set a different TableColumnModel."); } } else { super.setRowSorter(sorter); } }
Example #9
Source File: SortableTableRowSorter.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
/** * Reverses the sort order from ascending to descending (or descending * to ascending) if the specified column is already the primary sorted * column; otherwise, makes the specified column the primary sorted * column, with an ascending sort order. If the specified column is not * sortable, this method has no effect. * * @param column index of the column to make the primary sorted column, * in terms of the underlying model * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override public void toggleSortOrder(int column) { List<RowSorter.SortKey> keys = new ArrayList<>(getSortKeys()); RowSorter.SortKey sortKey; int sortIndex; for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) { if (keys.get(sortIndex).getColumn() == column) { break; } } if (sortIndex == -1) { // Key doesn't exist sortKey = new RowSorter.SortKey(column, SortOrder.ASCENDING); keys.add(0, sortKey); } else if (sortIndex == 0) { // It's the primary sorting key, toggle it keys.set(0, toggle(keys.get(0))); } else { // It's not the first, but was sorted on, remove old // entry, insert as first with ascending. keys.remove(sortIndex); keys.add(0, new RowSorter.SortKey(column, SortOrder.ASCENDING)); } if (keys.size() > 2) { keys = keys.subList(0, 2); } setSortKeys(keys); }
Example #10
Source File: ServerLogsTableModel.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Initializes the model */ private void init() { if (initialized.compareAndSet(false, true)) { final RowSorter<? extends TableModel> rowSorter = table.getRowSorter(); rowSorter.toggleSortOrder(1); // sort by date rowSorter.toggleSortOrder(1); // descending final TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(1).setCellRenderer(dateRenderer); columnModel.getColumn(2).setCellRenderer(sizeRenderer); } }
Example #11
Source File: ProfilerRowSorter.java From visualvm with GNU General Public License v2.0 | 5 votes |
void setSortKey(RowSorter.SortKey key) { RowSorter.SortKey secondaryKey = secondarySortColumn == -1 || secondarySortColumn == key.getColumn() ? null : new RowSorter.SortKey(secondarySortColumn, getDefaultSortOrder(secondarySortColumn)); setSortKeysImpl(secondaryKey == null ? Arrays.asList(key) : Arrays.asList(key, secondaryKey)); }
Example #12
Source File: FilteredTreeViewTable.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public FilteredTreeViewTable() { RowSorter<SortableTableModel> rowSorter = new SortableTableRowSorter() { @Override public SortableTableModel getModel() { return (SortableTableModel) FilteredTreeViewTable.this.getModel(); } }; setRowSorter(rowSorter); rowSorter.toggleSortOrder(0); }
Example #13
Source File: ProfilerRowSorter.java From visualvm with GNU General Public License v2.0 | 5 votes |
void saveToStorage(Properties properties, ProfilerTable table) { RowSorter.SortKey key = getSortKey(); if (key == null) { properties.remove(SORT_COLUMN_KEY); properties.remove(SORT_ORDER_KEY); } else { int column = key.getColumn(); SortOrder order = key.getSortOrder(); properties.setProperty(SORT_COLUMN_KEY, Integer.toString(column)); properties.setProperty(SORT_ORDER_KEY, order.toString()); } }
Example #14
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 #15
Source File: JTableEx.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public void sortModel() { RowSorter<?> rowSorter = getRowSorter(); if (rowSorter != null) { rowSorter.setSortKeys(getRowSorter().getSortKeys()); } }
Example #16
Source File: SortableTableRowSorter.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
private RowSorter.SortKey toggle(RowSorter.SortKey key) { if (key.getSortOrder() == SortOrder.ASCENDING) { return new RowSorter.SortKey(key.getColumn(), SortOrder.DESCENDING); } return new RowSorter.SortKey(key.getColumn(), SortOrder.ASCENDING); }
Example #17
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 #18
Source File: ETable.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get the RowSorter in case that the ETable does not have ETableColumnModel set. * @return {@inheritDoc} */ @Override public RowSorter<? extends TableModel> getRowSorter() { if (getColumnModel() instanceof ETableColumnModel) { return null; } else { return super.getRowSorter(); } }
Example #19
Source File: FilteredTreeViewTable.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public FilteredTreeViewTable() { RowSorter<SortableTableModel> rowSorter = new SortableTableRowSorter() { @Override public SortableTableModel getModel() { return (SortableTableModel) FilteredTreeViewTable.this.getModel(); } }; setRowSorter(rowSorter); rowSorter.toggleSortOrder(0); }
Example #20
Source File: PageableTable.java From jdal with Apache License 2.0 | 5 votes |
/** * Convert the Order from SortKey to Page.Order * @param key the SortKey * @return the Page order */ private Page.Order converSortOrder(RowSorter.SortKey key) { Page.Order order = Order.ASC; if (key.getSortOrder() == SortOrder.DESCENDING) { order = Order.DESC; } return order; }
Example #21
Source File: SortableTableRowSorter.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
private RowSorter.SortKey toggle(RowSorter.SortKey key) { if (key.getSortOrder() == SortOrder.ASCENDING) { return new RowSorter.SortKey(key.getColumn(), SortOrder.DESCENDING); } return new RowSorter.SortKey(key.getColumn(), SortOrder.ASCENDING); }
Example #22
Source File: JTableEx.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public void sortModel() { RowSorter<?> rowSorter = getRowSorter(); if (rowSorter != null) { rowSorter.setSortKeys(getRowSorter().getSortKeys()); } }
Example #23
Source File: ProfilerRowSorter.java From netbeans with Apache License 2.0 | 5 votes |
void saveToStorage(Properties properties, ProfilerTable table) { RowSorter.SortKey key = getSortKey(); if (key == null) { properties.remove(SORT_COLUMN_KEY); properties.remove(SORT_ORDER_KEY); } else { int column = key.getColumn(); SortOrder order = key.getSortOrder(); properties.setProperty(SORT_COLUMN_KEY, Integer.toString(column)); properties.setProperty(SORT_ORDER_KEY, order.toString()); } }
Example #24
Source File: RepositoryEntryCellRenderer.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
public Component getTableCellRendererComponent( final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column ) { final JLabel component = (JLabel) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column ); try { if ( column == 0 ) { final RepositoryTableModel tableModel = (RepositoryTableModel) table.getModel(); final RowSorter rowSorter = table.getRowSorter(); final FileObject e; if ( rowSorter != null ) { e = tableModel.getElementForRow( rowSorter.convertRowIndexToModel( row ) ); } else { e = tableModel.getElementForRow( row ); } if ( e.getType() == FileType.FOLDER ) { component.setIcon( closedIcon ); } else { component.setIcon( leafIcon ); } } else { component.setIcon( null ); } } catch ( FileSystemException fse ) { // ok, ugly, but not fatal. } return component; }
Example #25
Source File: UClassifierConfiguration.java From wandora with GNU General Public License v3.0 | 5 votes |
public void setClassifiers(String[] cs) { classifiers = cs; TableModel model = new ClassifierTableModel(cs); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); classifierTable.setRowSorter(sorter); classifierTable.setModel(model); }
Example #26
Source File: TableViewTopComponent.java From constellation with Apache License 2.0 | 5 votes |
/** * Assign a new table model and filter while keeping the sort keys. */ private void setNewModel() { final RowSorter<? extends TableModel> oldSorter = dataTable.getRowSorter(); final GraphTableModel gtm = new GraphTableModel(graphNode.getGraph(), currentElementType); final TableRowSorter<GraphTableModel> sorter = new TableRowSorter<>(gtm); sorter.setSortKeys(oldSorter.getSortKeys()); if (selectedOnlyButton.isSelected()) { sorter.setRowFilter(new SelectionRowFilter(graphNode.getGraph(), currentElementType)); } dataTable.setModel(gtm); dataTable.setRowSorter(sorter); }
Example #27
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; }
Example #28
Source File: ProfilerRowSorter.java From visualvm with GNU General Public License v2.0 | 4 votes |
int getSortColumn() { RowSorter.SortKey key = getSortKey(); return key == null ? -1 : key.getColumn(); }
Example #29
Source File: TroopTableHeaderRenderer.java From dsworkbench with Apache License 2.0 | 4 votes |
@Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Icon sortIcon = null; boolean isPaintingForPrint = false; if (table != null) { JTableHeader header = table.getTableHeader(); if (header != null) { Color fgColor = null; Color bgColor = null; if (hasFocus) { fgColor = UIManager.getColor("TableHeader.focusCellForeground"); bgColor = UIManager.getColor("TableHeader.focusCellBackground"); } if (fgColor == null) { fgColor = header.getForeground(); } if (bgColor == null) { bgColor = header.getBackground(); } setForeground(fgColor); setFont(header.getFont()); isPaintingForPrint = header.isPaintingForPrint(); } if (!isPaintingForPrint && table.getRowSorter() != null) { if (!horizontalTextPositionSet) { // There is a row sorter, and the developer hasn't // set a text position, change to leading. setHorizontalTextPosition(JLabel.LEADING); } java.util.List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys(); if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) { switch (sortKeys.get(0).getSortOrder()) { case ASCENDING: sortIcon = UIManager.getIcon("Table.ascendingSortIcon"); break; case DESCENDING: sortIcon = UIManager.getIcon("Table.descendingSortIcon"); break; case UNSORTED: sortIcon = UIManager.getIcon("Table.naturalSortIcon"); break; } } } } TroopsTableModel model = (TroopsTableModel) table.getModel(); ImageIcon icon = model.getColumnIcon((String) value); BufferedImage i = ImageUtils.createCompatibleBufferedImage(18, 18, BufferedImage.BITMASK); Graphics2D g2d = i.createGraphics(); // setIcon(sortIcon); if (icon != null) { icon.paintIcon(this, g2d, 0, 0); setText(""); if (sortIcon != null) { g2d.setColor(getBackground()); g2d.fillRect(18 - sortIcon.getIconWidth() - 2, 18 - sortIcon.getIconHeight() - 2, sortIcon.getIconWidth() + 2, sortIcon.getIconHeight() + 2); sortIcon.paintIcon(this, g2d, 18 - sortIcon.getIconWidth() - 1, 18 - sortIcon.getIconHeight() - 1); } setIcon(new ImageIcon(i)); } else { setIcon(sortIcon); setText(value == null ? "" : value.toString()); } Border border = null; if (hasFocus) { border = UIManager.getBorder("TableHeader.focusCellBorder"); } if (border == null) { border = UIManager.getBorder("TableHeader.cellBorder"); } setBorder(border); return this; }
Example #30
Source File: ProfilerTable.java From visualvm with GNU General Public License v2.0 | 4 votes |
public void setSorting(int column, SortOrder sortOrder) { if (isSortable()) { RowSorter.SortKey sortKey = new RowSorter.SortKey(column, sortOrder); _getRowSorter().setSortKeysImpl(Collections.singletonList(sortKey)); } }