1 | // License: GPL. v2 and later. Copyright 2008-2009 by Pieren <pieren3@gmail.com> and others
|
---|
2 | package cadastre_fr;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.ActionListener;
|
---|
8 | import javax.swing.*;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.Main;
|
---|
11 | import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
|
---|
12 | import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
|
---|
13 | import org.openstreetmap.josm.tools.GBC;
|
---|
14 | import org.openstreetmap.josm.tools.I18n;
|
---|
15 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Preference settings for the French Cadastre plugin
|
---|
19 | *
|
---|
20 | * @author Pieren <pieren3@gmail.com>
|
---|
21 | */
|
---|
22 | public class CadastrePreferenceSetting implements PreferenceSetting {
|
---|
23 |
|
---|
24 | static final int TRANS_MIN = 1;
|
---|
25 | static final int TRANS_MAX = 10;
|
---|
26 | private JSlider sliderTrans = new JSlider(JSlider.HORIZONTAL, TRANS_MIN, TRANS_MAX, TRANS_MAX);
|
---|
27 |
|
---|
28 | private JTextField sourcing = new JTextField(20);
|
---|
29 |
|
---|
30 | private JCheckBox alterColors = new JCheckBox(tr("Replace original background by JOSM background color."));
|
---|
31 |
|
---|
32 | private JCheckBox reversGrey = new JCheckBox(tr("Reverse grey colors (for black backgrounds)."));
|
---|
33 |
|
---|
34 | private JCheckBox transparency = new JCheckBox(tr("Set background transparent."));
|
---|
35 |
|
---|
36 | private JCheckBox drawBoundaries = new JCheckBox(tr("Draw boundaries of downloaded data."));
|
---|
37 |
|
---|
38 | private JCheckBox disableImageCropping = new JCheckBox(tr("Disable image cropping during georeferencing."));
|
---|
39 |
|
---|
40 | private JRadioButton grabMultiplier1 = new JRadioButton("", true);
|
---|
41 |
|
---|
42 | private JRadioButton grabMultiplier2 = new JRadioButton("", true);
|
---|
43 |
|
---|
44 | private JRadioButton grabMultiplier3 = new JRadioButton("", true);
|
---|
45 |
|
---|
46 | private JRadioButton grabMultiplier4 = new JRadioButton("", true);
|
---|
47 |
|
---|
48 | private JRadioButton crosspiece1 = new JRadioButton("off");
|
---|
49 |
|
---|
50 | private JRadioButton crosspiece2 = new JRadioButton("25m");
|
---|
51 |
|
---|
52 | private JRadioButton crosspiece3 = new JRadioButton("50m");
|
---|
53 |
|
---|
54 | private JRadioButton crosspiece4 = new JRadioButton("100m");
|
---|
55 |
|
---|
56 | private JCheckBox autoFirstLayer = new JCheckBox(tr("Automaticly select first WMS layer when grabing if multiple layers exist."));
|
---|
57 |
|
---|
58 | static final int DEFAULT_SQUARE_SIZE = 100;
|
---|
59 | private JTextField grabMultiplier4Size = new JTextField(5);
|
---|
60 |
|
---|
61 | private JCheckBox enableCache = new JCheckBox(tr("Enable automatic caching."));
|
---|
62 |
|
---|
63 | static final int DEFAULT_CACHE_SIZE = 500;
|
---|
64 | JLabel jLabelCacheSize = new JLabel(tr("Max. cache size (in MB)"));
|
---|
65 | private JTextField cacheSize = new JTextField(20);
|
---|
66 |
|
---|
67 | static final String DEFAULT_RASTER_DIVIDER = "5";
|
---|
68 | private JTextField rasterDivider = new JTextField(10);
|
---|
69 |
|
---|
70 | static final int DEFAULT_CROSSPIECES = 0;
|
---|
71 |
|
---|
72 | public void addGui(final PreferenceTabbedPane gui) {
|
---|
73 |
|
---|
74 | String description = tr("A special handler of the French cadastre wms at www.cadastre.gouv.fr" + "<BR><BR>"
|
---|
75 | + "Please read the Terms and Conditions of Use here (in French): <br>"
|
---|
76 | + "<a href=\"http://www.cadastre.gouv.fr/scpc/html/CU_01_ConditionsGenerales_fr.html\"> "
|
---|
77 | + "http://www.cadastre.gouv.fr/scpc/html/CU_01_ConditionsGenerales_fr.html</a> <BR>"
|
---|
78 | + "before any upload of data created by this plugin.");
|
---|
79 | JPanel cadastrewms = gui.createPreferenceTab("cadastrewms.gif", I18n.tr("French cadastre WMS"), description);
|
---|
80 |
|
---|
81 | // option to automatically set the source tag when uploading
|
---|
82 | sourcing.setText(CadastrePlugin.source);
|
---|
83 | sourcing.setToolTipText(tr("<html>Value of key \"source\" when autosourcing is enabled</html>"));
|
---|
84 | JLabel jLabelSource = new JLabel(tr("Source"));
|
---|
85 | cadastrewms.add(jLabelSource, GBC.eop().insets(0, 0, 0, 0));
|
---|
86 | cadastrewms.add(sourcing, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 0, 0, 5));
|
---|
87 |
|
---|
88 | // option to alter the original colors of the wms images
|
---|
89 | alterColors.setSelected(Main.pref.getBoolean("cadastrewms.alterColors", false));
|
---|
90 | alterColors.setToolTipText(tr("Replace the original white background by the backgound color defined in JOSM preferences."));
|
---|
91 | cadastrewms.add(alterColors, GBC.eop().insets(0, 0, 0, 0));
|
---|
92 |
|
---|
93 | // option to reverse the grey colors (to see texts background)
|
---|
94 | reversGrey.setSelected(Main.pref.getBoolean("cadastrewms.invertGrey", false));
|
---|
95 | reversGrey.setToolTipText(tr("Invert the original black and white colors (and all intermediate greys). Useful for texts on dark backgrounds."));
|
---|
96 | cadastrewms.add(reversGrey, GBC.eop().insets(00, 0, 0, 0));
|
---|
97 |
|
---|
98 | // option to enable transparency
|
---|
99 | transparency.addActionListener(new ActionListener() {
|
---|
100 | public void actionPerformed(ActionEvent e) {
|
---|
101 | sliderTrans.setEnabled(transparency.isSelected());
|
---|
102 | }
|
---|
103 | });
|
---|
104 | transparency.setSelected(Main.pref.getBoolean("cadastrewms.backgroundTransparent", false));
|
---|
105 | transparency.setToolTipText(tr("Allows multiple layers stacking"));
|
---|
106 | cadastrewms.add(transparency, GBC.eop().insets(0, 0, 0, 0));
|
---|
107 |
|
---|
108 | // slider for transparency level
|
---|
109 | sliderTrans.setSnapToTicks(true);
|
---|
110 | sliderTrans.setToolTipText(tr("Set WMS layers transparency. Right is opaque, left is transparent."));
|
---|
111 | sliderTrans.setMajorTickSpacing(10);
|
---|
112 | sliderTrans.setMinorTickSpacing(1);
|
---|
113 | sliderTrans.setValue((int)(Float.parseFloat(Main.pref.get("cadastrewms.brightness", "1.0f"))*10));
|
---|
114 | sliderTrans.setPaintTicks(true);
|
---|
115 | sliderTrans.setPaintLabels(false);
|
---|
116 | sliderTrans.setEnabled(transparency.isSelected());
|
---|
117 | cadastrewms.add(sliderTrans, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 250, 0));
|
---|
118 |
|
---|
119 | // option to draw boundaries of downloaded data
|
---|
120 | drawBoundaries.setSelected(Main.pref.getBoolean("cadastrewms.drawBoundaries", false));
|
---|
121 | drawBoundaries.setToolTipText(tr("Draw a rectangle around downloaded data from WMS server."));
|
---|
122 | cadastrewms.add(drawBoundaries, GBC.eop().insets(0, 0, 0, 5));
|
---|
123 |
|
---|
124 | // separator
|
---|
125 | cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
126 |
|
---|
127 | // the vectorized images multiplier
|
---|
128 | JLabel jLabelScale = new JLabel(tr("Vector images grab multiplier:"));
|
---|
129 | cadastrewms.add(jLabelScale, GBC.std().insets(0, 5, 10, 0));
|
---|
130 | ButtonGroup bgGrabMultiplier = new ButtonGroup();
|
---|
131 | ActionListener multiplierActionListener = new ActionListener() {
|
---|
132 | public void actionPerformed(ActionEvent actionEvent) {
|
---|
133 | AbstractButton button = (AbstractButton) actionEvent.getSource();
|
---|
134 | grabMultiplier4Size.setEnabled(button == grabMultiplier4);
|
---|
135 | }
|
---|
136 | };
|
---|
137 | grabMultiplier1.setIcon(ImageProvider.get("preferences", "unsel_box_1"));
|
---|
138 | grabMultiplier1.setSelectedIcon(ImageProvider.get("preferences", "sel_box_1"));
|
---|
139 | grabMultiplier1.addActionListener( multiplierActionListener);
|
---|
140 | grabMultiplier2.setIcon(ImageProvider.get("preferences", "unsel_box_2"));
|
---|
141 | grabMultiplier2.setSelectedIcon(ImageProvider.get("preferences", "sel_box_2"));
|
---|
142 | grabMultiplier2.addActionListener( multiplierActionListener);
|
---|
143 | grabMultiplier2.setToolTipText(tr("Grab smaller images (higher quality but use more memory)"));
|
---|
144 | grabMultiplier3.setIcon(ImageProvider.get("preferences", "unsel_box_3"));
|
---|
145 | grabMultiplier3.setSelectedIcon(ImageProvider.get("preferences", "sel_box_3"));
|
---|
146 | grabMultiplier3.addActionListener( multiplierActionListener);
|
---|
147 | grabMultiplier3.setToolTipText(tr("Grab smaller images (higher quality but use more memory)"));
|
---|
148 | grabMultiplier4.setIcon(ImageProvider.get("preferences", "unsel_box_4"));
|
---|
149 | grabMultiplier4.setSelectedIcon(ImageProvider.get("preferences", "sel_box_4"));
|
---|
150 | grabMultiplier4.addActionListener( multiplierActionListener);
|
---|
151 | grabMultiplier4.setToolTipText(tr("Fixed size square (default is 100m)"));
|
---|
152 | bgGrabMultiplier.add(grabMultiplier1);
|
---|
153 | bgGrabMultiplier.add(grabMultiplier2);
|
---|
154 | bgGrabMultiplier.add(grabMultiplier3);
|
---|
155 | bgGrabMultiplier.add(grabMultiplier4);
|
---|
156 | String currentScale = Main.pref.get("cadastrewms.scale", "1");
|
---|
157 | if (currentScale.equals(Scale.X1.value))
|
---|
158 | grabMultiplier1.setSelected(true);
|
---|
159 | if (currentScale.equals(Scale.X2.value))
|
---|
160 | grabMultiplier2.setSelected(true);
|
---|
161 | if (currentScale.equals(Scale.X3.value))
|
---|
162 | grabMultiplier3.setSelected(true);
|
---|
163 | if (currentScale.equals(Scale.SQUARE_100M.value))
|
---|
164 | grabMultiplier4.setSelected(true);
|
---|
165 | cadastrewms.add(grabMultiplier1, GBC.std().insets(5, 0, 5, 0));
|
---|
166 | cadastrewms.add(grabMultiplier2, GBC.std().insets(5, 0, 5, 0));
|
---|
167 | cadastrewms.add(grabMultiplier3, GBC.std().insets(5, 0, 5, 0));
|
---|
168 | cadastrewms.add(grabMultiplier4, GBC.std().insets(5, 0, 5, 0));
|
---|
169 | int squareSize = getNumber("cadastrewms.squareSize", DEFAULT_SQUARE_SIZE);
|
---|
170 | grabMultiplier4Size.setText(String.valueOf(squareSize));
|
---|
171 | grabMultiplier4Size.setToolTipText(tr("Fixed size (from 25 to 1000 meters)"));
|
---|
172 | grabMultiplier4Size.setEnabled(currentScale.equals(Scale.SQUARE_100M.value));
|
---|
173 | cadastrewms.add(grabMultiplier4Size, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
|
---|
174 |
|
---|
175 | // separator
|
---|
176 | cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
177 |
|
---|
178 | // for raster images (not vectorized), image grab divider (from 1 to 12)
|
---|
179 | String savedRasterDivider = Main.pref.get("cadastrewms.rasterDivider", DEFAULT_RASTER_DIVIDER);
|
---|
180 | JLabel jLabelRasterDivider = new JLabel(tr("Raster images grab multiplier:"));
|
---|
181 | rasterDivider.setText(savedRasterDivider);
|
---|
182 | rasterDivider.setToolTipText("Raster image grab division, from 1 to 12; 12 is very high definition");
|
---|
183 | cadastrewms.add(jLabelRasterDivider, GBC.std().insets(0, 5, 10, 0));
|
---|
184 | cadastrewms.add(rasterDivider, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5));
|
---|
185 | // option to disable image cropping during raster image georeferencing
|
---|
186 | disableImageCropping.setSelected(Main.pref.getBoolean("cadastrewms.noImageCropping", false));
|
---|
187 | disableImageCropping.setToolTipText(tr("Disable image cropping during georeferencing."));
|
---|
188 | cadastrewms.add(disableImageCropping, GBC.eop().insets(0, 0, 0, 0));
|
---|
189 | // the crosspiece display
|
---|
190 | JLabel jLabelCrosspieces = new JLabel(tr("Display crosspieces:"));
|
---|
191 | cadastrewms.add(jLabelCrosspieces, GBC.std().insets(0, 0, 10, 0));
|
---|
192 | ButtonGroup bgCrosspieces = new ButtonGroup();
|
---|
193 | int crosspieces = getNumber("cadastrewms.crosspieces", DEFAULT_CROSSPIECES);
|
---|
194 | if (crosspieces == 0) crosspiece1.setSelected(true);
|
---|
195 | if (crosspieces == 1) crosspiece2.setSelected(true);
|
---|
196 | if (crosspieces == 2) crosspiece3.setSelected(true);
|
---|
197 | if (crosspieces == 3) crosspiece4.setSelected(true);
|
---|
198 | bgCrosspieces.add(crosspiece1);
|
---|
199 | bgCrosspieces.add(crosspiece2);
|
---|
200 | bgCrosspieces.add(crosspiece3);
|
---|
201 | bgCrosspieces.add(crosspiece4);
|
---|
202 | cadastrewms.add(crosspiece1, GBC.std().insets(5, 0, 5, 0));
|
---|
203 | cadastrewms.add(crosspiece2, GBC.std().insets(5, 0, 5, 0));
|
---|
204 | cadastrewms.add(crosspiece3, GBC.std().insets(5, 0, 5, 0));
|
---|
205 | cadastrewms.add(crosspiece4, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5));
|
---|
206 |
|
---|
207 | // separator
|
---|
208 | cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
209 |
|
---|
210 | // option to enable automatic caching
|
---|
211 | enableCache.addActionListener(new ActionListener() {
|
---|
212 | public void actionPerformed(ActionEvent e) {
|
---|
213 | jLabelCacheSize.setEnabled(enableCache.isSelected());
|
---|
214 | cacheSize.setEnabled(enableCache.isSelected());
|
---|
215 | }
|
---|
216 | });
|
---|
217 | enableCache.setSelected(Main.pref.getBoolean("cadastrewms.enableCaching", true));
|
---|
218 | enableCache.setToolTipText(tr("Replace the original white background by the backgound color defined in JOSM preferences."));
|
---|
219 | cadastrewms.add(enableCache, GBC.eop().insets(0, 0, 0, 0));
|
---|
220 |
|
---|
221 | // option to fix the cache size(in MB)
|
---|
222 | int size = getNumber("cadastrewms.cacheSize", DEFAULT_CACHE_SIZE);
|
---|
223 | cacheSize.setText(String.valueOf(size));
|
---|
224 | cacheSize.setToolTipText(tr("Oldest files are automatically deleted when this size is exceeded"));
|
---|
225 | cadastrewms.add(jLabelCacheSize, GBC.std().insets(20, 0, 0, 0));
|
---|
226 | cadastrewms.add(cacheSize, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 200, 5));
|
---|
227 | // separator
|
---|
228 | cadastrewms.add(new JSeparator(SwingConstants.HORIZONTAL), GBC.eol().fill(GBC.HORIZONTAL));
|
---|
229 | autoFirstLayer.setSelected(Main.pref.getBoolean("cadastrewms.autoFirstLayer", false));
|
---|
230 | autoFirstLayer.setToolTipText(tr("Automatically selects the first WMS layer if multiple layers exist when grabbing."));
|
---|
231 | cadastrewms.add(autoFirstLayer, GBC.eop().insets(0, 0, 0, 0));
|
---|
232 | cadastrewms.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL));
|
---|
233 |
|
---|
234 | }
|
---|
235 |
|
---|
236 | public boolean ok() {
|
---|
237 | Main.pref.put("cadastrewms.source", sourcing.getText());
|
---|
238 | CadastrePlugin.source = sourcing.getText();
|
---|
239 | Main.pref.put("cadastrewms.alterColors", alterColors.isSelected());
|
---|
240 | Main.pref.put("cadastrewms.invertGrey", reversGrey.isSelected());
|
---|
241 | Main.pref.put("cadastrewms.backgroundTransparent", transparency.isSelected());
|
---|
242 | Main.pref.put("cadastrewms.brightness", Float.toString((float)sliderTrans.getValue()/10));
|
---|
243 | Main.pref.put("cadastrewms.drawBoundaries", drawBoundaries.isSelected());
|
---|
244 | if (grabMultiplier1.isSelected())
|
---|
245 | Main.pref.put("cadastrewms.scale", Scale.X1.toString());
|
---|
246 | else if (grabMultiplier2.isSelected())
|
---|
247 | Main.pref.put("cadastrewms.scale", Scale.X2.toString());
|
---|
248 | else if (grabMultiplier3.isSelected())
|
---|
249 | Main.pref.put("cadastrewms.scale", Scale.X3.toString());
|
---|
250 | else {
|
---|
251 | Main.pref.put("cadastrewms.scale", Scale.SQUARE_100M.toString());
|
---|
252 | try {
|
---|
253 | int squareSize = Integer.parseInt(grabMultiplier4Size.getText());
|
---|
254 | if (squareSize >= 25 && squareSize <= 1000)
|
---|
255 | Main.pref.put("cadastrewms.squareSize", grabMultiplier4Size.getText());
|
---|
256 | } catch (NumberFormatException e) { // ignore the last input
|
---|
257 | }
|
---|
258 | }
|
---|
259 | try {
|
---|
260 | int i = Integer.parseInt(rasterDivider.getText());
|
---|
261 | if (i > 0 && i < 13)
|
---|
262 | Main.pref.put("cadastrewms.rasterDivider", String.valueOf(i));
|
---|
263 | } catch (NumberFormatException e) { // ignore the last input
|
---|
264 | }
|
---|
265 | Main.pref.put("cadastrewms.noImageCropping", disableImageCropping.isSelected());
|
---|
266 | if (crosspiece1.isSelected()) Main.pref.put("cadastrewms.crosspieces", "0");
|
---|
267 | else if (crosspiece2.isSelected()) Main.pref.put("cadastrewms.crosspieces", "1");
|
---|
268 | else if (crosspiece3.isSelected()) Main.pref.put("cadastrewms.crosspieces", "2");
|
---|
269 | else if (crosspiece4.isSelected()) Main.pref.put("cadastrewms.crosspieces", "3");
|
---|
270 | Main.pref.put("cadastrewms.enableCaching", enableCache.isSelected());
|
---|
271 |
|
---|
272 | // spread data into objects instead of restarting the application
|
---|
273 | try {
|
---|
274 | CacheControl.cacheSize = Integer.parseInt(cacheSize.getText());
|
---|
275 | Main.pref.put("cadastrewms.cacheSize", String.valueOf(CacheControl.cacheSize));
|
---|
276 | } catch (NumberFormatException e) { // ignore the last input
|
---|
277 | }
|
---|
278 | Main.pref.put("cadastrewms.autoFirstLayer", autoFirstLayer.isSelected());
|
---|
279 | CacheControl.cacheEnabled = enableCache.isSelected();
|
---|
280 | CadastrePlugin.refreshConfiguration();
|
---|
281 | CadastrePlugin.refreshMenu();
|
---|
282 |
|
---|
283 | return false;
|
---|
284 | }
|
---|
285 |
|
---|
286 | private int getNumber(String pref_parameter, int def_value) {
|
---|
287 | try {
|
---|
288 | return Integer.parseInt(Main.pref.get(pref_parameter, String.valueOf(def_value)));
|
---|
289 | } catch (NumberFormatException e) {
|
---|
290 | return def_value;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | }
|
---|