From 3cf558f466cf01f3fb3a116f230c892821e8e2d1 Mon Sep 17 00:00:00 2001 From: harry Date: Thu, 10 Aug 2023 23:14:06 +0530 Subject: [PATCH 1/4] Add support for alternative tagging of the presets. --- resources/data/tagging-preset.xsd | 7 +++++ .../gui/tagging/presets/TaggingPreset.java | 6 +++- .../gui/tagging/presets/items/PresetLink.java | 28 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/resources/data/tagging-preset.xsd b/resources/data/tagging-preset.xsd index 097224b111f..4e006e4a519 100644 --- a/resources/data/tagging-preset.xsd +++ b/resources/data/tagging-preset.xsd @@ -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..01129187a66 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java @@ -420,6 +420,7 @@ public void applyComponentOrientation(ComponentOrientation o) { }; JPanel linkPanel = new JPanel(new GridBagLayout()); TaggingPresetItem previous = null; + boolean alternativeLabel = false; // true if an alternative label has been added for (TaggingPresetItem i : data) { if (i instanceof Link) { i.addToPanel(linkPanel, itemGuiSupport); @@ -427,7 +428,10 @@ 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))) { + if (!alternativeLabel && link.isAlternative()) { + itemPanel.add(link.createAlternativeLabel(), GBC.eol().insets(0, 8, 0, 0)); + alternativeLabel = true; + } else if (!(previous instanceof PresetLink && Objects.equals(((PresetLink) previous).text, link.text))) { itemPanel.add(link.createLabel(), GBC.eol().insets(0, 8, 0, 0)); } } 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..92b5ddaa4c5 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java @@ -44,6 +44,25 @@ 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 @@ -53,6 +72,15 @@ public JLabel createLabel() { return new JLabel(locale_text); } + /** + * Creates a label to be inserted above the alternative presets + * @return a label + */ + public JLabel createAlternativeLabel() { + initializeLocaleText(tr("Alternative Presets")); + return new JLabel(locale_text); + } + @Override public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) { final String presetName = preset_name; From c572c6ee78547877b635cec8f38d578cfa66773f Mon Sep 17 00:00:00 2001 From: harry Date: Wed, 16 Aug 2023 02:51:41 +0530 Subject: [PATCH 2/4] Fix orientation issue for alternative tags --- .../gui/tagging/presets/TaggingPreset.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java index 01129187a66..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,8 +418,8 @@ public void applyComponentOrientation(ComponentOrientation o) { } }; JPanel linkPanel = new JPanel(new GridBagLayout()); - TaggingPresetItem previous = null; - boolean alternativeLabel = false; // true if an alternative label has been added + 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); @@ -428,18 +427,34 @@ public void applyComponentOrientation(ComponentOrientation o) { } else { if (i instanceof PresetLink) { PresetLink link = (PresetLink) i; - if (!alternativeLabel && link.isAlternative()) { - itemPanel.add(link.createAlternativeLabel(), GBC.eol().insets(0, 8, 0, 0)); - alternativeLabel = true; - } else 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()); From 5c692a4e0e46f7b79b7afe634fbb988a8977c8c3 Mon Sep 17 00:00:00 2001 From: harry Date: Wed, 16 Aug 2023 15:14:51 +0530 Subject: [PATCH 3/4] Update label text --- .../josm/gui/tagging/presets/items/PresetLink.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 92b5ddaa4c5..2e2a0eb10aa 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java @@ -77,7 +77,7 @@ public JLabel createLabel() { * @return a label */ public JLabel createAlternativeLabel() { - initializeLocaleText(tr("Alternative Presets")); + initializeLocaleText(tr("Alternative Tags")); return new JLabel(locale_text); } From c6b2b934f725eaf7e606989ecc46c5675bb1dc32 Mon Sep 17 00:00:00 2001 From: harry Date: Mon, 28 Aug 2023 15:57:57 +0530 Subject: [PATCH 4/4] Add suitable label text --- resources/data/tagging-preset.xsd | 2 +- .../josm/gui/tagging/presets/items/PresetLink.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/data/tagging-preset.xsd b/resources/data/tagging-preset.xsd index 4e006e4a519..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. ]]> 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 2e2a0eb10aa..21ecefc9447 100644 --- a/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java +++ b/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java @@ -68,7 +68,7 @@ public void setAlternative(boolean alternative) { * @return a label */ public JLabel createLabel() { - initializeLocaleText(tr("Edit also …")); + initializeLocaleText(tr("Additional tags to edit")); return new JLabel(locale_text); } @@ -77,7 +77,7 @@ public JLabel createLabel() { * @return a label */ public JLabel createAlternativeLabel() { - initializeLocaleText(tr("Alternative Tags")); + initializeLocaleText(tr("Similar but different tags")); return new JLabel(locale_text); }