Changeset 10766 in josm


Ignore:
Timestamp:
2016-08-07T22:52:29+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #13290 - pasting from other layer changes objects position (modified patch by michael2402) - gsoc-core

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java

    r10682 r10766  
    1010import java.util.Collection;
    1111
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.osm.OsmPrimitive;
    14 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
    1513import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
    1614import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
     
    2018 * An action that duplicates the given nodes. They are not added to the clipboard.
    2119 */
    22 public final class DuplicateAction extends JosmAction {
     20public final class DuplicateAction extends AbstractPasteAction {
    2321
    2422    /**
     
    3533    public void actionPerformed(ActionEvent e) {
    3634        PrimitiveTransferData data = PrimitiveTransferData.getDataWithReferences(getLayerManager().getEditDataSet().getSelected());
    37         new OsmTransferHandler().pasteOn(Main.getLayerManager().getEditLayer(),
    38                 PasteAction.computePastePosition(e, getValue(NAME)), new PrimitiveTransferable(data));
     35        doPaste(e, new PrimitiveTransferable(data));
    3936    }
    4037
  • trunk/src/org/openstreetmap/josm/actions/PasteAction.java

    r10682 r10766  
    66import static org.openstreetmap.josm.tools.I18n.tr;
    77
    8 import java.awt.MouseInfo;
    9 import java.awt.Point;
    10 import java.awt.datatransfer.FlavorEvent;
    11 import java.awt.datatransfer.FlavorListener;
    12 import java.awt.event.ActionEvent;
    138import java.awt.event.KeyEvent;
    149
    1510import org.openstreetmap.josm.Main;
    16 import org.openstreetmap.josm.data.coor.EastNorth;
    17 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    18 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
    1911import org.openstreetmap.josm.tools.Shortcut;
    2012
     
    2315 * @since 404
    2416 */
    25 public final class PasteAction extends JosmAction implements FlavorListener {
    26 
    27     private final OsmTransferHandler transferHandler;
     17public final class PasteAction extends AbstractPasteAction {
    2818
    2919    /**
     
    3121     */
    3222    public PasteAction() {
    33         super(tr("Paste"), "paste", tr("Paste contents of paste buffer."),
     23        super(tr("Paste"), "paste", tr("Paste contents of clipboard."),
    3424                Shortcut.registerShortcut("system:paste", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_V, Shortcut.CTRL), true);
    3525        putValue("help", ht("/Action/Paste"));
     
    3727        Main.registerActionShortcut(this,
    3828                Shortcut.registerShortcut("system:paste:cua", tr("Edit: {0}", tr("Paste")), KeyEvent.VK_INSERT, Shortcut.SHIFT));
    39         transferHandler = new OsmTransferHandler();
    40         ClipboardUtils.getClipboard().addFlavorListener(this);
    41     }
    42 
    43     @Override
    44     public void actionPerformed(ActionEvent e) {
    45         transferHandler.pasteOn(Main.getLayerManager().getEditLayer(), computePastePosition(e, getValue(NAME)));
    46     }
    47 
    48     static EastNorth computePastePosition(ActionEvent e, Object name) {
    49         // default to paste in center of map (pasted via menu or cursor not in MapView)
    50         EastNorth mPosition = Main.map.mapView.getCenter();
    51         // We previously checked for modifier to know if the action has been trigerred via shortcut or via menu
    52         // But this does not work if the shortcut is changed to a single key (see #9055)
    53         // Observed behaviour: getActionCommand() returns Action.NAME when triggered via menu, but shortcut text when triggered with it
    54         if (e != null && !name.equals(e.getActionCommand())) {
    55             final Point mp = MouseInfo.getPointerInfo().getLocation();
    56             final Point tl = Main.map.mapView.getLocationOnScreen();
    57             final Point pos = new Point(mp.x-tl.x, mp.y-tl.y);
    58             if (Main.map.mapView.contains(pos)) {
    59                 mPosition = Main.map.mapView.getEastNorth(pos.x, pos.y);
    60             }
    61         }
    62         return mPosition;
    63     }
    64 
    65     @Override
    66     protected void updateEnabledState() {
    67         setEnabled(getLayerManager().getEditDataSet() != null && transferHandler.isDataAvailable());
    68     }
    69 
    70     @Override
    71     public void flavorsChanged(FlavorEvent e) {
    72         updateEnabledState();
    7329    }
    7430}
  • trunk/src/org/openstreetmap/josm/gui/MainMenu.java

    r10611 r10766  
    7474import org.openstreetmap.josm.actions.OverpassDownloadAction;
    7575import org.openstreetmap.josm.actions.PasteAction;
     76import org.openstreetmap.josm.actions.PasteAtSourcePositionAction;
    7677import org.openstreetmap.josm.actions.PasteTagsAction;
    7778import org.openstreetmap.josm.actions.PreferenceToggleAction;
     
    195196    /** Edit / Paste */
    196197    public final PasteAction paste = new PasteAction();
     198    /** Edit / Paste at source */
     199    private final PasteAtSourcePositionAction pasteAtSource = new PasteAtSourcePositionAction();
    197200    /** Edit / Paste Tags */
    198201    public final PasteTagsAction pasteTags = new PasteTagsAction();
     
    680683        add(editMenu, copyCoordinates, true);
    681684        add(editMenu, paste);
     685        add(editMenu, pasteAtSource, true);
    682686        add(editMenu, pasteTags);
    683687        add(editMenu, duplicate);
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/OsmTransferHandler.java

    r10737 r10766  
    8383     * Paste the current clipboard current at the given position
    8484     * @param editLayer The layer to paste on.
    85      * @param mPosition The position to paste at.
     85     * @param mPosition The position to paste at. If it is <code>null</code>, the original position will be used.
    8686     */
    8787    public void pasteOn(OsmDataLayer editLayer, EastNorth mPosition) {
     
    9393     * Paste the given clipboard current at the given position
    9494     * @param editLayer The layer to paste on.
    95      * @param mPosition The position to paste at.
     95     * @param mPosition The position to paste at. If it is <code>null</code>, the original position will be used.
    9696     * @param transferable The transferable to use.
    9797     */
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java

    r10604 r10766  
    5050
    5151        EastNorth center = pasteBuffer.getCenter();
    52         EastNorth offset = center == null ? null : pasteAt.subtract(center);
     52        EastNorth offset = center == null || pasteAt == null ? new EastNorth(0, 0) : pasteAt.subtract(center);
    5353
    5454        AddPrimitivesCommand command = createNewPrimitives(pasteBuffer, offset, layer);
Note: See TracChangeset for help on using the changeset viewer.