Changeset 16688 in josm


Ignore:
Timestamp:
2020-06-21T09:54:48+02:00 (3 weeks ago)
Author:
simon04
Message:

see #16031 - Extract ComboMultiSelect.getItemToSelect

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

    r16687 r16688  
    7777        }
    7878        combobox.setEditor(tf);
     79        combobox.setSelectedItem(getItemToSelect(def, presetInitiallyMatches));
    7980
    80         if (usage.hasUniqueValue()) {
    81             // all items have the same value (and there were no unset items)
    82             originalValue = getListEntry(usage.getFirst());
    83             combobox.setSelectedItem(originalValue);
    84         } else if (def != null && usage.unused()) {
    85             // default is set and all items were unset
    86             if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || isForceUseLastAsDefault()) {
    87                 // selected osm primitives are untagged or filling default feature is enabled
    88                 combobox.setSelectedItem(getListEntry(def).getDisplayValue());
    89             } else {
    90                 // selected osm primitives are tagged and filling default feature is disabled
    91                 combobox.setSelectedItem("");
    92             }
    93             originalValue = getListEntry(DIFFERENT);
    94         } else if (usage.unused()) {
    95             // all items were unset (and so is default)
    96             originalValue = getListEntry("");
    97             if (!presetInitiallyMatches && isUseLastAsDefault() && LAST_VALUES.containsKey(key)) {
    98                 combobox.setSelectedItem(getListEntry(LAST_VALUES.get(key)));
    99             } else {
    100                 combobox.setSelectedItem(originalValue);
    101             }
    102         } else {
    103             originalValue = getListEntry(DIFFERENT);
    104             combobox.setSelectedItem(originalValue);
    105         }
    10681        if (key != null && ("colour".equals(key) || key.startsWith("colour:") || key.endsWith(":colour"))) {
    10782            p.add(combobox, GBC.std().fill(GBC.HORIZONTAL));
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/ComboMultiSelect.java

    r16643 r16688  
    517517    }
    518518
     519    protected Object getItemToSelect(String def, boolean presetInitiallyMatches) {
     520        final Object itemToSelect;
     521        if (usage.hasUniqueValue()) {
     522            // all items have the same value (and there were no unset items)
     523            originalValue = getListEntry(usage.getFirst());
     524            itemToSelect = originalValue;
     525        } else if (def != null && usage.unused()) {
     526            // default is set and all items were unset
     527            if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || isForceUseLastAsDefault()) {
     528                // selected osm primitives are untagged or filling default feature is enabled
     529                itemToSelect = getListEntry(def).getDisplayValue();
     530            } else {
     531                // selected osm primitives are tagged and filling default feature is disabled
     532                itemToSelect = "";
     533            }
     534            originalValue = getListEntry(DIFFERENT);
     535        } else if (usage.unused()) {
     536            // all items were unset (and so is default)
     537            originalValue = getListEntry("");
     538            if (!presetInitiallyMatches && isUseLastAsDefault() && LAST_VALUES.containsKey(key)) {
     539                itemToSelect = getListEntry(LAST_VALUES.get(key));
     540            } else {
     541                itemToSelect = originalValue;
     542            }
     543        } else {
     544            originalValue = getListEntry(DIFFERENT);
     545            itemToSelect = originalValue;
     546        }
     547        return itemToSelect;
     548    }
     549
    519550    protected String getSelectedValue() {
    520551        Object obj = getSelectedItem();
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/MultiSelect.java

    r16687 r16688  
    3030        ListCellRenderer<PresetListEntry> renderer = getListCellRenderer();
    3131        list.setCellRenderer(renderer);
    32 
    33         if (usage.hasUniqueValue() && !usage.unused()) {
    34             originalValue = usage.getFirst();
    35             list.setSelectedItem(originalValue);
    36         } else if ((def != null && !usage.hadKeys()) || PROP_FILL_DEFAULT.get() || isForceUseLastAsDefault()) {
    37             originalValue = DIFFERENT;
    38             list.setSelectedItem(def);
    39         } else if (usage.unused()) {
    40             originalValue = null;
    41             if (!presetInitiallyMatches && isUseLastAsDefault() && LAST_VALUES.containsKey(key)) {
    42                 list.setSelectedItem(getListEntry(LAST_VALUES.get(key)));
    43             } else {
    44                 list.setSelectedItem(originalValue);
    45             }
    46         } else {
    47             originalValue = DIFFERENT;
    48             list.setSelectedItem(originalValue);
    49         }
     32        list.setSelectedItem(getItemToSelect(def, presetInitiallyMatches));
    5033
    5134        JScrollPane sp = new JScrollPane(list);
Note: See TracChangeset for help on using the changeset viewer.