001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.dialogs.relation.actions;
003
004import static org.openstreetmap.josm.tools.I18n.tr;
005
006import java.awt.GraphicsEnvironment;
007import java.awt.event.ActionEvent;
008
009import org.openstreetmap.josm.data.osm.Relation;
010import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
011import org.openstreetmap.josm.tools.ImageProvider;
012
013/**
014 * Creates a new relation with a copy of the current editor state.
015 * @since 9496
016 */
017public class DuplicateRelationAction extends AbstractRelationEditorAction {
018    private static final long serialVersionUID = 1L;
019
020    /**
021     * Constructs a new {@code DuplicateRelationAction}.
022     * @param editorAccess An interface to access the relation editor contents.
023     */
024    public DuplicateRelationAction(IRelationEditorActionAccess editorAccess) {
025        super(editorAccess);
026        putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
027        // FIXME provide an icon
028        new ImageProvider("duplicate").getResource().attachImageIcon(this, true);
029        putValue(NAME, tr("Duplicate"));
030        setEnabled(true);
031    }
032
033    @Override
034    public void actionPerformed(ActionEvent e) {
035        Relation copy = new Relation();
036        getTagModel().applyToPrimitive(copy);
037        editorAccess.getMemberTableModel().applyToRelation(copy);
038        if (!GraphicsEnvironment.isHeadless()) {
039            RelationEditor.getEditor(getLayer(), copy, editorAccess.getMemberTableModel().getSelectedMembers()).setVisible(true);
040        }
041    }
042
043    @Override
044    protected void updateEnabledState() {
045        // Do nothing
046    }
047}