Ignore:
Timestamp:
2017-12-26T17:50:55+01:00 (6 years ago)
Author:
michael2402
Message:

See #15310: Replace use of dx/dy in bookmark loading/storing code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/OffsetBookmark.java

    r12851 r13243  
    1616import org.openstreetmap.josm.data.StructUtils.WriteExplicitly;
    1717import org.openstreetmap.josm.data.coor.EastNorth;
     18import org.openstreetmap.josm.data.coor.ILatLon;
    1819import org.openstreetmap.josm.data.coor.LatLon;
    1920import org.openstreetmap.josm.data.projection.Projection;
     
    4041    @StructEntry private double center_lon, center_lat;
    4142
     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     */
    4248    public boolean isUsable(ImageryLayer layer) {
    4349        if (projection_code == null) return false;
     
    5561    }
    5662
     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     */
    5773    public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy) {
    5874        this(projectionCode, imageryName, name, dx, dy, 0, 0);
    5975    }
    6076
     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     */
    61102    public OffsetBookmark(String projectionCode, String imageryName, String name, double dx, double dy, double centerLon, double centerLat) {
    62103        this.projection_code = projectionCode;
     
    69110    }
    70111
     112    /**
     113     * Loads an old bookmark. For backward compatibility with settings. Do not use.
     114     * @param list The settings that were read
     115     */
    71116    public OffsetBookmark(Collection<String> list) {
    72117        List<String> array = new ArrayList<>(list);
     
    85130    }
    86131
     132    /**
     133     * Get the projection code for which this bookmark was created.
     134     * @return The projection.
     135     */
    87136    public String getProjectionCode() {
    88137        return projection_code;
    89138    }
    90139
     140    /**
     141     * Get the name of this bookmark. This name can e.g. be displayed in menus.
     142     * @return The name
     143     */
    91144    public String getName() {
    92145        return name;
    93146    }
    94147
     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     */
    95152    public String getImageryName() {
    96153        return imagery_name;
     
    149206    }
    150207
     208    /**
     209     * Set the projection code for which this bookmark was created
     210     * @param projectionCode The projection
     211     */
    151212    public void setProjectionCode(String projectionCode) {
    152213        this.projection_code = projectionCode;
    153214    }
    154215
     216    /**
     217     * Set the name of the bookmark
     218     * @param name The name
     219     * @see #getName()
     220     */
    155221    public void setName(String name) {
    156222        this.name = name;
    157223    }
    158224
     225    /**
     226     * Sets the name of the imagery
     227     * @param imageryName The name
     228     * @see #getImageryName()
     229     */
    159230    public void setImageryName(String imageryName) {
    160231        this.imagery_name = imageryName;
    161232    }
    162233
     234    /**
     235     * Update the displacement of this imagery.
     236     * @param displacement The displacement
     237     */
    163238    public void setDisplacement(EastNorth displacement) {
    164239        this.dx = displacement.east();
     
    166241    }
    167242
     243    /**
     244     * Load the global list of bookmarks from preferences.
     245     */
    168246    public static void loadBookmarks() {
    169247        List<OffsetBookmark> bookmarks = StructUtils.getListOfStructs(
     
    184262    }
    185263
     264    /**
     265     * Stores the bookmakrs in the settings.
     266     */
    186267    public static void saveBookmarks() {
    187268        StructUtils.putListOfStructs(Config.getPref(), "imagery.offsetbookmarks", allBookmarks, OffsetBookmark.class);
     
    238319    }
    239320
     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     */
    240327    public static OffsetBookmark getBookmarkByName(ImageryLayer layer, String name) {
    241328        for (OffsetBookmark b : allBookmarks) {
     
    246333    }
    247334
    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) {
    249341        LatLon center;
    250342        if (MainApplication.isDisplayingMapView()) {
     
    255347        OffsetBookmark nb = new OffsetBookmark(
    256348                Main.getProjection().toCode(), layer.getInfo().getName(),
    257                 name, layer.getDisplaySettings().getDx(), layer.getDisplaySettings().getDy(), center.lon(), center.lat());
     349                name, layer.getDisplaySettings().getDisplacement(), center);
    258350        for (ListIterator<OffsetBookmark> it = allBookmarks.listIterator(); it.hasNext();) {
    259351            OffsetBookmark b = it.next();
Note: See TracChangeset for help on using the changeset viewer.