Ignore:
Timestamp:
2017-11-02T20:03:28+01:00 (7 years ago)
Author:
donvip
Message:

fix #josm15510 (refresh dialog when way nodes change) + update to JOSM 12636

Location:
applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement
Files:
4 edited

Legend:

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

    r32936 r33760  
    1616import javax.swing.JPanel;
    1717
    18 import org.openstreetmap.josm.Main;
    1918import org.openstreetmap.josm.data.SelectionChangedListener;
    2019import org.openstreetmap.josm.data.SystemOfMeasurement;
     
    3332import org.openstreetmap.josm.data.osm.event.TagsChangedEvent;
    3433import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
     34import org.openstreetmap.josm.gui.MainApplication;
    3535import org.openstreetmap.josm.gui.SideButton;
    3636import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
     
    171171    @Override
    172172    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     173        refresh(newSelection);
     174    }
     175
     176    private void refresh(Collection<? extends OsmPrimitive> selection) {
    173177        double length = 0.0;
    174178        double segAngle = 0.0;
     
    177181        Node lastNode = null;
    178182        // Don't mix up way and nodes computation (fix #6872). Priority given to ways
    179         ways = new SubclassFilteredCollection<>(newSelection, Way.class::isInstance);
     183        ways = new SubclassFilteredCollection<>(selection, Way.class::isInstance);
    180184        if (ways.isEmpty()) {
    181             nodes = new SubclassFilteredCollection<>(newSelection, Node.class::isInstance);
     185            nodes = new SubclassFilteredCollection<>(selection, Node.class::isInstance);
    182186            for (Node n : nodes) {
    183187                if (n.getCoor() != null) {
     
    241245        });
    242246
    243         DataSet currentDs = Main.getLayerManager().getEditDataSet();
     247        DataSet currentDs = MainApplication.getLayerManager().getEditDataSet();
    244248
    245249        if (ds != currentDs) {
     
    280284        // Refresh selection if a node belonging to a selected member has moved (example: scale action)
    281285        if ((nodes != null && nodes.contains(n)) || waysContain(n)) {
    282             selectionChanged(Main.getLayerManager().getEditDataSet().getSelected());
     286            refresh(event.getDataset().getSelected());
     287        }
     288    }
     289
     290    @Override public void wayNodesChanged(WayNodesChangedEvent event) {
     291        if (ways.contains(event.getChangedWay())) {
     292            refresh(event.getDataset().getSelected());
    283293        }
    284294    }
     
    287297    @Override public void primitivesRemoved(PrimitivesRemovedEvent event) {}
    288298    @Override public void tagsChanged(TagsChangedEvent event) {}
    289     @Override public void wayNodesChanged(WayNodesChangedEvent event) { }
    290299    @Override public void relationMembersChanged(RelationMembersChangedEvent event) {}
    291300    @Override public void otherDatasetChange(AbstractDatasetChangedEvent event) {}
     
    295304    public void systemOfMeasurementChanged(String oldSoM, String newSoM) {
    296305        // Refresh selection to take into account new system of measurement
    297         DataSet currentDs = Main.getLayerManager().getEditDataSet();
     306        DataSet currentDs = MainApplication.getLayerManager().getEditDataSet();
    298307        if (currentDs != null) {
    299             selectionChanged(currentDs.getSelected());
     308            refresh(currentDs.getSelected());
    300309        }
    301310    }
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementLayer.java

    r32324 r33760  
    3434import org.openstreetmap.josm.data.gpx.WayPoint;
    3535import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     36import org.openstreetmap.josm.gui.MainApplication;
    3637import org.openstreetmap.josm.gui.MapView;
    3738import org.openstreetmap.josm.gui.NavigatableComponent;
     
    115116        if(l != null) points.remove(l);
    116117        recalculate();
    117         Main.map.repaint();
    118118    }
    119119
     
    121121        if (e.getButton() != MouseEvent.BUTTON1) return;
    122122
    123         LatLon coor = Main.map.mapView.getLatLon(e.getX(), e.getY());
     123        LatLon coor = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY());
    124124        points.add(new WayPoint(coor));
    125125
    126         Main.map.repaint();
    127126        recalculate();
    128127    }
     
    131130        points.clear();
    132131        recalculate();
    133         Main.map.repaint();
    134132    }
    135133
     
    149147            MeasurementPlugin.measurementDialog.pathLengthLabel.setText(NavigatableComponent.getDistText(pathLength));
    150148        }
    151         if (Main.map.mapMode instanceof MeasurementMode) {
    152             Main.map.statusLine.setDist(pathLength);
    153         }
     149        if (MainApplication.getMap().mapMode instanceof MeasurementMode) {
     150            MainApplication.getMap().statusLine.setDist(pathLength);
     151        }
     152        invalidate();
    154153    }
    155154
     
    234233            Box panel = Box.createVerticalBox();
    235234            final JList<GpxLayer> layerList = new JList<>(model);
    236             Collection<Layer> data = Main.getLayerManager().getLayers();
     235            Collection<Layer> data = MainApplication.getLayerManager().getLayers();
    237236            Layer lastLayer = null;
    238237            int layerCnt = 0;
     
    295294                }
    296295                recalculate();
    297                 Main.parent.repaint();
    298296            } else{
    299297                // TODO: register a listener and show menu entry only if gps layers are available
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementMode.java

    r30641 r33760  
    1212import org.openstreetmap.josm.actions.mapmode.MapMode;
    1313import org.openstreetmap.josm.data.coor.LatLon;
    14 import org.openstreetmap.josm.gui.MapFrame;
     14import org.openstreetmap.josm.gui.MainApplication;
    1515
    1616public class MeasurementMode extends MapMode {
    1717
    1818    private static final long serialVersionUID = 3853830673475744263L;
    19    
    20     public MeasurementMode(MapFrame mapFrame, String name, String desc) {
    21         super(name, "measurement.png", desc, mapFrame, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
     19
     20    public MeasurementMode(String name, String desc) {
     21        super(name, "measurement.png", desc, Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
    2222    }
    2323
     
    2525    public void enterMode() {
    2626        super.enterMode();
    27         Main.map.mapView.addMouseListener(this);
     27        MainApplication.getMap().mapView.addMouseListener(this);
    2828    }
    2929
     
    3131    public void exitMode() {
    3232        super.exitMode();
    33         Main.map.mapView.removeMouseListener(this);
     33        MainApplication.getMap().mapView.removeMouseListener(this);
    3434    }
    3535
     
    4747            MeasurementPlugin.getCurrentLayer().removeLastPoint();
    4848        } else if (e.getButton() == MouseEvent.BUTTON1){
    49             LatLon coor = Main.map.mapView.getLatLon(e.getX(), e.getY());
     49            LatLon coor = MainApplication.getMap().mapView.getLatLon(e.getX(), e.getY());
    5050            if (coor.isOutSideWorld()) {
    5151                JOptionPane.showMessageDialog(Main.parent,tr("Can not draw outside of the world."));
  • applications/editors/josm/plugins/measurement/src/org/openstreetmap/josm/plugins/measurement/MeasurementPlugin.java

    r32454 r33760  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.gui.IconToggleButton;
     7import org.openstreetmap.josm.gui.MainApplication;
    88import org.openstreetmap.josm.gui.MapFrame;
    99import org.openstreetmap.josm.gui.layer.Layer;
     
    3232        if (newFrame != null) {
    3333            newFrame.addToggleDialog(measurementDialog = new MeasurementDialog());
    34             mode = new MeasurementMode(newFrame, "measurement", tr("measurement mode"));
     34            mode = new MeasurementMode("measurement", tr("measurement mode"));
    3535            btn = new IconToggleButton(mode);
    3636            btn.setVisible(true);
     
    4646        if (currentLayer == null) {
    4747            currentLayer = new MeasurementLayer(tr("Measurements"));
    48             Main.getLayerManager().addLayer(currentLayer);
     48            MainApplication.getLayerManager().addLayer(currentLayer);
    4949            final ActiveLayerChangeListener activeListener = new ActiveLayerChangeListener() {
    5050                @Override
    5151                public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    52                     Layer newLayer = Main.getLayerManager().getActiveLayer();
     52                    Layer newLayer = MainApplication.getLayerManager().getActiveLayer();
    5353                    if (newLayer instanceof MeasurementLayer)
    5454                        MeasurementPlugin.currentLayer = (MeasurementLayer)newLayer;
    5555                }
    5656            };
    57             Main.getLayerManager().addActiveLayerChangeListener(activeListener);
    58             Main.getLayerManager().addLayerChangeListener(new LayerChangeListener(){
     57            MainApplication.getLayerManager().addActiveLayerChangeListener(activeListener);
     58            MainApplication.getLayerManager().addLayerChangeListener(new LayerChangeListener(){
    5959                @Override
    6060                public void layerAdded(LayerAddEvent e) {
     
    6666                    Layer oldLayer = e.getRemovedLayer();
    6767                    if (oldLayer != null && oldLayer == currentLayer) {
    68                         Main.getLayerManager().removeActiveLayerChangeListener(activeListener);
    69                         Main.getLayerManager().removeLayerChangeListener(this);
     68                        MainApplication.getLayerManager().removeActiveLayerChangeListener(activeListener);
     69                        MainApplication.getLayerManager().removeLayerChangeListener(this);
    7070                    }
    7171                }
Note: See TracChangeset for help on using the changeset viewer.