source: josm/trunk/src/org/openstreetmap/josm/gui/MapScaler.java@ 1480

Last change on this file since 1480 was 1274, checked in by ulfl, 15 years ago

start to show km for the map scaler at >= 2000 meters, the "1km" display is otherwise a bit course - this wasn't a problem with slow mappaint display before as no one noticed it ;-)

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. See LICENSE file for details.
2
3package org.openstreetmap.josm.gui;
4
5import static org.openstreetmap.josm.tools.I18n.marktr;
6
7import java.awt.Color;
8import java.awt.Graphics;
9import java.awt.geom.Rectangle2D;
10
11import javax.swing.JComponent;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.actions.HelpAction.Helpful;
15import org.openstreetmap.josm.data.coor.LatLon;
16import org.openstreetmap.josm.data.projection.Projection;
17
18public class MapScaler extends JComponent implements Helpful {
19
20 private final NavigatableComponent mv;
21 public MapScaler(NavigatableComponent mv, Projection proj) {
22 this.mv = mv;
23 setSize(100,30);
24 setOpaque(false);
25 }
26
27 @Override public void paint(Graphics g) {
28 LatLon ll1 = mv.getLatLon(0,0);
29 LatLon ll2 = mv.getLatLon(100,0);
30 double dist = ll1.greatCircleDistance(ll2);
31 String text = dist >= 2000 ? Math.round(dist/100)/10 +" km" : (dist >= 1
32 ? Math.round(dist*10)/10 +" m" : "< 1 m");
33 Rectangle2D bound = g.getFontMetrics().getStringBounds(text, g);
34 g.setColor(getColor());
35 g.drawLine(0, 5, 99, 5);
36 g.drawLine(0, 0, 0, 10);
37 g.drawLine(99, 0, 99, 10);
38 g.drawLine(49, 0, 49, 10);
39 g.drawLine(24, 3, 24, 7);
40 g.drawLine(74, 3, 74, 7);
41 g.drawString(text, (int)(100-bound.getWidth()), 23);
42 g.drawString("0", 0, 23);
43 }
44
45 static public Color getColor()
46 {
47 return Main.pref.getColor(marktr("scale"), Color.white);
48 }
49
50 public String helpTopic() {
51 return "MapView/Scaler";
52 }
53}
Note: See TracBrowser for help on using the repository browser.