Changeset 17684 in josm


Ignore:
Timestamp:
2021-03-28T20:43:23+02:00 (4 years ago)
Author:
simon04
Message:

fix #20678 - History Browser: reset coordinates of a node to previous versions (via popup menu)

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r15145 r17684  
    77import java.awt.GridBagLayout;
    88import java.awt.Insets;
     9import java.awt.event.ActionEvent;
    910import java.awt.event.MouseAdapter;
    1011import java.awt.event.MouseEvent;
    1112
     13import javax.swing.AbstractAction;
    1214import javax.swing.BorderFactory;
    1315import javax.swing.JLabel;
    1416import javax.swing.JPanel;
     17import javax.swing.JPopupMenu;
    1518import javax.swing.UIManager;
    1619import javax.swing.event.ChangeEvent;
     
    1922import org.openstreetmap.gui.jmapviewer.JMapViewer;
    2023import org.openstreetmap.gui.jmapviewer.MapMarkerDot;
     24import org.openstreetmap.josm.command.MoveCommand;
     25import org.openstreetmap.josm.data.UndoRedoHandler;
    2126import org.openstreetmap.josm.data.coor.LatLon;
    2227import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat;
     28import org.openstreetmap.josm.data.osm.Node;
     29import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2330import org.openstreetmap.josm.data.osm.history.HistoryNode;
    2431import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
     
    3037import org.openstreetmap.josm.tools.CheckParameterUtil;
    3138import org.openstreetmap.josm.tools.Destroyable;
     39import org.openstreetmap.josm.tools.ImageProvider;
    3240import org.openstreetmap.josm.tools.Pair;
    3341
     
    114122        add(mapViewer, gc);
    115123        mapViewer.setZoomControlsVisible(false);
     124
     125        JPopupMenu popupMenu = new JPopupMenu();
     126        popupMenu.add(new RestoreCoordinateAction());
     127        setComponentPopupMenu(popupMenu);
     128        mapViewer.setComponentPopupMenu(popupMenu);
    116129    }
    117130
     
    424437        }
    425438    }
     439
     440    private class RestoreCoordinateAction extends AbstractAction {
     441
     442        RestoreCoordinateAction() {
     443            super(tr("Restore"));
     444            new ImageProvider("undo").getResource().attachImageIcon(this, true);
     445        }
     446
     447        @Override
     448        public void actionPerformed(ActionEvent e) {
     449            OsmPrimitive primitive = getPrimitiveFromDataSet(PointInTimeType.REFERENCE_POINT_IN_TIME);
     450            if (!(primitive instanceof Node)) {
     451                return;
     452            }
     453            HistoryOsmPrimitive historyPrimitive = model.getPointInTime(PointInTimeType.REFERENCE_POINT_IN_TIME);
     454            if (!(historyPrimitive instanceof HistoryNode) || ((HistoryNode) historyPrimitive).getCoords() == null) {
     455                return;
     456            }
     457            MoveCommand command = new MoveCommand(((Node) primitive), ((HistoryNode) historyPrimitive).getCoords());
     458            UndoRedoHandler.getInstance().add(command);
     459        }
     460    }
    426461}
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserPanel.java

    r14463 r17684  
    1010
    1111import org.openstreetmap.josm.actions.JosmAction;
     12import org.openstreetmap.josm.data.osm.DataSet;
     13import org.openstreetmap.josm.data.osm.OsmPrimitive;
     14import org.openstreetmap.josm.data.osm.PrimitiveId;
     15import org.openstreetmap.josm.gui.MainApplication;
    1216import org.openstreetmap.josm.tools.Destroyable;
    1317
     
    6468    }
    6569
     70    protected OsmPrimitive getPrimitiveFromDataSet(PointInTimeType pointInTime) {
     71        DataSet dataSet = MainApplication.getLayerManager().getEditDataSet();
     72        PrimitiveId primitiveId = model.getPointInTime(pointInTime);
     73        if (dataSet == null || primitiveId == null) {
     74            return null;
     75        }
     76        return dataSet.getPrimitiveById(primitiveId.getUniqueId(), primitiveId.getType());
     77    }
     78
    6679    protected final <T extends AbstractAction> T trackJosmAction(T action) {
    6780        if (action instanceof JosmAction) {
  • trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java

    r16960 r17684  
    1515
    1616import org.openstreetmap.josm.actions.RestorePropertyAction;
    17 import org.openstreetmap.josm.data.osm.DataSet;
    1817import org.openstreetmap.josm.data.osm.OsmPrimitive;
    19 import org.openstreetmap.josm.data.osm.PrimitiveId;
    2018import org.openstreetmap.josm.data.osm.Tagged;
    21 import org.openstreetmap.josm.gui.MainApplication;
    2219import org.openstreetmap.josm.gui.dialogs.properties.CopyAllKeyValueAction;
    2320import org.openstreetmap.josm.gui.dialogs.properties.CopyKeyValueAction;
     
    8380        };
    8481        Supplier<Collection<? extends Tagged>> objectSp = () -> Collections.singletonList(model.getPointInTime(pointInTime));
    85         Supplier<OsmPrimitive> primitiveSupplier = () -> {
    86             DataSet dataSet = MainApplication.getLayerManager().getEditDataSet();
    87             PrimitiveId primitiveId = model.getPointInTime(pointInTime);
    88             if (dataSet == null || primitiveId == null) {
    89                 return null;
    90             }
    91             return dataSet.getPrimitiveById(primitiveId.getUniqueId(), primitiveId.getType());
    92         };
     82        Supplier<OsmPrimitive> primitiveSupplier = () -> getPrimitiveFromDataSet(pointInTime);
    9383
    9484        tagMenu.add(trackJosmAction(new CopyValueAction(table, tagKeyFn, objectSp)));
Note: See TracChangeset for help on using the changeset viewer.