[9665] | 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 {
|
---|
[14027] | 18 | private static final long serialVersionUID = 1L;
|
---|
[9665] | 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Constructs a new {@code DuplicateRelationAction}.
|
---|
| 22 | * @param memberTableModel member table model
|
---|
| 23 | * @param tagEditorModel tag editor model
|
---|
| 24 | * @param layer OSM data layer
|
---|
| 25 | */
|
---|
[14027] | 26 | public DuplicateRelationAction(IRelationEditorActionAccess editorAccess) {
|
---|
| 27 | super(editorAccess);
|
---|
[9665] | 28 | putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
|
---|
| 29 | // FIXME provide an icon
|
---|
[13130] | 30 | new ImageProvider("duplicate").getResource().attachImageIcon(this, true);
|
---|
[9665] | 31 | putValue(NAME, tr("Duplicate"));
|
---|
| 32 | setEnabled(true);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Override
|
---|
| 36 | public void actionPerformed(ActionEvent e) {
|
---|
| 37 | Relation copy = new Relation();
|
---|
[14027] | 38 | getTagModel().applyToPrimitive(copy);
|
---|
| 39 | editorAccess.getMemberTableModel().applyToRelation(copy);
|
---|
[9665] | 40 | if (!GraphicsEnvironment.isHeadless()) {
|
---|
[14027] | 41 | RelationEditor.getEditor(getLayer(), copy, editorAccess.getMemberTableModel().getSelectedMembers()).setVisible(true);
|
---|
[9665] | 42 | }
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | @Override
|
---|
| 46 | protected void updateEnabledState() {
|
---|
| 47 | // Do nothing
|
---|
| 48 | }
|
---|
| 49 | }
|
---|