- Timestamp:
- 2020-06-21T09:54:50+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/tagging/presets/items
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
r16688 r16689 18 18 import java.util.Objects; 19 19 import java.util.Set; 20 import java.util.TreeSet;21 20 import java.util.concurrent.CopyOnWriteArraySet; 22 21 import java.util.stream.Collectors; … … 29 28 import javax.swing.JPanel; 30 29 import javax.swing.ListCellRenderer; 31 import javax.swing.ListModel;32 30 33 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 154 152 155 153 return lbl; 156 }157 }158 159 /**160 * Class that allows list values to be assigned and retrieved as a comma-delimited161 * string (extracted from TaggingPreset)162 */163 protected static class ConcatenatingJList extends JList<PresetListEntry> {164 private final char delimiter;165 166 protected ConcatenatingJList(char del, PresetListEntry... o) {167 super(o);168 delimiter = del;169 }170 171 public void setSelectedItem(Object o) {172 if (o == null) {173 clearSelection();174 } else {175 String s = o.toString();176 Set<String> parts = new TreeSet<>(Arrays.asList(s.split(String.valueOf(delimiter), -1)));177 ListModel<PresetListEntry> lm = getModel();178 int[] intParts = new int[lm.getSize()];179 int j = 0;180 for (int i = 0; i < lm.getSize(); i++) {181 final String value = lm.getElementAt(i).value;182 if (parts.contains(value)) {183 intParts[j++] = i;184 parts.remove(value);185 }186 }187 setSelectedIndices(Arrays.copyOf(intParts, j));188 // check if we have actually managed to represent the full189 // value with our presets. if not, cop out; we will not offer190 // a selection list that threatens to ruin the value.191 setEnabled(parts.isEmpty());192 }193 }194 195 public String getSelectedItem() {196 ListModel<PresetListEntry> lm = getModel();197 int[] si = getSelectedIndices();198 StringBuilder builder = new StringBuilder();199 for (int i = 0; i < si.length; i++) {200 if (i > 0) {201 builder.append(delimiter);202 }203 builder.append(lm.getElementAt(si[i]).value);204 }205 return builder.toString();206 154 } 207 155 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelect.java
r16688 r16689 3 3 4 4 import java.awt.Dimension; 5 import java.util.Arrays; 5 6 import java.util.List; 7 import java.util.Set; 8 import java.util.TreeSet; 6 9 10 import javax.swing.JList; 7 11 import javax.swing.JPanel; 8 12 import javax.swing.JScrollPane; 9 13 import javax.swing.ListCellRenderer; 14 import javax.swing.ListModel; 10 15 11 16 import org.openstreetmap.josm.data.osm.Tag; … … 55 60 } 56 61 } 62 63 /** 64 * Class that allows list values to be assigned and retrieved as a comma-delimited 65 * string (extracted from TaggingPreset) 66 */ 67 private static class ConcatenatingJList extends JList<PresetListEntry> { 68 private final char delimiter; 69 70 protected ConcatenatingJList(char del, PresetListEntry... o) { 71 super(o); 72 delimiter = del; 73 } 74 75 public void setSelectedItem(Object o) { 76 if (o == null) { 77 clearSelection(); 78 } else { 79 String s = o.toString(); 80 Set<String> parts = new TreeSet<>(Arrays.asList(s.split(String.valueOf(delimiter), -1))); 81 ListModel<PresetListEntry> lm = getModel(); 82 int[] intParts = new int[lm.getSize()]; 83 int j = 0; 84 for (int i = 0; i < lm.getSize(); i++) { 85 final String value = lm.getElementAt(i).value; 86 if (parts.contains(value)) { 87 intParts[j++] = i; 88 parts.remove(value); 89 } 90 } 91 setSelectedIndices(Arrays.copyOf(intParts, j)); 92 // check if we have actually managed to represent the full 93 // value with our presets. if not, cop out; we will not offer 94 // a selection list that threatens to ruin the value. 95 setEnabled(parts.isEmpty()); 96 } 97 } 98 99 public String getSelectedItem() { 100 ListModel<PresetListEntry> lm = getModel(); 101 int[] si = getSelectedIndices(); 102 StringBuilder builder = new StringBuilder(); 103 for (int i = 0; i < si.length; i++) { 104 if (i > 0) { 105 builder.append(delimiter); 106 } 107 builder.append(lm.getElementAt(si[i]).value); 108 } 109 return builder.toString(); 110 } 111 } 57 112 }
Note:
See TracChangeset
for help on using the changeset viewer.