source: subversion/applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CurveAction.java

Last change on this file was 34840, checked in by gerdp, 3 months ago

fix #9346: Circle arc wrongly deleting way

Add check to make sure that selected points are different, show message if the selection doesn't work

File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.plugins.utilsplugin2.curves;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.util.ArrayList;
10import java.util.Collection;
11import java.util.List;
12
13import javax.swing.JOptionPane;
14
15import org.openstreetmap.josm.actions.JosmAction;
16import org.openstreetmap.josm.command.Command;
17import org.openstreetmap.josm.command.SequenceCommand;
18import org.openstreetmap.josm.data.UndoRedoHandler;
19import org.openstreetmap.josm.data.osm.Node;
20import org.openstreetmap.josm.data.osm.OsmPrimitive;
21import org.openstreetmap.josm.data.osm.Way;
22import org.openstreetmap.josm.gui.Notification;
23import org.openstreetmap.josm.spi.preferences.Config;
24import org.openstreetmap.josm.tools.Shortcut;
25
26// TODO: investigate splines
27
28/**
29 * Create a circle arc
30 */
31public class CurveAction extends JosmAction {
32
33    private static final long serialVersionUID = 1L;
34
35    private int angleSeparation = -1;
36
37    public CurveAction() {
38        super(tr("Circle arc"), "circlearc", tr("Create a circle arc"),
39                Shortcut.registerShortcut("tools:createcurve", tr("Tool: {0}", tr("Create a circle arc")), KeyEvent.VK_C,
40                        Shortcut.SHIFT), true);
41        putValue("help", ht("/Action/CreateCircleArc"));
42        updatePreferences();
43    }
44
45    private void updatePreferences() {
46        // @formatter:off
47        angleSeparation = Config.getPref().getInt(prefKey("circlearc.angle-separation"), 20);
48        // @formatter:on
49    }
50
51    private String prefKey(String subKey) {
52        return "curves." + subKey;
53    }
54
55    @Override
56    public void actionPerformed(ActionEvent e) {
57        if (!isEnabled())
58            return;
59
60        updatePreferences();
61
62        List<Node> selectedNodes = new ArrayList<>(getLayerManager().getEditDataSet().getSelectedNodes());
63        List<Way> selectedWays = new ArrayList<>(getLayerManager().getEditDataSet().getSelectedWays());
64
65        Collection<Command> cmds = CircleArcMaker.doCircleArc(selectedNodes, selectedWays, angleSeparation);
66        if (cmds == null || cmds.isEmpty()) {
67            new Notification(tr("Could not use selection to create a curve")).setIcon(JOptionPane.WARNING_MESSAGE).show();
68
69        } else {
70            UndoRedoHandler.getInstance().add(new SequenceCommand("Create a curve", cmds));
71        }
72    }
73
74    @Override
75    protected void updateEnabledState() {
76        updateEnabledStateOnCurrentSelection();
77    }
78
79    @Override
80    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
81        setEnabled(selection != null && !selection.isEmpty());
82    }
83}
Note: See TracBrowser for help on using the repository browser.