Changeset 17639 in josm for trunk/src/org


Ignore:
Timestamp:
2021-03-22T23:25:18+01:00 (4 years ago)
Author:
simon04
Message:

see #18949 - Tagging presets: trigger value_template="..." from <combo> and <multiselect> changes

Location:
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items
Files:
3 edited

Legend:

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

    r17077 r17639  
    1919import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
    2020import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
     21import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    2122import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    2223import org.openstreetmap.josm.spi.preferences.Config;
     
    4748
    4849    @Override
    49     protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
     50    protected void addToPanelAnchor(JPanel p, String def, TaggingPresetItemGuiSupport support) {
    5051        if (!usage.unused()) {
    5152            for (String s : usage.values) {
     
    7778        }
    7879        combobox.setEditor(tf);
    79         combobox.setSelectedItem(getItemToSelect(def, presetInitiallyMatches, false));
     80        combobox.setSelectedItem(getItemToSelect(def, support, false));
    8081
    8182        if (key != null && ("colour".equals(key) || key.startsWith("colour:") || key.endsWith(":colour"))) {
     
    9293            p.add(combobox, GBC.eol().fill(GBC.HORIZONTAL));
    9394        }
     95        combobox.addActionListener(l -> support.fireItemValueModified(this, key, getSelectedValue()));
    9496    }
    9597
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java

    r17609 r17639  
    188188    protected abstract Object getSelectedItem();
    189189
    190     protected abstract void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches);
     190    protected abstract void addToPanelAnchor(JPanel p, String def, TaggingPresetItemGuiSupport support);
    191191
    192192    @Override
     
    220220        label.setComponentPopupMenu(getPopupMenu());
    221221        p.add(label, GBC.std().insets(0, 0, 10, 0));
    222         addToPanelAnchor(p, default_, support.isPresetInitiallyMatches());
     222        addToPanelAnchor(p, default_, support);
    223223        label.setLabelFor(component);
    224224        component.setToolTipText(getKeyTooltipText());
     
    343343    }
    344344
    345     protected Object getItemToSelect(String def, boolean presetInitiallyMatches, boolean multi) {
     345    protected Object getItemToSelect(String def, TaggingPresetItemGuiSupport support, boolean multi) {
    346346        final Object itemToSelect;
    347347        if (usage.hasUniqueValue()) {
     
    367367            // all items were unset (and so is default)
    368368            originalValue = multi ? null : getListEntry("");
    369             if (LAST_VALUES.containsKey(key) && isUseLastAsDefault() && (!presetInitiallyMatches || isForceUseLastAsDefault())) {
     369            if (LAST_VALUES.containsKey(key) && isUseLastAsDefault() && (!support.isPresetInitiallyMatches() || isForceUseLastAsDefault())) {
    370370                itemToSelect = getListEntry(LAST_VALUES.get(key));
    371371            } else {
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelect.java

    r17077 r17639  
    1515
    1616import org.openstreetmap.josm.data.osm.Tag;
     17import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItemGuiSupport;
    1718import org.openstreetmap.josm.tools.GBC;
    1819
     
    3031
    3132    @Override
    32     protected void addToPanelAnchor(JPanel p, String def, boolean presetInitiallyMatches) {
     33    protected void addToPanelAnchor(JPanel p, String def, TaggingPresetItemGuiSupport support) {
    3334        list = new ConcatenatingJList(delimiter, presetListEntries.toArray(new PresetListEntry[0]));
    3435        component = list;
    3536        ListCellRenderer<PresetListEntry> renderer = getListCellRenderer();
    3637        list.setCellRenderer(renderer);
    37         list.setSelectedItem(getItemToSelect(def, presetInitiallyMatches, true));
     38        list.setSelectedItem(getItemToSelect(def, support, true));
    3839        JScrollPane sp = new JScrollPane(list);
    3940        // if a number of rows has been specified in the preset,
     
    4445            sp.setPreferredSize(new Dimension((int) sp.getPreferredSize().getWidth(), (int) height));
    4546        }
     47        list.addListSelectionListener(l -> support.fireItemValueModified(this, key, getSelectedValue()));
    4648        p.add(sp, GBC.eol().fill(GBC.HORIZONTAL));
    4749    }
Note: See TracChangeset for help on using the changeset viewer.