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

下面列出了怎么用javax.swing.RowSorter.SortKey的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: radiance   文件: 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;
}
 
源代码2 项目: radiance   文件: SubstanceTableUI.java
@Override
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<>();
        for (SortKey sortKey : sortKeys) {
            SortKey copy = new SortKey(sortKey.getColumn(), sortKey.getSortOrder());
            oldSortKeys.add(copy);
        }
    }
    syncSelection(isDifferentSorter);
}
 
源代码3 项目: 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;
}
 
源代码4 项目: 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;
}
 
源代码5 项目: 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);
}
 
源代码6 项目: 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 );
}
 
源代码7 项目: 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;
		}
	}
}
 
源代码8 项目: 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;
}
 
源代码9 项目: 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;
}
 
源代码10 项目: 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;
}
 
源代码11 项目: jdal   文件: PageableTable.java
/**
 * Convert the Order from SortKey to Page.Order
 * @param key the SortKey
 * @return  the Page order
 */
private Page.Order converSortOrder(RowSorter.SortKey key) {
	Page.Order order = Order.ASC;
	if (key.getSortOrder() == SortOrder.DESCENDING) {
		order = Order.DESC;
	}
	return order;
}
 
源代码12 项目: arcusplatform   文件: ProductListView.java
protected Component createListSelector() {
   TableModel<ProductModel> tableModel = createTableModel();
   TableRowSorter<TableModel<ProductModel>> sorter = new TableRowSorter<>(tableModel);
   sorter.setSortKeys(ImmutableList.<SortKey>of(
         new RowSorter.SortKey(0, SortOrder.UNSORTED),
         new RowSorter.SortKey(1, SortOrder.UNSORTED)
   ));
   Table<ProductModel> table = new Table<>(tableModel);
   table.setRowSorter(sorter);
   table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
      @Override
      public void valueChanged(ListSelectionEvent e) {
         if(e.getValueIsAdjusting()) {
            return;
         }
         int selected = table.getSelectedRow();
         if(selected == -1) {
            selectionModel.clearSelection();
         }
         else {
            selected = table.getRowSorter().convertRowIndexToModel(selected);
            selectionModel.setSelection(table.getModel().getValue(selected));
         }
      }
   });
   // TODO wrap this into a selection listener
   table.addMouseListener(new MouseAdapter() {
      @Override
      public void mousePressed(MouseEvent me) {
         if (me.getClickCount() == 2) {
            Point p = me.getPoint();
            int row = table.rowAtPoint(p);
            int offset = table.convertRowIndexToModel(row);
            ProductModel model = table.getModel().getValue(offset);
            controller.getProductSelection().setSelection(model);
         }
     }
   });
   return new JScrollPane(table);
}
 
源代码13 项目: scelight   文件: EnvVarsPage.java
@Override
public JComponent createPageComp() {
	final BorderPanel p = new BorderPanel();
	
	final XTable table = new XTable();
	
	final Vector< Vector< Object > > data = new Vector<>();
	
	for ( final Entry< String, String > entry : System.getenv().entrySet() )
		data.add( Utils.vector( entry.getKey(), entry.getValue() ) );
	
	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;
}
 
源代码14 项目: scelight   文件: RepFoldersComp.java
/**
 * Rebuilds the table.
 * 
 * @param rebuildHeader tells if column headers are also to be rebuilt
 */
private void rebuildTable( final boolean rebuildHeader ) {
	table.saveSelection( beanColIdx );
	
	// Model cannot be updated while editing, so stop editing if it is in progress!
	if ( table.isEditing() )
		table.getCellEditor().stopCellEditing();
	
	final XTableModel model = table.getXTableModel();
	
	final boolean showRepsCount = Env.APP_SETTINGS.get( Settings.SHOW_REPLAYS_COUNT );
	
	if ( rebuildHeader ) {
		// Re-set column headers
		final Vector< String > columns = Utils.asNewVector( "Bean", "I", "Folder", "Include sub-folders?", "Monitored?", "Filters", "Position", "Comment",
		        "# of Replays" );
		final List< Class< ? > > columnClasses = Utils.< Class< ? > > asNewList( RepFolderBean.class, TableIcon.class, Path.class, Boolean.class,
		        Boolean.class, Integer.class, Integer.class, String.class, Integer.class );
		beanColIdx = 0;
		pathColIdx = 2;
		recursiveColIdx = 3;
		monitoredColIdx = 4;
		filtersColIdx = 5;
		positionColIdx = 6;
		commentColIdx = 7;
		countColIdx = 8;
		table.setEditableColModelIndices( pathColIdx, recursiveColIdx, monitoredColIdx, commentColIdx );
		table.getXTableRowSorter().setColumnDefaultDescs( true, recursiveColIdx, monitoredColIdx, filtersColIdx, countColIdx );
		
		model.setColumnIdentifiers( columns );
		model.setColumnClasses( columnClasses );
		if ( !showRepsCount )
			table.getColumnModel().removeColumn( table.getColumnModel().getColumn( countColIdx ) );
		table.getColumnModel().removeColumn( table.getColumnModel().getColumn( beanColIdx ) );
		table.getRowSorter().setSortKeys( Arrays.asList( new SortKey( positionColIdx, SortOrder.ASCENDING ) ) );
	}
	
	// Build table data
	model.getDataVector().clear();
	model.fireTableDataChanged();
	final RepFoldersBean rfsBean = Env.APP_SETTINGS.get( Settings.REPLAY_FOLDERS_BEAN );
	int pos = 1;
	for ( final RepFolderBean rfBean : rfsBean.getReplayFolderBeanList() ) {
		final Vector< Object > row = Utils.< Object > asNewVector( rfBean, rfBean.getOrigin().tableIcon, rfBean.getPath(), rfBean.getRecursive(),
		        rfBean.getMonitored(), rfBean.getActiveFilterCount(), pos++, rfBean.getComment(), rfBean.getReplaysCount() );
		model.addRow( row );
	}
	
	// Pack all columns except the path and comment columns (leave remaining space for them)
	for ( int i = table.getColumnCount() - 1; i >= 0; i-- )
		if ( i != table.convertColumnIndexToView( pathColIdx ) && i != table.convertColumnIndexToView( commentColIdx ) )
			table.packColumns( i );
	
	table.restoreSelection( beanColIdx );
}
 
