Changeset 7171 in josm


Ignore:
Timestamp:
2014-05-23T08:02:13+02:00 (5 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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r7118 r7171  
    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
     
    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>
     
    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" />
     
    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" />
     
    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" />
     
    457458                    <check key="oneway" text="Oneway" default="on" />
    458459                    <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" />
     460                    <check key="bridge" text="Bridge" disable_off="true" />
     461                    <check key="tunnel" text="Tunnel" disable_off="true" />
     462                    <check key="cutting" text="Cutting" disable_off="true" />
     463                    <check key="embankment" text="Embankment" disable_off="true" />
    463464                    <check key="lit" text="Lit" />
    464465                    <check key="toll" text="Toll" />
     
    26302631            <key key="public_transport" value="station" />
    26312632            <text key="name" text="Name" />
    2632             <check key="area" text="Area" />
    2633             <check key="building" text="Building" />
     2633            <check key="area" text="Area" disable_off="true" />
     2634            <check key="building" text="Building" disable_off="true" />
    26342635            <text key="operator" text="Operator" />
    26352636            <text key="network" text="Network" />
  • trunk/data/tagging-preset.xsd

    r7118 r7171  
    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
  • 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.