Changeset 28950 in osm for applications/editors
- Timestamp:
- 2012-11-18T21:37:23+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geotools/src/org/openstreetmap/josm/plugins/geotools/GeoToolsPlugin.java
r28592 r28950 2 2 package org.openstreetmap.josm.plugins.geotools; 3 3 4 import java.io.IOException; 5 import java.io.InputStream; 6 7 import javax.media.jai.JAI; 8 import javax.media.jai.OperationRegistry; 9 10 import org.geotools.referencing.CRS; 11 import org.opengis.referencing.FactoryException; 12 import org.opengis.referencing.NoSuchAuthorityCodeException; 4 13 import org.openstreetmap.josm.plugins.Plugin; 5 14 import org.openstreetmap.josm.plugins.PluginInformation; 15 16 import com.sun.media.jai.imageioimpl.ImageReadWriteSpi; 6 17 7 18 public class GeoToolsPlugin extends Plugin { 8 19 public GeoToolsPlugin(PluginInformation info) { 9 20 super(info); 21 initJAI(); 22 checkEPSG(); 23 } 24 25 private void initJAI() { 26 // As the JAI jars are bundled in the geotools plugin, JAI initialization does not work, 27 // so we need to perform the tasks described here ("Initialization and automatic loading of registry objects"): 28 // http://docs.oracle.com/cd/E17802_01/products/products/java-media/jai/forDevelopers/jai-apidocs/javax/media/jai/OperationRegistry.html 29 OperationRegistry registry = JAI.getDefaultInstance().getOperationRegistry(); 30 if (registry == null) { 31 System.err.println("geotools: error in JAI initialization. Cannot access default operation registry"); 32 } else { 33 // Update registry with com.sun.media.jai.imageioimpl.ImageReadWriteSpi (only class listed javax.media.jai.OperationRegistrySpi) 34 // it would be safer to parse this file instead, but a JAI update is very unlikely as it has not been modified since 2005 35 new ImageReadWriteSpi().updateRegistry(registry); 36 37 // Update registry with GeoTools registry file 38 InputStream in = GeoToolsPlugin.class.getResourceAsStream("/META-INF/registryFile.jai"); 39 if (in == null) { 40 System.err.println("geotools: error in JAI initialization. Cannot access META-INF/registryFile.jai"); 41 } else { 42 try { 43 registry.updateFromStream(in); 44 } catch (IOException e) { 45 System.err.println("geotools: error in JAI initialization. Cannot update default operation registry"); 46 } 47 try { 48 in.close(); 49 } catch (IOException e) { 50 System.err.println("geotools: error in JAI initialization. Cannot close input stream"); 51 } 52 } 53 54 // Print JAI registry contents 55 //for (String mode : RegistryMode.getModeNames()) { 56 // System.out.println("geotools: JAI mode "+mode+": "+Arrays.toString(registry.getDescriptorNames(mode))); 57 //} 58 } 59 } 60 61 private void checkEPSG() { 62 try { 63 CRS.decode("EPSG:4326"); 64 } catch (NoSuchAuthorityCodeException e) { 65 System.err.println("geotools: error in EPSG database initialization. NoSuchAuthorityCodeException: "+e.getMessage()); 66 } catch (FactoryException e) { 67 System.err.println("geotools: error in EPSG database initialization. FactoryException: "+e.getMessage()); 68 } 10 69 } 11 70 }
Note:
See TracChangeset
for help on using the changeset viewer.