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.MemberTableModel;
|
---|
11 | import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
|
---|
12 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
13 | import org.openstreetmap.josm.gui.tagging.TagEditorModel;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Creates a new relation with a copy of the current editor state.
|
---|
18 | * @since 9496
|
---|
19 | */
|
---|
20 | public class DuplicateRelationAction extends AbstractRelationEditorAction {
|
---|
21 |
|
---|
22 | private final transient TagEditorModel tagEditorModel;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Constructs a new {@code DuplicateRelationAction}.
|
---|
26 | * @param memberTableModel member table model
|
---|
27 | * @param tagEditorModel tag editor model
|
---|
28 | * @param layer OSM data layer
|
---|
29 | */
|
---|
30 | public DuplicateRelationAction(MemberTableModel memberTableModel, TagEditorModel tagEditorModel, OsmDataLayer layer) {
|
---|
31 | super(null, memberTableModel, null, layer, null);
|
---|
32 | this.tagEditorModel = tagEditorModel;
|
---|
33 | putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
|
---|
34 | // FIXME provide an icon
|
---|
35 | new ImageProvider("duplicate").getResource().attachImageIcon(this, true);
|
---|
36 | putValue(NAME, tr("Duplicate"));
|
---|
37 | setEnabled(true);
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public void actionPerformed(ActionEvent e) {
|
---|
42 | Relation copy = new Relation();
|
---|
43 | tagEditorModel.applyToPrimitive(copy);
|
---|
44 | memberTableModel.applyToRelation(copy);
|
---|
45 | if (!GraphicsEnvironment.isHeadless()) {
|
---|
46 | RelationEditor.getEditor(layer, copy, memberTableModel.getSelectedMembers()).setVisible(true);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | protected void updateEnabledState() {
|
---|
52 | // Do nothing
|
---|
53 | }
|
---|
54 | }
|
---|