源代码15 项目: megamek   文件: UnitSelectorDialog.java
public void run() {
    // Loading mechs can take a while, so it will have its own thread.
    // This prevents the UI from freezing, and allows the
    // "Please wait..." dialog to behave properly on various Java VMs.
    MechSummaryCache mscInstance = MechSummaryCache.getInstance();
    mechs = mscInstance.getAllMechs();

    // break out if there are no units to filter
    if (mechs == null) {
        System.err.println("No units to filter!");
    } else {
        unitModel.setData(mechs);
    }
    filterUnits();

    //initialize with the units sorted alphabetically by chassis
    ArrayList<SortKey> sortlist = new ArrayList<>();
    sortlist.add(new SortKey(MechTableModel.COL_CHASSIS,SortOrder.ASCENDING));
    //sortlist.add(new RowSorter.SortKey(MechTableModel.COL_MODEL,SortOrder.ASCENDING));
    tableUnits.getRowSorter().setSortKeys(sortlist);
    ((DefaultRowSorter<?, ?>)tableUnits.getRowSorter()).sort();

    tableUnits.invalidate(); // force re-layout of window
    pack();
    //setLocation(computeDesiredLocation());

    unitLoadingDialog.setVisible(false);

    // In some cases, it's possible to get here without an initialized
    // instance (loading a saved game without a cache).  In these cases,
    // we dn't care about the failed loads.
    if (mscInstance.isInitialized() && !useAlternate)
    {
        final Map<String, String> hFailedFiles =
            MechSummaryCache.getInstance().getFailedFiles();
        if ((hFailedFiles != null) && (hFailedFiles.size() > 0)) {
            // self-showing dialog
            new UnitFailureDialog(frame, hFailedFiles);
        }
    }
    GUIPreferences guip = GUIPreferences.getInstance();
    int width = guip.getMechSelectorSizeWidth();
    int height = guip.getMechSelectorSizeHeight();
    setSize(width,height);
}
 
源代码16 项目: dsworkbench   文件: RankTableTab.java
/**
 * Creates new form AttackTablePanel
 */
public RankTableTab(RANK_TYPE pType, final ActionListener pActionListener) {
    eType = pType;
    initComponents();
    switch (eType) {
        case TRIBE: {
            buildTribeModel();
            break;
        }
        case ALLY: {
            buildAllyModel();
            break;
        }
        case TRIBE_BASH: {
            buildTribeBashModel();
            break;
        }
        case ALLY_BASH: {
            buildAllyBashModel();
            break;
        }
    }
    jScrollPane1.setViewportView(jxRankTable);
    jxRankTable.setRowHeight(24);
    jxRankTable.setHighlighters(HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B));
    jxRankTable.setColumnControlVisible(true);
    jxRankTable.setModel(theModel);
    List<SortKey> keys = new LinkedList<>();
    keys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
    jxRankTable.getRowSorter().setSortKeys(keys);
    jxRankTable.setDefaultRenderer(Integer.class, new NumberFormatCellRenderer());
    jxRankTable.setDefaultRenderer(Double.class, new NumberFormatCellRenderer());

    jxRankTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            pActionListener.actionPerformed(new ActionEvent(jxRankTable, 0, "Find"));
        }
    });

    jxRankTable.getSelectionModel().addListSelectionListener(RankTableTab.this);
}
 
 类所在包
 同包方法