本文整理汇总了Java中javax.swing.SortOrder类的典型用法代码示例。如果您正苦于以下问题:Java SortOrder类的具体用法?Java SortOrder怎么用?Java SortOrder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SortOrder类属于javax.swing包,在下文中一共展示了SortOrder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadFromStorage
import javax.swing.SortOrder; //导入依赖的package包/类
void loadFromStorage(Properties properties, ProfilerTable table) {
String columnS = properties.getProperty(SORT_COLUMN_KEY);
String orderS = properties.getProperty(SORT_ORDER_KEY);
if (columnS != null) {
try {
int column = Integer.parseInt(columnS);
SortOrder order = getSortOrder(orderS);
if (SortOrder.UNSORTED.equals(order)) order = getDefaultSortOrder(column);
setSortColumn(column, order);
} catch (NumberFormatException e) {
// Reset sorting? Set default column?
}
} else {
// Reset sorting? Set default column?
}
}
示例2: getComparator
import javax.swing.SortOrder; //导入依赖的package包/类
private Comparator getComparator() {
SortOrder sortOrder = getSortOrder();
if (SortOrder.UNSORTED.equals(sortOrder)) return null;
final boolean ascending = SortOrder.ASCENDING.equals(sortOrder);
final int sortColumn = getSortColumn();
boolean sortingTree = JTree.class.equals(model.getColumnClass(sortColumn));
final Comparator comparator = sortingTree ? null : getComparator(sortColumn);
return new Comparator() {
public int compare(Object o1, Object o2) {
int result;
if (comparator == null) {
String s1 = o1.toString();
String s2 = o2.toString();
result = s1.compareTo(s2);
} else {
Object v1 = model.getValueAt((TreeNode)o1, sortColumn);
Object v2 = model.getValueAt((TreeNode)o2, sortColumn);
result = comparator.compare(v1, v2);
}
return ascending ? result : result * -1;
}
};
}
示例3: setSelectedAccount
import javax.swing.SortOrder; //导入依赖的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.SortOrder; //导入依赖的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.SortOrder; //导入依赖的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.SortOrder; //导入依赖的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: getColumnSortOrder
import javax.swing.SortOrder; //导入依赖的package包/类
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;
}
示例8: updateClusterTable
import javax.swing.SortOrder; //导入依赖的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();
}
示例9: toggleSortOrder
import javax.swing.SortOrder; //导入依赖的package包/类
/**
* {@inheritDoc}
* <p>
*
* Overridden - that is completely new implementation - to get first/next SortOrder
* from sort order cycle. Does nothing if the cycle is empty.
*/
@Override
public void toggleSortOrder(int column) {
checkColumn(column);
if (!isSortable(column))
return;
SortOrder firstInCycle = getFirstInCycle();
// nothing to toggle through
if (firstInCycle == null)
return;
List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
SortKey sortKey = SortUtils.getFirstSortKeyForColumn(keys, column);
if (keys.indexOf(sortKey) == 0) {
// primary key: in this case we'll use next sortorder in cylce
keys.set(0, new SortKey(column, getNextInCycle(sortKey.getSortOrder())));
} else {
// all others: make primary with first sortOrder in cycle
keys.remove(sortKey);
keys.add(0, new SortKey(column, getFirstInCycle()));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
}
示例10: assertControlsSorterPropertiesFalse
import javax.swing.SortOrder; //导入依赖的package包/类
/**
* RowSorter properties not touched if getControlsSorterProperties false.
*/
private void assertControlsSorterPropertiesFalse(boolean setSorter) {
table.setAutoCreateRowSorter(false);
SortOrder[] cycle = new SortOrder[] {SortOrder.DESCENDING, SortOrder.UNSORTED};
table.setSortOrderCycle(cycle);
table.setSortsOnUpdates(!table.getSortsOnUpdates());
table.setSortable(!table.isSortable());
if (setSorter) {
table.setRowSorter(new TableSortController<TableModel>(table.getModel()));
assertFalse("StringValueProvider propagated to controller",
table.getStringValueRegistry().equals(getSortController(table).getStringValueProvider()));
}
assertEquals("sortsOnUpdates propagated to controller",
!table.getSortsOnUpdates(), getSortController(table).getSortsOnUpdates());
assertEquals("sortable propagated to controller",
!table.isSortable(), getSortController(table).isSortable());
assertFalse("sortOrderCycle propagated to controller",
Arrays.equals(table.getSortOrderCycle(),
getSortController(table).getSortOrderCycle()));
}
示例11: assertControlsSorterPropertiesTrue
import javax.swing.SortOrder; //导入依赖的package包/类
/**
* RowSorter properties updated on getControlsSorterProperties true.
*/
private void assertControlsSorterPropertiesTrue(boolean setSorter) {
SortOrder[] cycle = new SortOrder[] {SortOrder.DESCENDING, SortOrder.UNSORTED};
table.setSortOrderCycle(cycle);
table.setSortsOnUpdates(!table.getSortsOnUpdates());
table.setSortable(!table.isSortable());
if (setSorter) {
table.setRowSorter(new TableSortController<TableModel>(table.getModel()));
}
assertEquals("sortsOnUpdates propagated to controller",
table.getSortsOnUpdates(), getSortController(table).getSortsOnUpdates());
assertEquals("sortable propagated to controller",
table.isSortable(), getSortController(table).isSortable());
assertTrue("sortOrderCycle propagated to controller",
Arrays.equals(table.getSortOrderCycle(),
getSortController(table).getSortOrderCycle()));
assertEquals("StringValueProvider propagated to controller",
table.getStringValueRegistry(), getSortController(table).getStringValueProvider());
}
示例12: testToggleSortOrderByIdentifier
import javax.swing.SortOrder; //导入依赖的package包/类
/**
* testing new sorter api:
* toggleSortOrder(Object), resetSortOrder.
*
*/
@Test
public void testToggleSortOrderByIdentifier() {
JXTable table = createTableWithCoreColumns();
Object firstColumn = "First Name";
Object secondColumn = "Last Name";
assertSame(SortOrder.UNSORTED, table.getSortOrder(secondColumn));
table.toggleSortOrder(firstColumn);
assertSame(SortOrder.ASCENDING, table.getSortOrder(firstColumn));
// sanity: other columns uneffected
assertSame(SortOrder.UNSORTED, table.getSortOrder(secondColumn));
table.toggleSortOrder(firstColumn);
assertSame(SortOrder.DESCENDING, table.getSortOrder(firstColumn));
table.resetSortOrder();
assertSame(SortOrder.UNSORTED, table.getSortOrder(firstColumn));
}
示例13: testComparableComparatorTable
import javax.swing.SortOrder; //导入依赖的package包/类
/**
* Issue #1156-swingx: sorter must use comparable if available
* TableSortController
*/
@Test
public void testComparableComparatorTable() {
TableModel model = new DefaultTableModel(2, 1) {
@Override
public Class<?> getColumnClass(int columnIndex) {
return Integer.class;
}
};
model.setValueAt(10, 0, 0);
model.setValueAt(2, 1, 0);
TableSortController<TableModel> sorter = new TableSortController<TableModel>(
model);
sorter.setSortOrder(0, SortOrder.ASCENDING);
assertEquals(0, sorter.convertRowIndexToModel(1));
}
示例14: testAddRowAboveSelectionInvertedOrder
import javax.swing.SortOrder; //导入依赖的package包/类
/**
* Issue #223
* test if selection is updated on add row above selection.
*
*/
@Test
public void testAddRowAboveSelectionInvertedOrder() {
// select the last row in view coordinates
int selectedRow = list.getElementCount() - 2;
list.setSelectedIndex(selectedRow);
// revert order
list.setSortOrder(SortOrder.DESCENDING);
assertEquals("second row must be selected", 1, list.getSelectedIndex());
// add row in model coordinates
// insert high value
Object row = new Integer(100);
ascendingListModel.addElement(row);
assertEquals(row, list.getElementAt(0));
// selection must be moved one below
assertEquals("selection must be incremented by one ", 2, list.getSelectedIndex());
}
示例15: getTableCellRendererComponent
import javax.swing.SortOrder; //导入依赖的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;
}