Ticket #1730: ticket1730_rev3.patch

File ticket1730_rev3.patch, 8.5 KB (added by markus.lindholm@…, 3 years ago)
  • home/mli/workspace/JOSM/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

     
    1313 
    1414import org.openstreetmap.josm.Main; 
    1515import org.openstreetmap.josm.data.projection.Projection; 
     16import org.openstreetmap.josm.data.projection.Projection.CoordinateDisplay; 
    1617import org.openstreetmap.josm.tools.GBC; 
    1718 
    1819public class ProjectionPreference implements PreferenceSetting { 
     
    2122         * Combobox with all projections available 
    2223         */ 
    2324        private JComboBox projectionCombo = new JComboBox(Projection.allProjections); 
     25        private JComboBox coordinatesCombo = new JComboBox(CoordinateDisplay.values()); 
    2426 
    2527        public void addGui(PreferenceDialog gui) { 
    26                 for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 
    27                         if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection"))) { 
    28                                 projectionCombo.setSelectedIndex(i); 
    29                                 break; 
    30                         } 
    31                 } 
     28                 
     29        for (int i = 0; i < projectionCombo.getItemCount(); ++i) { 
     30            if (projectionCombo.getItemAt(i).getClass().getName().equals(Main.pref.get("projection"))) { 
     31                projectionCombo.setSelectedIndex(i); 
     32                break; 
     33            } 
     34        } 
     35 
     36        for (int i = 0; i < coordinatesCombo.getItemCount(); ++i) { 
     37            if (coordinatesCombo.getItemAt(i).toString().equals(Main.pref.get("coordinates"))) { 
     38                coordinatesCombo.setSelectedIndex(i); 
     39                break; 
     40            } 
     41        } 
     42 
    3243                projectionCombo.addActionListener(gui.requireRestartAction); 
     44        coordinatesCombo.addActionListener(gui.requireRestartAction); 
    3345                 
    3446                JPanel projPanel = new JPanel(); 
    3547                projPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray), tr("Map Projection"))); 
     
    3749                projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5,5,0,5)); 
    3850                projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 
    3951                projPanel.add(projectionCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 
     52            projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5)); 
     53            projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 
     54            projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5)); 
    4055                gui.map.add(projPanel, GBC.eol().insets(0,0,0,10).fill(GBC.HORIZONTAL)); 
    4156    } 
    4257 
    4358        public void ok() { 
    4459                Main.pref.put("projection", projectionCombo.getSelectedItem().getClass().getName()); 
     60                Main.pref.put("coordinates", coordinatesCombo.getSelectedItem().toString()); 
    4561    } 
    4662} 
  • home/mli/workspace/JOSM/src/org/openstreetmap/josm/gui/MapStatus.java

     
    8888                } 
    8989        } 
    9090 
     91        String mCord; 
    9192    DecimalFormat latlon = new DecimalFormat("###0.0000"); 
    92     ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 8); 
     93    ImageLabel lonText = new ImageLabel("lon", tr("The geographic longitude at the mouse pointer."), 11); 
    9394    ImageLabel nameText = new ImageLabel("name", tr("The name of the object at the mouse pointer."), 20); 
    9495    JTextField helpText = new JTextField(); 
    95     ImageLabel latText = new ImageLabel("lat", tr("The geographic latitude at the mouse pointer."), 7); 
     96    ImageLabel latText = new ImageLabel("lat", tr("The geographic latitude at the mouse pointer."), 10); 
    9697    ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6); 
    9798    ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6); 
    9899    ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 8); 
     
    253254         */ 
    254255        public MapStatus(final MapFrame mapFrame) { 
    255256                this.mv = mapFrame.mapView; 
    256  
     257                 
     258                mCord = Main.pref.get("coordinates"); 
     259                 
    257260                // Listen for mouse movements and set the position text field 
    258261                mv.addMouseMotionListener(new MouseMotionListener(){ 
    259262                        public void mouseDragged(MouseEvent e) { 
     
    265268                                // Do not update the view, if ctrl is pressed. 
    266269                                if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == 0) { 
    267270                                        LatLon p = mv.getLatLon(e.getX(),e.getY()); 
    268                                         latText.setText(latlon.format(p.lat())); 
    269                                         lonText.setText(latlon.format(p.lon())); 
     271                                        latText.setText(p.lat(mCord, latlon)); 
     272                                        lonText.setText(p.lon(mCord, latlon)); 
    270273                                } 
    271274                        } 
    272275                }); 
  • home/mli/workspace/JOSM/src/org/openstreetmap/josm/data/coor/LatLon.java

     
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others 
    22package org.openstreetmap.josm.data.coor; 
    33 
     4import java.text.DecimalFormat; 
     5import java.text.NumberFormat; 
     6import java.lang.Math; 
     7 
    48import org.openstreetmap.josm.data.Bounds; 
    59import org.openstreetmap.josm.data.projection.Projection; 
    6 import java.text.NumberFormat; 
     10import org.openstreetmap.josm.data.projection.Projection.CoordinateDisplay; 
    711 
    812/** 
    913 * LatLon are unprojected latitude / longitude coordinates. 
     
    1317 * @author Imi 
    1418 */ 
    1519public class LatLon extends Coordinate { 
     20     
     21    private static DecimalFormat cDmsMinuteFormatter = new DecimalFormat("00"); 
     22    private static DecimalFormat cDmsSecondFormatter = new DecimalFormat("00.0"); 
     23     
     24    public static String convertDDToDMS(double pCoordinate, boolean pIsLon) { 
     25         
     26        String tDir = ""; 
     27        if (pIsLon && pCoordinate < 0) {tDir = "W";} 
     28        else if (pIsLon && pCoordinate > 0) {tDir = "E";} 
     29        else if (!pIsLon && pCoordinate < 0) {tDir = "S";} 
     30        else if (!pIsLon && pCoordinate > 0) {tDir = "N";} 
     31         
     32        double tAbsCoord = Math.abs(pCoordinate); 
     33        int tDegree = (int) tAbsCoord; 
     34        double tTmpMinutes = (tAbsCoord - tDegree) * 60; 
     35        int tMinutes = (int) tTmpMinutes; 
     36        double tSeconds = (tTmpMinutes - tMinutes) * 60; 
     37         
     38        return tDir + tDegree + "\u00B0" + cDmsMinuteFormatter.format(tMinutes) + "\'"  
     39            + cDmsSecondFormatter.format(tSeconds) + "\""; 
     40    } 
    1641 
    17         public LatLon(double lat, double lon) { 
     42    public LatLon(double lat, double lon) { 
    1843                super(lon, lat); 
    1944        } 
    2045 
    2146        public double lat() { 
    2247                return y; 
    2348        } 
     49         
     50        public String lat(String pCoord, DecimalFormat pFormat) { 
     51        
     52            boolean tIsLon = false; 
     53             
     54            if (pCoord.equals(CoordinateDisplay.DMS.toString())) { 
     55                return convertDDToDMS(y, tIsLon); 
     56            } else { 
     57            return pFormat.format(y); 
     58        } 
     59        } 
    2460 
    2561        public double lon() { 
    2662                return x; 
    2763        } 
     64         
     65        public String lon(String pCoord, DecimalFormat pFormat) { 
     66             
     67            boolean tIsLon = true; 
     68             
     69            if (pCoord.equals(CoordinateDisplay.DMS.toString())) { 
     70                return convertDDToDMS(x, tIsLon); 
     71            } else { 
     72            return pFormat.format(x); 
     73        } 
     74        } 
    2875 
    2976        /** 
    3077         * @return <code>true</code> if the other point has almost the same lat/lon 
  • home/mli/workspace/JOSM/src/org/openstreetmap/josm/data/projection/Projection.java

     
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others 
    22package org.openstreetmap.josm.data.projection; 
    33 
     4import static org.openstreetmap.josm.tools.I18n.tr; 
     5 
    46import org.openstreetmap.josm.data.coor.EastNorth; 
    57import org.openstreetmap.josm.data.coor.LatLon; 
    68 
     
    3739        }; 
    3840         
    3941        /** 
     42         * Possible ways to display coordinates 
     43         */ 
     44        public enum CoordinateDisplay { 
     45            DD {public String toString() {return tr("Decimal Degrees");}},  
     46            DMS {public String toString() {return tr("Degrees Minutes Seconds");}}; 
     47        } 
     48         
     49        /** 
    4050         * Convert from lat/lon to northing/easting.  
    4151         *  
    4252         * @param p             The geo point to convert. x/y members of the point are filled.