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