Changeset 4065 in josm


Ignore:
Timestamp:
2011-05-01T21:56:49+02:00 (13 years ago)
Author:
jttt
Message:

Improved wms cache

  • files saved in original format (no need to recode to png)
  • possibility to tile with different pos/ppd that overlaps current tile
Location:
trunk/src/org/openstreetmap/josm
Files:
9 added
13 edited

Legend:

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

    r2943 r4065  
    178178     */
    179179    public boolean intersects(Bounds b) {
    180         return b.getMax().lat() >= minLat &&
    181         b.getMax().lon() >= minLon &&
    182         b.getMin().lat() <= maxLat &&
    183         b.getMin().lon() <= maxLon;
     180        return b.maxLat >= minLat &&
     181        b.maxLon >= minLon &&
     182        b.minLat <= maxLat &&
     183        b.minLon <= maxLon;
    184184    }
    185185
  • trunk/src/org/openstreetmap/josm/data/ProjectionBounds.java

    r3083 r4065  
    66/**
    77 * This is a simple data class for "rectangular" areas of the world, given in
    8  * lat/lon min/max values.
     8 * east/north min/max values.
    99 *
    1010 * @author imi
     
    1414     * The minimum and maximum coordinates.
    1515     */
    16     public EastNorth min, max;
     16    public double minEast, minNorth, maxEast, maxNorth;
    1717
    1818    /**
     
    2020     */
    2121    public ProjectionBounds(EastNorth min, EastNorth max) {
    22         this.min = min;
    23         this.max = max;
     22        this.minEast = min.east();
     23        this.minNorth = min.north();
     24        this.maxEast = max.east();
     25        this.maxNorth = max.north();
    2426    }
    2527    public ProjectionBounds(EastNorth p) {
    26         this.min = p;
    27         this.max = p;
     28        this.minEast = this.maxEast = p.east();
     29        this.minNorth = this.maxNorth = p.north();
    2830    }
    2931    public ProjectionBounds(EastNorth center, double east, double north) {
    30         this.min = new EastNorth(center.east()-east/2.0, center.north()-north/2.0);
    31         this.max = new EastNorth(center.east()+east/2.0, center.north()+north/2.0);
     32        this.minEast = center.east()-east/2.0;
     33        this.minNorth = center.north()-north/2.0;
     34        this.maxEast = center.east()+east/2.0;
     35        this.maxNorth = center.north()+north/2.0;
     36    }
     37    public ProjectionBounds(double minEast, double minNorth, double maxEast, double maxNorth) {
     38        this.minEast = minEast;
     39        this.minNorth = minNorth;
     40        this.maxEast = maxEast;
     41        this.maxNorth = maxNorth;
    3242    }
    3343    public void extend(EastNorth e)
    3444    {
    35         if (e.east() < min.east() || e.north() < min.north())
    36             min = new EastNorth(Math.min(e.east(), min.east()), Math.min(e.north(), min.north()));
    37         if (e.east() > max.east() || e.north() > max.north())
    38             max = new EastNorth(Math.max(e.east(), max.east()), Math.max(e.north(), max.north()));
     45        if (e.east() < minEast) {
     46            minEast = e.east();
     47        }
     48        if (e.east() > maxEast) {
     49            maxEast = e.east();
     50        }
     51        if (e.north() < minNorth) {
     52            minNorth = e.north();
     53        }
     54        if (e.north() > maxNorth) {
     55            maxNorth = e.north();
     56        }
    3957    }
    4058    public EastNorth getCenter()
    4159    {
    42         return min.getCenter(max);
     60        return new EastNorth((minEast + maxEast) / 2.0, (minNorth + maxNorth) / 2.0);
    4361    }
    4462
    4563    @Override public String toString() {
    46         return "ProjectionBounds["+min.east()+","+min.north()+","+max.east()+","+max.north()+"]";
     64        return "ProjectionBounds["+minEast+","+minNorth+","+maxEast+","+maxNorth+"]";
    4765    }
     66
     67    /**
     68     * The two bounds intersect? Compared to java Shape.intersects, if does not use
     69     * the interior but the closure. (">=" instead of ">")
     70     */
     71    public boolean intersects(ProjectionBounds b) {
     72        return b.maxEast >= minEast &&
     73        b.maxNorth >= minNorth &&
     74        b.minEast <= maxEast &&
     75        b.minNorth <= maxNorth;
     76    }
     77
     78    public EastNorth getMin() {
     79        return new EastNorth(minEast, minNorth);
     80    }
     81
     82    public EastNorth getMax() {
     83        return new EastNorth(maxEast, maxNorth);
     84    }
     85
    4886}
  • trunk/src/org/openstreetmap/josm/data/imagery/GeorefImage.java

    r4014 r4065  
    2626    private static final long serialVersionUID = 1L;
    2727
    28     public enum State { IMAGE, NOT_IN_CACHE, FAILED}
     28    public enum State { IMAGE, NOT_IN_CACHE, FAILED, PARTLY_IN_CACHE}
    2929
    3030    private WMSLayer layer;
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/BoundingXYVisitor.java

    r2686 r4065  
    5656        if(b != null)
    5757        {
    58             visit(b.min);
    59             visit(b.max);
     58            visit(b.getMin());
     59            visit(b.getMax());
    6060        }
    6161    }
     
    8484    public boolean hasExtend()
    8585    {
    86         return bounds != null && !bounds.min.equals(bounds.max);
     86        return bounds != null && !bounds.getMin().equals(bounds.getMax());
    8787    }
    8888
     
    113113        if (bounds == null)
    114114            return;
    115         LatLon minLatlon = Main.proj.eastNorth2latlon(bounds.min);
    116         LatLon maxLatlon = Main.proj.eastNorth2latlon(bounds.max);
     115        LatLon minLatlon = Main.proj.eastNorth2latlon(bounds.getMin());
     116        LatLon maxLatlon = Main.proj.eastNorth2latlon(bounds.getMax());
    117117        bounds = new ProjectionBounds(
    118118                Main.proj.latlon2eastNorth(new LatLon(minLatlon.lat() - enlargeDegree, minLatlon.lon() - enlargeDegree)),
  • trunk/src/org/openstreetmap/josm/gui/MapSlider.java

    r3754 r4065  
    3535        ProjectionBounds current = this.mv.getProjectionBounds();
    3636
    37         double cur_e = current.max.east()-current.min.east();
    38         double cur_n = current.max.north()-current.min.north();
    39         double e = world.max.east()-world.min.east();
    40         double n = world.max.north()-world.min.north();
     37        double cur_e = current.maxEast-current.minEast;
     38        double cur_n = current.maxNorth-current.minNorth;
     39        double e = world.maxEast-world.minEast;
     40        double n = world.maxNorth-world.minNorth;
    4141        int zoom = 0;
    4242
     
    5959        ProjectionBounds world = this.mv.getMaxProjectionBounds();
    6060        double fact = Math.pow(1.1, getValue());
    61         double es = world.max.east()-world.min.east();
    62         double n = world.max.north()-world.min.north();
     61        double es = world.maxEast-world.minEast;
     62        double n = world.maxNorth-world.minNorth;
    6363
    6464        this.mv.zoomTo(new ProjectionBounds(this.mv.getCenter(), es/fact, n/fact));
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r3919 r4065  
    2424
    2525import javax.swing.JComponent;
    26 import javax.swing.SwingUtilities;
    2726
    2827import org.openstreetmap.josm.Main;
     
    367366
    368367    /**
    369      * Create a thread that moves the viewport to the given center in an 
     368     * Create a thread that moves the viewport to the given center in an
    370369     * animated fashion.
    371370     */
     
    382381
    383382            new Thread(
    384                 new Runnable() {
    385                     public void run() {
    386                         for (int i=0; i<frames; i++)
    387                         {
    388                             // fixme - not use zoom history here
    389                             zoomTo(oldCenter.interpolate(finalNewCenter, (double) (i+1) / (double) frames));
    390                             try { Thread.sleep(1000 / fps); } catch (InterruptedException ex) { };
     383                    new Runnable() {
     384                        public void run() {
     385                            for (int i=0; i<frames; i++)
     386                            {
     387                                // fixme - not use zoom history here
     388                                zoomTo(oldCenter.interpolate(finalNewCenter, (i+1) / frames));
     389                                try { Thread.sleep(1000 / fps); } catch (InterruptedException ex) { };
     390                            }
    391391                        }
    392392                    }
    393                 }
    394393            ).start();
    395394        }
     
    425424        }
    426425
    427         double scaleX = (box.max.east()-box.min.east())/w;
    428         double scaleY = (box.max.north()-box.min.north())/h;
     426        double scaleX = (box.maxEast-box.minEast)/w;
     427        double scaleY = (box.maxNorth-box.minNorth)/h;
    429428        double newScale = Math.max(scaleX, scaleY);
    430429
     
    12311230        if(Cursors.size() > 0) {
    12321231            CursorInfo l = Cursors.getLast();
    1233             if(l != null && l.cursor == cursor && l.object == reference) {
     1232            if(l != null && l.cursor == cursor && l.object == reference)
    12341233                return;
    1235             }
    12361234            stripCursors(reference);
    12371235        }
     
    12531251        stripCursors(reference);
    12541252        if(l != null && l.object == reference) {
    1255             if(Cursors.size() == 0)
     1253            if(Cursors.size() == 0) {
    12561254                setCursor(null);
    1257             else
     1255            } else {
    12581256                setCursor(Cursors.getLast().cursor);
     1257            }
    12591258        }
    12601259    }
     
    12631262        LinkedList<CursorInfo> c = new LinkedList<CursorInfo>();
    12641263        for(CursorInfo i : Cursors) {
    1265             if(i.object != reference)
     1264            if(i.object != reference) {
    12661265                c.add(i);
     1266            }
    12671267        }
    12681268        Cursors = c;
  • trunk/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    r3878 r4065  
    8585        if (Main.map == null || Main.map.mapView == null) return Main.proj.getDefaultZoomInPPD();
    8686        ProjectionBounds bounds = Main.map.mapView.getProjectionBounds();
    87         return Main.map.mapView.getWidth() / (bounds.max.east() - bounds.min.east());
     87        return Main.map.mapView.getWidth() / (bounds.maxEast - bounds.minEast);
    8888    }
    8989
  • trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java

    r4043 r4065  
    1616import java.util.ArrayList;
    1717import java.util.Collections;
     18import java.util.HashSet;
    1819import java.util.Iterator;
    1920import java.util.List;
     21import java.util.Set;
    2022import java.util.concurrent.locks.Condition;
    2123import java.util.concurrent.locks.Lock;
     
    4143import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    4244import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
     45import org.openstreetmap.josm.data.imagery.WmsCache;
    4346import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
    4447import org.openstreetmap.josm.data.preferences.BooleanProperty;
     
    4750import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    4851import org.openstreetmap.josm.gui.dialogs.LayerListPopup;
    49 import org.openstreetmap.josm.io.CacheFiles;
    5052import org.openstreetmap.josm.io.imagery.Grabber;
    5153import org.openstreetmap.josm.io.imagery.HTMLGrabber;
     
    7981    protected ImageryInfo info;
    8082    protected final MapView mv;
     83    public WmsCache cache;
     84
    8185
    8286    // Image index boundary for current view
     
    118122        setBackgroundLayer(true); /* set global background variable */
    119123        initializeImages();
     124        if (info.getUrl() != null) {
     125            for (WMSLayer layer: Main.map.mapView.getLayersOfType(WMSLayer.class)) {
     126                if (layer.getInfo().getUrl().equals(info.getUrl())) {
     127                    cache = layer.cache;
     128                    break;
     129                }
     130            }
     131            if (cache == null) {
     132                cache = new WmsCache(info.getUrl(), imageSize);
     133                cache.loadIndex();
     134            }
     135        }
    120136        this.info = new ImageryInfo(info);
    121137        if(this.info.getPixelPerDegree() == 0.0) {
     
    157173        cancelGrabberThreads(false);
    158174        Main.pref.removePreferenceChangeListener(this);
     175        if (cache != null) {
     176            cache.saveIndex();
     177        }
    159178    }
    160179
     
    205224
    206225        ProjectionBounds bounds = mv.getProjectionBounds();
    207         bminx= getImageXIndex(bounds.min.east());
    208         bminy= getImageYIndex(bounds.min.north());
    209         bmaxx= getImageXIndex(bounds.max.east());
    210         bmaxy= getImageYIndex(bounds.max.north());
    211 
    212         leftEdge = (int)(bounds.min.east() * getPPD());
    213         bottomEdge = (int)(bounds.min.north() * getPPD());
     226        bminx= getImageXIndex(bounds.minEast);
     227        bminy= getImageYIndex(bounds.minNorth);
     228        bmaxx= getImageXIndex(bounds.maxEast);
     229        bmaxy= getImageYIndex(bounds.maxNorth);
     230
     231        leftEdge = (int)(bounds.minEast * getPPD());
     232        bottomEdge = (int)(bounds.minNorth * getPPD());
    214233
    215234        if (zoomIsTooBig()) {
    216             for(int x = bminx; x<=bmaxx; ++x) {
    217                 for(int y = bminy; y<=bmaxy; ++y) {
    218                     images[modulo(x,dax)][modulo(y,day)].paint(g, mv, x, y, leftEdge, bottomEdge);
     235            for(int x = 0; x<images.length; ++x) {
     236                for(int y = 0; y<images[0].length; ++y) {
     237                    GeorefImage image = images[x][y];
     238                    image.paint(g, mv, image.getXIndex(), image.getYIndex(), leftEdge, bottomEdge);
    219239                }
    220240            }
     
    305325    }
    306326
     327    public boolean isOverlapEnabled() {
     328        return WMSLayer.PROP_OVERLAP.get() && (WMSLayer.PROP_OVERLAP_EAST.get() > 0 || WMSLayer.PROP_OVERLAP_NORTH.get() > 0);
     329    }
     330
    307331    /**
    308332     *
     
    310334     */
    311335    public BufferedImage normalizeImage(BufferedImage img) {
    312         if (WMSLayer.PROP_OVERLAP.get() && (WMSLayer.PROP_OVERLAP_EAST.get() > 0 || WMSLayer.PROP_OVERLAP_NORTH.get() > 0)) {
     336        if (isOverlapEnabled()) {
    313337            BufferedImage copy = img;
    314338            img = new BufferedImage(imageSize, imageSize, copy.getType());
     
    357381
    358382        gatherFinishedRequests();
     383        Set<ProjectionBounds> areaToCache = new HashSet<ProjectionBounds>();
    359384
    360385        for(int x = bminx; x<=bmaxx; ++x) {
     
    362387                GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    363388                if (!img.paint(g, mv, x, y, leftEdge, bottomEdge)) {
    364                     WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real);
     389                    WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real, true);
    365390                    addRequest(request);
    366                 }
    367             }
    368         }
     391                    areaToCache.add(new ProjectionBounds(getEastNorth(x, y), getEastNorth(x + 1, y + 1)));
     392                } else if (img.getState() == State.PARTLY_IN_CACHE && autoDownloadEnabled) {
     393                    WMSRequest request = new WMSRequest(x, y, info.getPixelPerDegree(), real, false);
     394                    addRequest(request);
     395                    areaToCache.add(new ProjectionBounds(getEastNorth(x, y), getEastNorth(x + 1, y + 1)));
     396                }
     397            }
     398        }
     399        cache.setAreaToCache(areaToCache);
    369400    }
    370401
     
    548579        @Override
    549580        public void actionPerformed(ActionEvent ev) {
    550             initializeImages();
    551581            resolution = mv.getDist100PixelText();
    552582            info.setPixelPerDegree(getPPD());
    553583            settingsChanged = true;
     584            for(int x = 0; x<dax; ++x) {
     585                for(int y = 0; y<day; ++y) {
     586                    images[x][y].changePosition(-1, -1);
     587                }
     588            }
    554589            mv.repaint();
    555590        }
     
    564599            // Delete small files, because they're probably blank tiles.
    565600            // See https://josm.openstreetmap.de/ticket/2307
    566             Grabber.cache.customCleanUp(CacheFiles.CLEAN_SMALL_FILES, 4096);
     601            cache.cleanSmallFiles(4096);
    567602
    568603            for (int x = 0; x < dax; ++x) {
     
    570605                    GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    571606                    if(img.getState() == State.FAILED){
    572                         addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), true));
    573                         mv.repaint();
     607                        addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), true, false));
    574608                    }
    575609                }
     
    680714                settingsChanged = true;
    681715                mv.repaint();
     716                if (cache != null) {
     717                    cache.saveIndex();
     718                    cache = null;
     719                }
    682720                if(info.getUrl() != null)
    683721                {
     722                    cache = new WmsCache(info.getUrl(), imageSize);
    684723                    startGrabberThreads();
    685724                }
     
    737776                        GeorefImage img = images[modulo(x,dax)][modulo(y,day)];
    738777                        if(img.getState() == State.NOT_IN_CACHE){
    739                             addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), false));
     778                            addRequest(new WMSRequest(img.getXIndex(), img.getYIndex(), info.getPixelPerDegree(), false, true));
    740779                        }
    741780                    }
  • trunk/src/org/openstreetmap/josm/io/imagery/Grabber.java

    r4027 r4065  
    99import org.openstreetmap.josm.gui.MapView;
    1010import org.openstreetmap.josm.gui.layer.WMSLayer;
    11 import org.openstreetmap.josm.io.CacheFiles;
    1211
    1312abstract public class Grabber implements Runnable {
    14     public final static CacheFiles cache = new CacheFiles("imagery", false);
    15 
    1613    protected final MapView mv;
    1714    protected final WMSLayer layer;
     
    3229                layer.getEastNorth(request.getXIndex(), request.getYIndex()),
    3330                layer.getEastNorth(request.getXIndex() + 1, request.getYIndex() + 1));
    34         if (b.min != null && b.max != null && WMSLayer.PROP_OVERLAP.get()) {
    35             double eastSize =  b.max.east() - b.min.east();
    36             double northSize =  b.max.north() - b.min.north();
     31        if (WMSLayer.PROP_OVERLAP.get()) {
     32            double eastSize =  b.maxEast - b.minEast;
     33            double northSize =  b.maxNorth - b.minNorth;
    3734
    3835            double eastCoef = WMSLayer.PROP_OVERLAP_EAST.get() / 100.0;
    3936            double northCoef = WMSLayer.PROP_OVERLAP_NORTH.get() / 100.0;
    4037
    41             this.b = new ProjectionBounds( new EastNorth(b.min.east(),
    42                     b.min.north()),
    43                     new EastNorth(b.max.east() + eastCoef * eastSize,
    44                             b.max.north() + northCoef * northSize));
     38            this.b = new ProjectionBounds(b.getMin(),
     39                    new EastNorth(b.maxEast + eastCoef * eastSize,
     40                            b.maxNorth + northCoef * northSize));
    4541        }
    4642
  • trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java

    r3808 r4065  
    33
    44import java.awt.image.BufferedImage;
     5import java.io.ByteArrayInputStream;
     6import java.io.ByteArrayOutputStream;
    57import java.io.IOException;
    68import java.net.URL;
     
    1113import javax.imageio.ImageIO;
    1214
     15import org.openstreetmap.josm.Main;
    1316import org.openstreetmap.josm.data.preferences.StringProperty;
    1417import org.openstreetmap.josm.gui.MapView;
    1518import org.openstreetmap.josm.gui.layer.WMSLayer;
     19import org.openstreetmap.josm.tools.Utils;
    1620
    1721public class HTMLGrabber extends WMSGrabber {
     
    4347        }
    4448
    45         BufferedImage img = layer.normalizeImage(ImageIO.read(browser.getInputStream()));
    46         cache.saveImg(urlstring, img);
     49        ByteArrayOutputStream baos = new ByteArrayOutputStream();
     50        Utils.copyStream(browser.getInputStream(), baos);
     51        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
     52        BufferedImage img = layer.normalizeImage(ImageIO.read(bais));
     53        bais.reset();
     54        layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.proj, pixelPerDegree, b.minEast, b.minNorth);
     55
    4756        return img;
    4857    }
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSGrabber.java

    r3826 r4065  
    66import java.awt.image.BufferedImage;
    77import java.io.BufferedReader;
     8import java.io.ByteArrayInputStream;
     9import java.io.ByteArrayOutputStream;
    810import java.io.IOException;
    911import java.io.InputStream;
     
    3436import org.openstreetmap.josm.io.OsmTransferException;
    3537import org.openstreetmap.josm.io.ProgressInputStream;
     38import org.openstreetmap.josm.tools.Utils;
    3639
    3740
     
    5356        try {
    5457            url = getURL(
    55                     b.min.east(), b.min.north(),
    56                     b.max.east(), b.max.north(),
     58                    b.minEast, b.minNorth,
     59                    b.maxEast, b.maxNorth,
    5760                    width(), height());
    5861            request.finish(State.IMAGE, grab(url, attempt));
     
    143146    @Override
    144147    public boolean loadFromCache(WMSRequest request) {
    145         URL url = null;
    146         try{
    147             url = getURL(
    148                     b.min.east(), b.min.north(),
    149                     b.max.east(), b.max.north(),
    150                     width(), height());
    151         } catch(Exception e) {
    152             return false;
    153         }
    154         BufferedImage cached = cache.getImg(url.toString());
    155         if((!request.isReal() && !layer.hasAutoDownload()) || cached != null){
    156             if(cached == null){
    157                 request.finish(State.NOT_IN_CACHE, null);
    158                 return true;
    159             }
     148        BufferedImage cached = layer.cache.getExactMatch(Main.proj, pixelPerDegree, b.minEast, b.minNorth);
     149
     150        if (cached != null) {
    160151            request.finish(State.IMAGE, cached);
    161152            return true;
    162         }
     153        } else if (request.isAllowPartialCacheMatch()) {
     154            BufferedImage partialMatch = layer.cache.getPartialMatch(Main.proj, pixelPerDegree, b.minEast, b.minNorth);
     155            if (partialMatch != null) {
     156                request.finish(State.PARTLY_IN_CACHE, partialMatch);
     157                return true;
     158            }
     159        }
     160
     161        if((!request.isReal() && !layer.hasAutoDownload())){
     162            request.finish(State.NOT_IN_CACHE, null);
     163            return true;
     164        }
     165
    163166        return false;
    164167    }
     
    180183            throw new IOException(readException(conn));
    181184
     185        ByteArrayOutputStream baos = new ByteArrayOutputStream();
    182186        InputStream is = new ProgressInputStream(conn, null);
    183         BufferedImage img = layer.normalizeImage(ImageIO.read(is));
    184         is.close();
    185 
    186         cache.saveImg(url.toString(), img);
     187        try {
     188            Utils.copyStream(is, baos);
     189        } finally {
     190            is.close();
     191        }
     192
     193        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
     194        BufferedImage img = layer.normalizeImage(ImageIO.read(bais));
     195        bais.reset();
     196        layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.proj, pixelPerDegree, b.minEast, b.minNorth);
    187197        return img;
    188198    }
  • trunk/src/org/openstreetmap/josm/io/imagery/WMSRequest.java

    r3747 r4065  
    1111    private final double pixelPerDegree;
    1212    private final boolean real; // Download even if autodownloading is disabled
     13    private final boolean allowPartialCacheMatch;
    1314    private int priority;
    1415    // Result
     
    1617    private BufferedImage image;
    1718
    18     public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real) {
     19    public WMSRequest(int xIndex, int yIndex, double pixelPerDegree, boolean real, boolean allowPartialCacheMatch) {
    1920        this.xIndex = xIndex;
    2021        this.yIndex = yIndex;
    2122        this.pixelPerDegree = pixelPerDegree;
    2223        this.real = real;
     24        this.allowPartialCacheMatch = allowPartialCacheMatch;
    2325    }
    2426
     
    6870        if (yIndex != other.yIndex)
    6971            return false;
     72        if (allowPartialCacheMatch != other.allowPartialCacheMatch)
     73            return false;
    7074        return true;
    7175    }
     
    101105        return real;
    102106    }
     107
     108    public boolean isAllowPartialCacheMatch() {
     109        return allowPartialCacheMatch;
     110    }
    103111}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r3979 r4065  
    33
    44import java.awt.Color;
     5import java.io.File;
     6import java.io.IOException;
     7import java.io.InputStream;
     8import java.io.OutputStream;
    59import java.util.Collection;
    610
     
    1519    }
    1620
    17     public static <T> boolean exists(Iterable collection, Class<? extends T> klass) {
     21    public static <T> boolean exists(Iterable<T> collection, Class<? extends T> klass) {
    1822        for (Object item : collection) {
    1923            if (klass.isInstance(item))
     
    3135    }
    3236
    33     public static <T> T find(Iterable collection, Class<? extends T> klass) {
     37    @SuppressWarnings("unchecked")
     38    public static <T> T find(Iterable<? super T> collection, Class<? extends T> klass) {
    3439        for (Object item : collection) {
    35             if (klass.isInstance(item)) {
    36                 @SuppressWarnings("unchecked") T res = (T) item;
    37                 return res;
    38             }
     40            if (klass.isInstance(item))
     41                return (T) item;
    3942        }
    4043        return null;
     
    6063            return b;
    6164        } else {
    62             if (a < c) {
     65            if (a < c)
    6366                return a;
    64             }
    6567            return c;
    6668        }
     
    160162    }
    161163
     164
     165    public static int copyStream(InputStream source, OutputStream destination) throws IOException {
     166        int count = 0;
     167        byte[] b = new byte[512];
     168        int read;
     169        while ((read = source.read(b)) != -1) {
     170            count += read;
     171            destination.write(b, 0, read);
     172        }
     173        return count;
     174    }
     175
     176
     177
    162178    public static Color complement(Color clr) {
    163179        return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
    164180    }
     181
     182    public static boolean deleteDirectory(File path) {
     183        if( path.exists() ) {
     184            File[] files = path.listFiles();
     185            for(int i=0; i<files.length; i++) {
     186                if(files[i].isDirectory()) {
     187                    deleteDirectory(files[i]);
     188                }
     189                else {
     190                    files[i].delete();
     191                }
     192            }
     193        }
     194        return( path.delete() );
     195    }
    165196}
Note: See TracChangeset for help on using the changeset viewer.