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


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

fix compilation warnings + minor code refactorization

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

Legend:

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

    r6471 r6615  
    3232import org.openstreetmap.josm.tools.I18n;
    3333import org.openstreetmap.josm.tools.Shortcut;
     34import org.openstreetmap.josm.tools.Utils;
    3435
    3536public class MainApplet extends JApplet {
     
    180181            @Override
    181182            public URL getCodeBase() {
    182                 try {
    183                     return new File(".").toURI().toURL();
    184                 } catch (Exception e) {
    185                     e.printStackTrace();
    186                     return null;
    187                 }
     183                return Utils.fileToURL(new File("."));
    188184            }
    189185
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r6248 r6615  
    77import java.awt.event.ActionEvent;
    88import java.io.File;
    9 import java.net.MalformedURLException;
    109import java.net.URL;
    1110import java.util.ArrayList;
     
    3231import org.openstreetmap.josm.tools.AudioUtil;
    3332import org.openstreetmap.josm.tools.ImageProvider;
     33import org.openstreetmap.josm.tools.Utils;
    3434
    3535/**
     
    125125     */
    126126    private void importAudio(File wavFile, MarkerLayer ml, double firstStartTime, Markers markers) {
    127         URL url = null;
     127        URL url = Utils.fileToURL(wavFile);
    128128        boolean hasTracks = layer.data.tracks != null && !layer.data.tracks.isEmpty();
    129129        boolean hasWaypoints = layer.data.waypoints != null && !layer.data.waypoints.isEmpty();
    130         try {
    131             url = wavFile.toURI().toURL();
    132         } catch (MalformedURLException e) {
    133             Main.error("Unable to convert filename " + wavFile.getAbsolutePath() + " to URL");
    134         }
    135130        Collection<WayPoint> waypoints = new ArrayList<WayPoint>();
    136131        boolean timedMarkersOmitted = false;
    137132        boolean untimedMarkersOmitted = false;
    138         double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); /*
    139          * about
    140          * 25
    141          * m
    142          */
     133        double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3);
     134        // about 25 m
    143135        WayPoint wayPointFromTimeStamp = null;
    144136
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r6380 r6615  
    3939import org.openstreetmap.josm.gui.MapView;
    4040import org.openstreetmap.josm.tools.ImageProvider;
     41import org.openstreetmap.josm.tools.Utils;
    4142import org.openstreetmap.josm.tools.template_engine.ParseError;
    4243import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
     
    210211                        // Try a relative file:// url, if the link is not in an URL-compatible form
    211212                        if (relativePath != null) {
    212                             try {
    213                                 url = new File(relativePath.getParentFile(), uri).toURI().toURL();
    214                             } catch (MalformedURLException e1) {
    215                                 Main.warn("Unable to convert uri {0} to URL: {1}", uri, e1.getMessage());
    216                             }
     213                            url = Utils.fileToURL(new File(relativePath.getParentFile(), uri));
    217214                        }
    218215                    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6611 r6615  
    471471            final String text = args[0];
    472472            System.arraycopy(args, 1, args, 0, args.length - 1);
    473             return org.openstreetmap.josm.tools.I18n.tr(text, args);
     473            return org.openstreetmap.josm.tools.I18n.tr(text, (Object[])args);
    474474        }
    475475
    476476        /**
    477477         * Returns the substring of {@code s} starting at index {@code begin} (inclusive, 0-indexed).
     478         * @param s The base string
     479         * @param begin The start index
     480         * @return the substring
    478481         * @see String#substring(int)
    479482         */
     
    485488         * Returns the substring of {@code s} starting at index {@code begin} (inclusive)
    486489         * and ending at index {@code end}, (exclusive, 0-indexed).
     490         * @param s The base string
     491         * @param begin The start index
     492         * @param end The end index
     493         * @return the substring
    487494         * @see String#substring(int, int)
    488495         */
  • trunk/src/org/openstreetmap/josm/plugins/Plugin.java

    r6380 r6615  
    144144        File pluginDir = Main.pref.getPluginsDirectory();
    145145        File pluginJar = new File(pluginDir, info.name + ".jar");
    146         final URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);
     146        final URL pluginJarUrl = Utils.fileToURL(pluginJar);
    147147        return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
    148148              public ClassLoader run() {
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r6544 r6615  
    527527            File pluginJar = new File(pluginDir, info.name + ".jar");
    528528            I18n.addTexts(pluginJar);
    529             URL pluginJarUrl = PluginInformation.fileToURL(pluginJar);
     529            URL pluginJarUrl = Utils.fileToURL(pluginJar);
    530530            allPluginLibraries.add(pluginJarUrl);
    531531        }
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r6571 r6615  
    9999                throw new PluginException(name, tr("The plugin file ''{0}'' does not include a Manifest.", file.toString()));
    100100            scanManifest(manifest, false);
    101             libraries.add(0, fileToURL(file));
     101            libraries.add(0, Utils.fileToURL(file));
    102102        } catch (IOException e) {
    103103            throw new PluginException(name, e);
     
    206206            }
    207207        } else {
    208             //noinspection NullArgumentToVariableArgMethod
    209             s = MessageFormat.format(s, null);
     208            s = MessageFormat.format(s, (Object[]) null);
    210209        }
    211210        description = s;
     
    263262                }
    264263
    265                 libraries.add(fileToURL(entryFile));
     264                libraries.add(Utils.fileToURL(entryFile));
    266265            }
    267266        }
     
    333332    }
    334333
    335     public static URL fileToURL(File f) {
    336         try {
    337             return f.toURI().toURL();
    338         } catch (MalformedURLException ex) {
    339             return null;
    340         }
    341     }
     334
    342335
    343336    /**
     
    395388    }
    396389
     390    /**
     391     * Returns all possible plugin locations.
     392     * @return all possible plugin locations.
     393     */
    397394    public static Collection<String> getPluginLocations() {
    398395        Collection<String> locations = Main.pref.getAllPossiblePreferenceDirs();
     
    462459
    463460    /**
    464      * Replies the name of the plugin
     461     * Replies the name of the plugin.
     462     * @return The plugin name
    465463     */
    466464    public String getName() {
  • 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.