Ignore:
Timestamp:
2014-01-12T10:41:20+01:00 (11 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/gui/dialogs/OsmIdSelectionDialog.java

    r6577 r6674  
    33
    44import org.openstreetmap.josm.Main;
     5import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    56import org.openstreetmap.josm.data.osm.PrimitiveId;
     7import org.openstreetmap.josm.data.osm.SimplePrimitiveId;
    68import org.openstreetmap.josm.gui.ExtendedDialog;
    79import org.openstreetmap.josm.gui.widgets.HistoryComboBox;
     
    2931import java.util.Collection;
    3032import java.util.Collections;
     33import java.util.HashSet;
    3134import java.util.LinkedList;
    3235import java.util.List;
     36import java.util.Set;
    3337
    3438import static org.openstreetmap.josm.tools.I18n.tr;
     
    187191        String buf = Utils.getClipboardContent();
    188192        if (buf != null) {
    189             if (buf.contains("node")) cbType.setSelectedIndex(0);
    190             if (buf.contains("way")) cbType.setSelectedIndex(1);
    191             if (buf.contains("relation")) cbType.setSelectedIndex(2);
    192             String[] res = buf.split("/");
    193             String txt;
    194             if (res.length > 0) {
    195                 txt = res[res.length - 1];
    196                 if (txt.isEmpty() && txt.length() > 1) txt = res[res.length - 2];
     193            if (buf.length() <= Main.pref.getInteger("downloadprimitive.max-autopaste-length", 2000)) {
     194                final List<SimplePrimitiveId> ids = SimplePrimitiveId.fuzzyParse(buf);
     195                final String parsedText = Utils.join(", ", Utils.transform(ids, new Utils.Function<SimplePrimitiveId, String>() {
     196                    @Override
     197                    public String apply(SimplePrimitiveId x) {
     198                        return x.getType().getAPIName().charAt(0) + String.valueOf(x.getUniqueId());
     199                    }
     200                }));
     201                tfId.tryToPasteFrom(parsedText);
     202                final Set<OsmPrimitiveType> types = new HashSet<OsmPrimitiveType>(Utils.transform(ids, new Utils.Function<SimplePrimitiveId, OsmPrimitiveType>() {
     203                    @Override
     204                    public OsmPrimitiveType apply(SimplePrimitiveId x) {
     205                        return x.getType();
     206                    }
     207                }));
     208                if (types.size() == 1) {
     209                    // select corresponding type
     210                    cbType.setSelectedItem(types.iterator().next());
     211                } else {
     212                    // select "mixed"
     213                    cbType.setSelectedIndex(3);
     214                }
    197215            } else {
    198                 txt = buf;
    199             }
    200             if (buf.length() <= Main.pref.getInteger("downloadprimitive.max-autopaste-length", 2000)) {
    201                 tfId.tryToPasteFrom(txt.replaceAll("[^0-9]+", " ").replaceAll("\\s\\s+", " "));
     216                if (buf.contains("node")) cbType.setSelectedIndex(0);
     217                if (buf.contains("way")) cbType.setSelectedIndex(1);
     218                if (buf.contains("relation")) cbType.setSelectedIndex(2);
     219                String[] res = buf.split("/");
     220                String txt;
     221                if (res.length > 0) {
     222                    txt = res[res.length - 1];
     223                    if (txt.isEmpty() && txt.length() > 1) txt = res[res.length - 2];
     224                }
    202225            }
    203226        }
Note: See TracChangeset for help on using the changeset viewer.