diff --git a/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java b/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
index 6901fed..e3b3ae5 100644
|
a
|
b
|
|
| 86 | 86 | * Class that helps PropertiesDialog add and edit tag values. |
| 87 | 87 | * @since 5633 |
| 88 | 88 | */ |
| 89 | | class TagEditHelper { |
| | 89 | public class TagEditHelper { |
| 90 | 90 | private final JTable tagTable; |
| 91 | 91 | private final DefaultTableModel tagData; |
| 92 | 92 | private final Map<String, Map<String, Integer>> valueCount; |
| 93 | 93 | |
| 94 | 94 | // Selection that we are editing by using both dialogs |
| 95 | | private Collection<OsmPrimitive> sel; |
| | 95 | protected Collection<OsmPrimitive> sel; |
| 96 | 96 | |
| 97 | 97 | private String changedKey; |
| 98 | 98 | private String objKey; |
| … |
… |
protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) {
|
| 118 | 118 | } |
| 119 | 119 | }; |
| 120 | 120 | |
| 121 | | TagEditHelper(JTable tagTable, DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) { |
| | 121 | public TagEditHelper(JTable tagTable, DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) { |
| 122 | 122 | this.tagTable = tagTable; |
| 123 | 123 | this.tagData = propertyData; |
| 124 | 124 | this.valueCount = valueCount; |
| … |
… |
public void addTag() {
|
| 142 | 142 | sel = Main.main.getInProgressSelection(); |
| 143 | 143 | if (sel == null || sel.isEmpty()) return; |
| 144 | 144 | |
| 145 | | final AddTagsDialog addDialog = new AddTagsDialog(); |
| | 145 | final AddTagsDialog addDialog = getAddTagsDialog(); |
| 146 | 146 | |
| 147 | 147 | addDialog.showDialog(); |
| 148 | 148 | |
| … |
… |
public void addTag() {
|
| 153 | 153 | addDialog.undoAllTagsAdding(); |
| 154 | 154 | } |
| 155 | 155 | |
| | 156 | protected AddTagsDialog getAddTagsDialog() { |
| | 157 | return new AddTagsDialog(); |
| | 158 | } |
| | 159 | |
| 156 | 160 | /** |
| 157 | 161 | * Edit the value in the tags table row. |
| 158 | 162 | * @param row The row of the table from which the value is edited. |
| … |
… |
public void editTag(final int row, boolean focusOnKey) {
|
| 167 | 171 | String key = getDataKey(row); |
| 168 | 172 | objKey = key; |
| 169 | 173 | |
| 170 | | final EditTagDialog editDialog = new EditTagDialog(key, getDataValues(row), focusOnKey); |
| | 174 | final IEditTagDialog editDialog = getEditTagDialog(row, focusOnKey, key); |
| 171 | 175 | editDialog.showDialog(); |
| 172 | 176 | if (editDialog.getValue() != 1) return; |
| 173 | 177 | editDialog.performTagEdit(); |
| 174 | 178 | } |
| 175 | 179 | |
| | 180 | protected interface IEditTagDialog { |
| | 181 | ExtendedDialog showDialog(); |
| | 182 | |
| | 183 | int getValue(); |
| | 184 | |
| | 185 | void performTagEdit(); |
| | 186 | } |
| | 187 | |
| | 188 | protected IEditTagDialog getEditTagDialog(int row, boolean focusOnKey, String key) { |
| | 189 | return new EditTagDialog(key, getDataValues(row), focusOnKey); |
| | 190 | } |
| | 191 | |
| 176 | 192 | /** |
| 177 | 193 | * If during last editProperty call user changed the key name, this key will be returned |
| 178 | 194 | * Elsewhere, returns null. |
| … |
… |
private static boolean warnOverwriteKey(String action, String togglePref) {
|
| 250 | 266 | return ed.getValue() == 1; |
| 251 | 267 | } |
| 252 | 268 | |
| 253 | | public final class EditTagDialog extends AbstractTagsDialog { |
| | 269 | protected class EditTagDialog extends AbstractTagsDialog implements IEditTagDialog { |
| 254 | 270 | private final String key; |
| 255 | 271 | private final transient Map<String, Integer> m; |
| 256 | 272 | |
| … |
… |
public Component getListCellRendererComponent(JList<? extends AutoCompletionList
|
| 289 | 305 | } |
| 290 | 306 | }; |
| 291 | 307 | |
| 292 | | private EditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) { |
| | 308 | protected EditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) { |
| 293 | 309 | super(Main.parent, trn("Change value?", "Change values?", map.size()), new String[] {tr("OK"), tr("Cancel")}); |
| 294 | 310 | setButtonIcons(new String[] {"ok", "cancel"}); |
| 295 | 311 | setCancelButton(2); |
| … |
… |
public void windowOpened(WindowEvent e) {
|
| 365 | 381 | * If value == "", tag will be deleted |
| 366 | 382 | * Confirmations may be needed. |
| 367 | 383 | */ |
| 368 | | private void performTagEdit() { |
| | 384 | @Override |
| | 385 | public void performTagEdit() { |
| 369 | 386 | String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString()); |
| 370 | 387 | value = Normalizer.normalize(value, java.text.Normalizer.Form.NFC); |
| 371 | 388 | if (value.isEmpty()) { |
| … |
… |
private void performTagEdit() {
|
| 429 | 446 | public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags", |
| 430 | 447 | DEFAULT_LRU_TAGS_NUMBER); |
| 431 | 448 | |
| 432 | | abstract class AbstractTagsDialog extends ExtendedDialog { |
| | 449 | protected abstract class AbstractTagsDialog extends ExtendedDialog { |
| 433 | 450 | protected AutoCompletingComboBox keys; |
| 434 | 451 | protected AutoCompletingComboBox values; |
| 435 | 452 | protected Component componentUnderMouse; |
| … |
… |
public void actionPerformed(ActionEvent e) {
|
| 545 | 562 | }; |
| 546 | 563 | } |
| 547 | 564 | |
| 548 | | class AddTagsDialog extends AbstractTagsDialog { |
| | 565 | protected class AddTagsDialog extends AbstractTagsDialog { |
| 549 | 566 | private final List<JosmAction> recentTagsActions = new ArrayList<>(); |
| | 567 | protected final FocusAdapter focus; |
| 550 | 568 | |
| 551 | 569 | // Counter of added commands for possible undo |
| 552 | 570 | private int commandCount; |
| 553 | 571 | |
| 554 | | AddTagsDialog() { |
| | 572 | protected AddTagsDialog() { |
| 555 | 573 | super(Main.parent, tr("Add value?"), new String[] {tr("OK"), tr("Cancel")}); |
| 556 | 574 | setButtonIcons(new String[] {"ok", "cancel"}); |
| 557 | 575 | setCancelButton(2); |
| … |
… |
public void actionPerformed(ActionEvent e) {
|
| 603 | 621 | } |
| 604 | 622 | } |
| 605 | 623 | |
| 606 | | FocusAdapter focus = addFocusAdapter(autocomplete, defaultACItemComparator); |
| | 624 | focus = addFocusAdapter(autocomplete, defaultACItemComparator); |
| 607 | 625 | // fire focus event in advance or otherwise the popup list will be too small at first |
| 608 | 626 | focus.focusGained(null); |
| 609 | 627 | |
| 610 | | int recentTagsToShow = PROPERTY_RECENT_TAGS_NUMBER.get(); |
| 611 | | if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) { |
| 612 | | recentTagsToShow = MAX_LRU_TAGS_NUMBER; |
| 613 | | } |
| 614 | | |
| 615 | 628 | // Add tag on Shift-Enter |
| 616 | 629 | mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( |
| 617 | 630 | KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK), "addAndContinue"); |
| … |
… |
public void actionPerformed(ActionEvent e) {
|
| 623 | 636 | } |
| 624 | 637 | }); |
| 625 | 638 | |
| 626 | | suggestRecentlyAddedTags(mainPanel, recentTagsToShow, focus); |
| | 639 | suggestRecentlyAddedTags(mainPanel, focus); |
| 627 | 640 | |
| 628 | 641 | mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill()); |
| 629 | 642 | setContent(mainPanel, false); |
| … |
… |
public void setContentPane(Container contentPane) {
|
| 673 | 686 | super.setContentPane(contentPane); |
| 674 | 687 | } |
| 675 | 688 | |
| 676 | | private void selectNumberOfTags() { |
| | 689 | protected void selectNumberOfTags() { |
| 677 | 690 | String s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display")); |
| 678 | 691 | if (s == null) { |
| 679 | 692 | return; |
| … |
… |
private void selectNumberOfTags() {
|
| 690 | 703 | JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER)); |
| 691 | 704 | } |
| 692 | 705 | |
| 693 | | private void suggestRecentlyAddedTags(JPanel mainPanel, int tagsToShow, final FocusAdapter focus) { |
| | 706 | protected void suggestRecentlyAddedTags(JPanel mainPanel, final FocusAdapter focus) { |
| | 707 | final int tagsToShow = Math.max(PROPERTY_RECENT_TAGS_NUMBER.get(), MAX_LRU_TAGS_NUMBER); |
| 694 | 708 | if (!(tagsToShow > 0 && !recentTags.isEmpty())) |
| 695 | 709 | return; |
| 696 | 710 | |
| … |
… |
public final void performTagAdding() {
|
| 816 | 830 | String key = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString()); |
| 817 | 831 | String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString()); |
| 818 | 832 | if (key.isEmpty() || value.isEmpty()) return; |
| 819 | | for (OsmPrimitive osm: sel) { |
| | 833 | for (OsmPrimitive osm : sel) { |
| 820 | 834 | String val = osm.get(key); |
| 821 | 835 | if (val != null && !val.equals(value)) { |
| 822 | 836 | if (!warnOverwriteKey(tr("You changed the value of ''{0}'' from ''{1}'' to ''{2}''.", key, val, value), |
| … |
… |
public final void performTagAdding() {
|
| 832 | 846 | commandCount++; |
| 833 | 847 | Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value)); |
| 834 | 848 | changedKey = key; |
| | 849 | clearEntries(); |
| | 850 | } |
| | 851 | |
| | 852 | protected void clearEntries() { |
| 835 | 853 | keys.getEditor().setItem(""); |
| 836 | 854 | values.getEditor().setItem(""); |
| 837 | 855 | } |