Ticket #22664: flexibilize-presets_v7.patch
File flexibilize-presets_v7.patch, 75.0 KB (added by , 2 years ago) |
---|
-
resources/data/tagging-preset.xsd
100 100 <complexType name="group"> 101 101 <annotation> 102 102 <documentation> 103 Used to group items in sub menus. name is required, icon is optional attribute.103 Used to group items in sub menus. name is required, icon and item_sort are optional attributes. 104 104 </documentation> 105 105 </annotation> 106 106 <complexContent> 107 107 <extension base="tns:group-parent"> 108 108 <attributeGroup ref="tns:attributes.name" /> 109 <attribute name="items_sort" type="tns:items_sort" /> 109 110 </extension> 110 111 </complexContent> 111 112 </complexType> … … 198 199 <group ref="tns:optional_elements" /> 199 200 <element name="key" type="tns:key" /> 200 201 <element name="optional" type="tns:optional" minOccurs="0" /> 202 <element name="selectgroup" type="tns:selectgroup" minOccurs="0" /> 201 203 <element name="roles" type="tns:roles" minOccurs="0" /> 202 204 </choice> 203 205 </sequence> … … 267 269 ]]></documentation> 268 270 </annotation> 269 271 </attribute> 272 <attribute name="prefix" type="string"> 273 <annotation> 274 <documentation> 275 Text that will be put at the start of the resulting value if key is empty, it's not used for appending of existing values. 276 </documentation> 277 </annotation> 278 </attribute> 279 <attributeGroup ref="tns:attributes.append" /> 270 280 <attribute name="match" type="tns:match" /> 271 281 </complexType> 272 282 … … 378 388 </annotation> 379 389 </attribute> 380 390 <attributeGroup ref="tns:attributes.icon" /> 391 <attribute name="delimiter" type="tns:values.delimiter" /> 381 392 <anyAttribute processContents="skip" /> 382 393 </complexType> 383 394 … … 404 415 <attributeGroup ref="tns:attributes.icon" /> 405 416 <attributeGroup ref="tns:attributes.values" /> 406 417 <attribute name="use_last_as_default" type="tns:last_default" /> 418 <attribute name="if_needed_only" type="tns:if_needed_only" /> 407 419 <attribute name="editable" type="boolean"> 408 420 <annotation> 409 421 <documentation> … … 425 437 <complexType name="multiselect"> 426 438 <!-- use either list_entry's or a combination of values/display_values --> 427 439 <sequence> 440 <element name="selectgroup" type="tns:selectgroup" minOccurs="0" maxOccurs="unbounded" /> 428 441 <group ref="tns:list_elements" minOccurs="0" maxOccurs="unbounded" /> 429 442 </sequence> 430 443 <attributeGroup ref="tns:attributes.key" /> … … 433 446 <attributeGroup ref="tns:attributes.values" /> 434 447 <attribute name="use_last_as_default" type="tns:last_default" /> 435 448 <attribute name="match" type="tns:match" /> 436 449 <attribute name="quick_select" type="boolean"> 450 <annotation> 451 <documentation> 452 Allows to enable quick selection of list entries with just clicking on it, without the need to use keyboard. Default is false. 453 </documentation> 454 </annotation> 455 </attribute> 456 <attribute name="prefix" type="string"> 457 <annotation> 458 <documentation> 459 Text that will be put at the start of the resulting value. If values start with prefix, it will be remove from the value first. 460 </documentation> 461 </annotation> 462 </attribute> 463 437 464 <attribute name="type" use="prohibited" /> 438 465 <attribute name="value" use="prohibited" /> 439 466 <attribute name="name" use="prohibited" /> … … 441 468 <attribute name="display-values" use="prohibited" /> 442 469 <anyAttribute processContents="skip" /> 443 470 </complexType> 444 471 445 472 <complexType name="checkgroup"> 446 473 <annotation> 447 474 <documentation> … … 462 489 </attribute> 463 490 <anyAttribute processContents="skip" /> 464 491 </complexType> 492 493 <complexType name="selectgroup"> 494 <annotation> 495 <documentation> 496 To group list_entries for multiselect. From all list_entries in a group only one can be selected at a time. 497 </documentation> 498 </annotation> 499 <sequence> 500 <choice minOccurs="1" maxOccurs="unbounded"> 501 <element name="list_entry" type="tns:list_entry" /> 502 <element name="reference" type="tns:reference" /> 503 </choice> 504 </sequence> 505 <attribute name="exclusive" type="boolean"> 506 <annotation> 507 <documentation><![CDATA[ 508 If items of the <selectgroup> can only be selected when no other item in any other <selectgroup> is selected. 509 ]]></documentation> 510 </annotation> 511 </attribute> 512 <anyAttribute processContents="skip" /> 513 </complexType> 465 514 466 515 <complexType name="check"> 467 516 <attributeGroup ref="tns:attributes.key" /> … … 502 551 <enumeration value="off" /> 503 552 </restriction> 504 553 </simpleType> 554 555 <simpleType name="append"> 556 <annotation> 557 <documentation> 558 Specify if value should be appended to existing value. This defaults implicitly to default if append_value is provided. 559 </documentation> 560 </annotation> 561 <restriction base="string"> 562 <enumeration value="default" /> 563 <enumeration value="always" /> 564 </restriction> 565 </simpleType> 566 567 <simpleType name="items_sort"> 568 <annotation> 569 <documentation> 570 If the items in the menu should be sorted. Defaults to "yes", when "always" is set the menu items will be sorted regardless how the sorting is configured in JOSM. 571 </documentation> 572 </annotation> 573 <restriction base="string"> 574 <enumeration value="yes" /> 575 <enumeration value="no" /> 576 <enumeration value="always" /> 577 </restriction> 578 </simpleType> 579 580 <simpleType name="values.delimiter"> 581 <annotation> 582 <documentation><![CDATA[ 583 The character that separates values. In case of <combo /> the default is comma. In case of <multiselect /> the default is semicolon and this will also be used to separate selected values in the tag. 584 ]]></documentation> 585 </annotation> 586 <restriction base="string"> 587 <minLength value="1"/> 588 <maxLength value="1"/> 589 </restriction> 590 </simpleType> 591 592 <simpleType name="append.delimiter"> 593 <annotation> 594 <documentation><![CDATA[ 595 The character that separates values for <key />. The default is semicolon and it's possible to provide an empty delimiter. 596 ]]></documentation> 597 </annotation> 598 <restriction base="string"> 599 <minLength value="0"/> 600 <maxLength value="1"/> 601 </restriction> 602 </simpleType> 603 604 <simpleType name="if_needed_only"> 605 <annotation> 606 <documentation> 607 Show combo selection only if key is missing otherwise don't show it and retain current value. 608 </documentation> 609 </annotation> 610 <restriction base="string"> 611 <enumeration value="true" /> 612 <enumeration value="false" /> 613 </restriction> 614 </simpleType> 505 615 506 616 <simpleType name="last_default"> 507 617 <annotation> … … 588 698 <enumeration value="optional" /> 589 699 </restriction> 590 700 </simpleType> 701 702 <simpleType name="sort_options"> 703 <annotation> 704 <documentation> 705 Possible options for values_sort. Default is "true"; 706 </documentation> 707 </annotation> 708 <restriction base="string"> 709 <enumeration value="true" /> 710 <enumeration value="false" /> 711 <enumeration value="user" /> 712 </restriction> 713 </simpleType> 591 714 592 715 <!-- Types and documentation for attributes --> 593 716 717 <attributeGroup name="attributes.append"> 718 <attribute name="append_value" type="string"> 719 <annotation> 720 <documentation><![CDATA[ 721 Specify a value to be appended to the <key> tag. Optional if this value should be used instead of value. The value is only appened if it doesn't already is set for <key> tag or if append=always was specified. 722 ]]></documentation> 723 </annotation> 724 </attribute> 725 <attribute name="append" type="tns:append" /> 726 <attribute name="delimiter" type="tns:append.delimiter" /> 727 </attributeGroup> 728 594 729 <attributeGroup name="attributes.name"> 595 730 <attribute name="name" type="string" use="required"> 596 731 <annotation> … … 671 806 </documentation> 672 807 </annotation> 673 808 </attribute> 674 <attribute name="values_sort" type=" boolean">809 <attribute name="values_sort" type="tns:sort_options"> 675 810 <annotation> 676 811 <documentation> 677 812 Values of are sorted alphabetic in every language. With this attribute you can disable the alphabetic sorting if the values should keep the given order, see #5509 and #11926. (In the JOSM internal preset this is used e.g. for the keys tracktype, direction, network, smoothness, visibility or trail_visibility.) Default is "true".<br /> … … 693 828 </documentation> 694 829 </annotation> 695 830 </attribute> 696 <attribute name="delimiter" type="string"> 697 <annotation> 698 <documentation><![CDATA[ 699 The character that separates values. In case of <combo /> the default is comma. In case of <multiselect /> the default is semicolon and this will also be used to separate selected values in the tag. 700 ]]></documentation> 701 </annotation> 702 </attribute> 831 <attribute name="delimiter" type="tns:values.delimiter" /> 703 832 </attributeGroup> 704 833 705 834 <attributeGroup name="attributes.icon"> -
src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java
39 39 Collection<OsmPrimitive> selection = t.createSelection(presetHandler.getSelection()); 40 40 if (selection.isEmpty()) 41 41 return; 42 int answer = t.showDialog(selection, false );42 int answer = t.showDialog(selection, false, (e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK); 43 43 DataSet ds = selection.iterator().next().getDataSet(); 44 44 boolean locked = ds != null && ds.isLocked(); 45 45 -
src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java
154 154 private SourceEditor sources; 155 155 private JCheckBox useValidator; 156 156 private JCheckBox sortMenu; 157 private JCheckBox ifNeddedOnlyEnabled; 157 158 158 159 /** 159 160 * Registers a new additional preset source provider. … … 172 173 public void addGui(PreferenceTabbedPane gui) { 173 174 useValidator = new JCheckBox(tr("Run data validator on user input"), TaggingPreset.USE_VALIDATOR.get()); 174 175 sortMenu = new JCheckBox(tr("Sort presets menu alphabetically"), TaggingPresets.SORT_MENU.get()); 175 176 ifNeddedOnlyEnabled = new JCheckBox(tr("Show input dialogs only if needed (can be overwritten with CTRL key down)"), TaggingPresets.IF_NEEDED_ONLY_ENABLED.get()); 176 177 final JPanel panel = new JPanel(new GridBagLayout()); 177 178 panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 178 179 179 180 panel.add(useValidator, GBC.std().insets(5, 5, 0, 0)); 180 181 panel.add(new JLabel(ImageProvider.get("dialogs/validator")), GBC.eol().insets(5, 5, 0, 0)); 181 182 panel.add(sortMenu, GBC.eol().insets(5, 0, 5, 0)); 183 panel.add(ifNeddedOnlyEnabled, GBC.eol().insets(5, 0, 5, 0)); 182 184 183 185 sources = new TaggingPresetSourceEditor(); 184 186 panel.add(sources, GBC.eol().fill(GBC.BOTH)); … … 252 254 @Override 253 255 public boolean ok() { 254 256 TaggingPreset.USE_VALIDATOR.put(useValidator.isSelected()); 255 if (sources.finish() || TaggingPresets.SORT_MENU.put(sortMenu.isSelected())) { 257 boolean rebuild = TaggingPresets.SORT_MENU.put(sortMenu.isSelected()); 258 rebuild = TaggingPresets.IF_NEEDED_ONLY_ENABLED.put(ifNeddedOnlyEnabled.isSelected()) || rebuild; 259 260 if (sources.finish() || rebuild) { 256 261 TaggingPresets.destroy(); 257 262 TaggingPresets.initialize(); 258 263 } -
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 … … 362 376 * This includes the elements from the individual {@link TaggingPresetItem items}. 363 377 * 364 378 * @param selected the selected primitives 379 * @param ctrlDown if the CTRL key was pressed while selecting preset menu entry 365 380 * @return the newly created panel 366 381 */ 367 public PresetPanel createPanel(Collection<OsmPrimitive> selected ) {382 public PresetPanel createPanel(Collection<OsmPrimitive> selected, boolean ctrlDown) { 368 383 PresetPanel p = new PresetPanel(); 369 384 370 385 final JPanel pp = new JPanel(); … … 422 437 TaggingPresetItem previous = null; 423 438 for (TaggingPresetItem i : data) { 424 439 if (i instanceof Link) { 425 i.addToPanel(linkPanel, itemGuiSupport );440 i.addToPanel(linkPanel, itemGuiSupport, ctrlDown); 426 441 p.hasElements = true; 427 442 } else { 428 443 if (i instanceof PresetLink) { … … 431 446 itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0)); 432 447 } 433 448 } 434 if (i.addToPanel(itemPanel, itemGuiSupport )) {449 if (i.addToPanel(itemPanel, itemGuiSupport, ctrlDown)) { 435 450 p.hasElements = true; 436 451 } 437 452 } … … 503 518 if (ds == null) { 504 519 return; 505 520 } 506 showAndApply(ds.getSelected() );521 showAndApply(ds.getSelected(), (e.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK); 507 522 } 508 523 509 524 /** 510 525 * {@linkplain #showDialog Show preset dialog}, apply changes 511 526 * @param primitives the primitives 527 * @param ctrlDown if the CTRL key was pressed while selecting preset menu entry 512 528 */ 513 public void showAndApply(Collection<OsmPrimitive> primitives ) {529 public void showAndApply(Collection<OsmPrimitive> primitives, boolean ctrlDown) { 514 530 // Display dialog even if no data layer (used by preset-tagging-tester plugin) 515 531 Collection<OsmPrimitive> sel = createSelection(primitives); 516 int answer = showDialog(sel, supportsRelation() );532 int answer = showDialog(sel, supportsRelation(), ctrlDown); 517 533 518 534 if (!sel.isEmpty() && answer == DIALOG_ANSWER_APPLY) { 519 535 Command cmd = createCommand(sel, getChangedTags()); … … 598 614 * Shows the preset dialog. 599 615 * @param sel selection 600 616 * @param showNewRelation whether to display "New relation" button 617 * @param ctrlDown if the CTRL key was pressed while selecting preset menu entry 601 618 * @return the user choice after the dialog has been closed 602 619 */ 603 public int showDialog(Collection<OsmPrimitive> sel, boolean showNewRelation ) {604 PresetPanel p = createPanel(sel );620 public int showDialog(Collection<OsmPrimitive> sel, boolean showNewRelation, boolean ctrlDown) { 621 PresetPanel p = createPanel(sel, ctrlDown); 605 622 606 623 int answer = 1; 607 624 boolean canCreateRelation = types == null || types.contains(TaggingPresetType.RELATION); -
src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java
78 78 * All components defining this tagging preset item must be added to given panel. 79 79 * 80 80 * @param p The panel where components must be added 81 * @param ctrlDown if the CTRL key was pressed when selecting preset menu item 81 82 * @param support supporting class for creating the GUI 82 83 * @return {@code true} if this item adds semantic tagging elements, {@code false} otherwise. 83 84 */ 84 protected abstract boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support );85 protected abstract boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown); 85 86 86 87 /** 87 88 * Adds the new tags to apply to selected OSM primitives when the preset holding this item is applied. -
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
54 54 */ 55 55 public static final BooleanProperty SORT_MENU = new BooleanProperty("taggingpreset.sortvalues", true); 56 56 /** 57 * Sort presets menu alphabetically 58 */ 59 public static final BooleanProperty IF_NEEDED_ONLY_ENABLED = new BooleanProperty("taggingpreset.ifneededonlyenabled", false); 60 /** 57 61 * Custom icon sources 58 62 */ 59 63 public static final ListProperty ICON_SOURCES = new ListProperty("taggingpreset.icon.sources", null); … … 123 127 } 124 128 } 125 129 } 126 if (SORT_MENU.get()) { 127 TaggingPresetMenu.sortMenu(presetsMenu);128 } 130 131 TaggingPresetMenu.sortMenu(presetsMenu, SORT_MENU.get()); 132 129 133 listeners.forEach(TaggingPresetListener::taggingPresetsModified); 130 134 } 131 135 -
src/org/openstreetmap/josm/gui/tagging/presets/items/Check.java
35 35 private Boolean def; 36 36 37 37 @Override 38 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {38 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 39 39 40 40 // find out if our key is already used in the selection. 41 41 final Usage usage = determineBooleanUsage(support.getSelected(), key); -
src/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroup.java
31 31 public final List<Check> checks = new LinkedList<>(); 32 32 33 33 @Override 34 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {34 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 35 35 int rows = (int) Math.ceil(checks.size() / ((double) columns)); 36 36 JPanel panel = new JPanel(new GridLayout(rows, columns)); 37 37 38 38 int i = 0; 39 39 for (Check check : checks) { 40 check.addToPanel(panel, support );40 check.addToPanel(panel, support, ctrlDown); 41 41 i++; 42 42 } 43 43 for (; i < rows * columns; i++) { -
src/org/openstreetmap/josm/gui/tagging/presets/items/Combo.java
84 84 } 85 85 86 86 @Override 87 protected boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {87 protected boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 88 88 initializeLocaleText(null); 89 89 usage = determineTextUsage(support.getSelected(), key); 90 90 seenValues.clear(); … … 168 168 combobox.setToolTipText(getKeyTooltipText()); 169 169 combobox.applyComponentOrientation(OrientationAction.getValueOrientation(key)); 170 170 171 return true; 171 172 return ctrlDown || 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 final boolean isNeeded(Usage usage) { 439 boolean result = !TaggingPresets.IF_NEEDED_ONLY_ENABLED.get() || !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/ItemSeparator.java
18 18 public class ItemSeparator extends TaggingPresetItem { 19 19 20 20 @Override 21 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {21 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 22 22 p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 5)); 23 23 return false; 24 24 } -
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 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) { 38 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 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/Label.java
13 13 public class Label extends TextItem { 14 14 15 15 @Override 16 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {16 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 17 17 initializeLocaleText(null); 18 18 JLabel label = new JLabel(locale_text); 19 19 addIcon(label); -
src/org/openstreetmap/josm/gui/tagging/presets/items/Link.java
33 33 public String locale_href; // NOSONAR 34 34 35 35 @Override 36 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {36 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 37 37 initializeLocaleText(tr("More information about this feature")); 38 38 UrlLabel label = buildUrlLabel(); 39 39 if (label != null) { -
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 protected boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {145 protected boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 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 ctrlDown || 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/Optional.java
17 17 18 18 // TODO: Draw a box around optional stuff 19 19 @Override 20 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {20 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 21 21 initializeLocaleText(tr("Optional Attributes:")); 22 22 JLabel label = new JLabel(locale_text); 23 23 label.applyComponentOrientation(support.getDefaultComponentOrientation()); -
src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java
37 37 38 38 @Override 39 39 public void mouseClicked(MouseEvent e) { 40 t.showAndApply(sel );40 t.showAndApply(sel, e.isControlDown()); 41 41 } 42 42 } 43 43 … … 54 54 } 55 55 56 56 @Override 57 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {57 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 58 58 final String presetName = preset_name; 59 59 Optional<TaggingPreset> found = TaggingPresets.getTaggingPresets().stream().filter(preset -> presetName.equals(preset.name)).findFirst(); 60 60 if (found.isPresent()) { -
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/Roles.java
189 189 public final List<Role> roles = new ArrayList<>(2); 190 190 191 191 @Override 192 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {192 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 193 193 p.add(new JLabel(" "), GBC.eol()); // space 194 194 if (!roles.isEmpty()) { 195 195 JPanel proles = new JPanel(new GridBagLayout()); -
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, boolean ctrlDown) { 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 } -
src/org/openstreetmap/josm/gui/tagging/presets/items/Space.java
Property changes on: src/org/openstreetmap/josm/gui/tagging/presets/items/SelectGroup.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain
17 17 public class Space extends TaggingPresetItem { 18 18 19 19 @Override 20 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {20 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 21 21 p.add(new JLabel(" "), GBC.eol()); // space 22 22 return false; 23 23 } -
src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java
72 72 private transient TemplateEntry valueTemplate; 73 73 74 74 @Override 75 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support ) {75 public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support, boolean ctrlDown) { 76 76 77 77 AutoCompComboBoxModel<AutoCompletionItem> model = new AutoCompComboBoxModel<>(); 78 78 List<String> keys = new ArrayList<>(); -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroupTest.java
33 33 CheckGroup cg = new CheckGroup(); 34 34 JPanel p = new JPanel(); 35 35 assertEquals(0, p.getComponentCount()); 36 assertFalse(cg.addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));36 assertFalse(cg.addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 37 37 assertTrue(p.getComponentCount() > 0); 38 38 } 39 39 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/CheckTest.java
6 6 7 7 import javax.swing.JPanel; 8 8 9 import org.junit.jupiter.api.extension.RegisterExtension;10 9 import org.junit.jupiter.api.Test; 10 import org.junit.jupiter.api.extension.RegisterExtension; 11 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 12 12 import org.openstreetmap.josm.testutils.JOSMTestRules; 13 13 … … 32 32 void testAddToPanel() { 33 33 JPanel p = new JPanel(); 34 34 assertEquals(0, p.getComponentCount()); 35 assertTrue(new Check().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));35 assertTrue(new Check().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 36 36 assertTrue(p.getComponentCount() > 0); 37 37 } 38 38 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ComboTest.java
36 36 void testAddToPanel() { 37 37 JPanel p = new JPanel(); 38 38 assertEquals(0, p.getComponentCount()); 39 assertTrue(new Combo().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));39 assertTrue(new Combo().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 40 40 assertTrue(p.getComponentCount() > 0); 41 41 } 42 42 … … 57 57 Combo.PROP_FILL_DEFAULT.put(false); 58 58 combo.use_last_as_default = 0; 59 59 60 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way) );60 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way), false); 61 61 assertEquals("", combo.getSelectedItem().value); 62 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged) );62 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged), false); 63 63 assertEquals("", combo.getSelectedItem().value); 64 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT) );64 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT), false); 65 65 assertEquals("AT", combo.getSelectedItem().value); 66 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI) );66 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI), false); 67 67 assertEquals("SI", combo.getSelectedItem().value); 68 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI) );68 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI), false); 69 69 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 70 70 71 71 combo.default_ = "AT"; 72 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way) );72 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way), false); 73 73 assertEquals("AT", combo.getSelectedItem().value); 74 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged) );74 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged), false); 75 75 assertEquals("", combo.getSelectedItem().value); 76 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT) );76 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT), false); 77 77 assertEquals("AT", combo.getSelectedItem().value); 78 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI) );78 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI), false); 79 79 assertEquals("SI", combo.getSelectedItem().value); 80 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI) );80 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI), false); 81 81 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 82 82 83 83 Combo.PROP_FILL_DEFAULT.put(true); 84 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way) );84 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way), false); 85 85 assertEquals("AT", combo.getSelectedItem().value); 86 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged) );86 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged), false); 87 87 assertEquals("AT", combo.getSelectedItem().value); 88 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT) );88 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT), false); 89 89 assertEquals("AT", combo.getSelectedItem().value); 90 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI) );90 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI), false); 91 91 assertEquals("SI", combo.getSelectedItem().value); 92 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI) );92 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI), false); 93 93 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 94 94 Combo.PROP_FILL_DEFAULT.put(false); 95 95 combo.default_ = null; 96 96 97 97 combo.use_last_as_default = 1; // untagged objects only 98 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way) );98 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way), false); 99 99 assertEquals("AT", combo.getSelectedItem().value); 100 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged) );100 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged), false); 101 101 assertEquals("", combo.getSelectedItem().value); 102 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT) );102 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT), false); 103 103 assertEquals("AT", combo.getSelectedItem().value); 104 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI) );104 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI), false); 105 105 assertEquals("SI", combo.getSelectedItem().value); 106 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI) );106 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI), false); 107 107 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 108 108 109 109 combo.use_last_as_default = 2; // "force" on tagged objects too 110 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way) );110 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, way), false); 111 111 assertEquals("AT", combo.getSelectedItem().value); 112 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged) );112 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayTagged), false); 113 113 assertEquals("AT", combo.getSelectedItem().value); 114 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT) );114 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT), false); 115 115 assertEquals("AT", combo.getSelectedItem().value); 116 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI) );116 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, waySI), false); 117 117 assertEquals("SI", combo.getSelectedItem().value); 118 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI) );118 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false, wayAT, waySI), false); 119 119 assertEquals(Combo.DIFFERENT, combo.getSelectedItem().value); 120 120 combo.use_last_as_default = 0; 121 121 … … 129 129 combo.values = "red;green;blue;black"; 130 130 combo.values_context = "color"; 131 131 combo.delimiter = ';'; 132 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false) );132 combo.addToPanel(new JPanel(), TaggingPresetItemGuiSupport.create(false), false); 133 133 assertEquals(5, combo.combobox.getItemCount()); 134 134 combo.presetListEntries.stream().filter(e -> "red".equals(e.value)).findFirst().ifPresent(combo.combobox::setSelectedItem); 135 135 assertEquals("red", combo.getSelectedItem().value); -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/ItemSeparatorTest.java
32 32 void testAddToPanel() { 33 33 JPanel p = new JPanel(); 34 34 assertEquals(0, p.getComponentCount()); 35 assertFalse(new ItemSeparator().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));35 assertFalse(new ItemSeparator().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 36 36 assertTrue(p.getComponentCount() > 0); 37 37 } 38 38 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/KeyTest.java
31 31 void testAddToPanel() { 32 32 JPanel p = new JPanel(); 33 33 assertEquals(0, p.getComponentCount()); 34 assertFalse(new Key().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));34 assertFalse(new Key().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 35 35 assertEquals(0, p.getComponentCount()); 36 36 } 37 37 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LabelTest.java
31 31 void testAddToPanel() { 32 32 JPanel p = new JPanel(); 33 33 assertEquals(0, p.getComponentCount()); 34 assertTrue(new Label().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));34 assertTrue(new Label().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 35 35 assertTrue(p.getComponentCount() > 0); 36 36 } 37 37 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/LinkTest.java
34 34 Link l = new Link(); 35 35 JPanel p = new JPanel(); 36 36 assertEquals(0, p.getComponentCount()); 37 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));37 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 38 38 assertEquals(0, p.getComponentCount()); 39 39 40 40 l.href = Config.getUrls().getJOSMWebsite(); 41 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));41 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 42 42 assertTrue(p.getComponentCount() > 0); 43 43 44 44 l.locale_href = Config.getUrls().getJOSMWebsite(); 45 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));45 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 46 46 assertTrue(p.getComponentCount() > 0); 47 47 } 48 48 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelectTest.java
31 31 void testAddToPanel() { 32 32 JPanel p = new JPanel(); 33 33 assertEquals(0, p.getComponentCount()); 34 assertTrue(new MultiSelect().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));34 assertTrue(new MultiSelect().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 35 35 assertTrue(p.getComponentCount() > 0); 36 36 } 37 37 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/OptionalTest.java
32 32 void testAddToPanel() { 33 33 JPanel p = new JPanel(); 34 34 assertEquals(0, p.getComponentCount()); 35 assertFalse(new Optional().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));35 assertFalse(new Optional().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 36 36 assertTrue(p.getComponentCount() > 0); 37 37 } 38 38 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/PresetLinkTest.java
7 7 8 8 import javax.swing.JPanel; 9 9 10 import org.junit.jupiter.api.extension.RegisterExtension;11 10 import org.junit.jupiter.api.Test; 11 import org.junit.jupiter.api.extension.RegisterExtension; 12 12 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 13 13 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 14 … … 35 35 l.preset_name = "River"; 36 36 JPanel p = new JPanel(); 37 37 assertEquals(0, p.getComponentCount()); 38 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));38 assertFalse(l.addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 39 39 assertTrue(p.getComponentCount() > 0); 40 40 } 41 41 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/RolesTest.java
32 32 void testAddToPanel() { 33 33 JPanel p = new JPanel(); 34 34 assertEquals(0, p.getComponentCount()); 35 assertFalse(new Roles().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));35 assertFalse(new Roles().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 36 36 assertTrue(p.getComponentCount() > 0); 37 37 } 38 38 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/SpaceTest.java
32 32 void testAddToPanel() { 33 33 JPanel p = new JPanel(); 34 34 assertEquals(0, p.getComponentCount()); 35 assertFalse(new Space().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));35 assertFalse(new Space().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 36 36 assertTrue(p.getComponentCount() > 0); 37 37 } 38 38 } -
test/unit/org/openstreetmap/josm/gui/tagging/presets/items/TextTest.java
6 6 7 7 import javax.swing.JPanel; 8 8 9 import org.junit.jupiter.api.extension.RegisterExtension;10 9 import org.junit.jupiter.api.Test; 10 import org.junit.jupiter.api.extension.RegisterExtension; 11 11 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport; 12 12 import org.openstreetmap.josm.testutils.JOSMTestRules; 13 13 … … 32 32 void testAddToPanel() { 33 33 JPanel p = new JPanel(); 34 34 assertEquals(0, p.getComponentCount()); 35 assertTrue(new Text().addToPanel(p, TaggingPresetItemGuiSupport.create(false) ));35 assertTrue(new Text().addToPanel(p, TaggingPresetItemGuiSupport.create(false), false)); 36 36 assertTrue(p.getComponentCount() > 0); 37 37 } 38 38 }