source: subversion/applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/CreateOrEditTurnRestrictionAction.java

Last change on this file was 33537, checked in by donvip, 20 months ago

update to JOSM 12663

File size: 3.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.turnrestrictions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.Collection;
9
10import org.openstreetmap.josm.actions.JosmAction;
11import org.openstreetmap.josm.data.osm.Relation;
12import org.openstreetmap.josm.gui.MainApplication;
13import org.openstreetmap.josm.gui.layer.OsmDataLayer;
14import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditor;
15import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionEditorManager;
16import org.openstreetmap.josm.plugins.turnrestrictions.editor.TurnRestrictionSelectionPopupPanel;
17import org.openstreetmap.josm.tools.Shortcut;
18
19/**
20 * This action is triggered by a global shortcut (default is Shift-Ctrl-T on windows).
21 * Depending on the current selection it either launches an editor for a new turn
22 * restriction or a popup component from which one can choose a turn restriction to
23 * edit.
24 *
25 */
26public class CreateOrEditTurnRestrictionAction extends JosmAction {
27    /** the singleton instance of this action */
28    private static CreateOrEditTurnRestrictionAction instance;
29
30    /**
31     * Replies the unique instance of this action
32     */
33    public static CreateOrEditTurnRestrictionAction getInstance() {
34        if (instance == null) {
35            instance = new CreateOrEditTurnRestrictionAction();
36        }
37        return instance;
38    }
39
40    protected CreateOrEditTurnRestrictionAction() {
41        super(
42            tr("Create/Edit turn restriction..."),
43            null,
44            tr("Create or edit a turn restriction."),
45            Shortcut.registerShortcut("tools:turnrestriction", tr("Tool: {0}", "Create or edit a turn restriction."),
46                KeyEvent.VK_2, Shortcut.ALT_SHIFT),
47            false
48        );
49    }
50
51    @Override
52    public void actionPerformed(ActionEvent e) {
53        OsmDataLayer layer = getLayerManager().getEditLayer();
54        if (layer == null) return;
55        Collection<Relation> trs = TurnRestrictionSelectionPopupPanel.getTurnRestrictionsParticipatingIn(layer.data.getSelected());
56        if (trs.isEmpty()) {
57            // current selection isn't participating in turn restrictions. Launch
58            // an editor for a new turn restriction
59            //
60            Relation tr = new TurnRestrictionBuilder().buildFromSelection(layer);
61            TurnRestrictionEditor editor = new TurnRestrictionEditor(MainApplication.getMap().mapView, layer, tr);
62            TurnRestrictionEditorManager.getInstance().positionOnScreen(editor);
63            TurnRestrictionEditorManager.getInstance().register(layer, tr, editor);
64            editor.setVisible(true);
65        } else {
66            // let the user choose whether he wants to create a new turn restriction or
67            // edit one of the turn restrictions participating in the current selection
68            TurnRestrictionSelectionPopupPanel pnl = new TurnRestrictionSelectionPopupPanel(layer);
69            pnl.launch();
70        }
71    }
72}
Note: See TracBrowser for help on using the repository browser.