source: osm/applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CadastrePreferenceSetting.java@ 19149

Last change on this file since 19149 was 19149, checked in by pieren, 16 years ago

Add a 25m crosspiece ref and the possibility to change the source in the UploadHook

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