Ticket #4439: 4439.patch
| File 4439.patch, 32.9 KB (added by , 15 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
117 117 private static final BooleanProperty PROP_FILL_DEFAULT = new BooleanProperty("taggingpreset.fill-default-for-tagged-primitives", false); 118 118 119 119 public static abstract class Item { 120 120 121 protected void initAutoCompletionField(AutoCompletingTextField field, String key) { 121 122 OsmDataLayer layer = Main.main.getEditLayer(); 122 if (layer == null) return; 123 AutoCompletionList list = new AutoCompletionList(); 123 if (layer == null) { 124 return; 125 } 126 AutoCompletionList list = new AutoCompletionList(); 124 127 Main.main.getEditLayer().data.getAutoCompletionManager().populateWithTagValues(list, key); 125 128 field.setAutoCompletionList(list); 126 129 } 127 130 128 131 abstract boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel); 132 129 133 abstract void addCommands(List<Tag> changedTags); 130 boolean requestFocusInWindow() {return false;} 134 135 boolean requestFocusInWindow() { 136 return false; 137 } 131 138 } 132 139 133 140 public static class Usage { … … 139 146 } 140 147 141 148 public boolean unused() { 142 return values. size() == 0;149 return values.isEmpty(); 143 150 } 144 151 public String getFirst() { 145 152 return values.first(); … … 289 296 return true; 290 297 } 291 298 292 @Override public void addCommands(List<Tag> changedTags) { 299 @Override 300 public void addCommands(List<Tag> changedTags) { 293 301 294 302 // return if unchanged 295 String v = (value instanceof JComboBox) ? 296 ((JComboBox)value).getEditor().getItem().toString() : 297 ((JTextField)value).getText(); 303 String v = (value instanceof JComboBox) 304 ? ((JComboBox) value).getEditor().getItem().toString() 305 : ((JTextField) value).getText(); 306 v = v.trim(); 298 307 299 if (!"false".equals(use_last_as_default)) { 300 lastValue.put(key, v); 301 } 302 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) return; 308 if (!"false".equals(use_last_as_default)) { 309 lastValue.put(key, v); 310 } 311 if (v.equals(originalValue) || (originalValue == null && v.length() == 0)) { 312 return; 313 } 303 314 304 if (delete_if_empty && v.length() == 0) {305 v = null;306 }307 changedTags.add(new Tag(key, v));315 if (delete_if_empty && v.length() == 0) { 316 v = null; 317 } 318 changedTags.add(new Tag(key, v)); 308 319 } 309 @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();} 320 321 @Override 322 boolean requestFocusInWindow() { 323 return value.requestFocusInWindow(); 324 } 310 325 } 311 326 312 327 public static class Check extends Item { … … 394 409 @Override boolean requestFocusInWindow() {return check.requestFocusInWindow();} 395 410 } 396 411 397 public static class Comboextends Item {412 public static abstract class ComboMultiSelect extends Item { 398 413 399 414 public String key; 400 415 public String text; … … 407 422 public String short_descriptions; 408 423 public String locale_short_descriptions; 409 424 public String default_; 425 public String delimiter = ";"; 410 426 public boolean delete_if_empty = false; 411 public boolean editable = true;412 427 public String use_last_as_default = "false"; 413 428 public boolean required = false; 414 429 415 pr ivateList<String> short_description_list;416 pr ivate JComboBox combo;417 pr ivateMap<String, PresetListEntry> lhm;418 pr ivateUsage usage;419 pr ivate PresetListEntryoriginalValue;430 protected List<String> short_description_list; 431 protected JComponent component; 432 protected Map<String, PresetListEntry> lhm; 433 protected Usage usage; 434 protected Object originalValue; 420 435 421 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 436 protected abstract Object getSelectedItem(); 437 protected abstract void addToPanelAnchor(JPanel p, String def, String[] display_array); 422 438 439 @Override 440 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 441 423 442 // find out if our key is already used in the selection. 424 443 usage = determineTextUsage(sel, key); 425 444 String def = default_; 426 445 427 String[] value_array = splitEscaped(',', values); 446 char delChar = ';'; 447 if (!delimiter.isEmpty()) { 448 delChar = delimiter.charAt(0); 449 } 450 451 String[] value_array = splitEscaped(delChar, values); 428 452 String[] display_array; 429 453 String[] short_descriptions_array = null; 430 454 431 if (locale_display_values != null) {432 display_array = splitEscaped( ',', locale_display_values);455 if (locale_display_values != null) { 456 display_array = splitEscaped(delChar, locale_display_values); 433 457 } else if (display_values != null) { 434 display_array = splitEscaped( ',', display_values);458 display_array = splitEscaped(delChar, display_values); 435 459 } else { 436 460 display_array = value_array; 437 461 } 438 462 439 463 if (locale_short_descriptions != null) { 440 short_descriptions_array = splitEscaped( ',', locale_short_descriptions);464 short_descriptions_array = splitEscaped(delChar, locale_short_descriptions); 441 465 } else if (short_descriptions != null) { 442 short_descriptions_array = splitEscaped( ',', short_descriptions);466 short_descriptions_array = splitEscaped(delChar, short_descriptions); 443 467 } else if (short_description_list != null) { 444 468 short_descriptions_array = short_description_list.toArray(new String[0]); 445 469 } … … 462 486 if (!usage.hasUniqueValue() && !usage.unused()) { 463 487 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 464 488 } 465 for (int i =0; i<value_array.length; i++) {489 for (int i = 0; i < value_array.length; i++) { 466 490 PresetListEntry e = new PresetListEntry(value_array[i]); 467 491 e.display_value = (locale_display_values == null) 468 ? (values_context == null ? tr(fixPresetString(display_array[i]))492 ? (values_context == null ? tr(fixPresetString(display_array[i])) 469 493 : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 470 494 if (short_descriptions_array != null) { 471 495 e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) … … 473 497 } 474 498 lhm.put(value_array[i], e); 475 499 } 476 if(!usage.unused()){477 for (String s : usage.values) {478 if (!lhm.containsKey(s)) {479 lhm.put(s, new PresetListEntry(s));480 }481 }482 }483 if (def != null && !lhm.containsKey(def)) {484 lhm.put(def, new PresetListEntry(def));485 }486 lhm.put("", new PresetListEntry(""));487 500 488 combo = new JComboBox(lhm.values().toArray()); 489 combo.setRenderer(new PresetComboListCellRenderer()); 490 combo.setEditable(editable); 491 combo.setMaximumRowCount(13); 492 AutoCompletingTextField tf = new AutoCompletingTextField(); 493 initAutoCompletionField(tf, key); 494 tf.getAutoCompletionList().add(Arrays.asList(display_array), AutoCompletionItemPritority.IS_IN_STANDARD); 495 combo.setEditor(tf); 496 497 if (usage.hasUniqueValue()) { 498 // all items have the same value (and there were no unset items) 499 originalValue=lhm.get(usage.getFirst()); 500 combo.setSelectedItem(originalValue); 501 } 502 else if (def != null && usage.unused()) { 503 // default is set and all items were unset 504 if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 505 // selected osm primitives are untagged or filling default feature is enabled 506 combo.setSelectedItem(def); 507 } else { 508 // selected osm primitives are tagged and filling default feature is disabled 509 combo.setSelectedItem(""); 510 } 511 originalValue=lhm.get(DIFFERENT); 512 } 513 else if (usage.unused()) { 514 // all items were unset (and so is default) 515 originalValue=lhm.get(""); 516 combo.setSelectedItem(originalValue); 517 } 518 else { 519 originalValue=lhm.get(DIFFERENT); 520 combo.setSelectedItem(originalValue); 521 } 522 523 if(locale_text == null) { 524 if(text_context != null) { 501 if (locale_text == null) { 502 if (text_context != null) { 525 503 locale_text = trc(text_context, fixPresetString(text)); 526 504 } else { 527 505 locale_text = tr(fixPresetString(text)); 528 506 } 529 507 } 530 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 531 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); 532 return true; 533 } 508 p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 534 509 510 addToPanelAnchor(p, def, display_array); 535 511 536 private static class PresetComboListCellRenderer implements ListCellRenderer {512 return true; 537 513 538 HtmlPanel lbl; 539 JComponent dummy = new JComponent() {}; 514 } 540 515 541 public PresetComboListCellRenderer() { 542 lbl = new HtmlPanel(); 543 } 544 545 public Component getListCellRendererComponent( 546 JList list, 547 Object value, 548 int index, 549 boolean isSelected, 550 boolean cellHasFocus) 551 { 552 if (isSelected) { 553 lbl.setBackground(list.getSelectionBackground()); 554 lbl.setForeground(list.getSelectionForeground()); 555 } else { 556 lbl.setBackground(list.getBackground()); 557 lbl.setForeground(list.getForeground()); 558 } 559 560 PresetListEntry item = (PresetListEntry) value; 561 String s = item.getListDisplay(); 562 lbl.setText(s); 563 // We do not want the editor to have the maximum height of all 564 // entries. Return a dummy with bogus height. 565 if (index == -1) { 566 dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 567 return dummy; 568 } 569 return lbl; 570 } 516 protected String getDisplayIfNull(String display) { 517 return display; 571 518 } 572 519 573 @Override public void addCommands(List<Tag> changedTags) { 574 Object obj = combo.getSelectedItem(); 520 @Override 521 public void addCommands(List<Tag> changedTags) { 522 Object obj = getSelectedItem(); 575 523 String display = (obj == null) ? null : obj.toString(); 576 524 String value = null; 577 if (display == null && combo.isEditable()) {578 display = combo.getEditor().getItem().toString();525 if (display == null) { 526 display = getDisplayIfNull(display); 579 527 } 580 528 581 if (display != null) 582 { 529 if (display != null) { 583 530 for (String key : lhm.keySet()) { 584 531 String k = lhm.get(key).toString(); 585 532 if (k != null && k.equals(display)) { 586 value =key;533 value = key; 587 534 } 588 535 } 589 if (value == null) {536 if (value == null) { 590 537 value = display; 591 538 } 592 539 } else { 593 540 value = ""; 594 541 } 542 value = value.trim(); 595 543 596 544 // no change if same as before 597 545 if (originalValue == null) { 598 if (value.length() == 0) 546 if (value.length() == 0) { 599 547 return; 600 } else if (value.equals(originalValue.toString())) 548 } 549 } else if (value.equals(originalValue.toString())) { 601 550 return; 551 } 602 552 603 553 if (delete_if_empty && value.length() == 0) { 604 554 value = null; … … 616 566 short_description_list.add(tr(s)); 617 567 } 618 568 619 @Override boolean requestFocusInWindow() {return combo.requestFocusInWindow();} 569 @Override 570 boolean requestFocusInWindow() { 571 return component.requestFocusInWindow(); 572 } 573 574 protected ListCellRenderer getListCellRenderer() { 575 return new ListCellRenderer() { 576 577 HtmlPanel lbl = new HtmlPanel(); 578 JComponent dummy = new JComponent() { 579 }; 580 581 public Component getListCellRendererComponent( 582 JList list, 583 Object value, 584 int index, 585 boolean isSelected, 586 boolean cellHasFocus) { 587 if (isSelected) { 588 lbl.setBackground(list.getSelectionBackground()); 589 lbl.setForeground(list.getSelectionForeground()); 590 } else { 591 lbl.setBackground(list.getBackground()); 592 lbl.setForeground(list.getForeground()); 593 } 594 595 PresetListEntry item = (PresetListEntry) value; 596 String s = item.getListDisplay(); 597 lbl.setText(s); 598 lbl.setEnabled(list.isEnabled()); 599 // We do not want the editor to have the maximum height of all 600 // entries. Return a dummy with bogus height. 601 if (index == -1) { 602 dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10)); 603 return dummy; 604 } 605 return lbl; 606 } 607 }; 608 } 620 609 } 621 610 611 public static class Combo extends ComboMultiSelect { 612 613 public boolean editable = true; 614 protected JComboBox combo; 615 616 public Combo() { 617 delimiter = ","; 618 } 619 620 @Override 621 protected void addToPanelAnchor(JPanel p, String def, String[] display_array) { 622 if (!usage.unused()) { 623 for (String s : usage.values) { 624 if (!lhm.containsKey(s)) { 625 lhm.put(s, new PresetListEntry(s)); 626 } 627 } 628 } 629 if (def != null && !lhm.containsKey(def)) { 630 lhm.put(def, new PresetListEntry(def)); 631 } 632 lhm.put("", new PresetListEntry("")); 633 634 combo = new JComboBox(lhm.values().toArray()); 635 component = combo; 636 combo.setRenderer(getListCellRenderer()); 637 combo.setEditable(editable); 638 combo.setMaximumRowCount(13); 639 AutoCompletingTextField tf = new AutoCompletingTextField(); 640 initAutoCompletionField(tf, key); 641 tf.getAutoCompletionList().add(Arrays.asList(display_array), AutoCompletionItemPritority.IS_IN_STANDARD); 642 combo.setEditor(tf); 643 644 if (usage.hasUniqueValue()) { 645 // all items have the same value (and there were no unset items) 646 originalValue = lhm.get(usage.getFirst()); 647 combo.setSelectedItem(originalValue); 648 } else if (def != null && usage.unused()) { 649 // default is set and all items were unset 650 if (!usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 651 // selected osm primitives are untagged or filling default feature is enabled 652 combo.setSelectedItem(def); 653 } else { 654 // selected osm primitives are tagged and filling default feature is disabled 655 combo.setSelectedItem(""); 656 } 657 originalValue = lhm.get(DIFFERENT); 658 } else if (usage.unused()) { 659 // all items were unset (and so is default) 660 originalValue = lhm.get(""); 661 combo.setSelectedItem(originalValue); 662 } else { 663 originalValue = lhm.get(DIFFERENT); 664 combo.setSelectedItem(originalValue); 665 } 666 p.add(combo, GBC.eol().fill(GBC.HORIZONTAL)); 667 668 } 669 670 @Override 671 protected Object getSelectedItem() { 672 return combo.getSelectedItem(); 673 674 } 675 676 @Override 677 protected String getDisplayIfNull(String display) { 678 if (combo.isEditable()) { 679 return combo.getEditor().getItem().toString(); 680 } else { 681 return display; 682 } 683 684 } 685 } 686 622 687 /** 623 * Class that allows list values to be assigned and retri ved as a comma-delimited688 * Class that allows list values to be assigned and retrieved as a comma-delimited 624 689 * string. 625 690 */ 626 691 public static class ConcatenatingJList extends JList { … … 664 729 } 665 730 } 666 731 667 public static class MultiSelect extends Item{732 public static class MultiSelect extends ComboMultiSelect { 668 733 669 public String key;670 public String text;671 public String text_context;672 public String locale_text;673 public String values;674 public String values_context;675 public String display_values;676 public String locale_display_values;677 public String short_descriptions;678 public String locale_short_descriptions;679 public String default_;680 public String delimiter = ";";681 public boolean delete_if_empty = false;682 public String use_last_as_default = "false";683 public boolean required = false;684 734 public long rows = -1; 735 protected ConcatenatingJList list; 685 736 686 private List<String> short_description_list; 687 private ConcatenatingJList list; 688 private Map<String, PresetListEntry> lhm; 689 private Usage usage; 690 private String originalValue; 691 692 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 693 694 // find out if our key is already used in the selection. 695 usage = determineTextUsage(sel, key); 696 String def = default_; 697 698 char delChar = ';'; 699 if (delimiter.length() > 0) { 700 delChar = delimiter.charAt(0); 701 } 702 703 String[] value_array = splitEscaped(delChar, values); 704 String[] display_array; 705 String[] short_descriptions_array = null; 706 707 if (locale_display_values != null) { 708 display_array = splitEscaped(delChar, locale_display_values); 709 } else if (display_values != null) { 710 display_array = splitEscaped(delChar, display_values); 711 } else { 712 display_array = value_array; 713 } 714 715 if (locale_short_descriptions != null) { 716 short_descriptions_array = splitEscaped(delChar, locale_short_descriptions); 717 } else if (short_descriptions != null) { 718 short_descriptions_array = splitEscaped(delChar, short_descriptions); 719 } else if (short_description_list != null) { 720 short_descriptions_array = short_description_list.toArray(new String[0]); 721 } 722 723 if (!"false".equals(use_last_as_default) && def == null && lastValue.containsKey(key)) { 724 def = lastValue.get(key); 725 } 726 727 if (display_array.length != value_array.length) { 728 System.err.println(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''display_values'' must be the same as in ''values''", key, text)); 729 display_array = value_array; 730 } 731 732 if (short_descriptions_array != null && short_descriptions_array.length != value_array.length) { 733 System.err.println(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''short_descriptions'' must be the same as in ''values''", key, text)); 734 short_descriptions_array = null; 735 } 736 737 lhm = new LinkedHashMap<String, PresetListEntry>(); 738 if (!usage.hasUniqueValue() && !usage.unused()) { 739 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 740 } 741 for (int i=0; i<value_array.length; i++) { 742 PresetListEntry e = new PresetListEntry(value_array[i]); 743 e.display_value = (locale_display_values == null) 744 ? (values_context == null ? tr(fixPresetString(display_array[i])) 745 : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 746 if (short_descriptions_array != null) { 747 e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) 748 : short_descriptions_array[i]; 749 } 750 lhm.put(value_array[i], e); 751 } 752 737 @Override 738 protected void addToPanelAnchor(JPanel p, String def, String[] display_array) { 753 739 list = new ConcatenatingJList(delimiter, lhm.values().toArray()); 754 PresetListCellRenderer renderer = new PresetListCellRenderer(); 740 component = list; 741 ListCellRenderer renderer = getListCellRenderer(); 755 742 list.setCellRenderer(renderer); 756 743 757 744 if (usage.hasUniqueValue() && !usage.unused()) { 758 originalValue =usage.getFirst();745 originalValue = usage.getFirst(); 759 746 list.setSelectedItem(originalValue); 760 } 761 else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 762 originalValue=DIFFERENT; 747 } else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 748 originalValue = DIFFERENT; 763 749 list.setSelectedItem(def); 764 } 765 else if (usage.unused()) { 766 originalValue=null; 750 } else if (usage.unused()) { 751 originalValue = null; 767 752 list.setSelectedItem(originalValue); 768 } 769 else { 770 originalValue=DIFFERENT; 753 } else { 754 originalValue = DIFFERENT; 771 755 list.setSelectedItem(originalValue); 772 756 } 773 757 774 if (locale_text == null) {775 if(text_context != null) {776 locale_text = trc(text_context, fixPresetString(text));777 } else {778 locale_text = tr(fixPresetString(text));779 }780 }781 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0));782 758 JScrollPane sp = new JScrollPane(list); 783 759 // if a number of rows has been specified in the preset, 784 760 // modify preferred height of scroll pane to match that row count. 785 if (rows != -1) 786 { 761 if (rows != -1) { 787 762 double height = renderer.getListCellRendererComponent(list, 788 763 new PresetListEntry("x"), 0, false, false).getPreferredSize().getHeight() * rows; 789 764 sp.setPreferredSize(new Dimension((int) sp.getPreferredSize().getWidth(), (int) height)); 790 765 } 791 766 p.add(sp, GBC.eol().fill(GBC.HORIZONTAL)); 792 return true;793 }794 767 795 private static class PresetListCellRenderer implements ListCellRenderer {796 768 797 HtmlPanel lbl;798 JComponent dummy = new JComponent() {};799 800 public PresetListCellRenderer() {801 lbl = new HtmlPanel();802 }803 804 public Component getListCellRendererComponent(805 JList list,806 Object value,807 int index,808 boolean isSelected,809 boolean cellHasFocus)810 {811 if (isSelected) {812 lbl.setBackground(list.getSelectionBackground());813 lbl.setForeground(list.getSelectionForeground());814 } else {815 lbl.setBackground(list.getBackground());816 lbl.setForeground(list.getForeground());817 }818 819 PresetListEntry item = (PresetListEntry) value;820 String s = item.getListDisplay();821 lbl.setText(s);822 lbl.setEnabled(list.isEnabled());823 // We do not want the editor to have the maximum height of all824 // entries. Return a dummy with bogus height.825 if (index == -1) {826 dummy.setPreferredSize(new Dimension(lbl.getPreferredSize().width, 10));827 return dummy;828 }829 return lbl;830 }831 769 } 832 770 833 @Override public void addCommands(List<Tag> changedTags) { 834 Object obj = list.getSelectedItem(); 835 String display = (obj == null) ? null : obj.toString(); 836 String value = null; 837 838 if (display != null) 839 { 840 for (String key : lhm.keySet()) { 841 String k = lhm.get(key).toString(); 842 if (k != null && k.equals(display)) { 843 value=key; 844 } 845 } 846 if (value == null) { 847 value = display; 848 } 849 } else { 850 value = ""; 851 } 852 853 // no change if same as before 854 if (originalValue == null) { 855 if (value.length() == 0) 856 return; 857 } else if (value.equals(originalValue.toString())) 858 return; 859 860 if (delete_if_empty && value.length() == 0) { 861 value = null; 862 } 863 if (!"false".equals(use_last_as_default)) { 864 lastValue.put(key, value); 865 } 866 changedTags.add(new Tag(key, value)); 771 @Override 772 protected Object getSelectedItem() { 773 return list.getSelectedItem(); 867 774 } 868 869 public void setShort_description(String s) {870 if (short_description_list == null) {871 short_description_list = new ArrayList<String>();872 }873 short_description_list.add(tr(s));874 }875 876 @Override boolean requestFocusInWindow() {return list.requestFocusInWindow();}877 775 } 878 776 879 777 /** … … 908 806 } 909 807 910 808 public static class Label extends Item { 809 911 810 public String text; 912 811 public String text_context; 913 812 public String locale_text; 914 813 915 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 916 if(locale_text == null) { 917 if(text_context != null) { 814 @Override 815 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 816 if (locale_text == null) { 817 if (text_context != null) { 918 818 locale_text = trc(text_context, fixPresetString(text)); 919 819 } else { 920 820 locale_text = tr(fixPresetString(text)); … … 923 823 p.add(new JLabel(locale_text), GBC.eol()); 924 824 return false; 925 825 } 926 @Override public void addCommands(List<Tag> changedTags) {} 826 827 @Override 828 public void addCommands(List<Tag> changedTags) { 829 } 927 830 } 928 831 929 832 public static class Link extends Item { 833 930 834 public String href; 931 835 public String text; 932 836 public String text_context; 933 837 public String locale_text; 934 838 public String locale_href; 935 839 936 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 937 if(locale_text == null) { 938 if(text == null) { 840 @Override 841 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 842 if (locale_text == null) { 843 if (text == null) { 939 844 locale_text = tr("More information about this feature"); 940 } else if (text_context != null) {845 } else if (text_context != null) { 941 846 locale_text = trc(text_context, fixPresetString(text)); 942 847 } else { 943 848 locale_text = tr(fixPresetString(text)); … … 952 857 } 953 858 return false; 954 859 } 955 @Override public void addCommands(List<Tag> changedTags) {} 860 861 @Override 862 public void addCommands(List<Tag> changedTags) { 863 } 956 864 } 957 865 958 866 public static class Role { … … 1024 932 } 1025 933 1026 934 public static class Roles extends Item { 935 1027 936 public List<Role> roles = new LinkedList<Role>(); 1028 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 937 938 @Override 939 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 1029 940 p.add(new JLabel(" "), GBC.eol()); // space 1030 if(roles.size() > 0) 1031 { 941 if (roles.size() > 0) { 1032 942 JPanel proles = new JPanel(new GridBagLayout()); 1033 proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0, 0,10,0));1034 proles.add(new JLabel(tr("role")), GBC.std().insets(0, 0,10,0));1035 proles.add(new JLabel(tr("count")), GBC.std().insets(0, 0,10,0));943 proles.add(new JLabel(tr("Available roles")), GBC.std().insets(0, 0, 10, 0)); 944 proles.add(new JLabel(tr("role")), GBC.std().insets(0, 0, 10, 0)); 945 proles.add(new JLabel(tr("count")), GBC.std().insets(0, 0, 10, 0)); 1036 946 proles.add(new JLabel(tr("elements")), GBC.eol()); 1037 947 for (Role i : roles) { 1038 948 i.addToPanel(proles, sel); … … 1041 951 } 1042 952 return false; 1043 953 } 1044 @Override public void addCommands(List<Tag> changedTags) {} 954 955 @Override 956 public void addCommands(List<Tag> changedTags) { 957 } 1045 958 } 1046 959 1047 960 public static class Optional extends Item { 961 1048 962 // TODO: Draw a box around optional stuff 1049 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 963 @Override 964 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 1050 965 p.add(new JLabel(" "), GBC.eol()); // space 1051 966 p.add(new JLabel(tr("Optional Attributes:")), GBC.eol()); 1052 967 p.add(new JLabel(" "), GBC.eol()); // space 1053 968 return false; 1054 969 } 1055 @Override public void addCommands(List<Tag> changedTags) {} 970 971 @Override 972 public void addCommands(List<Tag> changedTags) { 973 } 1056 974 } 1057 975 1058 976 public static class Space extends Item { 1059 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 977 978 @Override 979 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 1060 980 p.add(new JLabel(" "), GBC.eol()); // space 1061 981 return false; 1062 982 } 1063 @Override public void addCommands(List<Tag> changedTags) {} 983 984 @Override 985 public void addCommands(List<Tag> changedTags) { 986 } 1064 987 } 1065 988 1066 989 public static class Key extends Item { 990 1067 991 public String key; 1068 992 public String value; 1069 993 1070 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { return false; }1071 @Override public void addCommands(List<Tag> changedTags) {1072 changedTags.add(new Tag(key, value != null && !value.equals("") ? value : null));994 @Override 995 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 996 return false; 1073 997 } 998 999 @Override 1000 public void addCommands(List<Tag> changedTags) { 1001 changedTags.add(new Tag(key, value)); 1002 } 1074 1003 } 1075 1004 1076 1005 /**
