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