本文整理汇总了Java中javax.swing.RowSorter.SortKey类的典型用法代码示例。如果您正苦于以下问题:Java SortKey类的具体用法?Java SortKey怎么用?Java SortKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SortKey类属于javax.swing.RowSorter包,在下文中一共展示了SortKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rebuildTableModel
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
@Override
public void rebuildTableModel() {
SortKey sortKey = this.getSortKey();
columnTitles.clear();
columnTitles.add(DEFAULT_TIME_COLUMN_TITLE);
// Remember the current width of the table columns
Vector<Integer> columnWidths = this.getColumnWidths();
// Rebuild the table model
this.tableModelDataVector = new TableModelDataVector(TimeSeries.class.getSimpleName(), this.tableModelDataVector.isActivateRowNumber(), this.tableModelDataVector.getKeyColumnIndex());
List chartDataSeries = this.parentDataModel.getOntologyModel().getChartData();
for (int i = 0; i < chartDataSeries.size(); i++) {
DataSeries chartData = (DataSeries) chartDataSeries.get(i);
this.addSeries(chartData, false);
}
// Set the width of the columns like before
this.setColumnWidths(columnWidths);
this.setSortKey(sortKey);
}
示例2: getIcon
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
/**
* Overloaded to return an icon suitable to the primary sorted column, or
* null if the column is not the primary sort key.
*
* @param table the <code>JTable</code>.
* @param column the column index.
* @return the sort icon, or null if the column is unsorted.
*/
protected Icon getIcon(JTable table, int column) {
SortKey sortKey = getSortKey(table, column);
if (sortKey != null && table.convertColumnIndexToView(sortKey.getColumn()) == column) {
switch (sortKey.getSortOrder()) {
case ASCENDING:
return UIManager.getIcon("Table.ascendingSortIcon");
case DESCENDING:
return UIManager.getIcon("Table.descendingSortIcon");
default:
// Just to remove unmatched case warning
}
}
return null;
}
示例3: setSelectedAccount
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
public void setSelectedAccount(Account account) {
if (this.selectedAccount == null || ! this.selectedAccount.getId().equals(account.getId())) {
this.selectedAccount = account;
setTitle(account);
transactionTable.getModel().removeTableModelListener(tableModelListener);
transactionTable.getModel().removePropertyChangeListener(TransactionTableModel.NEW_TRANSACTION_PAYEE_PROPERTY, payeeChangeListener);
TransactionTableModel newModel = transactionModelCache.getModel(account);
transactionTable.setModel(newModel);
transactionTable.getRowSorter().setSortKeys(Collections.singletonList(new SortKey(0, SortOrder.ASCENDING)));
newModel.addTableModelListener(tableModelListener);
newModel.addPropertyChangeListener(TransactionTableModel.NEW_TRANSACTION_PAYEE_PROPERTY, payeeChangeListener);
ComponentBinder.bind(newModel, TransactionTableModel.CLEARED_BALANCE_PROPERTY, newModel.getClearedBalance(), clearedBalance, currencyFormat);
if (transactionTable.getModel().getBeans().isEmpty()) {
refreshAction.actionPerformed(new ActionEvent(this, RefreshAction.INITIAL_LOAD_ACTION_ID, null));
}
else {
transactionTable.selectLastTransaction();
}
firePropertyChange(ACCOUNT_PROPERTY, null, selectedAccount);
}
}
示例4: AccountSecuritiesPanel
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
public AccountSecuritiesPanel(ServiceLocator serviceLocator, DomainEventPublisher domainEventPublisher,
Iterable<SecurityTableExtension> tableExtensions, FinanceTableFactory tableFactory, WindowEventPublisher<WindowType> windowEventPublisher) {
this.assetOperations = serviceLocator.getAssetOperations();
this.windowEventPublisher = windowEventPublisher;
AccountSecurityTableModel tableModel = new AccountSecurityTableModel(domainEventPublisher, tableExtensions);
table = tableFactory.createTable(tableModel);
SectionTableRowSorter<SecuritySummary, AccountSecurityTableModel> sorter = new SectionTableRowSorter<>(table);
sorter.setRowFilter(SecuritySummary::isNotEmpty);
sorter.setSortKeys(Lists.newArrayList(new SortKey(AccountSecurityTableModel.NAME_INDEX, SortOrder.ASCENDING)));
table.setRowSorter(sorter);
reloadAction = new ReloadActionHandler();
setLayout(new BorderLayout());
add(BorderLayout.CENTER, new JScrollPane(table));
// for (SecurityTableExtension extension : tableExtensions) {
// if (extension instanceof TableSummary) {
// addSummaries((TableSummary) extension);
// }
// }
reloadHandler = new ReloadEventHandler<>(this, RELOAD_MESSAGE_KEY,
assetOperations::getSecuritySummariesByAccount, this::getTableModel, SecuritySummary::isSameIds);
domainEventPublisher.register(SecuritySummary.class, reloadHandler);
}
示例5: newTransactionAlwaysLast
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
@Test
public void newTransactionAlwaysLast() throws Exception {
TransactionTableModel model = new TransactionTableModel(new Account(1L));
TransactionTable table = new TransactionTable(model);
model.addBean(newTransaction(1L));
model.addBean(newTransaction(null));
model.addBean(newTransaction(2L));
TransactionTableRowSorter sorter = new TransactionTableRowSorter(table);
sorter.setSortKeys(Collections.singletonList(new SortKey(1, SortOrder.ASCENDING)));
assertThat(sorter.convertRowIndexToView(0)).isEqualTo(0);
assertThat(sorter.convertRowIndexToView(1)).isEqualTo(1);
assertThat(sorter.convertRowIndexToView(4)).isEqualTo(2);
assertThat(sorter.convertRowIndexToView(5)).isEqualTo(3);
assertThat(sorter.convertRowIndexToView(2)).isEqualTo(4);
assertThat(sorter.convertRowIndexToView(3)).isEqualTo(5);
sorter.toggleSortOrder(1);
assertThat(sorter.convertRowIndexToView(0)).isEqualTo(2);
assertThat(sorter.convertRowIndexToView(1)).isEqualTo(3);
assertThat(sorter.convertRowIndexToView(4)).isEqualTo(0);
assertThat(sorter.convertRowIndexToView(5)).isEqualTo(1);
assertThat(sorter.convertRowIndexToView(2)).isEqualTo(4);
assertThat(sorter.convertRowIndexToView(3)).isEqualTo(5);
}
示例6: createPageComp
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
@Override
public JComponent createPageComp() {
final BorderPanel p = new BorderPanel();
final XTable table = new XTable();
final Vector< Vector< Object > > data = new Vector<>();
final Properties props = System.getProperties();
// Use name enumeration which properly returns names from the default properties of a property
// (while HashTable.entrySet() does not!).
final Enumeration< ? > nameEnum = props.propertyNames();
while ( nameEnum.hasMoreElements() ) {
final Object name = nameEnum.nextElement();
data.add( Utils.vector( name, props.getProperty( name.toString() ) ) );
}
table.getXTableModel().setDataVector( data, Utils.vector( "Property name", "Property value" ) );
table.getRowSorter().setSortKeys( Arrays.asList( new SortKey( 0, SortOrder.ASCENDING ) ) );
table.packColumnsExceptLast();
p.addCenter( table.createWrapperBox( true, table.createToolBarParams( p ) ) );
return p;
}
示例7: updateClusterTable
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
private void updateClusterTable() {
int index = annotationSetCombo.getSelectedIndex();
AnnotationSet annotationSet = annotationSetCombo.getItemAt(index).getValue();
ClusterTableModel clusterModel = new ClusterTableModel(annotationSet);
int widths[] = getColumnWidths(clusterTable);
clusterTable.setModel(clusterModel);
setColumnWidths(clusterTable, widths);
TableColumn collapsedColumn = clusterTable.getColumnModel().getColumn(ClusterTableModel.COLLAPSED_COLUMN_INDEX);
collapsedColumn.setCellRenderer(new ClusterTableCollapsedCellRenderer(iconManager));
// sort
TableRowSorter<TableModel> sorter = new TableRowSorter<>(clusterTable.getModel());
clusterTable.setRowSorter(sorter);
List<SortKey> sortKeys = new ArrayList<>(2);
sortKeys.add(new RowSorter.SortKey(ClusterTableModel.NODES_COLUMN_INDEX, SortOrder.DESCENDING));
sortKeys.add(new RowSorter.SortKey(ClusterTableModel.CLUSTER_COLUMN_INDEX, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
sorter.sort();
}
示例8: getSortedColumn
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
/**
* Returns the primary sort column, or null if nothing sorted or no sortKey
* corresponds to a TableColumn currently contained in the TableColumnModel.
*
* @return the currently interactively sorted TableColumn or null if there
* is not sorter active or if the sorted column index does not
* correspond to any column in the TableColumnModel.
*/
public TableColumn getSortedColumn() {
// bloody hack: get primary SortKey and
// check if there's a column with it available
RowSorter<?> controller = getRowSorter();
if (controller != null) {
// PENDING JW: must use RowSorter?
SortKey sortKey = SortUtils.getFirstSortingKey(controller
.getSortKeys());
if (sortKey != null) {
int sorterColumn = sortKey.getColumn();
List<TableColumn> columns = getColumns(true);
for (Iterator<TableColumn> iter = columns.iterator(); iter
.hasNext();) {
TableColumn column = iter.next();
if (column.getModelIndex() == sorterColumn) {
return column;
}
}
}
}
return null;
}
示例9: getSessionState
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
public Object getSessionState(Component c) {
checkComponent(c);
JXTable table = (JXTable) c;
List<ColumnState> columnStates = new ArrayList<ColumnState>();
List<TableColumn> columns = table.getColumns(true);
List<TableColumn> visibleColumns = table.getColumns();
for (TableColumn column : columns) {
columnStates.add(new ColumnState((TableColumnExt) column,
visibleColumns.indexOf(column)));
}
XTableState tableState = new XTableState(columnStates.toArray(new ColumnState[columnStates.size()]));
tableState.setHorizontalScrollEnabled(table.isHorizontalScrollEnabled());
List<? extends SortKey> sortKeys = null;
if (table.getRowSorter() != null) {
sortKeys = table.getRowSorter().getSortKeys();
}
// PENDING: store all!
if ((sortKeys != null) && (sortKeys.size() >0)) {
tableState.setSortKey(sortKeys.get(0));
}
return tableState;
}
示例10: getTableCellRendererComponent
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
@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;
}
示例11: getSortKeys
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
public List<SortKey> getSortKeys()
{
if (sortIndexes2Direction.isEmpty())
{
return Collections.emptyList();
}
final List<SortKey> sortKeys = new ArrayList<>(sortIndexes2Direction.size());
for (final Map.Entry<Integer, Boolean> e : sortIndexes2Direction.entrySet())
{
final int modelColumnIndex = e.getKey();
final SortOrder sortOrder = getSortOrderOfBooleanAscendingFlag(e.getValue());
final SortKey sortKey = new SortKey(modelColumnIndex, sortOrder);
sortKeys.add(sortKey);
}
return sortKeys;
}
示例12: setSortKeys
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
public final void setSortKeys(final List<? extends SortKey> sortKeys)
{
sortIndexes2Direction.clear();
if (sortKeys == null || sortKeys.isEmpty())
{
return;
}
for (final SortKey sortKey : sortKeys)
{
final int modelColumnIndex = sortKey.getColumn();
final Boolean isSortAscending = getSortAscendingFlagOfSortOrder(sortKey.getSortOrder());
if (isSortAscending == null)
{
continue;
}
sortIndexes2Direction.put(modelColumnIndex, isSortAscending);
}
}
示例13: sorterChanged
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
@Override
public void sorterChanged(RowSorterEvent e) {
if (e.getType() == Type.SORT_ORDER_CHANGED) {
@SuppressWarnings("unchecked")
List<? extends SortKey> sortKeys = e.getSource().getSortKeys();
Object[] keys = new Object[sortKeys.size()];
boolean[] directions = new boolean[sortKeys.size()];
int index = 0;
for (SortKey s : sortKeys) {
keys[index] = SwingTable.this.keys[s.getColumn()];
directions[index] = s.getSortOrder() == SortOrder.ASCENDING;
index++;
}
if (list instanceof Sortable) {
((Sortable) list).sort(keys, directions);
}
setOffset(0);
}
}
示例14: compareRows
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
public int compareRows(int row1, int row2) {
int order = 0;
for (int i = 0; i < criteria.size(); i++) {
SortKey key = criteria.get(i);
if (key.getSortOrder() != SortOrder.UNSORTED) {
Object o1 = model.getValueAt(row1, key.getColumn());
Object o2 = model.getValueAt(row2, key.getColumn());
if (o1 instanceof Comparable<?> && o2 instanceof Comparable<?>) {
Comparable<Object> c1 = (Comparable<Object>) o1;
Comparable<Object> c2 = (Comparable<Object>) o2;
order = c1.compareTo(c2);
} else if (o1 == null && o2 != null) {
order = 1;
} else if (o1 != null && o2 == null) {
order = -1;
}
order = key.getSortOrder() == SortOrder.DESCENDING ? -order : order;
if (order != 0) {
break;
}
}
}
return order;
}
示例15: sortByFirstModelColumnTest
import javax.swing.RowSorter.SortKey; //导入依赖的package包/类
@Test
public void sortByFirstModelColumnTest() throws Exception {
int fixedRows = 2;
int fixedCols = 3;
LinearInset rowsInset = new LinearInset(1, 1);
LinearInset columnsInset = new LinearInset(1, 1);
ConfResult conf = beginSortedVisual(fixedRows, fixedCols, rowsInset, columnsInset);
for (int i = 1; i < conf.tlTable.getRowCount(); i++) {
assertEquals(new Long(i), (Long)conf.tlTable.getValueAt(i, 1));
}
for (int i = 0; i < conf.blTable.getRowCount() - 1; i++) {
assertEquals(new Long(i + conf.tlTable.getRowCount()), (Long)conf.blTable.getValueAt(i, 1));
}
SortKey sk = new SortKey(0/*in terms of the model, not the view*/, SortOrder.DESCENDING);
List<SortKey> keys = new ArrayList<>();
keys.add(sk);
conf.tlTable.getRowSorter().setSortKeys(keys);
Long k = 7l;
for (int i = 1; i < conf.tlTable.getRowCount(); i++) {
assertEquals(k--, (Long)conf.tlTable.getValueAt(i, 1));
}
for (int i = 0; i < conf.blTable.getRowCount() - 1; i++) {
assertEquals(k--, (Long)conf.blTable.getValueAt(i, 1));
}
endVisual();
}