Changeset 6114 in josm


Ignore:
Timestamp:
2013-08-06T23:48:20+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8735 - Presets: add new checkgroup item to specify group of checkboxes on multiple columns

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/data/defaultpresets.xml

    r6044 r6114  
    8989  match: none/key/key!/keyvalue (default is "none", see below for more information)
    9090
     91checkgroup: group of checks
     92  columns: number of columns
     93
    9194check: checkbox
    9295  key: key to set
     
    24272430                <combo key="shop" text="With shop" values="yes,convenience,kiosk,no" />
    24282431                <label text="Fuel types:" />
    2429                 <check key="fuel:diesel" text="Diesel" default="off" />
    2430                 <check key="fuel:biodiesel" text="Bio Diesel" default="off" />
    2431                 <check key="fuel:GTL_diesel" text="Diesel (Gas To Liquid - ultimate diesel)" default="off" />
    2432                 <check key="fuel:HGV_diesel" text="Diesel for Heavy Good Vehicles" default="off" />
    2433                 <check key="fuel:octane_80" text="Octane 80" default="off" />
    2434                 <check key="fuel:octane_91" text="Octane 91" default="off" />
    2435                 <check key="fuel:octane_92" text="Octane 92" default="off" />
    2436                 <check key="fuel:octane_95" text="Octane 95" default="off" />
    2437                 <check key="fuel:octane_98" text="Octane 98" default="off" />
    2438                 <check key="fuel:octane_100" text="Octane 100" default="off" />
    2439                 <check key="fuel:e10" text="E10 (10% Ethanol mix)" default="off" />
    2440                 <check key="fuel:e85" text="E85 (85% Ethanol mix)" default="off" />
    2441                 <check key="fuel:lpg" text="LPG (Liquefied petroleum gas)" default="off" />
    2442                 <check key="fuel:cng" text="CNG (Compressed Natural Gas)" default="off" />
    2443                 <check key="fuel:1_25" text="1/25 mix (mofa/moped)" default="off" />
    2444                 <check key="fuel:1_50" text="1/50 mix (mofa/moped)" default="off" />
     2432                <checkgroup columns="2">
     2433                    <check key="fuel:diesel" text="Diesel" default="off" />
     2434                    <check key="fuel:biodiesel" text="Bio Diesel" default="off" />
     2435                    <check key="fuel:GTL_diesel" text="Diesel (Gas To Liquid - ultimate diesel)" default="off" />
     2436                    <check key="fuel:HGV_diesel" text="Diesel for Heavy Good Vehicles" default="off" />
     2437                    <check key="fuel:octane_80" text="Octane 80" default="off" />
     2438                    <check key="fuel:octane_91" text="Octane 91" default="off" />
     2439                    <check key="fuel:octane_92" text="Octane 92" default="off" />
     2440                    <check key="fuel:octane_95" text="Octane 95" default="off" />
     2441                    <check key="fuel:octane_98" text="Octane 98" default="off" />
     2442                    <check key="fuel:octane_100" text="Octane 100" default="off" />
     2443                    <check key="fuel:e10" text="E10 (10% Ethanol mix)" default="off" />
     2444                    <check key="fuel:e85" text="E85 (85% Ethanol mix)" default="off" />
     2445                    <check key="fuel:lpg" text="LPG (Liquefied petroleum gas)" default="off" />
     2446                    <check key="fuel:cng" text="CNG (Compressed Natural Gas)" default="off" />
     2447                    <check key="fuel:1_25" text="1/25 mix (mofa/moped)" default="off" />
     2448                    <check key="fuel:1_50" text="1/50 mix (mofa/moped)" default="off" />
     2449                </checkgroup>
    24452450            </optional>
    24462451        </item>
  • trunk/data/tagging-preset.xsd

    r6057 r6114  
    8181                        <element name="combo" type="tns:combo" />
    8282                        <element name="multiselect" type="tns:multiselect" />
     83            <element name="checkgroup" type="tns:checkgroup" />
    8384                        <element name="check" type="tns:check" />
    8485                </choice>
     
    189190        </complexType>
    190191
     192    <complexType name="checkgroup">
     193        <sequence>
     194            <choice minOccurs="1" maxOccurs="unbounded">
     195                <element name="check" type="tns:check" />
     196            </choice>
     197        </sequence>
     198        <attribute name="columns" type="positiveInteger" />
     199        <anyAttribute processContents="skip" />
     200    </complexType>
     201
    191202        <complexType name="check">
    192203                <attribute name="key" type="string" use="required" />
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java

    r6093 r6114  
    66import java.awt.Font;
    77import java.awt.GridBagLayout;
     8import java.awt.GridLayout;
    89import java.awt.event.ActionEvent;
    910import java.awt.event.ActionListener;
     
    2425import java.util.Map;
    2526import java.util.TreeSet;
     27
    2628import javax.swing.ButtonGroup;
    2729import javax.swing.ImageIcon;
     
    3537import javax.swing.ListCellRenderer;
    3638import javax.swing.ListModel;
     39
    3740import org.xml.sax.SAXException;
    38 
    3941import org.openstreetmap.josm.Main;
    4042import org.openstreetmap.josm.actions.search.SearchCompiler;
     
    315317        public void addCommands(List<Tag> changedTags) {
    316318        }
     319
     320        @Override
     321        public String toString() {
     322            return "Label ["
     323                    + (text != null ? "text=" + text + ", " : "")
     324                    + (text_context != null ? "text_context=" + text_context
     325                            + ", " : "")
     326                    + (locale_text != null ? "locale_text=" + locale_text : "")
     327                    + "]";
     328        }
    317329    }
    318330
     
    391403        public void addCommands(List<Tag> changedTags) {
    392404        }
     405
     406        @Override
     407        public String toString() {
     408            return "Optional";
     409        }
    393410    }
    394411
     
    403420        @Override
    404421        public void addCommands(List<Tag> changedTags) {
     422        }
     423
     424        @Override
     425        public String toString() {
     426            return "Space";
    405427        }
    406428    }
     
    643665                return Collections.emptyList();
    644666            return Collections.singleton(default_);
     667        }
     668    }
     669
     670    /**
     671     * A group of {@link Check}s.
     672     * @since 6114
     673     */
     674    public static class CheckGroup extends TaggingPresetItem {
     675       
     676        /**
     677         * Number of columns (positive integer)
     678         */
     679        public String columns;
     680       
     681        /**
     682         * List of checkboxes
     683         */
     684        public final List<Check> checks = new LinkedList<Check>();
     685
     686        @Override
     687        boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) {
     688            Integer cols = new Integer(columns);
     689            int rows = (int) Math.ceil((double)checks.size()/cols.doubleValue());
     690            JPanel panel = new JPanel(new GridLayout(rows, cols));
     691           
     692            for (Check check : checks) {
     693                check.addToPanel(panel, sel);
     694            }
     695           
     696            p.add(panel, GBC.eol());
     697            return false;
     698        }
     699
     700        @Override
     701        void addCommands(List<Tag> changedTags) {
     702        }
     703
     704        @Override
     705        public String toString() {
     706            return "CheckGroup [columns=" + columns + "]";
    645707        }
    646708    }
     
    734796        public Collection<String> getValues() {
    735797            return Arrays.asList(value_on, value_off);
     798        }
     799
     800        @Override
     801        public String toString() {
     802            return "Check ["
     803                    + (locale_text != null ? "locale_text=" + locale_text + ", " : "")
     804                    + (value_on != null ? "value_on=" + value_on + ", " : "")
     805                    + (value_off != null ? "value_off=" + value_off + ", " : "")
     806                    + "default_=" + default_ + ", "
     807                    + (check != null ? "check=" + check + ", " : "")
     808                    + (initialState != null ? "initialState=" + initialState
     809                            + ", " : "") + "def=" + def + "]";
    736810        }
    737811    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java

    r6093 r6114  
    1212import java.util.LinkedList;
    1313import java.util.List;
     14
    1415import javax.swing.JOptionPane;
     16
    1517import org.xml.sax.SAXException;
    16 
    1718import org.openstreetmap.josm.Main;
    1819import org.openstreetmap.josm.gui.preferences.SourceEntry;
     
    5859        parser.mapOnStart("roles", TaggingPresetItems.Roles.class);
    5960        parser.map("role", TaggingPresetItems.Role.class);
     61        parser.map("checkgroup", TaggingPresetItems.CheckGroup.class);
    6062        parser.map("check", TaggingPresetItems.Check.class);
    6163        parser.map("combo", TaggingPresetItems.Combo.class);
     
    6971        TaggingPresetMenu lastmenu = null;
    7072        TaggingPresetItems.Roles lastrole = null;
     73        final List<TaggingPresetItems.Check> checks = new LinkedList<TaggingPresetItems.Check>();
    7174        List<TaggingPresetItems.PresetListEntry> listEntries = new LinkedList<TaggingPresetItems.PresetListEntry>();
    7275
     
    113116                            throw new SAXException(tr("Preset role element without parent"));
    114117                        lastrole.roles.add((TaggingPresetItems.Role) o);
     118                    } else if (o instanceof TaggingPresetItems.Check) {
     119                        checks.add((TaggingPresetItems.Check) o);
    115120                    } else if (o instanceof TaggingPresetItems.PresetListEntry) {
    116121                        listEntries.add((TaggingPresetItems.PresetListEntry) o);
     122                    } else if (o instanceof TaggingPresetItems.CheckGroup) {
     123                        all.getLast().data.add((TaggingPresetItem) o);
     124                        ((TaggingPresetItems.CheckGroup) o).checks.addAll(checks);
     125                        checks.clear();
    117126                    } else {
     127                        if (!checks.isEmpty()) {
     128                            all.getLast().data.addAll(checks);
     129                            checks.clear();
     130                        }
    118131                        all.getLast().data.add((TaggingPresetItem) o);
    119132                        if (o instanceof TaggingPresetItems.ComboMultiSelect) {
Note: See TracChangeset for help on using the changeset viewer.