Ticket #12281: 12281-v1-core.patch

File 12281-v1-core.patch, 8.4 KB (added by simon04, 10 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    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  
    8686 * Class that helps PropertiesDialog add and edit tag values.
    8787 * @since 5633
    8888 */
    89 class TagEditHelper {
     89public class TagEditHelper {
    9090    private final JTable tagTable;
    9191    private final DefaultTableModel tagData;
    9292    private final Map<String, Map<String, Integer>> valueCount;
    9393
    9494    // Selection that we are editing by using both dialogs
    95     private Collection<OsmPrimitive> sel;
     95    protected Collection<OsmPrimitive> sel;
    9696
    9797    private String changedKey;
    9898    private String objKey;
    protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) {  
    118118        }
    119119    };
    120120
    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) {
    122122        this.tagTable = tagTable;
    123123        this.tagData = propertyData;
    124124        this.valueCount = valueCount;
    public void addTag() {  
    142142        sel = Main.main.getInProgressSelection();
    143143        if (sel == null || sel.isEmpty()) return;
    144144
    145         final AddTagsDialog addDialog = new AddTagsDialog();
     145        final AddTagsDialog addDialog = getAddTagsDialog();
    146146
    147147        addDialog.showDialog();
    148148
    public void addTag() {  
    153153            addDialog.undoAllTagsAdding();
    154154    }
    155155
     156    protected AddTagsDialog getAddTagsDialog() {
     157        return new AddTagsDialog();
     158    }
     159
    156160    /**
    157161    * Edit the value in the tags table row.
    158162    * @param row The row of the table from which the value is edited.
    public void editTag(final int row, boolean focusOnKey) {  
    167171        String key = getDataKey(row);
    168172        objKey = key;
    169173
    170         final EditTagDialog editDialog = new EditTagDialog(key, getDataValues(row), focusOnKey);
     174        final IEditTagDialog editDialog = getEditTagDialog(row, focusOnKey, key);
    171175        editDialog.showDialog();
    172176        if (editDialog.getValue() != 1) return;
    173177        editDialog.performTagEdit();
    174178    }
    175179
     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
    176192    /**
    177193     * If during last editProperty call user changed the key name, this key will be returned
    178194     * Elsewhere, returns null.
    private static boolean warnOverwriteKey(String action, String togglePref) {  
    250266        return ed.getValue() == 1;
    251267    }
    252268
    253     public final class EditTagDialog extends AbstractTagsDialog {
     269    protected class EditTagDialog extends AbstractTagsDialog implements IEditTagDialog {
    254270        private final String key;
    255271        private final transient Map<String, Integer> m;
    256272
    public Component getListCellRendererComponent(JList<? extends AutoCompletionList  
    289305            }
    290306        };
    291307
    292         private EditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) {
     308        protected EditTagDialog(String key, Map<String, Integer> map, final boolean initialFocusOnKey) {
    293309            super(Main.parent, trn("Change value?", "Change values?", map.size()), new String[] {tr("OK"), tr("Cancel")});
    294310            setButtonIcons(new String[] {"ok", "cancel"});
    295311            setCancelButton(2);
    public void windowOpened(WindowEvent e) {  
    365381         * If value == "", tag will be deleted
    366382         * Confirmations may be needed.
    367383         */
    368         private void performTagEdit() {
     384        @Override
     385        public void performTagEdit() {
    369386            String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());
    370387            value = Normalizer.normalize(value, java.text.Normalizer.Form.NFC);
    371388            if (value.isEmpty()) {
    private void performTagEdit() {  
    429446    public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = new IntegerProperty("properties.recently-added-tags",
    430447            DEFAULT_LRU_TAGS_NUMBER);
    431448
    432     abstract class AbstractTagsDialog extends ExtendedDialog {
     449    protected abstract class AbstractTagsDialog extends ExtendedDialog {
    433450        protected AutoCompletingComboBox keys;
    434451        protected AutoCompletingComboBox values;
    435452        protected Component componentUnderMouse;
    public void actionPerformed(ActionEvent e) {  
    545562        };
    546563    }
    547564
    548     class AddTagsDialog extends AbstractTagsDialog {
     565    protected class AddTagsDialog extends AbstractTagsDialog {
    549566        private final List<JosmAction> recentTagsActions = new ArrayList<>();
     567        protected final FocusAdapter focus;
    550568
    551569        // Counter of added commands for possible undo
    552570        private int commandCount;
    553571
    554         AddTagsDialog() {
     572        protected AddTagsDialog() {
    555573            super(Main.parent, tr("Add value?"), new String[] {tr("OK"), tr("Cancel")});
    556574            setButtonIcons(new String[] {"ok", "cancel"});
    557575            setCancelButton(2);
    public void actionPerformed(ActionEvent e) {  
    603621                }
    604622            }
    605623
    606             FocusAdapter focus = addFocusAdapter(autocomplete, defaultACItemComparator);
     624            focus = addFocusAdapter(autocomplete, defaultACItemComparator);
    607625            // fire focus event in advance or otherwise the popup list will be too small at first
    608626            focus.focusGained(null);
    609627
    610             int recentTagsToShow = PROPERTY_RECENT_TAGS_NUMBER.get();
    611             if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) {
    612                 recentTagsToShow = MAX_LRU_TAGS_NUMBER;
    613             }
    614 
    615628            // Add tag on Shift-Enter
    616629            mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
    617630                        KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK), "addAndContinue");
    public void actionPerformed(ActionEvent e) {  
    623636                    }
    624637                });
    625638
    626             suggestRecentlyAddedTags(mainPanel, recentTagsToShow, focus);
     639            suggestRecentlyAddedTags(mainPanel, focus);
    627640
    628641            mainPanel.add(Box.createVerticalGlue(), GBC.eop().fill());
    629642            setContent(mainPanel, false);
    public void setContentPane(Container contentPane) {  
    673686            super.setContentPane(contentPane);
    674687        }
    675688
    676         private void selectNumberOfTags() {
     689        protected void selectNumberOfTags() {
    677690            String s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display"));
    678691            if (s == null) {
    679692                return;
    private void selectNumberOfTags() {  
    690703            JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER));
    691704        }
    692705
    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);
    694708            if (!(tagsToShow > 0 && !recentTags.isEmpty()))
    695709                return;
    696710
    public final void performTagAdding() {  
    816830            String key = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString());
    817831            String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString());
    818832            if (key.isEmpty() || value.isEmpty()) return;
    819             for (OsmPrimitive osm: sel) {
     833            for (OsmPrimitive osm : sel) {
    820834                String val = osm.get(key);
    821835                if (val != null && !val.equals(value)) {
    822836                    if (!warnOverwriteKey(tr("You changed the value of ''{0}'' from ''{1}'' to ''{2}''.", key, val, value),
    public final void performTagAdding() {  
    832846            commandCount++;
    833847            Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
    834848            changedKey = key;
     849            clearEntries();
     850        }
     851
     852        protected void clearEntries() {
    835853            keys.getEditor().setItem("");
    836854            values.getEditor().setItem("");
    837855        }