Ignore:
Timestamp:
2009-02-10T17:42:52+01:00 (16 years ago)
Author:
stoecker
Message:

apply patches from xeen: #1954 and #1906

Location:
applications/editors/josm/plugins/wmsplugin/src/wmsplugin
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/GeorefImage.java

    r13497 r13645  
    11package wmsplugin;
    22
     3import java.awt.Dimension;
    34import java.awt.Graphics;
    45import java.awt.Point;
     
    1617public class GeorefImage implements Serializable {
    1718    public BufferedImage image = null;
     19    private BufferedImage reImg = null;
     20    private Dimension reImgHash = new Dimension(0, 0);
    1821    public EastNorth min, max;
    1922    public boolean downloadingStarted;
     
    4447        Point minPt = nc.getPoint(mi), maxPt = nc.getPoint(ma);
    4548
     49        // downloadAndPaintVisible in WMSLayer.java requests visible images only
     50        // so this path is never hit.
    4651        /* this is isVisible() but taking dx, dy into account */
    47         if(!(g.hitClip(minPt.x, maxPt.y,
    48                 maxPt.x - minPt.x, minPt.y - maxPt.y)))
     52        /*if(!(g.hitClip(minPt.x, maxPt.y, maxPt.x - minPt.x, minPt.y - maxPt.y))) {
    4953            return false;
     54        }*/
     55       
     56        // Width and height flicker about 2 pixels due to rounding errors, typically only 1
     57        int width = Math.abs(maxPt.x-minPt.x);
     58        int height = Math.abs(minPt.y-maxPt.y);
     59        int diffx = reImgHash.width - width;
     60        int diffy = reImgHash.height - height;
     61       
     62        // We still need to re-render if the requested size is larger (otherwise we'll have black lines)
     63        // If it's only up to two pixels smaller, just draw the old image, the errors are minimal
     64        // but the performance improvements when moving are huge
     65        // Zooming is still slow because the images need to be resized
     66        if(diffx >= 0 && diffx <= 2 && diffy >= 0 && diffy <= 2 && reImg != null) {
     67            g.drawImage(reImg, minPt.x, maxPt.y, null);
     68            return true;
     69        }
    5070
    51         g.drawImage(image,
    52             minPt.x, maxPt.y, maxPt.x, minPt.y, // dest
     71        // We haven't got a saved resized copy, so resize and cache it       
     72        reImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
     73        reImg.getGraphics().drawImage(image,
     74            0, 0, width, height, // dest
    5375            0, 0, image.getWidth(), image.getHeight(), // src
    5476            null);
    5577
     78        reImgHash.setSize(width, height);       
     79        g.drawImage(reImg, minPt.x, maxPt.y, null);
    5680        return true;
    5781    }
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java

    r13618 r13645  
    3131public class WMSGrabber extends Grabber {
    3232    protected String baseURL;
     33    protected Cache cache = new wmsplugin.Cache();
    3334    private static Boolean shownWarning = false;
    3435
     
    112113
    113114    protected BufferedImage grab(URL url) throws IOException {
     115        BufferedImage cached = cache.getImg(url.toString());
     116        if(cached != null) return cached;
     117   
    114118        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    115119
     
    123127        BufferedImage img = ImageIO.read(is);
    124128        is.close();
    125         return img;
     129       
     130        return cache.saveImg(url.toString(), img, true);
    126131    }
    127132
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java

    r13497 r13645  
    88 * @author Frederik Ramm <frederik@remote.org>
    99 */
    10 public class WMSInfo implements Comparable {
     10public class WMSInfo implements Comparable<WMSInfo> {
    1111
    1212    String name;
     
    2323        Main.pref.put("wmsplugin.url." + prefid + ".url", url);
    2424    }
    25     public int compareTo(Object c)
     25    public int compareTo(WMSInfo c)
    2626    {
    27         Integer i = 0;
    28         if(c instanceof WMSInfo)
    29         {
    30             WMSInfo in = (WMSInfo)c;
    31             i = name.compareTo(in.name);
    32             if(i == 0)
    33                 i = url.compareTo(in.url);
    34             if(i == 0)
    35                 i = prefid-in.prefid;
    36         }
     27        WMSInfo in = (WMSInfo)c;
     28        Integer i = name.compareTo(in.name);
     29        if(i == 0)
     30            i = url.compareTo(in.url);
     31        if(i == 0)
     32            i = prefid-in.prefid;
    3733        return i;
    3834    }
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java

    r13600 r13645  
    177177            }
    178178        }
     179
     180        new wmsplugin.Cache().cleanUp();
    179181    }
    180182
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java

    r13497 r13645  
    3131import org.openstreetmap.josm.gui.MapView;
    3232
    33 
    34 // NW 151006 only add the landsat task when the map frame is initialised with
    35 // data.
    36 
    37 
    38 
    3933public class WMSPlugin extends Plugin {
    4034
     
    6660    public void copy(String from, String to) throws FileNotFoundException, IOException
    6761    {
    68         File pluginDir = new File(Main.pref.getPreferencesDir() + "plugins/wmsplugin/");
     62        File pluginDir = new File(getPrefsPath());
    6963        if (!pluginDir.exists())
    7064            pluginDir.mkdirs();
    71         FileOutputStream out = new FileOutputStream(Main.pref.getPreferencesDir() + "plugins/wmsplugin/" + to);
     65        FileOutputStream out = new FileOutputStream(getPrefsPath() + to);
    7266        InputStream in = WMSPlugin.class.getResourceAsStream(from);
    7367        byte[] buffer = new byte[8192];
     
    222216        return new WMSPreferenceEditor();
    223217    }
     218
     219    static public String getPrefsPath()
     220    {
     221        return Main.pref.getPluginsDirFile().getPath() + "wmsplugin/";
     222    }
    224223}
  • applications/editors/josm/plugins/wmsplugin/src/wmsplugin/YAHOOGrabber.java

    r13497 r13645  
    2121public class YAHOOGrabber extends WMSGrabber{
    2222    protected String browserCmd;
     23    protected Cache cache = new wmsplugin.Cache();
    2324
    2425    YAHOOGrabber(String baseURL, Bounds b, Projection proj,
    2526            double pixelPerDegree, GeorefImage image, MapView mv, WMSLayer layer) {
    26         super("file:///" + Main.pref.getPreferencesDir() + "plugins/wmsplugin/ymap.html?"
    27 //                + "request=getmap&format=image/jpeg"
     27        super("file:///" + WMSPlugin.getPrefsPath() + "ymap.html?"
    2828        , b, proj, pixelPerDegree, image, mv, layer);
    2929        this.browserCmd = baseURL.replaceFirst("yahoo://", "");
     
    3131
    3232    protected BufferedImage grab(URL url) throws IOException {
    33         ArrayList<String> cmdParams = new ArrayList<String>();
    3433        String urlstring = url.toExternalForm();
    3534        // work around a problem in URL removing 2 slashes
    3635        if(!urlstring.startsWith("file:///"))
    3736            urlstring = urlstring.replaceFirst("file:", "file://");
     37
     38        BufferedImage cached = cache.getImg(urlstring);
     39        if(cached != null) return cached;
     40
     41        ArrayList<String> cmdParams = new ArrayList<String>();
    3842        StringTokenizer st = new StringTokenizer(MessageFormat.format(browserCmd, urlstring));
    3943        while( st.hasMoreTokens() )
     
    5054        }
    5155
    52         return ImageIO.read(browser.getInputStream());
     56        return cache.saveImg(urlstring, ImageIO.read(browser.getInputStream()), true);
    5357    }
    5458}
Note: See TracChangeset for help on using the changeset viewer.