Ticket #1730: ticket1730.patch

File ticket1730.patch, 7.6 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."), 10); 
    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; 
     6 
    47import org.openstreetmap.josm.data.Bounds; 
    58import org.openstreetmap.josm.data.projection.Projection; 
    6 import java.text.NumberFormat; 
     9import org.openstreetmap.josm.data.projection.Projection.CoordinateDisplay; 
    710 
    811/** 
    912 * LatLon are unprojected latitude / longitude coordinates. 
     
    1316 * @author Imi 
    1417 */ 
    1518public class LatLon extends Coordinate { 
     19     
     20    private static DecimalFormat mFormatter = new DecimalFormat("00.00"); 
     21     
     22    public static String convertDDToDMS(double pCordinate) { 
     23         
     24        int tDegree = (int) pCordinate; 
     25        double tTmpMinutes = (pCordinate - tDegree) * 60; 
     26        int tMinutes = (int) tTmpMinutes; 
     27        double tSeconds = (tTmpMinutes - tMinutes) * 60; 
     28         
     29        return tDegree + "\u00B0" + tMinutes + "\'" + mFormatter.format(tSeconds) + "\""; 
     30    } 
    1631 
    1732        public LatLon(double lat, double lon) { 
    1833                super(lon, lat); 
     
    2136        public double lat() { 
    2237                return y; 
    2338        } 
     39         
     40        public String lat(String pCord, DecimalFormat pFormat) { 
     41             
     42            if (pCord.equals(CoordinateDisplay.DD.toString())) { 
     43                return pFormat.format(y); 
     44            } 
     45            else { 
     46                return convertDDToDMS(y); 
     47            } 
     48        } 
    2449 
    2550        public double lon() { 
    2651                return x; 
    2752        } 
     53         
     54        public String lon(String pCord, DecimalFormat pFormat) { 
     55             
     56       if (pCord.equals(CoordinateDisplay.DD.toString())) { 
     57            return pFormat.format(x); 
     58        } 
     59        else { 
     60            return convertDDToDMS(x); 
     61        } 
     62        } 
    2863 
    2964        /** 
    3065         * @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

     
    3737        }; 
    3838         
    3939        /** 
     40         * Possible ways to display coordinates 
     41         */ 
     42        public enum CoordinateDisplay { 
     43            DD {public String toString() {return "Decimal Degrees";}},  
     44            DMS {public String toString() {return "Degree Minute Second";}}; 
     45        } 
     46         
     47        /** 
    4048         * Convert from lat/lon to northing/easting.  
    4149         *  
    4250         * @param p             The geo point to convert. x/y members of the point are filled.