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

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

javadoc/code style/minor refactorization

File size: 1.8 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 * Creates a new relation with a copy of the current editor state
15 * @since 5799
16 */
17public class DuplicateRelationAction extends AbstractRelationAction {
18
19 /**
20 * Constructs a new {@code DuplicateRelationAction}.
21 */
22 public DuplicateRelationAction() {
23 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
24 putValue(SMALL_ICON, ImageProvider.get("duplicate"));
25 putValue(NAME, tr("Duplicate"));
26 }
27
28 /**
29 * Duplicates the given relation and launches the relation editor for the created copy.
30 * @param original The relation to duplicate
31 */
32 public static void duplicateRelationAndLaunchEditor(Relation original) {
33 Relation copy = new Relation(original, true);
34 copy.setModified(true);
35 RelationEditor editor = RelationEditor.getEditor(
36 Main.main.getEditLayer(),
37 copy,
38 null /* no selected members */
39 );
40 editor.setVisible(true);
41 }
42
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 if (!isEnabled() || relations.isEmpty())
46 return;
47 Relation r = relations.iterator().next();
48 duplicateRelationAndLaunchEditor(r);
49 }
50
51 @Override
52 protected void updateEnabledState() {
53 // only one selected relation can be edited
54 setEnabled( relations.size()==1 );
55 }
56}
Note: See TracBrowser for help on using the repository browser.