Ignore:
Timestamp:
2014-01-03T19:32:18+01:00 (9 years ago)
Author:
Don-vip
Message:

fix compilation warnings + minor code refactorization

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

Legend:

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

    r6380 r6615  
    517517            switch (type) {
    518518            case SVG:
    519                 URI uri = getSvgUniverse().loadSVG(is, is.getFile().toURI().toURL().toString());
     519                URI uri = getSvgUniverse().loadSVG(is, Utils.fileToURL(is.getFile()).toString());
    520520                SVGDiagram svg = getSvgUniverse().getDiagram(uri);
    521521                return svg == null ? null : new ImageResource(svg);
     
    523523                BufferedImage img = null;
    524524                try {
    525                     img = ImageIO.read(is.getFile().toURI().toURL());
     525                    img = ImageIO.read(Utils.fileToURL(is.getFile()));
    526526                } catch (IOException e) {
    527527                    Main.warn("IOException while reading HTTP image: "+e.getMessage());
     
    654654            }
    655655        } else {
    656             try {
    657                 File f = new File(path, name);
    658                 if ((path != null || f.isAbsolute()) && f.exists())
    659                     return f.toURI().toURL();
    660             } catch (MalformedURLException e) {
    661                 Main.warn(e);
    662             }
     656            File f = new File(path, name);
     657            if ((path != null || f.isAbsolute()) && f.exists())
     658                return Utils.fileToURL(f);
    663659        }
    664660        return null;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6610 r6615  
    2424import java.io.OutputStream;
    2525import java.net.HttpURLConnection;
     26import java.net.MalformedURLException;
    2627import java.net.URL;
    2728import java.net.URLConnection;
     
    373374        }
    374375    }
     376   
     377    /**
     378     * Converts the given file to its URL.
     379     * @param f The file to get URL from
     380     * @return The URL of the given file, or {@code null} if not possible.
     381     * @since 6615
     382     */
     383    public static URL fileToURL(File f) {
     384        if (f != null) {
     385            try {
     386                return f.toURI().toURL();
     387            } catch (MalformedURLException ex) {
     388                Main.error("Unable to convert filename " + f.getAbsolutePath() + " to URL");
     389            }
     390        }
     391        return null;
     392    }
    375393
    376394    private final static double EPSILON = 1e-11;
Note: See TracChangeset for help on using the changeset viewer.