Ticket #22664: flexibilize-presets_v6.patch
| File flexibilize-presets_v6.patch, 31.4 KB (added by , 3 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java
138 138 public boolean preset_name_label; 139 139 140 140 /** 141 * If menu items should be sorted 142 */ 143 public String items_sort = "yes"; 144 145 /** 141 146 * The types as preparsed collection. 142 147 */ 143 148 public transient Set<TaggingPresetType> types; … … 255 260 } 256 261 257 262 /** 263 * Called from the XML parser to set the sort option. 264 * @param sort The sort value for the menu items. 265 * @since 18619 266 */ 267 public void setItems_sort(final String sort) { 268 this.items_sort = sort; 269 } 270 271 /** 258 272 * Called from the XML parser to set the icon. 259 273 * The loading task is performed in the background in order to speedup startup. 260 274 * @param iconName icon name -
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetMenu.java
120 120 * Sorts the menu items using the translated item text 121 121 */ 122 122 public void sortMenu() { 123 TaggingPresetMenu.sortMenu(this.menu );123 TaggingPresetMenu.sortMenu(this.menu, TaggingPresets.SORT_MENU.get()); 124 124 } 125 125 126 126 /** 127 127 * Sorts the menu items using the translated item text 128 128 * @param menu menu to sort 129 * @param itemssort if menu should be sorted. 129 130 */ 130 public static void sortMenu(JMenu menu) { 131 public static void sortMenu(JMenu menu, boolean itemssort) { 132 Action a = menu.getAction(); 133 134 boolean sort = itemssort; 135 136 if (a instanceof TaggingPreset) { 137 sort = (sort && ((TaggingPreset) a).items_sort.equals("yes")) || ((TaggingPreset) a).items_sort.equals("always"); 138 } 139 131 140 Component[] items = menu.getMenuComponents(); 132 141 PresetTextComparator comp = new PresetTextComparator(); 133 142 List<JMenuItem> sortarray = new ArrayList<>(); … … 135 144 for (int i = 0; i < items.length; i++) { 136 145 Object item = items[i]; 137 146 if (item instanceof JMenu) { 138 sortMenu((JMenu) item );147 sortMenu((JMenu) item, itemssort); 139 148 } 140 if (item instanceof JMenuItem) { 141 sortarray.add((JMenuItem) item); 142 if (i == items.length-1) { 149 if (sort) { 150 if (item instanceof JMenuItem) { 151 sortarray.add((JMenuItem) item); 152 if (i == items.length-1) { 153 handleMenuItem(menu, comp, sortarray, lastSeparator); 154 sortarray = new ArrayList<>(); 155 lastSeparator = 0; 156 } 157 } else if (item instanceof JSeparator) { 143 158 handleMenuItem(menu, comp, sortarray, lastSeparator); 144 159 sortarray = new ArrayList<>(); 145 lastSeparator = 0;160 lastSeparator = i; 146 161 } 147 } else if (item instanceof JSeparator) {148 handleMenuItem(menu, comp, sortarray, lastSeparator);149 sortarray = new ArrayList<>();150 lastSeparator = i;151 162 } 152 163 } 153 164 } -
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java
39 39 import org.openstreetmap.josm.gui.tagging.presets.items.PresetListEntry; 40 40 import org.openstreetmap.josm.gui.tagging.presets.items.Roles; 41 41 import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role; 42 import org.openstreetmap.josm.gui.tagging.presets.items.SelectGroup; 42 43 import org.openstreetmap.josm.gui.tagging.presets.items.Space; 43 44 import org.openstreetmap.josm.gui.tagging.presets.items.Text; 44 45 import org.openstreetmap.josm.io.CachedFile; … … 145 146 parser.mapOnStart("roles", Roles.class); 146 147 parser.map("role", Role.class); 147 148 parser.mapBoth("checkgroup", CheckGroup.class); 149 parser.mapBoth("selectgroup", SelectGroup.class); 148 150 parser.map("check", Check.class); 149 151 parser.map("combo", Combo.class); 150 152 parser.map("multiselect", MultiSelect.class); … … 182 184 183 185 /** to detect end of {@code <checkgroup>} */ 184 186 CheckGroup lastcheckgroup = null; 187 /** to detect end of {@code <selectgroup>} */ 188 SelectGroup lastselectgroup = null; 189 int selectgroupcount = PresetListEntry.SELECT_GROUP_NONE; 185 190 /** to detect end of {@code <group>} */ 186 191 TaggingPresetMenu lastmenu = null; 187 192 /** to detect end of reused {@code <group>} */ … … 302 307 all.getLast().data.add((TaggingPresetItem) o); 303 308 } 304 309 } else if (o instanceof PresetListEntry) { 305 listEntries.add((PresetListEntry) o); 310 PresetListEntry entry = (PresetListEntry) o; 311 312 if(lastselectgroup != null) { 313 if(!lastselectgroup.exclusive) { 314 entry.select_group = selectgroupcount; 315 } 316 else { 317 entry.select_group = -selectgroupcount; 318 } 319 } 320 321 listEntries.add(entry); 306 322 } else if (o instanceof CheckGroup) { 307 323 CheckGroup cg = (CheckGroup) o; 308 324 if (cg == lastcheckgroup) { … … 316 332 } else { 317 333 lastcheckgroup = cg; 318 334 } 335 } else if (o instanceof SelectGroup) { 336 SelectGroup sg = (SelectGroup) o; 337 if (sg == lastselectgroup) { 338 lastselectgroup = null; 339 } else { 340 lastselectgroup = sg; 341 selectgroupcount++; 342 } 319 343 } else { 320 344 if (!checks.isEmpty()) { 321 345 all.getLast().data.addAll(checks); … … 329 353 } 330 354 listEntries.clear(); 331 355 lastrole = null; 356 selectgroupcount = PresetListEntry.SELECT_GROUP_NONE; 332 357 } 333 358 } else 334 359 throw new SAXException(tr("Preset sub element without parent")); -
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresets.java
123 123 } 124 124 } 125 125 } 126 if (SORT_MENU.get()) { 127 TaggingPresetMenu.sortMenu(presetsMenu);128 } 126 127 TaggingPresetMenu.sortMenu(presetsMenu, SORT_MENU.get()); 128 129 129 listeners.forEach(TaggingPresetListener::taggingPresetsModified); 130 130 } 131 131 -
src/org/openstreetmap/josm/gui/tagging/presets/items/Combo.java
168 168 combobox.setToolTipText(getKeyTooltipText()); 169 169 combobox.applyComponentOrientation(OrientationAction.getValueOrientation(key)); 170 170 171 return true; 171 172 return isNeeded(usage); 172 173 } 173 174 175 176 174 177 /** 175 178 * Finds the PresetListEntry that matches value. 176 179 * <p> -
src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java
35 35 * Abstract superclass for combo box and multi-select list types. 36 36 */ 37 37 public abstract class ComboMultiSelect extends KeyedItem { 38 38 protected static final String VALUE_SORT_USER = "user"; 39 39 /** 40 40 * A list of entries. 41 41 * The list has to be separated by commas (for the {@link Combo} box) or by the specified delimiter (for the {@link MultiSelect}). … … 53 53 /** Disabled internationalisation for value to avoid mistakes, see #11696 */ 54 54 public boolean values_no_i18n; // NOSONAR 55 55 /** Whether to sort the values, defaults to true. */ 56 public boolean values_sort = true; // NOSONAR 56 public String values_sort = String.valueOf(true); // NOSONAR 57 /** Whether to show this combo in dialog only when it's needed. 58 * It's needed when key doesn't exist or if current value is not in values */ 59 public boolean if_needed_only = false; // NOSONAR 57 60 /** 58 61 * A list of entries that is displayed to the user. 59 62 * Must be the same number and order of entries as {@link #values} and editable must be false or not specified. … … 138 141 // editor-ersatz of a readonly combobox. fixes #6157 139 142 l.setText(value.getListDisplay(width)); 140 143 } 144 141 145 if (value.getCount() > 0) { 142 146 l.setFont(l.getFont().deriveFont(Font.ITALIC + Font.BOLD)); 143 147 } … … 310 314 addListEntry(e); 311 315 } 312 316 313 if (values_sort && TaggingPresets.SORT_MENU.get()) {317 if (values_sort.equals(String.valueOf(true)) && TaggingPresets.SORT_MENU.get()) { 314 318 Collections.sort(presetListEntries, (a, b) -> AlphanumComparator.getInstance().compare(a.getDisplayValue(), b.getDisplayValue())); 315 319 } 316 320 } … … 430 434 public MatchType getDefaultMatch() { 431 435 return MatchType.NONE; 432 436 } 437 438 protected boolean isNeeded(Usage usage) { 439 boolean result = !if_needed_only || usage.unused(); 440 441 if (!result) { 442 for (String v : usage.map.keySet()) { 443 boolean found = false; 444 445 for (PresetListEntry p : presetListEntries) { 446 if (p.value.equals(v)) { 447 found = true; 448 break; 449 } 450 } 451 452 if (!found) { 453 return true; 454 } 455 } 456 } 457 458 return result; 459 } 433 460 } -
src/org/openstreetmap/josm/gui/tagging/presets/items/Key.java
7 7 8 8 import javax.swing.JPanel; 9 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 11 import org.openstreetmap.josm.data.osm.Tag; 11 12 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 12 13 … … 14 15 * Invisible type allowing to hardcode an OSM key/value from the preset definition. 15 16 */ 16 17 public class Key extends KeyedItem { 18 private static final String VALUE_APPEND_ALWAYS = "always"; 17 19 18 20 /** The hardcoded value for key */ 19 21 public String value; // NOSONAR 20 22 23 /** The hardcoded value for key appending existing value **/ 24 public String append_value; // NOSONAR 25 26 /** The hardcoded delimiter to use for appending values **/ 27 public String delimiter = ";"; // NOSONAR 28 29 /** The hardcoded type of appending */ 30 public String append = null; // NOSONAR 31 32 /** The hardcoded prefix to use for setting value to empty key */ 33 public String prefix = null; // NOSONAR 34 35 private String useValue; 36 21 37 @Override 22 38 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) { 39 if (prefix != null) { 40 useValue = prefix + value; 41 } 42 else { 43 useValue = value; 44 } 45 46 // If append_value is present append also if append was not set 47 if (append_value != null || append != null) { 48 String toUse = append_value != null ? append_value : value; 49 50 Collection<OsmPrimitive> col = support.getSelected(); 51 52 for (OsmPrimitive pr : col) { 53 String currentValue = pr.get(key); 54 55 if (currentValue != null) { 56 useValue = currentValue; 57 58 if ((append != null && append.equals(VALUE_APPEND_ALWAYS)) || !useValue.contains(toUse)) { 59 useValue += delimiter + toUse; 60 } 61 62 break; 63 } 64 } 65 } 66 23 67 return false; 24 68 } 25 69 … … 33 77 * @return the tag 34 78 */ 35 79 public Tag asTag() { 36 return new Tag(key, value);80 return new Tag(key, useValue != null ? useValue : value); 37 81 } 38 82 39 83 @Override … … 43 87 44 88 @Override 45 89 public Collection<String> getValues() { 46 return Collections.singleton( value);90 return Collections.singleton(useValue != null ? useValue : value); 47 91 } 48 92 49 93 @Override 50 94 public String toString() { 51 return "Key [key=" + key + ", value=" + value + ", text=" + text52 + ", text _context=" + text_context + ", match=" + match53 + ']';95 return "Key [key=" + key + ", value=" + value + ", value_append=" + append_value 96 + ", text=" + text + ", text_context=" + text_context + ", match=" + match 97 + ", delimiter=" + delimiter + ']'; 54 98 } 55 99 } -
src/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelect.java
1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 6 import java.awt.Dimension; 7 import java.awt.GridBagLayout; 5 8 import java.awt.Insets; 6 9 import java.awt.Rectangle; 7 import java.util.stream.Collectors; 10 import java.awt.event.MouseAdapter; 11 import java.awt.event.MouseEvent; 12 import java.util.Collections; 13 import java.util.List; 14 import java.util.Objects; 8 15 9 16 import javax.swing.DefaultListModel; 17 import javax.swing.DefaultListSelectionModel; 18 import javax.swing.JButton; 10 19 import javax.swing.JLabel; 11 20 import javax.swing.JList; 12 21 import javax.swing.JPanel; 13 22 import javax.swing.JScrollPane; 23 import javax.swing.ListModel; 24 import javax.swing.ListSelectionModel; 25 import javax.swing.event.ListSelectionEvent; 26 import javax.swing.event.ListSelectionListener; 14 27 15 28 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 29 import org.openstreetmap.josm.gui.util.ReorderableTableModel; 16 30 import org.openstreetmap.josm.gui.widgets.OrientationAction; 17 31 import org.openstreetmap.josm.tools.GBC; 32 import org.openstreetmap.josm.tools.ImageProvider; 33 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 18 34 19 35 /** 20 36 * Multi-select list type. 21 37 */ 22 38 public class MultiSelect extends ComboMultiSelect { 23 24 39 /** 25 40 * Number of rows to display (positive integer, optional). 26 41 */ 27 42 public short rows; // NOSONAR 28 43 29 44 /** The model for the JList */ 30 protected final DefaultListModel<PresetListEntry> model = new DefaultListModel<>();45 protected final PresetListModel model = new PresetListModel(); 31 46 /** The swing component */ 32 47 protected final JList<PresetListEntry> list = new JList<>(model); 33 48 49 /** 50 * Text that will be put in front of the resulting value. 51 */ 52 public String prefix; // NOSONAR 53 54 /** 55 * If the entries in the list should be selected with clicking only. 56 */ 57 public boolean quick_select = false; 58 59 /** 60 * Use selection model that selects/deselects values with single click. 61 * @since 18619 62 */ 63 public MultiSelect() { 64 list.setSelectionModel(new SingleClickSelectionModel(list)); 65 } 66 34 67 private void addEntry(PresetListEntry entry) { 68 addEntry(entry, -1); 69 } 70 71 private void addEntry(PresetListEntry entry, int presetCount) { 72 if (prefix != null && entry.value.startsWith(prefix)) { 73 entry.value = entry.value.substring(prefix.length()); 74 } 75 35 76 if (!seenValues.containsKey(entry.value)) { 36 model.addElement(entry); 37 seenValues.put(entry.value, entry); 77 boolean add = true; 78 79 for (int i = 0; i < model.size(); i++) { 80 PresetListEntry test = model.get(i); 81 82 if (test.delimiter != null && entry.value.matches(".+\\\\{0}" + test.delimiter+".+")) { 83 add = false; 84 85 if (usage != null && usage.map.containsKey(entry.value)) { 86 usage.map.remove(entry.value); 87 } 88 89 String[] parts = entry.value.split(test.delimiter,-1); 90 91 for (int j = 0; j < parts.length; j++) { 92 if (prefix != null && parts[j].startsWith(prefix)) { 93 parts[j] = parts[j].substring(prefix.length()); 94 } 95 addEntry(new PresetListEntry(parts[j], this, j == 0 ? String.valueOf(delimiter) : test.delimiter), presetCount); 96 } 97 98 break; 99 } 100 } 101 102 if (add) { 103 if (presetCount == -1) { 104 model.addElement(entry); 105 } 106 else { 107 model.insertElementAt(entry, model.getSize() - presetCount); 108 } 109 seenValues.put(entry.value, entry); 110 } 38 111 } 39 112 } 40 113 114 private void select(PresetListEntry entry, boolean addUsage) { 115 for (int i = 0; i < model.getSize(); i++) { 116 PresetListEntry test = model.get(i); 117 118 if (Objects.equals(test.value, entry.value)) { 119 int[] indices = model.getSelectedIndices(); 120 121 if (indices != null && indices.length > 0 && indices[indices.length - 1] > i) { 122 PresetListEntry removed = model.remove(i); 123 model.add(indices[indices.length-1], removed); 124 list.addSelectionInterval(indices[indices.length-1], indices[indices.length-1]); 125 } 126 else { 127 list.addSelectionInterval(i, i); 128 } 129 130 if (addUsage && usage != null && usage.map != null && !usage.map.containsKey(test.value)) { 131 usage.map.put(test.value, 1); 132 } 133 134 break; 135 } 136 else if (test.delimiter != null && entry.value.matches(".*\\\\{0}" + test.delimiter+".*")) { 137 for (String part : entry.value.split(test.delimiter, -1)) { 138 select(new PresetListEntry(part, this, test.delimiter), true); 139 } 140 } 141 } 142 } 143 41 144 @Override 42 145 protected boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) { 43 146 initializeLocaleText(null); 44 147 usage = determineTextUsage(support.getSelected(), key); 148 149 if (prefix != null) { 150 String[] keys = usage.map.keySet().toArray(new String[0]); 151 152 if(key != null) { 153 for (String k : keys) { 154 if(k.startsWith(prefix)) { 155 Integer count = usage.map.remove(k); 156 usage.map.put(k.substring(prefix.length()), count); 157 } 158 } 159 } 160 } 161 45 162 seenValues.clear(); 46 163 initListEntries(); 47 48 164 model.clear(); 49 165 // disable if the selected primitives have different values 50 166 list.setEnabled(usage.hasUniqueValue() || usage.unused()); … … 53 169 // Add values from the preset. 54 170 presetListEntries.forEach(this::addEntry); 55 171 172 int count = model.getSize(); 173 56 174 // Add all values used in the selected primitives. This also adds custom values and makes 57 175 // sure we won't lose them. 58 176 usage = usage.splitValues(String.valueOf(delimiter)); 59 for (String value: usage.map.keySet()) { 60 addEntry(new PresetListEntry(value, this)); 177 String[] keys = usage.map.keySet().toArray(new String[0]); 178 179 if (keys != null) { 180 for (String value: keys) { 181 addEntry(new PresetListEntry(value, this), count); 182 } 61 183 } 62 184 63 185 // Select the values in the initial value. … … 65 187 for (String value : initialValue.split(String.valueOf(delimiter), -1)) { 66 188 PresetListEntry e = new PresetListEntry(value, this); 67 189 addEntry(e); 68 int i = model.indexOf(e); 69 list.addSelectionInterval(i, i); 190 select(e, !usage.unused()); 70 191 } 71 192 } 193 else if (default_ != null) { 194 select(new PresetListEntry(default_, this), false); 195 } 72 196 73 197 ComboMultiSelectListCellRenderer renderer = new ComboMultiSelectListCellRenderer(list, list.getCellRenderer(), 200, key); 74 198 list.setCellRenderer(renderer); … … 89 213 insets = sp.getInsets(); 90 214 r.width += insets.left + insets.right; 91 215 r.height += insets.top + insets.bottom; 92 sp.setPreferredSize(new Dimension( r.width, r.height));216 sp.setPreferredSize(new Dimension(Math.max(r.width, sp.getPreferredSize().width), r.height)); 93 217 } 94 218 } 95 p.add(sp, GBC.eol().fill(GBC.HORIZONTAL)); // NOSONAR 219 220 if(values_sort.equals(VALUE_SORT_USER)) { 221 final JButton up = new JButton(ImageProvider.get("dialogs", "up", ImageSizes.LARGEICON)); 222 up.setToolTipText(tr("Move the currently selected members up")); 223 up.addActionListener(e -> { 224 model.moveUp(); 225 }); 226 final JButton down = new JButton(ImageProvider.get("dialogs", "down", ImageSizes.LARGEICON)); 227 down.setToolTipText(tr("Move the currently selected members down")); 228 down.addActionListener(e -> { 229 model.moveDown(); 230 }); 231 up.setEnabled(model.canMoveUp()); 232 down.setEnabled(model.canMoveDown()); 233 234 list.addListSelectionListener(new ListSelectionListener() { 235 @Override 236 public void valueChanged(ListSelectionEvent e) { 237 up.setEnabled(model.canMoveUp()); 238 down.setEnabled(model.canMoveDown()); 239 } 240 }); 241 242 JPanel content = new JPanel(new GridBagLayout()); 243 content.add(sp, GBC.std(0,0).span(1, 4).fill()); 244 content.add(GBC.glue(0, 1), GBC.std(1, 0).fill(GBC.VERTICAL)); 245 content.add(up, GBC.std(1, 1)); 246 content.add(down, GBC.std(1, 2)); 247 content.add(GBC.glue(0, 1), GBC.std(1, 3).fill(GBC.VERTICAL)); 248 249 p.add(content, GBC.eol().fill(GBC.HORIZONTAL)); // NOSONAR 250 } 251 else { 252 p.add(sp, GBC.eol().fill(GBC.HORIZONTAL)); // NOSONAR 253 } 96 254 97 255 list.addListSelectionListener(l -> support.fireItemValueModified(this, key, getSelectedItem().value)); 98 256 list.setToolTipText(getKeyTooltipText()); 99 257 list.applyComponentOrientation(OrientationAction.getValueOrientation(key)); 100 258 101 return true;259 return isNeeded(usage); 102 260 } 103 261 104 262 @Override 105 263 protected PresetListEntry getSelectedItem() { 106 return new PresetListEntry(list.getSelectedValuesList() 107 .stream().map(e -> e.value).distinct().sorted().collect(Collectors.joining(String.valueOf(delimiter))), this); 264 StringBuilder result = new StringBuilder(); 265 List<PresetListEntry> temp = list.getSelectedValuesList(); 266 267 if (!temp.isEmpty()) { 268 if (values_sort.equals(String.valueOf(true))) { 269 Collections.sort(temp); 270 } 271 272 if (prefix != null) { 273 result.append(prefix); 274 } 275 276 result.append(temp.get(0).value); 277 278 for (int i = 1; i < temp.size(); i++) { 279 if (result.indexOf(temp.get(i).value) == -1) { 280 result.append(temp.get(i).delimiter != null ? temp.get(i).delimiter : delimiter).append(temp.get(i).value); 281 } 282 } 283 } 284 285 return new PresetListEntry(result.toString(), this); 286 } 287 288 private final class SingleClickSelectionModel extends DefaultListSelectionModel { 289 private boolean mousePressed; 290 private ListModel<PresetListEntry> model; 291 292 private SingleClickSelectionModel(JList<PresetListEntry> list) { 293 this.model = list.getModel(); 294 list.addMouseListener(new MouseAdapter() { 295 @Override 296 public void mousePressed(MouseEvent e) { 297 mousePressed = true; 298 } 299 @Override 300 public void mouseReleased(MouseEvent e) { 301 mousePressed = false; 302 } 303 }); 304 } 305 306 @Override 307 public void addSelectionInterval(int index0, int index1) { 308 removeSelectionForGroupAtIndex(index0); 309 super.addSelectionInterval(index0, index1); 310 } 311 312 private void removeSelectionForGroupAtIndex(int index) { 313 if(!isSelectedIndex(index)) { 314 int selectGroup = model.getElementAt(index).select_group; 315 316 for(int i = 0; i < model.getSize(); i++) { 317 if(isSelectedIndex(i) && (selectGroup < 0 || (model.getElementAt(i).select_group != PresetListEntry.SELECT_GROUP_NONE && model.getElementAt(i).select_group == selectGroup) || model.getElementAt(i).select_group < 0)) { 318 super.removeSelectionInterval(i, i); 319 } 320 } 321 } 322 } 323 324 @Override 325 public void setSelectionInterval(int index0, int index1) { 326 if (quick_select && getSelectionMode() == MULTIPLE_INTERVAL_SELECTION) { 327 if (!mousePressed) { 328 if (isSelectedIndex(index0)) { 329 super.removeSelectionInterval(index0, index1); 330 } 331 else { 332 removeSelectionForGroupAtIndex(index0); 333 super.addSelectionInterval(index0, index1); 334 } 335 } 336 } 337 else { 338 super.setSelectionInterval(index0, index1); 339 } 340 } 341 } 342 343 private final class PresetListModel extends DefaultListModel<PresetListEntry> implements ReorderableTableModel<PresetListEntry> { 344 @Override 345 public PresetListEntry getValue(int index) { 346 return get(index); 347 } 348 349 @Override 350 public PresetListEntry setValue(int index, PresetListEntry value) { 351 return set(index, value); 352 } 353 354 @Override 355 public ListSelectionModel getSelectionModel() { 356 return list.getSelectionModel(); 357 } 358 359 @Override 360 public int getRowCount() { 361 return size(); 362 } 108 363 } 109 364 } -
src/org/openstreetmap/josm/gui/tagging/presets/items/PresetListEntry.java
21 21 * {@link MultiSelect}. 22 22 */ 23 23 public class PresetListEntry implements Comparable<PresetListEntry> { 24 /** Value for entries without a select group*/ 25 public static final int SELECT_GROUP_NONE = 0; 24 26 /** Used to display an entry matching several different values. */ 25 27 protected static final PresetListEntry ENTRY_DIFFERENT = new PresetListEntry(KeyedItem.DIFFERENT, null); 26 28 /** Used to display an empty entry used to clear values. */ … … 46 48 public String locale_display_value; // NOSONAR 47 49 /** The localized version of {@link #short_description}. */ 48 50 public String locale_short_description; // NOSONAR 51 /** The delimiter for separating this entry from the previous */ 52 public String delimiter; // NOSONAR 53 /** The select group for multi select */ 54 public int select_group = SELECT_GROUP_NONE; 49 55 50 56 private String cachedDisplayValue; 51 57 private String cachedShortDescription; 52 58 private ImageIcon cachedIcon; 53 59 60 54 61 /** 55 62 * Constructs a new {@code PresetListEntry}, uninitialized. 56 63 * … … 67 74 * @param cms the ComboMultiSelect 68 75 */ 69 76 public PresetListEntry(String value, ComboMultiSelect cms) { 77 this(value, cms, null); 78 } 79 80 /** 81 * Constructs a new {@code PresetListEntry}, initialized with a value and 82 * {@link ComboMultiSelect} context and the delimiter for this entry. 83 * 84 * @param value value 85 * @param cms the ComboMultiSelect 86 * @param delimiter The character to use to separate this entry from the previous 87 * @since 18619 88 */ 89 public PresetListEntry(String value, ComboMultiSelect cms, String delimiter) { 70 90 this.value = value; 71 91 this.cms = cms; 92 this.delimiter = delimiter; 72 93 } 73 94 74 95 /** -
src/org/openstreetmap/josm/gui/tagging/presets/items/SelectGroup.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.tagging.presets.items; 3 4 import java.util.List; 5 6 import javax.swing.JPanel; 7 8 import org.openstreetmap.josm.data.osm.Tag; 9 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem; 10 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 11 12 /** 13 * A group of {@link PresetListEntry}s. 14 * @since 18637 15 */ 16 public class SelectGroup extends TaggingPresetItem { 17 /** If items in this SelectGroup can only be selected when no item in the complete list is selected */ 18 public boolean exclusive = false; 19 20 @Override 21 protected boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) { 22 // TODO Auto-generated method stub 23 return false; 24 } 25 26 @Override 27 protected void addCommands(List<Tag> changedTags) { 28 // TODO Auto-generated method stub 29 30 } 31 32 }
