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 new ImageProvider("duplicate").getResource().attachImageIcon(this, true); 028 putValue(NAME, tr("Duplicate")); 029 setEnabled(true); 030 } 031 032 @Override 033 public void actionPerformed(ActionEvent e) { 034 Relation copy = new Relation(); 035 getTagModel().applyToPrimitive(copy); 036 editorAccess.getMemberTableModel().applyToRelation(copy); 037 if (!GraphicsEnvironment.isHeadless()) { 038 RelationEditor.getEditor(getLayer(), copy, editorAccess.getMemberTableModel().getSelectedMembers()).setVisible(true); 039 } 040 } 041 042 @Override 043 protected void updateEnabledState() { 044 // Do nothing 045 } 046}