Ticket #2088: FixInsertingViaMouse.patch

File FixInsertingViaMouse.patch, 3.0 KB (added by xeen, 17 years ago)

Adds DocumentListener back in, so it reacts to pastings as well

  • src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java

     
    1919import javax.swing.JTextArea;
    2020import javax.swing.JTextField;
    2121import javax.swing.SwingUtilities;
     22import javax.swing.event.DocumentListener;
     23import javax.swing.event.DocumentEvent;
    2224
    2325import org.openstreetmap.josm.data.Bounds;
    2426import org.openstreetmap.josm.data.coor.LatLon;
     
    7577            f.addFocusListener(dialogUpdater);
    7678        }
    7779       
     80        class osmUrlRefresher implements DocumentListener {
     81            public void changedUpdate(DocumentEvent e) { parseURL(gui); }
     82            public void insertUpdate(DocumentEvent e) { parseURL(gui); }
     83            public void removeUpdate(DocumentEvent e) { parseURL(gui); }
     84        }
     85       
    7886        KeyListener osmUrlKeyListener = new KeyListener() {
    79           public void keyPressed(KeyEvent keyEvent) {}
    80 
    81           public void keyReleased(KeyEvent keyEvent) {
    82               Bounds b = OsmUrlToBounds.parse(osmUrl.getText());
    83               if (b != null) {
    84                   gui.minlon = b.min.lon();
    85                   gui.minlat = b.min.lat();
    86                   gui.maxlon = b.max.lon();
    87                   gui.maxlat = b.max.lat();
    88                   gui.boundingBoxChanged(BoundingBoxSelection.this);
    89                   updateBboxFields(gui);
    90                   updateUrl(gui);
    91                   if(keyEvent.getKeyCode() == keyEvent.VK_ENTER)
    92                       gui.closeDownloadDialog(true);
    93               }
    94           }
    95 
    96           public void keyTyped(KeyEvent keyEvent) {}
     87            public void keyPressed(KeyEvent keyEvent) {}
     88            public void keyReleased(KeyEvent keyEvent) {
     89                if (keyEvent.getKeyCode() == keyEvent.VK_ENTER && parseURL(gui))
     90                    gui.closeDownloadDialog(true);
     91            }
     92            public void keyTyped(KeyEvent keyEvent) {}
    9793        };
    9894       
    9995        osmUrl.addKeyListener(osmUrlKeyListener);
     96        osmUrl.getDocument().addDocumentListener(new osmUrlRefresher());
    10097
    10198        // select content on receiving focus. this seems to be the default in the
    10299        // windows look+feel but not for others. needs invokeLater to avoid strange
     
    144141        updateBboxFields(gui);
    145142        updateUrl(gui);
    146143    }
     144   
     145    private boolean parseURL(DownloadDialog gui) {
     146        Bounds b = OsmUrlToBounds.parse(osmUrl.getText());
     147        if(b == null) return false;
     148        gui.minlon = b.min.lon();
     149        gui.minlat = b.min.lat();
     150        gui.maxlon = b.max.lon();
     151        gui.maxlat = b.max.lat();
     152        gui.boundingBoxChanged(BoundingBoxSelection.this);
     153        updateBboxFields(gui);
     154        updateUrl(gui);
     155        return true;
     156    }
    147157
    148158    private void updateBboxFields(DownloadDialog gui) {
    149159        latlon[0].setText(Double.toString(gui.minlat));