1 | package relcontext.actions;
|
---|
2 |
|
---|
3 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import javax.swing.AbstractAction;
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.command.AddCommand;
|
---|
8 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
9 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
10 | import relcontext.ChosenRelation;
|
---|
11 | import relcontext.ChosenRelationListener;
|
---|
12 |
|
---|
13 | public class DuplicateChosenRelationAction extends AbstractAction implements ChosenRelationListener {
|
---|
14 | private ChosenRelation rel;
|
---|
15 |
|
---|
16 | public DuplicateChosenRelationAction( ChosenRelation rel ) {
|
---|
17 | super(tr("Duplicate relation"));
|
---|
18 | putValue(SMALL_ICON, ImageProvider.get("duplicate"));
|
---|
19 | putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window"));
|
---|
20 | this.rel = rel;
|
---|
21 | rel.addChosenRelationListener(this);
|
---|
22 | setEnabled(rel.get() != null);
|
---|
23 | }
|
---|
24 |
|
---|
25 | public void actionPerformed( ActionEvent e ) {
|
---|
26 | Relation r = rel.get();
|
---|
27 | Relation copy = new Relation(r, true);
|
---|
28 | Main.main.undoRedo.add(new AddCommand(copy));
|
---|
29 | rel.set(copy);
|
---|
30 | if( Main.main.getCurrentDataSet() != null )
|
---|
31 | Main.main.getCurrentDataSet().setSelected(copy);
|
---|
32 | }
|
---|
33 |
|
---|
34 | public void chosenRelationChanged( Relation oldRelation, Relation newRelation ) {
|
---|
35 | setEnabled(newRelation != null);
|
---|
36 | }
|
---|
37 | }
|
---|