Ignore:
Timestamp:
2020-05-10T15:58:34+02:00 (4 years ago)
Author:
simon04
Message:

fix #19127 - Jump to Position: jump to place name

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r14742 r16402  
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
     11import java.io.IOException;
     12import java.util.List;
    1113import java.util.Optional;
    1214
     15import javax.swing.BorderFactory;
    1316import javax.swing.JLabel;
    1417import javax.swing.JOptionPane;
    1518import javax.swing.JPanel;
     19import javax.swing.JSeparator;
    1620import javax.swing.event.DocumentEvent;
    1721import javax.swing.event.DocumentListener;
     
    2327import org.openstreetmap.josm.gui.MainApplication;
    2428import org.openstreetmap.josm.gui.MapView;
     29import org.openstreetmap.josm.gui.Notification;
    2530import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    2631import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2732import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
     33import org.openstreetmap.josm.io.NameFinder;
    2834import org.openstreetmap.josm.spi.preferences.Config;
    2935import org.openstreetmap.josm.tools.GBC;
     
    4046
    4147    private final JosmTextField url = new JosmTextField();
     48    private final JosmTextField place = new JosmTextField();
    4249    private final JosmTextField lat = new JosmTextField();
    4350    private final JosmTextField lon = new JosmTextField();
     
    112119        if (boundsFromClipboard.isPresent() && Config.getPref().getBoolean("jumpto.use.clipboard", true)) {
    113120            setBounds(boundsFromClipboard.get());
     121            place.setText("");
    114122        } else {
    115123            setBounds(mv.getState().getViewArea().getCornerBounds());
     
    132140        url.getDocument().addDocumentListener(new OsmURLListener());
    133141
     142        SelectAllOnFocusGainedDecorator.decorate(place);
    134143        SelectAllOnFocusGainedDecorator.decorate(lat);
    135144        SelectAllOnFocusGainedDecorator.decorate(lon);
     
    140149        panel.add(p, BorderLayout.NORTH);
    141150
     151        p.add(new JLabel(tr("Enter a place name to search for")), GBC.eol());
     152        p.add(place, GBC.eol().fill(GBC.HORIZONTAL));
     153        p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(3, 5, 3, 5));
     154
    142155        p.add(new JLabel(tr("Latitude")), GBC.eol());
    143156        p.add(lat, GBC.eol().fill(GBC.HORIZONTAL));
     
    148161        p.add(new JLabel(tr("Zoom (in metres)")), GBC.eol());
    149162        p.add(zm, GBC.eol().fill(GBC.HORIZONTAL));
     163        p.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(3, 5, 3, 5));
    150164
    151165        p.add(new JLabel(tr("URL")), GBC.eol());
     
    159173
    160174            if (option != 1) return;
     175            if (place.hasFocus() && !place.getText().trim().isEmpty()) {
     176                try {
     177                    List<NameFinder.SearchResult> searchResults = NameFinder.queryNominatim(place.getText());
     178                    if (!searchResults.isEmpty()) {
     179                        NameFinder.SearchResult searchResult = searchResults.get(0);
     180                        new Notification(tr("Jumping to: {0}", searchResult.getName()))
     181                                .setIcon(JOptionPane.INFORMATION_MESSAGE)
     182                                .show();
     183                        mv.zoomTo(searchResult.getBounds());
     184                    }
     185                    return;
     186                } catch (IOException | RuntimeException ex) {
     187                    Logging.warn(ex);
     188                }
     189            }
    161190            try {
    162191                zoomLvl = Double.parseDouble(zm.getText());
Note: See TracChangeset for help on using the changeset viewer.