Changeset 5158 in josm
- Timestamp:
- 2012-04-01T20:36:32+02:00 (12 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/data/defaultpresets.xml
r5156 r5158 40 40 display_values: comma separated list of values to be displayed instead of the 41 41 database values, order and number must be equal to values 42 short_description: comma separated list of texts to be displayed below each 43 display_value. (Only if it is not possible to describe 44 the entry in 2-3 words.) Instead of comma separeted list, you can 45 also write it in the following form: 46 <short_description>first description</short_description> 47 ... 48 <short_description>last description</short_description> 42 short_descriptions: comma separated list of texts to be displayed below each 43 display_value. (Only if it is not possible to describe 44 the entry in 2-3 words.) Instead of comma separeted list 45 instead using values, display_values and short_descriptions, the following form is also supported: 46 <list_item value="" display_value="' short_description="" icon=""/> 49 47 default: default string to display (defaults to "") 50 48 use_last_as_default: true/false/force (default is "false") … … 60 58 display_values: delimiter-separated list of values to be displayed instead of the 61 59 database values, order and number must be equal to values 62 short_description: delimiter-separated list of texts to be displayed below each 63 display_value. (Only if it is not possible to describe 64 the entry in 2-3 words.) Instead of a separated list, you can 65 also write it in the following form: 66 <short_description>first description</short_description> 67 ... 68 <short_description>last description</short_description> 60 short_descriptions: delimiter-separated list of texts to be displayed below each 61 display_value. (Only if it is not possible to describe 62 the entry in 2-3 words.) Instead of a separated list 63 instead using values, display_values and short_descriptions, the following form is also supported: 64 <list_item value="" display_value="' short_description="" icon=""/> 69 65 default: default string to display (defaults to "") 70 66 use_last_as_default: true/false/force (default is "false") … … 700 696 <optional> 701 697 <text key="name" text="Name" /> 702 <combo key="sac_scale" text="SAC Scale" values="hiking,mountain_hiking,demanding_mountain_hiking,alpine_hiking,demanding_alpine_hiking,difficult_alpine_hiking" 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">703 < short_description>Trail well cleared. Area flat or slightly sloped, no fall hazard</short_description>704 < short_description>Trail with continuous line and balanced ascent. Terrain partially steep, fall hazard possible</short_description>705 < 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>706 < short_description>sometimes need for hand use to get ahead. Terrain quite exposed, precarious grassy acclivities, jagged rocks, facile snow-free glaciers.</short_description>707 < short_description>single plainly climbing up to second grade. Exposed, demanding terrain, jagged rocks, few dangerous glacier and snow</short_description>708 < short_description>climbing up to second grade. Often very exposed, precarious jagged rocks, glacier with danger to slip and fall</short_description>698 <combo key="sac_scale" text="SAC Scale"> 699 <list_entry value="hiking" display_value="T1 - hiking trail" short_description="Trail well cleared. Area flat or slightly sloped, no fall hazard" /> 700 <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" /> 701 <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" /> 702 <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" /> 703 <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" /> 704 <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" /> 709 705 </combo> 710 706 <combo key="mtb:scale" text="MTB Scale" values="0,1,2,3,4,5" /> -
trunk/data/tagging-preset.xsd
r5157 r5158 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 < sequence>130 <element name="short_description" type="string" minOccurs="0"131 132 </sequence> 133 <attribute name="key" type="string" use="required" /> 134 <attribute name="text" type="string" /> 135 <attribute name="text_context" type="string" /> 136 <attribute name="values" type="string" use="required"/>136 <!-- use either list_entry's or a combination of values/display_values --> 137 <sequence> 138 <element name="list_entry" type="tns:list_entry" minOccurs="0" maxOccurs="unbounded" /> 139 </sequence> 140 <attribute name="key" type="string" use="required" /> 141 <attribute name="text" type="string" /> 142 <attribute name="text_context" type="string" /> 143 <attribute name="values" type="string" /> 137 144 <attribute name="values_context" type="string" /> 138 145 <attribute name="display_values" type="string" /> -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r5155 r5158 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; … … 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; … … 263 263 } 264 264 265 protected static class PresetListEntry { 266 String value; 267 String display_value; 268 String short_description; 265 public static class PresetListEntry { 266 public String value; 267 public String display_value; 268 public String short_description; 269 public String icon; 269 270 270 271 public String getListDisplay() { … … 284 285 if (short_description != null) { 285 286 // wrap in table to restrict the text width 286 res.append("< br><table><td width='232'>(").append(short_description).append(")</td></table>");287 res.append("<div style=\"width:300px; padding:0 0 5px 5px\">").append(short_description).append("</div>"); 287 288 } 288 289 return res.toString(); 290 } 291 292 public ImageIcon getIcon() { 293 return icon == null ? null : ImageProvider.getIfAvailable(icon); 294 } 295 296 public PresetListEntry() { 289 297 } 290 298 … … 304 312 if (value.equals(DIFFERENT)) 305 313 return DIFFERENT; 306 return display_value .replaceAll("<.*>", ""); // remove additional markup, e.g. <br>314 return display_value == null ? value : display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br> 307 315 } 308 316 } … … 525 533 public String match = MatchType.NONE.getValue(); 526 534 527 protected List<String> short_description_list;528 535 protected JComponent component; 529 protected Map<String, PresetListEntry> lhm ;536 protected Map<String, PresetListEntry> lhm = new LinkedHashMap<String, PresetListEntry>(); 530 537 protected Usage usage; 531 538 protected Object originalValue; … … 543 550 // find out if our key is already used in the selection. 544 551 usage = determineTextUsage(sel, key); 545 String def = default_; 552 553 String[] display_array; 554 if (lhm.isEmpty()) { 555 display_array = initListEntriesFromAttributes(); 556 } else { 557 if (values != null) { 558 System.err.println(tr("Warning in tagging preset \"{0}-{1}\": " 559 + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.", 560 key, text, "values", "list_entry")); 561 } 562 if (display_values != null || locale_display_values != null) { 563 System.err.println(tr("Warning in tagging preset \"{0}-{1}\": " 564 + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.", 565 key, text, "display_values", "list_entry")); 566 } 567 if (short_descriptions != null || locale_short_descriptions != null) { 568 System.err.println(tr("Warning in tagging preset \"{0}-{1}\": " 569 + "Ignoring ''{2}'' attribute as ''{3}'' elements are given.", 570 key, text, "short_descriptions", "list_entry")); 571 } 572 display_array = new String[lhm.values().size()]; 573 int i = 0; 574 for (PresetListEntry e : lhm.values()) { 575 display_array[i++] = e.display_value; 576 } 577 } 578 579 if (locale_text == null) { 580 if (text_context != null) { 581 locale_text = trc(text_context, fixPresetString(text)); 582 } else { 583 locale_text = tr(fixPresetString(text)); 584 } 585 } 586 p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 587 588 addToPanelAnchor(p, default_, display_array); 589 590 return true; 591 592 } 593 594 private String[] initListEntriesFromAttributes() { 546 595 547 596 char delChar = getDelChar(); … … 563 612 } else if (short_descriptions != null) { 564 613 short_descriptions_array = splitEscaped(delChar, short_descriptions); 565 } else if (short_description_list != null) {566 short_descriptions_array = short_description_list.toArray(new String[0]);567 }568 569 if (!"false".equals(use_last_as_default) && def == null && lastValue.containsKey(key)) {570 def = lastValue.get(key);571 614 } 572 615 … … 581 624 } 582 625 583 lhm = new LinkedHashMap<String, PresetListEntry>();584 626 if (!usage.hasUniqueValue() && !usage.unused()) { 585 627 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); … … 597 639 } 598 640 599 if (locale_text == null) { 600 if (text_context != null) { 601 locale_text = trc(text_context, fixPresetString(text)); 602 } else { 603 locale_text = tr(fixPresetString(text)); 604 } 605 } 606 p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 607 608 addToPanelAnchor(p, def, display_array); 609 610 return true; 611 641 return display_array; 612 642 } 613 643 … … 653 683 } 654 684 655 public void setShort_description(String s) { 656 if (short_description_list == null) { 657 short_description_list = new ArrayList<String>(); 658 } 659 short_description_list.add(tr(s)); 685 public void addListEntry(PresetListEntry e) { 686 lhm.put(e.value, e); 687 } 688 689 public void addListEntries(Collection<PresetListEntry> e) { 690 for (PresetListEntry i : e) { 691 addListEntry(i); 692 } 660 693 } 661 694 … … 668 701 return new ListCellRenderer() { 669 702 670 HtmlPanel lbl = new HtmlPanel();703 JLabel lbl = new JLabel(); 671 704 JComponent dummy = new JComponent() { 672 705 }; … … 687 720 688 721 PresetListEntry item = (PresetListEntry) value; 689 String s = item.getListDisplay(); 690 lbl.setText(s); 722 lbl.setOpaque(true); 723 lbl.setFont(lbl.getFont().deriveFont(Font.PLAIN)); 724 lbl.setText("<html>" + item.getListDisplay() + "</html>"); 725 lbl.setIcon(item.getIcon()); 691 726 lbl.setEnabled(list.isEnabled()); 692 727 // We do not want the editor to have the maximum height of all … … 1292 1327 parser.map("space", Space.class); 1293 1328 parser.map("key", Key.class); 1329 parser.map("list_entry", PresetListEntry.class); 1294 1330 LinkedList<TaggingPreset> all = new LinkedList<TaggingPreset>(); 1295 1331 TaggingPresetMenu lastmenu = null; 1296 1332 Roles lastrole = null; 1333 List<PresetListEntry> listEntries = new LinkedList<PresetListEntry>(); 1297 1334 1298 1335 if (validate) { … … 1328 1365 lastrole = null; 1329 1366 } else { 1330 if (all.size() != 0) {1331 if (o instanceof Roles) {1332 all.getLast().data.add((Item) o);1367 if (all.size() != 0) { 1368 if (o instanceof Roles) { 1369 all.getLast().data.add((Item) o); 1333 1370 lastrole = (Roles) o; 1334 } 1335 else if(o instanceof Role) { 1336 if(lastrole == null) 1371 } else if (o instanceof Role) { 1372 if (lastrole == null) { 1337 1373 throw new SAXException(tr("Preset role element without parent")); 1374 } 1338 1375 lastrole.roles.add((Role) o); 1339 } 1340 else { 1341 all.getLast().data.add((Item)o); 1376 } else if (o instanceof PresetListEntry) { 1377 listEntries.add((PresetListEntry) o); 1378 } else { 1379 all.getLast().data.add((Item) o); 1380 if (o instanceof ComboMultiSelect) { 1381 ((ComboMultiSelect) o).addListEntries(listEntries); 1382 } 1383 listEntries = new LinkedList<PresetListEntry>(); 1342 1384 lastrole = null; 1343 1385 }
Note:
See TracChangeset
for help on using the changeset viewer.