Changeset 6509 in josm


Ignore:
Timestamp:
2013-12-22T18:18:43+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #9459 - initialize default center view of MapView to last download location, if any, instead of (0,0)

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r6380 r6509  
    3131import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    3232import org.openstreetmap.josm.gui.dialogs.ValidatorDialog.ValidatorBoundingXYVisitor;
     33import org.openstreetmap.josm.gui.download.DownloadDialog;
    3334import org.openstreetmap.josm.gui.layer.Layer;
    3435import org.openstreetmap.josm.tools.Shortcut;
     
    244245        }
    245246        else if (mode.equals("download")) {
    246             if (!Main.pref.get("osm-download.bounds").isEmpty()) {
     247            Bounds bounds = DownloadDialog.getSavedDownloadBounds();
     248            if (bounds != null) {
    247249                try {
    248                     v.visit(new Bounds(Main.pref.get("osm-download.bounds"), ";"));
     250                    v.visit(bounds);
    249251                } catch (Exception e) {
    250                     e.printStackTrace();
     252                    Main.warn(e);
    251253                }
    252254            }
  • trunk/src/org/openstreetmap/josm/actions/DownloadAction.java

    r6380 r6509  
    2626 */
    2727public class DownloadAction extends JosmAction {
     28   
     29    /**
     30     * Constructs a new {@code DownloadAction}.
     31     */
    2832    public DownloadAction() {
    2933        super(tr("Download from OSM..."), "download", tr("Download map data from the OSM server."),
  • trunk/src/org/openstreetmap/josm/actions/NewAction.java

    r6380 r6509  
    1313import org.openstreetmap.josm.tools.Shortcut;
    1414
     15/**
     16 * Creates a blank new OSM data layer.
     17 * @since 169
     18 */
    1519public class NewAction extends JosmAction {
    1620
     21    /**
     22     * Constructs a {@code NewAction}.
     23     */
    1724    public NewAction() {
    1825        super(tr("New Layer"), "new", tr("Create a new map layer."),
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r6380 r6509  
    276276     * @return Center of the bounding box.
    277277     */
    278     public LatLon getCenter()
    279     {
     278    public LatLon getCenter() {
    280279        if (crosses180thMeridian()) {           
    281280            double lat = (minLat + maxLat) / 2;
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r6422 r6509  
    4747import org.openstreetmap.josm.data.projection.Projection;
    4848import org.openstreetmap.josm.data.projection.Projections;
     49import org.openstreetmap.josm.gui.download.DownloadDialog;
    4950import org.openstreetmap.josm.gui.help.Helpful;
    5051import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
     
    193194    private Polygon paintPoly = null;
    194195
     196    /**
     197     * Constructs a new {@code NavigatableComponent}.
     198     */
    195199    public NavigatableComponent() {
    196200        setLayout(null);
     
    202206
    203207    private EastNorth calculateDefaultCenter() {
    204         Bounds b = Main.getProjection().getWorldBoundsLatLon();
    205         double lat = (b.getMaxLat() + b.getMinLat())/2;
    206         double lon = (b.getMaxLon() + b.getMinLon())/2;
    207         // FIXME is it correct? b.getCenter() makes some adjustments...
    208         return Main.getProjection().latlon2eastNorth(new LatLon(lat, lon));
     208        Bounds b = DownloadDialog.getSavedDownloadBounds();
     209        if (b == null) {
     210            b = Main.getProjection().getWorldBoundsLatLon();
     211        }
     212        return Main.getProjection().latlon2eastNorth(b.getCenter());
    209213    }
    210214
     
    412416        int width = getWidth()/2;
    413417        int height = getHeight()/2;
     418        if (width == 0 || height == 0) {
     419            throw new IllegalStateException("Cannot zoom into undimensioned NavigatableComponent");
     420        }
    414421        LatLon l1 = new LatLon(b.getMinLat(), lon);
    415422        LatLon l2 = new LatLon(b.getMaxLat(), lon);
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r6380 r6509  
    307307   
    308308    /**
    309      * Remembers the current settings in the download dialog
    310      *
     309     * Remembers the current settings in the download dialog.
    311310     */
    312311    public void rememberSettings() {
     
    320319    }
    321320
     321    /**
     322     * Restores the previous settings in the download dialog.
     323     */
    322324    public void restoreSettings() {
    323325        cbDownloadOsmData.setSelected(Main.pref.getBoolean("download.osm", true));
     
    339341            boundingBoxChanged(currentBounds,null);
    340342        }
    341         else if (!Main.pref.get("osm-download.bounds").isEmpty()) {
    342             // read the bounding box from the preferences
     343        else {
     344            Bounds bounds = getSavedDownloadBounds();
     345            if (bounds != null) {
     346                currentBounds = bounds;
     347                boundingBoxChanged(currentBounds, null);
     348            }
     349        }
     350    }
     351   
     352    /**
     353     * Returns the previously saved bounding box from preferences.
     354     * @return The bounding box saved in preferences if any, {@code null} otherwise
     355     * @since 6509
     356     */
     357    public static Bounds getSavedDownloadBounds() {
     358        String value = Main.pref.get("osm-download.bounds");
     359        if (!value.isEmpty()) {
    343360            try {
    344                 currentBounds = new Bounds(Main.pref.get("osm-download.bounds"), ";");
    345                 boundingBoxChanged(currentBounds,null);
    346             }
    347             catch (Exception e) {
    348                 e.printStackTrace();
    349             }
    350         }
    351     }
    352 
     361                return new Bounds(value, ";");
     362            } catch (IllegalArgumentException e) {
     363                Main.warn(e);
     364            }
     365        }
     366        return null;
     367    }
     368
     369    /**
     370     * Determines if the dialog autorun is enabled in preferences.
     371     * @return {@code true} if the download dialog must be open at startup, {@code false} otherwise
     372     */
    353373    public static boolean isAutorunEnabled() {
    354374        return Main.pref.getBoolean("download.autorun",false);
     
    362382
    363383    /**
    364      * Replies the currently selected download area. May be null, if no download area is selected yet.
     384     * Replies the currently selected download area.
     385     * @return the currently selected download area. May be {@code null}, if no download area is selected yet.
    365386     */
    366387    public Bounds getSelectedDownloadArea() {
Note: See TracChangeset for help on using the changeset viewer.