Changeset 1711 in josm


Ignore:
Timestamp:
2009-06-28T14:40:12+02:00 (15 years ago)
Author:
stoecker
Message:

support URL's for preset images

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

Legend:

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

    r1523 r1711  
    2121public class MirroredInputStream extends InputStream {
    2222    InputStream fs = null;
     23    File file = null;
    2324
    2425    public MirroredInputStream(String name) throws IOException {
     
    3031    }
    3132
     33    public MirroredInputStream(String name, String destDir) throws IOException {
     34        this(name, destDir, -1L);
     35    }
     36
    3237    public MirroredInputStream(String name, String destDir, long maxTime) throws IOException {
    3338        URL url;
    34         File file = null;
    3539        try {
    3640            url = new URL(name);
     
    5357            throw new IOException();
    5458        fs = new FileInputStream(file);
     59    }
     60
     61    public File getFile()
     62    {
     63       return file;
    5564    }
    5665
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r1677 r1711  
    1515import java.awt.image.BufferedImage;
    1616import java.io.File;
     17import java.io.IOException;
    1718import java.net.MalformedURLException;
    1819import java.net.URL;
     
    2829
    2930import org.openstreetmap.josm.Main;
     31import org.openstreetmap.josm.io.MirroredInputStream;
    3032
    3133/**
     
    8587        if (name == null)
    8688            return null;
     89        if (name.startsWith("http://"))
     90        {
     91            Image img = cache.get(name);
     92            if(img == null)
     93            {
     94                try
     95                {
     96                    MirroredInputStream is = new MirroredInputStream(name,
     97                    new File(Main.pref.getPreferencesDir(), "images").toString());
     98                    if(is != null)
     99                    {
     100                      img = Toolkit.getDefaultToolkit().createImage(is.getFile().toURI().toURL());
     101                      cache.put(name, img);
     102                    }
     103                }
     104                catch(IOException e) {
     105                }
     106            }
     107            return img == null ? null : new ImageIcon(img);
     108        }
    87109        if (subdir == null)
    88110            subdir = "";
Note: See TracChangeset for help on using the changeset viewer.