Changeset 7171 in josm for trunk/src


Ignore:
Timestamp:
2014-05-23T08:02:13+02:00 (11 years ago)
Author:
simon04
Message:

fix #9682 #10048 - Presets: disable no value for some checkboxes in the preset dialog

This avoid that unneeded keys are created/suggested by JOSM, such as building=no

File:
1 edited

Legend:

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

    r7128 r7171  
    799799        public String value_on = OsmUtils.trueval;
    800800        public String value_off = OsmUtils.falseval;
     801        public boolean disable_off = false;
    801802        public boolean default_ = false; // only used for tagless objects
    802803
     
    808809
    809810            // find out if our key is already used in the selection.
    810             Usage usage = determineBooleanUsage(sel, key);
     811            final Usage usage = determineBooleanUsage(sel, key);
     812            final String oneValue = usage.values.isEmpty() ? null : usage.values.last();
    811813            def = default_;
    812814
     
    819821            }
    820822
    821             String oneValue = null;
    822             for (String s : usage.values) {
    823                 oneValue = s;
    824             }
    825823            if (usage.values.size() < 2 && (oneValue == null || value_on.equals(oneValue) || value_off.equals(oneValue))) {
    826824                if (def && !PROP_FILL_DEFAULT.get()) {
     
    834832                // all selected objects share the same value which is either true or false or unset,
    835833                // we can display a standard check box.
    836                 initialState = value_on.equals(oneValue) ?
    837                         QuadStateCheckBox.State.SELECTED :
    838                             value_off.equals(oneValue) ?
    839                                     QuadStateCheckBox.State.NOT_SELECTED :
    840                                         def ? QuadStateCheckBox.State.SELECTED
    841                                                 : QuadStateCheckBox.State.UNSET;
    842                 check = new QuadStateCheckBox(locale_text, initialState,
    843                         new QuadStateCheckBox.State[] {
    844                         QuadStateCheckBox.State.SELECTED,
    845                         QuadStateCheckBox.State.NOT_SELECTED,
    846                         QuadStateCheckBox.State.UNSET });
     834                initialState = value_on.equals(oneValue)
     835                        ? QuadStateCheckBox.State.SELECTED
     836                        : value_off.equals(oneValue)
     837                        ? QuadStateCheckBox.State.NOT_SELECTED
     838                        : def
     839                        ? QuadStateCheckBox.State.SELECTED
     840                        : QuadStateCheckBox.State.UNSET;
    847841            } else {
    848842                def = false;
     
    851845                // in "partial" state.
    852846                initialState = QuadStateCheckBox.State.PARTIAL;
    853                 check = new QuadStateCheckBox(locale_text, QuadStateCheckBox.State.PARTIAL,
    854                         new QuadStateCheckBox.State[] {
    855                         QuadStateCheckBox.State.PARTIAL,
    856                         QuadStateCheckBox.State.SELECTED,
    857                         QuadStateCheckBox.State.NOT_SELECTED,
    858                         QuadStateCheckBox.State.UNSET });
    859             }
     847            }
     848
     849            final List<QuadStateCheckBox.State> allowedStates = new ArrayList<>(4);
     850            if (QuadStateCheckBox.State.PARTIAL.equals(initialState))
     851                allowedStates.add(QuadStateCheckBox.State.PARTIAL);
     852            allowedStates.add(QuadStateCheckBox.State.SELECTED);
     853            if (!disable_off || value_off.equals(oneValue))
     854                allowedStates.add(QuadStateCheckBox.State.NOT_SELECTED);
     855            allowedStates.add(QuadStateCheckBox.State.UNSET);
     856            check = new QuadStateCheckBox(locale_text, initialState,
     857                    allowedStates.toArray(new QuadStateCheckBox.State[allowedStates.size()]));
     858
    860859            p.add(check, GBC.eol().fill(GBC.HORIZONTAL));
    861860            return true;
     
    881880        @Override
    882881        public Collection<String> getValues() {
    883             return Arrays.asList(value_on, value_off);
     882            return disable_off ? Arrays.asList(value_on) : Arrays.asList(value_on, value_off);
    884883        }
    885884
Note: See TracChangeset for help on using the changeset viewer.