Ticket #7552: 7552_gamma.patch

File 7552_gamma.patch, 18.8 KB (added by simon04, 14 months ago)
  • data/defaultpresets.xml

    diff --git a/data/defaultpresets.xml b/data/defaultpresets.xml
    index d8a5172..ff22e70 100755
    a b combo: combo box, with multiple choices and possible to enter free form text 
    3838  values: comma separated list of values 
    3939  display_values: comma separated list of values to be displayed instead of the 
    4040                  database values, order and number must be equal to values 
    41   short_description: comma separated list of texts to be displayed below each 
    42                     display_value. (Only if it is not possible to describe  
    43                     the entry in 2-3 words.) Instead of comma separeted list, you can 
    44                     also write it in the following form:  
    45                         <short_description>first description</short_description> 
    46                                 ... 
    47                         <short_description>last description</short_description> 
     41  short_descriptions: comma separated list of texts to be displayed below each 
     42                      display_value. (Only if it is not possible to describe 
     43                      the entry in 2-3 words.) Instead of comma separeted list 
     44  instead using values, display_values and short_descriptions, the following form is also supported: 
     45    <list_item value="" display_value="' short_description="" icon=""/> 
    4846  default: default string to display 
    4947  delete_if_empty: true/false 
    5048  use_last_as_default: true/false/force 
    multiselect: list of values from which zero or more can be selected 
    5452  text: fixed label to display 
    5553  delimiter: character that separates values (default: semicolon) - this 
    5654             will also be used to separate selected values in the tag. 
    57   values: delimiter-separated list of values (delimiter can be escaped with backslash) 
    5855  rows: specify the number of rows to display (default -1) 
     56  values: delimiter-separated list of values (delimiter can be escaped with backslash) 
    5957  display_values: delimiter-separated list of values to be displayed instead of the 
    6058                  database values, order and number must be equal to values 
    61   short_description: delimiter-separated list of texts to be displayed below each 
    62                     display_value. (Only if it is not possible to describe  
    63                     the entry in 2-3 words.) Instead of a separated list, you can 
    64                     also write it in the following form:  
    65                         <short_description>first description</short_description> 
    66                                 ... 
    67                         <short_description>last description</short_description> 
     59  short_descriptions: delimiter-separated list of texts to be displayed below each 
     60                     display_value. (Only if it is not possible to describe 
     61                     the entry in 2-3 words.) Instead of a separated list 
     62  instead using values, display_values and short_descriptions, the following form is also supported: 
     63    <list_item value="" display_value="' short_description="" icon=""/> 
    6864  default: default string to display 
    6965  delete_if_empty: true/false 
    7066  use_last_as_default: true/false/force 
    are supplied, then "values" will be treated as "display_values" and translated i 
    690686            <key key="highway" value="path" /> 
    691687            <optional> 
    692688                <text key="name" text="Name" default="" delete_if_empty="true" /> 
    693                 <combo key="sac_scale" text="SAC Scale" values="hiking,mountain_hiking,demanding_mountain_hiking,alpine_hiking,demanding_alpine_hiking,difficult_alpine_hiking" default="" delete_if_empty="true" display_values="T1 - hiking trail,T2 - mountain hiking trail,T3 - difficult\, exposed hiking trail,T4 - difficult\, exposed\, steep alpine trail,T5 - difficult alpine trail with climbing,T6 - hazardous alpine trail with climbing"> 
    694                     <short_description>Trail well cleared. Area flat or slightly sloped, no fall hazard</short_description> 
    695                     <short_description>Trail with continuous line and balanced ascent. Terrain partially steep, fall hazard possible</short_description> 
    696                     <short_description>exposed sites may be secured with ropes or chains, possible need to use hands for balance. Partly exposed sites with fall hazard, scree, pathless jagged rocks</short_description> 
    697                     <short_description>sometimes need for hand use to get ahead. Terrain quite exposed, precarious grassy acclivities, jagged rocks, facile snow-free glaciers.</short_description> 
    698                     <short_description>single plainly climbing up to second grade. Exposed, demanding terrain, jagged rocks, few dangerous glacier and snow</short_description> 
    699                     <short_description>climbing up to second grade. Often very exposed, precarious jagged rocks, glacier with danger to slip and fall</short_description> 
     689                <combo key="sac_scale" text="SAC Scale"> 
     690                    <list_entry value="hiking" display_value="T1 - hiking trail" short_description="Trail well cleared. Area flat or slightly sloped, no fall hazard" /> 
     691                    <list_entry value="mountain_hiking" display_value="T2 - mountain hiking trail" short_description="Trail with continuous line and balanced ascent. Terrain partially steep, fall hazard possible" /> 
     692                    <list_entry value="demanding_mountain_hiking" display_value="T3 - difficult, exposed hiking trail" short_description="exposed sites may be secured with ropes or chains, possible need to use hands for balance. Partly exposed sites with fall hazard, scree, pathless jagged rocks" /> 
     693                    <list_entry value="alpine_hiking" display_value="T4 - difficult, exposed, steep alpine trail" short_description="sometimes need for hand use to get ahead. Terrain quite exposed, precarious grassy acclivities, jagged rocks, facile snow-free glaciers" /> 
     694                    <list_entry value="demanding_alpine_hiking" display_value="T5 - difficult alpine trail with climbing" short_description="single plainly climbing up to second grade. Exposed, demanding terrain, jagged rocks, few dangerous glacier and snow" /> 
     695                    <list_entry value="difficult_alpine_hiking" display_value="T6 - hazardous alpine trail with climbing" short_description="climbing up to second grade. Often very exposed, precarious jagged rocks, glacier with danger to slip and fall" /> 
    700696                </combo> 
    701697                <combo key="mtb:scale" text="MTB Scale" values="0,1,2,3,4,5" default="" delete_if_empty="true" /> 
    702698                <combo key="surface" text="Surface" values="paved,unpaved,asphalt,concrete,metal,wood,paving_stones,cobblestone,gravel,pebblestone,compacted,grass_paver,grass,sand,ground" default="" delete_if_empty="true" /> 
  • data/tagging-preset.xsd

    diff --git a/data/tagging-preset.xsd b/data/tagging-preset.xsd
    index 64a0d4e..f4d17b8 100644
    a b  
    125125                <anyAttribute processContents="skip" /> 
    126126        </complexType> 
    127127 
     128        <complexType name="list_entry"> 
     129                <attribute name="value" type="string" use="required" /> 
     130                <attribute name="display_value" type="string" /> 
     131                <attribute name="short_description" type="string" /> 
     132                <attribute name="icon" type="string" /> 
     133        </complexType> 
     134 
    128135        <complexType name="combo"> 
    129136                <sequence> 
    130                         <element name="short_description" type="string" minOccurs="0" 
    131                                 maxOccurs="unbounded" /> 
     137                        <element name="list_entry" type="tns:list_entry" /> 
    132138                </sequence> 
    133139                <attribute name="key" type="string" use="required" /> 
    134140                <attribute name="text" type="string" /> 
  • src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    diff --git a/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java b/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
    index 86749ee..7d5a8c6 100644
    a b import static org.openstreetmap.josm.tools.I18n.trn; 
    77 
    88import java.awt.Component; 
    99import java.awt.Dimension; 
     10import java.awt.Font; 
    1011import java.awt.GridBagLayout; 
    1112import java.awt.Image; 
    1213import java.awt.Insets; 
    import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 
    7172import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; 
    7273import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 
    7374import org.openstreetmap.josm.gui.util.GuiHelper; 
    74 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 
    7575import org.openstreetmap.josm.io.MirroredInputStream; 
    7676import org.openstreetmap.josm.tools.GBC; 
    7777import org.openstreetmap.josm.tools.ImageProvider; 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    193193        return returnValue; 
    194194    } 
    195195 
    196     protected static class PresetListEntry { 
    197         String value; 
    198         String display_value; 
    199         String short_description; 
     196    public static class PresetListEntry { 
     197        public String value; 
     198        public String display_value; 
     199        public String short_description; 
     200        public String icon; 
    200201 
    201202        public String getListDisplay() { 
    202203            if (value.equals(DIFFERENT)) 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    214215            res.append("</b>"); 
    215216            if (short_description != null) { 
    216217                // wrap in table to restrict the text width 
    217                 res.append("<br><table><td width='232'>(").append(short_description).append(")</td></table>"); 
     218                res.append("<div style=\"width:300px; padding:0 0 5px 5px\">").append(short_description).append("</div>"); 
    218219            } 
    219220            return res.toString(); 
    220221        } 
    221222 
     223        public ImageIcon getIcon() { 
     224            return icon == null ? null : ImageProvider.getIfAvailable(icon); 
     225        } 
     226 
     227        public PresetListEntry() { 
     228        } 
     229 
    222230        public PresetListEntry(String value) { 
    223231            this.value = value; 
    224232            this.display_value = value; 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    234242        public String toString() { 
    235243            if (value.equals(DIFFERENT)) 
    236244                return DIFFERENT; 
    237             return display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br> 
     245            return display_value == null ? value : display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br> 
    238246        } 
    239247    } 
    240248 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    430438        public String use_last_as_default = "false"; 
    431439        public boolean required = false; 
    432440 
    433         protected List<String> short_description_list; 
    434441        protected JComponent component; 
    435         protected Map<String, PresetListEntry> lhm; 
     442        protected Map<String, PresetListEntry> lhm = new LinkedHashMap<String, PresetListEntry>(); 
    436443        protected Usage usage; 
    437444        protected Object originalValue; 
    438445 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    444451 
    445452            // find out if our key is already used in the selection. 
    446453            usage = determineTextUsage(sel, key); 
    447             String def = default_; 
     454            String[] display_array; 
     455 
     456            if (lhm.isEmpty()) { 
     457                display_array = initListEntriesFromAttributes(); 
     458            } else { 
     459                if (values != null) { 
     460                    System.err.println(tr("Warning in tagging preset \"{0}-{1}\": " 
     461                            + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.", 
     462                            key, text, "values", "list_entry")); 
     463                } 
     464                if (display_values != null || locale_display_values != null) { 
     465                    System.err.println(tr("Warning in tagging preset \"{0}-{1}\": " 
     466                            + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.", 
     467                            key, text, "display_values", "list_entry")); 
     468                } 
     469                if (short_descriptions != null || locale_short_descriptions != null) { 
     470                    System.err.println(tr("Warning in tagging preset \"{0}-{1}\": " 
     471                            + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.", 
     472                            key, text, "short_descriptions", "list_entry")); 
     473                } 
     474                display_array = new String[lhm.values().size()]; 
     475                int i = 0; 
     476                for (PresetListEntry e : lhm.values()) { 
     477                    display_array[i++] = e.display_value; 
     478                } 
     479            } 
     480 
     481            if (locale_text == null) { 
     482                if (text_context != null) { 
     483                    locale_text = trc(text_context, fixPresetString(text)); 
     484                } else { 
     485                    locale_text = tr(fixPresetString(text)); 
     486                } 
     487            } 
     488            p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 
     489 
     490            addToPanelAnchor(p, default_, display_array); 
     491 
     492            return true; 
     493 
     494        } 
    448495 
     496        private String[] initListEntriesFromAttributes() { 
    449497            char delChar = ';'; 
    450498            if (!delimiter.isEmpty()) { 
    451499                delChar = delimiter.charAt(0); 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    467515                short_descriptions_array = splitEscaped(delChar, locale_short_descriptions); 
    468516            } else if (short_descriptions != null) { 
    469517                short_descriptions_array = splitEscaped(delChar, short_descriptions); 
    470             } else if (short_description_list != null) { 
    471                 short_descriptions_array = short_description_list.toArray(new String[0]); 
    472             } 
    473  
    474             if (!"false".equals(use_last_as_default) && def == null && lastValue.containsKey(key)) { 
    475                 def = lastValue.get(key); 
    476518            } 
    477519 
    478520            if (display_array.length != value_array.length) { 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    485527                short_descriptions_array = null; 
    486528            } 
    487529 
    488             lhm = new LinkedHashMap<String, PresetListEntry>(); 
    489530            if (!usage.hasUniqueValue() && !usage.unused()) { 
    490531                lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 
    491532            } 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    501542                        lhm.put(value_array[i], e); 
    502543            } 
    503544 
    504             if (locale_text == null) { 
    505                 if (text_context != null) { 
    506                     locale_text = trc(text_context, fixPresetString(text)); 
    507                 } else { 
    508                     locale_text = tr(fixPresetString(text)); 
    509                 } 
    510             } 
    511             p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 
    512  
    513             addToPanelAnchor(p, def, display_array); 
    514  
    515             return true; 
    516  
     545            return display_array; 
    517546        } 
    518547 
    519548        protected String getDisplayIfNull(String display) { 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    560589            changedTags.add(new Tag(key, value)); 
    561590        } 
    562591 
    563         public void setShort_description(String s) { 
    564             if (short_description_list == null) { 
    565                 short_description_list = new ArrayList<String>(); 
     592        public void addListEntry(PresetListEntry e) { 
     593            lhm.put(e.value, e); 
     594        } 
     595 
     596        public void addListEntries(Collection<PresetListEntry> e) { 
     597            for (PresetListEntry i : e) { 
     598                addListEntry(i); 
    566599            } 
    567             short_description_list.add(tr(s)); 
    568600        } 
    569601 
    570602        @Override 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    575607        protected ListCellRenderer getListCellRenderer() { 
    576608            return new ListCellRenderer() { 
    577609 
    578                 HtmlPanel lbl = new HtmlPanel(); 
     610                JLabel lbl = new JLabel(); 
    579611                JComponent dummy = new JComponent() { 
    580612                }; 
    581613 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    594626                    } 
    595627 
    596628                    PresetListEntry item = (PresetListEntry) value; 
    597                     String s = item.getListDisplay(); 
    598                     lbl.setText(s); 
     629                    lbl.setOpaque(true); 
     630                    lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN)); 
     631                    lbl.setText("<html>" + item.getListDisplay() + "</html>"); 
     632                    lbl.setIcon(item.getIcon()); 
    599633                    lbl.setEnabled(list.isEnabled()); 
    600634                    // We do not want the editor to have the maximum height of all 
    601635                    // entries. Return a dummy with bogus height. 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    11401174        parser.map("label", Label.class); 
    11411175        parser.map("space", Space.class); 
    11421176        parser.map("key", Key.class); 
     1177        parser.map("list_entry", PresetListEntry.class); 
    11431178        LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 
    11441179        TaggingPresetMenu lastmenu = null; 
    11451180        Roles lastrole = null; 
     1181        List<PresetListEntry> listEntries = new LinkedList<PresetListEntry>(); 
    11461182 
    11471183        if (validate) { 
    11481184            parser.startWithValidation(in, "http://josm.openstreetmap.de/tagging-preset-1.0", "resource://data/tagging-preset.xsd"); 
    public class TaggingPreset extends AbstractAction implements MapView.LayerChange 
    11761212                all.add(tp); 
    11771213                lastrole = null; 
    11781214            } else { 
    1179                 if(all.size() != 0) { 
    1180                     if(o instanceof Roles) { 
    1181                         all.getLast().data.add((Item)o); 
     1215                if (all.size() != 0) { 
     1216                    if (o instanceof Roles) { 
     1217                        all.getLast().data.add((Item) o); 
    11821218                        lastrole = (Roles) o; 
    1183                     } 
    1184                     else if(o instanceof Role) { 
    1185                         if(lastrole == null) 
     1219                    } else if (o instanceof Role) { 
     1220                        if (lastrole == null) { 
    11861221                            throw new SAXException(tr("Preset role element without parent")); 
     1222                        } 
    11871223                        lastrole.roles.add((Role) o); 
    1188                     } 
    1189                     else { 
    1190                         all.getLast().data.add((Item)o); 
     1224                    } else if (o instanceof PresetListEntry) { 
     1225                        listEntries.add((PresetListEntry) o); 
     1226                    } else { 
     1227                        all.getLast().data.add((Item) o); 
     1228                        if (o instanceof ComboMultiSelect) { 
     1229                            ((ComboMultiSelect) o).addListEntries(listEntries); 
     1230                        } 
     1231                        listEntries = new LinkedList<PresetListEntry>(); 
    11911232                        lastrole = null; 
    11921233                    } 
    11931234                } else