Changeset 12093 in josm
- Timestamp:
- 2017-05-10T12:22:20+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r11713 r12093 26 26 import org.openstreetmap.josm.actions.mapmode.MapMode; 27 27 import org.openstreetmap.josm.data.coor.EastNorth; 28 import org.openstreetmap.josm.data.coor.LatLon; 28 29 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 29 30 import org.openstreetmap.josm.gui.ExtendedDialog; … … 43 44 private static Cursor cursor = ImageProvider.getCursor("normal", "move"); 44 45 45 private EastNorth old; 46 private OffsetBookmark old; 47 private OffsetBookmark tempOffset; 46 48 private EastNorth prevEastNorth; 47 49 private transient AbstractTileSourceLayer<?> layer; … … 66 68 layer.setVisible(true); 67 69 } 68 old = layer.getDisplaySettings().getDisplacement(); 70 old = layer.getDisplaySettings().getOffsetBookmark(); 71 EastNorth curOff = old == null ? EastNorth.ZERO : old.getDisplacement(Main.getProjection()); 72 LatLon center; 73 if (Main.isDisplayingMapView()) { 74 center = Main.getProjection().eastNorth2latlon(Main.map.mapView.getCenter()); 75 } else { 76 center = LatLon.ZERO; 77 } 78 tempOffset = new OffsetBookmark( 79 Main.getProjection().toCode(), 80 layer.getInfo().getName(), 81 null, 82 curOff.east(), curOff.north(), center.lon(), center.lat()); 83 layer.getDisplaySettings().setOffsetBookmark(tempOffset); 69 84 addListeners(); 70 85 showOffsetDialog(new ImageryOffsetDialog()); … … 96 111 if (offsetDialog != null) { 97 112 if (layer != null) { 98 layer.getDisplaySettings().set Displacement(old);113 layer.getDisplaySettings().setOffsetBookmark(old); 99 114 } 100 115 hideOffsetDialog(); … … 136 151 if (dx != 0 || dy != 0) { 137 152 double ppd = layer.getPPD(); 138 layer.getDisplaySettings().addDisplacement(new EastNorth(dx / ppd, dy / ppd)); 153 EastNorth d = tempOffset.getDisplacement().add(new EastNorth(dx / ppd, dy / ppd)); 154 tempOffset.setDisplacement(d); 155 layer.getDisplaySettings().setOffsetBookmark(tempOffset); 139 156 if (offsetDialog != null) { 140 157 offsetDialog.updateOffset(); … … 163 180 if (layer == null || prevEastNorth == null) return; 164 181 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 165 EastNorth d = layer.getDisplaySettings().getDisplacement().add(eastNorth).subtract(prevEastNorth); 166 layer.getDisplaySettings().setDisplacement(d); 182 EastNorth d = tempOffset.getDisplacement().add(eastNorth).subtract(prevEastNorth); 183 tempOffset.setDisplacement(d); 184 layer.getDisplaySettings().setOffsetBookmark(tempOffset); 167 185 if (offsetDialog != null) { 168 186 offsetDialog.updateOffset(); … … 239 257 double dx = Double.parseDouble(easting); 240 258 double dy = Double.parseDouble(northing); 241 layer.getDisplaySettings().setDisplacement(new EastNorth(dx, dy)); 259 tempOffset.setDisplacement(new EastNorth(dx, dy)); 260 layer.getDisplaySettings().setOffsetBookmark(tempOffset); 242 261 } catch (NumberFormatException nfe) { 243 262 // we repaint offset numbers in any case … … 305 324 if (layer != null) { 306 325 if (getValue() != 1) { 307 layer.getDisplaySettings().set Displacement(old);326 layer.getDisplaySettings().setOffsetBookmark(old); 308 327 } else if (tBookmarkName.getText() != null && !tBookmarkName.getText().isEmpty()) { 309 328 OffsetBookmark.bookmarkOffset(tBookmarkName.getText(), layer); -
trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java
r11844 r12093 15 15 16 16 private static final long serialVersionUID = 1L; 17 18 public static final EastNorth ZERO = new EastNorth(0, 0); 17 19 18 20 /** -
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r12084 r12093 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.Preferences.pref; 14 import org.openstreetmap.josm.data.Preferences.writeExplicitly; 14 15 import org.openstreetmap.josm.data.coor.EastNorth; 15 16 import org.openstreetmap.josm.data.coor.LatLon; 17 import org.openstreetmap.josm.data.projection.Projection; 18 import org.openstreetmap.josm.data.projection.Projections; 16 19 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 17 20 import org.openstreetmap.josm.gui.layer.ImageryLayer; 18 21 22 /** 23 * Class to save a displacement of background imagery as a bookmark. 24 * 25 * Known offset bookmarks will be stored in the preferences and can be 26 * restored by the user in later sessions. 27 */ 19 28 public class OffsetBookmark { 20 29 private static final List<OffsetBookmark> allBookmarks = new ArrayList<>(); … … 23 32 @pref private String imagery_name; 24 33 @pref private String name; 25 @pref private double dx, dy;34 @pref @writeExplicitly private double dx, dy; 26 35 @pref private double center_lon, center_lat; 27 36 28 37 public boolean isUsable(ImageryLayer layer) { 29 38 if (projection_code == null) return false; 30 if (!Main.getProjection().toCode().equals(projection_code) ) return false;39 if (!Main.getProjection().toCode().equals(projection_code) && !hasCenter()) return false; 31 40 return layer.getInfo().getName().equals(imagery_name); 32 41 } … … 83 92 } 84 93 85 public EastNorth getOffset() { 94 /** 95 * Get displacement in EastNorth coordinates of the original projection. 96 * 97 * @see #getProjectionCode() 98 * @return the displacement 99 */ 100 public EastNorth getDisplacement() { 86 101 return new EastNorth(dx, dy); 87 102 } 88 103 104 /** 105 * Get displacement in EastNorth coordinates of a given projection. 106 * 107 * Displacement will be converted to the given projection, with respect to the 108 * center (reference point) of this bookmark. 109 * @param proj the projection 110 * @return the displacement, converted to that projection 111 */ 112 public EastNorth getDisplacement(Projection proj) { 113 if (proj.toCode().equals(projection_code)) { 114 return getDisplacement(); 115 } 116 LatLon center = getCenter(); 117 Projection offsetProj = Projections.getProjectionByCode(projection_code); 118 EastNorth centerEN = offsetProj.latlon2eastNorth(center); 119 EastNorth shiftedEN = centerEN.add(getDisplacement()); 120 LatLon shifted = offsetProj.eastNorth2latlon(shiftedEN); 121 EastNorth centerEN2 = proj.latlon2eastNorth(center); 122 EastNorth shiftedEN2 = proj.latlon2eastNorth(shifted); 123 return shiftedEN2.subtract(centerEN2); 124 } 125 126 /** 127 * Get center/reference point of the bookmark. 128 * 129 * Basically this is the place where it was created and is valid. 130 * The center may be unrecorded (see {@link #hasCenter()), in which 131 * case a dummy center (0,0) will be returned. 132 * @return the center 133 */ 89 134 public LatLon getCenter() { 90 135 return new LatLon(center_lat, center_lon); 91 136 } 92 137 138 /** 139 * Check if bookmark has a valid center. 140 * @return true if bookmark has a valid center 141 */ 142 public boolean hasCenter() { 143 return center_lat != 0 || center_lon != 0; 144 } 145 93 146 public void setProjectionCode(String projectionCode) { 94 147 this.projection_code = projectionCode; … … 103 156 } 104 157 105 public void set Offset(EastNorth offset) {106 this.dx = offset.east();107 this.dy = offset.north();158 public void setDisplacement(EastNorth displacement) { 159 this.dx = displacement.east(); 160 this.dy = displacement.north(); 108 161 } 109 162 -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r12028 r12093 81 81 import org.openstreetmap.josm.data.coor.LatLon; 82 82 import org.openstreetmap.josm.data.imagery.ImageryInfo; 83 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 83 84 import org.openstreetmap.josm.data.imagery.TMSCachedTileLoader; 84 85 import org.openstreetmap.josm.data.imagery.TileLoaderFactory; … … 334 335 @Override 335 336 @Deprecated 336 public void displace(double dx, double dy) { 337 getDisplaySettings().addDisplacement(new EastNorth(dx, dy)); 338 } 339 340 /** 341 * {@inheritDoc} 342 * @deprecated Use {@link TileSourceDisplaySettings} 343 */ 344 @Override 345 @Deprecated 346 public void setOffset(double dx, double dy) { 347 getDisplaySettings().setDisplacement(new EastNorth(dx, dy)); 337 public void setOffset(OffsetBookmark offset) { 338 getDisplaySettings().setOffsetBookmark(offset); 348 339 } 349 340 … … 1856 1847 public void projectionChanged(Projection oldValue, Projection newValue) { 1857 1848 super.projectionChanged(oldValue, newValue); 1849 displaySettings.setOffsetBookmark(displaySettings.getOffsetBookmark()); 1858 1850 if (tileCache != null) { 1859 1851 tileCache.clear(); -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r12085 r12093 31 31 import org.openstreetmap.josm.Main; 32 32 import org.openstreetmap.josm.data.ProjectionBounds; 33 import org.openstreetmap.josm.data.coor.EastNorth; 33 34 import org.openstreetmap.josm.data.imagery.ImageryInfo; 34 35 import org.openstreetmap.josm.data.imagery.OffsetBookmark; … … 108 109 * Sets the displacement offset of this layer. The layer is automatically invalidated. 109 110 * To be removed end of 2016 110 * @param dx The x offset 111 * @param dy The y offset 111 * @param offset the offset bookmark 112 112 * @deprecated Use {@link TileSourceDisplaySettings} 113 113 */ 114 114 @Deprecated 115 public void setOffset(double dx, double dy) { 116 // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate. 117 } 118 119 /** 120 * To be removed end of 2016 121 * @param dx deprecated 122 * @param dy deprecated 123 * @deprecated Use {@link TileSourceDisplaySettings} 124 */ 125 @Deprecated 126 public void displace(double dx, double dy) { 115 public void setOffset(OffsetBookmark offset) { 127 116 // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate. 128 117 } … … 210 199 @Override 211 200 public void actionPerformed(ActionEvent ev) { 212 setOffset(b .getOffset().east(), b.getOffset().north());201 setOffset(b); 213 202 Main.main.menu.imageryMenu.refreshOffsetMenu(); 214 203 Main.map.repaint(); … … 253 242 } 254 243 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 255 if (Utils.equalsEpsilon(b.getOffset().east(), getDx()) &&256 Utils.equalsEpsilon(b.getOffset().north(), getDy())) {244 EastNorth offset = b.getDisplacement(Main.getProjection()); 245 if (Utils.equalsEpsilon(offset.east(), getDx()) && Utils.equalsEpsilon(offset.north(), getDy())) { 257 246 item.setSelected(true); 258 247 } -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r11893 r12093 8 8 import org.openstreetmap.josm.Main; 9 9 import org.openstreetmap.josm.data.coor.EastNorth; 10 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 10 11 import org.openstreetmap.josm.data.preferences.BooleanProperty; 11 12 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; … … 62 63 private boolean showErrors; 63 64 64 /** 65 * The displacement 66 */ 67 private EastNorth displacement = new EastNorth(0, 0); 65 private OffsetBookmark offsetBookmark = null; 66 /** 67 * the displacement (basically caches the displacement from the offsetBookmark 68 * in the current projection) 69 */ 70 private EastNorth displacement = EastNorth.ZERO; 68 71 69 72 private final CopyOnWriteArrayList<DisplaySettingsChangeListener> listeners = new CopyOnWriteArrayList<>(); … … 189 192 190 193 /** 191 * Set the displacement 192 * @param displacement The new displacement 193 * @since 10571 194 */ 195 public void setDisplacement(EastNorth displacement) { 194 * Sets an offset bookmark to use. 195 * 196 * @param offsetBookmark the offset bookmark, may be null 197 */ 198 public void setOffsetBookmark(OffsetBookmark offsetBookmark) { 199 this.offsetBookmark = offsetBookmark; 200 if (offsetBookmark == null) { 201 setDisplacement(EastNorth.ZERO); 202 } else { 203 setDisplacement(offsetBookmark.getDisplacement(Main.getProjection())); 204 } 205 } 206 207 /** 208 * Gets the offset bookmark in use. 209 * @return the offset bookmark, may be null 210 */ 211 public OffsetBookmark getOffsetBookmark() { 212 return this.offsetBookmark; 213 } 214 215 private void setDisplacement(EastNorth displacement) { 196 216 CheckParameterUtil.ensureValidCoordinates(displacement, "displacement"); 197 217 this.displacement = displacement; 198 218 fireSettingsChange(DISPLACEMENT); 199 }200 201 /**202 * Adds the given value to the displacement.203 * @param displacement The value to add.204 * @since 10571205 */206 public void addDisplacement(EastNorth displacement) {207 CheckParameterUtil.ensureValidCoordinates(displacement, "displacement");208 setDisplacement(this.displacement.add(displacement));209 219 } 210 220 -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r12084 r12093 912 912 return info.getName(); 913 913 case 3: 914 return info.get Offset().east();914 return info.getDisplacement().east(); 915 915 case 4: 916 return info.get Offset().north();916 return info.getDisplacement().north(); 917 917 default: 918 918 throw new ArrayIndexOutOfBoundsException(); … … 932 932 case 3: 933 933 double dx = Double.parseDouble((String) o); 934 info.set Offset(new EastNorth(dx, info.getOffset().north()));934 info.setDisplacement(new EastNorth(dx, info.getDisplacement().north())); 935 935 break; 936 936 case 4: 937 937 double dy = Double.parseDouble((String) o); 938 info.set Offset(new EastNorth(info.getOffset().east(), dy));938 info.setDisplacement(new EastNorth(info.getDisplacement().east(), dy)); 939 939 break; 940 940 default:
Note:
See TracChangeset
for help on using the changeset viewer.