1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package relcontext.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 |
|
---|
8 | import javax.swing.AbstractAction;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.command.AddCommand;
|
---|
12 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
13 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
14 |
|
---|
15 | import relcontext.ChosenRelation;
|
---|
16 | import relcontext.ChosenRelationListener;
|
---|
17 |
|
---|
18 | public 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 | }
|
---|