Changeset 17590 in osm for applications


Ignore:
Timestamp:
2009-09-12T15:17:27+02:00 (15 years ago)
Author:
frederik
Message:

added "addNode" command to RemoteControl plugin, patch by sybren@… (modified by fr)

Location:
applications/editors/josm/plugins/remotecontrol/src/org/openstreetmap/josm/plugins/remotecontrol
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/remotecontrol/src/org/openstreetmap/josm/plugins/remotecontrol/RemoteControlPreferences.java

    r16589 r17590  
    2525{
    2626    private JCheckBox permissionLoadData = new JCheckBox(tr("load data from API"));
     27    private JCheckBox permissionCreateObjects = new JCheckBox(tr("create new objects"));
    2728    private JCheckBox permissionChangeSelection = new JCheckBox(tr("change the selection"));
    2829    private JCheckBox permissionChangeViewport = new JCheckBox(tr("change the viewport"));
     
    5152        permissionChangeSelection.setSelected(Main.pref.getBoolean("remotecontrol.permission.change-selection", true));
    5253        permissionChangeViewport.setSelected(Main.pref.getBoolean("remotecontrol.permission.change-viewport", true));
     54        permissionCreateObjects.setSelected(Main.pref.getBoolean("remotecontrol.permission.create-objects", true));
    5355        alwaysAskUserConfirm.setSelected(Main.pref.getBoolean("remotecontrol.always-confirm", false));
    5456
     
    5961        Main.pref.put("remotecontrol.permission.change-selection", permissionChangeSelection.isSelected());
    6062        Main.pref.put("remotecontrol.permission.change-viewport", permissionChangeViewport.isSelected());
     63        Main.pref.put("remotecontrol.permission.create-objects", permissionCreateObjects.isSelected());
    6164        Main.pref.put("remotecontrol.always-confirm", alwaysAskUserConfirm.isSelected());
    6265        // FIXME confirm return value - really no restart needed?
  • applications/editors/josm/plugins/remotecontrol/src/org/openstreetmap/josm/plugins/remotecontrol/RequestProcessor.java

    r17457 r17590  
    2525import org.openstreetmap.josm.actions.AutoScaleAction;
    2626import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     27import org.openstreetmap.josm.command.AddCommand;
    2728import org.openstreetmap.josm.data.Bounds;
    2829import org.openstreetmap.josm.data.coor.LatLon;
     
    216217                    });
    217218                }
     219            } else if (command.equals("/add_node")) {
     220                if (!Main.pref.getBoolean("remotecontrol.permission.create-objects", true)) {
     221                    sendForbidden(out);
     222                    return;
     223                }
     224                if (Main.pref.getBoolean("remotecontrol.always-confirm", false)) {
     225                    if (JOptionPane.showConfirmDialog(Main.parent,
     226                        "<html>" + tr("Remote Control has been asked to create a new node.") +
     227                        "<br>" + tr("Do you want to allow this?"),
     228                        tr("Confirm Remote Control action"),
     229                        JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
     230                            sendForbidden(out);
     231                            return;
     232                    }
     233                }
     234                addNode(args, out);
    218235            } else if (command.equals("/import")) {
    219236                if (Main.pref.getBoolean("remotecontrol.always-confirm", false)) {
     
    269286
    270287    /**
     288     * Adds a node, reacts to the GET /add_node?lon=...&amp;lat=... request.
     289     * @param args
     290     * @param out
     291     * @throws IOException
     292     */
     293    private void addNode(HashMap<String, String> args, Writer out) throws IOException {
     294        if(!args.containsKey("lat") || !args.containsKey("lon")) {
     295            sendBadRequest(out);
     296            return;
     297        }
     298       
     299        // Parse the arguments
     300        double lat = Double.parseDouble(args.get("lat"));
     301        double lon = Double.parseDouble(args.get("lon"));
     302        System.out.println("Adding node at (" + lat + ", " + lon + ")");
     303       
     304        // Create a new node
     305        LatLon ll = new LatLon(lat, lon);
     306        Node nnew = new Node(ll);
     307       
     308        // Now execute the commands to add this node.
     309        Main.main.undoRedo.add(new AddCommand(nnew));
     310        Main.main.getCurrentDataSet().setSelected(nnew);
     311        Main.map.mapView.repaint();
     312       
     313    }
     314
     315    /**
    271316     * Sends a 500 error: server error
    272317     * @param out The writer where the error is written
Note: See TracChangeset for help on using the changeset viewer.