Line | |
---|
1 | package org.openstreetmap.josm.gui;
|
---|
2 |
|
---|
3 | import java.awt.Graphics;
|
---|
4 | import java.awt.geom.Rectangle2D;
|
---|
5 |
|
---|
6 | import javax.swing.JComponent;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.actions.HelpAction.Helpful;
|
---|
10 | import org.openstreetmap.josm.tools.ColorHelper;
|
---|
11 |
|
---|
12 | public 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.