Ignore:
Timestamp:
2020-08-15T00:15:18+02:00 (4 years ago)
Author:
simon04
Message:

fix #4888 - SlippyMapBBoxChooser: show map scale

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapScaler.java

    r12987 r16894  
    99import java.awt.Graphics;
    1010import java.awt.geom.Rectangle2D;
     11import java.util.function.DoubleSupplier;
     12import java.util.function.Supplier;
    1113
    1214import javax.accessibility.Accessible;
     
    2426public class MapScaler extends JComponent implements Helpful, Accessible {
    2527
    26     private final NavigatableComponent mv;
     28    private final DoubleSupplier getDist100Pixel;
     29    private final Supplier<Color> colorSupplier;
    2730
    2831    private static final int PADDING_LEFT = 5;
     
    3639     */
    3740    public MapScaler(NavigatableComponent mv) {
    38         this.mv = mv;
     41        this(() -> mv.getDist100Pixel(true), MapScaler::getColor);
     42    }
     43
     44    /**
     45     * Constructs a new {@code MapScaler}.
     46     * @param getDist100Pixel supplier for distance in meter that correspond to 100 px on screen
     47     * @param colorSupplier supplier for color
     48     */
     49    public MapScaler(DoubleSupplier getDist100Pixel, Supplier<Color> colorSupplier) {
     50        this.getDist100Pixel = getDist100Pixel;
     51        this.colorSupplier = colorSupplier;
    3952        setPreferredLineLength(100);
    4053        setOpaque(false);
     
    5164    @Override
    5265    public void paint(Graphics g) {
    53         g.setColor(getColor());
    54 
    55         double dist100Pixel = mv.getDist100Pixel(true);
     66        g.setColor(colorSupplier.get());
     67        double dist100Pixel = getDist100Pixel.getAsDouble();
    5668        TickMarks tickMarks = new TickMarks(dist100Pixel, getWidth() - PADDING_LEFT - PADDING_RIGHT);
    5769        tickMarks.paintTicks(g);
     
    8395        @Override
    8496        public Number getCurrentAccessibleValue() {
    85             return mv.getDist100Pixel();
     97            return getDist100Pixel.getAsDouble();
    8698        }
    8799
Note: See TracChangeset for help on using the changeset viewer.