Changeset 3406 in josm for trunk/src/org


Ignore:
Timestamp:
2010-08-02T20:00:36+02:00 (14 years ago)
Author:
bastiK
Message:

fixed #5284 - change units at bottom of screen

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapScaler.java

    r3234 r3406  
    1717
    1818    private final NavigatableComponent mv;
     19   
     20    private static int PADDING_RIGHT = 100;
     21   
    1922    public MapScaler(NavigatableComponent mv) {
    2023        this.mv = mv;
    21         setSize(100,30);
     24        setSize(100+PADDING_RIGHT,30);
    2225        setOpaque(false);
    2326    }
     
    3336        g.drawLine(24, 3, 24, 7);
    3437        g.drawLine(74, 3, 74, 7);
    35         g.drawString(text, (int)(100-bound.getWidth()), 23);
     38        g.drawString(text, (int)(100-bound.getWidth()/2), 23);
    3639        g.drawString("0", 0, 23);
    3740    }
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r3376 r3406  
    11// License: GPL. See LICENSE file for details.
    2 
    32package org.openstreetmap.josm.gui;
    43
     
    101100    ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6);
    102101    ImageLabel headingText = new ImageLabel("heading", tr("The (compass) heading of the line segment being drawn."), 6);
    103     ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 8);
     102    ImageLabel distText = new ImageLabel("dist", tr("The length of the new way segment being drawn."), 10);
    104103
    105104    /**
     
    635634    }
    636635    public void setDist(double dist) {
    637         String text = dist > 1000 ? (Math.round(dist/100)/10.0)+" km" : Math.round(dist*10)/10.0 +" m";
    638         distText.setText(dist < 0 ? "--" : text);
     636        distText.setText(dist < 0 ? "--" : NavigatableComponent.getDistText(dist));
    639637    }
    640638}
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r3177 r3406  
    11// License: GPL. See LICENSE file for details.
    2 
    32package org.openstreetmap.josm.gui;
     3
     4import static org.openstreetmap.josm.tools.I18n.marktr;
    45
    56import java.awt.Point;
     
    1011import java.util.Date;
    1112import java.util.HashSet;
     13import java.util.LinkedHashMap;
    1214import java.util.LinkedList;
    1315import java.util.List;
     16import java.util.Locale;
     17import java.util.Map;
    1418import java.util.Stack;
    1519import java.util.TreeMap;
     
    111115    }
    112116
     117    public static String getDistText(double dist) {
     118        SystemOfMeasurement som = SYSTEMS_OF_MEASUREMENT.get(Main.pref.get("system_of_measurement", "Metric"));
     119        if (som == null) {
     120            som = METRIC_SOM;
     121        }
     122        return som.getDistText(dist);
     123    }
     124
    113125    public String getDist100PixelText()
    114126    {
    115         double dist = getDist100Pixel();
    116         return dist >= 2000 ? Math.round(dist/100)/10 +" km" : (dist >= 1
    117                 ? Math.round(dist*10)/10 +" m" : "< 1 m");
     127        return getDistText(getDist100Pixel());
    118128    }
    119129
     
    707717        return (int)id.getValue();
    708718    }
     719
     720    public static class SystemOfMeasurement {
     721        public final double aValue;
     722        public final double bValue;
     723        public final String aName;
     724        public final String bName;
     725
     726        /**
     727         * System of measurement. Currently covers only length units.
     728         *
     729         * If a quantity x is given in m (x_m) and in unit a (x_a) then it translates as
     730         * x_a == x_m / aValue
     731         */
     732        public SystemOfMeasurement(double aValue, String aName, double bValue, String bName) {
     733            this.aValue = aValue;
     734            this.aName = aName;
     735            this.bValue = bValue;
     736            this.bName = bName;
     737        }
     738
     739        public String getDistText(double dist) {
     740            double a = dist / aValue;
     741            if (a > bValue / aValue) {
     742                double b = dist / bValue;
     743                return String.format(Locale.US, "%." + (b<10 ? 2 : 1) + "f %s", b, bName);
     744            } else if (a < 0.01)
     745                return "< 0.01 " + aName;
     746            else
     747                return String.format(Locale.US, "%." + (a<10 ? 2 : 1) + "f %s", a, aName);
     748        }
     749    }
     750
     751    public static final SystemOfMeasurement METRIC_SOM = new SystemOfMeasurement(1, "m", 1000, "km");
     752    public static final SystemOfMeasurement CHINESE_SOM = new SystemOfMeasurement(1.0/3.0, "\u5e02\u5c3a" /* chi */, 500, "\u5e02\u91cc" /* li */);
     753    public static final SystemOfMeasurement IMPERIAL_SOM = new SystemOfMeasurement(0.9144, "yd.", 1609.344, "mi.");
     754
     755    public static Map<String, SystemOfMeasurement> SYSTEMS_OF_MEASUREMENT;
     756    static {
     757        SYSTEMS_OF_MEASUREMENT = new LinkedHashMap<String, SystemOfMeasurement>();
     758        SYSTEMS_OF_MEASUREMENT.put(marktr("Metric"), METRIC_SOM);
     759        SYSTEMS_OF_MEASUREMENT.put(marktr("Chinese"), CHINESE_SOM);
     760        SYSTEMS_OF_MEASUREMENT.put(marktr("Imperial"), IMPERIAL_SOM);
     761    }
    709762}
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r3246 r3406  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.ActionListener;
     9import java.util.ArrayList;
    910import java.util.Collection;
    1011import java.util.concurrent.CopyOnWriteArrayList;
     
    1617import javax.swing.JPanel;
    1718import javax.swing.JScrollPane;
     19import javax.swing.JSeparator;
    1820
    1921import org.openstreetmap.josm.Main;
     
    2628import org.openstreetmap.josm.data.projection.Projection;
    2729import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;
     30import org.openstreetmap.josm.gui.NavigatableComponent;
    2831import org.openstreetmap.josm.tools.GBC;
    2932
     
    5154        }
    5255    };
     56    private static final StringProperty PROP_SYSTEM_OF_MEASUREMENT = new StringProperty("system_of_measurement", "Metric");
     57    private static final String[] unitsValues = (new ArrayList<String>(NavigatableComponent.SYSTEMS_OF_MEASUREMENT.keySet())).toArray(new String[0]);
     58    private static final String[] unitsValuesTr = new String[unitsValues.length];
     59    static {
     60        for (int i=0; i<unitsValues.length; ++i) {
     61            unitsValuesTr[i] = tr(unitsValues[i]);
     62        }
     63    }
    5364
    5465    //TODO This is not nice place for a listener code but probably only Dataset will want to listen for projection changes so it's acceptable
     
    8091    private JComboBox coordinatesCombo = new JComboBox(CoordinateFormat.values());
    8192
     93    private JComboBox unitsCombo = new JComboBox(unitsValuesTr);
     94
    8295    /**
    8396     * This variable holds the JPanel with the projection's preferences. If the
     
    8699     */
    87100    private JPanel projSubPrefPanel;
     101    private JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout());
    88102
    89103    private JLabel projectionCode = new JLabel();
     
    100114     * in sync
    101115     */
    102     static private GBC projSubPrefPanelGBC = GBC.eol().fill(GBC.BOTH).insets(20,5,5,5);
     116    static private GBC projSubPrefPanelGBC = GBC.std().fill(GBC.BOTH).weight(1.0, 1.0);
    103117
    104118    public void addGui(PreferenceTabbedPane gui) {
     
    112126        }
    113127
     128        for (int i = 0; i < unitsValues.length; ++i) {
     129            if (unitsValues[i].equals(PROP_SYSTEM_OF_MEASUREMENT.get())) {
     130                unitsCombo.setSelectedIndex(i);
     131                break;
     132            }
     133        }
     134
    114135        projPanel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
    115136        projPanel.setLayout(new GridBagLayout());
    116         projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5));
    117         projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    118         projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
    119137        projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5,5,0,5));
    120138        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     
    126144        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
    127145        projPanel.add(bounds, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
    128         projPanel.add(projSubPrefPanel, projSubPrefPanelGBC);
     146        projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC);
     147        projPanel.add(projSubPrefPanelWrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(20,5,5,5));
     148
     149        projPanel.add(new JSeparator(), GBC.eol().fill(GBC.HORIZONTAL).insets(0,5,0,10));
     150        projPanel.add(new JLabel(tr("Display coordinates as")), GBC.std().insets(5,5,0,5));
     151        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     152        projPanel.add(coordinatesCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
     153        projPanel.add(new JLabel(tr("System of measurement")), GBC.std().insets(5,5,0,5));
     154        projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL));
     155        projPanel.add(unitsCombo, GBC.eop().fill(GBC.HORIZONTAL).insets(0,5,5,5));
     156        projPanel.add(GBC.glue(1,1), GBC.std().fill(GBC.HORIZONTAL).weight(1.0, 1.0));
    129157
    130158        JScrollPane scrollpane = new JScrollPane(projPanel);
     
    157185            CoordinateFormat.setCoordinateFormat((CoordinateFormat)coordinatesCombo.getSelectedItem());
    158186        }
     187
     188        int i = unitsCombo.getSelectedIndex();
     189        PROP_SYSTEM_OF_MEASUREMENT.put(unitsValues[i]);
    159190
    160191        return false;
     
    234265
    235266        // Replace old panel with new one
    236         projPanel.remove(size - 1);
    237         projPanel.add(projSubPrefPanel, projSubPrefPanelGBC);
     267        projSubPrefPanelWrapper.removeAll();
     268        projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC);
    238269        projPanel.revalidate();
    239270        projSubPrefPanel.repaint();
Note: See TracChangeset for help on using the changeset viewer.