Changeset 16894 in josm for trunk/src/org
- Timestamp:
- 2020-08-15T00:15:18+02:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapScaler.java
r12987 r16894 9 9 import java.awt.Graphics; 10 10 import java.awt.geom.Rectangle2D; 11 import java.util.function.DoubleSupplier; 12 import java.util.function.Supplier; 11 13 12 14 import javax.accessibility.Accessible; … … 24 26 public class MapScaler extends JComponent implements Helpful, Accessible { 25 27 26 private final NavigatableComponent mv; 28 private final DoubleSupplier getDist100Pixel; 29 private final Supplier<Color> colorSupplier; 27 30 28 31 private static final int PADDING_LEFT = 5; … … 36 39 */ 37 40 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; 39 52 setPreferredLineLength(100); 40 53 setOpaque(false); … … 51 64 @Override 52 65 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(); 56 68 TickMarks tickMarks = new TickMarks(dist100Pixel, getWidth() - PADDING_LEFT - PADDING_RIGHT); 57 69 tickMarks.paintTicks(g); … … 83 95 @Override 84 96 public Number getCurrentAccessibleValue() { 85 return mv.getDist100Pixel();97 return getDist100Pixel.getAsDouble(); 86 98 } 87 99 -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r16893 r16894 35 35 import org.openstreetmap.josm.data.preferences.StringProperty; 36 36 import org.openstreetmap.josm.gui.MainApplication; 37 import org.openstreetmap.josm.gui.MapScaler; 38 import org.openstreetmap.josm.gui.NavigatableComponent; 37 39 import org.openstreetmap.josm.gui.layer.ImageryLayer; 38 40 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent; … … 119 121 add(iSizeButton); 120 122 123 MapScaler scaler = new MapScaler(this::getDist100Pixel, () -> Color.BLACK); 124 add(scaler); 125 springLayout.putConstraint(SpringLayout.SOUTH, scaler, 5, SpringLayout.SOUTH, this); 126 121 127 String mapStyle = PROP_MAPSTYLE.get(); 122 128 boolean foundSource = false; … … 149 155 LinkedHashMap::new 150 156 )); 157 } 158 159 /** 160 * Get the distance in meter that correspond to 100 px on screen. 161 * @return the distance in meter that correspond to 100 px on screen 162 * @see NavigatableComponent#getDist100Pixel 163 */ 164 private double getDist100Pixel() { 165 int w = getWidth() / 2; 166 int h = getHeight() / 2; 167 ICoordinate c1 = getPosition(w - 50, h); 168 ICoordinate c2 = getPosition(w + 50, h); 169 final LatLon ll1 = new LatLon(c1.getLat(), c1.getLon()); 170 final LatLon ll2 = new LatLon(c2.getLat(), c2.getLon()); 171 double gcd = ll1.greatCircleDistance(ll2); 172 return gcd <= 0 ? 0.1 : gcd; 151 173 } 152 174
Note:
See TracChangeset
for help on using the changeset viewer.