當前位置: 首頁>>代碼示例>>Java>>正文


Java SortOrder類代碼示例

本文整理匯總了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?
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:ProfilerRowSorter.java

示例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;
        }
    };
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ProfilerTreeTable.java

示例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);
    }
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:22,代碼來源:TransactionsPanel.java

示例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);
    }
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:23,代碼來源:AccountSecuritiesPanel.java

示例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);
}
 
開發者ID:jonestimd,項目名稱:finances,代碼行數:27,代碼來源:TransactionTableRowSorterTest.java

示例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;
}
 
開發者ID:icza,項目名稱:scelight,代碼行數:26,代碼來源:JavaSysPropsPage.java

示例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;
}
 
開發者ID:freeseawind,項目名稱:littleluck,代碼行數:21,代碼來源:LuckTableCellHeaderRenderer.java

示例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();
}
 
開發者ID:BaderLab,項目名稱:AutoAnnotateApp,代碼行數:22,代碼來源:ClusterPanel.java

示例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);
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:32,代碼來源:DefaultSortController.java

示例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()));
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:23,代碼來源:JXTableUnitTest.java

示例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());
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:22,代碼來源:JXTableUnitTest.java

示例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));
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:21,代碼來源:JXTableUnitTest.java

示例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));
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:22,代碼來源:TableSortControllerTest.java

示例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());
}
 
開發者ID:RockManJoe64,項目名稱:swingx,代碼行數:22,代碼來源:ListSortUITest.java

示例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;
}
 
開發者ID:Torridity,項目名稱:dsworkbench,代碼行數:20,代碼來源:SortableTableHeaderRenderer.java


注:本文中的javax.swing.SortOrder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。