Ticket #9682: 9682.patch

File 9682.patch, 11.1 KB (added by simon04, 7 years ago)
  • data/defaultpresets.xml

    diff --git a/data/defaultpresets.xml b/data/defaultpresets.xml
    index 57d4539..6376227 100644
    a b check: checkbox 
    117117  default: ticked on/off (default is "off")
    118118  value_on: the value to set when checked (default is "yes")
    119119  value_off: the value to set when unchecked (default is "no")
     120  disable_off: whether the off value is disabled in the dialog, i.e., only unset or yes are provided
    120121  match: none/key/key!/keyvalue (default is "none", see below for more information)
    121122
    122123role: type to specify possible roles in relations
    Note that for a match, at least one positive and no negative is required. 
    171172        <reference ref="surface" />
    172173    </chunk>
    173174    <chunk id="highway_yesno_incline">
    174         <check key="bridge" text="Bridge" />
    175         <check key="tunnel" text="Tunnel" />
    176         <check key="cutting" text="Cutting" />
    177         <check key="embankment" text="Embankment" />
     175        <check key="bridge" text="Bridge" disable_off="true" />
     176        <check key="tunnel" text="Tunnel" disable_off="true" />
     177        <check key="cutting" text="Cutting" disable_off="true" />
     178        <check key="embankment" text="Embankment" disable_off="true" />
    178179        <combo key="incline" text="Incline" values="10%,-10%,10°,-10°,up,down"/>
    179180    </chunk>
    180181    <chunk id="highway_yesno_incline_oneway">
    Note that for a match, at least one positive and no negative is required. 
    379380                <reference ref="highway_base" />
    380381                <checkgroup columns="4">
    381382                    <check key="oneway" text="Oneway" default="on" />
    382                     <check key="bridge" text="Bridge" />
    383                     <check key="tunnel" text="Tunnel" />
    384                     <check key="cutting" text="Cutting" />
    385                     <check key="embankment" text="Embankment" />
     383                    <check key="bridge" text="Bridge" disable_off="true" />
     384                    <check key="tunnel" text="Tunnel" disable_off="true" />
     385                    <check key="cutting" text="Cutting" disable_off="true" />
     386                    <check key="embankment" text="Embankment" disable_off="true" />
    386387                    <check key="lit" text="Lit" />
    387388                    <check key="toll" text="Toll" />
    388389                </checkgroup>
    Note that for a match, at least one positive and no negative is required. 
    403404                <reference ref="highway_base" />
    404405                <checkgroup columns="4">
    405406                    <check key="oneway" text="Oneway" default="on" />
    406                     <check key="bridge" text="Bridge" />
    407                     <check key="tunnel" text="Tunnel" />
    408                     <check key="cutting" text="Cutting" />
    409                     <check key="embankment" text="Embankment" />
     407                    <check key="bridge" text="Bridge" disable_off="true" />
     408                    <check key="tunnel" text="Tunnel" disable_off="true" />
     409                    <check key="cutting" text="Cutting" disable_off="true" />
     410                    <check key="embankment" text="Embankment" disable_off="true" />
    410411                    <check key="lit" text="Lit" />
    411412                    <check key="toll" text="Toll" />
    412413                </checkgroup>
    Note that for a match, at least one positive and no negative is required. 
    431432                <checkgroup columns="4">
    432433                    <check key="oneway" text="Oneway" default="on" />
    433434                    <check key="motorroad" text="Motorroad" default="on" />
    434                     <check key="bridge" text="Bridge" />
    435                     <check key="tunnel" text="Tunnel" />
    436                     <check key="cutting" text="Cutting" />
    437                     <check key="embankment" text="Embankment" />
     435                    <check key="bridge" text="Bridge" disable_off="true" />
     436                    <check key="tunnel" text="Tunnel" disable_off="true" />
     437                    <check key="cutting" text="Cutting" disable_off="true" />
     438                    <check key="embankment" text="Embankment" disable_off="true" />
    438439                    <check key="lit" text="Lit" />
    439440                    <check key="toll" text="Toll" />
    440441                </checkgroup>
    Note that for a match, at least one positive and no negative is required. 
    455456                <reference ref="highway_base" />
    456457                <checkgroup columns="4">
    457458                    <check key="oneway" text="Oneway" default="on" />
    458                     <check key="motorroad" text="Motorroad" default="on" />
    459                     <check key="bridge" text="Bridge" />
    460                     <check key="tunnel" text="Tunnel" />
    461                     <check key="cutting" text="Cutting" />
    462                     <check key="embankment" text="Embankment" />
     459                    <check key="bridge" text="Bridge" disable_off="true" />
     460                    <check key="tunnel" text="Tunnel" disable_off="true" />
     461                    <check key="cutting" text="Cutting" disable_off="true" />
     462                    <check key="embankment" text="Embankment" disable_off="true" />
    463463                    <check key="lit" text="Lit" />
    464464                    <check key="toll" text="Toll" />
    465465                </checkgroup>
    Note that for a match, at least one positive and no negative is required. 
    26292629            <space />
    26302630            <key key="public_transport" value="station" />
    26312631            <text key="name" text="Name" />
    2632             <check key="area" text="Area" />
    2633             <check key="building" text="Building" />
     2632            <check key="area" text="Area" disable_off="true" />
     2633            <check key="building" text="Building" disable_off="true" />
    26342634            <text key="operator" text="Operator" />
    26352635            <text key="network" text="Network" />
    26362636        </item>
  • data/tagging-preset.xsd

    diff --git a/data/tagging-preset.xsd b/data/tagging-preset.xsd
    index 2ab4de5..df890d4 100644
    a b  
    246246                <attribute name="default" type="tns:check_default" />
    247247                <attribute name="value_on" type="string" />
    248248                <attribute name="value_off" type="string" />
     249        <attribute name="disable_off" type="boolean" />
    249250                <attribute name="match" type="tns:match" />
    250251
    251252                <attribute name="name" use="prohibited" />
  • src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    diff --git a/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java b/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
    index d08f784..9a2c6af 100644
    a b public final class TaggingPresetItems { 
    798798        public String locale_text;
    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
    803804        private QuadStateCheckBox check;
    public final class TaggingPresetItems { 
    807808        @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) {
    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
    813815            if(locale_text == null) {
    public final class TaggingPresetItems { 
    818820                }
    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()) {
    827825                    // default is set and filling default values feature is disabled - check if all primitives are untagged
    public final class TaggingPresetItems { 
    833831
    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;
    849843                // the objects have different values, or one or more objects have something
    850844                // else than true/false. we display a quad-state check box
    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 });
    859847            }
     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;
    862861        }
    public final class TaggingPresetItems { 
    880879
    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
    886885        @Override