source: osm/applications/editors/josm/plugins/reltoolbox/src/relcontext/actions/DuplicateChosenRelationAction.java@ 34551

Last change on this file since 34551 was 34551, checked in by donvip, 6 years ago

update to JOSM 14153

File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package relcontext.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7
8import javax.swing.AbstractAction;
9
10import org.openstreetmap.josm.command.AddCommand;
11import org.openstreetmap.josm.data.UndoRedoHandler;
12import org.openstreetmap.josm.data.osm.DataSet;
13import org.openstreetmap.josm.data.osm.Relation;
14import org.openstreetmap.josm.gui.MainApplication;
15import org.openstreetmap.josm.tools.ImageProvider;
16
17import relcontext.ChosenRelation;
18import relcontext.ChosenRelationListener;
19
20public class DuplicateChosenRelationAction extends AbstractAction implements ChosenRelationListener {
21 private final ChosenRelation rel;
22
23 public DuplicateChosenRelationAction(ChosenRelation rel) {
24 super(tr("Duplicate relation"));
25 putValue(SMALL_ICON, ImageProvider.get("duplicate"));
26 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
27 this.rel = rel;
28 rel.addChosenRelationListener(this);
29 setEnabled(rel.get() != null);
30 }
31
32 @Override
33 public void actionPerformed(ActionEvent e) {
34 DataSet ds = MainApplication.getLayerManager().getEditDataSet();
35 if (ds != null) {
36 Relation r = rel.get();
37 Relation copy = new Relation(r, true);
38 UndoRedoHandler.getInstance().add(new AddCommand(ds, copy));
39 rel.set(copy);
40 ds.setSelected(copy);
41 }
42 }
43
44 @Override
45 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
46 setEnabled(newRelation != null);
47 }
48}
Note: See TracBrowser for help on using the repository browser.