Ticket #19127: 19127.patch

File 19127.patch, 3.0 KB (added by simon04, 4 years ago)
  • src/org/openstreetmap/josm/actions/JumpToAction.java

    commit c71170c24333954bc836ef60cdb3b45aef488fd4
    Author: Simon Legner <Simon.Legner@gmail.com>
    Date:   2020-04-20 23:21:12 +0200
    
        fix #19127 - Jump to Position: jump to place name
    
    diff --git a/src/org/openstreetmap/josm/actions/JumpToAction.java b/src/org/openstreetmap/josm/actions/JumpToAction.java
    index 52cbca965..77bccd469 100644
    a b  
    88import java.awt.GridBagLayout;
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.KeyEvent;
     11import java.io.IOException;
     12import java.util.List;
    1113import java.util.Optional;
    1214
    1315import javax.swing.JLabel;
     
    2527import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    2628import org.openstreetmap.josm.gui.widgets.JosmTextField;
    2729import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
     30import org.openstreetmap.josm.io.NameFinder;
    2831import org.openstreetmap.josm.spi.preferences.Config;
    2932import org.openstreetmap.josm.tools.GBC;
    3033import org.openstreetmap.josm.tools.ImageProvider;
     
    3942public class JumpToAction extends JosmAction {
    4043
    4144    private final JosmTextField url = new JosmTextField();
     45    private final JosmTextField place = new JosmTextField();
    4246    private final JosmTextField lat = new JosmTextField();
    4347    private final JosmTextField lon = new JosmTextField();
    4448    private final JosmTextField zm = new JosmTextField();
    public void showJumpToDialog() {  
    131135        zm.getDocument().addDocumentListener(x);
    132136        url.getDocument().addDocumentListener(new OsmURLListener());
    133137
     138        SelectAllOnFocusGainedDecorator.decorate(place);
    134139        SelectAllOnFocusGainedDecorator.decorate(lat);
    135140        SelectAllOnFocusGainedDecorator.decorate(lon);
    136141        SelectAllOnFocusGainedDecorator.decorate(zm);
    public void showJumpToDialog() {  
    139144        JPanel p = new JPanel(new GridBagLayout());
    140145        panel.add(p, BorderLayout.NORTH);
    141146
     147        p.add(new JLabel(tr("Areas around places")), GBC.eol());
     148        p.add(place, GBC.eol().fill(GBC.HORIZONTAL));
     149
    142150        p.add(new JLabel(tr("Latitude")), GBC.eol());
    143151        p.add(lat, GBC.eol().fill(GBC.HORIZONTAL));
    144152
    public void showJumpToDialog() {  
    158166            final int option = new JumpToPositionDialog(buttons, panel).showDialog().getValue();
    159167
    160168            if (option != 1) return;
     169            if (place.hasFocus()) {
     170                try {
     171                    List<NameFinder.SearchResult> placeResults = NameFinder.queryNominatim(place.getText());
     172                    mv.zoomTo(placeResults.get(0).getBounds());
     173                    return;
     174                } catch (IOException | RuntimeException ignore) {
     175                    Logging.debug(ignore);
     176                }
     177            }
    161178            try {
    162179                zoomLvl = Double.parseDouble(zm.getText());
    163180                ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText()));