Ignore:
Timestamp:
2009-10-31T21:14:07+01:00 (15 years ago)
Author:
miken
Message:

Address Interpolation Plugin: Update to use undoRedo to manipulate objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationDialog.java

    r18398 r18399  
    2424import java.awt.event.WindowEvent;
    2525import java.util.ArrayList;
     26import java.util.Collection;
     27import java.util.LinkedList;
    2628import java.util.regex.Pattern;
    2729
     
    4042
    4143import org.openstreetmap.josm.Main;
     44import org.openstreetmap.josm.command.AddCommand;
     45import org.openstreetmap.josm.command.ChangeCommand;
     46import org.openstreetmap.josm.command.ChangePropertyCommand;
     47import org.openstreetmap.josm.command.Command;
     48import org.openstreetmap.josm.command.SequenceCommand;
    4249import org.openstreetmap.josm.data.osm.DataSet;
    4350import org.openstreetmap.josm.data.osm.Node;
     
    9299        private JComboBox addrInterpolationList = null;
    93100
     101        // For tracking edit changes as group for undo
     102        private Collection<Command> commandGroup = null;
     103        private Relation editedRelation = null;
    94104
    95105        public AddrInterpolationDialog(String name) {
     
    744754
    745755                // Entries are valid ... save in map
     756
     757                commandGroup = new LinkedList<Command>();
     758
    746759                String streetName = selectedStreet.get("name");
    747760
    748761                if (addrInterpolationWay != null) {
    749                         addrInterpolationWay.setModified(true);
    750762
    751763                        Node firstNode = addrInterpolationWay.getNode(0);
    752764                        Node lastNode = addrInterpolationWay.getNode(addrInterpolationWay.getNodesCount()-1);
    753765
    754                         addrInterpolationWay.put("addr:interpolation", selectedMethod);
    755                         firstNode.put("addr:housenumber", startValueString);
    756                         lastNode.put("addr:housenumber", endValueString);
     766                        commandGroup.add(new ChangePropertyCommand(addrInterpolationWay, "addr:interpolation", selectedMethod));
     767                        commandGroup.add(new ChangePropertyCommand(firstNode, "addr:housenumber", startValueString));
     768                        commandGroup.add(new ChangePropertyCommand(lastNode, "addr:housenumber", endValueString));
    757769                        if (streetNameButton.isSelected()) {
    758770
    759                                 firstNode.put("addr:street", streetName);
    760                                 lastNode.put("addr:street", streetName);
     771                                commandGroup.add(new ChangePropertyCommand(firstNode, "addr:street", streetName));
     772                                commandGroup.add(new ChangePropertyCommand(lastNode, "addr:street", streetName));
    761773
    762774                        }
     
    779791                        if (associatedStreetRelation == null) {
    780792                                CreateRelation(streetName);
    781                                 relationChanged = true;
    782                         }
    783 
     793                                // relationChanged = true;   (not changed since it was created)
     794                        }
     795                        // Make any additional changes only to the copy
     796                        editedRelation = new Relation(associatedStreetRelation);
    784797
    785798                        if (addrInterpolationWay != null) {
     
    793806                for (Node node : houseNumberNodes) {
    794807
    795                         node.setModified(true); // Trigger re-upload in case there is a change
    796 
    797808                        if (streetRelationButton.isSelected()) {
    798809                                AddToRelation(associatedStreetRelation, node, "house");
     
    800811                        if ((city != null) || (streetNameButton.isSelected()) ) {
    801812                                // Include street unconditionally if adding nodes only or city name specified
    802                                 node.put("addr:street", streetName);
     813                                commandGroup.add(new ChangePropertyCommand(node, "addr:street", streetName));
    803814                        }
    804815                        // Set or remove remaining optional fields
    805                         node.put("addr:city", city);
    806                         node.put("addr:state", state);
    807                         node.put("addr:postcode", postCode);
    808                         node.put("addr:country", country);
    809                         node.put("addr:full", fullAddress);
     816                        commandGroup.add(new ChangePropertyCommand(node, "addr:city", city));
     817                        commandGroup.add(new ChangePropertyCommand(node, "addr:state", state));
     818                        commandGroup.add(new ChangePropertyCommand(node, "addr:postcode", postCode));
     819                        commandGroup.add(new ChangePropertyCommand(node, "addr:country", country));
     820                        commandGroup.add(new ChangePropertyCommand(node, "addr:full", fullAddress));
    810821                }
    811822
    812823                if (relationChanged) {
    813                         associatedStreetRelation.setModified(true);
    814 
    815                         // Redraw relation list dialog
    816                         Main.main.getEditLayer().fireDataChange();
    817                 }
    818 
    819 
    820                 Main.map.mapView.repaint();
     824                        commandGroup.add(new ChangeCommand(associatedStreetRelation, editedRelation));
     825                }
     826
     827
     828                Main.main.undoRedo.add(new SequenceCommand(tr("Address Interpolation"), commandGroup));
     829                Main.map.repaint();
    821830
    822831                return true;
    823832        }
    824833
    825         // Create Associated Street relation, add street, and add to map
     834        // Create Associated Street relation, add street, and add to list of commands to perform
    826835        private void CreateRelation(String streetName) {
    827836                associatedStreetRelation = new Relation();
     
    830839                RelationMember newStreetMember = new RelationMember("street", selectedStreet);
    831840                associatedStreetRelation.addMember(newStreetMember);
    832                 Main.main.getCurrentDataSet().addPrimitive(associatedStreetRelation);
     841                commandGroup.add(new AddCommand(associatedStreetRelation));
    833842        }
    834843
     
    863872                if (!isFound) {
    864873                        RelationMember newMember = new RelationMember(role, testMember);
    865                         associatedStreetRelation.addMember(newMember);
     874                        editedRelation.addMember(newMember);
     875
    866876                        relationChanged = true;
    867877                }
Note: See TracChangeset for help on using the changeset viewer.