Changeset 17609 in josm for trunk/src


Ignore:
Timestamp:
2021-03-20T23:07:02+01:00 (4 years ago)
Author:
simon04
Message:

see #18949 - Extract class TaggingPresetItemGuiSupport

Location:
trunk/src/org/openstreetmap/josm/gui/tagging/presets
Files:
1 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r17606 r17609  
    329329
    330330        boolean presetInitiallyMatches = !selected.isEmpty() && selected.stream().allMatch(this);
     331        final TaggingPresetItemGuiSupport itemGuiSupport = TaggingPresetItemGuiSupport.create(presetInitiallyMatches, selected);
    331332        JPanel items = new JPanel(new GridBagLayout());
    332333        TaggingPresetItem previous = null;
     
    342343                    }
    343344                }
    344                 if (i.addToPanel(items, selected, presetInitiallyMatches)) {
     345                if (i.addToPanel(items, itemGuiSupport)) {
    345346                    p.hasElements = true;
    346347                }
     
    355356        // add Link
    356357        for (Link link : l) {
    357             link.addToPanel(p, selected, presetInitiallyMatches);
     358            link.addToPanel(p, itemGuiSupport);
    358359        }
    359360
     
    674675        return iconFuture;
    675676    }
     677
    676678}
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetItem.java

    r16690 r17609  
    5757     *
    5858     * @param p The panel where components must be added
    59      * @param sel The related selected OSM primitives
    60      * @param presetInitiallyMatches Whether this {@link TaggingPreset} already matched before applying,
    61      *                               i.e. whether the map feature already existed on the primitive.
     59     * @param support supporting class for creating the GUI
    6260     * @return {@code true} if this item adds semantic tagging elements, {@code false} otherwise.
    6361     */
    64     protected abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches);
     62    protected abstract boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support);
    6563
    6664    /**
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Check.java

    r17607 r17609  
    1616import org.openstreetmap.josm.data.osm.OsmUtils;
    1717import org.openstreetmap.josm.data.osm.Tag;
     18import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1819import org.openstreetmap.josm.gui.widgets.QuadStateCheckBox;
    1920import org.openstreetmap.josm.tools.GBC;
     
    3839
    3940    @Override
    40     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     41    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    4142
    4243        // find out if our key is already used in the selection.
    43         final Usage usage = determineBooleanUsage(sel, key);
     44        final Usage usage = determineBooleanUsage(support.getSelected(), key);
    4445        final String oneValue = usage.values.isEmpty() ? null : usage.values.last();
    4546        def = "on".equals(default_) ? Boolean.TRUE : "off".equals(default_) ? Boolean.FALSE : null;
     
    5051            if (def != null && !PROP_FILL_DEFAULT.get()) {
    5152                // default is set and filling default values feature is disabled - check if all primitives are untagged
    52                 for (OsmPrimitive s : sel) {
     53                for (OsmPrimitive s : support.getSelected()) {
    5354                    if (s.hasKeys()) {
    5455                        def = null;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/CheckGroup.java

    r16042 r17609  
    33
    44import java.awt.GridLayout;
    5 import java.util.Collection;
    65import java.util.LinkedList;
    76import java.util.List;
     
    109import javax.swing.JPanel;
    1110
    12 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1311import org.openstreetmap.josm.data.osm.Tag;
    1412import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     13import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1514import org.openstreetmap.josm.tools.GBC;
    1615
     
    3231
    3332    @Override
    34     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     33    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    3534        int rows = (int) Math.ceil(checks.size() / ((double) columns));
    3635        JPanel panel = new JPanel(new GridLayout(rows, columns));
    3736
    3837        for (Check check : checks) {
    39             check.addToPanel(panel, sel, presetInitiallyMatches);
     38            check.addToPanel(panel, support);
    4039        }
    4140
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java

    r17605 r17609  
    2828import javax.swing.ListCellRenderer;
    2929
    30 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3130import org.openstreetmap.josm.data.osm.Tag;
     31import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    3232import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSelector;
    3333import org.openstreetmap.josm.spi.preferences.Config;
     
    206206
    207207    @Override
    208     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     208    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    209209        initListEntries(true);
    210210
    211211        // find out if our key is already used in the selection.
    212         usage = determineTextUsage(sel, key);
     212        usage = determineTextUsage(support.getSelected(), key);
    213213        if (!usage.hasUniqueValue() && !usage.unused()) {
    214214            presetListEntries.add(new PresetListEntry(DIFFERENT));
     
    220220        label.setComponentPopupMenu(getPopupMenu());
    221221        p.add(label, GBC.std().insets(0, 0, 10, 0));
    222         addToPanelAnchor(p, default_, presetInitiallyMatches);
     222        addToPanelAnchor(p, default_, support.isPresetInitiallyMatches());
    223223        label.setLabelFor(component);
    224224        component.setToolTipText(getKeyTooltipText());
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ItemSeparator.java

    r9665 r17609  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import java.util.Collection;
    54import java.util.List;
    65
     
    87import javax.swing.JSeparator;
    98
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    119import org.openstreetmap.josm.data.osm.Tag;
    1210import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1312import org.openstreetmap.josm.tools.GBC;
    1413
     
    2019
    2120    @Override
    22     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     21    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    2322        p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0, 5, 0, 5));
    2423        return false;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Key.java

    r9665 r17609  
    88import javax.swing.JPanel;
    99
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1110import org.openstreetmap.josm.data.osm.Tag;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1212
    1313/**
     
    2020
    2121    @Override
    22     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     22    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    2323        return false;
    2424    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Label.java

    r17605 r17609  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    3 
    4 import java.util.Collection;
    53
    64import javax.swing.JLabel;
    75import javax.swing.JPanel;
    86
    9 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     7import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    108import org.openstreetmap.josm.tools.GBC;
    119
     
    1614
    1715    @Override
    18     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     16    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    1917        initializeLocaleText(null);
    2018        JLabel label = new JLabel(locale_text);
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Link.java

    r17605 r17609  
    66import java.awt.event.MouseEvent;
    77import java.util.Arrays;
    8 import java.util.Collection;
    98import java.util.Optional;
    109
     
    1211import javax.swing.SwingUtilities;
    1312
    14 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1513import org.openstreetmap.josm.gui.dialogs.properties.HelpAction;
     14import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1615import org.openstreetmap.josm.gui.widgets.UrlLabel;
    1716import org.openstreetmap.josm.spi.preferences.Config;
     
    3534
    3635    @Override
    37     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     36    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    3837        initializeLocaleText(tr("More information about this feature"));
    3938        Optional.ofNullable(buildUrlLabel()).ifPresent(label -> p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL)));
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Optional.java

    r9665 r17609  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.util.Collection;
    7 
    86import javax.swing.JLabel;
    97import javax.swing.JPanel;
    108
    11 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     9import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1210import org.openstreetmap.josm.tools.GBC;
    1311
     
    2018    // TODO: Draw a box around optional stuff
    2119    @Override
    22     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     20    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    2321        initializeLocaleText(tr("Optional Attributes:"));
    2422        p.add(new JLabel(" "), GBC.eol()); // space
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/PresetLink.java

    r16699 r17609  
    1616import org.openstreetmap.josm.data.osm.Tag;
    1717import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
     18import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1819import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetLabel;
    1920import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
     
    5455
    5556    @Override
    56     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     57    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    5758        final String presetName = preset_name;
    5859        Optional<TaggingPreset> found = TaggingPresets.getTaggingPresets().stream().filter(preset -> presetName.equals(preset.name)).findFirst();
     
    6061            TaggingPreset t = found.get();
    6162            JLabel lbl = new TaggingPresetLabel(t);
    62             lbl.addMouseListener(new TaggingPresetMouseAdapter(t, sel));
     63            lbl.addMouseListener(new TaggingPresetMouseAdapter(t, support.getSelected()));
    6364            p.add(lbl, GBC.eol().fill(GBC.HORIZONTAL));
    6465        }
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Roles.java

    r17333 r17609  
    66import java.awt.GridBagLayout;
    77import java.util.ArrayList;
    8 import java.util.Collection;
    98import java.util.List;
    109import java.util.Set;
     
    1312import javax.swing.JPanel;
    1413
    15 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1614import org.openstreetmap.josm.data.osm.Tag;
    1715import org.openstreetmap.josm.data.osm.search.SearchCompiler;
     
    1917import org.openstreetmap.josm.data.osm.search.SearchSetting;
    2018import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     19import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    2120import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
    2221import org.openstreetmap.josm.tools.GBC;
     
    191190
    192191    @Override
    193     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     192    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    194193        p.add(new JLabel(" "), GBC.eol()); // space
    195194        if (!roles.isEmpty()) {
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Space.java

    r9665 r17609  
    22package org.openstreetmap.josm.gui.tagging.presets.items;
    33
    4 import java.util.Collection;
    54import java.util.List;
    65
     
    87import javax.swing.JPanel;
    98
    10 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    119import org.openstreetmap.josm.data.osm.Tag;
    1210import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
     11import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1312import org.openstreetmap.josm.tools.GBC;
    1413
     
    1918
    2019    @Override
    21     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     20    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    2221        p.add(new JLabel(" "), GBC.eol()); // space
    2322        return false;
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Text.java

    r17605 r17609  
    2222import javax.swing.JToggleButton;
    2323
    24 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2524import org.openstreetmap.josm.data.osm.Tag;
    2625import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    2726import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
     27import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    2828import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    2929import org.openstreetmap.josm.gui.widgets.JosmTextField;
     
    6161
    6262    @Override
    63     public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
     63    public boolean addToPanel(JPanel p, TaggingPresetItemGuiSupport support) {
    6464
    6565        // find out if our key is already used in the selection.
    66         Usage usage = determineTextUsage(sel, key);
     66        Usage usage = determineTextUsage(support.getSelected(), key);
    6767        AutoCompletingTextField textField = new AutoCompletingTextField();
    6868        if (alternative_autocomplete_keys != null) {
     
    8888            } else if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {
    8989                // selected osm primitives are untagged or filling default values feature is enabled
    90                 if (!presetInitiallyMatches && !"false".equals(use_last_as_default) && LAST_VALUES.containsKey(key)) {
     90                if (!support.isPresetInitiallyMatches() && !"false".equals(use_last_as_default) && LAST_VALUES.containsKey(key)) {
    9191                    textField.setText(LAST_VALUES.get(key));
    9292                } else {
Note: See TracChangeset for help on using the changeset viewer.