| 1 | // License: GPL. See LICENSE file for details. |
|---|
| 2 | |
|---|
| 3 | package org.openstreetmap.josm.gui; |
|---|
| 4 | |
|---|
| 5 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht; |
|---|
| 6 | import static org.openstreetmap.josm.tools.I18n.marktr; |
|---|
| 7 | |
|---|
| 8 | import java.awt.Color; |
|---|
| 9 | import java.awt.Graphics; |
|---|
| 10 | import java.awt.geom.Rectangle2D; |
|---|
| 11 | |
|---|
| 12 | import javax.swing.JComponent; |
|---|
| 13 | |
|---|
| 14 | import org.openstreetmap.josm.Main; |
|---|
| 15 | import org.openstreetmap.josm.gui.help.Helpful; |
|---|
| 16 | |
|---|
| 17 | public class MapScaler extends JComponent implements Helpful { |
|---|
| 18 | |
|---|
| 19 | private final NavigatableComponent mv; |
|---|
| 20 | |
|---|
| 21 | private static int PADDING_RIGHT = 100; |
|---|
| 22 | |
|---|
| 23 | public MapScaler(NavigatableComponent mv) { |
|---|
| 24 | this.mv = mv; |
|---|
| 25 | setSize(100+PADDING_RIGHT,30); |
|---|
| 26 | setOpaque(false); |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | @Override public void paint(Graphics g) { |
|---|
| 30 | String text = mv.getDist100PixelText(); |
|---|
| 31 | Rectangle2D bound = g.getFontMetrics().getStringBounds(text, g); |
|---|
| 32 | g.setColor(getColor()); |
|---|
| 33 | g.drawLine(0, 5, 99, 5); |
|---|
| 34 | g.drawLine(0, 0, 0, 10); |
|---|
| 35 | g.drawLine(99, 0, 99, 10); |
|---|
| 36 | g.drawLine(49, 3, 49, 7); |
|---|
| 37 | g.drawLine(24, 3, 24, 7); |
|---|
| 38 | g.drawLine(74, 3, 74, 7); |
|---|
| 39 | g.drawString(text, (int)(100-bound.getWidth()/2), 23); |
|---|
| 40 | g.drawString("0", 0, 23); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | static public Color getColor() |
|---|
| 44 | { |
|---|
| 45 | return Main.pref.getColor(marktr("scale"), Color.white); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | public String helpTopic() { |
|---|
| 49 | return ht("/MapView/Scaler"); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|