Changeset 11365 in josm for trunk


Ignore:
Timestamp:
2016-12-07T23:47:56+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14090 - use DefaultListSelectionModel adjusting selection mode to avoid too much costly listener calls

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java

    r11330 r11365  
    505505        }
    506506        fireModelDataChanged();
     507        mergedEntriesSelectionModel.setValueIsAdjusting(true);
    507508        mergedEntriesSelectionModel.clearSelection();
    508509        for (int row: rows) {
    509510            mergedEntriesSelectionModel.addSelectionInterval(row-1, row-1);
    510511        }
     512        mergedEntriesSelectionModel.setValueIsAdjusting(false);
    511513    }
    512514
     
    531533        }
    532534        fireModelDataChanged();
     535        mergedEntriesSelectionModel.setValueIsAdjusting(true);
    533536        mergedEntriesSelectionModel.clearSelection();
    534537        for (int row: rows) {
    535538            mergedEntriesSelectionModel.addSelectionInterval(row+1, row+1);
    536539        }
     540        mergedEntriesSelectionModel.setValueIsAdjusting(false);
    537541    }
    538542
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r11357 r11365  
    313313    @Override
    314314    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     315        lstConflicts.setValueIsAdjusting(true);
    315316        lstConflicts.clearSelection();
    316317        for (OsmPrimitive osm : newSelection) {
     
    322323            }
    323324        }
     325        lstConflicts.setValueIsAdjusting(false);
    324326    }
    325327
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r10824 r11365  
    841841            }
    842842            fireTableDataChanged();
     843            selectionModel.setValueIsAdjusting(true);
    843844            selectionModel.clearSelection();
    844845            for (int row : sel) {
    845846                selectionModel.addSelectionInterval(row-1, row-1);
    846847            }
     848            selectionModel.setValueIsAdjusting(false);
    847849            ensureSelectedIsVisible();
    848850        }
     
    874876            }
    875877            fireTableDataChanged();
     878            selectionModel.setValueIsAdjusting(true);
    876879            selectionModel.clearSelection();
    877880            for (int row : sel) {
    878881                selectionModel.addSelectionInterval(row+1, row+1);
    879882            }
     883            selectionModel.setValueIsAdjusting(false);
    880884            ensureSelectedIsVisible();
    881885        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r10694 r11365  
    351351            int[] pos = tblStyles.getSelectedRows();
    352352            MapPaintStyles.toggleStyleActive(pos);
     353            selectionModel.setValueIsAdjusting(true);
    353354            selectionModel.clearSelection();
    354355            for (int p: pos) {
    355356                selectionModel.addSelectionInterval(p, p);
    356357            }
     358            selectionModel.setValueIsAdjusting(false);
    357359        }
    358360    }
     
    387389            MapPaintStyles.moveStyles(sel, increment);
    388390
     391            selectionModel.setValueIsAdjusting(true);
    389392            selectionModel.clearSelection();
    390393            for (int row: sel) {
    391394                selectionModel.addSelectionInterval(row + increment, row + increment);
    392395            }
     396            selectionModel.setValueIsAdjusting(false);
    393397            model.ensureSelectedIsVisible();
    394398        }
     
    434438            MapPaintStyles.reloadStyles(rows);
    435439            Main.worker.submit(() -> SwingUtilities.invokeLater(() -> {
     440                selectionModel.setValueIsAdjusting(true);
    436441                selectionModel.clearSelection();
    437442                for (int r: rows) {
    438443                    selectionModel.addSelectionInterval(r, r);
    439444                }
     445                selectionModel.setValueIsAdjusting(false);
    440446            }));
    441447        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r11357 r11365  
    149149        filter = setupFilter();
    150150
    151         displaylist.addListSelectionListener(e -> updateActionsRelationLists());
     151        displaylist.addListSelectionListener(e -> {
     152            if (!e.getValueIsAdjusting()) updateActionsRelationLists();
     153        });
    152154
    153155        // Setup popup menu handler
     
    563565         */
    564566        public void setSelectedRelations(Collection<Relation> sel) {
     567            selectionModel.setValueIsAdjusting(true);
    565568            selectionModel.clearSelection();
    566             if (sel == null || sel.isEmpty())
    567                 return;
    568             if (!getVisibleRelations().containsAll(sel)) {
    569                 resetFilter();
    570             }
    571             for (Relation r: sel) {
    572                 Integer i = getVisibleRelationIndex(r);
    573                 if (i != null) {
    574                     selectionModel.addSelectionInterval(i, i);
    575                 }
    576             }
     569            if (sel != null && !sel.isEmpty()) {
     570                if (!getVisibleRelations().containsAll(sel)) {
     571                    resetFilter();
     572                }
     573                for (Relation r: sel) {
     574                    Integer i = getVisibleRelationIndex(r);
     575                    if (i != null) {
     576                        selectionModel.addSelectionInterval(i, i);
     577                    }
     578                }
     579            }
     580            selectionModel.setValueIsAdjusting(false);
    577581        }
    578582
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r11177 r11365  
    578578         */
    579579        public synchronized void setSelected(Collection<OsmPrimitive> sel) {
     580            selectionModel.setValueIsAdjusting(true);
    580581            selectionModel.clearSelection();
    581             if (sel == null) return;
    582             for (OsmPrimitive p: sel) {
    583                 int i = selection.indexOf(p);
    584                 if (i >= 0) {
    585                     selectionModel.addSelectionInterval(i, i);
    586                 }
    587             }
     582            if (sel != null) {
     583                for (OsmPrimitive p: sel) {
     584                    int i = selection.indexOf(p);
     585                    if (i >= 0) {
     586                        selectionModel.addSelectionInterval(i, i);
     587                    }
     588                }
     589            }
     590            selectionModel.setValueIsAdjusting(false);
    588591        }
    589592
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java

    r10647 r11365  
    104104     */
    105105    public void setSelectedChangesets(Collection<Changeset> selected) {
    106         GuiHelper.runInEDTAndWait(selectionModel::clearSelection);
    107         if (selected == null || selected.isEmpty())
    108             return;
    109         for (Changeset cs: selected) {
    110             final int idx = data.indexOf(cs);
    111             if (idx >= 0) {
    112                 GuiHelper.runInEDTAndWait(() -> selectionModel.addSelectionInterval(idx, idx));
     106        selectionModel.setValueIsAdjusting(true);
     107        selectionModel.clearSelection();
     108        if (selected != null) {
     109            for (Changeset cs: selected) {
     110                final int idx = data.indexOf(cs);
     111                if (idx >= 0) {
     112                    selectionModel.addSelectionInterval(idx, idx);
     113                }
    113114            }
    114115        }
     116        GuiHelper.runInEDTAndWait(() -> selectionModel.setValueIsAdjusting(false));
    115117    }
    116118
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java

    r10647 r11365  
    5050
    5151    public void setSelectedChangesets(Collection<Changeset> changesets) {
     52        selectionModel.setValueIsAdjusting(true);
    5253        selectionModel.clearSelection();
    53         if (changesets == null) return;
    54         for (Changeset cs: changesets) {
    55             int idx = data.indexOf(cs);
    56             if (idx < 0) {
    57                 continue;
    58             }
    59             selectionModel.addSelectionInterval(idx, idx);
    60         }
     54        if (changesets != null) {
     55            for (Changeset cs: changesets) {
     56                int idx = data.indexOf(cs);
     57                if (idx >= 0) {
     58                    selectionModel.addSelectionInterval(idx, idx);
     59                }
     60            }
     61        }
     62        selectionModel.setValueIsAdjusting(false);
    6163    }
    6264
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java

    r10755 r11365  
    192192        }
    193193        ListSelectionModel s = table.getSelectionModel();
     194        s.setValueIsAdjusting(true);
    194195        s.clearSelection();
    195196        for (int i = 0; i < layer.trackVisibility.length; i++) {
     
    198199            }
    199200        }
     201        s.setValueIsAdjusting(false);
    200202    }
    201203
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r10733 r11365  
    665665            }
    666666            fireTableDataChanged();
     667            selectionModel.setValueIsAdjusting(true);
    667668            selectionModel.clearSelection();
    668669            for (ExtendedSourceEntry info: sources) {
     
    672673                }
    673674            }
     675            selectionModel.setValueIsAdjusting(false);
    674676        }
    675677
     
    699701                data.set(row + i, t1);
    700702            }
     703            selectionModel.setValueIsAdjusting(true);
    701704            selectionModel.clearSelection();
    702705            for (int row: sel) {
    703706                selectionModel.addSelectionInterval(row + i, row + i);
    704707            }
     708            selectionModel.setValueIsAdjusting(false);
    705709        }
    706710    }
Note: See TracChangeset for help on using the changeset viewer.