1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs.relation.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.GraphicsEnvironment;
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 |
|
---|
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 | * Creates a new relation with a copy of the current editor state.
|
---|
15 | * @since 9496
|
---|
16 | */
|
---|
17 | public class DuplicateRelationAction extends AbstractRelationEditorAction {
|
---|
18 | private static final long serialVersionUID = 1L;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Constructs a new {@code DuplicateRelationAction}.
|
---|
22 | * @param editorAccess An interface to access the relation editor contents.
|
---|
23 | */
|
---|
24 | public DuplicateRelationAction(IRelationEditorActionAccess editorAccess) {
|
---|
25 | super(editorAccess);
|
---|
26 | putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
|
---|
27 | // FIXME provide an icon
|
---|
28 | new ImageProvider("duplicate").getResource().attachImageIcon(this, true);
|
---|
29 | putValue(NAME, tr("Duplicate"));
|
---|
30 | setEnabled(true);
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void actionPerformed(ActionEvent e) {
|
---|
35 | Relation copy = new Relation();
|
---|
36 | getTagModel().applyToPrimitive(copy);
|
---|
37 | editorAccess.getMemberTableModel().applyToRelation(copy);
|
---|
38 | if (!GraphicsEnvironment.isHeadless()) {
|
---|
39 | RelationEditor.getEditor(getLayer(), copy, editorAccess.getMemberTableModel().getSelectedMembers()).setVisible(true);
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | protected void updateEnabledState() {
|
---|
45 | // Do nothing
|
---|
46 | }
|
---|
47 | }
|
---|