Ticket #1730: ticket1730_rev2.patch

File ticket1730_rev2.patch, 8.9 KB (added by markus.lindholm@…, 17 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 DMSsFormatter = new DecimalFormat("00.0");
     22    private static DecimalFormat DMmFormatter = new DecimalFormat("00.00");
     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 + Math.abs(tDegree) + "\u00B0" + tMinutes + "\'" + DMSsFormatter.format(tSeconds) + "\"";
     39    }
    1640
     41    public static String convertDDToDM(double pCoordinate, boolean pIsLon) {
     42       
     43        int tDegree = (int) pCoordinate;
     44        double tTmpMinutes = (pCoordinate - tDegree) * 60;
     45        int tMinutes = Math.abs((int) tTmpMinutes);
     46       
     47        return tDegree + "\u00B0" + DMmFormatter.format(tMinutes) + "'";
     48    }
     49
    1750        public LatLon(double lat, double lon) {
    1851                super(lon, lat);
    1952        }
     
    2154        public double lat() {
    2255                return y;
    2356        }
     57       
     58        public String lat(String pCoord, DecimalFormat pFormat) {
     59       
     60            boolean tIsLon = false;
     61           
     62            if (pCoord.equals(CoordinateDisplay.DD.toString())) {
     63                return pFormat.format(y);
     64            } else if (pCoord.equals(CoordinateDisplay.DM.toString())) {
     65            return convertDDToDM(y, tIsLon);
     66            } else if (pCoord.equals(CoordinateDisplay.DMS.toString())) {
     67                return convertDDToDMS(y, tIsLon);
     68            } else {
     69            return "ERROR";
     70        }
     71        }
    2472
    2573        public double lon() {
    2674                return x;
    2775        }
     76       
     77        public String lon(String pCoord, DecimalFormat pFormat) {
     78           
     79            boolean tIsLon = true;
     80           
     81            if (pCoord.equals(CoordinateDisplay.DD.toString())) {
     82                return pFormat.format(x);
     83            } else if (pCoord.equals(CoordinateDisplay.DM.toString())) {
     84            return convertDDToDM(x, tIsLon);
     85            } else if (pCoord.equals(CoordinateDisplay.DMS.toString())) {
     86                return convertDDToDMS(x, tIsLon);
     87            } else {
     88            return "ERROR";
     89        }
     90        }
    2891
    2992        /**
    3093         * @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 "hddd.ddddd°";}},
     44            DM {public String toString() {return "hddd.mm.mmm'";}},
     45            DMS {public String toString() {return "hddd°mm'ss.s\"";}};
     46        }
     47       
     48        /**
    4049         * Convert from lat/lon to northing/easting.
    4150         *
    4251         * @param p             The geo point to convert. x/y members of the point are filled.