Java 类javax.swing.RowSorter.SortKey 实例源码

项目:AgentWorkbench    文件:TimeSeriesTableModel.java   
@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);
}
项目:smile_1.5.0_java7    文件:DefaultTableHeaderCellRenderer.java   
/**
 * 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;
}
项目: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;
}
项目: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    文件:JXTable.java   
/**
 * 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;
}
项目:swingx    文件:XProperties.java   
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;
}
项目: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   
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    文件:CTableModelRowSorter.java   
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);
    }
}
项目: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);
        }
    }
项目:platypus-js    文件:TabularRowsSorter.java   
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;
}
项目:platypus-js    文件:RowsMovementsTest.java   
@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();
}
项目:jClipCorn    文件:ClipTable.java   
private void initialSort() {
    @SuppressWarnings("unchecked")
    TableRowSorter<ClipTableModel> sorter = ((TableRowSorter<ClipTableModel>)table.getRowSorter());
    List<SortKey> list = new ArrayList<>(); 

    switch (CCProperties.getInstance().PROP_VIEW_DB_START_SORT.getValue()) {
    case LOCALID:
        //DO nothing
        return;
    case TITLE:
        list.add( new RowSorter.SortKey(ClipTableModel.COLUMN_TITLE, SortOrder.ASCENDING) );
        break;
    case ADDDATE:
        list.add( new RowSorter.SortKey(ClipTableModel.COLUMN_DATE, SortOrder.DESCENDING) );
        break;
    }

    sorter.setSortKeys(list);
    sorter.sort();
}
项目:jClipCorn    文件:ExtendedSettingsFrame.java   
private void finalizeGUI() {
    if (! LookAndFeelManager.isSubstance()) {
        edName.setBackground(Color.WHITE);
    }
    if (! LookAndFeelManager.isSubstance()) {
        edTyp.setBackground(Color.WHITE);
    }

    lsModel = new SettingsTableModel(properties); // $hide$
    rowsorter = new TableRowSorter<>();
    rowsorter.setModel(lsModel);
    List<SortKey> sk = new ArrayList<>();
    sk.add( new RowSorter.SortKey(0, SortOrder.ASCENDING) );
    rowsorter.setSortKeys(sk);
    rowsorter.sort();

    tabSettings.setModel(lsModel);
    tabSettings.setRowSorter(rowsorter);

    tabSettings.getColumnModel().getColumn(0).setPreferredWidth(getWidth()*2/3);
    tabSettings.getColumnModel().getColumn(1).setPreferredWidth(getWidth()*1/3);

    tabSettings.getSelectionModel().addListSelectionListener(this);
    tabSettings.getColumnModel().getColumn(1).setCellEditor(lsEditor = new SettingsTableEditor(properties));
}
项目:edacc_gui    文件:EDACCCourse.java   
private void btnColumnsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnColumnsActionPerformed
    List<SortKey> sortKeys = (List<SortKey>) tblInstanceSeed.getRowSorter().getSortKeys();
    List<String> columnNames = new ArrayList<String>();
    for (SortKey sk : sortKeys) {
        columnNames.add(tblInstanceSeed.getColumnName(tblInstanceSeed.convertColumnIndexToView(sk.getColumn())));
    }
    EDACCInstanceColumnSelection dialog = new EDACCInstanceColumnSelection(EDACCApp.getApplication().getMainFrame(), true, selector, InstanceTableModel.COL_PROP + 1);
    dialog.setLocationRelativeTo(EDACCApp.getApplication().getMainFrame());
    dialog.setVisible(true);
    List<SortKey> newSortKeys = new ArrayList<SortKey>();
    for (int k = 0; k < columnNames.size(); k++) {
        String col = columnNames.get(k);
        for (int i = 0; i < tblInstanceSeed.getColumnCount(); i++) {
            if (tblInstanceSeed.getColumnName(i).equals(col)) {
                newSortKeys.add(new SortKey(tblInstanceSeed.convertColumnIndexToModel(i), sortKeys.get(k).getSortOrder()));
            }
        }
    }
    tblInstanceSeed.getRowSorter().setSortKeys(newSortKeys);
    edacc.experiment.Util.updateTableColumnWidth(tblInstanceSeed);
}
项目:edacc_gui    文件:EDACCExperimentModeClientDialog.java   
private void btnBrowserColumnSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowserColumnSelectionActionPerformed
    List<SortKey> sortKeys = (List<SortKey>) tblJobs.getRowSorter().getSortKeys();
    List<String> columnNames = new ArrayList<String>();
    for (SortKey sk : sortKeys) {
        columnNames.add(tblJobs.getColumnName(tblJobs.convertColumnIndexToView(sk.getColumn())));
    }
    EDACCResultsBrowserColumnSelection dialog = new EDACCResultsBrowserColumnSelection(EDACCApp.getApplication().getMainFrame(), true, jobsColumnSelector, jobsTableModel);
    dialog.setLocationRelativeTo(EDACCApp.getApplication().getMainFrame());
    dialog.setVisible(true);
    List<SortKey> newSortKeys = new ArrayList<SortKey>();
    for (int k = 0; k < columnNames.size(); k++) {
        String col = columnNames.get(k);
        for (int i = 0; i < tblJobs.getColumnCount(); i++) {
            if (tblJobs.getColumnName(i).equals(col)) {
                newSortKeys.add(new SortKey(tblJobs.convertColumnIndexToModel(i), sortKeys.get(k).getSortOrder()));
            }
        }
    }
    tblJobs.getRowSorter().setSortKeys(newSortKeys);
    Util.updateTableColumnWidth(tblJobs);        
}
项目:edacc_gui    文件:EDACCManageDBMode.java   
private void btnSelectInstanceColumnsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelectInstanceColumnsActionPerformed
    instanceTableModel.updateProperties();
    List<SortKey> sortKeys = (List<SortKey>) tableInstances.getRowSorter().getSortKeys();
    List<String> columnNames = new ArrayList<String>();
    for (SortKey sk : sortKeys) {
        columnNames.add(tableInstances.getColumnName(tableInstances.convertColumnIndexToView(sk.getColumn())));
    }
    EDACCManageInstanceColumnSelection dialog = new EDACCManageInstanceColumnSelection(EDACCApp.getApplication().getMainFrame(), true, instanceTableModel);
    dialog.setLocationRelativeTo(EDACCApp.getApplication().getMainFrame());
    dialog.setVisible(true);
    List<SortKey> newSortKeys = new ArrayList<SortKey>();
    for (int k = 0; k < columnNames.size(); k++) {
        String col = columnNames.get(k);
        for (int i = 0; i < tableInstances.getColumnCount(); i++) {
            if (tableInstances.getColumnName(i).equals(col)) {
                newSortKeys.add(new SortKey(tableInstances.convertColumnIndexToModel(i), sortKeys.get(k).getSortOrder()));
            }
        }
    }
    tableInstances.getRowSorter().setSortKeys(newSortKeys);
    edacc.experiment.Util.updateTableColumnWidth(tableInstances);
    instanceTableModel.fireTableDataChanged();
    instanceTableModel.updateProperties();
    tableInstances.updateUI();
}
项目:edacc_gui    文件:EDACCExperimentMode.java   
private void btnBrowserColumnSelectionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowserColumnSelectionActionPerformed
    updateJobBrowserProperties();

    List<SortKey> sortKeys = (List<SortKey>) tableJobs.getRowSorter().getSortKeys();
    List<String> columnNames = new ArrayList<String>();
    for (SortKey sk : sortKeys) {
        columnNames.add(tableJobs.getColumnName(tableJobs.convertColumnIndexToView(sk.getColumn())));
    }
    EDACCResultsBrowserColumnSelection dialog = new EDACCResultsBrowserColumnSelection(EDACCApp.getApplication().getMainFrame(), true, jobsColumnSelector, jobsTableModel);
    dialog.setLocationRelativeTo(EDACCApp.getApplication().getMainFrame());
    dialog.setVisible(true);
    List<SortKey> newSortKeys = new ArrayList<SortKey>();
    for (int k = 0; k < columnNames.size(); k++) {
        String col = columnNames.get(k);
        for (int i = 0; i < tableJobs.getColumnCount(); i++) {
            if (tableJobs.getColumnName(i).equals(col)) {
                newSortKeys.add(new SortKey(tableJobs.convertColumnIndexToModel(i), sortKeys.get(k).getSortOrder()));
            }
        }
    }
    tableJobs.getRowSorter().setSortKeys(newSortKeys);
    Util.updateTableColumnWidth(tableJobs);
}
项目:jdal    文件:PageableTable.java   
/**
 * 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);
}
项目:JRLib    文件:SubstanceTableUI.java   
private boolean isSameSorter(List<? extends SortKey> sortKeys1,
        List<? extends SortKey> sortKeys2) {
    int size1 = (sortKeys1 == null) ? 0 : sortKeys1.size();
    int size2 = (sortKeys2 == null) ? 0 : sortKeys2.size();
    if ((size1 == 0) && (size2 == 0)) {
        return true;
    }
    if ((sortKeys1 == null) && (sortKeys2 == null))
        return true;
    if ((sortKeys1 == null) || (sortKeys2 == null))
        return false;
    if (size1 != size2)
        return false;
    for (int i = 0; i < size1; i++) {
        SortKey sortKey1 = sortKeys1.get(i);
        SortKey sortKey2 = sortKeys2.get(i);
        if ((sortKey1.getColumn() != sortKey2.getColumn())
                || (sortKey1.getSortOrder() != sortKey2.getSortOrder())) {
            return false;
        }
    }
    return true;
}
项目:JRLib    文件:SubstanceTableUI.java   
@SuppressWarnings("unchecked")
public void valueChanged(final ListSelectionEvent e) {
    // fix for issue 478 - no animations when sorter has changed
    List<? extends SortKey> sortKeys = (table.getRowSorter() == null) ? null
            : table.getRowSorter().getSortKeys();
    boolean isDifferentSorter = !isSameSorter(sortKeys, oldSortKeys);
    if (e.getValueIsAdjusting() && isDifferentSorter)
        return;
    if (sortKeys == null) {
        oldSortKeys = null;
    } else {
        oldSortKeys = new ArrayList<SortKey>();
        for (SortKey sortKey : sortKeys) {
            SortKey copy = new SortKey(sortKey.getColumn(),
                    sortKey.getSortOrder());
            oldSortKeys.add(copy);
        }
    }
    syncSelection(isDifferentSorter);
}
项目:AgentWorkbench    文件:TimeSeriesTableModel.java   
/**
     * Removes a time series from the table model
     * @param seriesIndex The index of the series to be removed
     * @throws NoSuchSeriesException Will be thrown if there is no series with the specified index
     */
    public void removeSeries(int seriesIndex) throws NoSuchSeriesException {

        SortKey sortKey = this.getSortKey();

        if (this.getColumnCount()==2) {
            // --- The last series has to be removed ------
            this.initilizeTabelModel();

        } else {
            int column2remove = seriesIndex+1;  // Column 0 contains the time stamps
            if(column2remove <= this.getColumnCount()){
                columnTitles.remove(column2remove);
                java.util.Iterator<Vector<Number>> rows = tableModelDataVector.iterator();
                while(rows.hasNext()){
                    rows.next().remove(column2remove);
                }
            }
//          else{
//              throw new NoSuchSeriesException();
//          }

        }
        fireTableStructureChanged();

        if(this.getColumnCount() > 0){
            this.setSortKey(sortKey);
        }
    }
