Changeset 29625 in osm for applications/editors


Ignore:
Timestamp:
2013-06-06T02:15:21+02:00 (12 years ago)
Author:
donvip
Message:

[josm_measurement] fix #josm8752 - measurements aren't updated when rescaling ways

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementDialog.java

    r29579 r29625  
    1515import javax.swing.JPanel;
    1616
     17import org.openstreetmap.josm.Main;
    1718import org.openstreetmap.josm.data.SelectionChangedListener;
    1819import org.openstreetmap.josm.data.osm.DataSet;
     
    2021import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2122import org.openstreetmap.josm.data.osm.Way;
     23import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
     24import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
     25import org.openstreetmap.josm.data.osm.event.DataSetListener;
     26import org.openstreetmap.josm.data.osm.event.NodeMovedEvent;
     27import org.openstreetmap.josm.data.osm.event.PrimitivesAddedEvent;
     28import org.openstreetmap.josm.data.osm.event.PrimitivesRemovedEvent;
     29import org.openstreetmap.josm.data.osm.event.RelationMembersChangedEvent;
     30import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
     31import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    2232import org.openstreetmap.josm.gui.NavigatableComponent;
    2333import org.openstreetmap.josm.gui.SideButton;
     
    3444 * @author ramack
    3545 */
    36 public class MeasurementDialog extends ToggleDialog implements SelectionChangedListener {
     46public class MeasurementDialog extends ToggleDialog implements SelectionChangedListener, DataSetListener {
    3747    private static final long serialVersionUID = 4708541586297950021L;
    3848
     
    6171     */
    6272    protected JLabel segAngleLabel;
     73   
     74    private DataSet ds;
     75
     76    private Collection<Way> ways;
     77    private Collection<Node> nodes;
    6378   
    6479    /**
     
    119134
    120135    /**
    121      * Cleans the active Meausurement Layer
     136     * Cleans the active Measurement Layer
    122137     */
    123138    public void resetValues(){
     
    132147        Node lastNode = null;
    133148        // Don't mix up way and nodes computation (fix #6872). Priority given to ways
    134         SubclassFilteredCollection<OsmPrimitive, Way> ways = new SubclassFilteredCollection<OsmPrimitive, Way>(newSelection, OsmPrimitive.wayPredicate);
     149        ways = new SubclassFilteredCollection<OsmPrimitive, Way>(newSelection, OsmPrimitive.wayPredicate);
    135150        if (ways.isEmpty()) {
    136             for (Node n : new SubclassFilteredCollection<OsmPrimitive, Node>(newSelection, OsmPrimitive.nodePredicate)) {
     151            nodes = new SubclassFilteredCollection<OsmPrimitive, Node>(newSelection, OsmPrimitive.nodePredicate);
     152            for (Node n : nodes) {
    137153                if (n.getCoor() != null) {
    138154                    if (lastNode == null) {
     
    146162            }
    147163        } else {
     164            nodes = null;
    148165            for (Way w : ways) {
    149166                Node lastN = null;
     
    179196            }
    180197        });
     198       
     199        DataSet currentDs = Main.main.getCurrentDataSet();
     200   
     201        if (ds != currentDs) {
     202            if (ds != null) {
     203                ds.removeDataSetListener(this);
     204            }
     205            if (currentDs != null) {
     206                currentDs.addDataSetListener(this);
     207            }
     208            ds = currentDs;
     209        }
    181210        }
    182211
     
    188217                super.destroy();
    189218                DataSet.removeSelectionListener(this);
     219                if (ds != null) {
     220                    ds.removeDataSetListener(this);
     221                    ds = null;
     222                }
    190223        }
     224
     225        private boolean waysContain(Node n) {
     226            if (ways != null) {
     227                for (Way w : ways) {
     228                    if (w.containsNode(n)) {
     229                        return true;
     230                    }
     231                }
     232            }
     233            return false;
     234        }
     235       
     236    @Override public void nodeMoved(NodeMovedEvent event) {
     237        Node n = event.getNode();
     238        // Refresh selection if a node belonging to a selected member has moved (example: scale action)
     239        if ((nodes != null && nodes.contains(n)) || waysContain(n)) {
     240            selectionChanged(Main.main.getCurrentDataSet().getSelected());
     241        }
     242    }
     243
     244    @Override public void primitivesAdded(PrimitivesAddedEvent event) {}
     245    @Override public void primitivesRemoved(PrimitivesRemovedEvent event) {}
     246    @Override public void tagsChanged(TagsChangedEvent event) {}
     247    @Override public void wayNodesChanged(WayNodesChangedEvent event) { }
     248    @Override public void relationMembersChanged(RelationMembersChangedEvent event) {}
     249    @Override public void otherDatasetChange(AbstractDatasetChangedEvent event) {}
     250    @Override public void dataChanged(DataChangedEvent event) {}
    191251}
Note: See TracChangeset for help on using the changeset viewer.