Changeset 4340 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-08-26T21:40:33+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r4302 r4340 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); … … 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 … … 140 147 141 148 public boolean unused() { 142 return values. size() == 0;149 return values.isEmpty(); 143 150 } 144 151 public String getFirst() { … … 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(); 298 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; 303 304 if (delete_if_empty && v.length() == 0) { 305 v = null; 306 } 307 changedTags.add(new Tag(key, v)); 308 } 309 @Override boolean requestFocusInWindow() {return value.requestFocusInWindow();} 303 String v = (value instanceof JComboBox) 304 ? ((JComboBox) value).getEditor().getItem().toString() 305 : ((JTextField) value).getText(); 306 v = v.trim(); 307 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 } 314 315 if (delete_if_empty && v.length() == 0) { 316 v = null; 317 } 318 changedTags.add(new Tag(key, v)); 319 } 320 321 @Override 322 boolean requestFocusInWindow() { 323 return value.requestFocusInWindow(); 324 } 310 325 } 311 326 … … 395 410 } 396 411 397 public static class Combo extends Item { 398 399 public String key; 400 public String text; 401 public String text_context; 402 public String locale_text; 403 public String values; 404 public String values_context; 405 public String display_values; 406 public String locale_display_values; 407 public String short_descriptions; 408 public String locale_short_descriptions; 409 public String default_; 410 public boolean delete_if_empty = false; 411 public boolean editable = true; 412 public String use_last_as_default = "false"; 413 public boolean required = false; 414 415 private List<String> short_description_list; 416 private JComboBox combo; 417 private Map<String, PresetListEntry> lhm; 418 private Usage usage; 419 private PresetListEntry originalValue; 420 421 @Override public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 422 423 // find out if our key is already used in the selection. 424 usage = determineTextUsage(sel, key); 425 String def = default_; 426 427 String[] value_array = splitEscaped(',', values); 428 String[] display_array; 429 String[] short_descriptions_array = null; 430 431 if(locale_display_values != null) { 432 display_array = splitEscaped(',', locale_display_values); 433 } else if (display_values != null) { 434 display_array = splitEscaped(',', display_values); 435 } else { 436 display_array = value_array; 437 } 438 439 if (locale_short_descriptions != null) { 440 short_descriptions_array = splitEscaped(',', locale_short_descriptions); 441 } else if (short_descriptions != null) { 442 short_descriptions_array = splitEscaped(',', short_descriptions); 443 } else if (short_description_list != null) { 444 short_descriptions_array = short_description_list.toArray(new String[0]); 445 } 446 447 if (!"false".equals(use_last_as_default) && def == null && lastValue.containsKey(key)) { 448 def = lastValue.get(key); 449 } 450 451 if (display_array.length != value_array.length) { 452 System.err.println(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''display_values'' must be the same as in ''values''", key, text)); 453 display_array = value_array; 454 } 455 456 if (short_descriptions_array != null && short_descriptions_array.length != value_array.length) { 457 System.err.println(tr("Broken tagging preset \"{0}-{1}\" - number of items in ''short_descriptions'' must be the same as in ''values''", key, text)); 458 short_descriptions_array = null; 459 } 460 461 lhm = new LinkedHashMap<String, PresetListEntry>(); 462 if (!usage.hasUniqueValue() && !usage.unused()) { 463 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 464 } 465 for (int i=0; i<value_array.length; i++) { 466 PresetListEntry e = new PresetListEntry(value_array[i]); 467 e.display_value = (locale_display_values == null) 468 ? (values_context == null ? tr(fixPresetString(display_array[i])) 469 : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 470 if (short_descriptions_array != null) { 471 e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) 472 : fixPresetString(short_descriptions_array[i]); 473 } 474 lhm.put(value_array[i], e); 475 } 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 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) { 525 locale_text = trc(text_context, fixPresetString(text)); 526 } else { 527 locale_text = tr(fixPresetString(text)); 528 } 529 } 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 } 534 535 536 private static class PresetComboListCellRenderer implements ListCellRenderer { 537 538 HtmlPanel lbl; 539 JComponent dummy = new JComponent() {}; 540 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 } 571 } 572 573 @Override public void addCommands(List<Tag> changedTags) { 574 Object obj = combo.getSelectedItem(); 575 String display = (obj == null) ? null : obj.toString(); 576 String value = null; 577 if(display == null && combo.isEditable()) { 578 display = combo.getEditor().getItem().toString(); 579 } 580 581 if (display != null) 582 { 583 for (String key : lhm.keySet()) { 584 String k = lhm.get(key).toString(); 585 if (k != null && k.equals(display)) { 586 value=key; 587 } 588 } 589 if(value == null) { 590 value = display; 591 } 592 } else { 593 value = ""; 594 } 595 596 // no change if same as before 597 if (originalValue == null) { 598 if (value.length() == 0) 599 return; 600 } else if (value.equals(originalValue.toString())) 601 return; 602 603 if (delete_if_empty && value.length() == 0) { 604 value = null; 605 } 606 if (!"false".equals(use_last_as_default)) { 607 lastValue.put(key, value); 608 } 609 changedTags.add(new Tag(key, value)); 610 } 611 612 public void setShort_description(String s) { 613 if (short_description_list == null) { 614 short_description_list = new ArrayList<String>(); 615 } 616 short_description_list.add(tr(s)); 617 } 618 619 @Override boolean requestFocusInWindow() {return combo.requestFocusInWindow();} 620 } 621 622 /** 623 * Class that allows list values to be assigned and retrived as a comma-delimited 624 * string. 625 */ 626 public static class ConcatenatingJList extends JList { 627 private String delimiter; 628 public ConcatenatingJList(String del, Object[] o) { 629 super(o); 630 delimiter = del; 631 } 632 public void setSelectedItem(Object o) { 633 if (o == null) { 634 clearSelection(); 635 } else { 636 String s = o.toString(); 637 HashSet<String> parts = new HashSet<String>(Arrays.asList(s.split(delimiter))); 638 ListModel lm = getModel(); 639 int[] intParts = new int[lm.getSize()]; 640 int j = 0; 641 for (int i = 0; i < lm.getSize(); i++) { 642 if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value))) { 643 intParts[j++]=i; 644 } 645 } 646 setSelectedIndices(Arrays.copyOf(intParts, j)); 647 // check if we have acutally managed to represent the full 648 // value with our presets. if not, cop out; we will not offer 649 // a selection list that threatens to ruin the value. 650 setEnabled(s.equals(getSelectedItem())); 651 } 652 } 653 public String getSelectedItem() { 654 ListModel lm = getModel(); 655 int[] si = getSelectedIndices(); 656 StringBuilder builder = new StringBuilder(); 657 for (int i=0; i<si.length; i++) { 658 if (i>0) { 659 builder.append(delimiter); 660 } 661 builder.append(((PresetListEntry)lm.getElementAt(si[i])).value); 662 } 663 return builder.toString(); 664 } 665 } 666 667 public static class MultiSelect extends Item { 412 public static abstract class ComboMultiSelect extends Item { 668 413 669 414 public String key; … … 682 427 public String use_last_as_default = "false"; 683 428 public boolean required = false; 684 public long rows = -1; 685 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) { 429 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; 435 436 protected abstract Object getSelectedItem(); 437 protected abstract void addToPanelAnchor(JPanel p, String def, String[] display_array); 438 439 @Override 440 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel) { 693 441 694 442 // find out if our key is already used in the selection. … … 697 445 698 446 char delChar = ';'; 699 if ( delimiter.length() > 0) {447 if (!delimiter.isEmpty()) { 700 448 delChar = delimiter.charAt(0); 701 449 } … … 739 487 lhm.put(DIFFERENT, new PresetListEntry(DIFFERENT)); 740 488 } 741 for (int i =0; i<value_array.length; i++) {489 for (int i = 0; i < value_array.length; i++) { 742 490 PresetListEntry e = new PresetListEntry(value_array[i]); 743 491 e.display_value = (locale_display_values == null) 744 ? (values_context == null ? tr(fixPresetString(display_array[i]))492 ? (values_context == null ? tr(fixPresetString(display_array[i])) 745 493 : trc(values_context, fixPresetString(display_array[i]))) : display_array[i]; 746 494 if (short_descriptions_array != null) { 747 495 e.short_description = locale_short_descriptions == null ? tr(fixPresetString(short_descriptions_array[i])) 748 : short_descriptions_array[i];496 : fixPresetString(short_descriptions_array[i]); 749 497 } 750 498 lhm.put(value_array[i], e); 751 499 } 752 500 753 list = new ConcatenatingJList(delimiter, lhm.values().toArray());754 PresetListCellRenderer renderer = new PresetListCellRenderer();755 list.setCellRenderer(renderer);756 757 if (usage.hasUniqueValue() && !usage.unused()) {758 originalValue=usage.getFirst();759 list.setSelectedItem(originalValue);760 }761 else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) {762 originalValue=DIFFERENT;763 list.setSelectedItem(def);764 }765 else if (usage.unused()) {766 originalValue=null;767 list.setSelectedItem(originalValue);768 }769 else {770 originalValue=DIFFERENT;771 list.setSelectedItem(originalValue);772 }773 774 501 if (locale_text == null) { 775 if (text_context != null) {502 if (text_context != null) { 776 503 locale_text = trc(text_context, fixPresetString(text)); 777 504 } else { … … 779 506 } 780 507 } 781 p.add(new JLabel(locale_text+":"), GBC.std().insets(0,0,10,0)); 508 p.add(new JLabel(locale_text + ":"), GBC.std().insets(0, 0, 10, 0)); 509 510 addToPanelAnchor(p, def, display_array); 511 512 return true; 513 514 } 515 516 protected String getDisplayIfNull(String display) { 517 return display; 518 } 519 520 @Override 521 public void addCommands(List<Tag> changedTags) { 522 Object obj = getSelectedItem(); 523 String display = (obj == null) ? null : obj.toString(); 524 String value = null; 525 if (display == null) { 526 display = getDisplayIfNull(display); 527 } 528 529 if (display != null) { 530 for (String key : lhm.keySet()) { 531 String k = lhm.get(key).toString(); 532 if (k != null && k.equals(display)) { 533 value = key; 534 } 535 } 536 if (value == null) { 537 value = display; 538 } 539 } else { 540 value = ""; 541 } 542 value = value.trim(); 543 544 // no change if same as before 545 if (originalValue == null) { 546 if (value.length() == 0) { 547 return; 548 } 549 } else if (value.equals(originalValue.toString())) { 550 return; 551 } 552 553 if (delete_if_empty && value.length() == 0) { 554 value = null; 555 } 556 if (!"false".equals(use_last_as_default)) { 557 lastValue.put(key, value); 558 } 559 changedTags.add(new Tag(key, value)); 560 } 561 562 public void setShort_description(String s) { 563 if (short_description_list == null) { 564 short_description_list = new ArrayList<String>(); 565 } 566 short_description_list.add(tr(s)); 567 } 568 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 } 609 } 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 687 /** 688 * Class that allows list values to be assigned and retrieved as a comma-delimited 689 * string. 690 */ 691 public static class ConcatenatingJList extends JList { 692 private String delimiter; 693 public ConcatenatingJList(String del, Object[] o) { 694 super(o); 695 delimiter = del; 696 } 697 public void setSelectedItem(Object o) { 698 if (o == null) { 699 clearSelection(); 700 } else { 701 String s = o.toString(); 702 HashSet<String> parts = new HashSet<String>(Arrays.asList(s.split(delimiter))); 703 ListModel lm = getModel(); 704 int[] intParts = new int[lm.getSize()]; 705 int j = 0; 706 for (int i = 0; i < lm.getSize(); i++) { 707 if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value))) { 708 intParts[j++]=i; 709 } 710 } 711 setSelectedIndices(Arrays.copyOf(intParts, j)); 712 // check if we have acutally managed to represent the full 713 // value with our presets. if not, cop out; we will not offer 714 // a selection list that threatens to ruin the value. 715 setEnabled(s.equals(getSelectedItem())); 716 } 717 } 718 public String getSelectedItem() { 719 ListModel lm = getModel(); 720 int[] si = getSelectedIndices(); 721 StringBuilder builder = new StringBuilder(); 722 for (int i=0; i<si.length; i++) { 723 if (i>0) { 724 builder.append(delimiter); 725 } 726 builder.append(((PresetListEntry)lm.getElementAt(si[i])).value); 727 } 728 return builder.toString(); 729 } 730 } 731 732 public static class MultiSelect extends ComboMultiSelect { 733 734 public long rows = -1; 735 protected ConcatenatingJList list; 736 737 @Override 738 protected void addToPanelAnchor(JPanel p, String def, String[] display_array) { 739 list = new ConcatenatingJList(delimiter, lhm.values().toArray()); 740 component = list; 741 ListCellRenderer renderer = getListCellRenderer(); 742 list.setCellRenderer(renderer); 743 744 if (usage.hasUniqueValue() && !usage.unused()) { 745 originalValue = usage.getFirst(); 746 list.setSelectedItem(originalValue); 747 } else if (def != null && !usage.hadKeys() || PROP_FILL_DEFAULT.get() || "force".equals(use_last_as_default)) { 748 originalValue = DIFFERENT; 749 list.setSelectedItem(def); 750 } else if (usage.unused()) { 751 originalValue = null; 752 list.setSelectedItem(originalValue); 753 } else { 754 originalValue = DIFFERENT; 755 list.setSelectedItem(originalValue); 756 } 757 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; … … 790 765 } 791 766 p.add(sp, GBC.eol().fill(GBC.HORIZONTAL)); 792 return true; 793 } 794 795 private static class PresetListCellRenderer implements ListCellRenderer { 796 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 all 824 // 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 } 832 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)); 867 } 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();} 767 768 769 } 770 771 @Override 772 protected Object getSelectedItem() { 773 return list.getSelectedItem(); 774 } 877 775 } 878 776 … … 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 { … … 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; … … 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 { … … 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 … … 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) { … … 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()); … … 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; 997 } 998 999 @Override 1000 public void addCommands(List<Tag> changedTags) { 1001 changedTags.add(new Tag(key, value)); 1073 1002 } 1074 1003 }
Note:
See TracChangeset
for help on using the changeset viewer.