Changeset 1101 in josm for trunk/src/org


Ignore:
Timestamp:
2008-12-03T00:26:37+01:00 (15 years ago)
Author:
framm
Message:

fix tag corrector to allow the swapping of keys between two tags. fixes #1812.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/ChangePropertyCommand.java

    r965 r1101  
    5151                        for (OsmPrimitive osm : objects) {
    5252                                String val = osm.get(key);
    53                                 if(val == null || !value.equals(val))
    54                                 {
     53                                if (val == null || !value.equals(val)) {
    5554                                        this.objects.add(osm);
    5655                                }
  • trunk/src/org/openstreetmap/josm/corrector/TagCorrector.java

    r1000 r1101  
    99import java.util.Collections;
    1010import java.util.HashMap;
     11import java.util.HashSet;
    1112import java.util.List;
    1213import java.util.Map;
     14import java.util.Set;
    1315
    1416import javax.swing.JLabel;
     
    2123import org.openstreetmap.josm.command.ChangePropertyCommand;
    2224import org.openstreetmap.josm.command.Command;
     25import org.openstreetmap.josm.data.osm.Node;
    2326import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2427import org.openstreetmap.josm.data.osm.Relation;
    2528import org.openstreetmap.josm.data.osm.RelationMember;
     29import org.openstreetmap.josm.data.osm.Way;
    2630import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
     31import org.openstreetmap.josm.data.osm.visitor.Visitor;
    2732import org.openstreetmap.josm.gui.JMultilineLabel;
    2833import org.openstreetmap.josm.tools.GBC;
     
    114119
    115120                                final JLabel rolesLabel = new JLabel(
    116                                         tr("Roles in relations refering to"));
     121                                        tr("Roles in relations referring to"));
    117122                                p.add(rolesLabel, GBC.std());
    118123
     
    136141                        if (answer == JOptionPane.YES_OPTION) {
    137142                                for (OsmPrimitive primitive : tagCorrectionsMap.keySet()) {
    138                                         List<TagCorrection> tagCorrections = tagCorrectionsMap
    139                                                 .get(primitive);
     143                                        List<TagCorrection> tagCorrections =
     144                        tagCorrectionsMap.get(primitive);
     145                   
     146                    // create the clone
     147                    OsmPrimitive clone = null;
     148                    if (primitive instanceof Way) clone = new Way((Way)primitive);
     149                    else if (primitive instanceof Node) clone = new Node((Node)primitive);
     150                    else if (primitive instanceof Relation) clone = new Relation((Relation)primitive);
     151                   
     152                    // use this structure to remember keys that have been set already so that
     153                    // they're not dropped by a later step
     154                    Set<String> keysChanged = new HashSet<String>();
     155                   
     156                    // apply all changes to this clone
    140157                                        for (int i = 0; i < tagCorrections.size(); i++) {
    141                                                 if (tagTableMap.get(primitive)
    142                                                         .getCorrectionTableModel().getApply(i)) {
     158                                                if (tagTableMap.get(primitive).getCorrectionTableModel().getApply(i)) {
    143159                                                        TagCorrection tagCorrection = tagCorrections.get(i);
    144                                                         if (tagCorrection.isKeyChanged())
    145                                                                 commands.add(new ChangePropertyCommand(
    146                                                                         primitive, tagCorrection.oldKey, null));
    147                                                         commands.add(new ChangePropertyCommand(primitive,
    148                                                                 tagCorrection.newKey,
    149                                                                 tagCorrection.newValue));
     160                                                        if (tagCorrection.isKeyChanged() && !keysChanged.contains(tagCorrection.oldKey)) clone.remove(tagCorrection.oldKey);
     161                                                        clone.put(tagCorrection.newKey, tagCorrection.newValue);
     162                                                        keysChanged.add(tagCorrection.newKey);
    150163                                                }
    151164                                        }
     165                   
     166                    // save the clone
     167                    if (!keysChanged.isEmpty()) commands.add(new ChangeCommand(primitive, clone));
    152168                                }
    153169                                for (OsmPrimitive primitive : roleCorrectionMap.keySet()) {
Note: See TracChangeset for help on using the changeset viewer.