1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package cadastre_fr;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.io.session.SessionReader.registerSessionLayerImporter;
|
---|
6 | import static org.openstreetmap.josm.io.session.SessionWriter.registerSessionLayerExporter;
|
---|
7 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
8 |
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 | import java.awt.event.ActionListener;
|
---|
11 | import java.awt.event.KeyEvent;
|
---|
12 | import java.io.File;
|
---|
13 | import java.util.Arrays;
|
---|
14 | import java.util.HashMap;
|
---|
15 | import java.util.Map;
|
---|
16 |
|
---|
17 | import javax.swing.JCheckBoxMenuItem;
|
---|
18 | import javax.swing.JDialog;
|
---|
19 | import javax.swing.JMenu;
|
---|
20 | import javax.swing.JMenuItem;
|
---|
21 | import javax.swing.JOptionPane;
|
---|
22 | import javax.swing.KeyStroke;
|
---|
23 |
|
---|
24 | import org.openstreetmap.josm.Main;
|
---|
25 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
26 | import org.openstreetmap.josm.actions.UploadAction;
|
---|
27 | import org.openstreetmap.josm.data.projection.AbstractProjection;
|
---|
28 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
29 | import org.openstreetmap.josm.gui.IconToggleButton;
|
---|
30 | import org.openstreetmap.josm.gui.MainMenu;
|
---|
31 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
32 | import org.openstreetmap.josm.gui.layer.Layer;
|
---|
33 | import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
|
---|
34 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
35 | import org.openstreetmap.josm.gui.preferences.map.MapPreference;
|
---|
36 | import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
|
---|
37 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
38 | import org.openstreetmap.josm.plugins.Plugin;
|
---|
39 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Plugin to access the French Cadastre WMS server at <a href="http://www.cadastre.gouv.fr">
|
---|
43 | * www.cadastre.gouv.fr</a>.<br>
|
---|
44 | * This WMS server requires some specific handling like retrieving a cookie for a
|
---|
45 | * limitation in case of no activity, or the request to the server shall provide
|
---|
46 | * a city/town/village code.
|
---|
47 | *
|
---|
48 | * @author Pieren <pieren3@gmail.com>,
|
---|
49 | * <matthieu.lochegnies@gmail.com> for the extension to codeCommune
|
---|
50 | *
|
---|
51 | * @version 2.6
|
---|
52 | * <br>History:
|
---|
53 | * <br>0.1 17-Jun-2008 first prototype using a first Lambert projection impl. in core
|
---|
54 | * <br>0.2 22-Jun-2008 first stable version
|
---|
55 | * <br>0.3 24-Jun-2008 add code departement
|
---|
56 | * <br>0.4 06-Jul-2008 - add images scales, icons, menu items disabling
|
---|
57 | * <br> - remove dependencies of wmsplugin
|
---|
58 | * <br> - add option to force a Lambert zone (for median locations)
|
---|
59 | * <br> - add auto-sourcing
|
---|
60 | * <br>0.5 16-Aug-2008 - add transparency in layer (allowing multiple wms layers displayed together)
|
---|
61 | * <br> - no overlapping of grabbed images if transparency is enabled
|
---|
62 | * <br> - set one layer per location
|
---|
63 | * <br> - use utf-8 charset in POST request to server
|
---|
64 | * <br> - improve the preferences setting dialog
|
---|
65 | * <br> - cancel the current download is now possible
|
---|
66 | * <br> - add automatic images caching and load on request (+ manage cache directory size)
|
---|
67 | * <br> - enable auto-sourcing only if a WMS layer is used
|
---|
68 | * <br>0.6 18-Aug-2008 - suppress the null-exception message after the dialog 'open a layer first'
|
---|
69 | * <br> - process the overlapping images when cache is loaded from disk
|
---|
70 | * <br> - save the last 'new location request' text again in preferences
|
---|
71 | * <br> - avoid duplicate layers with same name
|
---|
72 | * <br> - set text input for new locations in upper case
|
---|
73 | * <br> - the cache directory is configurable in "cadastrewms.cacheDir"
|
---|
74 | * <br> - improve configuration change updates
|
---|
75 | * <br>0.7 24-Aug-2008 - mask images only if transparency enabled
|
---|
76 | * <br> - validate projection name by Lambert.toString() method
|
---|
77 | * <br>0.8 25-Jan-2009 - display returned list of communes if direct name is not recognized by server
|
---|
78 | * <br> - new possible grab factor of 100 square meters fixed size
|
---|
79 | * <br> - minor fixes due to changes in JOSM core classes
|
---|
80 | * <br> - first draft of raster image support
|
---|
81 | * <br>0.9 05-Feb-2009 - grab vectorized full commune bbox, save in file, convert to OSM way
|
---|
82 | * and simplify
|
---|
83 | * <br>1.0 18-Feb-2009 - fix various bugs in color management and preference dialog
|
---|
84 | * <br> - increase PNG picture size requested to WMS (800x1000)
|
---|
85 | * <br> - set 4th grab scale fixed size configurable (from 25 to 1000 meters)
|
---|
86 | * <br>1.1 11-Jun-2009 - fixed a null exception error when trying to displace a vectorized layer
|
---|
87 | * <br> - propose to use shortcut F11 for grabbing
|
---|
88 | * <br>1.2 16-Aug-2009 - implementation of raster image grabbing, cropping and georeferencing (not the
|
---|
89 | * <br> overview rasters (Tableau d'assemblage) but directly small units (Feuille)
|
---|
90 | * <br>1.3 23-Aug-2009 - improve georeferencing action cancellation
|
---|
91 | * <br> - fixed bug of raster image loaded from cache not working on Java1.6
|
---|
92 | * <br> - improve mouse click bounce detection during georeferencing process
|
---|
93 | * <br>1.4 25-Oct-2009 - add support for new Lambert CC 9 Zones projection
|
---|
94 | * <br> - add optional crosspieces display on raster image layers
|
---|
95 | * <br> - add automatic raster images georeferencing when WMS provides data
|
---|
96 | * <br> - re-implement manual adjustment mode in raster image layer
|
---|
97 | * <br>1.5 21-Nov-2009 - major changes in projection in core : no magical zone prediction anymore for
|
---|
98 | * Lambert 4 and 9 zones; grid translation implemented for Lambert 4 zones;
|
---|
99 | * support of subprojections in preferences for zones setting and UTM20N
|
---|
100 | * <br> - removed autosourcing of empty new nodes
|
---|
101 | * <br>1.6 28-Nov-2009 - Fix minor issues if Grab is called without layer (possible since projection rework)
|
---|
102 | * <br>1.7 12-Dec-2009 - Change URL's changes for cookie and downgrade imgs resolution due to WMS changes
|
---|
103 | * <br>1.8 11-Mar-2010 - filter the mouse button 1 during georeferencing
|
---|
104 | * <br> - retry if getting a new cookie failed (10 times during 30 seconds)
|
---|
105 | * <br> - cookie expiration automatically detected and renewed (after 30 minutes)
|
---|
106 | * <br> - proper WMS layer cleanup at destruction (workaround for memory leak)
|
---|
107 | * <br> - new cache format (v3) storing original image and cropped image bbox + angle
|
---|
108 | * <br> - new cache format (v4) storing original image size for later rotation
|
---|
109 | * <br> - cache files read compatible with previous formats
|
---|
110 | * <br> - raster image rotation issues fixed, now using shift+ctrl key instead of ctrl
|
---|
111 | * <br> - raster image adjustment using default system menu modifier (ctrl for windows) for Mac support
|
---|
112 | * <br> - image resolution configurable (high, medium, low) like the online interface
|
---|
113 | * <br> - layer selection configurable for vectorized images
|
---|
114 | * <br> - improved download cancellation
|
---|
115 | * <br> - from Erik Amzallag:
|
---|
116 | * <br> - possibility to modify the auto-sourcing text just before upload
|
---|
117 | * <br> - from Clément Ménier:
|
---|
118 | * <br> - new option allowing an auto-selection of the first cadastre layer for grab
|
---|
119 | * <br> - non-modal JDialog in MenuActionGrabPlanImage
|
---|
120 | * <br> - new options in the image filter (bilinear, bicubic)
|
---|
121 | * <br>1.9 05-Apr-2010 - added a scroll bar in preferences
|
---|
122 | * <br> - download cancellation improved
|
---|
123 | * <br> - last deployment for Java1.5 compatibility
|
---|
124 | * <br>2.0 07-Jul-2010 - update projection for "La Reunion" departement to RGR92, UTM40S.
|
---|
125 | * <br> - add 'departement' as option in the municipality selection
|
---|
126 | * <br> - fixed bug in cache directory size control (and disabled by default)
|
---|
127 | * <br> - add map mode for addressing
|
---|
128 | * <br> - from Nicolas Dumoulin:
|
---|
129 | * <br> - add "tableau d'assemblage" in raster images for georeferencing (as option)
|
---|
130 | * <br>2.1 14-Jan-2011 - add GrabThread moving the grab to a separate thread
|
---|
131 | * <br> - the divided BBox mode starts from the central square and loads the next in a spiral
|
---|
132 | * <br> - move the grabber from CadastrPlugin singleton to each wmsLayer instance to allow grabbing
|
---|
133 | * of multiple municipalities in parallel.
|
---|
134 | * <br>2.2 01-Jul-2011 - replace deprecated Main.proj by newest Main.getProjection()
|
---|
135 | * <br> - fix list of raster images (Feuilles) parsing failing after a Cadastre server change/maintenance
|
---|
136 | * <br>2.3 11-Jan-2013 - add various improvements from Don-Vip (Vincent Privat) trac #8175, #8229 and #5626.
|
---|
137 | * <br>2.4 27-Jun-2013 - fix raster image georeferencing issues. Add new MenuActionRefineGeoRef for a new georeferencing
|
---|
138 | * of already referenced plan image.
|
---|
139 | * <br>2.5 06-Aug-2013 - fix transparency issue on new raster images. Temporary disable georeferences parsing not
|
---|
140 | * working on new cadastre WMS.
|
---|
141 | * <br> - workaround on address help tool when switching to full screen
|
---|
142 | * <br> - improvement when clicking on existing node address street in mode relation
|
---|
143 | * <br> - option to simplify raster images in 2 bits colors (like images served in the past).
|
---|
144 | * <br>2.6 10-Sep-2013 - add JOSM "sessions" feature support (list of layers stored in a file)
|
---|
145 | */
|
---|
146 | public class CadastrePlugin extends Plugin {
|
---|
147 | static String VERSION = "2.6";
|
---|
148 |
|
---|
149 | static JMenu cadastreJMenu;
|
---|
150 |
|
---|
151 | public static String source = "";
|
---|
152 |
|
---|
153 | // true if the checkbox "auto-sourcing" is set in the plugin menu
|
---|
154 | public static boolean autoSourcing = false;
|
---|
155 |
|
---|
156 | // true when the plugin is first used, e.g. grab from WMS or download cache file
|
---|
157 | public static boolean pluginUsed = false;
|
---|
158 |
|
---|
159 | public static String cacheDir = null;
|
---|
160 |
|
---|
161 | public static boolean alterColors = false;
|
---|
162 |
|
---|
163 | public static boolean backgroundTransparent = false;
|
---|
164 |
|
---|
165 | public static float transparency = 1.0f;
|
---|
166 |
|
---|
167 | public static boolean drawBoundaries = false;
|
---|
168 |
|
---|
169 | public static int imageWidth, imageHeight;
|
---|
170 |
|
---|
171 | public static String grabLayers, grabStyles = null;
|
---|
172 |
|
---|
173 | private static boolean menuEnabled = false;
|
---|
174 |
|
---|
175 | private static String LAYER_BULDINGS = "CDIF:LS2";
|
---|
176 | private static String STYLE_BUILDING = "LS2_90";
|
---|
177 | private static String LAYER_WATER = "CDIF:LS3";
|
---|
178 | private static String STYLE_WATER = "LS3_90";
|
---|
179 | private static String LAYER_SYMBOL = "CDIF:LS1";
|
---|
180 | private static String STYLE_SYMBOL = "LS1_90";
|
---|
181 | private static String LAYER_PARCELS = "CDIF:PARCELLE";
|
---|
182 | private static String STYLE_PARCELS = "PARCELLE_90";
|
---|
183 | private static String LAYER_NUMERO = "CDIF:NUMERO";
|
---|
184 | private static String STYLE_NUMERO = "NUMERO_90";
|
---|
185 | private static String LAYER_LABEL = "CDIF:PT3,CDIF:PT2,CDIF:PT1";
|
---|
186 | private static String STYLE_LABEL = "PT3_90,PT2_90,PT1_90";
|
---|
187 | private static String LAYER_LIEUDIT = "CDIF:LIEUDIT";
|
---|
188 | private static String STYLE_LIEUDIT = "LIEUDIT_90";
|
---|
189 | private static String LAYER_SECTION = "CDIF:SUBSECTION,CDIF:SECTION";
|
---|
190 | private static String STYLE_SECTION = "SUBSECTION_90,SECTION_90";
|
---|
191 | private static String LAYER_COMMUNE = "CDIF:COMMUNE";
|
---|
192 | private static String STYLE_COMMUNE = "COMMUNE_90";
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Creates the plugin and setup the default settings if necessary.
|
---|
196 | * @param info plugin information
|
---|
197 | */
|
---|
198 | public CadastrePlugin(PluginInformation info) {
|
---|
199 | super(info);
|
---|
200 | Main.info("Pluging cadastre-fr v"+VERSION+" started...");
|
---|
201 | initCacheDir();
|
---|
202 |
|
---|
203 | refreshConfiguration();
|
---|
204 |
|
---|
205 | UploadAction.registerUploadHook(new CheckSourceUploadHook());
|
---|
206 |
|
---|
207 | registerSessionLayerExporter(WMSLayer.class, CadastreSessionExporter.class);
|
---|
208 | registerSessionLayerImporter("cadastre-fr", CadastreSessionImporter.class);
|
---|
209 | }
|
---|
210 |
|
---|
211 | private static void initCacheDir() {
|
---|
212 | if (Main.pref.get("cadastrewms.cacheDir").isEmpty()) {
|
---|
213 | cacheDir = new File(Main.pref.getCacheDirectory(), "cadastrewms").getAbsolutePath();
|
---|
214 | } else {
|
---|
215 | cacheDir = Main.pref.get("cadastrewms.cacheDir");
|
---|
216 | }
|
---|
217 | if (cacheDir.charAt(cacheDir.length()-1) != File.separatorChar)
|
---|
218 | cacheDir += File.separatorChar;
|
---|
219 | Main.info("current cache directory: "+cacheDir);
|
---|
220 | }
|
---|
221 |
|
---|
222 | public static void refreshMenu() {
|
---|
223 | MainMenu menu = Main.main.menu;
|
---|
224 |
|
---|
225 | if (cadastreJMenu == null) {
|
---|
226 | cadastreJMenu = menu.addMenu("Cadastre", tr("Cadastre"), KeyEvent.VK_C, menu.getDefaultMenuPos(), ht("/Plugin/CadastreFr"));
|
---|
227 | JosmAction grab = new MenuActionGrab();
|
---|
228 | JMenuItem menuGrab = new JMenuItem(grab);
|
---|
229 | KeyStroke ks = grab.getShortcut().getKeyStroke();
|
---|
230 | if (ks != null) {
|
---|
231 | menuGrab.setAccelerator(ks);
|
---|
232 | }
|
---|
233 | JMenuItem menuActionGrabPlanImage = new JMenuItem(new MenuActionGrabPlanImage());
|
---|
234 | JMenuItem menuSettings = new JMenuItem(new MenuActionNewLocation());
|
---|
235 | final JCheckBoxMenuItem menuSource = new JCheckBoxMenuItem(tr("Auto sourcing"));
|
---|
236 | menuSource.setSelected(autoSourcing);
|
---|
237 | menuSource.addActionListener(new ActionListener() {
|
---|
238 | @Override
|
---|
239 | public void actionPerformed(ActionEvent ev) {
|
---|
240 | Main.pref.put("cadastrewms.autosourcing", menuSource.isSelected());
|
---|
241 | autoSourcing = menuSource.isSelected();
|
---|
242 | }
|
---|
243 | });
|
---|
244 |
|
---|
245 | //JMenuItem menuResetCookie = new JMenuItem(new MenuActionResetCookie());
|
---|
246 | //JMenuItem menuLambertZone = new JMenuItem(new MenuActionLambertZone());
|
---|
247 | JMenuItem menuLoadFromCache = new JMenuItem(new MenuActionLoadFromCache());
|
---|
248 | // temporary disabled:
|
---|
249 | //JMenuItem menuActionBoundaries = new JMenuItem(new MenuActionBoundaries());
|
---|
250 | //JMenuItem menuActionBuildings = new JMenuItem(new MenuActionBuildings());
|
---|
251 |
|
---|
252 | cadastreJMenu.add(menuGrab);
|
---|
253 | cadastreJMenu.add(menuActionGrabPlanImage);
|
---|
254 | cadastreJMenu.add(menuSettings);
|
---|
255 | cadastreJMenu.add(menuSource);
|
---|
256 | //cadastreJMenu.add(menuResetCookie); not required any more
|
---|
257 | //cadastreJMenu.add(menuLambertZone);
|
---|
258 | //if (Main.pref.getBoolean("cadastrewms.buildingsMenu", false))
|
---|
259 | // cadastreJMenu.add(menuActionBuildings);
|
---|
260 | cadastreJMenu.add(menuLoadFromCache);
|
---|
261 | // all SVG features disabled until official WMS is released
|
---|
262 | //cadastreJMenu.add(menuActionBoundaries);
|
---|
263 | cadastreJMenu.add(new JMenuItem(new MenuActionOpenPreferences()));
|
---|
264 | }
|
---|
265 | setEnabledAll(menuEnabled);
|
---|
266 | }
|
---|
267 |
|
---|
268 | public static void refreshConfiguration() {
|
---|
269 | source = checkSourceMillesime();
|
---|
270 | autoSourcing = Main.pref.getBoolean("cadastrewms.autosourcing", true);
|
---|
271 | alterColors = Main.pref.getBoolean("cadastrewms.alterColors");
|
---|
272 | drawBoundaries = Main.pref.getBoolean("cadastrewms.drawBoundaries", false);
|
---|
273 | if (alterColors) {
|
---|
274 | backgroundTransparent = Main.pref.getBoolean("cadastrewms.backgroundTransparent");
|
---|
275 | transparency = Float.parseFloat(Main.pref.get("cadastrewms.brightness", "1.0f"));
|
---|
276 | } else {
|
---|
277 | backgroundTransparent = false;
|
---|
278 | transparency = 1.0f;
|
---|
279 | }
|
---|
280 | String currentResolution = Main.pref.get("cadastrewms.resolution", "high");
|
---|
281 | if (currentResolution.equals("high")) {
|
---|
282 | imageWidth = 1000; imageHeight = 800;
|
---|
283 | } else if (currentResolution.equals("medium")) {
|
---|
284 | imageWidth = 800; imageHeight = 600;
|
---|
285 | } else {
|
---|
286 | imageWidth = 600; imageHeight = 400;
|
---|
287 | }
|
---|
288 | refreshLayersURL();
|
---|
289 | refreshMenu();
|
---|
290 | }
|
---|
291 |
|
---|
292 | private static void refreshLayersURL() {
|
---|
293 | grabLayers = "";
|
---|
294 | grabStyles = "";
|
---|
295 | int countLayers = 0;
|
---|
296 | if (Main.pref.getBoolean("cadastrewms.layerWater", true)) {
|
---|
297 | grabLayers += LAYER_WATER + ",";
|
---|
298 | grabStyles += STYLE_WATER + ",";
|
---|
299 | countLayers++;
|
---|
300 | }
|
---|
301 | if (Main.pref.getBoolean("cadastrewms.layerBuilding", true)) {
|
---|
302 | grabLayers += LAYER_BULDINGS + ",";
|
---|
303 | grabStyles += STYLE_BUILDING + ",";
|
---|
304 | countLayers++;
|
---|
305 | }
|
---|
306 | if (Main.pref.getBoolean("cadastrewms.layerSymbol", true)) {
|
---|
307 | grabLayers += LAYER_SYMBOL + ",";
|
---|
308 | grabStyles += STYLE_SYMBOL + ",";
|
---|
309 | countLayers++;
|
---|
310 | }
|
---|
311 | if (Main.pref.getBoolean("cadastrewms.layerParcel", true)) {
|
---|
312 | grabLayers += LAYER_PARCELS + ",";
|
---|
313 | grabStyles += STYLE_PARCELS + ",";
|
---|
314 | countLayers++;
|
---|
315 | }
|
---|
316 | if (Main.pref.getBoolean("cadastrewms.layerNumero", true)) {
|
---|
317 | grabLayers += LAYER_NUMERO + ",";
|
---|
318 | grabStyles += STYLE_NUMERO + ",";
|
---|
319 | countLayers++;
|
---|
320 | }
|
---|
321 | if (Main.pref.getBoolean("cadastrewms.layerLabel", true)) {
|
---|
322 | grabLayers += LAYER_LABEL + ",";
|
---|
323 | grabStyles += STYLE_LABEL + ",";
|
---|
324 | countLayers++;
|
---|
325 | }
|
---|
326 | if (Main.pref.getBoolean("cadastrewms.layerLieudit", true)) {
|
---|
327 | grabLayers += LAYER_LIEUDIT + ",";
|
---|
328 | grabStyles += STYLE_LIEUDIT + ",";
|
---|
329 | countLayers++;
|
---|
330 | }
|
---|
331 | if (Main.pref.getBoolean("cadastrewms.layerSection", true)) {
|
---|
332 | grabLayers += LAYER_SECTION + ",";
|
---|
333 | grabStyles += STYLE_SECTION + ",";
|
---|
334 | countLayers++;
|
---|
335 | }
|
---|
336 | if (Main.pref.getBoolean("cadastrewms.layerCommune", true)) {
|
---|
337 | grabLayers += LAYER_COMMUNE + ",";
|
---|
338 | grabStyles += STYLE_COMMUNE + ",";
|
---|
339 | countLayers++;
|
---|
340 | }
|
---|
341 | if (countLayers > 2) { // remove the last ','
|
---|
342 | grabLayers = grabLayers.substring(0, grabLayers.length()-1);
|
---|
343 | grabStyles = grabStyles.substring(0, grabStyles.length()-1);
|
---|
344 | } else {
|
---|
345 | JOptionPane.showMessageDialog(Main.parent, tr("Please enable at least two WMS layers in the cadastre-fr "
|
---|
346 | + "plugin configuration.\nLayers ''Building'' and ''Parcel'' added by default."));
|
---|
347 | Main.pref.put("cadastrewms.layerBuilding", true);
|
---|
348 | Main.pref.put("cadastrewms.layerParcel", true);
|
---|
349 | grabLayers += LAYER_BULDINGS + "," + LAYER_PARCELS;
|
---|
350 | grabStyles += STYLE_BUILDING + "," + STYLE_PARCELS;
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | @Override
|
---|
355 | public PreferenceSetting getPreferenceSetting() {
|
---|
356 | return new CadastrePreferenceSetting();
|
---|
357 | }
|
---|
358 |
|
---|
359 | private static void setEnabledAll(boolean isEnabled) {
|
---|
360 | for (int i = 0; i < cadastreJMenu.getItemCount(); i++) {
|
---|
361 | JMenuItem item = cadastreJMenu.getItem(i);
|
---|
362 | if (item != null)
|
---|
363 | if (item.getText().equals(MenuActionGrabPlanImage.NAME) /*||
|
---|
364 | item.getText().equals(MenuActionGrab.name) ||
|
---|
365 | item.getText().equals(MenuActionBoundaries.name) ||
|
---|
366 | item.getText().equals(MenuActionBuildings.name)*/) {
|
---|
367 | item.setEnabled(isEnabled);
|
---|
368 | }
|
---|
369 | }
|
---|
370 | menuEnabled = isEnabled;
|
---|
371 | }
|
---|
372 |
|
---|
373 | @Override
|
---|
374 | public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
|
---|
375 | if (cadastreJMenu != null) {
|
---|
376 | if (oldFrame == null && newFrame != null) {
|
---|
377 | setEnabledAll(true);
|
---|
378 | Main.map.addMapMode(new IconToggleButton(new WMSAdjustAction()));
|
---|
379 | Main.map.addMapMode(new IconToggleButton(new Address()));
|
---|
380 | } else if (oldFrame != null && newFrame == null) {
|
---|
381 | setEnabledAll(false);
|
---|
382 | //Lambert.layoutZone = -1;
|
---|
383 | //LambertCC9Zones.layoutZone = -1;
|
---|
384 | }
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | public static boolean isLambert() {
|
---|
389 | String code = Main.getProjection().toCode();
|
---|
390 | return Arrays.asList(ProjectionPreference.lambert.allCodes()).contains(code);
|
---|
391 | }
|
---|
392 |
|
---|
393 | public static boolean isUtm_france_dom() {
|
---|
394 | String code = Main.getProjection().toCode();
|
---|
395 | return Arrays.asList(ProjectionPreference.utm_france_dom.allCodes()).contains(code);
|
---|
396 | }
|
---|
397 |
|
---|
398 | public static boolean isLambert_cc9() {
|
---|
399 | String code = Main.getProjection().toCode();
|
---|
400 | return Arrays.asList(ProjectionPreference.lambert_cc9.allCodes()).contains(code);
|
---|
401 | }
|
---|
402 |
|
---|
403 | public static boolean isCadastreProjection() {
|
---|
404 | return isLambert() || isUtm_france_dom() || isLambert_cc9();
|
---|
405 | }
|
---|
406 |
|
---|
407 | public static int getCadastreProjectionLayoutZone() {
|
---|
408 | int zone = -1;
|
---|
409 | Projection proj = Main.getProjection();
|
---|
410 | if (proj instanceof AbstractProjection) {
|
---|
411 | Integer code = ((AbstractProjection) proj).getEpsgCode();
|
---|
412 | if (code != null) {
|
---|
413 | if (code >= 3942 && code <= 3950) { // LambertCC9Zones
|
---|
414 | zone = code - 3942;
|
---|
415 | } else if (code >= 27561 && 27564 <= code) { // Lambert
|
---|
416 | zone = code - 27561;
|
---|
417 | } else { // UTM_France_DOM
|
---|
418 | Map<Integer, Integer> utmfr = new HashMap<>();
|
---|
419 | utmfr.put(2969, 0);
|
---|
420 | utmfr.put(2970, 1);
|
---|
421 | utmfr.put(2973, 2);
|
---|
422 | utmfr.put(2975, 3);
|
---|
423 | utmfr.put(2972, 4);
|
---|
424 | if (utmfr.containsKey(code)) {
|
---|
425 | zone = utmfr.get(code);
|
---|
426 | }
|
---|
427 | }
|
---|
428 | }
|
---|
429 | }
|
---|
430 | return zone;
|
---|
431 | }
|
---|
432 |
|
---|
433 | public static void safeSleep(long milliseconds) {
|
---|
434 | try {
|
---|
435 | Thread.sleep(milliseconds);
|
---|
436 | } catch (InterruptedException e) {
|
---|
437 | Main.debug(e);
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | // See OptionPaneUtil
|
---|
442 | // FIXME: this is a temporary solution.
|
---|
443 | public static void prepareDialog(JDialog dialog) {
|
---|
444 | if (Main.pref.getBoolean("window-handling.option-pane-always-on-top", true)) {
|
---|
445 | try {
|
---|
446 | dialog.setAlwaysOnTop(true);
|
---|
447 | } catch (SecurityException e) {
|
---|
448 | Main.warn(tr("Warning: failed to put option pane dialog always on top. Exception was: {0}", e.toString()));
|
---|
449 | }
|
---|
450 | }
|
---|
451 | dialog.setModal(true);
|
---|
452 | dialog.toFront();
|
---|
453 | dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
---|
454 | }
|
---|
455 |
|
---|
456 | /**
|
---|
457 | * Adds the WMSLayer following this rule:<br/>
|
---|
458 | * - if a WMSLayer exists place this new layer just before this layer<br/>
|
---|
459 | * - Otherwise place it at the bottom
|
---|
460 | * @param wmsLayer the wmsLayer to add
|
---|
461 | */
|
---|
462 | public static void addWMSLayer(WMSLayer wmsLayer) {
|
---|
463 | if (Main.map != null && Main.map.mapView != null) {
|
---|
464 | int wmsNewLayerPos = Main.getLayerManager().getLayers().size();
|
---|
465 | for (Layer l : Main.getLayerManager().getLayersOfType(WMSLayer.class)) {
|
---|
466 | int wmsPos = Main.getLayerManager().getLayers().indexOf(l);
|
---|
467 | if (wmsPos < wmsNewLayerPos) wmsNewLayerPos = wmsPos;
|
---|
468 | }
|
---|
469 | Main.getLayerManager().addLayer(wmsLayer);
|
---|
470 | // Move the layer to its new position
|
---|
471 | Main.map.mapView.moveLayer(wmsLayer, wmsNewLayerPos);
|
---|
472 | } else
|
---|
473 | Main.getLayerManager().addLayer(wmsLayer);
|
---|
474 | }
|
---|
475 |
|
---|
476 | private static String checkSourceMillesime() {
|
---|
477 | java.util.Calendar calendar = java.util.Calendar.getInstance();
|
---|
478 | int currentYear = calendar.get(java.util.Calendar.YEAR);
|
---|
479 | String src = Main.pref.get("cadastrewms.source",
|
---|
480 | "cadastre-dgi-fr source : Direction G\u00e9n\u00e9rale des Imp\u00f4ts - Cadastre. Mise \u00e0 jour : AAAA");
|
---|
481 | String srcYear = src.substring(src.lastIndexOf(" ")+1);
|
---|
482 | Integer year = null;
|
---|
483 | try {
|
---|
484 | year = Integer.decode(srcYear);
|
---|
485 | } catch (NumberFormatException e) {
|
---|
486 | Main.debug(e);
|
---|
487 | }
|
---|
488 | if (srcYear.equals("AAAA") || (year != null && year < currentYear)) {
|
---|
489 | Main.info("Replace source year "+srcYear+" by current year "+currentYear);
|
---|
490 | src = src.substring(0, src.lastIndexOf(" ")+1)+currentYear;
|
---|
491 | Main.pref.put("cadastrewms.source", src);
|
---|
492 | }
|
---|
493 | return src;
|
---|
494 | }
|
---|
495 |
|
---|
496 | /**
|
---|
497 | * Ask to change projection if current one is not suitable for French cadastre.
|
---|
498 | */
|
---|
499 | public static void askToChangeProjection() {
|
---|
500 | GuiHelper.runInEDTAndWait(new Runnable() {
|
---|
501 | @Override
|
---|
502 | public void run() {
|
---|
503 | if (JOptionPane.showConfirmDialog(Main.parent,
|
---|
504 | tr("To enable the cadastre WMS plugin, change\n"
|
---|
505 | + "the current projection to one of the cadastre\n"
|
---|
506 | + "projections and retry"),
|
---|
507 | tr("Change the current projection"), JOptionPane.OK_CANCEL_OPTION)
|
---|
508 | == JOptionPane.OK_OPTION) {
|
---|
509 | PreferenceDialog p = new PreferenceDialog(Main.parent);
|
---|
510 | p.selectPreferencesTabByClass(MapPreference.class);
|
---|
511 | p.getTabbedPane().getSetting(ProjectionPreference.class).selectProjection(ProjectionPreference.lambert_cc9);
|
---|
512 | p.setVisible(true);
|
---|
513 | }
|
---|
514 | }
|
---|
515 | });
|
---|
516 | }
|
---|
517 | }
|
---|