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

Last change on this file since 155 was 155, checked in by imi, 18 years ago
  • added online help system
File size: 1.0 KB
Line 
1package org.openstreetmap.josm.gui;
2
3import java.awt.Graphics;
4import java.awt.geom.Rectangle2D;
5
6import javax.swing.JComponent;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.actions.HelpAction.Helpful;
10import org.openstreetmap.josm.tools.ColorHelper;
11
12public class MapScaler extends JComponent implements Helpful {
13
14 private final MapView mv;
15
16 public MapScaler(MapView mv) {
17 this.mv = mv;
18 setSize(100,30);
19 setOpaque(false);
20 }
21
22 @Override public void paint(Graphics g) {
23 double circum = mv.getScale()*100*Main.proj.scaleFactor()*40041455; // circumference of the earth in meter
24 String text = circum > 1000 ? (Math.round(circum/100)/10.0)+"km" : Math.round(circum)+"m";
25 g.setColor(ColorHelper.html2color(Main.pref.get("color.scale", "#ffffff")));
26 g.drawLine(0, 5, 99, 5);
27 g.drawLine(0, 0, 0, 10);
28 g.drawLine(99, 0, 99, 10);
29 Rectangle2D bound = g.getFontMetrics().getStringBounds(text, g);
30 g.drawString(text, (int)(50-bound.getWidth()/2), 23);
31 }
32
33 public String helpTopic() {
34 return "MapView/Scaler";
35 }
36}
Note: See TracBrowser for help on using the repository browser.