Ignore:
Timestamp:
2011-02-09T09:53:35+01:00 (15 years ago)
Author:
bastiK
Message:

use classloader to find projections from plugins

File:
1 edited

Legend:

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

    r3873 r3874  
    3030import org.openstreetmap.josm.data.projection.ProjectionSubPrefs;
    3131import org.openstreetmap.josm.gui.NavigatableComponent;
     32import org.openstreetmap.josm.plugins.PluginHandler;
    3233import org.openstreetmap.josm.tools.GBC;
    3334
     
    203204        Projection oldProj = Main.proj;
    204205
    205         try {
    206             Main.proj = (Projection)Class.forName(name).newInstance();
    207         } catch (final Exception e) {
    208             // backup plan: if we cannot instantiate this, maybe we have an instance already.
    209             Main.proj = null;
    210             for (Projection p : Projections.getProjections()) {
    211                 if (p.getClass().getName().equals(name)) {
    212                     Main.proj = p; break;
    213                 }
    214             }
    215             if (Main.proj == null) {
    216                 JOptionPane.showMessageDialog(
    217                         Main.parent,
    218                         tr("The projection {0} could not be activated. Using Mercator", name),
    219                         tr("Error"),
    220                         JOptionPane.ERROR_MESSAGE
    221                 );
    222                 coll = null;
    223                 Main.proj = new Mercator();
    224                 name = Main.proj.getClass().getName();
    225             }
     206        Projection p = null;
     207        for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) {
     208            try {
     209                p = (Projection) Class.forName(name, true, cl).newInstance();
     210            } catch (final Exception e) {
     211            }
     212            if (p != null) {
     213                Main.proj = p;
     214                break;
     215            }
     216        }
     217        if (p == null) {
     218            JOptionPane.showMessageDialog(
     219                    Main.parent,
     220                    tr("The projection {0} could not be activated. Using Mercator", name),
     221                    tr("Error"),
     222                    JOptionPane.ERROR_MESSAGE
     223            );
     224            coll = null;
     225            Main.proj = new Mercator();
     226            name = Main.proj.getClass().getName();
    226227        }
    227228        PROP_SUB_PROJECTION.put(coll);
     
    285286     */
    286287    private void setupProjectionCombo() {
     288        boolean found = false;
    287289        for (int i = 0; i < projectionCombo.getItemCount(); ++i) {
    288290            Projection proj = (Projection)projectionCombo.getItemAt(i);
     
    294296                projectionCombo.setSelectedIndex(i);
    295297                selectedProjectionChanged(proj);
     298                found = true;
    296299                break;
    297300            }
    298301        }
     302        if (!found)
     303            throw new RuntimeException("Couldn't find the current projection in the list of available projections!");
    299304
    300305        projectionCombo.addActionListener(new ActionListener() {
Note: See TracChangeset for help on using the changeset viewer.