1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.relation;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
10 | import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
|
---|
11 | import 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 | */
|
---|
18 | public 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 | }
|
---|