Skip to content

Commit 089748b

Browse files
committed
Viewer3D: Resolve bottlenecks in manager list
1 parent 0e295fb commit 089748b

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

‎src/main/java/sc/fiji/snt/viewer/Viewer3D.java‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -981,13 +981,16 @@ private void initManagerList() {
981981
if (!e.getValueIsAdjusting() && getManagerPanel() != null) {
982982
final Set<String> selectedKeys = getLabelsCheckedInManager();
983983
plottedTrees.forEach((k, shapeTree) -> {
984-
shapeTree.setDisplayed(selectedKeys.contains(k));
984+
final boolean show = selectedKeys.contains(k);
985+
if (shapeTree.isDisplayed() != show) shapeTree.setDisplayed(show);
985986
});
986987
plottedObjs.forEach((k, drawableVBO) -> {
987-
drawableVBO.setDisplayed(selectedKeys.contains(k));
988+
final boolean show = selectedKeys.contains(k);
989+
if (drawableVBO.isDisplayed() != show) drawableVBO.setDisplayed(show);
988990
});
989991
plottedAnnotations.forEach((k, annot) -> {
990-
annot.getDrawable().setDisplayed(selectedKeys.contains(k));
992+
final boolean show = selectedKeys.contains(k);
993+
if (annot.getDrawable().isDisplayed() != show) annot.getDrawable().setDisplayed(show);
991994
});
992995
if (getRecorder(false) != null) {
993996
// Record toggling of last checkbox interaction
@@ -1447,10 +1450,13 @@ private void addItemToManager(final String label) {
14471450
final int[] indices = managerList.getCheckBoxListSelectedIndices();
14481451
final int index = managerList.model.size() - 1;
14491452
managerList.model.insertElementAt(label, index);
1450-
// managerList.ensureIndexIsVisible(index);
1453+
// Batch-update selection without firing the visibility listener on each call
1454+
final var selModel = managerList.getCheckBoxListSelectionModel();
1455+
selModel.setValueIsAdjusting(true);
14511456
managerList.addCheckBoxListSelectedIndex(index);
14521457
for (final int i : indices)
14531458
managerList.addCheckBoxListSelectedIndex(i);
1459+
selModel.setValueIsAdjusting(false);
14541460
}
14551461

14561462
private boolean deleteItemFromManager(final String managerEntry) {
@@ -7568,17 +7574,21 @@ class UpdatableListModel<T> extends DefaultListModel<T> {
75687574

75697575
@SuppressWarnings("unchecked")
75707576
public void sort() {
7571-
final List<T> list = new ArrayList<>();
7572-
for (int i = 0; i < getSize(); i++) {
7577+
final int size = getSize();
7578+
if (size <= 2) return; // 0-1 items + ALL_ENTRY: nothing to sort
7579+
final List<T> list = new ArrayList<>(size - 1);
7580+
for (int i = 0; i < size; i++) {
75737581
final T o = get(i);
75747582
if (!CheckBoxList.ALL_ENTRY.equals(o))
75757583
list.add(o);
75767584
}
75777585
list.sort(Comparator.comparing(T::toString));
7578-
list.add((T) CheckBoxList.ALL_ENTRY);
7586+
// Rewrite elements in place: sorted items first, ALL_ENTRY last
75797587
setListenersEnabled(false);
7580-
removeAllElements();
7581-
addAll(list);
7588+
for (int i = 0; i < list.size(); i++) {
7589+
set(i, list.get(i));
7590+
}
7591+
set(size - 1, (T) CheckBoxList.ALL_ENTRY);
75827592
setListenersEnabled(true);
75837593
}
75847594

0 commit comments

Comments
 (0)