Java 类javax.swing.RowSorter 实例源码

项目:incubator-netbeans    文件:ProfilerRowSorter.java   
public void setSortKeys(List newKeys) {
    if (newKeys == null) {
        setSortKeysImpl(newKeys);
        return;
    }

    RowSorter.SortKey oldKey = getSortKey();
    RowSorter.SortKey newKey = (RowSorter.SortKey)newKeys.get(0);

    if (oldKey == null || oldKey.getColumn() != newKey.getColumn()) {
        // Use defined initial SortOrder for a newly sorted column
        setSortColumn(newKey.getColumn());
    } else {
        setSortKeysImpl(newKeys);
    }
}
项目:smile_1.5.0_java7    文件:MultiColumnSortTableHeaderCellRenderer.java   
/**
 * Overridden to return an icon suitable to a sorted column, or null if the
 * column is unsorted. The icon for the primary sorted column is fully
 * opaque, and the opacity is reduced by a factor of
 * <code>alpha</code> for each subsequent sort index.
 *
 * @param table the <code>JTable</code>.
 * @param column the column index.
 * @return the sort icon with appropriate opacity, or null if the column is
 * unsorted.
 */
@Override
public Icon getIcon(JTable table, int column) {
    float computedAlpha = 1.0F;
    for (RowSorter.SortKey sortKey : table.getRowSorter().getSortKeys()) {
        if (table.convertColumnIndexToView(sortKey.getColumn()) == column) {
            switch (sortKey.getSortOrder()) {
                case ASCENDING:
                    return new AlphaIcon(UIManager.getIcon("Table.ascendingSortIcon"), computedAlpha);
                case DESCENDING:
                    return new AlphaIcon(UIManager.getIcon("Table.descendingSortIcon"), computedAlpha);

                default:
                    // Just to remove unmatched case warning
            }
        }
        computedAlpha *= alpha;
    }
    return null;
}
项目: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;
}
项目:jailer    文件:DetailsView.java   
/** Creates new form DetailsView 
     * @param rowSorter 
    */
    public DetailsView(List<Row> rows, int size, DataModel dataModel, Table table, int rowIndex, RowSorter<? extends TableModel> rowSorter, boolean showSpinner) {
        this.table = table;
        this.rows = rows;
        this.rowSorter = rowSorter;
        initComponents();
        if (rowSorter != null) {
            rowIndex = rowSorter.convertRowIndexToView(rowIndex);
        }
        final SpinnerNumberModel model = new SpinnerNumberModel(rowIndex + 1, 1, size, -1);
        rowSpinner.setModel(model);
        rowSpinner.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                setCurrentRow((Integer) model.getValue() - 1, true);
            }
        });
        if (!showSpinner) {
            jLabel1.setVisible(false);
            rowSpinner.setVisible(false);
//          jScrollPane1.setBorder(null);
            jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        }
        setCurrentRow(rowIndex, showSpinner);
    }
项目:GitDirStat    文件:RowSorterAwareListSelectionModelUpdater.java   
public void setSourceModel(ListSelectionModel listSelectionModel,
        RowSorter<?> rowSorter) {
    if (this.sourceModel != null) {
        this.sourceModel.removeListSelectionListener(targetModelSync);
    }

    if (rowSorter == null) {
        targetModelSync.setIndexConverter(null);
        sourceModelSync.setIndexConverter(null);
    } else {
        targetModelSync
                .setIndexConverter(new ViewToModelRowSorterConverter(
                        rowSorter));
        sourceModelSync
                .setIndexConverter(new ModelToViewRowSorterConverter(
                        rowSorter));
    }
    this.sourceModel = listSelectionModel;
    if (this.sourceModel != null) {
        sourceModelSync.setTargetModel(sourceModel, targetModelSync);
        this.sourceModel.addListSelectionListener(targetModelSync);
    }
}
项目: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();
}
项目:mars-sim    文件:MultisortTableHeaderCellRenderer.java   
/**
 * Overridden to return an icon suitable to a sorted column, or null if the column is unsorted.
 * The icon for the primary sorted column is fully opaque, and the opacity is reduced by a
 * factor of <code>alpha</code> for each subsequent sort index.
 *
 * @param table the <code>JTable</code>.
 * @param column the column index.
 * @return the sort icon with appropriate opacity, or null if the column is unsorted.
 */
