Changeset 10605 in josm


Ignore:
Timestamp:
2016-07-23T15:15:14+02:00 (8 years ago)
Author:
Don-vip
Message:

see #12478 - Use ​Swing Copy/Paste instead of CopyAction/PasteAction with custom buffer (layer part: patch by michael2402, modified) - gsoc-core

Location:
trunk
Files:
6 added
5 edited

Legend:

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

    r10604 r10605  
    8585import org.openstreetmap.josm.gui.MapFrameListener;
    8686import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
     87import org.openstreetmap.josm.gui.datatransfer.data.OsmLayerTransferData;
    8788import org.openstreetmap.josm.gui.help.HelpUtil;
    8889import org.openstreetmap.josm.gui.io.SaveLayersDialog;
  • trunk/src/org/openstreetmap/josm/actions/CopyAction.java

    r10604 r10605  
    1919import org.openstreetmap.josm.gui.datatransfer.PrimitiveTransferable;
    2020import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
     21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2122import org.openstreetmap.josm.tools.Shortcut;
    2223
     
    4849        }
    4950
    50         copy(selection);
     51        copy(getLayerManager().getEditLayer(), selection);
    5152    }
    5253
     
    5455     * Copies the given primitive ids to the clipboard. The output by this function
    5556     * looks similar to: node 1089302677,node 1089303458,way 93793372
     57     * @param source The OSM data layer source
    5658     * @param primitives The OSM primitives to copy
    5759     */
    58     public static void copy(Collection<OsmPrimitive> primitives) {
     60    public static void copy(OsmDataLayer source, Collection<OsmPrimitive> primitives) {
    5961        // copy ids to the clipboard
    60         ClipboardUtils.copy(new PrimitiveTransferable(PrimitiveTransferData.getDataWithReferences(primitives)));
     62        ClipboardUtils.copy(new PrimitiveTransferable(PrimitiveTransferData.getDataWithReferences(primitives), source));
    6163    }
    6264
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/PrimitiveTransferable.java

    r10604 r10605  
    1111import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1212import org.openstreetmap.josm.data.osm.PrimitiveData;
     13import org.openstreetmap.josm.gui.datatransfer.data.OsmLayerTransferData;
    1314import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData;
    1415import org.openstreetmap.josm.gui.datatransfer.data.TagTransferData;
     16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1517
    1618/**
     
    2729            TagTransferData.FLAVOR, DataFlavor.stringFlavor);
    2830    private final PrimitiveTransferData primitives;
     31    private OsmDataLayer sourceLayer;
    2932
    3033    /**
     
    3336     */
    3437    public PrimitiveTransferable(PrimitiveTransferData primitives) {
     38        this(primitives, null);
     39    }
     40
     41    /**
     42     * Constructs a new {@code PrimitiveTransferable}.
     43     * @param primitives collection of OSM primitives
     44     * @param sourceLayer The layer the primitives are copied from
     45     */
     46    public PrimitiveTransferable(PrimitiveTransferData primitives, OsmDataLayer sourceLayer) {
    3547        this.primitives = primitives;
     48        this.sourceLayer = sourceLayer;
    3649    }
    3750
     
    3952    public DataFlavor[] getTransferDataFlavors() {
    4053        ArrayList<DataFlavor> flavors = new ArrayList<>(PRIMITIVE_FLAVORS);
     54        if (sourceLayer != null) {
     55            flavors.addAll(OsmLayerTransferData.FLAVORS);
     56        }
    4157        return flavors.toArray(new DataFlavor[flavors.size()]);
    4258    }
     
    6177        } else if (TagTransferData.FLAVOR.equals(flavor)) {
    6278            return new TagTransferData(primitives.getDirectlyAdded());
     79        } else if (sourceLayer != null && OsmLayerTransferData.FLAVORS.contains(flavor)) {
     80            return new OsmLayerTransferData(null, sourceLayer);
    6381        } else {
    6482            throw new UnsupportedFlavorException(flavor);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    r10600 r10605  
    2525import javax.swing.DefaultCellEditor;
    2626import javax.swing.DefaultListSelectionModel;
     27import javax.swing.DropMode;
    2728import javax.swing.ImageIcon;
    2829import javax.swing.JCheckBox;
     
    5253import org.openstreetmap.josm.gui.dialogs.layer.DeleteLayerAction;
    5354import org.openstreetmap.josm.gui.dialogs.layer.DuplicateAction;
     55import org.openstreetmap.josm.gui.dialogs.layer.LayerListTransferHandler;
    5456import org.openstreetmap.josm.gui.dialogs.layer.LayerVisibilityAction;
    5557import org.openstreetmap.josm.gui.dialogs.layer.MergeAction;
     
    11041106        @Override
    11051107        public void layerOrderChanged(LayerOrderChangeEvent e) {
    1106             // ignored for now, since only we change layer order.
     1108            fireTableDataChanged();
    11071109        }
    11081110
     
    11301132            super(dataModel);
    11311133            dataModel.setLayerList(this);
     1134            setDragEnabled(true);
     1135            setDropMode(DropMode.INSERT_ROWS);
     1136            setTransferHandler(new LayerListTransferHandler());
    11321137        }
    11331138
     
    11411146            viewport.scrollRectToVisible(rect);
    11421147        }
     1148
     1149        @Override
     1150        public LayerListModel getModel() {
     1151            return (LayerListModel) super.getModel();
     1152        }
    11431153    }
    11441154
  • trunk/src/org/openstreetmap/josm/gui/dialogs/layer/DuplicateAction.java

    r10600 r10605  
    55
    66import java.awt.event.ActionEvent;
    7 import java.util.ArrayList;
    8 import java.util.List;
    97
    108import javax.swing.AbstractAction;
     
    2119
    2220/**
    23  * The action to merge the currently selected layer into another layer.
     21 * The action to dupplicate the given selected layer into another layer.
    2422 */
    2523public final class DuplicateAction extends AbstractAction implements IEnabledStateUpdating {
     
    5351    }
    5452
    55     private void duplicate(Layer layer) {
    56         if (!Main.isDisplayingMapView())
    57             return;
    58 
    59         List<String> layerNames = new ArrayList<>();
    60         for (Layer l: Main.getLayerManager().getLayers()) {
    61             layerNames.add(l.getName());
    62         }
     53    private static void duplicate(Layer layer) {
    6354        if (layer instanceof OsmDataLayer) {
     55            String newName = LayerListTransferHandler.suggestNewLayerName(layer.getName(), Main.getLayerManager().getLayers());
    6456            OsmDataLayer oldLayer = (OsmDataLayer) layer;
    65             // Translators: "Copy of {layer name}"
    66             String newName = tr("Copy of {0}", oldLayer.getName());
    67             int i = 2;
    68             while (layerNames.contains(newName)) {
    69                 // Translators: "Copy {number} of {layer name}"
    70                 newName = tr("Copy {1} of {0}", oldLayer.getName(), i);
    71                 i++;
    72             }
    7357            Main.getLayerManager().addLayer(new OsmDataLayer(new DataSet(oldLayer.data), newName, null));
    7458        }
Note: See TracChangeset for help on using the changeset viewer.