Changeset 12777 in josm for trunk/src/org
- Timestamp:
- 2017-09-08T00:42:43+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r12776 r12777 17 17 import java.util.Iterator; 18 18 import java.util.List; 19 import java.util.Locale;20 19 import java.util.Map; 21 20 import java.util.Objects; … … 57 56 import org.openstreetmap.josm.tools.PlatformHook; 58 57 import org.openstreetmap.josm.tools.PlatformHookOsx; 59 import org.openstreetmap.josm.tools.PlatformHookUnixoid;60 58 import org.openstreetmap.josm.tools.PlatformHookWindows; 61 59 import org.openstreetmap.josm.tools.Shortcut; -
trunk/src/org/openstreetmap/josm/data/projection/datum/NTV2GridShiftFileWrapper.java
r12776 r12777 8 8 import java.util.Collections; 9 9 import java.util.List; 10 import java.util.Map; 11 import java.util.TreeMap; 10 12 11 import org.openstreetmap.josm.Main;12 import org.openstreetmap.josm.io.CachedFile;13 import org.openstreetmap.josm.tools.Platform;14 13 import org.openstreetmap.josm.tools.PlatformVisitor; 15 14 … … 24 23 private NTV2GridShiftFile instance; 25 24 private final String gridFileName; 25 26 public static float NTV2_SOURCE_PRIORITY_LOCAL = 10f; 27 public static float NTV2_SOURCE_PRIORITY_DOWNLOAD = 5f; 28 29 private static Map<Float, NTV2GridShiftFileSource> sources = 30 new TreeMap<Float, NTV2GridShiftFileSource>(Collections.reverseOrder()); 31 32 /** 33 * Register a source for NTV2 grid files. 34 * @param priority the priority, sources with higher priority are checked first; 35 * use {@link #NTV2_SOURCE_PRIORITY_LOCAL} for local files and 36 * {@link #NTV2_SOURCE_PRIORITY_DOWNLOAD} for remote downloads 37 * @param source the NTV2 grid file source 38 * @since 12777 39 */ 40 public static void registerNTV2GridShiftFileSource(float priority, NTV2GridShiftFileSource source) { 41 sources.put(priority, source); 42 } 26 43 27 44 /** … … 63 80 public synchronized NTV2GridShiftFile getShiftFile() throws IOException { 64 81 if (instance == null) { 65 File grid = null; 66 // Check is the grid is installed in default PROJ.4 directories 67 for (File dir : Platform.determinePlatform().accept(DEFAULT_PROJ4_NTV2_SHIFT_DIRS)) { 68 File file = new File(dir, gridFileName); 69 if (file.exists() && file.isFile()) { 70 grid = file; 71 break; 72 } 73 } 74 // If not, search into PROJ_LIB directory 75 if (grid == null) { 76 String projLib = System.getProperty("PROJ_LIB"); 77 if (projLib != null && !projLib.isEmpty()) { 78 File dir = new File(projLib); 79 if (dir.exists() && dir.isDirectory()) { 80 File file = new File(dir, gridFileName); 81 if (file.exists() && file.isFile()) { 82 grid = file; 83 } 84 } 85 } 86 } 87 // If not, retrieve it from JOSM website 88 String location = grid != null ? grid.getAbsolutePath() : (Main.getJOSMWebsite() + "/proj/" + gridFileName); 89 // Try to load grid file 90 try (CachedFile cf = new CachedFile(location); InputStream is = cf.getInputStream()) { 91 NTV2GridShiftFile ntv2 = new NTV2GridShiftFile(); 92 ntv2.loadGridShiftFile(is, false); 93 instance = ntv2; 94 } 82 for (Map.Entry<Float, NTV2GridShiftFileSource> entry : sources.entrySet()) { 83 NTV2GridShiftFileSource source = entry.getValue(); 84 try (InputStream is = source.getNTV2GridShiftFile(gridFileName)) { 85 if (is != null) { 86 NTV2GridShiftFile ntv2 = new NTV2GridShiftFile(); 87 ntv2.loadGridShiftFile(is, false); 88 instance = ntv2; 89 break; 90 } 91 } 92 } 95 93 } 96 94 return instance; -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12770 r12777 85 85 import org.openstreetmap.josm.data.osm.UserInfo; 86 86 import org.openstreetmap.josm.data.osm.search.SearchMode; 87 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileSource; 88 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; 89 import org.openstreetmap.josm.data.projection.datum.NTV2Proj4DirGridShiftFileSource; 87 90 import org.openstreetmap.josm.data.validation.OsmValidator; 88 91 import org.openstreetmap.josm.gui.ProgramArguments.Option; … … 113 116 import org.openstreetmap.josm.gui.util.WindowGeometry; 114 117 import org.openstreetmap.josm.gui.widgets.UrlLabel; 118 import org.openstreetmap.josm.io.CachedFile; 115 119 import org.openstreetmap.josm.io.CertificateAmendment; 116 120 import org.openstreetmap.josm.io.DefaultProxySelector; … … 235 239 menu.redo.setEnabled(redoSize > 0); 236 240 }; 241 242 /** 243 * Source of NTV2 shift files: Download from JOSM website. 244 * @since 12777 245 */ 246 public static final NTV2GridShiftFileSource JOSM_WEBSITE_NTV2_SOURCE = gridFileName -> { 247 String location = Main.getJOSMWebsite() + "/proj/" + gridFileName; 248 // Try to load grid file 249 CachedFile cf = new CachedFile(location); 250 try { 251 return cf.getInputStream(); 252 } catch (IOException ex) { 253 Logging.warn(ex); 254 return null; 255 } 256 }; 237 257 238 258 /** … … 902 922 Main.toolbar = toolbar; 903 923 ProjectionPreference.setProjection(); 924 NTV2GridShiftFileWrapper.registerNTV2GridShiftFileSource( 925 NTV2GridShiftFileWrapper.NTV2_SOURCE_PRIORITY_LOCAL, 926 NTV2Proj4DirGridShiftFileSource.getInstance()); 927 NTV2GridShiftFileWrapper.registerNTV2GridShiftFileSource( 928 NTV2GridShiftFileWrapper.NTV2_SOURCE_PRIORITY_DOWNLOAD, 929 JOSM_WEBSITE_NTV2_SOURCE); 904 930 GuiHelper.translateJavaInternalMessages(); 905 931 preConstructorInit(); -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r12776 r12777 20 20 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.data.projection.datum.NTV2 GridShiftFileWrapper;22 import org.openstreetmap.josm.data.projection.datum.NTV2Proj4DirGridShiftFileSource; 23 23 import org.openstreetmap.josm.io.CertificateAmendment.CertAmend; 24 24 import org.openstreetmap.josm.tools.date.DateUtils; … … 259 259 */ 260 260 default List<File> getDefaultProj4NadshiftDirectories() { 261 return getPlatform().accept(NTV2 GridShiftFileWrapper.DEFAULT_PROJ4_NTV2_SHIFT_DIRS);261 return getPlatform().accept(NTV2Proj4DirGridShiftFileSource.getInstance()); 262 262 } 263 263
Note:
See TracChangeset
for help on using the changeset viewer.