Ticket #7552: 7552_gamma.patch
| File 7552_gamma.patch, 18.8 KB (added by , 14 years 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 38 38 values: comma separated list of values 39 39 display_values: comma separated list of values to be displayed instead of the 40 40 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=""/> 48 46 default: default string to display 49 47 delete_if_empty: true/false 50 48 use_last_as_default: true/false/force … … multiselect: list of values from which zero or more can be selected 54 52 text: fixed label to display 55 53 delimiter: character that separates values (default: semicolon) - this 56 54 will also be used to separate selected values in the tag. 57 values: delimiter-separated list of values (delimiter can be escaped with backslash)58 55 rows: specify the number of rows to display (default -1) 56 values: delimiter-separated list of values (delimiter can be escaped with backslash) 59 57 display_values: delimiter-separated list of values to be displayed instead of the 60 58 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=""/> 68 64 default: default string to display 69 65 delete_if_empty: true/false 70 66 use_last_as_default: true/false/force … … are supplied, then "values" will be treated as "display_values" and translated i 690 686 <key key="highway" value="path" /> 691 687 <optional> 692 688 <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" /> 700 696 </combo> 701 697 <combo key="mtb:scale" text="MTB Scale" values="0,1,2,3,4,5" default="" delete_if_empty="true" /> 702 698 <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 125 125 <anyAttribute processContents="skip" /> 126 126 </complexType> 127 127 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 128 135 <complexType name="combo"> 129 136 <sequence> 130 <element name="short_description" type="string" minOccurs="0" 131 maxOccurs="unbounded" /> 137 <element name="list_entry" type="tns:list_entry" /> 132 138 </sequence> 133 139 <attribute name="key" type="string" use="required" /> 134 140 <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; 7 7 8 8 import java.awt.Component; 9 9 import java.awt.Dimension; 10 import java.awt.Font; 10 11 import java.awt.GridBagLayout; 11 12 import java.awt.Image; 12 13 import java.awt.Insets; … … import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 71 72 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; 72 73 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 73 74 import org.openstreetmap.josm.gui.util.GuiHelper; 74 import org.openstreetmap.josm.gui.widgets.HtmlPanel;75 75 import org.openstreetmap.josm.io.MirroredInputStream; 76 76 import org.openstreetmap.josm.tools.GBC; 77 77 import org.openstreetmap.josm.tools.ImageProvider; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 193 193 return returnValue; 194 194 } 195 195 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; 200 201 201 202 public String getListDisplay() { 202 203 if (value.equals(DIFFERENT)) … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 214 215 res.append("</b>"); 215 216 if (short_description != null) { 216 217 // 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>"); 218 219 } 219 220 return res.toString(); 220 221 } 221 222 223 public ImageIcon getIcon() { 224 return icon == null ? null : ImageProvider.getIfAvailable(icon); 225 } 226 227 public PresetListEntry() { 228 } 229 222 230 public PresetListEntry(String value) { 223 231 this.value = value; 224 232 this.display_value = value; … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 234 242 public String toString() { 235 243 if (value.equals(DIFFERENT)) 236 244 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> 238 246 } 239 247 } 240 248 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 430 438 public String use_last_as_default = "false"; 431 439 public boolean required = false; 432 440 433 protected List<String> short_description_list;434 441 protected JComponent component; 435 protected Map<String, PresetListEntry> lhm ;442 protected Map<String, PresetListEntry> lhm = new LinkedHashMap<String, PresetListEntry>(); 436 443 protected Usage usage; 437 444 protected Object originalValue; 438 445 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 444 451 445 452 // find out if our key is already used in the selection. 446 453 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 } 448 495 496 private String[] initListEntriesFromAttributes() { 449 497 char delChar = ';'; 450 498 if (!delimiter.isEmpty()) { 451 499 delChar = delimiter.charAt(0); … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 467 515 short_descriptions_array = splitEscaped(delChar, locale_short_descriptions); 468 516 } else if (short_descriptions != null) { 469 517 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);476 518 } 477 519 478 520 if (display_array.length != value_array.length) { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 485 527 short_descriptions_array = null; 486 528 } 487 529 488 lhm = new LinkedHashMap<String, PresetListEntry>();489 530 if (!usage.hasUniqueValue() && !usage.unused()) { 490 531 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 491 532 } … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 501 542 lhm.put(value_array[i], e); 502 543 } 503 544 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; 517 546 } 518 547 519 548 protected String getDisplayIfNull(String display) { … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 560 589 changedTags.add(new Tag(key, value)); 561 590 } 562 591 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); 566 599 } 567 short_description_list.add(tr(s));568 600 } 569 601 570 602 @Override … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 575 607 protected ListCellRenderer getListCellRenderer() { 576 608 return new ListCellRenderer() { 577 609 578 HtmlPanel lbl = new HtmlPanel();610 JLabel lbl = new JLabel(); 579 611 JComponent dummy = new JComponent() { 580 612 }; 581 613 … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 594 626 } 595 627 596 628 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()); 599 633 lbl.setEnabled(list.isEnabled()); 600 634 // We do not want the editor to have the maximum height of all 601 635 // entries. Return a dummy with bogus height. … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 1140 1174 parser.map("label", Label.class); 1141 1175 parser.map("space", Space.class); 1142 1176 parser.map("key", Key.class); 1177 parser.map("list_entry", PresetListEntry.class); 1143 1178 LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 1144 1179 TaggingPresetMenu lastmenu = null; 1145 1180 Roles lastrole = null; 1181 List<PresetListEntry> listEntries = new LinkedList<PresetListEntry>(); 1146 1182 1147 1183 if (validate) { 1148 1184 parser.startWithValidation(in, "http://josm.openstreetmap.de/tagging-preset-1.0", "resource://data/tagging-preset.xsd"); … … public class TaggingPreset extends AbstractAction implements MapView.LayerChange 1176 1212 all.add(tp); 1177 1213 lastrole = null; 1178 1214 } 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); 1182 1218 lastrole = (Roles) o; 1183 } 1184 else if(o instanceof Role) { 1185 if(lastrole == null) 1219 } else if (o instanceof Role) { 1220 if (lastrole == null) { 1186 1221 throw new SAXException(tr("Preset role element without parent")); 1222 } 1187 1223 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>(); 1191 1232 lastrole = null; 1192 1233 } 1193 1234 } else
