- Timestamp:
- 2021-04-13T22:20:22+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/RestorePropertyAction.java
r17034 r17773 6 6 import java.awt.event.ActionEvent; 7 7 import java.util.Collections; 8 import java.util. HashMap;8 import java.util.Map; 9 9 import java.util.function.IntFunction; 10 10 import java.util.function.Supplier; 11 import java.util.stream.Collectors; 11 12 12 13 import javax.swing.AbstractAction; … … 54 55 if (primitive == null) return; 55 56 56 HashMap<String, String> changes = new HashMap<>(); 57 for (int index : TableHelper.getSelectedIndices(selectionModel)) { 58 changes.put(keyFn.apply(index), valueFn.apply(index)); 59 } 57 Map<String, String> changes = TableHelper.selectedIndices(selectionModel).boxed() 58 .collect(Collectors.toMap(keyFn::apply, valueFn::apply, (a, b) -> b)); 60 59 ChangePropertyCommand command = new ChangePropertyCommand(Collections.singleton(primitive), changes); 61 60 UndoRedoHandler.getInstance().add(command); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r17626 r17773 90 90 import org.openstreetmap.josm.gui.widgets.ScrollableTable; 91 91 import org.openstreetmap.josm.spi.preferences.Config; 92 import org.openstreetmap.josm.tools.ArrayUtils;93 92 import org.openstreetmap.josm.tools.ImageProvider; 94 93 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; … … 892 891 */ 893 892 public List<Integer> getSelectedRows() { 894 return ArrayUtils.toList(TableHelper.getSelectedIndices(selectionModel));893 return TableHelper.selectedIndices(selectionModel).boxed().collect(Collectors.toList()); 895 894 } 896 895 … … 905 904 layer.removePropertyChangeListener(this); 906 905 final int size = getRowCount(); 907 final int[] rows = TableHelper.getSelectedIndices(selectionModel); 908 909 if (rows.length == 0 && size > 0) { 906 907 if (selectionModel.isSelectionEmpty() && size > 0) { 910 908 selectionModel.setSelectionInterval(size-1, size-1); 911 909 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r17423 r17773 3 3 4 4 import java.util.ArrayList; 5 import java.util.Arrays;6 5 import java.util.BitSet; 7 6 import java.util.Collection; … … 51 50 import org.openstreetmap.josm.gui.util.SortableTableModel; 52 51 import org.openstreetmap.josm.gui.widgets.OsmPrimitivesTableModel; 53 import org.openstreetmap.josm.tools.ArrayUtils;54 52 import org.openstreetmap.josm.tools.JosmRuntimeException; 55 53 import org.openstreetmap.josm.tools.bugreport.BugReport; … … 513 511 */ 514 512 public Collection<RelationMember> getSelectedMembers() { 515 return Arrays.stream(getSelectedIndices())513 return selectedIndices() 516 514 .mapToObj(members::get) 517 515 .collect(Collectors.toList()); … … 692 690 addToSelectedMembers(selected); 693 691 getSelectionModel().setValueIsAdjusting(false); 694 int[] selectedIndices = getSelectedIndices(); 695 if (selectedIndices.length > 0) { 696 fireMakeMemberVisible(selectedIndices[0]); 697 } 692 selectedIndices().findFirst().ifPresent(this::fireMakeMemberVisible); 698 693 } 699 694 … … 723 718 } else { 724 719 sortedMembers = relationSorter.sortMembers(selectedMembers); 725 List<Integer> selectedIndices = ArrayUtils.toList(getSelectedIndices());720 List<Integer> selectedIndices = selectedIndices().boxed().collect(Collectors.toList()); 726 721 newMembers = new ArrayList<>(); 727 722 boolean inserted = false; … … 784 779 @Override 785 780 public void reverse() { 786 List<Integer> selectedIndices = ArrayUtils.toList(getSelectedIndices());787 List<Integer> selectedIndicesReversed = ArrayUtils.toList(getSelectedIndices());781 List<Integer> selectedIndices = selectedIndices().boxed().collect(Collectors.toList()); 782 List<Integer> selectedIndicesReversed = selectedIndices().boxed().collect(Collectors.toList()); 788 783 789 784 if (selectedIndices.size() <= 1) { -
trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java
r16609 r17773 2 2 package org.openstreetmap.josm.gui.history; 3 3 4 import java.util.Arrays;5 4 import java.util.HashSet; 6 5 import java.util.Objects; … … 61 60 preventRecursion = true; 62 61 ListSelectionModel referenceModel = (ListSelectionModel) e.getSource(); 63 int[] selectedIndices = TableHelper.getSelectedIndices(referenceModel);64 62 for (ListSelectionModel model : participants) { 65 63 if (model == referenceModel) { … … 67 65 } 68 66 TableHelper.setSelectedIndices(model, 69 Arrays.stream(selectedIndices).flatMap(i -> selectionIndexMapper.apply(i, referenceModel)));67 TableHelper.selectedIndices(referenceModel).flatMap(i -> selectionIndexMapper.apply(i, referenceModel))); 70 68 } 71 69 preventRecursion = false; -
trunk/src/org/openstreetmap/josm/gui/util/ReorderableTableModel.java
r16601 r17773 3 3 4 4 import java.util.Arrays; 5 import java.util.stream.IntStream; 5 6 6 7 import javax.swing.JList; … … 38 39 * Returns an array of all of the selected indices in the selection model, in increasing order. 39 40 * @return an array of all of the selected indices in the selection model, in increasing order 41 * @see #selectedIndices() 40 42 */ 41 43 default int[] getSelectedIndices() { 42 44 return TableHelper.getSelectedIndices(getSelectionModel()); 45 } 46 47 /** 48 * Returns a stream of all of the selected indices in the selection model, in increasing order. 49 * @return a stream of all of the selected indices in the selection model, in increasing order 50 * @since 17773 51 */ 52 default IntStream selectedIndices() { 53 return TableHelper.selectedIndices(getSelectionModel()); 43 54 } 44 55 -
trunk/src/org/openstreetmap/josm/gui/util/TableHelper.java
r16960 r17773 123 123 * Unfortunately this method is not available in OpenJDK before version 11, see 124 124 * https://bugs.openjdk.java.net/browse/JDK-8199395 125 * Code taken from OpenJDK 11. To be removed when we switch to Java 11 or later. 125 * 126 * To be removed when we switch to Java 11 or later. 126 127 * 127 128 * @param selectionModel list selection model. … … 130 131 * or an empty array if nothing is selected 131 132 * @since 15226 133 * @see #selectedIndices(ListSelectionModel) 132 134 */ 133 135 public static int[] getSelectedIndices(ListSelectionModel selectionModel) { 134 int iMin = selectionModel.getMinSelectionIndex();135 int iMax = selectionModel.getMaxSelectionIndex();136 return selectedIndices(selectionModel).toArray(); 137 } 136 138 137 if (iMin < 0 || iMax < 0) { 138 return new int[0]; 139 /** 140 * Returns a stream of all of the selected indices in the selection model, in increasing order. 141 * 142 * @param selectionModel list selection model. 143 * 144 * @return all of the selected indices, in increasing order, 145 * or an empty stream if nothing is selected 146 * @since 17773 147 */ 148 public static IntStream selectedIndices(ListSelectionModel selectionModel) { 149 if (selectionModel.isSelectionEmpty()) { 150 return IntStream.empty(); 139 151 } 140 141 int[] rvTmp = new int[1 + iMax - iMin]; 142 int n = 0; 143 for (int i = iMin; i <= iMax; i++) { 144 if (selectionModel.isSelectedIndex(i)) { 145 rvTmp[n++] = i; 146 } 147 } 148 int[] rv = new int[n]; 149 System.arraycopy(rvTmp, 0, rv, 0, n); 150 return rv; 152 return IntStream.rangeClosed(selectionModel.getMinSelectionIndex(), selectionModel.getMaxSelectionIndex()) 153 .filter(selectionModel::isSelectedIndex); 151 154 } 152 155
Note:
See TracChangeset
for help on using the changeset viewer.