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 | public DuplicateRelationAction() {
|
---|
20 | putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
|
---|
21 | putValue(SMALL_ICON, ImageProvider.get("duplicate"));
|
---|
22 | putValue(NAME, tr("Duplicate"));
|
---|
23 | }
|
---|
24 |
|
---|
25 | public static void duplicateRelationAndLaunchEditor(Relation original) {
|
---|
26 | Relation copy = new Relation(original, true);
|
---|
27 | copy.setModified(true);
|
---|
28 | RelationEditor editor = RelationEditor.getEditor(
|
---|
29 | Main.main.getEditLayer(),
|
---|
30 | copy,
|
---|
31 | null /* no selected members */
|
---|
32 | );
|
---|
33 | editor.setVisible(true);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void actionPerformed(ActionEvent e) {
|
---|
38 | if (!isEnabled() || relations.size()==0)
|
---|
39 | return;
|
---|
40 | Relation r = relations.iterator().next();
|
---|
41 | duplicateRelationAndLaunchEditor(r);
|
---|
42 | }
|
---|
43 |
|
---|
44 | @Override
|
---|
45 | protected void updateEnabledState() {
|
---|
46 | // only one selected relation can be edited
|
---|
47 | setEnabled( relations.size()==1 );
|
---|
48 | }
|
---|
49 | }
|
---|