Changeset 7679 in josm for trunk/src/org


Ignore:
Timestamp:
2014-10-30T20:23:04+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #10498 - Remote Control applies tags incorrectly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/AddTagsDialog.java

    r7539 r7679  
    3131import org.openstreetmap.josm.Main;
    3232import org.openstreetmap.josm.command.ChangePropertyCommand;
    33 import org.openstreetmap.josm.data.SelectionChangedListener;
    34 import org.openstreetmap.josm.data.osm.DataSet;
    3533import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3634import org.openstreetmap.josm.gui.ExtendedDialog;
     
    4038
    4139/**
    42  *
    43  * @author master
    44  *
    45  * Dialog to add tags as part of the remotecontrol
     40 * Dialog to add tags as part of the remotecontrol.
    4641 * Existing Keys get grey color and unchecked selectboxes so they will not overwrite the old Key-Value-Pairs by default.
    4742 * You can choose the tags you want to add by selectboxes. You can edit the tags before you apply them.
    48  *
     43 * @author master
     44 * @since 3850
    4945 */
    50 public class AddTagsDialog extends ExtendedDialog implements SelectionChangedListener {
    51 
    52 
    53     /** initially given tags  **/
    54     String[][] tags;
     46public class AddTagsDialog extends ExtendedDialog {
    5547
    5648    private final JTable propertyTable;
    57     private Collection<? extends OsmPrimitive> sel;
    58     int[] count;
    59 
    60     String sender;
    61     static Set<String> trustedSenders = new HashSet<>();
     49    private final Collection<? extends OsmPrimitive> sel;
     50    private final int[] count;
     51
     52    private final String sender;
     53    private static final Set<String> trustedSenders = new HashSet<>();
    6254
    6355    /**
     
    122114    }
    123115
    124     public AddTagsDialog(String[][] tags, String senderName) {
     116    /**
     117     * Constructs a new {@code AddTagsDialog}.
     118     */
     119    public AddTagsDialog(String[][] tags, String senderName, Collection<? extends OsmPrimitive> primitives) {
    125120        super(Main.parent, tr("Add tags to selected objects"), new String[] { tr("Add selected tags"), tr("Add all tags"),  tr("Cancel")},
    126121                false,
     
    129124
    130125        this.sender = senderName;
    131 
    132         DataSet.addSelectionListener(this);
    133 
    134126
    135127        final DefaultTableModel tm = new DefaultTableModel(new String[] {tr("Assume"), tr("Key"), tr("Value"), tr("Existing values")}, tags.length) {
     
    141133        };
    142134
    143         sel = Main.main.getCurrentDataSet().getSelected();
     135        sel = primitives;
    144136        count = new int[tags.length];
    145137
     
    168160        propertyTable = new JTable(tm) {
    169161
    170             private static final long serialVersionUID = 1L;
    171 
    172162            @Override
    173163            public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
     
    200190                return tr("Enable the checkbox to accept the value");
    201191            }
    202 
    203192        };
    204193
     
    240229
    241230    /**
    242      * This method looks for existing tags in the current selection and sets the corresponding boolean in the boolean array existing[]
    243      */
    244     private void findExistingTags() {
    245         TableModel tm = propertyTable.getModel();
    246         for (int i=0; i<tm.getRowCount(); i++) {
    247             String key = (String)tm.getValueAt(i, 1);
    248             String value = (String)tm.getValueAt(i, 1);
    249             count[i] = 0;
    250             for (OsmPrimitive osm : sel) {
    251                 if (osm.keySet().contains(key) && !osm.get(key).equals(value)) {
    252                     count[i]++;
    253                     break;
    254                 }
    255             }
    256         }
    257         propertyTable.repaint();
    258     }
    259 
    260     /**
    261231     * If you click the "Add tags" button build a ChangePropertyCommand for every key that has a checked checkbox to apply the key value pair to all selected osm objects.
    262232     * You get a entry for every key in the command queue.
     
    280250        }
    281251        setVisible(false);
    282     }
    283 
    284     @Override
    285     public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    286         sel = newSelection;
    287         findExistingTags();
    288252    }
    289253
     
    323287                    }
    324288                }
    325 
    326 
    327289            });
    328290        }
     
    332294     * Ask user and add the tags he confirm.
    333295     * @param keyValue is a table or {{tag1,val1},{tag2,val2},...}
    334      * @param sender is a string for skipping confirmations. Use epmty string for always confirmed adding.
     296     * @param sender is a string for skipping confirmations. Use empty string for always confirmed adding.
    335297     * @param primitives OSM objects that will be modified
    336298     * @since 7521
     
    344306            }
    345307        } else {
    346             new AddTagsDialog(keyValue, sender).showDialog();
     308            new AddTagsDialog(keyValue, sender, primitives).showDialog();
    347309        }
    348310    }
Note: See TracChangeset for help on using the changeset viewer.