- Timestamp:
- 2017-12-26T17:50:55+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
r13050 r13243 33 33 import org.openstreetmap.josm.gui.MapView; 34 34 import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer; 35 import org.openstreetmap.josm.gui.layer.imagery.TileSourceDisplaySettings;36 35 import org.openstreetmap.josm.gui.util.WindowGeometry; 37 36 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; … … 86 85 layer.getInfo().getName(), 87 86 null, 88 curOff .east(), curOff.north(), center.lon(), center.lat());87 curOff, center); 89 88 layer.getDisplaySettings().setOffsetBookmark(tempOffset); 90 89 addListeners(); … … 293 292 // US locale to force decimal separator to be '.' 294 293 try (Formatter us = new Formatter(Locale.US)) { 295 TileSourceDisplaySettings ds = layer.getDisplaySettings();294 EastNorth displacement = layer.getDisplaySettings().getDisplacement(); 296 295 tOffset.setText(us.format(new StringBuilder() 297 296 .append("%1.").append(precision).append("f; %1.").append(precision).append('f').toString(), 298 d s.getDx(), ds.getDy()).toString());297 displacement.east(), displacement.north()).toString()); 299 298 } 300 299 } -
trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java
r12851 r13243 16 16 import org.openstreetmap.josm.data.StructUtils.WriteExplicitly; 17 17 import org.openstreetmap.josm.data.coor.EastNorth; 18 import org.openstreetmap.josm.data.coor.ILatLon; 18 19 import org.openstreetmap.josm.data.coor.LatLon; 19 20 import org.openstreetmap.josm.data.projection.Projection; … … 40 41 @StructEntry private double center_lon, center_lat; 41 42 43 /** 44 * Test if an image is usable for the given imagery layer. 45 * @param layer The layer to use the image at 46 * @return <code>true</code> if it is usable on the projection of the layer and the imagery name matches. 47 */ 42 48 public boolean isUsable(ImageryLayer layer) { 43 49 if (projection_code == null) return false; … … 55 61 } 56 62 63 /** 64 * Create a new {@link OffsetBookmark} object using (0, 0) as center 65 * <p> 66 * The use of the {@link #OffsetBookmark(String, String, String, EastNorth, ILatLon)} constructor is preferred. 67 * @param projectionCode The projection for which this object was created 68 * @param imageryName The name of the imagery on the layer 69 * @param name The name of the new bookmark 70 * @param dx The x displacement 71 * @param dy The y displacement 72 */ 57 73 public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy) { 58 74 this(projectionCode, imageryName, name, dx, dy, 0, 0); 59 75 } 60 76 77 /** 78 * Create a new {@link OffsetBookmark} object 79 * @param projectionCode The projection for which this object was created 80 * @param imageryName The name of the imagery on the layer 81 * @param name The name of the new bookmark 82 * @param displacement The displacement in east/north space. 83 * @param center The point on earth that was used as reference to align the image. 84 * @since 13243 85 */ 86 public OffsetBookmark(String projectionCode, String imageryName, String name, EastNorth displacement, ILatLon center) { 87 this(projectionCode, imageryName, name, displacement.east(), displacement.north(), center.lon(), center.lat()); 88 } 89 90 /** 91 * Create a new {@link OffsetBookmark} by specifying all values. 92 * <p> 93 * The use of the {@link #OffsetBookmark(String, String, String, EastNorth, ILatLon)} constructor is preferred. 94 * @param projectionCode The projection for which this object was created 95 * @param imageryName The name of the imagery on the layer 96 * @param name The name of the new bookmark 97 * @param dx The x displacement 98 * @param dy The y displacement 99 * @param centerLon The point on earth that was used as reference to align the image. 100 * @param centerLat The point on earth that was used as reference to align the image. 101 */ 61 102 public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy, double centerLon, double centerLat) { 62 103 this.projection_code = projectionCode; … … 69 110 } 70 111 112 /** 113 * Loads an old bookmark. For backward compatibility with settings. Do not use. 114 * @param list The settings that were read 115 */ 71 116 public OffsetBookmark(Collection<String> list) { 72 117 List<String> array = new ArrayList<>(list); … … 85 130 } 86 131 132 /** 133 * Get the projection code for which this bookmark was created. 134 * @return The projection. 135 */ 87 136 public String getProjectionCode() { 88 137 return projection_code; 89 138 } 90 139 140 /** 141 * Get the name of this bookmark. This name can e.g. be displayed in menus. 142 * @return The name 143 */ 91 144 public String getName() { 92 145 return name; 93 146 } 94 147 148 /** 149 * Get the name of the imagery for which this bookmark was created. It is used to match the bookmark to the right layers. 150 * @return The name 151 */ 95 152 public String getImageryName() { 96 153 return imagery_name; … … 149 206 } 150 207 208 /** 209 * Set the projection code for which this bookmark was created 210 * @param projectionCode The projection 211 */ 151 212 public void setProjectionCode(String projectionCode) { 152 213 this.projection_code = projectionCode; 153 214 } 154 215 216 /** 217 * Set the name of the bookmark 218 * @param name The name 219 * @see #getName() 220 */ 155 221 public void setName(String name) { 156 222 this.name = name; 157 223 } 158 224 225 /** 226 * Sets the name of the imagery 227 * @param imageryName The name 228 * @see #getImageryName() 229 */ 159 230 public void setImageryName(String imageryName) { 160 231 this.imagery_name = imageryName; 161 232 } 162 233 234 /** 235 * Update the displacement of this imagery. 236 * @param displacement The displacement 237 */ 163 238 public void setDisplacement(EastNorth displacement) { 164 239 this.dx = displacement.east(); … … 166 241 } 167 242 243 /** 244 * Load the global list of bookmarks from preferences. 245 */ 168 246 public static void loadBookmarks() { 169 247 List<OffsetBookmark> bookmarks = StructUtils.getListOfStructs( … … 184 262 } 185 263 264 /** 265 * Stores the bookmakrs in the settings. 266 */ 186 267 public static void saveBookmarks() { 187 268 StructUtils.putListOfStructs(Config.getPref(), "imagery.offsetbookmarks", allBookmarks, OffsetBookmark.class); … … 238 319 } 239 320 321 /** 322 * Gets a bookmark that is usable on the given layer by it's name. 323 * @param layer The layer to use the bookmark at 324 * @param name The name of the bookmark 325 * @return The bookmark if found, <code>null</code> if not. 326 */ 240 327 public static OffsetBookmark getBookmarkByName(ImageryLayer layer, String name) { 241 328 for (OffsetBookmark b : allBookmarks) { … … 246 333 } 247 334 248 public static void bookmarkOffset(String name, AbstractTileSourceLayer layer) { 335 /** 336 * Add a bookmark for the displacement of that layer 337 * @param name The bookmark name 338 * @param layer The layer to store the bookmark for 339 */ 340 public static void bookmarkOffset(String name, AbstractTileSourceLayer<?> layer) { 249 341 LatLon center; 250 342 if (MainApplication.isDisplayingMapView()) { … … 255 347 OffsetBookmark nb = new OffsetBookmark( 256 348 Main.getProjection().toCode(), layer.getInfo().getName(), 257 name, layer.getDisplaySettings().getD x(), layer.getDisplaySettings().getDy(), center.lon(), center.lat());349 name, layer.getDisplaySettings().getDisplacement(), center); 258 350 for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator(); it.hasNext();) { 259 351 OffsetBookmark b = it.next(); -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractTileSourceLayer.java
r13222 r13243 660 660 break; 661 661 default: 662 // trigger a redraw just to be sure. 662 // e.g. displacement 663 // trigger a redraw in every case 663 664 invalidate(); 664 665 } … … 1922 1923 } 1923 1924 } 1925 1926 @Override 1927 protected List<OffsetMenuEntry> getOffsetMenuEntries() { 1928 return OffsetBookmark.getBookmarks() 1929 .stream() 1930 .filter(b -> b.isUsable(this)) 1931 .map(OffsetMenuBookmarkEntry::new) 1932 .collect(Collectors.toList()); 1933 } 1934 1935 /** 1936 * An entry for a bookmark in the offset menu. 1937 * @author Michael Zangl 1938 */ 1939 private class OffsetMenuBookmarkEntry implements OffsetMenuEntry { 1940 private final OffsetBookmark bookmark; 1941 1942 OffsetMenuBookmarkEntry(OffsetBookmark bookmark) { 1943 this.bookmark = bookmark; 1944 1945 } 1946 1947 @Override 1948 public String getLabel() { 1949 return bookmark.getName(); 1950 } 1951 1952 @Override 1953 public boolean isActive() { 1954 EastNorth offset = bookmark.getDisplacement(Main.getProjection()); 1955 EastNorth active = getDisplaySettings().getDisplacement(); 1956 return Utils.equalsEpsilon(offset.east(), active.east()) && Utils.equalsEpsilon(offset.north(), active.north()); 1957 } 1958 1959 @Override 1960 public void actionPerformed() { 1961 getDisplaySettings().setOffsetBookmark(bookmark); 1962 } 1963 } 1924 1964 } -
trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
r13214 r13243 31 31 import org.openstreetmap.josm.Main; 32 32 import org.openstreetmap.josm.data.ProjectionBounds; 33 import org.openstreetmap.josm.data.coor.EastNorth;34 33 import org.openstreetmap.josm.data.imagery.ImageryInfo; 35 34 import org.openstreetmap.josm.data.imagery.OffsetBookmark; … … 45 44 import org.openstreetmap.josm.tools.ImageProvider; 46 45 import org.openstreetmap.josm.tools.ImageProvider.ImageSizes; 47 import org.openstreetmap.josm.tools.Utils;48 46 49 47 /** … … 54 52 public abstract class ImageryLayer extends Layer { 55 53 54 /** 55 * The default value for the sharpen filter for each imagery layer. 56 */ 56 57 public static final IntegerProperty PROP_SHARPEN_LEVEL = new IntegerProperty("imagery.sharpen_level", 0); 57 58 … … 187 188 } 188 189 190 /** 191 * Create a new imagery layer 192 * @param info The imagery info to use as base 193 * @return The created layer 194 */ 189 195 public static ImageryLayer create(ImageryInfo info) { 190 196 switch(info.getImageryType()) { … … 203 209 204 210 class ApplyOffsetAction extends AbstractAction { 205 private final transient Offset Bookmark b;206 207 ApplyOffsetAction(Offset Bookmark b) {208 super( b.getName());209 this. b = b;211 private final transient OffsetMenuEntry menuEntry; 212 213 ApplyOffsetAction(OffsetMenuEntry menuEntry) { 214 super(menuEntry.getLabel()); 215 this.menuEntry = menuEntry; 210 216 } 211 217 212 218 @Override 213 219 public void actionPerformed(ActionEvent ev) { 214 setOffset(b); 220 menuEntry.actionPerformed(); 221 //TODO: Use some form of listeners for this. 215 222 MainApplication.getMenu().imageryMenu.refreshOffsetMenu(); 216 MainApplication.getMap().repaint();217 223 } 218 224 } … … 235 241 } 236 242 243 /** 244 * Create the menu item that should be added to the offset menu. 245 * It may have a sub menu of e.g. bookmarks added to it. 246 * @return The menu item to add to the imagery menu. 247 */ 237 248 public JMenuItem getOffsetMenuItem() { 238 249 JMenu subMenu = new JMenu(trc("layer", "Offset")); … … 241 252 } 242 253 254 /** 255 * Create the submenu or the menu item to set the offset of the layer. 256 * 257 * If only one menu item for this layer exists, it is returned by this method. 258 * 259 * If there are multiple, this method appends them to the subMenu and then returns the reference to the subMenu. 260 * @param subMenu The subMenu to use 261 * @return A single menu item to adjust the layer or the passed subMenu to which the menu items were appended. 262 */ 243 263 public JComponent getOffsetMenuItem(JComponent subMenu) { 244 264 JMenuItem adjustMenuItem = new JMenuItem(getAdjustAction()); 245 List<OffsetBookmark> allBookmarks = OffsetBookmark.getBookmarks(); 246 if (allBookmarks.isEmpty()) return adjustMenuItem; 265 List<OffsetMenuEntry> usableBookmarks = getOffsetMenuEntries(); 266 if (usableBookmarks.isEmpty()) { 267 return adjustMenuItem; 268 } 247 269 248 270 subMenu.add(adjustMenuItem); 249 271 subMenu.add(new JSeparator()); 250 boolean hasBookmarks = false;251 272 int menuItemHeight = 0; 252 for (OffsetBookmark b : allBookmarks) { 253 if (!b.isUsable(this)) { 254 continue; 255 } 273 for (OffsetMenuEntry b : usableBookmarks) { 256 274 JCheckBoxMenuItem item = new JCheckBoxMenuItem(new ApplyOffsetAction(b)); 257 EastNorth offset = b.getDisplacement(Main.getProjection()); 258 if (Utils.equalsEpsilon(offset.east(), getDx()) && Utils.equalsEpsilon(offset.north(), getDy())) { 259 item.setSelected(true); 260 } 275 item.setSelected(b.isActive()); 261 276 subMenu.add(item); 262 277 menuItemHeight = item.getPreferredSize().height; 263 hasBookmarks = true;264 278 } 265 279 if (menuItemHeight > 0) { … … 270 284 } 271 285 } 272 return hasBookmarks ? subMenu : adjustMenuItem;286 return subMenu; 273 287 } 274 288 275 289 protected abstract Action getAdjustAction(); 290 291 protected abstract List<OffsetMenuEntry> getOffsetMenuEntries(); 276 292 277 293 /** … … 340 356 } 341 357 358 /** 359 * An additional menu entry in the imagery offset menu. 360 * @author Michael Zangl 361 * @since 13243 362 * @see ImageryLayer#getOffsetMenuEntries() 363 */ 364 public static interface OffsetMenuEntry { 365 /** 366 * Get the label to use for this menu item 367 * @return The label to display in the menu. 368 */ 369 String getLabel(); 370 371 /** 372 * Test whether this bookmark is currently active 373 * @return <code>true</code> if it is active 374 */ 375 boolean isActive(); 376 377 /** 378 * Load this bookmark 379 */ 380 void actionPerformed(); 381 } 382 342 383 @Override 343 384 public String toString() { -
trunk/src/org/openstreetmap/josm/gui/layer/imagery/TileSourceDisplaySettings.java
r12846 r13243 171 171 * @return The displacement. 172 172 * @since 10571 173 * @see #getDisplacement() 173 174 */ 174 175 public double getDx() { 175 return displacement.east();176 return getDisplacement().east(); 176 177 } 177 178 … … 180 181 * @return The displacement. 181 182 * @since 10571 183 * @see #getDisplacement() 182 184 */ 183 185 public double getDy() { 184 return displacement.north();186 return getDisplacement().north(); 185 187 } 186 188 … … 195 197 196 198 /** 197 * Sets an offset bookmark to use. 199 * Sets an offset bookmark to use. Loads the displacement from the bookmark. 198 200 * 199 201 * @param offsetBookmark the offset bookmark, may be null
Note:
See TracChangeset
for help on using the changeset viewer.