Changeset 8828 in josm for trunk/src/org


Ignore:
Timestamp:
2015-10-05T22:34:08+02:00 (4 years ago)
Author:
simon04
Message:

fix #10493 - Preset <check>: make default="on/off" work

File:
1 edited

Legend:

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

    r8811 r8828  
    886886        /** whether the off value is disabled in the dialog, i.e., only unset or yes are provided */
    887887        public boolean disable_off = false;
    888         /** ticked on/off (default is "off") */
    889         public boolean default_ = false; // only used for tagless objects
     888        /** "on" or "off" or unset (default is unset) */
     889        public String default_ = null; // only used for tagless objects
    890890
    891891        private QuadStateCheckBox check;
    892892        private QuadStateCheckBox.State initialState;
    893         private boolean def;
     893        private Boolean def;
    894894
    895895        @Override
     
    899899            final Usage usage = determineBooleanUsage(sel, key);
    900900            final String oneValue = usage.values.isEmpty() ? null : usage.values.last();
    901             def = default_;
     901            def = "on".equals(default_) ? Boolean.TRUE : "off".equals(default_) ? Boolean.FALSE : null;
    902902
    903903            if (locale_text == null) {
     
    906906
    907907            if (usage.values.size() < 2 && (oneValue == null || value_on.equals(oneValue) || value_off.equals(oneValue))) {
    908                 if (def && !PROP_FILL_DEFAULT.get()) {
     908                if (def != null && !PROP_FILL_DEFAULT.get()) {
    909909                    // default is set and filling default values feature is disabled - check if all primitives are untagged
    910910                    for (OsmPrimitive s : sel) {
    911911                        if (s.hasKeys()) {
    912                             def = false;
     912                            def = null;
    913913                        }
    914914                    }
     
    917917                // all selected objects share the same value which is either true or false or unset,
    918918                // we can display a standard check box.
    919                 initialState = value_on.equals(oneValue)
     919                initialState = value_on.equals(oneValue) || Boolean.TRUE.equals(def)
    920920                        ? QuadStateCheckBox.State.SELECTED
    921                         : value_off.equals(oneValue)
     921                        : value_off.equals(oneValue) || Boolean.FALSE.equals(def)
    922922                        ? QuadStateCheckBox.State.NOT_SELECTED
    923                         : def
    924                         ? QuadStateCheckBox.State.SELECTED
    925923                        : QuadStateCheckBox.State.UNSET;
     924
    926925            } else {
    927                 def = false;
     926                def = null;
    928927                // the objects have different values, or one or more objects have something
    929928                // else than true/false. we display a quad-state check box
     
    949948        public void addCommands(List<Tag> changedTags) {
    950949            // if the user hasn't changed anything, don't create a command.
    951             if (check.getState() == initialState && !def) return;
     950            if (check.getState() == initialState && def == null) return;
    952951
    953952            // otherwise change things according to the selected value.
Note: See TracChangeset for help on using the changeset viewer.