source: subversion/applications/editors/josm/plugins/HouseNumberTaggingTool/src/org/openstreetmap/josm/plugins/housenumbertool/LaunchAction.java

Last change on this file was 34517, checked in by donvip, 8 months ago

update to JOSM 14153

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.housenumbertool;
3
4import java.awt.event.ActionEvent;
5import java.awt.event.KeyEvent;
6import java.io.File;
7import java.util.Set;
8
9import org.openstreetmap.josm.actions.JosmAction;
10import org.openstreetmap.josm.data.osm.DataSelectionListener;
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.event.SelectionEventManager;
13import org.openstreetmap.josm.tools.Shortcut;
14
15public class LaunchAction extends JosmAction implements DataSelectionListener {
16
17    private OsmPrimitive selection = null;
18
19    private File pluginDir;
20
21    /**
22     * Constructs a new {@code LaunchAction}.
23     * @param pluginDir plugin directory
24     */
25    public LaunchAction(File pluginDir) {
26        super("HouseNumberTaggingTool", 
27              "home-icon32", 
28              "Launches the HouseNumberTaggingTool dialog", 
29              Shortcut.registerShortcut("edit:housenumbertaggingtool", "HouseNumberTaggingTool", KeyEvent.VK_K, Shortcut.DIRECT),
30              true);
31
32        this.pluginDir = pluginDir;
33        SelectionEventManager.getInstance().addSelectionListener(this);
34        setEnabled(false);
35    }
36
37    /**
38     * launch the editor
39     */
40    protected void launchEditor() {
41        if (!isEnabled()) {
42            return;
43        }
44     
45        TagDialog dialog = new TagDialog(pluginDir, selection);
46        dialog.showDialog();
47    }
48
49    @Override
50    public void actionPerformed(ActionEvent e) {
51        launchEditor();
52    }
53
54    @Override
55    public void selectionChanged(SelectionChangeEvent event) {
56        Set<OsmPrimitive> newSelection = event.getSelection();
57        if (newSelection != null && newSelection.size() == 1) {
58            setEnabled(true);
59            selection  =  newSelection.iterator().next();
60        } else {
61            setEnabled(false);
62            selection = null;
63        }
64    }
65}
Note: See TracBrowser for help on using the repository browser.