项目:AgentWorkbench    文件:TimeSeriesTableModel.java   
private void setSortKey(SortKey sortKey){
    if(sortKey != null){
        Vector<SortKey> keyVector = new Vector<SortKey>();
        keyVector.addElement(sortKey);
        myJTable.getRowSorter().setSortKeys(keyVector);
    }
}
项目: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;
        }
    }
}
项目:rapidminer    文件:TableHeaderUI.java   
/**
 * 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;
}
项目:smile_1.5.0_java7    文件:DefaultTableHeaderCellRenderer.java   
/**
 * 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
 */
@SuppressWarnings("rawtypes")
protected SortKey getSortKey(JTable table, int column) {
    RowSorter rowSorter = table.getRowSorter();
    if (rowSorter == null) {
        return null;
    }

    List sortedColumns = rowSorter.getSortKeys();
    if (!sortedColumns.isEmpty()) {
        return (SortKey) sortedColumns.get(0);
    }
    return null;
}
项目: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 );
}
项目: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);
}
项目:somado    文件:TableFilters.java   
/**
 * Aktualizacja modelu tabeli w zwiazku ze zmianami filtrow
 */
private void doUpdate() {

   Map<String, String> params = getParams();

   // zachowanie kluczy sortowania
   List<? extends SortKey> sortKeys = objTable.getRowSorter().getSortKeys();
   // zmiana modelu
   objTable.setModel(tablePanel.getNewTableModel(params));
   // przywrocenie szerokosci kolumn i kluczy sortowania
   tablePanel.afterModelChange();
   objTable.getRowSorter().setSortKeys(sortKeys);

}
项目:rapidminer-studio    文件: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;
        }
    }
}
项目:rapidminer-studio    文件:TableHeaderUI.java   
/**
 * 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;
}
项目:mars-sim    文件:DefaultTableHeaderCellRenderer.java   
/**
 * 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");
    }
  }
  return null;
}
项目:mars-sim    文件:DefaultTableHeaderCellRenderer.java   
/**
 * 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;
}
项目:swingx    文件:JXTable.java   
/**
 * Returns the view column index of the primary sort column. 
 * 
 * @return the view column index of the primary sort column or -1 if nothing
 * sorted or the primary sort column not visible.
 */