public Icon getIcon(JTable table, int column) {
  float computedAlpha = 1.0F;
  for (RowSorter.SortKey sortKey : table.getRowSorter().getSortKeys()) {
    if (table.convertColumnIndexToView(sortKey.getColumn()) == column) {
      switch (sortKey.getSortOrder()) {
        case ASCENDING:
          return new AlphaIcon(UIManager.getIcon("Table.ascendingSortIcon"), computedAlpha);
        case DESCENDING:
          return new AlphaIcon(UIManager.getIcon("Table.descendingSortIcon"), computedAlpha);
      }
    }
    computedAlpha *= alpha;
  }
  return null;
}
项目:vso-intellij    文件:ImportForm.java   
public void setTeamProjectTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) {
    teamProjectTable.setModel(tableModel);
    teamProjectTable.setSelectionModel(selectionModel);

    // Setup table sorter
    final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    teamProjectTable.setRowSorter(sorter);

    // Attach an index converter to fix the indexes if the user sorts the list
    tableModel.setSelectionConverter(new TableModelSelectionConverter() {
        @Override
        public int convertRowIndexToModel(int viewRowIndex) {
            if (viewRowIndex >= 0) {
                return teamProjectTable.convertRowIndexToModel(viewRowIndex);
            }

            return viewRowIndex;
        }
    });
}
项目:vso-intellij    文件:TeamServicesSettingsForm.java   
public void setContextTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) {
    contextTable.setModel(tableModel);
    contextTable.setSelectionModel(selectionModel);

    // Setup table sorter
    final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    contextTable.setRowSorter(sorter);

    // Attach an index converter to fix the indexes if the user sorts the list
    tableModel.setSelectionConverter(new TableModelSelectionConverter() {
        @Override
        public int convertRowIndexToModel(int viewRowIndex) {
            if (viewRowIndex >= 0) {
                return contextTable.convertRowIndexToModel(viewRowIndex);
            }
            return viewRowIndex;
        }
    });
}
项目:vso-intellij    文件:SelectWorkItemsForm.java   
public void setWorkItemTable(final WorkItemsTableModel tableModel, final ListSelectionModel selectionModel) {
    workItemTable.setModel(tableModel);
    workItemTable.setSelectionModel(selectionModel);

    // Setup table sorter
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    workItemTable.setRowSorter(sorter);

    // Attach an index converter to fix the indexes if the user sorts the list
    tableModel.setSelectionConverter(new TableModelSelectionConverter() {
        @Override
        public int convertRowIndexToModel(int viewRowIndex) {
            if (viewRowIndex >= 0) {
                return workItemTable.convertRowIndexToModel(viewRowIndex);
            }

            return viewRowIndex;
        }
    });
}
项目:vso-intellij    文件:CheckoutForm.java   
public void setRepositoryTable(final ServerContextTableModel tableModel, final ListSelectionModel selectionModel) {
    repositoryTable.setModel(tableModel);
    repositoryTable.setSelectionModel(selectionModel);

    // Setup table sorter
    RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    repositoryTable.setRowSorter(sorter);

    // Attach an index converter to fix the indexes if the user sorts the list
    tableModel.setSelectionConverter(new TableModelSelectionConverter() {
        @Override
        public int convertRowIndexToModel(int viewRowIndex) {
            if (viewRowIndex >= 0) {
                return repositoryTable.convertRowIndexToModel(viewRowIndex);
            }

            return viewRowIndex;
        }
    });
}
项目: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;
}
项目:JBroTable    文件:JBroTableHeaderUI.java   
@Override
public void mouseClicked( MouseEvent e ) {
  JBroTableHeader header = getHeader();
  if ( !header.isEnabled() )
    return;
  Point point = e.getPoint();
  JBroTableColumn column = getColumnAtPoint( point );
  if ( column == null )
    return;
  if ( isLeaf( column ) && e.getClickCount() == 1 && SwingUtilities.isLeftMouseButton( e ) ) {
    JTable table = header.getTable();
    RowSorter sorter;
    if ( table != null && ( sorter = table.getRowSorter() ) != null ) {
      int columnIndex = column.getModelIndex();
      if ( columnIndex != -1 ) {
        sorter.toggleSortOrder( columnIndex );
        header.repaint();
      }
    }
  }
}
项目:JBroTable    文件:JBroPredefinedRowSorter.java   
private RowSorter.SortKey[] toNumericKeys( SortKey... modelColumns ) {
  if ( modelColumns != null && modelColumns.length != 0 ) {
    JBroTable table = getTable();
    ModelData data = table.getData();
    RowSorter.SortKey keys[] = new RowSorter.SortKey[ modelColumns.length ];
    for ( int i = 0; i < modelColumns.length; i++ ) {
      SortKey modelColumn = modelColumns[ i ];
      int col = data.getIndexOfModelField( modelColumn.getColumn() );
      if ( col < 0 )
        throw new IllegalArgumentException( "Field \"" + modelColumn.getColumn() + "\" not found" );
      RowSorter.SortKey key = new RowSorter.SortKey( col, modelColumn.getSortOrder() );
      keys[ i ] = key;
    }
    return keys;
  }
  return null;
}
项目:JBroTable    文件:JBroPredefinedRowSorter.java   
private SortKey[] toStringKeys( RowSorter.SortKey... modelColumns ) {
  if ( modelColumns != null && modelColumns.length != 0 ) {
    JBroTable table = getTable();
    ModelData data = table.getData();
    ModelField fields[] = data.getFields();
    SortKey keys[] = new SortKey[ modelColumns.length ];
    for ( int i = 0; i < modelColumns.length; i++ ) {
      RowSorter.SortKey modelColumn = modelColumns[ i ];
      ModelField col = fields[ modelColumn.getColumn() ];
      SortKey key = new SortKey( col.getIdentifier(), modelColumn.getSortOrder() );
      keys[ i ] = key;
    }
    return keys;
  }
  return EMPTY_ARRAY;
}
项目: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;
}
项目:GitDirStat    文件:RowSorterAwareListSelectionModelUpdater.java   
public void setSourceModel(ListSelectionModel listSelectionModel,
        RowSorter<?> rowSorter) {
    if (this.sourceModel != null) {
        this.sourceModel.removeListSelectionListener(targetModelSync);
    }

    if (rowSorter == null) {
        targetModelSync.setIndexConverter(null);
        sourceModelSync.setIndexConverter(null);
    } else {
        targetModelSync
                .setIndexConverter(new ViewToModelRowSorterConverter(
                        rowSorter));
        sourceModelSync
                .setIndexConverter(new ModelToViewRowSorterConverter(
                        rowSorter));
    }
    this.sourceModel = listSelectionModel;
    if (this.sourceModel != null) {
        sourceModelSync.setTargetModel(sourceModel, targetModelSync);
        this.sourceModel.addListSelectionListener(targetModelSync);
    }
}
项目:Zettelkasten    文件:Settings.java   
public void setTableSorting(javax.swing.JTable[] tables) {
    Element el = settingsFile.getRootElement().getChild(SETTING_TABLEROWSORTING);
    if (null == el) {
        el = new Element(SETTING_TABLEROWSORTING);
        settingsFile.getRootElement().addContent(el);
    }
    // iterate all tables
    for (javax.swing.JTable t : tables) {
        // check if table is valid
        if (t != null) {
            // get sorter for each table
            javax.swing.DefaultRowSorter sorter = (javax.swing.DefaultRowSorter) t.getRowSorter();
            // get sort keys (column, sort order)
            List<RowSorter.SortKey> sk = sorter.getSortKeys();
            if (sk != null && sk.size() > 0) {
                // get first element
                RowSorter.SortKey ssk = sk.get(0);
                // set sortcolumn and sort order
                String value = String.valueOf(ssk.getColumn()) + "," + ssk.getSortOrder().toString();
                el.setAttribute(t.getName(), value);
            }
        }
    }
}
项目:SubTools    文件:GUI.java   
private CustomTable createVideoTable() {
  CustomTable customTable = new CustomTable();
  customTable.setModel(VideoTableModel.getDefaultVideoTableModel());
  ((VideoTableModel) customTable.getModel()).setShowOnlyFound(settingsControl.getSettings()
      .isOptionsShowOnlyFound());
  ((VideoTableModel) customTable.getModel()).setSubtitleSelection(new SubtitleSelectionGUI(
      settingsControl.getSettings(), this));
  final RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(customTable.getModel());
  customTable.setRowSorter(sorter);
  customTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

  int columnId = customTable.getColumnIdByName(SearchColumnName.FOUND);
  customTable.getColumnModel().getColumn(columnId).setResizable(false);
  customTable.getColumnModel().getColumn(columnId).setPreferredWidth(100);
  customTable.getColumnModel().getColumn(columnId).setMaxWidth(100);
  columnId = customTable.getColumnIdByName(SearchColumnName.SELECT);
  customTable.getColumnModel().getColumn(columnId).setResizable(false);
  customTable.getColumnModel().getColumn(columnId).setPreferredWidth(85);
  customTable.getColumnModel().getColumn(columnId).setMaxWidth(85);
  customTable.hideColumn(SearchColumnName.OBJECT);
  customTable.hideColumn(SearchColumnName.SEASON);
  customTable.hideColumn(SearchColumnName.EPISODE);
  customTable.hideColumn(SearchColumnName.TYPE);
  customTable.hideColumn(SearchColumnName.TITLE);
  return customTable;
}
项目: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));
}
项目:TreeTable    文件:BasicTreeTableUI.java   
private boolean sortNode(MouseEvent e) {
    switch (e.getID()) {
    default:
        return false;
    case MouseEvent.MOUSE_RELEASED:
        try {
            return sortPressed;
        } finally {
            sortPressed = false;
        }
    case MouseEvent.MOUSE_PRESSED:
    }
    if (mouseOverSortPath == null)
        return false;
    TreeTableSorter<?,?> sorter = treeTable.getRowSorter();
    if (sorter == null)
        return false;
    RowSorter<?> nodeSorter = sorter.getRowSorter(mouseOverSortPath);
    if (nodeSorter == null)
        return false;
    nodeSorter.toggleSortOrder(table.convertColumnIndexToModel(mouseOverSortColumn));
    paintMouseOverSortPath = false;
    sortPressed = true;
    e.consume();
    return true;
}
项目:Lightstreamer-example-StockList-client-java    文件:StockView.java   
@Override
public synchronized void sorterChanged(RowSorterEvent e) {
    //the sort listener waits for changes on the sorted columns
    //if the first sort key is the stock_name or the open_price column
    //(that are fields that never change) it disable the dynamic sort
    if (e.getType().equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) {
        List<RowSorter.SortKey> keys = e.getSource().getSortKeys();
        if(!keys.isEmpty()) {
            int y = keys.get(0).getColumn();
            if (y != 0 && y != 11) {
                enableDynamicSort(true);
            } else {
                enableDynamicSort(false);
            }
        }
    } 
}
项目: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);
}
项目:jmetadata    文件:DescriptionTableHeader.java   
private Icon getIcon(JTable table, int column) {
    // DescriptionTable dTable = (DescriptionTable) table;
    if (table == null || table.getRowSorter() == null) {
        return UIManager.getIcon("Table.naturalSortIcon");
    }
    Icon sortIcon = null;

    List<? extends RowSorter.SortKey> sortKeys = table.getRowSorter().getSortKeys();
    if (sortKeys.size() > 0 && sortKeys.get(0).getColumn() == table.convertColumnIndexToModel(column)) {
        switch (sortKeys.get(0).getSortOrder()) {
        case ASCENDING:
            sortIcon = SynthIcons.SORT_ASCENDING_ICON;
            break;
        case DESCENDING:
            sortIcon = SynthIcons.SORT_DESCENDING_ICON;
            break;
        case UNSORTED:
            sortIcon = SynthIcons.SORT_NATURAL_ICON;
            break;
        default:
            throw new AssertionError("Cannot happen");
        }
    }

    return sortIcon;
}
项目:Jailer    文件:DetailsView.java   
/** Creates new form DetailsView 
     * @param rowSorter 
    */
    public DetailsView(List<Row> rows, int size, DataModel dataModel, Table table, int rowIndex, RowSorter<? extends TableModel> rowSorter, boolean showSpinner) {
        this.table = table;
        this.rows = rows;
        this.rowSorter = rowSorter;
        initComponents();
        if (rowSorter != null) {
            rowIndex = rowSorter.convertRowIndexToView(rowIndex);
        }
        final SpinnerNumberModel model = new SpinnerNumberModel(rowIndex + 1, 1, size, -1);
        rowSpinner.setModel(model);
        rowSpinner.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                setCurrentRow((Integer) model.getValue() - 1, true);
            }
        });
        if (!showSpinner) {
            jLabel1.setVisible(false);
            rowSpinner.setVisible(false);
//          jScrollPane1.setBorder(null);
            jScrollPane1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
            jScrollPane1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        }
        setCurrentRow(rowIndex, showSpinner);
    }
