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