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

Last change on this file since 33311 was 32398, checked in by donvip, 9 years ago

checkstyle

File size: 1.5 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.Main;
11import org.openstreetmap.josm.command.AddCommand;
12import org.openstreetmap.josm.data.osm.Relation;
13import org.openstreetmap.josm.tools.ImageProvider;
14
15import relcontext.ChosenRelation;
16import relcontext.ChosenRelationListener;
17
18public class DuplicateChosenRelationAction extends AbstractAction implements ChosenRelationListener {
19 private ChosenRelation rel;
20
21 public DuplicateChosenRelationAction(ChosenRelation rel) {
22 super(tr("Duplicate relation"));
23 putValue(SMALL_ICON, ImageProvider.get("duplicate"));
24 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
25 this.rel = rel;
26 rel.addChosenRelationListener(this);
27 setEnabled(rel.get() != null);
28 }
29
30 @Override
31 public void actionPerformed(ActionEvent e) {
32 Relation r = rel.get();
33 Relation copy = new Relation(r, true);
34 Main.main.undoRedo.add(new AddCommand(copy));
35 rel.set(copy);
36 if (Main.getLayerManager().getEditDataSet() != null) {
37 Main.getLayerManager().getEditDataSet().setSelected(copy);
38 }
39 }
40
41 @Override
42 public void chosenRelationChanged(Relation oldRelation, Relation newRelation) {
43 setEnabled(newRelation != null);
44 }
45}
Note: See TracBrowser for help on using the repository browser.