/** * Inovked when either the table has changed or the sorter has changed * and after the sorter has been notified. If necessary this will * reapply the selection and variable row heights. */ private void processChange(ModelChange change) { if (change != null && change.allRowsChanged) { allChanged(); getViewSelectionModel().clearSelection(); } else if (sorterChanged) { restoreSelection(change); } }
private void cacheModelSelection(RowSorterEvent sortEvent) { lastModelSelection = convertSelectionToModel(sortEvent); modelLeadIndex = convertRowIndexToModel(sortEvent, getViewSelectionModel().getLeadSelectionIndex()); }
/** * Dispose and null's the sortUI if installed. Does nothing if not. */ protected void uninstallSortUI() { if (sortUI == null) return; sortUI.dispose(); sortUI = null; }
sorter.getViewRowCount() != sorter.getModelRowCount()) { modelSelection = new DefaultListSelectionModel(); ListSelectionModel viewSelection = getViewSelectionModel(); int min = viewSelection.getMinSelectionIndex(); int max = viewSelection.getMaxSelectionIndex(); for (int viewIndex = min; viewIndex <= max; viewIndex++) { if (viewSelection.isSelectedIndex(viewIndex)) { modelIndex = convertRowIndexToModel( sortEvent, viewIndex); if (modelIndex != -1) { modelIndex = convertRowIndexToModel(sortEvent, viewSelection.getLeadSelectionIndex()); SwingXUtilities.setLeadAnchorWithoutSelection( cacheModelSelection(sortEvent);
/** * Restores the selection after a model event/sort order changes. * All coordinates are in terms of the model. */ private void restoreSortingSelection(int[] selection, int lead, ModelChange change) { // Convert the selection from model to view for (int i = selection.length - 1; i >= 0; i--) { selection[i] = convertRowIndexToView(change, selection[i]); } lead = convertRowIndexToView(change, lead); // Check for the common case of no change in selection for 1 row if (selection.length == 0 || (selection.length == 1 && selection[0] == list.getSelectedIndex())) { return; } ListSelectionModel selectionModel = getViewSelectionModel(); // And apply the new selection selectionModel.setValueIsAdjusting(true); selectionModel.clearSelection(); for (int i = selection.length - 1; i >= 0; i--) { if (selection[i] != -1) { selectionModel.addSelectionInterval(selection[i], selection[i]); } } SwingXUtilities.setLeadAnchorWithoutSelection( selectionModel, lead, lead); selectionModel.setValueIsAdjusting(false); }
syncingSelection = true; if (lastModelSelection != null) { restoreSortingSelection(lastModelSelection, modelLeadIndex, change); lastModelSelection = null; } else if (modelSelection != null) { ListSelectionModel viewSelection = getViewSelectionModel(); viewSelection.setValueIsAdjusting(true); viewSelection.clearSelection();
/** * Installs SortUI if the list has a rowSorter. Does nothing if not. */ protected void installSortUI() { if (list.getRowSorter() == null) return; sortUI = new ListSortUI(list, list.getRowSorter()); }
/** * Converts the selection to model coordinates. This is used when * the model changes or the sorter changes. */ private int[] convertSelectionToModel(RowSorterEvent e) { int[] selection = list.getSelectedIndices(); for (int i = selection.length - 1; i >= 0; i--) { selection[i] = convertRowIndexToModel(e, selection[i]); } return selection; }
/** * Returns a boolean indicating whether or not the event has been processed * by the sortUI. * @param e * @return */ protected boolean processedBySortUI(ListDataEvent e) { if (sortUI == null) return false; sortUI.modelChanged(e); updateLayoutStateNeeded = modelChanged; redrawList(); return true; }
/** * Intanstiates a SortUI on the list which has the given RowSorter. * * @param list the list to control, must not be null * @param sorter the rowSorter of the list, must not be null * @throws NullPointerException if either the list or the sorter is null * @throws IllegalStateException if the sorter is not the sorter installed * on the list */ public ListSortUI(JXList list, RowSorter<? extends ListModel> sorter) { this.sorter = Contract.asNotNull(sorter, "RowSorter must not be null"); this.list = Contract.asNotNull(list, "list must not be null"); if (sorter != list.getRowSorter()) throw new IllegalStateException("sorter must be same as the one on list"); sorterListener = createRowSorterListener(); sorter.addRowSorterListener(sorterListener); }
sorter.getViewRowCount() != sorter.getModelRowCount()) { modelSelection = new DefaultListSelectionModel(); ListSelectionModel viewSelection = getViewSelectionModel(); int min = viewSelection.getMinSelectionIndex(); int max = viewSelection.getMaxSelectionIndex(); for (int viewIndex = min; viewIndex <= max; viewIndex++) { if (viewSelection.isSelectedIndex(viewIndex)) { modelIndex = convertRowIndexToModel( sortEvent, viewIndex); if (modelIndex != -1) { modelIndex = convertRowIndexToModel(sortEvent, viewSelection.getLeadSelectionIndex()); SwingXUtilities.setLeadAnchorWithoutSelection( cacheModelSelection(sortEvent);
/** * Restores the selection after a model event/sort order changes. * All coordinates are in terms of the model. */ private void restoreSortingSelection(int[] selection, int lead, ModelChange change) { // Convert the selection from model to view for (int i = selection.length - 1; i >= 0; i--) { selection[i] = convertRowIndexToView(change, selection[i]); } lead = convertRowIndexToView(change, lead); // Check for the common case of no change in selection for 1 row if (selection.length == 0 || (selection.length == 1 && selection[0] == list.getSelectedIndex())) { return; } ListSelectionModel selectionModel = getViewSelectionModel(); // And apply the new selection selectionModel.setValueIsAdjusting(true); selectionModel.clearSelection(); for (int i = selection.length - 1; i >= 0; i--) { if (selection[i] != -1) { selectionModel.addSelectionInterval(selection[i], selection[i]); } } SwingXUtilities.setLeadAnchorWithoutSelection( selectionModel, lead, lead); selectionModel.setValueIsAdjusting(false); }
syncingSelection = true; if (lastModelSelection != null) { restoreSortingSelection(lastModelSelection, modelLeadIndex, change); lastModelSelection = null; } else if (modelSelection != null) { ListSelectionModel viewSelection = getViewSelectionModel(); viewSelection.setValueIsAdjusting(true); viewSelection.clearSelection();
/** * Installs SortUI if the list has a rowSorter. Does nothing if not. */ protected void installSortUI() { if (list.getRowSorter() == null) return; sortUI = new ListSortUI(list, list.getRowSorter()); }
/** * Converts the selection to model coordinates. This is used when * the model changes or the sorter changes. */ private int[] convertSelectionToModel(RowSorterEvent e) { int[] selection = list.getSelectedIndices(); for (int i = selection.length - 1; i >= 0; i--) { selection[i] = convertRowIndexToModel(e, selection[i]); } return selection; }
/** * Returns a boolean indicating whether or not the event has been processed * by the sortUI. * @param e * @return */ protected boolean processedBySortUI(ListDataEvent e) { if (sortUI == null) return false; sortUI.modelChanged(e); updateLayoutStateNeeded = modelChanged; redrawList(); return true; }
/** * Intanstiates a SortUI on the list which has the given RowSorter. * * @param list the list to control, must not be null * @param sorter the rowSorter of the list, must not be null * @throws NullPointerException if either the list or the sorter is null * @throws IllegalStateException if the sorter is not the sorter installed * on the list */ public ListSortUI(JXList list, RowSorter<? extends ListModel> sorter) { this.sorter = Contract.asNotNull(sorter, "RowSorter must not be null"); this.list = Contract.asNotNull(list, "list must not be null"); if (sorter != list.getRowSorter()) throw new IllegalStateException("sorter must be same as the one on list"); sorterListener = createRowSorterListener(); sorter.addRowSorterListener(sorterListener); }
private void cacheModelSelection(RowSorterEvent sortEvent) { lastModelSelection = convertSelectionToModel(sortEvent); modelLeadIndex = convertRowIndexToModel(sortEvent, getViewSelectionModel().getLeadSelectionIndex()); }