source: josm/trunk/src/org/openstreetmap/josm/actions/DuplicateLayerAction.java@ 3779

Last change on this file since 3779 was 3083, checked in by bastiK, 14 years ago

added svn:eol-style=native to source files

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. See LICENSE file for details.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.util.ArrayList;
10import java.util.List;
11
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.gui.layer.Layer;
14import org.openstreetmap.josm.gui.layer.OsmDataLayer;
15import org.openstreetmap.josm.tools.Shortcut;
16
17public class DuplicateLayerAction extends JosmAction {
18
19 public DuplicateLayerAction() {
20 super(tr("Duplicate Layer"), "dialogs/duplicatelayer", tr("Make a duplicate of the currently selected layer."),
21 Shortcut.registerShortcut("layer:duplicate", tr("Layer: {0}", tr("Duplicate")), KeyEvent.VK_N, Shortcut.GROUP_NONE), true);
22 putValue("help", ht("/Action/DuplicateLayer"));
23 }
24
25 public void actionPerformed(ActionEvent e) {
26 Layer sourceLayer = Main.main.getEditLayer();
27 if (sourceLayer == null)
28 return;
29 duplicate(sourceLayer);
30 }
31
32 public void duplicate(Layer layer) {
33 if ((Main.map == null) || (Main.map.mapView == null))
34 return;
35 List<String> layerNames = new ArrayList<String>();
36 for (Layer l: Main.map.mapView.getAllLayers()) {
37 layerNames.add(l.getName());
38 }
39 if (layer instanceof OsmDataLayer) {
40 OsmDataLayer oldLayer = (OsmDataLayer)layer;
41 // Translators: "Copy of {layer name}"
42 String newName = tr("Copy of {0}", oldLayer.getName());
43 int i = 2;
44 while (layerNames.contains(newName)) {
45 // Translators: "Copy {number} of {layer name}"
46 newName = tr("Copy {1} of {0}", oldLayer.getName(), i);
47 i++;
48 }
49 Main.main.addLayer(new OsmDataLayer(oldLayer.data.clone(), newName, null));
50 }
51 }
52
53 public static boolean canDuplicate(Layer layer) {
54 if (layer instanceof OsmDataLayer)
55 return true;
56 return false;
57 }
58}
Note: See TracBrowser for help on using the repository browser.