Changeset 2531 in josm


Ignore:
Timestamp:
Nov 28, 2009 2:40:35 PM (3 years ago)
Author:
Gubaer
Message:

fixed in #2730: "Add Node..." dialog: wrong focus after showing up

File:
1 edited

Legend:

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

    r2512 r2531  
    22package org.openstreetmap.josm.actions; 
    33 
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
    45import static org.openstreetmap.josm.tools.I18n.tr; 
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
    66 
    77import java.awt.GridBagLayout; 
    88import java.awt.event.ActionEvent; 
    99import java.awt.event.KeyEvent; 
     10import java.awt.event.WindowAdapter; 
     11import java.awt.event.WindowEvent; 
    1012 
     13import javax.swing.JDialog; 
    1114import javax.swing.JLabel; 
    1215import javax.swing.JOptionPane; 
     
    3235                        Shortcut.SHIFT_DEFAULT), true); 
    3336        putValue("help", ht("/Action/AddNode")); 
     37    } 
     38 
     39    private String normalizeUserInputForLatLonValue(String value) { 
     40        if (value == null) return null; 
     41        value = value.trim(); 
     42        return value.replaceAll("\u00B0", ""); // the degree symbol 
    3443    } 
    3544 
     
    5867        while(nnew == null) { 
    5968            JOptionPane pane = new JOptionPane(p, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 
    60             pane.createDialog(Main.parent, tr("Add Node...")).setVisible(true); 
     69            JDialog dialog = pane.createDialog(Main.parent, tr("Add Node...")); 
     70            dialog.addWindowListener(new WindowAdapter() { 
     71                @Override 
     72                public void windowGainedFocus(WindowEvent e) { 
     73                    lat.selectAll(); 
     74                    lat.requestFocusInWindow(); 
     75                } 
     76            } 
     77            ); 
     78            dialog.setVisible(true); 
     79 
    6180            if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 
    6281                return; 
    6382            try { 
    64                 LatLon ll = new LatLon(Double.parseDouble(lat.getText()), Double.parseDouble(lon.getText())); 
     83                LatLon ll = new LatLon( 
     84                        Double.parseDouble( 
     85                                normalizeUserInputForLatLonValue(lat.getText()) 
     86                        ), 
     87                        Double.parseDouble( 
     88                                normalizeUserInputForLatLonValue(lon.getText()) 
     89                        ) 
     90                ); 
    6591                if (!ll.isOutSideWorld()) { 
    6692                    nnew = new Node(ll); 
    6793                } 
    68             } catch (Exception ex) { } 
     94            } catch (Exception ex) { 
     95                ex.printStackTrace(); 
     96                JOptionPane.showMessageDialog( 
     97                        Main.parent, 
     98                        tr("Could not create a node with the entered latitude/longitude."), 
     99                        tr("Illegal lat/lon value"), 
     100                        JOptionPane.ERROR_MESSAGE 
     101                ); 
     102            } 
    69103        } 
    70104 
     
    79113        setEnabled(getEditLayer() != null); 
    80114    } 
    81  
    82115} 
Note: See TracChangeset for help on using the changeset viewer.