/** * Creates and returns a RowSorterListener which re-fires received * events. * * @return */ protected RowSorterListener getRowSorterListener() { if (rowSorterListener == null) { RowSorterListener listener = new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { if (RowSorterEvent.Type.SORT_ORDER_CHANGED == e.getType()) { fireSortOrderChanged(); } else if (RowSorterEvent.Type.SORTED == e.getType()) { fireRowSorterChanged(null); } } }; rowSorterListener = listener; } return rowSorterListener; }
void fireRowSorterChanged(RowSorterEvent event) { Object[] listeners = listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == RowSorterListener.class) { ((RowSorterListener) listeners[i + 1]).sorterChanged(event); } } }
/** * Creates a new instance of <code>AbstractInstrumentsDbTable</code> */ public AbstractInstrumentsDbTable(InstrumentsDbTableModel model, String tablePrefix) { super(model); setView(CC.getViewConfig().getInstrumentsDbTableView()); this.tablePrefix = tablePrefix; loadColumnsVisibleState(); loadColumnWidths(); setAutoResizeMode(AUTO_RESIZE_OFF); rowSorter = new InstrumentsDbTableRowSorter(getModel()); setRowSorter(rowSorter); loadSortOrder(); RowSorterListener l = new RowSorterListener() { public void sorterChanged(RowSorterEvent e) { if(e.getType() != SORT_ORDER_CHANGED) return; rowSorterChanged(); } }; getRowSorter().addRowSorterListener(l); putClientProperty("JTable.autoStartsEdit", false); nameEditor = new DefaultCellEditor(tfEditor); nameEditor.setClickCountToStart(5); if( getModel().getShowDummyColumn()) { TableColumn dummy; dummy = getColumnModel().getColumn(getModel().getDummyColumnIndex()); dummy.setPreferredWidth(10); } }
/** * Creates and returns a RowSorterListener. This implementation * calls sortedChanged if the event is of type SORTED. * * @return rowSorterListener to install on sorter. */ protected RowSorterListener createRowSorterListener() { RowSorterListener l = new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { if (e.getType() == RowSorterEvent.Type.SORTED) { sortedChanged(e); } } }; return l; }
protected void fireSortOrderChanged() { RowSorterEvent event = new RowSorterEvent(this); RowSorterListener[] listenerArray = (RowSorterListener[]) listeners.toArray(); for (int i=0; i<listenerArray.length; i++) { listenerArray[i].sorterChanged(event); } }
protected void fireRowSorterChanged(int[] lastRowIndexToModel) { RowSorterEvent event = new RowSorterEvent(this, RowSorterEvent.Type.SORTED, lastRowIndexToModel); RowSorterListener[] listenerArray = (RowSorterListener[]) listeners.toArray(); for (int i=0; i<listenerArray.length; i++) { listenerArray[i].sorterChanged(event); } }
public void addRowSorterListener(RowSorterListener l) { listenerList.add(RowSorterListener.class, l); }
public void removeRowSorterListener(RowSorterListener l) { listenerList.remove(RowSorterListener.class, l); }
private void createTablePanel(JPanel tablePanel) { tablePanel.setLayout(new GridBagLayout()); keyTable = new JTable(keyDefTableModel); JScrollPane scrollPane = new JScrollPane(keyTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); enableSorting(keyTable); keyTable.getTableHeader().setReorderingAllowed(false); keyTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); keyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); keyTable.getColumnModel().getColumn(0).setPreferredWidth(25); keyTable.getColumnModel().getColumn(0).setMaxWidth(30); keyTable.getColumnModel().getColumn(0).setResizable(false); keyTable.getColumnModel().getColumn(1).setPreferredWidth(150); keyTable.getColumnModel().getColumn(2).setPreferredWidth(150); keyTable.getColumnModel().getColumn(3).setPreferredWidth(150); keyTable.getColumnModel().getColumn(4).setPreferredWidth(150); GridBagConstraints localConstr = new GridBagConstraints(); localConstr.insets = new Insets(2, 2, 2, 2); localConstr.anchor = GridBagConstraints.WEST; localConstr.fill = GridBagConstraints.BOTH; localConstr.gridx = 0; localConstr.gridy = 0; localConstr.weightx = 1; localConstr.weighty = 1; DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer(); centerRenderer.setHorizontalAlignment(JLabel.CENTER); keyTable.getColumnModel().getColumn(0).setCellRenderer(centerRenderer); tablePanel.add(scrollPane, localConstr); sorter = new TableRowSorter<>(keyDefTableModel); sorter.toggleSortOrder(0); sorter.toggleSortOrder(0); // initial sorting be priority descending sorter.addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged (RowSorterEvent e) { if (e.getType () == RowSorterEvent.Type.SORTED) { int selection = keyTable.getSelectedRow(); if (selection >= 0) { boxAction = false; reloadBoxItems(); updateComboBoxes(); boxAction = true; keyTable.setRowSelectionInterval(selection, selection); Rectangle selectRect = keyTable.getCellRect(selection, 0, true); selectRect.height = (keyTable.getParent().getHeight() / 2); keyTable.scrollRectToVisible(selectRect); } else { if (keyTable.getRowCount() > 0) { keyTable.changeSelection(0, 0, false, false); boxAction = false; reloadBoxItems(); updateComboBoxes(); boxAction = true; } } } } }); keyTable.setRowSorter(sorter); }
public void addRowSorterListener(RowSorterListener l) { if (l == null) return; listeners.add(l); }
public void removeRowSorterListener(RowSorterListener l) { if (l == null) return; listeners.remove(l); }
@Override public void addRowSorterListener(RowSorterListener l) { if(!ignoreAddRowSorterListener) { super.addRowSorterListener(l); } }
@Override public void addRowSorterListener(RowSorterListener l) {}
@Override public void removeRowSorterListener(RowSorterListener l) {}