项目:GhostGrader    文件:AddNewStudent.java   
@SuppressWarnings({ "rawtypes", "unchecked" })
private void setup() {
       model = (DefaultTableModel)studentTable.getModel();
    TableRowSorter sorter = new TableRowSorter(model);
    sorter.setComparator(0, new Comparator(){
           @Override
           public int compare(Object arg0, Object arg1) {
               return arg0.toString().compareTo(arg1.toString());
           }
    });
       ArrayList sortKeys = new ArrayList();
       sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
       sorter.setSortKeys(sortKeys);
       studentTable.setRowSorter(sorter);
       sorter.sort();
   }
项目:GhostGrader    文件:EditSelectedClass.java   
@SuppressWarnings("unchecked")
private void setup() {
       model = (DefaultTableModel)assignmentTable.getModel();
    TableRowSorter sorter = new TableRowSorter(model);
    sorter.setComparator(0, new Comparator(){
           @Override
           public int compare(Object arg0, Object arg1) {
               return arg0.toString().compareTo(arg1.toString());
           }
    });
       if (parent.courses.get(courseIndex).getNumberOfAssignmentCategories() > 0) {
           loadCourseData();
       }
       ArrayList sortKeys = new ArrayList();
       sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
       sorter.setSortKeys(sortKeys);
       assignmentTable.setRowSorter(sorter);
       sorter.sort();
   }
