Changeset 3406 in josm for trunk/src/org
- Timestamp:
- 2010-08-02T20:00:36+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r3234 r3406 17 17 18 18 private final NavigatableComponent mv; 19 20 private static int PADDING_RIGHT = 100; 21 19 22 public MapScaler(NavigatableComponent mv) { 20 23 this.mv = mv; 21 setSize(100 ,30);24 setSize(100+PADDING_RIGHT,30); 22 25 setOpaque(false); 23 26 } … … 33 36 g.drawLine(24, 3, 24, 7); 34 37 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); 36 39 g.drawString("0", 0, 23); 37 40 } -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r3376 r3406 1 1 // License: GPL. See LICENSE file for details. 2 3 2 package org.openstreetmap.josm.gui; 4 3 … … 101 100 ImageLabel angleText = new ImageLabel("angle", tr("The angle between the previous and the current way segment."), 6); 102 101 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); 104 103 105 104 /** … … 635 634 } 636 635 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)); 639 637 } 640 638 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r3177 r3406 1 1 // License: GPL. See LICENSE file for details. 2 3 2 package org.openstreetmap.josm.gui; 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 5 6 import java.awt.Point; … … 10 11 import java.util.Date; 11 12 import java.util.HashSet; 13 import java.util.LinkedHashMap; 12 14 import java.util.LinkedList; 13 15 import java.util.List; 16 import java.util.Locale; 17 import java.util.Map; 14 18 import java.util.Stack; 15 19 import java.util.TreeMap; … … 111 115 } 112 116 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 113 125 public String getDist100PixelText() 114 126 { 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()); 118 128 } 119 129 … … 707 717 return (int)id.getValue(); 708 718 } 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 } 709 762 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java
r3246 r3406 7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.util.ArrayList; 9 10 import java.util.Collection; 10 11 import java.util.concurrent.CopyOnWriteArrayList; … … 16 17 import javax.swing.JPanel; 17 18 import javax.swing.JScrollPane; 19 import javax.swing.JSeparator; 18 20 19 21 import org.openstreetmap.josm.Main; … … 26 28 import org.openstreetmap.josm.data.projection.Projection; 27 29 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs; 30 import org.openstreetmap.josm.gui.NavigatableComponent; 28 31 import org.openstreetmap.josm.tools.GBC; 29 32 … … 51 54 } 52 55 }; 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 } 53 64 54 65 //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 … … 80 91 private JComboBox coordinatesCombo = new JComboBox(CoordinateFormat.values()); 81 92 93 private JComboBox unitsCombo = new JComboBox(unitsValuesTr); 94 82 95 /** 83 96 * This variable holds the JPanel with the projection's preferences. If the … … 86 99 */ 87 100 private JPanel projSubPrefPanel; 101 private JPanel projSubPrefPanelWrapper = new JPanel(new GridBagLayout()); 88 102 89 103 private JLabel projectionCode = new JLabel(); … … 100 114 * in sync 101 115 */ 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); 103 117 104 118 public void addGui(PreferenceTabbedPane gui) { … … 112 126 } 113 127 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 114 135 projPanel.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 115 136 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));119 137 projPanel.add(new JLabel(tr("Projection method")), GBC.std().insets(5,5,0,5)); 120 138 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); … … 126 144 projPanel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 127 145 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)); 129 157 130 158 JScrollPane scrollpane = new JScrollPane(projPanel); … … 157 185 CoordinateFormat.setCoordinateFormat((CoordinateFormat)coordinatesCombo.getSelectedItem()); 158 186 } 187 188 int i = unitsCombo.getSelectedIndex(); 189 PROP_SYSTEM_OF_MEASUREMENT.put(unitsValues[i]); 159 190 160 191 return false; … … 234 265 235 266 // Replace old panel with new one 236 proj Panel.remove(size - 1);237 proj Panel.add(projSubPrefPanel, projSubPrefPanelGBC);267 projSubPrefPanelWrapper.removeAll(); 268 projSubPrefPanelWrapper.add(projSubPrefPanel, projSubPrefPanelGBC); 238 269 projPanel.revalidate(); 239 270 projSubPrefPanel.repaint();
Note:
See TracChangeset
for help on using the changeset viewer.