Ignore:
Timestamp:
2017-06-05T23:42:44+02:00 (7 years ago)
Author:
donvip
Message:

see #josm14894 - add non-regression unit test

Location:
applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImageLayer.java

    r33028 r33372  
    55
    66import java.awt.Graphics2D;
     7import java.awt.GraphicsEnvironment;
    78import java.awt.Image;
    89import java.awt.event.ActionEvent;
     
    1011import java.io.File;
    1112import java.io.IOException;
     13import java.net.URL;
    1214
    1315import javax.media.jai.PlanarImage;
     
    7375        this.imageFile = file;
    7476        this.image = (BufferedImage) createImage();
    75         layericon = new ImageIcon(ImportImagePlugin.pluginClassLoader.getResource("images/layericon.png"));
     77        URL iconURL = ImportImagePlugin.pluginClassLoader.getResource("images/layericon.png");
     78        if (iconURL != null) {
     79            layericon = new ImageIcon(iconURL);
     80        }
    7681    }
    7782
     
    96101        } catch (Exception e) {
    97102            if (e.getMessage().contains("No projection file found")) {
    98                 ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"),
    99                     new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")});
    100                 // CHECKSTYLE.OFF: LineLength
    101                 ex.setContent(tr("No projection file (.prj) found.<br>"
    102                     + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>"
    103                     + "(It can be changed later from the right click menu of the image layer.)",
    104                     ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode()));
    105                 // CHECKSTYLE.ON: LineLength
    106                 ex.showDialog();
    107                 int val = ex.getValue();
    108                 if (val == 3) {
    109                     logger.debug("No projection and user declined un-projected use");
    110                     throw new LayerCreationCanceledException();
     103                int val = 2;
     104                if (!GraphicsEnvironment.isHeadless()) {
     105                    ExtendedDialog ex = new ExtendedDialog(Main.parent, tr("Warning"),
     106                        new String[] {tr("Default image projection"), tr("JOSM''s current projection"), tr("Cancel")});
     107                    // CHECKSTYLE.OFF: LineLength
     108                    ex.setContent(tr("No projection file (.prj) found.<br>"
     109                        + "You can choose the default image projection ({0}) or JOSM''s current editor projection ({1}) as original image projection.<br>"
     110                        + "(It can be changed later from the right click menu of the image layer.)",
     111                        ImportImagePlugin.pluginProps.getProperty("default_crs_srid"), Main.getProjection().toCode()));
     112                    // CHECKSTYLE.ON: LineLength
     113                    val = ex.showDialog().getValue();
     114                    if (val == 3) {
     115                        logger.debug("No projection and user declined un-projected use");
     116                        throw new LayerCreationCanceledException();
     117                    }
    111118                }
    112119                CoordinateReferenceSystem src = null;
     
    299306     *
    300307     */
    301     public class LayerPropertiesAction extends AbstractAction {
     308    public static class LayerPropertiesAction extends AbstractAction {
    302309        public ImageLayer imageLayer;
    303310
     
    307314        }
    308315
     316        @Override
    309317        public void actionPerformed(ActionEvent arg0) {
    310318            LayerPropertiesDialog layerProps = new LayerPropertiesDialog(imageLayer, PluginOperations.crsDescriptions);
     
    317325     * Exception which represents that the layer creation has been canceled by the user.
    318326     */
    319     class LayerCreationCanceledException extends IOException{
     327    static class LayerCreationCanceledException extends IOException{
    320328    }
    321329
  • applications/editors/josm/plugins/ImportImagePlugin/src/org/openstreetmap/josm/plugins/ImportImagePlugin/ImportImagePlugin.java

    r33028 r33372  
    2020import org.openstreetmap.josm.plugins.Plugin;
    2121import org.openstreetmap.josm.plugins.PluginInformation;
     22import org.openstreetmap.josm.tools.JosmRuntimeException;
    2223import org.openstreetmap.josm.tools.Utils;
    2324
     
    3738    JosmAction loadFileAction = null;
    3839
    39     // custom Classloader
    40     static ClassLoader pluginClassLoader;
     40    // custom Classloader to load resources from the main JAR
     41    static ClassLoader pluginClassLoader = createPluginClassLoader();
    4142
    4243    // plugin proerties
     
    4445
    4546    // path constants
    46     static final String PLUGIN_DIR =
    47             Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/";
    48     static final String PLUGINPROPERTIES_PATH =
    49             Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/pluginProperties.properties";
    50     static final String PLUGINLIBRARIES_DIR =
    51             Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/lib/";
     47    static final String PLUGIN_DIR = Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/";
    5248    static final String PLUGINPROPERTIES_FILENAME = "pluginProperties.properties";
    53     static final String LOGGING_PROPERTIES_FILEPATH =
    54             Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin/log4j.properties/";
     49    static final String PLUGINPROPERTIES_PATH = PLUGIN_DIR + PLUGINPROPERTIES_FILENAME;
     50    static final String PLUGINLIBRARIES_DIR = PLUGIN_DIR + "lib/";
     51    static final String LOGGING_PROPERTIES_FILEPATH = PLUGIN_DIR + "log4j.properties/";
    5552
    5653    public Properties getPluginProps() {
     
    6764
    6865        try {
    69             // First create custom ClassLoader to load resources from the main JAR
    70             pluginClassLoader = createPluginClassLoader();
    71 
    7266            // Initialize logger
    7367            initializeLogger(pluginClassLoader);
     
    206200     * get a plugin-specific classloader.
    207201     */
    208     private ClassLoader createPluginClassLoader() throws MalformedURLException {
    209         ClassLoader loader = null;
    210         loader = URLClassLoader.newInstance(
    211                 new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()},
    212                 ImportImagePlugin.class.getClassLoader()
    213                 );
    214 
    215         return loader;
    216     }
    217 
     202    private static ClassLoader createPluginClassLoader() {
     203        try {
     204            return URLClassLoader.newInstance(
     205                    new URL[] {new File(Main.pref.getPluginsDirectory().getAbsolutePath() + "/ImportImagePlugin.jar").toURI().toURL()},
     206                    ImportImagePlugin.class.getClassLoader()
     207                    );
     208        } catch (MalformedURLException e) {
     209            throw new JosmRuntimeException(e);
     210        }
     211    }
    218212}
Note: See TracChangeset for help on using the changeset viewer.