public int getSortedColumnIndex() {
    RowSorter<?> controller = getRowSorter();
    if (controller != null) {
        SortKey sortKey = SortUtils.getFirstSortingKey(controller.getSortKeys());
        if (sortKey != null) {
            return convertColumnIndexToView(sortKey.getColumn());
        }
    }
    return -1;
}
项目:swingx    文件:JXTableUnitTest.java   
/**
 * For comparison ...
 * 
 * Issue #1132-swingx: JXTable - define and implement behaviour on remove column
 */
@Test
public void testSortStateAfterRemoveColumn() {
    JTable table = new JTable();
    table.setAutoCreateRowSorter(true);
    table.setModel(new AncientSwingTeam());
    table.getRowSorter().toggleSortOrder(0);
    List<? extends SortKey> sortKeys = table.getRowSorter().getSortKeys();
    table.removeColumn(table.getColumnModel().getColumn(0));
    assertEquals(sortKeys, table.getRowSorter().getSortKeys());
}
项目:swingx    文件:SortControllerIssues.java   
/**
 * Issue #1156-swingx: sorter must use comparable if available
 * ListSortController
 */
@Test
public void testComparableComparatorList() {
    ListModel model = new DefaultComboBoxModel(new Integer[] {10, 2});
    ListSortController<ListModel> sorter = new ListSortController<ListModel>(model);
    List<SortKey> keys = new ArrayList<SortKey>();
    keys.add(new SortKey(0, SortOrder.ASCENDING));
    sorter.setSortKeys(keys);
    assertEquals(0, sorter.convertRowIndexToModel(1));
}
项目:swingx    文件:AbstractTestSortController.java   
/**
 * Test that resetSortOrders doesn't change sorts at all if controller is not sortable.
 * Does nothing if columnCount < 2.
 */
@Test
public void testResetSortOrdersIfSortableFalse() {
    if (getColumnCount() < 2) return;
    controller.toggleSortOrder(0);
    controller.toggleSortOrder(1);
    controller.setSortable(false);
    List<? extends SortKey> keys = controller.getSortKeys();
    assertEquals(2, keys.size());
    controller.resetSortOrders();
    assertEquals("resetSortOrders must not touch unsortable columns", 
            keys, controller.getSortKeys());
}