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