Changeset 19655 in josm
- Timestamp:
- 2026-10-22T17:13:42+02:00 (3 hours ago)
- Location:
- trunk
- Files:
-
- 6 edited
-
src/org/openstreetmap/josm/actions/AlignGridRotationAction.java (modified) (5 diffs)
-
src/org/openstreetmap/josm/gui/MapFrame.java (modified) (1 diff)
-
src/org/openstreetmap/josm/gui/layer/MapGridPaintable.java (modified) (12 diffs)
-
src/org/openstreetmap/josm/gui/layer/imagery/ShowTileBordersAction.java (modified) (1 diff)
-
src/org/openstreetmap/josm/gui/preferences/display/GridPreference.java (modified) (5 diffs)
-
test/unit/org/openstreetmap/josm/actions/GridActionsTest.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AlignGridRotationAction.java
r19640 r19655 27 27 public class AlignGridRotationAction extends JosmAction { 28 28 29 /** returned when the selection does not define a direction */ 30 private static final EastNorth[] EMPTY_DIRECTION = new EastNorth[0]; 31 29 32 /** 30 33 * Constructs a new {@code AlignGridRotationAction}. … … 40 43 * Determines the direction given by the selection: a single way with at least two nodes, or exactly two nodes. 41 44 * @param ds the data set, may be null 42 * @return start and end point, or {@code null}if the selection does not define a direction45 * @return start and end point, or an empty array if the selection does not define a direction 43 46 */ 44 47 static EastNorth[] getSelectedDirection(DataSet ds) { 45 48 if (ds == null) { 46 return null;49 return EMPTY_DIRECTION; 47 50 } 48 51 Collection<Way> ways = ds.getSelectedWays(); … … 62 65 } 63 66 if (a == null || b == null || !a.isLatLonKnown() || !b.isLatLonKnown()) { 64 return null;67 return EMPTY_DIRECTION; 65 68 } 66 69 EastNorth[] result = {a.getEastNorth(), b.getEastNorth()}; 67 return result[0].equalsEpsilon(result[1], 1e-9) ? null: result;70 return result[0].equalsEpsilon(result[1], 1e-9) ? EMPTY_DIRECTION : result; 68 71 } 69 72 … … 86 89 @Override 87 90 protected void updateEnabledState() { 88 setEnabled(getSelectedDirection(getLayerManager().getEditDataSet()) != null);91 setEnabled(getSelectedDirection(getLayerManager().getEditDataSet()).length == 2); 89 92 } 90 93 … … 97 100 public void actionPerformed(ActionEvent e) { 98 101 EastNorth[] direction = getSelectedDirection(getLayerManager().getEditDataSet()); 99 if (direction == null) {102 if (direction.length != 2) { 100 103 return; 101 104 } -
trunk/src/org/openstreetmap/josm/gui/MapFrame.java
r19640 r19655 125 125 public final MapView mapView; 126 126 /** The grid drawn over the map view, see {@link MapGridPaintable} */ 127 private final MapGridPaintable gridOverlay = new MapGridPaintable(); 127 private final transient MapGridPaintable gridOverlay = new MapGridPaintable(); 128 128 129 129 /** -
trunk/src/org/openstreetmap/josm/gui/layer/MapGridPaintable.java
r19640 r19655 13 13 import java.util.ArrayList; 14 14 import java.util.List; 15 import java.util.concurrent.atomic.AtomicReference; 15 16 16 17 import org.openstreetmap.josm.data.Bounds; 17 18 import org.openstreetmap.josm.data.ProjectionBounds; 18 19 import org.openstreetmap.josm.data.coor.EastNorth; 19 import org.openstreetmap.josm.data.coor.ILatLon;20 20 import org.openstreetmap.josm.data.coor.LatLon; 21 21 import org.openstreetmap.josm.data.preferences.BooleanProperty; … … 138 138 139 139 /** written by {@link #paint} and read by {@link #preferenceChanged}, which may run on another thread */ 140 private volatileMapView mapView;140 private final AtomicReference<MapView> mapView = new AtomicReference<>(); 141 141 142 142 /** … … 149 149 @Override 150 150 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 151 mapView = mv;151 mapView.set(mv); 152 152 if (!Boolean.TRUE.equals(ENABLED.get()) || mv.getWidth() <= 0 || mv.getHeight() <= 0) { 153 153 return; … … 319 319 return 1; 320 320 } 321 double metres = a.greatCircleDistance( (ILatLon)b);321 double metres = a.greatCircleDistance(b); 322 322 return metres > 0 && Double.isFinite(metres) ? step / metres : 1; 323 323 } catch (IllegalArgumentException e) { … … 358 358 double rotationDegrees, double originX, double originY) { 359 359 List<ProjectedGridLine> lines = new ArrayList<>(); 360 if (!(spacingX > 0) || !(spacingY> 0)) {360 if (!isPositive(spacingX) || !isPositive(spacingY)) { 361 361 return lines; 362 362 } … … 421 421 double originLon, double originLat, int segments) { 422 422 List<LatLonGridLine> lines = new ArrayList<>(); 423 if (!(spacingLon > 0) || !(spacingLat> 0) || segments < 1) {423 if (!isPositive(spacingLon) || !isPositive(spacingLat) || segments < 1) { 424 424 return lines; 425 425 } … … 446 446 for (long k = kLonMin; k <= kLonMax; k++) { 447 447 double lon = LatLon.toIntervalLon(originLon + k * spacingLon); 448 if (limitedLon && (lon < world.getMinLon() || lon > world.getMaxLon())) { 449 continue; 450 } 451 List<LatLon> line = new ArrayList<>(segments + 1); 452 for (int i = 0; i <= segments; i++) { 453 line.add(new LatLon(minLat + (maxLat - minLat) * i / segments, lon)); 454 } 455 lines.add(new LatLonGridLine(line, true)); 448 if (!limitedLon || (lon >= world.getMinLon() && lon <= world.getMaxLon())) { 449 addMeridian(lines, lon, minLat, maxLat, segments); 450 } 456 451 } 457 452 for (long k = kLatMin; k <= kLatMax; k++) { … … 463 458 } 464 459 return lines; 460 } 461 462 /** 463 * Adds a meridian running from one latitude to another. 464 * @param lines the list to add to 465 * @param lon the longitude of the meridian 466 * @param minLat the latitude to start at 467 * @param maxLat the latitude to end at 468 * @param segments number of segments of the polyline 469 */ 470 private static void addMeridian(List<LatLonGridLine> lines, double lon, double minLat, double maxLat, int segments) { 471 List<LatLon> line = new ArrayList<>(segments + 1); 472 for (int i = 0; i <= segments; i++) { 473 line.add(new LatLon(minLat + (maxLat - minLat) * i / segments, lon)); 474 } 475 lines.add(new LatLonGridLine(line, true)); 465 476 } 466 477 … … 481 492 return; 482 493 } 483 if ( !(maxLon>minLon)) {494 if (maxLon <= minLon) { 484 495 return; 485 496 } … … 489 500 } 490 501 lines.add(new LatLonGridLine(line, false)); 502 } 503 504 /** 505 * Determines if a value is strictly positive. Unlike {@code value <= 0}, this rejects NaN. 506 * @param value the value 507 * @return {@code true} if the value is greater than 0 508 */ 509 private static boolean isPositive(double value) { 510 return value > 0; 491 511 } 492 512 … … 495 515 if (e.getKey().startsWith(PREFIX) || e.getKey().equals(COLOR_EAST.getKey()) || e.getKey().equals(COLOR_NORTH.getKey())) { 496 516 invalidate(); 497 if (mapView != null) { 498 mapView.repaint(); 517 MapView mv = mapView.get(); 518 if (mv != null) { 519 mv.repaint(); 499 520 } 500 521 } … … 504 525 public void destroy() { 505 526 Config.getPref().removePreferenceChangeListener(this); 506 mapView = null;527 mapView.set(null); 507 528 } 508 529 } -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/ShowTileBordersAction.java
r19640 r19655 21 21 public class ShowTileBordersAction extends AbstractAction implements LayerAction { 22 22 23 private final AbstractTileSourceLayer<?> layer; 23 private final transient AbstractTileSourceLayer<?> layer; 24 24 25 25 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/display/GridPreference.java
r19640 r19655 5 5 6 6 import java.awt.Component; 7 import java.awt.GridBagConstraints; 7 8 import java.awt.GridBagLayout; 8 9 import java.text.DecimalFormat; … … 101 102 panel.add(enabled, GBC.eol().insets(0, 0, 0, 10)); 102 103 panel.add(new JLabel(tr("Grid type")), GBC.std().insets(5, 0, 5, 5)); 103 panel.add(type, GBC.eol().fill(G BC.HORIZONTAL).insets(0, 0, 0, 5));104 panel.add(type, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5)); 104 105 panel.add(spacingXLabel, GBC.std().insets(5, 0, 5, 5)); 105 106 panel.add(spacingX, GBC.eol().insets(0, 0, 0, 5)); … … 117 118 panel.add(lineWidth, GBC.eol().insets(0, 0, 0, 5)); 118 119 panel.add(new JLabel(tr("Blend mode")), GBC.std().insets(5, 0, 5, 5)); 119 panel.add(blendMode, GBC.eol().fill(G BC.HORIZONTAL).insets(0, 0, 0, 5));120 panel.add(GBC.glue(0, 0), GBC.eol().fill(G BC.BOTH));120 panel.add(blendMode, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(0, 0, 0, 5)); 121 panel.add(GBC.glue(0, 0), GBC.eol().fill(GridBagConstraints.BOTH)); 121 122 122 123 createPreferenceTabWithScrollPane(gui, panel); … … 143 144 /** Renders enum values with a translated name */ 144 145 private static final class TranslatedRenderer<T> extends DefaultListCellRenderer { 145 private final Function<T, String> name; 146 private final transient Function<T, String> name; 146 147 147 148 TranslatedRenderer(Function<T, String> name) { … … 179 180 try { 180 181 double value = FORMAT.parse(field.getText().trim()).doubleValue(); 181 if (positive && !(value >0)) {182 if (positive && (Double.isNaN(value) || value <= 0)) { 182 183 Logging.warn("Ignoring invalid grid setting {0}: {1}", property.getKey(), field.getText()); 183 184 return; -
trunk/test/unit/org/openstreetmap/josm/actions/GridActionsTest.java
r19640 r19655 165 165 166 166 ds.setSelected(); 167 assert Null(AlignGridRotationAction.getSelectedDirection(ds));167 assertEquals(0, AlignGridRotationAction.getSelectedDirection(ds).length); 168 168 AlignGridRotationAction action = new AlignGridRotationAction(); 169 169 assertFalse(action.isEnabled()); 170 170 ds.setSelected(a); 171 assert Null(AlignGridRotationAction.getSelectedDirection(ds));171 assertEquals(0, AlignGridRotationAction.getSelectedDirection(ds).length); 172 172 assertFalse(action.isEnabled()); 173 173 ds.setSelected(a, b, c); 174 assert Null(AlignGridRotationAction.getSelectedDirection(ds));174 assertEquals(0, AlignGridRotationAction.getSelectedDirection(ds).length); 175 175 assertFalse(action.isEnabled()); 176 176
Note:
See TracChangeset
for help on using the changeset viewer.