项目:incubator-netbeans    文件:ETable.java   
/**
 * When ETable has ETableColumnModel set, only <code>null</code> sorter
 * is accepted, which turns off sorting. Otherwise UnsupportedOperationException is thrown.
 * RowSorter can be used when a different TableColumnModel is set.
 * 
 * @param sorter {@inheritDoc}
 */
@Override
public void setRowSorter(RowSorter<? extends TableModel> sorter) {
    if (getColumnModel() instanceof ETableColumnModel) {
        if (sorter == null) {
            sortable = false;
            ((ETableColumnModel) getColumnModel()).clearSortedColumns();
        } else {
            throw new UnsupportedOperationException(
                    "ETable with ETableColumnModel has it's own sorting mechanism. Use ETableColumnModel to define sorting, or set a different TableColumnModel.");
        }
    } else {
        super.setRowSorter(sorter);
    }
}
项目:incubator-netbeans    文件:ETable.java   
/**
 * Get the RowSorter in case that the ETable does not have ETableColumnModel set.
 * @return {@inheritDoc}
 */
@Override
public RowSorter<? extends TableModel> getRowSorter() {
    if (getColumnModel() instanceof ETableColumnModel) {
        return null;
    } else {
        return super.getRowSorter();
    }
}
项目:incubator-netbeans    文件:ProfilerRowSorter.java   
void setSortKey(RowSorter.SortKey key) {
    RowSorter.SortKey secondaryKey = secondarySortColumn == key.getColumn() ?
                      null : new RowSorter.SortKey(secondarySortColumn,
                      getDefaultSortOrder(secondarySortColumn));
    setSortKeysImpl(secondaryKey == null ? Arrays.asList(key) :
                      Arrays.asList(key, secondaryKey));
}
项目: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());
    }
}
项目: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;
}
项目:RxJava2Swing    文件:RowSorterEventObservable.java   
@Override
protected void subscribeActual(Observer<? super RowSorterEvent> observer) {
    RowSorter<?> w = widget;

    RowSorterEventConsumer aec = new RowSorterEventConsumer(observer, w);
    observer.onSubscribe(aec);

    w.addRowSorterListener(aec);
    if (aec.get() == null) {
        aec.onDispose(w);
    }
}
项目:finances    文件:TransactionTable.java   
public void setRowSorter(RowSorter<? extends TableModel> sorter) {
    if (! (sorter instanceof TransactionTableRowSorter)) {
        sorter = new TransactionTableRowSorter(this);
    }
    sorter.setSortKeys(Collections.singletonList(defaultSortKey()));
    super.setRowSorter(sorter);
}
项目:finances    文件:TransactionTableRowSorterTest.java   
@Test
public void defaultSortPutsNewDetailAtEndOfTransaction() throws Exception {
    TransactionTableModel model = new TransactionTableModel(new Account(1L));
    Transaction transaction = newTransaction(1L);
    model.addBean(newTransaction(2L));
    model.addBean(transaction);
    model.addBean(newTransaction(null));
    TransactionTable table = new TransactionTable(model);
    RowSorter<? extends TableModel> sorter = table.getRowSorter();

    model.queueAppendSubRow(model.getLeadRowForGroup(1));

    assertThat(sorter.convertRowIndexToView(model.getLeadRowForGroup(1) + transaction.getDetails().size()))
            .isEqualTo(model.getLeadRowForGroup(1) + transaction.getDetails().size());
}
项目:libraries    文件:JTableUtilities.java   
public static int getRealRowIndexAtPoint(final JTable table, final Point point) {
  final int rowIndex = table.rowAtPoint(point);
  final RowSorter<? extends TableModel> rowSorter = table.getRowSorter();
  if (rowSorter == null) {
    return rowIndex;
  }
  return rowSorter.convertRowIndexToModel(rowIndex);
}
项目:kdxplore    文件:CellSelectableTable.java   
@Override
public void setRowSorter(RowSorter<? extends TableModel> sorter) {
    if (sorter != null) {
        throw new IllegalArgumentException("Does not support setRowSorter(non-null)");
    }
    super.setRowSorter(null);
}
项目: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;
}