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

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