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

Last change on this file since 26816 was 26290, checked in by zverik, 13 years ago

implemented most TODO requests, fixed some bugs

File size: 1.4 KB
Line 
1package relcontext.actions;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4import java.awt.event.ActionEvent;
5import javax.swing.AbstractAction;
6import org.openstreetmap.josm.Main;
7import org.openstreetmap.josm.command.AddCommand;
8import org.openstreetmap.josm.data.osm.Relation;
9import org.openstreetmap.josm.tools.ImageProvider;
10import relcontext.ChosenRelation;
11import relcontext.ChosenRelationListener;
12
13public 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}
Note: See TracBrowser for help on using the repository browser.