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.command.AddCommand;
|
---|
11 | import org.openstreetmap.josm.data.UndoRedoHandler;
|
---|
12 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
13 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
14 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | import relcontext.ChosenRelation;
|
---|
18 | import relcontext.ChosenRelationListener;
|
---|
19 |
|
---|
20 | public 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 | }
|
---|