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