Changeset 2327 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2009-10-27T01:21:32+01:00 (14 years ago)
Author:
Gubaer
Message:

Cleanup in download logic (less global, more encapsulation)

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

Legend:

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

    r2322 r2327  
    4141import org.openstreetmap.josm.data.UndoRedoHandler;
    4242import org.openstreetmap.josm.data.coor.CoordinateFormat;
     43import org.openstreetmap.josm.data.coor.LatLon;
    4344import org.openstreetmap.josm.data.osm.DataSet;
    4445import org.openstreetmap.josm.data.osm.PrimitiveDeepCopy;
     
    423424                //DownloadTask osmTask = main.menu.download.downloadTasks.get(0);
    424425                DownloadTask osmTask = new DownloadOsmTask();
    425                 Future<?> future = osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon(), null);
     426                Future<?> future = osmTask.download(main.menu.download, b, null);
    426427                Main.worker.submit(new PostDownloadHandler(osmTask, future));
    427428            }
     
    467468        final StringTokenizer st = new StringTokenizer(s, ",");
    468469        if (st.countTokens() == 4) {
     470            Bounds b = new Bounds(
     471                   new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())),
     472                   new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken()))
     473                   );
    469474            try {
    470475                DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask();
    471476                // asynchronously launch the download task ...
    472                 Future<?> future = task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), null);
     477                Future<?> future = task.download(main.menu.download, b, null);
    473478                // ... and the continuation when the download is finished (this will wait for the download to finish)
    474479                Main.worker.execute(new PostDownloadHandler(task, future));
  • trunk/src/org/openstreetmap/josm/actions/DownloadAction.java

    r2323 r2327  
    22package org.openstreetmap.josm.actions;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    66
    77import java.awt.BorderLayout;
     
    1515
    1616import org.openstreetmap.josm.Main;
    17 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
     17import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
     18import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    1819import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    1920import org.openstreetmap.josm.gui.ExtendedDialog;
     
    3132 */
    3233public class DownloadAction extends JosmAction {
     34   
    3335
    3436    public DownloadDialog dialog;
     37    private ExtendedDialog downloadDialog;
    3538
    3639    public DownloadAction() {
     
    4548     */
    4649    protected ExtendedDialog createUploadDialog() {
    47         dialog = new DownloadDialog();
     50        if (dialog == null)
     51            dialog = new DownloadDialog();
     52        dialog.restoreSettings();
    4853        JPanel downPanel = new JPanel(new BorderLayout());
    4954        downPanel.add(dialog, BorderLayout.CENTER);
     
    5358                new Dimension(1000,600));
    5459
    55         ExtendedDialog dialog = new ExtendedDialog(Main.parent,
     60        if (downloadDialog == null) {
     61            downloadDialog= new ExtendedDialog(Main.parent,
    5662                tr("Download"),
    5763                new String[] {tr("OK"), tr("Cancel")});
    58         dialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */);
    59         dialog.setButtonIcons(new String[] {"ok", "cancel"});
    60         dialog.setRememberWindowGeometry(prefName, wg);
    61         return dialog;
     64            downloadDialog.setContent(downPanel, false /* don't use a scroll pane inside the dialog */);
     65            downloadDialog.setButtonIcons(new String[] {"ok", "cancel"});
     66            downloadDialog.setRememberWindowGeometry(prefName, wg);
     67        }
     68        return downloadDialog;
    6269    }
    6370
     
    6572        ExtendedDialog dlg = createUploadDialog();
    6673        boolean finish = false;
    67         while (!finish) {
     74        while (!finish) {           
    6875            dlg.showDialog();
    69             Main.pref.put("download.newlayer", dialog.newLayer.isSelected());
    7076            if (dlg.getValue() == 1 /* OK */) {
    71                 Main.pref.put("download.tab", Integer.toString(dialog.getSelectedTab()));
    72                 for (DownloadTask task : dialog.downloadTasks) {
    73                     Main.pref.put("download."+task.getPreferencesSuffix(), task.getCheckBox().isSelected());
    74                     if (task.getCheckBox().isSelected()) {
    75                         // asynchronously launch the download task ...
    76                         Future<?> future = task.download(this, dialog.minlat, dialog.minlon, dialog.maxlat, dialog.maxlon, null);
    77                         // ... and the continuation when the download task is finished
    78                         Main.worker.submit(new PostDownloadHandler(task, future));
    79                         finish = true;
    80                     }
     77                dialog.rememberSettings();
     78                if (dialog.isDownloadOsmData()) {
     79                    DownloadOsmTask task = new DownloadOsmTask();
     80                    Future<?> future = task.download(this, dialog.getSelectedDownloadArea(), null);
     81                    Main.worker.submit(new PostDownloadHandler(task, future));
     82                    finish = true;
     83                }
     84                if (dialog.isDownloadGpxData()) {
     85                    DownloadGpsTask task = new DownloadGpsTask();
     86                    Future<?> future = task.download(this,dialog.getSelectedDownloadArea(), null);
     87                    Main.worker.submit(new PostDownloadHandler(task, future));
     88                    finish = true;
    8189                }
    8290            } else {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r2322 r2327  
    77import java.util.concurrent.Future;
    88
    9 import javax.swing.JCheckBox;
    10 
    119import org.openstreetmap.josm.Main;
    1210import org.openstreetmap.josm.actions.DownloadAction;
     11import org.openstreetmap.josm.data.Bounds;
    1312import org.openstreetmap.josm.data.gpx.GpxData;
    1413import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    2221public class DownloadGpsTask extends AbstractDownloadTask {
    2322
    24     private JCheckBox checkBox = new JCheckBox(tr("Raw GPS data"));
    2523    private DownloadTask downloadTask;
    2624
    27     public Future<?> download(DownloadAction action, double minlat, double minlon,
    28             double maxlat, double maxlon, ProgressMonitor progressMonitor) {
    29         downloadTask = new DownloadTask(action.dialog.newLayer.isSelected(),
    30                 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor);
     25    public Future<?> download(DownloadAction action, Bounds downloadArea, ProgressMonitor progressMonitor) {
     26        downloadTask = new DownloadTask(action.dialog.isNewLayerRequired(),
     27                new BoundingBoxDownloader(downloadArea), progressMonitor);
    3128        // We need submit instead of execute so we can wait for it to finish and get the error
    3229        // message if necessary. If no one calls getErrorMessage() it just behaves like execute.
    3330        return Main.worker.submit(downloadTask);
    3431    }
    35 
    36     public JCheckBox getCheckBox() {
    37         return checkBox;
    38     }
    39 
    40     public String getPreferencesSuffix() {
    41         return "gps";
    42     }
    43 
     32   
    4433    public Future<?> loadUrl(boolean a,java.lang.String b,  ProgressMonitor progressMonitor) {
    4534        return null;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r2322 r2327  
    88import java.util.concurrent.Future;
    99import java.util.logging.Logger;
    10 
    11 import javax.swing.JCheckBox;
    1210
    1311import org.openstreetmap.josm.Main;
     
    3836    private DownloadTask downloadTask;
    3937
    40     private JCheckBox checkBox = new JCheckBox(tr("OpenStreetMap data"), true);
    41 
    4238    private void rememberDownloadedData(DataSet ds) {
    4339        this.downloadedData = ds;
     
    4844    }
    4945
    50     public Future<?> download(DownloadAction action, double minlat, double minlon,
    51             double maxlat, double maxlon, ProgressMonitor progressMonitor) {
    52         // Swap min and max if user has specified them the wrong way round
    53         // (easy to do if you are crossing 0, for example)
    54         // FIXME should perhaps be done in download dialog?
    55         if (minlat > maxlat) {
    56             double t = minlat; minlat = maxlat; maxlat = t;
    57         }
    58         if (minlon > maxlon) {
    59             double t = minlon; minlon = maxlon; maxlon = t;
    60         }
    61 
     46    public Future<?> download(DownloadAction action, Bounds downloadArea, ProgressMonitor progressMonitor) {
     47       
    6248        boolean newLayer = action != null
    63         && (action.dialog == null || action.dialog.newLayer.isSelected());
     49        && (action.dialog == null || action.dialog.isNewLayerRequired());
    6450
    6551        downloadTask = new DownloadTask(newLayer,
    66                 new BoundingBoxDownloader(minlat, minlon, maxlat, maxlon), progressMonitor);
    67         currentBounds = new Bounds(new LatLon(minlat, minlon), new LatLon(maxlat, maxlon));
     52                new BoundingBoxDownloader(downloadArea), progressMonitor);
     53        currentBounds = new Bounds(downloadArea);
    6854        // We need submit instead of execute so we can wait for it to finish and get the error
    6955        // message if necessary. If no one calls getErrorMessage() it just behaves like execute.
     
    8268        currentBounds = new Bounds(new LatLon(0,0), new LatLon(0,0));
    8369        return Main.worker.submit(downloadTask);
    84     }
    85 
    86     public JCheckBox getCheckBox() {
    87         return checkBox;
    88     }
    89 
    90     public String getPreferencesSuffix() {
    91         return "osm";
    9270    }
    9371
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskList.java

    r2325 r2327  
    2121import org.openstreetmap.josm.Main;
    2222import org.openstreetmap.josm.actions.UpdateSelectionAction;
     23import org.openstreetmap.josm.data.Bounds;
    2324import org.openstreetmap.josm.data.osm.DataSet;
    2425import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6566            childProgress.setSilent(true);
    6667            childProgress.setCustomText(tr("Download {0} of {1} ({2} left)", i, rects.size(), rects.size() - i));
    67             Future<?> future = dt.download(null, td.getMinY(), td.getMinX(), td.getMaxY(), td.getMaxX(), childProgress);
     68            Future<?> future = dt.download(null, new Bounds(td), childProgress);
    6869            osmTaskFutures.add(future);
    6970            osmTasks.add(dt);
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

    r2322 r2327  
    55import java.util.concurrent.Future;
    66
    7 import javax.swing.JCheckBox;
    8 
    97import org.openstreetmap.josm.actions.DownloadAction;
     8import org.openstreetmap.josm.data.Bounds;
    109import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1110
     
    1615     * if no error messages should be popped up.
    1716     */
    18     Future<?> download(DownloadAction action, double minlat, double minlon,
    19             double maxlat, double maxlon, ProgressMonitor progressMonitor);
     17    Future<?> download(DownloadAction action, Bounds downloadArea, ProgressMonitor progressMonitor);
    2018
    2119    /**
     
    2523     */
    2624    Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);
    27 
    28     /**
    29      * @return The checkbox presented to the user
    30      */
    31     JCheckBox getCheckBox();
    32 
    33     /**
    34      * @return The name of the preferences suffix to use for storing the
    35      * selection state.
    36      */
    37     String getPreferencesSuffix();
    3825
    3926    /**
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/PostDownloadHandler.java

    r2322 r2327  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.util.ArrayList;
    67import java.util.LinkedHashSet;
     8import java.util.List;
    79import java.util.concurrent.Future;
    810
     
    1618public class PostDownloadHandler implements Runnable {
    1719    private DownloadTask task;
    18     private Future<?> future;
     20    private List<Future<?>> futures;
    1921
    2022    /**
     
    2527    public PostDownloadHandler(DownloadTask task, Future<?> future) {
    2628        this.task = task;
    27         this.future = future;
     29        this.futures = new ArrayList<Future<?>>();
     30        if (future != null) {
     31            this.futures.add(future);
     32        }
    2833    }
    2934
     35    /**
     36     * constructor
     37     * @param task the asynchronous download task
     38     * @param future the future on which the completion of the download task can be synchronized
     39     */
     40    public PostDownloadHandler(DownloadTask task, Future<?> ... futures) {
     41        this.task = task;
     42        this.futures = new ArrayList<Future<?>>();
     43        if (futures == null) return;
     44        for (Future<?> future: futures) {
     45            this.futures.add(future);
     46        }
     47    }
     48   
     49
     50    /**
     51     * constructor
     52     * @param task the asynchronous download task
     53     * @param future the future on which the completion of the download task can be synchronized
     54     */
     55    public PostDownloadHandler(DownloadTask task, List<Future<?>> futures) {
     56        this.task = task;
     57        this.futures = new ArrayList<Future<?>>();
     58        if (futures == null) return;
     59        this.futures.addAll(futures);
     60    }
     61   
    3062    public void run() {
    31         // wait for the download task to complete
     63        // wait for all downloads task to finish (by waiting for the futures
     64        // to return a value)
    3265        //
    33         try {
    34             future.get();
    35         } catch(Exception e) {
    36             e.printStackTrace();
    37             return;
     66        for (Future<?> future: futures) {
     67            try {
     68                future.get();
     69            } catch(Exception e) {
     70                e.printStackTrace();
     71                return;
     72            }
    3873        }
    3974
  • trunk/src/org/openstreetmap/josm/data/Bounds.java

    r2017 r2327  
    44import java.awt.geom.Rectangle2D;
    55
     6import org.openstreetmap.josm.Main;
    67import org.openstreetmap.josm.data.coor.LatLon;
     8import static org.openstreetmap.josm.tools.I18n.tr;
    79
    810/**
     
    1618     * The minimum and maximum coordinates.
    1719     */
    18     public LatLon min, max;
     20    private LatLon min, max;
     21   
     22    public LatLon getMin() {
     23        return min;
     24    }
     25
     26    public LatLon getMax() {
     27        return max;
     28    }
    1929
    2030    /**
     
    3040        this.max = b;
    3141    }
     42   
     43    public Bounds(double minlat, double minlon, double maxlat, double maxlon) {
     44        this.min = new LatLon(minlat, minlon);
     45        this.max = new LatLon(maxlat, maxlon);
     46    }
     47   
     48    public Bounds(double [] coords) {
     49        if (coords == null)
     50            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "coords"));
     51        if (coords.length != 4)
     52            throw new IllegalArgumentException(tr("Expected array of length 4, got {0}", coords.length));
     53        this.min = new LatLon(coords[0], coords[1]);
     54        this.max = new LatLon(coords[2], coords[3]);
     55    }
     56   
     57    public Bounds(String asString, String separator) throws IllegalArgumentException {
     58        if (asString == null)
     59            throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null", "asString"));
     60        String[] components = asString.split(separator);
     61        if (components.length != 4) {
     62            throw new IllegalArgumentException(tr("Exactly four doubles excpected in string, got {0}", components.length));
     63        }
     64        double[] values = new double[4];
     65        for (int i=0; i<4; i++) {
     66            try {
     67                values[i] = Double.parseDouble(components[i]);
     68            } catch(NumberFormatException e) {
     69                throw new IllegalArgumentException(tr("Illegal double value ''{0}''", components[i]));
     70            }
     71        }
     72        this.min = new LatLon(values[0], values[1]);
     73        this.max = new LatLon(values[2], values[3]);
     74    }
     75   
     76    public Bounds(Bounds other) {
     77        this.min = new LatLon(other.min);
     78        this.max = new LatLon(other.max);
     79    }
    3280
     81    public Bounds(Rectangle2D rect) {
     82        this.min = new LatLon(rect.getMinY(), rect.getMinX());
     83        this.max = new LatLon(rect.getMaxY(), rect.getMaxX());
     84    }
     85   
    3386    @Override public String toString() {
    3487        return "Bounds["+min.lat()+","+min.lon()+","+max.lat()+","+max.lon()+"]";
     
    70123        return new Rectangle2D.Double(min.lon(), min.lat(), max.lon()-min.lon(), max.lat()-min.lat());
    71124    }
     125   
     126    public double getArea() {
     127        return (max.lon() - min.lon()) * (max.lat() - min.lat());
     128    }
     129
     130    public String encodeAsString(String separator) {
     131        StringBuffer sb = new StringBuffer();
     132        sb.append(min.lat()).append(separator).append(min.lon())
     133        .append(separator).append(max.lat()).append(separator)
     134        .append(max.lon());
     135        return sb.toString();
     136    }
     137   
     138    @Override
     139    public int hashCode() {
     140        final int prime = 31;
     141        int result = 1;
     142        result = prime * result + ((max == null) ? 0 : max.hashCode());
     143        result = prime * result + ((min == null) ? 0 : min.hashCode());
     144        return result;
     145    }
     146
     147    @Override
     148    public boolean equals(Object obj) {
     149        if (this == obj)
     150            return true;
     151        if (obj == null)
     152            return false;
     153        if (getClass() != obj.getClass())
     154            return false;
     155        Bounds other = (Bounds) obj;
     156        if (max == null) {
     157            if (other.max != null)
     158                return false;
     159        } else if (!max.equals(other.max))
     160            return false;
     161        if (min == null) {
     162            if (other.min != null)
     163                return false;
     164        } else if (!min.equals(other.min))
     165            return false;
     166        return true;
     167    }
    72168
    73169}
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r2224 r2327  
    6262        public String name;
    6363        public double[] latlon = new double[4]; // minlat, minlon, maxlat, maxlon
     64       
     65        public Bookmark() {           
     66        }
     67       
     68        public Bookmark(Bounds b) {
     69            if (b == null) {
     70                latlon[0] = 0.0;
     71                latlon[1] = 0.0;
     72                latlon[2] = 0.0;
     73                latlon[3] = 0.0;
     74            } else {
     75                latlon[0] = b.getMin().lat();
     76                latlon[1] = b.getMin().lon();
     77                latlon[2] = b.getMax().lat();
     78                latlon[3] = b.getMax().lon();
     79            }
     80        }
     81       
    6482        @Override public String toString() {
    6583            return name;
    6684        }
     85               
    6786        public int compareTo(Bookmark b) {
    6887            return name.toLowerCase().compareTo(b.name.toLowerCase());
     88        }
     89       
     90        public Bounds asBounds() {
     91            return new Bounds(latlon[0], latlon[1], latlon[2], latlon[3]);
    6992        }
    7093    }
  • trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java

    r1169 r2327  
    4545    }
    4646
     47    @Override
     48    public int hashCode() {
     49        final int prime = 31;
     50        int result = super.hashCode();
     51        long temp;
     52        temp = java.lang.Double.doubleToLongBits(x);
     53        result = prime * result + (int) (temp ^ (temp >>> 32));
     54        temp = java.lang.Double.doubleToLongBits(y);
     55        result = prime * result + (int) (temp ^ (temp >>> 32));
     56        return result;
     57    }
     58
     59    @Override
     60    public boolean equals(Object obj) {
     61        if (this == obj)
     62            return true;
     63        if (!super.equals(obj))
     64            return false;
     65        if (getClass() != obj.getClass())
     66            return false;
     67        Coordinate other = (Coordinate) obj;
     68        if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x))
     69            return false;
     70        if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y))
     71            return false;
     72        return true;
     73    }
    4774}
  • trunk/src/org/openstreetmap/josm/data/coor/LatLon.java

    r2174 r2327  
    9090    public boolean isOutSideWorld() {
    9191        Bounds b = Main.proj.getWorldBoundsLatLon();
    92         return lat() < b.min.lat() || lat() > b.max.lat() ||
    93         lon() < b.min.lon() || lon() > b.max.lon();
     92        return lat() < b.getMin().lat() || lat() > b.getMax().lat() ||
     93        lon() < b.getMin().lon() || lon() > b.getMax().lon();
    9494    }
    9595
     
    9898     */
    9999    public boolean isWithin(Bounds b) {
    100         return lat() >= b.min.lat() && lat() <= b.max.lat() && lon() > b.min.lon() && lon() < b.max.lon();
     100        return lat() >= b.getMin().lat() && lat() <= b.getMax().lat() && lon() > b.getMin().lon() && lon() < b.getMax().lon();
    101101    }
    102102
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r1946 r2327  
    4545        if(b != null)
    4646        {
    47             visit(b.min);
    48             visit(b.max);
     47            visit(b.getMin());
     48            visit(b.getMax());
    4949        }
    5050    }
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r2192 r2327  
    369369        tempG.setColor(Color.WHITE);
    370370        Bounds b = getProjection().getWorldBoundsLatLon();
    371         double lat = b.min.lat();
    372         double lon = b.min.lon();
    373 
    374         Point p = getPoint(b.min);
     371        double lat = b.getMin().lat();
     372        double lon = b.getMin().lon();
     373
     374        Point p = getPoint(b.getMin());
    375375
    376376        GeneralPath path = new GeneralPath();
    377377
    378378        path.moveTo(p.x, p.y);
    379         double max = b.max.lat();
     379        double max = b.getMax().lat();
    380380        for(; lat <= max; lat += 1.0)
    381381        {
     
    383383            path.lineTo(p.x, p.y);
    384384        }
    385         lat = max; max = b.max.lon();
     385        lat = max; max = b.getMax().lon();
    386386        for(; lon <= max; lon += 1.0)
    387387        {
     
    389389            path.lineTo(p.x, p.y);
    390390        }
    391         lon = max; max = b.min.lat();
     391        lon = max; max = b.getMin().lat();
    392392        for(; lat >= max; lat -= 1.0)
    393393        {
     
    395395            path.lineTo(p.x, p.y);
    396396        }
    397         lat = max; max = b.min.lon();
     397        lat = max; max = b.getMin().lon();
    398398        for(; lon >= max; lon -= 1.0)
    399399        {
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r2273 r2327  
    6060    private EastNorth calculateDefaultCenter() {
    6161        Bounds b = Main.proj.getWorldBoundsLatLon();
    62         double lat = (b.max.lat() + b.min.lat())/2;
    63         double lon = (b.max.lon() + b.min.lon())/2;
     62        double lat = (b.getMax().lat() + b.getMin().lat())/2;
     63        double lon = (b.getMax().lon() + b.getMin().lon())/2;
    6464
    6565        return Main.proj.latlon2eastNorth(new LatLon(lat, lon));
     
    128128    public ProjectionBounds getMaxProjectionBounds() {
    129129        Bounds b = getProjection().getWorldBoundsLatLon();
    130         return new ProjectionBounds(getProjection().latlon2eastNorth(b.min),
    131                 getProjection().latlon2eastNorth(b.max));
     130        return new ProjectionBounds(getProjection().latlon2eastNorth(b.getMin()),
     131                getProjection().latlon2eastNorth(b.getMax()));
    132132    }
    133133
     
    193193        double lat = cl.lat();
    194194        double lon = cl.lon();
    195         if(lat < b.min.lat()) {changed = true; lat = b.min.lat(); }
    196         else if(lat > b.max.lat()) {changed = true; lat = b.max.lat(); }
    197         if(lon < b.min.lon()) {changed = true; lon = b.min.lon(); }
    198         else if(lon > b.max.lon()) {changed = true; lon = b.max.lon(); }
     195        if(lat < b.getMin().lat()) {changed = true; lat = b.getMin().lat(); }
     196        else if(lat > b.getMax().lat()) {changed = true; lat = b.getMax().lat(); }
     197        if(lon < b.getMin().lon()) {changed = true; lon = b.getMin().lon(); }
     198        else if(lon > b.getMax().lon()) {changed = true; lon = b.getMax().lon(); }
    199199        if(changed) {
    200200            newCenter = new CachedLatLon(lat, lon).getEastNorth();
     
    209209        int width = getWidth()/2;
    210210        int height = getHeight()/2;
    211         LatLon l1 = new LatLon(b.min.lat(), lon);
    212         LatLon l2 = new LatLon(b.max.lat(), lon);
     211        LatLon l1 = new LatLon(b.getMin().lat(), lon);
     212        LatLon l2 = new LatLon(b.getMax().lat(), lon);
    213213        EastNorth e1 = getProjection().latlon2eastNorth(l1);
    214214        EastNorth e2 = getProjection().latlon2eastNorth(l2);
     
    217217        {
    218218            double newScaleH = d/height;
    219             e1 = getProjection().latlon2eastNorth(new LatLon(lat, b.min.lon()));
    220             e2 = getProjection().latlon2eastNorth(new LatLon(lat, b.max.lon()));
     219            e1 = getProjection().latlon2eastNorth(new LatLon(lat, b.getMin().lon()));
     220            e2 = getProjection().latlon2eastNorth(new LatLon(lat, b.getMax().lon()));
    221221            d = e2.east() - e1.east();
    222222            if(d < width*newScale) {
     
    292292
    293293    public void zoomTo(Bounds box) {
    294         zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.min),
    295                 getProjection().latlon2eastNorth(box.max)));
     294        zoomTo(new ProjectionBounds(getProjection().latlon2eastNorth(box.getMin()),
     295                getProjection().latlon2eastNorth(box.getMax())));
    296296    }
    297297
  • trunk/src/org/openstreetmap/josm/gui/download/BookmarkSelection.java

    r2142 r2327  
    88import java.awt.event.ActionEvent;
    99import java.awt.event.ActionListener;
    10 import java.awt.event.MouseAdapter;
    11 import java.awt.event.MouseEvent;
    12 import java.awt.event.MouseListener;
    1310
    1411import javax.swing.DefaultListModel;
     
    4239
    4340        JPanel dlg = new JPanel(new GridBagLayout());
    44         gui.tabpane.addTab(tr("Bookmarks"), dlg);
     41        gui.addDownloadAreaSelector(dlg, tr("Bookmarks"));
    4542
    4643        bookmarks = new BookmarkList();
     
    4946                Preferences.Bookmark b = (Preferences.Bookmark)bookmarks.getSelectedValue();
    5047                if (b != null) {
    51                     gui.minlat = b.latlon[0];
    52                     gui.minlon = b.latlon[1];
    53                     gui.maxlat = b.latlon[2];
    54                     gui.maxlon = b.latlon[3];
    55                     gui.boundingBoxChanged(BookmarkSelection.this);
     48                    gui.boundingBoxChanged(b.asBounds(),BookmarkSelection.this);
    5649                }
    5750            }
     
    108101
    109102    public void boundingBoxChanged(DownloadDialog gui) {
    110         tempBookmark = new Preferences.Bookmark();
    111         tempBookmark.latlon[0] = gui.minlat;
    112         tempBookmark.latlon[1] = gui.minlon;
    113         tempBookmark.latlon[2] = gui.maxlat;
    114         tempBookmark.latlon[3] = gui.maxlon;
     103        tempBookmark = new Preferences.Bookmark(gui.getSelectedDownloadArea());
    115104        bookmarks.clearSelection();
    116105    }
  • trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java

    r2142 r2327  
    99import java.awt.event.FocusEvent;
    1010import java.awt.event.FocusListener;
    11 import java.awt.event.KeyEvent;
    12 import java.awt.event.KeyListener;
    1311
    1412import javax.swing.JLabel;
     
    5654                            double maxlat = Double.parseDouble(latlon[2].getText());
    5755                            double maxlon = Double.parseDouble(latlon[3].getText());
    58                             if (minlat != gui.minlat || minlon != gui.minlon || maxlat != gui.maxlat || maxlon != gui.maxlon) {
    59                                 gui.minlat = minlat; gui.minlon = minlon;
    60                                 gui.maxlat = maxlat; gui.maxlon = maxlon;
    61                                 gui.boundingBoxChanged(BoundingBoxSelection.this);
     56                            Bounds b = new Bounds(minlat,minlon, maxlat,maxlon);
     57                            if (gui.getSelectedDownloadArea() == null) return;
     58                            if (gui.getSelectedDownloadArea() == null || !gui.getSelectedDownloadArea().equals(new Bounds(minlat,minlon, maxlat,maxlon))) {
     59                                gui.boundingBoxChanged(b, BoundingBoxSelection.this);
    6260                            }
    6361                        } catch (NumberFormatException x) {
     
    119117        });
    120118
    121         gui.tabpane.addTab(tr("Bounding Box"), dlg);
     119        gui.addDownloadAreaSelector(dlg, tr("Bounding Box"));
    122120    }
    123121
     
    132130    private boolean parseURL(DownloadDialog gui) {
    133131        Bounds b = OsmUrlToBounds.parse(osmUrl.getText());
    134         if(b == null) return false;
    135         gui.minlon = b.min.lon();
    136         gui.minlat = b.min.lat();
    137         gui.maxlon = b.max.lon();
    138         gui.maxlat = b.max.lat();
    139         gui.boundingBoxChanged(BoundingBoxSelection.this);
     132        if(b == null) return false;       
     133        gui.boundingBoxChanged(b,BoundingBoxSelection.this);
    140134        updateBboxFields(gui);
    141135        updateUrl(gui);
     
    144138
    145139    private void updateBboxFields(DownloadDialog gui) {
    146         latlon[0].setText(Double.toString(gui.minlat));
    147         latlon[1].setText(Double.toString(gui.minlon));
    148         latlon[2].setText(Double.toString(gui.maxlat));
    149         latlon[3].setText(Double.toString(gui.maxlon));
     140        Bounds b = gui.getSelectedDownloadArea();
     141        if (b == null) return;
     142        latlon[0].setText(Double.toString(b.getMin().lat()));
     143        latlon[1].setText(Double.toString(b.getMin().lon()));
     144        latlon[2].setText(Double.toString(b.getMax().lat()));
     145        latlon[3].setText(Double.toString(b.getMax().lon()));
    150146        for (JTextField f : latlon) {
    151147            f.setCaretPosition(0);
     
    154150
    155151    private void updateUrl(DownloadDialog gui) {
    156         showUrl.setText(OsmUrlToBounds.getURL(new Bounds(
    157                 new LatLon(gui.minlat, gui.minlon), new LatLon(gui.maxlat, gui.maxlon))));
     152        if (gui.getSelectedDownloadArea() == null) return;
     153        showUrl.setText(OsmUrlToBounds.getURL(gui.getSelectedDownloadArea()));
    158154    }
    159155}
  • trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    r2322 r2327  
    1515import java.util.ArrayList;
    1616import java.util.List;
     17import java.util.logging.Logger;
    1718
    1819import javax.swing.AbstractAction;
     
    2425
    2526import org.openstreetmap.josm.Main;
    26 import org.openstreetmap.josm.actions.DownloadAction;
    27 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
    28 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
    29 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
    3027import org.openstreetmap.josm.data.Bounds;
    3128import org.openstreetmap.josm.gui.MapView;
    32 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3329import org.openstreetmap.josm.plugins.PluginHandler;
    3430import org.openstreetmap.josm.tools.GBC;
     
    4642 */
    4743public class DownloadDialog extends JPanel {
    48 
    49     /**
    50      * The list of download tasks. First entry should be the osm data entry
    51      * and the second the gps entry. After that, plugins can register additional
    52      * download possibilities.
    53      */
    54     public final List<DownloadTask> downloadTasks = new ArrayList<DownloadTask>(5);
    55 
    56     public final List<DownloadSelection> downloadSelections = new ArrayList<DownloadSelection>();
    57     public final JTabbedPane tabpane = new JTabbedPane();
    58     public final JCheckBox newLayer;
    59     public final JLabel sizeCheck = new JLabel();
    60 
    61     public double minlon;
    62     public double minlat;
    63     public double maxlon;
    64     public double maxlat;
     44    static private final Logger logger = Logger.getLogger(DownloadDialog.class.getName());
     45
     46    private final List<DownloadSelection> downloadSelections = new ArrayList<DownloadSelection>();
     47    private final JTabbedPane tpDownloadAreaSelectors = new JTabbedPane();
     48    private final JCheckBox cbNewLayer;
     49    private final JLabel sizeCheck = new JLabel();
     50
     51    private Bounds currentBounds = null;
     52
     53    private JCheckBox cbDownloadOsmData = new JCheckBox(tr("OpenStreetMap data"), true);
     54    private JCheckBox cbDownloadGpxData = new JCheckBox(tr("Raw GPS data"));
    6555
    6656
     
    6858        setLayout(new GridBagLayout());
    6959
    70         downloadTasks.add(new DownloadOsmTask());
    71         downloadTasks.add(new DownloadGpsTask());
    72 
    7360        // adding the download tasks
    7461        add(new JLabel(tr("Data Sources and Types")), GBC.eol().insets(0,5,0,0));
    75         for (DownloadTask task : downloadTasks) {
    76             add(task.getCheckBox(), GBC.eol().insets(20,0,0,0));
    77             // don't override defaults, if we (initially) don't have any preferences
    78             if(Main.pref.hasKey("download."+task.getPreferencesSuffix())) {
    79                 task.getCheckBox().setSelected(Main.pref.getBoolean("download."+task.getPreferencesSuffix()));
    80             }
    81         }
    82 
     62        add(cbDownloadOsmData,  GBC.eol().insets(20,0,0,0));
     63        add(cbDownloadGpxData,  GBC.eol().insets(20,0,0,0));
     64       
    8365        // predefined download selections
    8466        downloadSelections.add(new SlippyMapChooser());
     
    9779            s.addGui(this);
    9880        }
    99 
    100         if (Main.map != null) {
    101             MapView mv = Main.map.mapView;
    102             minlon = mv.getLatLon(0, mv.getHeight()).lon();
    103             minlat = mv.getLatLon(0, mv.getHeight()).lat();
    104             maxlon = mv.getLatLon(mv.getWidth(), 0).lon();
    105             maxlat = mv.getLatLon(mv.getWidth(), 0).lat();
    106             boundingBoxChanged(null);
    107         }
    108         else if (Main.pref.hasKey("osm-download.bounds")) {
    109             // read the bounding box from the preferences
    110             try {
    111                 String bounds[] = Main.pref.get("osm-download.bounds").split(";");
    112                 minlat = Double.parseDouble(bounds[0]);
    113                 minlon = Double.parseDouble(bounds[1]);
    114                 maxlat = Double.parseDouble(bounds[2]);
    115                 maxlon = Double.parseDouble(bounds[3]);
    116                 boundingBoxChanged(null);
    117             }
    118             catch (Exception e) {
    119                 e.printStackTrace();
    120             }
    121         }
    122 
    123         newLayer = new JCheckBox(tr("Download as new layer"), Main.pref.getBoolean("download.newlayer", false));
    124         add(newLayer, GBC.eol().insets(0,5,0,0));
     81   
     82        cbNewLayer = new JCheckBox(tr("Download as new layer"));
     83        add(cbNewLayer, GBC.eol().insets(0,5,0,0));
    12584
    12685        add(new JLabel(tr("Download Area")), GBC.eol().insets(0,5,0,0));
    127         add(tabpane, GBC.eol().fill());
     86        add(tpDownloadAreaSelectors, GBC.eol().fill());
    12887
    12988        try {
    130             tabpane.setSelectedIndex(Main.pref.getInteger("download.tab", 0));
     89            tpDownloadAreaSelectors.setSelectedIndex(Main.pref.getInteger("download.tab", 0));
    13190        } catch (Exception ex) {
    13291            Main.pref.putInteger("download.tab", 0);
     
    145104            }
    146105        });
     106       
     107        restoreSettings();
    147108    }
    148109
     
    163124        Bounds b = OsmUrlToBounds.parse(result);
    164125        if (b != null) {
    165             minlon = b.min.lon();
    166             minlat = b.min.lat();
    167             maxlon = b.max.lon();
    168             maxlat = b.max.lat();
    169             boundingBoxChanged(null);
     126            boundingBoxChanged(new Bounds(b),null);
    170127        }
    171128    }
    172129
    173130    private void updateSizeCheck() {
    174         if ((maxlon-minlon)*(maxlat-minlat) > Main.pref.getDouble("osm-server.max-request-area", 0.25)) {
     131        if (currentBounds == null) {
     132            sizeCheck.setText(tr("No area selected yet"));
     133            sizeCheck.setForeground(Color.darkGray);
     134        } else if (currentBounds.getArea() > Main.pref.getDouble("osm-server.max-request-area", 0.25)) {
    175135            sizeCheck.setText(tr("Download area too large; will probably be rejected by server"));
    176136            sizeCheck.setForeground(Color.red);
     
    188148     * @param eventSource - the DownloadSelection object that fired this notification.
    189149     */
    190     public void boundingBoxChanged(DownloadSelection eventSource) {
     150    public void boundingBoxChanged(Bounds b, DownloadSelection eventSource) {
     151        this.currentBounds = b;
    191152        for (DownloadSelection s : downloadSelections) {
    192153            if (s != eventSource) {
     
    196157        updateSizeCheck();
    197158    }
    198 
    199     /*
    200      * Returns currently selected tab.
    201      */
    202     public int getSelectedTab() {
    203         return tabpane.getSelectedIndex();
    204     }
     159   
     160    /**
     161     * Replies true if the user selected to download OSM data
     162     *
     163     * @return true if the user selected to download OSM data
     164     */
     165    public boolean isDownloadOsmData() {
     166        return cbDownloadOsmData.isSelected();
     167    }
     168   
     169    /**
     170     * Replies true if the user selected to download GPX data
     171     *
     172     * @return true if the user selected to download GPX data
     173     */
     174    public boolean isDownloadGpxData() {
     175        return cbDownloadGpxData.isSelected();
     176    }
     177   
     178    /**
     179     * Replies true if the user requires to download into a new layer
     180     *
     181     * @return true if the user requires to download into a new layer
     182     */
     183    public boolean isNewLayerRequired() {
     184        return cbNewLayer.isSelected();
     185    }
     186   
     187    /**
     188     * Adds a new download area selector to the download dialog
     189     *
     190     * @param selector the download are selector
     191     * @param displayName the display name of the selector
     192     */
     193    public void addDownloadAreaSelector(JPanel selector, String displayName) {
     194        tpDownloadAreaSelectors.add(displayName, selector);
     195    }
     196   
     197    /**
     198     * Remembers the current settings in the download dialog
     199     *
     200     */
     201    public void rememberSettings() {
     202        Main.pref.put("download.tab", Integer.toString(tpDownloadAreaSelectors.getSelectedIndex()));
     203        Main.pref.put("download.osm", cbDownloadOsmData.isSelected());
     204        Main.pref.put("download.gps", cbDownloadGpxData.isSelected());
     205        Main.pref.put("download.newlayer", cbNewLayer.isSelected());
     206        if (currentBounds != null) {
     207            Main.pref.put("osm-download.bounds", currentBounds.encodeAsString(";"));
     208        }
     209    }
     210   
     211    public void restoreSettings() {
     212        cbDownloadOsmData.setSelected(Main.pref.getBoolean("download.osm", true));
     213        cbDownloadGpxData.setSelected(Main.pref.getBoolean("download.gps", false));
     214        cbNewLayer.setSelected(Main.pref.getBoolean("download.newlayer", false));
     215        int idx = Main.pref.getInteger("download.tab", 0);
     216        if (idx < 0 || idx > tpDownloadAreaSelectors.getTabCount()) {
     217            idx = 0;
     218        }
     219        tpDownloadAreaSelectors.setSelectedIndex(idx);
     220       
     221        if (Main.map != null) {
     222            MapView mv = Main.map.mapView;
     223            currentBounds = new Bounds(
     224                    mv.getLatLon(0, mv.getHeight()),
     225                    mv.getLatLon(mv.getWidth(), 0)                   
     226                    );
     227            boundingBoxChanged(currentBounds,null);
     228        }
     229        else if (Main.pref.hasKey("osm-download.bounds")) {
     230            // read the bounding box from the preferences
     231            try {
     232                currentBounds = new Bounds(Main.pref.get("osm-download.bounds"), ";");
     233                boundingBoxChanged(currentBounds,null);
     234            }
     235            catch (Exception e) {
     236                e.printStackTrace();
     237            }
     238        }
     239    }
     240   
     241    /**
     242     * Replies the currently selected download area. May be null, if no download area is selected
     243     * yet.
     244     */
     245    public Bounds getSelectedDownloadArea() {
     246        return currentBounds;
     247    }
     248   
    205249}
  • trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java

    r2017 r2327  
    3232
    3333import org.openstreetmap.josm.Main;
     34import org.openstreetmap.josm.data.Bounds;
     35import org.openstreetmap.josm.data.coor.LatLon;
    3436import org.openstreetmap.josm.tools.GBC;
    3537import org.xml.sax.Attributes;
     
    224226        scrollPane.setPreferredSize(new Dimension(200,200));
    225227        panel.add(scrollPane, c);
    226         gui.tabpane.add(panel, tr("Places"));
     228        gui.addDownloadAreaSelector(panel, tr("Places"));
    227229
    228230        scrollPane.setPreferredSize(scrollPane.getPreferredSize());
     
    298300                {
    299301                    double size = 180.0 / Math.pow(2, r.zoom);
    300                     gui.minlat = r.lat - size / 2;
    301                     gui.maxlat = r.lat + size / 2;
    302                     gui.minlon = r.lon - size;
    303                     gui.maxlon = r.lon + size;
     302                    Bounds b = new Bounds(
     303                        new LatLon(
     304                            r.lat - size / 2,
     305                            r.lat + size / 2
     306                         ),
     307                         new LatLon(
     308                            r.lon - size,
     309                            r.lon + size
     310                         )
     311                    );
    304312                    updatingSelf = true;
    305                     gui.boundingBoxChanged(null);
     313                    gui.boundingBoxChanged(b,null);
    306314                    updatingSelf = false;
    307315                }
  • trunk/src/org/openstreetmap/josm/gui/download/SlippyMapChooser.java

    r2093 r2327  
    3030import org.openstreetmap.gui.jmapviewer.interfaces.TileSource;
    3131import org.openstreetmap.josm.Main;
     32import org.openstreetmap.josm.data.Bounds;
     33import org.openstreetmap.josm.data.coor.LatLon;
    3234
    3335/**
     
    120122        String labelText = tr("<b>Zoom:</b> Mousewheel, double click or Ctrl + Up/Down "
    121123                + "<b>Move map:</b> Hold right mousebutton and move mouse or use cursor keys. <b>Select:</b> Hold left mousebutton and draw a frame.");
    122         slipyyMapTabPanel.add(new JLabel("<html>" + labelText + "</html>"), BorderLayout.SOUTH);
    123         iGui.tabpane.add(slipyyMapTabPanel, tr("Slippy map"));
     124        slipyyMapTabPanel.add(new JLabel("<html>" + labelText + "</html>"), BorderLayout.SOUTH);       
     125        iGui.addDownloadAreaSelector(slipyyMapTabPanel, tr("Slippy map"));
    124126        new OsmMapControl(this, slipyyMapTabPanel, iSizeButton, iSourceButton);
    125127    }
     
    165167
    166168    public void boundingBoxChanged(DownloadDialog gui) {
    167 
     169        Bounds b = gui.getSelectedDownloadArea();
     170        if (b == null)
     171            return;
     172       
    168173        // test if a bounding box has been set set
    169         if (gui.minlat == 0.0 && gui.minlon == 0.0 && gui.maxlat == 0.0 && gui.maxlon == 0.0)
     174        if (b.getMin().lat() == 0.0 && b.getMin().lon() == 0.0 && b.getMax().lat() == 0.0 && b.getMax().lon() == 0.0)
    170175            return;
    171176
    172         int y1 = OsmMercator.LatToY(gui.minlat, MAX_ZOOM);
    173         int y2 = OsmMercator.LatToY(gui.maxlat, MAX_ZOOM);
    174         int x1 = OsmMercator.LonToX(gui.minlon, MAX_ZOOM);
    175         int x2 = OsmMercator.LonToX(gui.maxlon, MAX_ZOOM);
     177        int y1 = OsmMercator.LatToY(b.getMin().lat(), MAX_ZOOM);
     178        int y2 = OsmMercator.LatToY(b.getMax().lat(), MAX_ZOOM);
     179        int x1 = OsmMercator.LonToX(b.getMin().lon(), MAX_ZOOM);
     180        int x2 = OsmMercator.LonToX(b.getMax().lon(), MAX_ZOOM);
    176181
    177182        iSelectionRectStart = new Point(Math.min(x1, x2), Math.min(y1, y2));
     
    179184
    180185        // calc the screen coordinates for the new selection rectangle
    181         MapMarkerDot xmin_ymin = new MapMarkerDot(gui.minlat, gui.minlon);
    182         MapMarkerDot xmax_ymax = new MapMarkerDot(gui.maxlat, gui.maxlon);
     186        MapMarkerDot xmin_ymin = new MapMarkerDot(b.getMin());
     187        MapMarkerDot xmax_ymax = new MapMarkerDot(b.getMax());
    183188
    184189        Vector<MapMarker> marker = new Vector<MapMarker>(2);
     
    218223        Coordinate l1 = getPosition(p_max);
    219224        Coordinate l2 = getPosition(p_min);
    220         iGui.minlon = Math.min(l2.getLon(), l1.getLon());
    221         iGui.minlat = Math.min(l1.getLat(), l2.getLat());
    222         iGui.maxlon = Math.max(l2.getLon(), l1.getLon());
    223         iGui.maxlat = Math.max(l1.getLat(), l2.getLat());
    224 
    225         iGui.boundingBoxChanged(this);
     225        Bounds b = new Bounds(
     226                new LatLon(
     227                        Math.min(l2.getLat(), l1.getLat()),
     228                        Math.min(l1.getLon(), l2.getLon())
     229                        ),
     230                new LatLon(
     231                        Math.max(l2.getLat(), l1.getLat()),
     232                        Math.max(l1.getLon(), l2.getLon()))
     233                );
     234        iGui.boundingBoxChanged(b, this);
    226235        repaint();
    227236    }
  • trunk/src/org/openstreetmap/josm/gui/download/TileSelection.java

    r1169 r2327  
    1616import javax.swing.SpinnerNumberModel;
    1717
     18import org.openstreetmap.josm.data.Bounds;
     19import org.openstreetmap.josm.data.coor.LatLon;
    1820import org.openstreetmap.josm.tools.GBC;
    1921/**
     
    6567                    if (toy<fromy) { int i = fromy; fromy=toy; toy=i; }
    6668
    67                     gui.minlat = tileYToLat(zoomlvl, toy+1);
    68                     gui.minlon = tileXToLon(zoomlvl, fromx);
    69                     gui.maxlat = tileYToLat(zoomlvl, fromy);
    70                     gui.maxlon = tileXToLon(zoomlvl, tox+1);
    71                     gui.boundingBoxChanged(TileSelection.this);
     69                    Bounds b = new Bounds(
     70                            new LatLon(tileYToLat(zoomlvl, toy + 1), tileXToLon(zoomlvl, fromx)),
     71                            new LatLon(tileYToLat(zoomlvl, fromy), tileXToLon(zoomlvl, tox + 1))
     72                            );
     73                    gui.boundingBoxChanged(b, TileSelection.this);
    7274                    //repaint();
    7375                } catch (NumberFormatException x) {
     
    8284        }
    8385
    84         gui.tabpane.addTab(tr("Tile Numbers"), smpanel);
     86        gui.addDownloadAreaSelector(smpanel, tr("Tile Numbers"));
    8587    }
    8688
     
    9496    private void updateBboxFields(DownloadDialog gui) {
    9597        int z = ((Integer) tileZ.getValue()).intValue();
    96         tileX0.setText(Integer.toString(lonToTileX(z, gui.minlon)));
    97         tileX1.setText(Integer.toString(lonToTileX(z, gui.maxlon-.00001)));
    98         tileY0.setText(Integer.toString(latToTileY(z, gui.maxlat-.00001)));
    99         tileY1.setText(Integer.toString(latToTileY(z, gui.minlat)));
     98        Bounds b = gui.getSelectedDownloadArea();
     99        if (b == null)
     100            return;
     101        tileX0.setText(Integer.toString(lonToTileX(z, b.getMin().lon())));
     102        tileX1.setText(Integer.toString(lonToTileX(z, b.getMax().lon()-.00001)));
     103        tileY0.setText(Integer.toString(latToTileY(z, b.getMax().lat()-.00001)));
     104        tileY1.setText(Integer.toString(latToTileY(z, b.getMin().lat())));
    100105    }
    101106
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r2325 r2327  
    226226            // now succesively subtract downloaded areas
    227227            for (DataSource src : data.dataSources) {
    228                 if (src.bounds != null && !src.bounds.min.equals(src.bounds.max)) {
    229                     EastNorth en1 = mv.getProjection().latlon2eastNorth(src.bounds.min);
    230                     EastNorth en2 = mv.getProjection().latlon2eastNorth(src.bounds.max);
     228                if (src.bounds != null && !src.bounds.getMin().equals(src.bounds.getMax())) {
     229                    EastNorth en1 = mv.getProjection().latlon2eastNorth(src.bounds.getMin());
     230                    EastNorth en2 = mv.getProjection().latlon2eastNorth(src.bounds.getMax());
    231231                    Point p1 = mv.getPoint(en1);
    232232                    Point p2 = mv.getPoint(en2);
  • trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java

    r2272 r2327  
    9797        Bounds b = Main.proj.getWorldBoundsLatLon();
    9898        CoordinateFormat cf = CoordinateFormat.getDefaultFormat();
    99         bounds.setText(b.min.latToString(cf)+"; "+b.min.lonToString(cf)+" : "+b.max.latToString(cf)+"; "+b.max.lonToString(cf));
     99        bounds.setText(b.getMin().latToString(cf)+"; "+b.getMin().lonToString(cf)+" : "+b.getMax().latToString(cf)+"; "+b.getMax().lonToString(cf));
    100100        /* TODO: Fix bugs, refresh code line and world bounds, fix design (e.g. add border around sub-prefs-stuff */
    101101    }
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r2181 r2327  
    77import java.io.InputStream;
    88
    9 import org.openstreetmap.josm.Main;
     9import org.openstreetmap.josm.data.Bounds;
    1010import org.openstreetmap.josm.data.gpx.GpxData;
    1111import org.openstreetmap.josm.data.osm.DataSet;
     
    2424    private final double lon2;
    2525
    26     public BoundingBoxDownloader(double lat1, double lon1, double lat2, double lon2) {
    27         this.lat1 = lat1;
    28         this.lon1 = lon1;
    29         this.lat2 = lat2;
    30         this.lon2 = lon2;
    31         // store the bounding box in the preferences so it can be
    32         // re-used across invocations of josm
    33         Main.pref.put("osm-download.bounds", lat1+";"+lon1+";"+lat2+";"+lon2);
     26    public BoundingBoxDownloader(Bounds downloadArea) {
     27        this.lat1 = downloadArea.getMin().lat();
     28        this.lon1 = downloadArea.getMin().lon();
     29        this.lat2 = downloadArea.getMax().lat();
     30        this.lon2 = downloadArea.getMax().lon();
    3431    }
    3532
     
    4441        try {
    4542            progressMonitor.indeterminateSubTask(tr("Contacting OSM Server..."));
    46             String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";
     43            String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";           
    4744
    4845            boolean done = false;
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r1975 r2327  
    127127        if(bounds != null)
    128128        {
    129             String b = "minlat=\"" + bounds.min.lat() + "\" minlon=\"" + bounds.min.lon() +
    130                 "\" maxlat=\"" + bounds.max.lat() + "\" maxlon=\"" + bounds.max.lon() + "\"" ;
     129            String b = "minlat=\"" + bounds.getMin().lat() + "\" minlon=\"" + bounds.getMin().lon() +
     130                "\" maxlat=\"" + bounds.getMax().lat() + "\" maxlon=\"" + bounds.getMax().lon() + "\"" ;
    131131            inline("bounds", b);
    132132        }
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r2291 r2327  
    9393        for (DataSource s : ds.dataSources) {
    9494            out.println("  <bounds minlat='"
    95                     + s.bounds.min.lat()+"' minlon='"
    96                     + s.bounds.min.lon()+"' maxlat='"
    97                     + s.bounds.max.lat()+"' maxlon='"
    98                     + s.bounds.max.lon()
     95                    + s.bounds.getMin().lat()+"' minlon='"
     96                    + s.bounds.getMin().lon()+"' maxlat='"
     97                    + s.bounds.getMax().lat()+"' maxlon='"
     98                    + s.bounds.getMax().lon()
    9999                    +"' origin='"+XmlWriter.encode(s.origin)+"' />");
    100100        }
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r1797 r2327  
    5959    static public int getZoom(Bounds b) {
    6060        // convert to mercator (for calculation of zoom only)
    61         double latMin = Math.log(Math.tan(Math.PI/4.0+b.min.lat()/180.0*Math.PI/2.0))*180.0/Math.PI;
    62         double latMax = Math.log(Math.tan(Math.PI/4.0+b.max.lat()/180.0*Math.PI/2.0))*180.0/Math.PI;
    63         double size = Math.max(Math.abs(latMax-latMin), Math.abs(b.max.lon()-b.min.lon()));
     61        double latMin = Math.log(Math.tan(Math.PI/4.0+b.getMin().lat()/180.0*Math.PI/2.0))*180.0/Math.PI;
     62        double latMax = Math.log(Math.tan(Math.PI/4.0+b.getMax().lat()/180.0*Math.PI/2.0))*180.0/Math.PI;
     63        double size = Math.max(Math.abs(latMax-latMin), Math.abs(b.getMax().lon()-b.getMin().lon()));
    6464        int zoom = 0;
    6565        while (zoom <= 20) {
Note: See TracChangeset for help on using the changeset viewer.