Java 类javax.swing.SortOrder 实例源码
项目:incubator-netbeans
文件:ProfilerRowSorter.java
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?
}
}
项目:incubator-netbeans
文件:ProfilerTreeTable.java
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;
}
};
}
项目:finances
文件:TransactionsPanel.java
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);
}
}
项目:finances
文件:AccountSecuritiesPanel.java
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);
}
项目:finances
文件:TransactionTableRowSorterTest.java
@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);
}
项目:scelight
文件:JavaSysPropsPage.java
@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;
}
项目:littleluck
文件:LuckTableCellHeaderRenderer.java
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;
}
项目:AutoAnnotateApp
文件:ClusterPanel.java
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();
}
项目:swingx
文件:DefaultSortController.java
/**
* {@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);
}
项目:swingx
文件:JXTableUnitTest.java
/**
* 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()));
}
项目:swingx
文件:JXTableUnitTest.java
/**
* 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());
}
项目:swingx
文件:JXTableUnitTest.java
/**
* 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));
}
项目:swingx
文件:TableSortControllerTest.java
/**
* 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));
}
项目:swingx
文件:ListSortUITest.java
/**
* 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());
}
项目:dsworkbench
文件:SortableTableHeaderRenderer.java
@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;
}
项目:metasfresh
文件:CTableModelRowSorter.java
protected final void setColumnSortOrder(final int modelColumnIndex, final SortOrder sortOrder)
{
sortIndexes2Direction.remove(modelColumnIndex);
if (sortOrder == SortOrder.ASCENDING)
{
sortIndexes2Direction.put(modelColumnIndex, true);
}
else if (sortOrder == SortOrder.DESCENDING)
{
sortIndexes2Direction.put(modelColumnIndex, false);
}
else if (sortOrder == SortOrder.UNSORTED)
{
// just removed it's fine
}
else
{
// shall not happen
}
}
项目:metasfresh
文件:CTableModelRowSorter.java
private static final Boolean getSortAscendingFlagOfSortOrder(final SortOrder sortOrder)
{
if (sortOrder == null)
{
return null;
}
else if (sortOrder == SortOrder.ASCENDING)
{
return true;
}
else if (sortOrder == SortOrder.DESCENDING)
{
return false;
}
else if (sortOrder == SortOrder.UNSORTED)
{
return null;
}
else
{
throw new IllegalArgumentException("Unknown sortOrder: " + sortOrder);
}
}
项目:metasfresh
文件:CTableModelRowSorter.java
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;
}
项目:metasfresh
文件:VHeaderRenderer.java
/** @return column sort icon or null */
private final Icon getColumnSortIcon(final JTable table, final int viewColumnIndex)
{
if (table instanceof CTable)
{
final CTable cTable = (CTable)table;
final int modelColumnIndex = table.convertColumnIndexToModel(viewColumnIndex);
final SortOrder sortOrder = cTable.getSortOrder(modelColumnIndex);
if (sortOrder == SortOrder.ASCENDING)
{
return Images.getImageIcon2("uparrow");
}
else if (sortOrder == SortOrder.DESCENDING)
{
return Images.getImageIcon2("downarrow");
}
else
{
return null;
}
}
else
{
return null;
}
}
项目:seaglass
文件:SeaGlassTableHeaderUI.java
/**
* 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;
}
项目:minimal-j
文件:SwingTable.java
@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);
}
}
项目:incubator-netbeans
文件:ProfilerRowSorter.java
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());
}
}
项目:incubator-netbeans
文件:ProfilerTable.java
protected TableRowSorter createRowSorter() {
ProfilerRowSorter s = new ProfilerRowSorter(getModel());
s.setStringConverter(new TableStringConverter() {
public String toString(TableModel model, int row, int column) {
return getModelStringValue(row, column);
}
});
s.setDefaultSortOrder(SortOrder.DESCENDING);
s.setSortColumn(0);
return s;
}
项目:incubator-netbeans
文件:ProfilerTreeTable.java
protected TableRowSorter createRowSorter() {
ProfilerRowSorter s = new ProfilerTreeTableSorter(getModel()) {
public void allRowsChanged() {
// Must invoke later, JTree.getRowCount() not ready yet
SwingUtilities.invokeLater(new Runnable() {
public void run() { updateColumnsPreferredWidth(); }
});
}
};
s.setDefaultSortOrder(SortOrder.DESCENDING);
s.setDefaultSortOrder(0, SortOrder.ASCENDING);
s.setSortColumn(0);
return s;
}
项目:rapidminer
文件:TableHeaderUI.java
@Override
public Icon getIcon() {
int modelCol = header.getTable().convertColumnIndexToModel(curCol);
TableModel model = header.getTable().getModel();
if (model instanceof ExtendedJTableSorterModel) {
ExtendedJTableSorterModel sortModel = (ExtendedJTableSorterModel) model;
switch (sortModel.getSortingStatus(modelCol)) {
case ExtendedJTableSorterModel.ASCENDING:
return UIManager.getIcon("Table.ascendingSortIcon");
case ExtendedJTableSorterModel.DESCENDING:
return UIManager.getIcon("Table.descendingSortIcon");
case ExtendedJTableSorterModel.NOT_SORTED:
default:
return null;
}
} else {
SortKey sortKey = getSortKey(header.getTable().getRowSorter(), modelCol);
SortOrder sortOrder = sortKey != null ? sortKey.getSortOrder() : SortOrder.UNSORTED;
switch (sortOrder) {
case ASCENDING:
return UIManager.getIcon("Table.ascendingSortIcon");
case DESCENDING:
return UIManager.getIcon("Table.descendingSortIcon");
case UNSORTED:
default:
return null;
}
}
}
项目:smile_1.5.0_java7
文件:Table.java
private void init() {
setAutoResizeMode(AUTO_RESIZE_OFF);
setCellSelectionEnabled(true);
setColumnControlVisible(true);
setHighlighters(HighlighterFactory.createAlternateStriping());
setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
TableCopyPasteAdapter.apply(this);
getTableHeader().setDefaultRenderer(new MultiColumnSortTableHeaderCellRenderer());
// workaround with table row filter to let it register to table changes
firePropertyChange("model", getModel(), getModel());
}
项目:OpenJSharp
文件:DefaultRowSorter.java
/**
* 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}
* @see #setSortable(int,boolean)
* @see #setMaxSortKeys(int)
*/
public void toggleSortOrder(int column) {
checkColumn(column);
if (isSortable(column)) {
List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
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 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 SortKey(column, SortOrder.ASCENDING));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
}
}
项目:jdk8u-jdk
文件:DefaultRowSorter.java
/**
* 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}
* @see #setSortable(int,boolean)
* @see #setMaxSortKeys(int)
*/
public void toggleSortOrder(int column) {
checkColumn(column);
if (isSortable(column)) {
List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
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 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 SortKey(column, SortOrder.ASCENDING));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
}
}
项目:Java8CN
文件:DefaultRowSorter.java
/**
* 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}
* @see #setSortable(int,boolean)
* @see #setMaxSortKeys(int)
*/
public void toggleSortOrder(int column) {
checkColumn(column);
if (isSortable(column)) {
List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
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 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 SortKey(column, SortOrder.ASCENDING));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
}
}
项目:finances
文件:TransactionTableRowSorter.java
@Override
protected Comparator<HeaderDetailViewToModel<Transaction>> columnComparator(SortKey sortKey) {
if (isDateColumn(sortKey)) {
return sortKey.getSortOrder() == SortOrder.ASCENDING ? beanIndexOrdering.compound(modelIndexComparator)
: beanIndexOrdering.reverse().compound(modelIndexComparator);
}
return super.columnComparator(sortKey);
}
项目:libraries
文件:ObjectTableRowSorter.java
@Override
public void toggleSortOrder(final int column) {
checkColumn(column);
if (isSortable(column)) {
List<SortKey> keys = new ArrayList<>(getSortKeys());
SortKey sortKey;
int sortIndex;
for (sortIndex = keys.size() - 1; sortIndex >= 0; sortIndex--) {
if (keys.get(sortIndex).getColumn() == column) {
break;
}
}
if (sortIndex == -1) {
sortKey = new SortKey(column, SortOrder.ASCENDING);
keys.add(0, sortKey);
} else if (sortIndex == 0) {
keys.set(0, toggle(keys.get(0)));
} else {
keys.remove(sortIndex);
keys.add(0, new SortKey(column, SortOrder.ASCENDING));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
checkSortState();
}
}
项目:libraries
文件:ObjectTableRowSorter.java
private void checkSortState() {
boolean state = false;
final List<SortKey> keys = new ArrayList<>(getSortKeys());
for (final SortKey sortKey : keys) {
state |= !sortKey.getSortOrder().equals(SortOrder.UNSORTED);
}
this.sortStateModel.set(state);
}
项目:libraries
文件:ObjectTableRowSorter.java
private SortKey toggle(final SortKey key) {
switch (key.getSortOrder()) {
case ASCENDING: {
return new SortKey(key.getColumn(), SortOrder.DESCENDING);
}
case DESCENDING: {
return new SortKey(key.getColumn(), SortOrder.UNSORTED);
}
case UNSORTED: {
return new SortKey(key.getColumn(), SortOrder.ASCENDING);
}
}
throw new UnreachableCodeReachedException();
}
项目:scelight
文件:XTableRowSorter.java
@Override
public void toggleSortOrder( final int column ) {
if ( defaultDescColumnSet != null && defaultDescColumnSet.contains( column ) ) {
// Column needs to be sorted descending by default
final List< ? extends SortKey > sortKeys = getSortKeys();
// Search for the column's sort key
int idx;
for ( idx = sortKeys.size() - 1; idx >= 0; idx-- )
if ( sortKeys.get( idx ).getColumn() == column )
break;
if ( idx != 0 ) {
// Currently column is not the primary sorting key but is about to become the primary,
// which means the default descending sorting order has to be applied.
final List< SortKey > sortKeyList = new ArrayList<>( getSortKeys() );
if ( idx > 0 ) {
// Column is part of the sorting strategy, move it to the front
sortKeyList.remove( idx );
}
// Add sort key for the column as ASCENDING and super implementation will toggle it to descending!
sortKeyList.add( 0, new SortKey( column, SortOrder.ASCENDING ) );
setSortKeys( sortKeyList );
}
}
super.toggleSortOrder( column );
}
项目:scelight
文件:RepListColumnSetupDialog.java
/**
* Rebuilds the table.
*/
private void rebuildTable() {
table.saveSelection( classColIdx );
final XTableModel model = table.getXTableModel();
model.getDataVector().clear();
model.fireTableDataChanged();
for ( final Class< ? extends IColumn< ? > > colClass : RepListColumnRegistry.COLUMN_LIST ) {
final boolean isCustom = BaseCustomColumn.class.isAssignableFrom( colClass );
// Only show custom columns if skill level is met
if ( isCustom && Settings.REP_LIST_CUST_COL_1_NAME.skillLevel.isBelow() )
continue;
final IColumn< ? > column = RepListColumnRegistry.getColumnInstance( colClass );
if ( column == null )
continue;
final int pos = rlcBean.getColumnClassList().indexOf( colClass ) + 1;
final Vector< Object > row = Utils.< Object > asNewVector( colClass, pos > 0 ? pos : -1, column.getRicon(), column.getDisplayName(), pos > 0,
isCustom, column.getDescription() );
model.addRow( row );
}
table.getRowSorter().setSortKeys( Arrays.asList( new SortKey( posColIdx, SortOrder.ASCENDING ) ) );
// Pack all columns except the last Description column
for ( int i = table.getColumnCount() - 1; i >= 0; i-- )
if ( i != table.convertColumnIndexToView( descColIdx ) )
table.packColumns( i );
table.restoreSelection( classColIdx );
}
项目:kdxplore
文件:SunSwingDefaultCellHeaderRenderer.java
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;
}
项目:jdk8u_jdk
文件:DefaultRowSorter.java
/**
* 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}
* @see #setSortable(int,boolean)
* @see #setMaxSortKeys(int)
*/
public void toggleSortOrder(int column) {
checkColumn(column);
if (isSortable(column)) {
List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
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 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 SortKey(column, SortOrder.ASCENDING));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
}
}
项目:lookaside_java-1.8.0-openjdk
文件:DefaultRowSorter.java
/**
* 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}
* @see #setSortable(int,boolean)
* @see #setMaxSortKeys(int)
*/
public void toggleSortOrder(int column) {
checkColumn(column);
if (isSortable(column)) {
List<SortKey> keys = new ArrayList<SortKey>(getSortKeys());
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 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 SortKey(column, SortOrder.ASCENDING));
}
if (keys.size() > getMaxSortKeys()) {
keys = keys.subList(0, getMaxSortKeys());
}
setSortKeys(keys);
}
}
项目:LS-jsampler
文件:AbstractInstrumentsDbTable.java
private void
rowSorterChanged() {
List<? extends SortKey> list = getRowSorter().getSortKeys();
if(list.isEmpty()) return;
SortKey k = list.get(0);
int i = k.getColumn() + 1;
if(k.getSortOrder() == SortOrder.UNSORTED) return;
if(k.getSortOrder() == SortOrder.DESCENDING) i *= -1;
preferences().setIntProperty(tablePrefix + "sortOrder", i);
}
项目:ca-iris
文件:ControllerTableModel.java
/** Get a table row sorter */
@Override
public RowSorter<ProxyTableModel<Controller>> createSorter() {
TableRowSorter<ProxyTableModel<Controller>> sorter =
new TableRowSorter<ProxyTableModel<Controller>>(this);
sorter.setSortsOnUpdates(true);
LinkedList<RowSorter.SortKey> keys =
new LinkedList<RowSorter.SortKey>();
keys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(keys);
if (isFiltered())
sorter.setRowFilter(createFilter());
return sorter;
}