diff --git a/resources/data/tagging-preset.xsd b/resources/data/tagging-preset.xsd index 097224b111f..ae3414d4de0 100644 --- a/resources/data/tagging-preset.xsd +++ b/resources/data/tagging-preset.xsd @@ -288,7 +288,7 @@ without text or a identical text value are grouped below one label. Watch out for presets with identical name as it is not predictable to which preset the link will lead to, see #12716. + Adds a link to an other preset with a label on top. The preset_name attribute is required. alternative, text to override the label (default is "Edit also …") and text_context are optional. A sequence of without text or a identical text value are grouped below one label. Watch out for presets with identical name as it is not predictable to which preset the link will lead to, see #12716. ]]> @@ -298,6 +298,13 @@ + + + + Indicates that the preset link points to an alternative tagging of the object. + + + diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java index d154158093d..e25c6f34691 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java @@ -18,7 +18,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.function.Predicate; @@ -419,7 +418,8 @@ public void applyComponentOrientation(ComponentOrientation o) { } }; JPanel linkPanel = new JPanel(new GridBagLayout()); - TaggingPresetItem previous = null; + List alternativeTags = new ArrayList<>(); //list to store PresetLinks with alternative="true" + List editAlsoTags = new ArrayList<>(); //list to store other presetLinks for (TaggingPresetItem i : data) { if (i instanceof Link) { i.addToPanel(linkPanel, itemGuiSupport); @@ -427,15 +427,34 @@ public void applyComponentOrientation(ComponentOrientation o) { } else { if (i instanceof PresetLink) { PresetLink link = (PresetLink) i; - if (!(previous instanceof PresetLink && Objects.equals(((PresetLink) previous).text, link.text))) { - itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0)); + if (link.isAlternative()) { + alternativeTags.add(link); + } else { + editAlsoTags.add(link); } } - if (i.addToPanel(itemPanel, itemGuiSupport)) { + if (!(i instanceof PresetLink) && (i.addToPanel(itemPanel, itemGuiSupport))) { p.hasElements = true; } } - previous = i; + } + + if (!alternativeTags.isEmpty()) { + PresetLink link = new PresetLink(); + itemPanel.add(link.createAlternativeLabel(), GBC.eol().insets(0, 8, 0, 0)); + for (PresetLink links : alternativeTags) { + links.addToPanel(itemPanel, itemGuiSupport); + p.hasElements = true; + } + } + + if (!editAlsoTags.isEmpty()) { + PresetLink link = new PresetLink(); + itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0)); + for (PresetLink links : editAlsoTags) { + links.addToPanel(itemPanel, itemGuiSupport); + p.hasElements = true; + } } p.add(itemPanel, GBC.eol().fill()); p.add(linkPanel, GBC.eol().fill()); diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java b/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java index 77c1e3648f5..21ecefc9447 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java @@ -44,12 +44,40 @@ public void mouseClicked(MouseEvent e) { /** The exact name of the preset to link to. Required. */ public String preset_name = ""; // NOSONAR + /** + * true if the PresetLink points to the alternative tagging of the preset. + */ + private boolean alternative; + + /** + * Gets the alternative for the preset + */ + public boolean isAlternative() { + return alternative; + } + + /** + * Sets the alternative for the preset. + */ + public void setAlternative(boolean alternative) { + this.alternative = alternative; + } + /** * Creates a label to be inserted above this link * @return a label */ public JLabel createLabel() { - initializeLocaleText(tr("Edit also …")); + initializeLocaleText(tr("Additional tags to edit")); + return new JLabel(locale_text); + } + + /** + * Creates a label to be inserted above the alternative presets + * @return a label + */ + public JLabel createAlternativeLabel() { + initializeLocaleText(tr("Similar but different tags")); return new JLabel(locale_text); }