Ignore:
Timestamp:
2014-01-12T10:41:20+01:00 (10 years ago)
Author:
simon04
Message:

Make strings like foo relation/123 and way/345 but also node/789 paste-able in "Download object", some refactoring of related code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java

    r6643 r6674  
    2222import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2323import org.openstreetmap.josm.data.osm.Relation;
     24import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    2425import org.openstreetmap.josm.data.osm.Way;
    2526import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
     
    5253
    5354    // Optional argument 'select'
    54     private final Set<Long> ways = new HashSet<Long>();
    55     private final Set<Long> nodes = new HashSet<Long>();
    56     private final Set<Long> relations = new HashSet<Long>();
     55    private final HashSet<SimplePrimitiveId> toSelect = new HashSet<SimplePrimitiveId>();
    5756
    5857    @Override
     
    6059        String msg = tr("Remote Control has been asked to load data from the API.") +
    6160                "<br>" + tr("Bounding box: ") + new BBox(minlon, minlat, maxlon, maxlat).toStringCSV(", ");
    62         if (args.containsKey("select") && ways.size()+nodes.size()+relations.size() > 0) {
    63             msg += "<br>" + tr("Sel.: Rel.:{0} / Ways:{1} / Nodes:{2}", relations.size(), ways.size(), nodes.size());
     61        if (args.containsKey("select") && toSelect.size() > 0) {
     62            msg += "<br>" + tr("Selection: {0}", toSelect.size());
    6463        }
    6564        return msg;
     
    168167                    if(ds == null) // e.g. download failed
    169168                        return;
    170                     for (Way w : ds.getWays()) {
    171                         if (ways.contains(w.getId())) {
    172                             newSel.add(w);
    173                         }
    174                     }
    175                     ways.clear();
    176                     for (Node n : ds.getNodes()) {
    177                         if (nodes.contains(n.getId())) {
    178                             newSel.add(n);
    179                         }
    180                     }
    181                     nodes.clear();
    182                     for (Relation r : ds.getRelations()) {
    183                         if (relations.contains(r.getId())) {
    184                             newSel.add(r);
    185                         }
    186                     }
    187                     relations.clear();
     169                    for (SimplePrimitiveId id : toSelect) {
     170                        final OsmPrimitive p = ds.getPrimitiveById(id);
     171                        if (p != null) {
     172                            newSel.add(p);
     173                        }
     174                    }
     175                    toSelect.clear();
    188176                    ds.setSelected(newSel);
    189177                    if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) {
     
    277265        // Process optional argument 'select'
    278266        if (args.containsKey("select")) {
    279             ways.clear();
    280             nodes.clear();
    281             relations.clear();
     267            toSelect.clear();
    282268            for (String item : args.get("select").split(",")) {
    283269                try {
    284                     if (item.startsWith("way")) {
    285                         ways.add(Long.parseLong(item.substring(3)));
    286                     } else if (item.startsWith("node")) {
    287                         nodes.add(Long.parseLong(item.substring(4)));
    288                     } else if (item.startsWith("relation")) {
    289                         relations.add(Long.parseLong(item.substring(8)));
    290                     } else if (item.startsWith("rel")) {
    291                         relations.add(Long.parseLong(item.substring(3)));
    292                     } else {
    293                         Main.warn("RemoteControl: invalid selection '"+item+"' ignored");
    294                     }
    295                 } catch (NumberFormatException e) {
    296                     Main.warn("RemoteControl: invalid selection '"+item+"' ignored");
     270                    toSelect.add(SimplePrimitiveId.fromString(item));
     271                } catch (IllegalArgumentException ex) {
     272                    Main.warn("RemoteControl: invalid selection '" + item + "' ignored");
    297273                }
    298274            }
Note: See TracChangeset for help on using the changeset viewer.