Changeset 9502 in josm
- Timestamp:
- 2016-01-17T15:27:57+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r9484 r9502 87 87 * @since 5633 88 88 */ 89 class TagEditHelper { 89 public class TagEditHelper { 90 90 91 private final JTable tagTable; 91 92 private final DefaultTableModel tagData; … … 93 94 94 95 // Selection that we are editing by using both dialogs 95 pr ivateCollection<OsmPrimitive> sel;96 protected Collection<OsmPrimitive> sel; 96 97 97 98 private String changedKey; … … 108 109 private String lastAddValue; 109 110 111 /** Default number of recent tags */ 110 112 public static final int DEFAULT_LRU_TAGS_NUMBER = 5; 113 /** Maximum number of recent tags */ 111 114 public static final int MAX_LRU_TAGS_NUMBER = 30; 115 116 /** Use English language for tag by default */ 117 public static final BooleanProperty PROPERTY_FIX_TAG_LOCALE = new BooleanProperty("properties.fix-tag-combobox-locale", false); 118 /** Whether recent tags must be remembered */ 119 public static final BooleanProperty PROPERTY_REMEMBER_TAGS = new BooleanProperty("properties.remember-recently-added-tags", true); 120 /** Number of recent tags */ 121 public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags", 122 DEFAULT_LRU_TAGS_NUMBER); 112 123 113 124 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) … … 119 130 }; 120 131 121 TagEditHelper(JTable tagTable, DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) {132 public TagEditHelper(JTable tagTable, DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) { 122 133 this.tagTable = tagTable; 123 134 this.tagData = propertyData; … … 141 152 changedKey = null; 142 153 sel = Main.main.getInProgressSelection(); 143 if (sel == null || sel.isEmpty()) return; 144 145 final AddTagsDialog addDialog = new AddTagsDialog(); 154 if (sel == null || sel.isEmpty()) 155 return; 156 157 final AddTagsDialog addDialog = getAddTagsDialog(); 146 158 147 159 addDialog.showDialog(); … … 152 164 else 153 165 addDialog.undoAllTagsAdding(); 166 } 167 168 protected AddTagsDialog getAddTagsDialog() { 169 return new AddTagsDialog(); 154 170 } 155 171 … … 163 179 changedKey = null; 164 180 sel = Main.main.getInProgressSelection(); 165 if (sel == null || sel.isEmpty()) return; 181 if (sel == null || sel.isEmpty()) 182 return; 166 183 167 184 String key = getDataKey(row); 168 185 objKey = key; 169 186 170 final EditTagDialog editDialog = new EditTagDialog(key, getDataValues(row), focusOnKey);187 final IEditTagDialog editDialog = getEditTagDialog(row, focusOnKey, key); 171 188 editDialog.showDialog(); 172 if (editDialog.getValue() != 1) return; 189 if (editDialog.getValue() != 1) 190 return; 173 191 editDialog.performTagEdit(); 192 } 193 194 protected interface IEditTagDialog { 195 ExtendedDialog showDialog(); 196 197 int getValue(); 198 199 void performTagEdit(); 200 } 201 202 protected IEditTagDialog getEditTagDialog(int row, boolean focusOnKey, String key) { 203 return new EditTagDialog(key, getDataValues(row), focusOnKey); 174 204 } 175 205 … … 251 281 } 252 282 253 p ublic final class EditTagDialog extends AbstractTagsDialog {283 protected class EditTagDialog extends AbstractTagsDialog implements IEditTagDialog { 254 284 private final String key; 255 285 private final transient Map<String, Integer> m; … … 278 308 String str = value.getValue(); 279 309 if (valueCount.containsKey(objKey)) { 280 Map<String, Integer> m = valueCount.get(objKey);281 if (m .containsKey(str)) {282 str = tr("{0} ({1})", str, m .get(str));310 Map<String, Integer> map = valueCount.get(objKey); 311 if (map.containsKey(str)) { 312 str = tr("{0} ({1})", str, map.get(str)); 283 313 c.setFont(c.getFont().deriveFont(Font.ITALIC + Font.BOLD)); 284 314 } … … 290 320 }; 291 321 292 pr ivateEditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) {322 protected EditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) { 293 323 super(Main.parent, trn("Change value?", "Change values?", map.size()), new String[] {tr("OK"), tr("Cancel")}); 294 324 setButtonIcons(new String[] {"ok", "cancel"}); … … 366 396 * Confirmations may be needed. 367 397 */ 368 private void performTagEdit() { 398 @Override 399 public void performTagEdit() { 369 400 String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString()); 370 401 value = Normalizer.normalize(value, java.text.Normalizer.Form.NFC); … … 425 456 } 426 457 427 public static final BooleanProperty PROPERTY_FIX_TAG_LOCALE = new BooleanProperty("properties.fix-tag-combobox-locale", false); 428 public static final BooleanProperty PROPERTY_REMEMBER_TAGS = new BooleanProperty("properties.remember-recently-added-tags", true); 429 public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags", 430 DEFAULT_LRU_TAGS_NUMBER); 431 432 abstract class AbstractTagsDialog extends ExtendedDialog { 458 protected abstract class AbstractTagsDialog extends ExtendedDialog { 433 459 protected AutoCompletingComboBox keys; 434 460 protected AutoCompletingComboBox values; … … 546 572 } 547 573 548 class AddTagsDialog extends AbstractTagsDialog {574 protected class AddTagsDialog extends AbstractTagsDialog { 549 575 private final List<JosmAction> recentTagsActions = new ArrayList<>(); 576 protected final transient FocusAdapter focus; 550 577 551 578 // Counter of added commands for possible undo 552 579 private int commandCount; 553 580 554 AddTagsDialog() {581 protected AddTagsDialog() { 555 582 super(Main.parent, tr("Add value?"), new String[] {tr("OK"), tr("Cancel")}); 556 583 setButtonIcons(new String[] {"ok", "cancel"}); … … 604 631 } 605 632 606 FocusAdapterfocus = addFocusAdapter(autocomplete, defaultACItemComparator);633 focus = addFocusAdapter(autocomplete, defaultACItemComparator); 607 634 // fire focus event in advance or otherwise the popup list will be too small at first 608 635 focus.focusGained(null); 609 610 int recentTagsToShow = PROPERTY_RECENT_TAGS_NUMBER.get();611 if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) {612 recentTagsToShow = MAX_LRU_TAGS_NUMBER;613 }614 636 615 637 // Add tag on Shift-Enter … … 624 646 }); 625 647 626 suggestRecentlyAddedTags(mainPanel, recentTagsToShow,focus);648 suggestRecentlyAddedTags(mainPanel, focus); 627 649 628 650 mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill()); … … 641 663 @Override 642 664 public void actionPerformed(ActionEvent e) { 643 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 644 PROPERTY_REMEMBER_TAGS.put(sel); 645 if (sel) saveTagsIfNeeded(); 665 boolean state = ((JCheckBoxMenuItem) e.getSource()).getState(); 666 PROPERTY_REMEMBER_TAGS.put(state); 667 if (state) 668 saveTagsIfNeeded(); 646 669 } 647 670 }); … … 674 697 } 675 698 676 pr ivatevoid selectNumberOfTags() {699 protected void selectNumberOfTags() { 677 700 String s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display")); 678 701 if (s == null) { … … 691 714 } 692 715 693 private void suggestRecentlyAddedTags(JPanel mainPanel, int tagsToShow, final FocusAdapter focus) { 716 protected void suggestRecentlyAddedTags(JPanel mainPanel, final FocusAdapter focus) { 717 final int tagsToShow = Math.max(PROPERTY_RECENT_TAGS_NUMBER.get(), MAX_LRU_TAGS_NUMBER); 694 718 if (!(tagsToShow > 0 && !recentTags.isEmpty())) 695 719 return; … … 816 840 String key = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString()); 817 841 String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString()); 818 if (key.isEmpty() || value.isEmpty()) return; 819 for (OsmPrimitive osm: sel) { 842 if (key.isEmpty() || value.isEmpty()) 843 return; 844 for (OsmPrimitive osm : sel) { 820 845 String val = osm.get(key); 821 846 if (val != null && !val.equals(value)) { … … 833 858 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value)); 834 859 changedKey = key; 860 clearEntries(); 861 } 862 863 protected void clearEntries() { 835 864 keys.getEditor().setItem(""); 836 865 values.getEditor().setItem("");
Note:
See TracChangeset
for help on using the changeset viewer.