- Timestamp:
- 2012-04-01T20:36:32+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 = newHtmlPanel();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.