Changeset 16601 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-06-11T14:19:10+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/pair/AbstractListMergeModel.java
r16553 r16601 13 13 import java.beans.PropertyChangeListener; 14 14 import java.util.ArrayList; 15 import java.util.Arrays; 15 16 import java.util.EnumMap; 16 17 import java.util.HashSet; … … 40 41 import org.openstreetmap.josm.gui.help.HelpUtil; 41 42 import org.openstreetmap.josm.gui.util.ChangeNotifier; 43 import org.openstreetmap.josm.gui.util.TableHelper; 42 44 import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel; 43 45 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 522 524 } 523 525 fireModelDataChanged(); 524 mergedEntriesSelectionModel.setValueIsAdjusting(true); 525 mergedEntriesSelectionModel.clearSelection(); 526 for (int row: rows) { 527 mergedEntriesSelectionModel.addSelectionInterval(row-1, row-1); 528 } 529 mergedEntriesSelectionModel.setValueIsAdjusting(false); 526 TableHelper.setSelectedIndices(mergedEntriesSelectionModel, Arrays.stream(rows).map(row -> row - 1)); 530 527 } 531 528 … … 550 547 } 551 548 fireModelDataChanged(); 552 mergedEntriesSelectionModel.setValueIsAdjusting(true); 553 mergedEntriesSelectionModel.clearSelection(); 554 for (int row: rows) { 555 mergedEntriesSelectionModel.addSelectionInterval(row+1, row+1); 556 } 557 mergedEntriesSelectionModel.setValueIsAdjusting(false); 549 TableHelper.setSelectedIndices(mergedEntriesSelectionModel, Arrays.stream(rows).map(row -> row + 1)); 558 550 } 559 551 -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r16563 r16601 69 69 import org.openstreetmap.josm.gui.util.GuiHelper; 70 70 import org.openstreetmap.josm.gui.util.StayOpenPopupMenu; 71 import org.openstreetmap.josm.gui.util.TableHelper; 71 72 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 72 73 import org.openstreetmap.josm.gui.widgets.FileChooserManager; … … 334 335 int[] pos = tblStyles.getSelectedRows(); 335 336 MapPaintStyles.toggleStyleActive(pos); 336 selectionModel.setValueIsAdjusting(true); 337 selectionModel.clearSelection(); 338 for (int p: pos) { 339 selectionModel.addSelectionInterval(p, p); 340 } 341 selectionModel.setValueIsAdjusting(false); 337 TableHelper.setSelectedIndices(selectionModel, Arrays.stream(pos)); 342 338 } 343 339 } … … 371 367 int[] sel = tblStyles.getSelectedRows(); 372 368 MapPaintStyles.moveStyles(sel, increment); 373 374 selectionModel.setValueIsAdjusting(true); 375 selectionModel.clearSelection(); 376 for (int row: sel) { 377 selectionModel.addSelectionInterval(row + increment, row + increment); 378 } 379 selectionModel.setValueIsAdjusting(false); 369 TableHelper.setSelectedIndices(selectionModel, Arrays.stream(sel).map(row -> row + increment)); 380 370 model.ensureSelectedIsVisible(); 381 371 } … … 414 404 final int[] rows = tblStyles.getSelectedRows(); 415 405 MapPaintStyleLoader.reloadStyles(rows); 416 MainApplication.worker.submit(() -> SwingUtilities.invokeLater(() -> { 417 selectionModel.setValueIsAdjusting(true); 418 selectionModel.clearSelection(); 419 for (int r: rows) { 420 selectionModel.addSelectionInterval(r, r); 421 } 422 selectionModel.setValueIsAdjusting(false); 423 })); 406 MainApplication.worker.submit(() -> SwingUtilities.invokeLater(() -> 407 TableHelper.setSelectedIndices(selectionModel, Arrays.stream(rows)))); 424 408 } 425 409 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r16512 r16601 82 82 import org.openstreetmap.josm.gui.util.AbstractTag2LinkPopupListener; 83 83 import org.openstreetmap.josm.gui.util.HighlightHelper; 84 import org.openstreetmap.josm.gui.util.TableHelper; 84 85 import org.openstreetmap.josm.gui.widgets.CompileSearchTextDecorator; 85 86 import org.openstreetmap.josm.gui.widgets.DisableShortcutsOnFocusGainedTextField; … … 309 310 } else { 310 311 model.setSelectedRelations(relations); 311 Integer i = model.getVisibleRelationIndex(relations.iterator().next());312 if (i != null) {312 int i = model.getVisibleRelations().indexOf(relations.iterator().next()); 313 if (i >= 0) { 313 314 // Not all relations have to be in the list 314 315 // (for example when the relation list is hidden, it's not updated with new relations) … … 584 585 */ 585 586 public void setSelectedRelations(Collection<? extends IRelation<?>> sel) { 586 selectionModel.setValueIsAdjusting(true);587 selectionModel.clearSelection();588 587 if (sel != null && !sel.isEmpty()) { 589 588 if (!getVisibleRelations().containsAll(sel)) { 590 589 resetFilter(); 591 590 } 592 for (IRelation<?> r: sel) { 593 Integer i = getVisibleRelationIndex(r); 594 if (i != null) { 595 selectionModel.addSelectionInterval(i, i); 596 } 597 } 598 } 599 selectionModel.setValueIsAdjusting(false); 600 } 601 602 private Integer getVisibleRelationIndex(IRelation<?> rel) { 603 int i = getVisibleRelations().indexOf(rel); 604 if (i < 0) 605 return null; 606 return i; 591 TableHelper.setSelectedIndices(selectionModel, sel.stream().mapToInt(getVisibleRelations()::indexOf)); 592 } else { 593 TableHelper.setSelectedIndices(selectionModel, IntStream.empty()); 594 } 607 595 } 608 596 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r16495 r16601 79 79 import org.openstreetmap.josm.gui.util.GuiHelper; 80 80 import org.openstreetmap.josm.gui.util.HighlightHelper; 81 import org.openstreetmap.josm.gui.util.TableHelper; 81 82 import org.openstreetmap.josm.gui.widgets.ListPopupMenu; 82 83 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 578 579 */ 579 580 public synchronized void setSelected(Collection<OsmPrimitive> sel) { 580 selectionModel.setValueIsAdjusting(true); 581 selectionModel.clearSelection(); 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); 581 TableHelper.setSelectedIndices(selectionModel, 582 sel != null ? sel.stream().mapToInt(selection::indexOf) : IntStream.empty()); 591 583 } 592 584 -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheManagerModel.java
r16436 r16601 10 10 import java.util.Set; 11 11 import java.util.stream.Collectors; 12 import java.util.stream.IntStream; 12 13 13 14 import javax.swing.DefaultListSelectionModel; … … 19 20 import org.openstreetmap.josm.data.osm.ChangesetCacheListener; 20 21 import org.openstreetmap.josm.gui.util.GuiHelper; 22 import org.openstreetmap.josm.gui.util.TableHelper; 21 23 22 24 /** … … 111 113 */ 112 114 public void setSelectedChangesets(Collection<Changeset> selected) { 113 selectionModel.setValueIsAdjusting(true); 114 selectionModel.clearSelection(); 115 if (selected != null) { 116 for (Changeset cs: selected) { 117 final int idx = data.indexOf(cs); 118 if (idx >= 0) { 119 selectionModel.addSelectionInterval(idx, idx); 120 } 121 } 122 } 123 GuiHelper.runInEDTAndWait(() -> selectionModel.setValueIsAdjusting(false)); 115 GuiHelper.runInEDTAndWait(() -> TableHelper.setSelectedIndices(selectionModel, 116 selected != null ? selected.stream().mapToInt(data::indexOf) : IntStream.empty())); 124 117 } 125 118 -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetListModel.java
r16436 r16601 22 22 import org.openstreetmap.josm.data.osm.Storage; 23 23 import org.openstreetmap.josm.gui.util.GuiHelper; 24 import org.openstreetmap.josm.gui.util.TableHelper; 24 25 25 26 /** … … 62 63 */ 63 64 public synchronized void setSelectedChangesets(Collection<Changeset> changesets) { 64 selectionModel.setValueIsAdjusting(true); 65 selectionModel.clearSelection(); 66 if (changesets != null) { 67 for (Changeset cs: changesets) { 68 int idx = data.indexOf(cs); 69 if (idx >= 0) { 70 selectionModel.addSelectionInterval(idx, idx); 71 } 72 } 73 } 74 selectionModel.setValueIsAdjusting(false); 65 TableHelper.setSelectedIndices(selectionModel, 66 changesets != null ? changesets.stream().mapToInt(data::indexOf) : IntStream.empty()); 75 67 } 76 68 -
trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java
r16600 r16601 2 2 package org.openstreetmap.josm.gui.history; 3 3 4 import java.util.Arrays; 4 5 import java.util.HashSet; 5 6 import java.util.Set; … … 53 54 preventRecursion = true; 54 55 DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource(); 56 int[] selectedIndices = TableHelper.getSelectedIndices(referenceModel); 55 57 for (ListSelectionModel model : participants) { 56 58 if (model == e.getSource()) { 57 59 continue; 58 60 } 59 model.clearSelection(); 60 for (int i : TableHelper.getSelectedIndices(referenceModel)) { 61 model.addSelectionInterval(i, i); 62 } 61 TableHelper.setSelectedIndices(model, Arrays.stream(selectedIndices)); 63 62 } 64 63 preventRecursion = false; -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
r16436 r16601 21 21 import java.util.Optional; 22 22 import java.util.stream.Collectors; 23 import java.util.stream.IntStream; 23 24 24 25 import javax.swing.AbstractAction; … … 46 47 import org.openstreetmap.josm.gui.layer.GpxLayer; 47 48 import org.openstreetmap.josm.gui.preferences.display.GPXSettingsPanel; 49 import org.openstreetmap.josm.gui.util.TableHelper; 48 50 import org.openstreetmap.josm.gui.util.WindowGeometry; 49 51 import org.openstreetmap.josm.tools.GBC; … … 219 221 } 220 222 ListSelectionModel s = table.getSelectionModel(); 221 s.setValueIsAdjusting(true); 222 s.clearSelection(); 223 for (int i = 0; i < layer.trackVisibility.length; i++) { 224 if (layer.trackVisibility[i]) { 225 s.addSelectionInterval(i, i); 226 } 227 } 228 s.setValueIsAdjusting(false); 223 TableHelper.setSelectedIndices(s, 224 IntStream.range(0, layer.trackVisibility.length).filter(i -> layer.trackVisibility[i])); 229 225 } 230 226 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r16553 r16601 745 745 } 746 746 fireTableDataChanged(); 747 selectionModel.setValueIsAdjusting(true); 748 selectionModel.clearSelection(); 749 for (ExtendedSourceEntry info: sources) { 750 int pos = data.indexOf(info); 751 if (pos >= 0) { 752 selectionModel.addSelectionInterval(pos, pos); 753 } 754 } 755 selectionModel.setValueIsAdjusting(false); 747 TableHelper.setSelectedIndices(selectionModel, sources.stream().mapToInt(data::indexOf)); 756 748 } 757 749 -
trunk/src/org/openstreetmap/josm/gui/util/ReorderableTableModel.java
r16416 r16601 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.util; 3 4 import java.util.Arrays; 3 5 4 6 import javax.swing.JList; … … 135 137 return false; 136 138 final ListSelectionModel selectionModel = getSelectionModel(); 137 selectionModel.setValueIsAdjusting(true); 138 selectionModel.clearSelection(); 139 for (int row: selectedRows) { 140 selectionModel.addSelectionInterval(row + delta, row + delta); 141 } 142 selectionModel.setValueIsAdjusting(false); 139 TableHelper.setSelectedIndices(selectionModel, Arrays.stream(selectedRows).map(i -> i + delta)); 143 140 return true; 144 141 } -
trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java
r15226 r16601 3 3 4 4 import java.awt.Component; 5 import java.util.stream.IntStream; 5 6 6 7 import javax.swing.JTable; … … 147 148 return rv; 148 149 } 150 151 /** 152 * Selects the given indices in the selection model 153 * @param selectionModel list selection model. 154 * @param indices the indices to select 155 * @see ListSelectionModel#addSelectionInterval(int, int) 156 * @since 16601 157 */ 158 public static void setSelectedIndices(ListSelectionModel selectionModel, IntStream indices) { 159 selectionModel.setValueIsAdjusting(true); 160 selectionModel.clearSelection(); 161 indices.filter(i -> i >= 0).forEach(i -> selectionModel.addSelectionInterval(i, i)); 162 selectionModel.setValueIsAdjusting(false); 163 } 149 164 }
Note:
See TracChangeset
for help on using the changeset viewer.