Changeset 10571 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-07-20T19:34:37+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r10467 r10571 28 28 import org.openstreetmap.josm.data.imagery.OffsetBookmark; 29 29 import org.openstreetmap.josm.gui.ExtendedDialog; 30 import org.openstreetmap.josm.gui.layer.ImageryLayer; 30 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 31 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 31 32 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 32 33 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 42 43 private static Cursor cursor = ImageProvider.getCursor("normal", "move"); 43 44 44 private double oldDx, oldDy;45 private EastNorth old; 45 46 private EastNorth prevEastNorth; 46 private transient ImageryLayerlayer;47 private transient AbstractTileSourceLayer<?> layer; 47 48 private MapMode oldMapMode; 48 49 … … 51 52 * @param layer The imagery layer 52 53 */ 53 public ImageryAdjustAction( ImageryLayerlayer) {54 public ImageryAdjustAction(AbstractTileSourceLayer<?> layer) { 54 55 super(tr("New offset"), "adjustimg", 55 56 tr("Adjust the position of this imagery layer"), Main.map, … … 67 68 layer.setVisible(true); 68 69 } 69 oldDx = layer.getDx(); 70 oldDy = layer.getDy(); 70 old = layer.getDisplaySettings().getDisplacement(); 71 71 addListeners(); 72 72 offsetDialog = new ImageryOffsetDialog(); … … 89 89 if (offsetDialog != null) { 90 90 if (layer != null) { 91 layer. setOffset(oldDx, oldDy);91 layer.getDisplaySettings().setDisplacement(old); 92 92 } 93 93 offsetDialog.setVisible(false); … … 155 155 public void mouseDragged(MouseEvent e) { 156 156 if (layer == null || prevEastNorth == null) return; 157 EastNorth eastNorth = 158 Main.map.mapView.getEastNorth(e.getX(), e.getY()); 159 double dx = layer.getDx()+eastNorth.east()-prevEastNorth.east(); 160 double dy = layer.getDy()+eastNorth.north()-prevEastNorth.north(); 161 layer.setOffset(dx, dy); 157 EastNorth eastNorth = Main.map.mapView.getEastNorth(e.getX(), e.getY()); 158 EastNorth d = layer.getDisplaySettings().getDisplacement().add(eastNorth).subtract(prevEastNorth); 159 layer.getDisplaySettings().setDisplacement(d); 162 160 if (offsetDialog != null) { 163 161 offsetDialog.updateOffset(); … … 234 232 double dx = Double.parseDouble(easting); 235 233 double dy = Double.parseDouble(northing); 236 layer. setOffset(dx, dy);234 layer.getDisplaySettings().setDisplacement(new EastNorth(dx, dy)); 237 235 } catch (NumberFormatException nfe) { 238 236 // we repaint offset numbers in any case … … 259 257 // US locale to force decimal separator to be '.' 260 258 try (Formatter us = new Formatter(Locale.US)) { 259 TileSourceDisplaySettings ds = layer.getDisplaySettings(); 261 260 tOffset.setText(us.format(new StringBuilder() 262 261 .append("%1.").append(precision).append("f; %1.").append(precision).append('f').toString(), 263 layer.getDx(), layer.getDy()).toString());262 ds.getDx(), ds.getDy()).toString()); 264 263 } 265 264 } … … 298 297 if (layer != null) { 299 298 if (getValue() != 1) { 300 layer. setOffset(oldDx, oldDy);299 layer.getDisplaySettings().setDisplacement(old); 301 300 } else if (tBookmarkName.getText() != null && !tBookmarkName.getText().isEmpty()) { 302 301 OffsetBookmark.bookmarkOffset(tBookmarkName.getText(), layer); -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r10568 r10571 64 64 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractTMSTileSource; 65 65 import org.openstreetmap.josm.Main; 66 import org.openstreetmap.josm.actions.ImageryAdjustAction; 66 67 import org.openstreetmap.josm.actions.RenameLayerAction; 67 68 import org.openstreetmap.josm.actions.SaveActionBase; … … 165 166 private final TileSourceDisplaySettings displaySettings = createDisplaySettings(); 166 167 168 private final ImageryAdjustAction adjustAction = new ImageryAdjustAction(this); 169 167 170 /** 168 171 * Creates Tile Source based Imagery Layer based on Imagery Info … … 286 289 } 287 290 291 @Override 292 public double getDx() { 293 return getDisplaySettings().getDx(); 294 } 295 296 @Override 297 public double getDy() { 298 return getDisplaySettings().getDy(); 299 } 300 301 @Override 302 public void displace(double dx, double dy) { 303 getDisplaySettings().addDisplacement(new EastNorth(dx, dy)); 304 } 305 288 306 /** 289 307 * Marks layer as needing redraw on offset change … … 291 309 @Override 292 310 public void setOffset(double dx, double dy) { 293 super.setOffset(dx, dy); 294 needRedraw = true; 295 } 296 311 getDisplaySettings().setDisplacement(new EastNorth(dx, dy)); 312 } 313 314 @Override 315 public Object getInfoComponent() { 316 JPanel panel = (JPanel) super.getInfoComponent(); 317 EastNorth offset = getDisplaySettings().getDisplacement(); 318 if (offset.distanceSq(0, 0) > 1e-10) { 319 panel.add(new JLabel(tr("Offset: ") + offset.east() + ';' + offset.north()), GBC.eol().insets(0, 5, 10, 0)); 320 } 321 return panel; 322 } 323 324 @Override 325 protected Action getAdjustAction() { 326 return adjustAction; 327 } 297 328 298 329 /** … … 1882 1913 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save WMS file"), WMSLayerImporter.FILE_FILTER); 1883 1914 } 1915 1916 @Override 1917 public void destroy() { 1918 super.destroy(); 1919 adjustAction.destroy(); 1920 } 1884 1921 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r10547 r10571 16 16 17 17 import javax.swing.AbstractAction; 18 import javax.swing.Action; 18 19 import javax.swing.Icon; 19 20 import javax.swing.JCheckBoxMenuItem; … … 27 28 28 29 import org.openstreetmap.josm.Main; 29 import org.openstreetmap.josm.actions.ImageryAdjustAction;30 30 import org.openstreetmap.josm.data.ProjectionBounds; 31 31 import org.openstreetmap.josm.data.imagery.ImageryInfo; … … 35 35 import org.openstreetmap.josm.gui.MenuScroller; 36 36 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings; 37 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings; 37 38 import org.openstreetmap.josm.gui.widgets.UrlLabel; 38 39 import org.openstreetmap.josm.tools.GBC; … … 61 62 62 63 protected Icon icon; 63 64 protected double dx;65 protected double dy;66 67 private final ImageryAdjustAction adjustAction = new ImageryAdjustAction(this);68 64 69 65 private final ImageryFilterSettings filterSettings = new ImageryFilterSettings(); … … 96 92 } 97 93 94 /** 95 * Gets the x displacement of this layer. 96 * To be removed end of 2016 97 * @return The x displacement. 98 * @deprecated Use {@link TileSourceDisplaySettings#getDx()} 99 */ 100 @Deprecated 98 101 public double getDx() { 99 return dx; 100 } 101 102 // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate. 103 return 0; 104 } 105 106 /** 107 * Gets the y displacement of this layer. 108 * To be removed end of 2016 109 * @return The y displacement. 110 * @deprecated Use {@link TileSourceDisplaySettings#getDy()} 111 */ 112 @Deprecated 102 113 public double getDy() { 103 return dy; 114 // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate. 115 return 0; 104 116 } 105 117 106 118 /** 107 119 * Sets the displacement offset of this layer. The layer is automatically invalidated. 120 * To be removed end of 2016 108 121 * @param dx The x offset 109 122 * @param dy The y offset 110 */ 123 * @deprecated Use {@link TileSourceDisplaySettings} 124 */ 125 @Deprecated 111 126 public void setOffset(double dx, double dy) { 112 this.dx = dx; 113 this.dy = dy; 114 invalidate(); 115 } 116 127 // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate. 128 } 129 130 /** 131 * To be removed end of 2016 132 * @param dx deprecated 133 * @param dy deprecated 134 * @deprecated Use {@link TileSourceDisplaySettings} 135 */ 136 @Deprecated 117 137 public void displace(double dx, double dy) { 118 this.dx += dx; 119 this.dy += dy; 120 setOffset(this.dx, this.dy); 138 // moved to AbstractTileSourceLayer/TileSourceDisplaySettings. Remains until all actions migrate. 121 139 } 122 140 … … 152 170 panel.add(new JLabel(tr("URL: ")), GBC.std().insets(0, 5, 2, 0)); 153 171 panel.add(new UrlLabel(url), GBC.eol().insets(2, 5, 10, 0)); 154 }155 if (dx != 0 || dy != 0) {156 panel.add(new JLabel(tr("Offset: ") + dx + ';' + dy), GBC.eol().insets(0, 5, 10, 0));157 172 } 158 173 } … … 216 231 217 232 public JComponent getOffsetMenuItem(JComponent subMenu) { 218 JMenuItem adjustMenuItem = new JMenuItem( adjustAction);233 JMenuItem adjustMenuItem = new JMenuItem(getAdjustAction()); 219 234 if (OffsetBookmark.allBookmarks.isEmpty()) return adjustMenuItem; 220 235 … … 228 243 } 229 244 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 230 if (Utils.equalsEpsilon(b.dx, dx) && Utils.equalsEpsilon(b.dy, dy)) {245 if (Utils.equalsEpsilon(b.dx, getDx()) && Utils.equalsEpsilon(b.dy, getDy())) { 231 246 item.setSelected(true); 232 247 } … … 245 260 } 246 261 262 protected abstract Action getAdjustAction(); 263 247 264 /** 248 265 * Gets the settings for the filter that is applied to this layer. … … 314 331 return img; 315 332 } 316 317 @Override318 public void destroy() {319 super.destroy();320 adjustAction.destroy();321 }322 333 } -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r10568 r10571 7 7 import org.openstreetmap.gui.jmapviewer.interfaces.TileSource; 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.data.coor.EastNorth; 9 10 import org.openstreetmap.josm.data.preferences.BooleanProperty; 10 11 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 12 import org.openstreetmap.josm.tools.CheckParameterUtil; 13 import org.openstreetmap.josm.tools.bugreport.BugReport; 11 14 12 15 /** … … 36 39 private static final String SHOW_ERRORS = "show-errors"; 37 40 41 private static final String DISPLACEMENT = "displacement"; 42 38 43 private static final String PREFERENCE_PREFIX = "imagery.generic"; 39 44 … … 47 52 */ 48 53 public static final BooleanProperty PROP_AUTO_ZOOM = new BooleanProperty(PREFERENCE_PREFIX + ".default_autozoom", true); 54 49 55 50 56 /** if layers changes automatically, when user zooms in */ … … 54 60 /** if layer should show errors on tiles */ 55 61 private boolean showErrors; 62 63 /** 64 * The displacement 65 */ 66 private EastNorth displacement = new EastNorth(0, 0); 56 67 57 68 private final CopyOnWriteArrayList<DisplaySettingsChangeListener> listeners = new CopyOnWriteArrayList<>(); … … 150 161 151 162 /** 163 * Gets the displacement in x (east) direction 164 * @return The displacement. 165 * @since 10571 166 */ 167 public double getDx() { 168 return displacement.east(); 169 } 170 171 /** 172 * Gets the displacement in y (north) direction 173 * @return The displacement. 174 * @since 10571 175 */ 176 public double getDy() { 177 return displacement.north(); 178 } 179 180 /** 181 * Gets the displacement of the image 182 * @return The displacement. 183 * @since xxx 184 */ 185 public EastNorth getDisplacement() { 186 return displacement; 187 } 188 189 /** 190 * Set the displacement 191 * @param displacement The new displacement 192 * @since xxx 193 */ 194 public void setDisplacement(EastNorth displacement) { 195 CheckParameterUtil.ensureValidCoordinates(displacement, "displacement"); 196 this.displacement = displacement; 197 fireSettingsChange(DISPLACEMENT); 198 } 199 200 /** 201 * Adds the given value to the displacement. 202 * @param displacement The value to add. 203 * @since xxx 204 */ 205 public void addDisplacement(EastNorth displacement) { 206 CheckParameterUtil.ensureValidCoordinates(displacement, "displacement"); 207 setDisplacement(this.displacement.add(displacement)); 208 } 209 210 /** 152 211 * Notifies all listeners that the paint settings have changed 153 212 * @param changedSetting The setting name … … 185 244 data.put(AUTO_ZOOM, Boolean.toString(autoZoom)); 186 245 data.put(SHOW_ERRORS, Boolean.toString(showErrors)); 246 data.put("dx", String.valueOf(getDx())); 247 data.put("dy", String.valueOf(getDy())); 187 248 } 188 249 … … 193 254 */ 194 255 public void loadFrom(Map<String, String> data) { 195 String doAutoLoad = data.get(AUTO_LOAD); 196 if (doAutoLoad != null) { 197 setAutoLoad(Boolean.parseBoolean(doAutoLoad)); 198 } 199 200 String doAutoZoom = data.get(AUTO_ZOOM); 201 if (doAutoZoom != null) { 202 setAutoZoom(Boolean.parseBoolean(doAutoZoom)); 203 } 204 205 String doShowErrors = data.get(SHOW_ERRORS); 206 if (doShowErrors != null) { 207 setShowErrors(Boolean.parseBoolean(doShowErrors)); 256 try { 257 String doAutoLoad = data.get(AUTO_LOAD); 258 if (doAutoLoad != null) { 259 setAutoLoad(Boolean.parseBoolean(doAutoLoad)); 260 } 261 262 String doAutoZoom = data.get(AUTO_ZOOM); 263 if (doAutoZoom != null) { 264 setAutoZoom(Boolean.parseBoolean(doAutoZoom)); 265 } 266 267 String doShowErrors = data.get(SHOW_ERRORS); 268 if (doShowErrors != null) { 269 setShowErrors(Boolean.parseBoolean(doShowErrors)); 270 } 271 272 String dx = data.get("dx"); 273 String dy = data.get("dy"); 274 if (dx != null && dy != null) { 275 setDisplacement(new EastNorth(Double.parseDouble(dx), Double.parseDouble(dy))); 276 } 277 } catch (RuntimeException e) { 278 throw BugReport.intercept(e).put("data", data); 208 279 } 209 280 } -
trunk/src/org/openstreetmap/josm/io/session/ImagerySessionImporter.java
r10568 r10571 54 54 tsLayer.getDisplaySettings().loadFrom(attributes); 55 55 } 56 if (attributes.containsKey("dx") && attributes.containsKey("dy")) {57 layer.setOffset(Double.parseDouble(attributes.get("dx")), Double.parseDouble(attributes.get("dy")));58 }59 56 return layer; 60 57 }
Note:
See TracChangeset
for help on using the changeset viewer.