source: josm/trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java@ 5821

Last change on this file since 5821 was 5821, checked in by Don-vip, 11 years ago

see #7846 - Large code refactorization in management of popup menus to simplify interactions with plugins (needed at least for imagery-xml-bounds and tag2link plugins)

File size: 1.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.relation;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.osm.Relation;
10import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
11import org.openstreetmap.josm.tools.ImageProvider;
12
13
14/**
15 * Creates a new relation with a copy of the current editor state
16 * @since 5799
17 */
18public class DuplicateRelationAction extends AbstractRelationAction {
19
20 /**
21 * Constructs a new {@code DuplicateRelationAction}.
22 */
23 public DuplicateRelationAction() {
24 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
25 putValue(SMALL_ICON, ImageProvider.get("duplicate"));
26 putValue(NAME, tr("Duplicate"));
27 }
28
29 public static void duplicateRelationAndLaunchEditor(Relation original) {
30 Relation copy = new Relation(original, true);
31 copy.setModified(true);
32 RelationEditor editor = RelationEditor.getEditor(
33 Main.main.getEditLayer(),
34 copy,
35 null /* no selected members */
36 );
37 editor.setVisible(true);
38 }
39
40 @Override
41 public void actionPerformed(ActionEvent e) {
42 if (!isEnabled() || relations.size()==0)
43 return;
44 Relation r = relations.iterator().next();
45 duplicateRelationAndLaunchEditor(r);
46 }
47
48 @Override
49 protected void updateEnabledState() {
50 // only one selected relation can be edited
51 setEnabled( relations.size()==1 );
52 }
53}
Note: See TracBrowser for help on using the repository browser.