Changeset 32637 in osm for applications/editors/josm/plugins/indoorhelper/src/controller
- Timestamp:
- 2016-07-11T22:48:15+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/controller/IndoorHelperController.java
r32468 r32637 49 49 50 50 /** 51 * 51 * 52 52 * Class for the Controller which provides the communication between 53 53 * the IndoorHelperModel and the different views. 54 * 54 * 55 55 * @author egru 56 56 * … … 58 58 public class IndoorHelperController { 59 59 60 private IndoorHelperModel model; 61 private ToolBoxView toolboxView; 62 private FittingView fittingView; 63 private LevelSelectorView selectorView; 64 private String sep = System.getProperty("file.separator"); 65 66 67 private int lastLevelIndex; 68 69 /** 70 * Constructor for the {@link IndoorHelperController} which initiates model and views. 71 * 72 */ 73 public IndoorHelperController(){ 74 this.model = new IndoorHelperModel(); 75 this.toolboxView = new ToolBoxView(); 76 77 this.lastLevelIndex = 0; 78 79 addToolboxListeners(); 80 Main.map.addToggleDialog(toolboxView); 81 } 82 83 /** 84 * Adds the button- and box-listeners to the {@link ToolBoxView}. 85 */ 86 private void addToolboxListeners(){ 87 88 if(this.toolboxView!=null){ 89 this.toolboxView.setPowerButtonListener(new ToolPowerButtonListener()); 90 this.toolboxView.setApplyButtonListener(new ToolApplyButtonListener()); 91 this.toolboxView.setLevelItemListener(new ToolLevelItemListener()); 92 this.toolboxView.setObjectItemListener(new ToolObjectItemListener()); 93 this.toolboxView.setPreset1Listener(new Preset1Listener()); 94 this.toolboxView.setPreset2Listener(new Preset2Listener()); 95 this.toolboxView.setPreset3Listener(new Preset3Listener()); 96 this.toolboxView.setPreset4Listener(new Preset4Listener()); 97 } 98 } 99 100 /** 101 * Adds the button-listeners to the {@link LevelSelectorView}. 102 */ 103 private void addLevelSelectorListeners(){ 104 if(this.selectorView!=null){ 105 this.selectorView.setOkButtonListener(new LevelOkButtonListener()); 106 this.selectorView.setCancelButtonListener(new LevelCancelButtonListener()); 107 } 108 } 109 110 /** 111 * Adds the button-listeners to the {@link FittingView}. 112 */ 113 private void addFittingListeners(){ 114 if(this.fittingView!=null){ 115 this.fittingView.setOkButtonListener(new FittingOkButtonListener()); 116 } 117 } 118 119 //******************************************************************** 120 //********************* TOOLBOX LISTENERS ************************ 121 //******************************************************************** 122 123 /** 124 * The listener which handles the power button. 125 * 126 * @author egru 127 * 128 */ 129 class ToolPowerButtonListener implements ActionListener{ 130 131 @Override 132 public void actionPerformed(ActionEvent e) { 133 if(toolboxView.getPowerButtonState()){ 134 selectorView = new LevelSelectorView(); 135 addLevelSelectorListeners(); 136 selectorView.setVisible(true); 137 setPluginPreferences(true); 138 } else if(!toolboxView.getPowerButtonState()){ 139 model = new IndoorHelperModel(); 140 selectorView.dispose(); 141 toolboxView.reset(); 142 setPluginPreferences(false); 143 144 // Delete the indoor filters 145 FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class); 146 147 if(filterDialog!=null){ 148 FilterTableModel filterTableModel = filterDialog.getFilterModel(); 149 150 for(int i=filterTableModel.getRowCount()-1;i>-1;i--){ 151 if(filterTableModel.getFilter(i).text.startsWith("\"indoor:level\"=\"")){ 152 filterTableModel.removeFilter(i); 153 } 154 } 155 156 } 157 } 158 } 159 } 160 161 162 /** 163 * The listener which provides the handling of the apply button. 164 * Gets the texts which were written by the user and writes them to the OSM-data. 165 * After that it checks the tagged data with the built-in validator file. 166 * 167 * @author egru 168 */ 169 class ToolApplyButtonListener implements ActionListener{ 170 171 @Override 172 public void actionPerformed(ActionEvent e) { 173 IndoorObject indoorObject = toolboxView.getSelectedObject(); 174 if(toolboxView.getNameText().isEmpty() && toolboxView.getRefText().isEmpty() && toolboxView.getLevelName().isEmpty()){ 175 model.addTagsToOSM(indoorObject); 176 } else { 177 List<Tag> tags = new ArrayList<>(); 178 if(!toolboxView.getLevelName().isEmpty()){ 179 model.getLevelList().get(toolboxView.getSelectedLevelIndex()).setNameTag(toolboxView.getLevelName()); 180 } 181 if(!toolboxView.getNameText().isEmpty()){ 182 tags.add(new Tag("name", toolboxView.getNameText())); 183 } 184 if(!toolboxView.getRefText().isEmpty()) { 185 tags.add(new Tag("ref", toolboxView.getRefText())); 186 } 187 model.addTagsToOSM(indoorObject, tags); 188 } 189 //Do the validation process 190 ValidateAction validateAction = new ValidateAction(); 191 validateAction.doValidate(true); 192 193 refreshPresets(); 194 } 195 } 196 197 /** 198 * <pre>The listener which is called when a new item in the level list is selected. 199 *It also sets the name-tag for a level, if the user has done an input in the textbox. 200 * </pre> 201 * @author egru 202 * 203 */ 204 class ToolLevelItemListener implements ItemListener{ 205 206 @Override 207 public void itemStateChanged(ItemEvent e) { 208 if(!toolboxView.levelListIsEmpty()){ 209 210 if(!toolboxView.getLevelName().isEmpty()){ 211 model.getLevelList().get(lastLevelIndex).setNameTag(toolboxView.getLevelName()); 212 } 213 214 if(!model.getLevelList().get(toolboxView.getSelectedLevelIndex()).hasEmptyName()){ 215 toolboxView.setLevelName(model.getLevelList().get(toolboxView.getSelectedLevelIndex()).getName()); 216 } else { 217 toolboxView.setLevelName(""); 218 } 219 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); 220 221 lastLevelIndex = toolboxView.getSelectedLevelIndex(); 222 } 223 } 224 } 225 226 227 228 /** 229 * The listener which is called when a new item in the object list is selected. 230 * 231 * @author egru 232 * 233 */ 234 class ToolObjectItemListener implements ItemListener{ 235 236 @Override 237 public void itemStateChanged(ItemEvent e) { 238 if(toolboxView.getSelectedObject().equals(IndoorObject.ROOM)){ 239 toolboxView.setTagUiElementsEnabled(true); 240 } else{ 241 toolboxView.setTagUiElementsEnabled(false); 242 } 243 } 244 245 } 246 247 /** 248 * Listener for preset button 1. 249 * @author egru 250 * 251 */ 252 class Preset1Listener implements ActionListener{ 253 254 @Override 255 public void actionPerformed(ActionEvent e) { 256 model.addTagsToOSM(toolboxView.getPreset1()); 257 258 } 259 260 } 261 262 /** 263 * Listener for preset button 2. 264 * @author egru 265 * 266 */ 267 class Preset2Listener implements ActionListener{ 268 269 @Override 270 public void actionPerformed(ActionEvent e) { 271 model.addTagsToOSM(toolboxView.getPreset2()); 272 273 } 274 275 } 276 277 /** 278 * Listener for preset button 3. 279 * @author egru 280 * 281 */ 282 class Preset3Listener implements ActionListener{ 283 284 @Override 285 public void actionPerformed(ActionEvent e) { 286 model.addTagsToOSM(toolboxView.getPreset3()); 287 288 } 289 290 } 291 292 /** 293 * Listener for preset button 4. 294 * @author egru 295 * 296 */ 297 class Preset4Listener implements ActionListener{ 298 299 @Override 300 public void actionPerformed(ActionEvent e) { 301 model.addTagsToOSM(toolboxView.getPreset4()); 302 303 } 304 305 } 306 307 /** 308 * Updates the preset button from the current ranking. 309 */ 310 private void refreshPresets(){ 311 toolboxView.setPresetButtons(model.getPresetRanking()); 312 } 313 314 315 //******************* 316 // SELECTOR LISTENERS 317 //******************* 318 319 /** 320 * <pre> 321 * The listener which handles the click on the OK-button of the {@link LevelSelectorView}. 322 * It sends the data of the view to the model and displays an error message, 323 * if the level-list couldn't be created. 324 * </pre> 325 * @author egru 326 * 327 */ 328 class LevelOkButtonListener implements ActionListener{ 329 330 @Override 331 public void actionPerformed(ActionEvent e) { 332 boolean levelSuccess = model.setBuildingLevels(selectorView.getMin(), selectorView.getMax()); 333 334 if(levelSuccess){ 335 toolboxView.setLevelList(model.getLevelList()); //set the levels to the ComboBox and 336 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); //sets the working level in the model 337 338 selectorView.dispose(); 339 340 fittingView = new FittingView(); 341 addFittingListeners(); 342 fittingView.setVisible(true); 343 } else{ 344 345 JOptionPane.showMessageDialog(null, "Lowest Level has to be lower than the highest level", 346 "Error", JOptionPane.ERROR_MESSAGE); 347 } 348 } 349 } 350 351 /** 352 * Closes the level selection view if the user hits the cancel button. 353 * 354 * @author egru 355 * 356 */ 357 class LevelCancelButtonListener implements ActionListener{ 358 359 @Override 360 public void actionPerformed(ActionEvent e) { 361 selectorView.dispose(); 362 toolboxView.setPowerButtonDisabled(); 363 setPluginPreferences(false); 364 } 365 366 } 367 368 369 370 //******************* 371 // FITTING LISTENERS 372 //******************* 373 /** 374 * Closes the {@link FittingView} if the OK-Button is clicked. 375 * Enables the UI elements of the toolbox 376 * 377 * @author egru 378 * 379 */ 380 class FittingOkButtonListener implements ActionListener{ 381 382 @Override 383 public void actionPerformed(ActionEvent e) { 384 fittingView.dispose(); 385 toolboxView.setAllUiElementsEnabled(true); 386 toolboxView.setTagUiElementsEnabled(false); 387 } 388 389 } 390 391 /* 392 HELPER METHODS 393 */ 394 395 /** 396 * Enables or disables the preferences for the mapcss-style and the validator. 397 * 398 * @param enabled Activates or disables the settings. 399 */ 400 private void setPluginPreferences(boolean enabled){ 401 Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 402 403 404 MapListSetting validatorMapListSetting = (MapListSetting) settings. 405 get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 406 List<Map<String, String>> validatorMaps = new ArrayList<>(); 407 if(validatorMapListSetting!=null){ 408 validatorMaps = validatorMapListSetting.getValue(); 409 } 410 411 MapListSetting styleMapListSetting = (MapListSetting) settings. 412 get("mappaint.style.entries"); 413 List<Map<String, String>> styleMaps = new ArrayList<>(); 414 if(styleMapListSetting != null){ 415 styleMaps = styleMapListSetting.getValue(); 416 } 417 418 if(enabled){ 419 //set the validator active 420 421 422 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 423 if(!validatorMaps.isEmpty()){ 424 validatorMapsNew.addAll(validatorMaps); 425 } 426 427 428 for(Map<String, String> map : validatorMapsNew){ 429 if(map.containsValue("Indoor")){ 430 validatorMapsNew.remove(map); 431 break; 432 } 433 } 434 435 Map<String, String> indoorValidator = new HashMap<>(); 436 indoorValidator.put("title", "Indoor"); 437 indoorValidator.put("active", "true"); 438 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 439 sep + "indoorhelper.validator.mapcss"); 440 441 validatorMapsNew.add(indoorValidator); 442 Main.pref.putListOfStructs 443 ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 444 validatorMapsNew); 445 446 447 448 449 //set mappaint active 450 451 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 452 if(!styleMaps.isEmpty()){ 453 styleMapsNew.addAll(styleMaps); 454 } 455 456 for(Map<String, String> map : styleMapsNew){ 457 if(map.containsValue("Indoor")){ 458 styleMapsNew.remove(map); 459 break; 460 } 461 } 462 Map<String, String> indoorMapPaint = new HashMap<>(); 463 indoorMapPaint.put("title", "Indoor"); 464 indoorMapPaint.put("active", "true"); 465 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 466 + sep + "indoor.mapcss"); 467 styleMapsNew.add(indoorMapPaint); 468 Main.pref.putListOfStructs 469 ("mappaint.style.entries", styleMapsNew); 470 471 updateSettings(); 472 }else{ 473 //set the validator inactive 474 475 476 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 477 if(!validatorMaps.isEmpty()){ 478 validatorMapsNew.addAll(validatorMaps); 479 } 480 481 for(Map<String, String> map : validatorMapsNew){ 482 if(map.containsValue("Indoor")){ 483 validatorMapsNew.remove(map); 484 break; 485 } 486 } 487 Map<String, String> indoorValidator = new HashMap<>(); 488 indoorValidator.put("title", "Indoor"); 489 indoorValidator.put("active", "false"); 490 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 491 sep + "indoorhelper.validator.mapcss"); 492 493 validatorMapsNew.add(indoorValidator); 494 Main.pref.putListOfStructs 495 ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 496 validatorMapsNew); 497 498 499 //set mappaint inactive 500 501 502 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 503 if(!styleMaps.isEmpty()){ 504 styleMapsNew.addAll(styleMaps); 505 } 506 for(Map<String, String> map : styleMapsNew){ 507 if(map.containsValue("Indoor")){ 508 styleMapsNew.remove(map); 509 break; 510 } 511 } 512 Map<String, String> indoorMapPaint = new HashMap<>(); 513 indoorMapPaint.put("title", "Indoor"); 514 indoorMapPaint.put("active", "false"); 515 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 516 + sep + "indoor.mapcss"); 517 styleMapsNew.add(indoorMapPaint); 518 Main.pref.putListOfStructs 519 ("mappaint.style.entries", styleMapsNew); 520 521 updateSettings(); 522 } 523 } 524 525 /** 526 * Forces JOSM to load the validator and mappaint settings. 527 */ 528 private void updateSettings(){ 529 Main.pref.init(false); 530 MapCSSTagChecker tagChecker = OsmValidator.getTest(MapCSSTagChecker.class); 60 private IndoorHelperModel model; 61 private ToolBoxView toolboxView; 62 private FittingView fittingView; 63 private LevelSelectorView selectorView; 64 private String sep = System.getProperty("file.separator"); 65 66 67 private int lastLevelIndex; 68 69 /** 70 * Constructor for the {@link IndoorHelperController} which initiates model and views. 71 * 72 */ 73 public IndoorHelperController() { 74 this.model = new IndoorHelperModel(); 75 this.toolboxView = new ToolBoxView(); 76 77 this.lastLevelIndex = 0; 78 79 addToolboxListeners(); 80 Main.map.addToggleDialog(toolboxView); 81 } 82 83 /** 84 * Adds the button- and box-listeners to the {@link ToolBoxView}. 85 */ 86 private void addToolboxListeners() { 87 88 if (this.toolboxView != null) { 89 this.toolboxView.setPowerButtonListener(new ToolPowerButtonListener()); 90 this.toolboxView.setApplyButtonListener(new ToolApplyButtonListener()); 91 this.toolboxView.setLevelItemListener(new ToolLevelItemListener()); 92 this.toolboxView.setObjectItemListener(new ToolObjectItemListener()); 93 this.toolboxView.setPreset1Listener(new Preset1Listener()); 94 this.toolboxView.setPreset2Listener(new Preset2Listener()); 95 this.toolboxView.setPreset3Listener(new Preset3Listener()); 96 this.toolboxView.setPreset4Listener(new Preset4Listener()); 97 } 98 } 99 100 /** 101 * Adds the button-listeners to the {@link LevelSelectorView}. 102 */ 103 private void addLevelSelectorListeners() { 104 if (this.selectorView != null) { 105 this.selectorView.setOkButtonListener(new LevelOkButtonListener()); 106 this.selectorView.setCancelButtonListener(new LevelCancelButtonListener()); 107 } 108 } 109 110 /** 111 * Adds the button-listeners to the {@link FittingView}. 112 */ 113 private void addFittingListeners() { 114 if (this.fittingView != null) { 115 this.fittingView.setOkButtonListener(new FittingOkButtonListener()); 116 } 117 } 118 119 //******************************************************************** 120 //********************* TOOLBOX LISTENERS ************************ 121 //******************************************************************** 122 123 /** 124 * The listener which handles the power button. 125 * 126 * @author egru 127 * 128 */ 129 class ToolPowerButtonListener implements ActionListener { 130 131 @Override 132 public void actionPerformed(ActionEvent e) { 133 if (toolboxView.getPowerButtonState()) { 134 selectorView = new LevelSelectorView(); 135 addLevelSelectorListeners(); 136 selectorView.setVisible(true); 137 setPluginPreferences(true); 138 } else if (!toolboxView.getPowerButtonState()) { 139 model = new IndoorHelperModel(); 140 selectorView.dispose(); 141 toolboxView.reset(); 142 setPluginPreferences(false); 143 144 // Delete the indoor filters 145 FilterDialog filterDialog = Main.map.getToggleDialog(FilterDialog.class); 146 147 if (filterDialog != null) { 148 FilterTableModel filterTableModel = filterDialog.getFilterModel(); 149 150 for (int i = filterTableModel.getRowCount()-1; i > -1; i--) { 151 if (filterTableModel.getFilter(i).text.startsWith("\"indoor:level\"=\"")) { 152 filterTableModel.removeFilter(i); 153 } 154 } 155 } 156 } 157 } 158 } 159 160 /** 161 * The listener which provides the handling of the apply button. 162 * Gets the texts which were written by the user and writes them to the OSM-data. 163 * After that it checks the tagged data with the built-in validator file. 164 * 165 * @author egru 166 */ 167 class ToolApplyButtonListener implements ActionListener { 168 169 @Override 170 public void actionPerformed(ActionEvent e) { 171 IndoorObject indoorObject = toolboxView.getSelectedObject(); 172 if (toolboxView.getNameText().isEmpty() && toolboxView.getRefText().isEmpty() && toolboxView.getLevelName().isEmpty()) { 173 model.addTagsToOSM(indoorObject); 174 } else { 175 List<Tag> tags = new ArrayList<>(); 176 if (!toolboxView.getLevelName().isEmpty()) { 177 model.getLevelList().get(toolboxView.getSelectedLevelIndex()).setNameTag(toolboxView.getLevelName()); 178 } 179 if (!toolboxView.getNameText().isEmpty()) { 180 tags.add(new Tag("name", toolboxView.getNameText())); 181 } 182 if (!toolboxView.getRefText().isEmpty()) { 183 tags.add(new Tag("ref", toolboxView.getRefText())); 184 } 185 model.addTagsToOSM(indoorObject, tags); 186 } 187 //Do the validation process 188 ValidateAction validateAction = new ValidateAction(); 189 validateAction.doValidate(true); 190 191 refreshPresets(); 192 } 193 } 194 195 /** 196 * <pre>The listener which is called when a new item in the level list is selected. 197 *It also sets the name-tag for a level, if the user has done an input in the textbox. 198 * </pre> 199 * @author egru 200 * 201 */ 202 class ToolLevelItemListener implements ItemListener { 203 204 @Override 205 public void itemStateChanged(ItemEvent e) { 206 if (!toolboxView.levelListIsEmpty()) { 207 208 if (!toolboxView.getLevelName().isEmpty()) { 209 model.getLevelList().get(lastLevelIndex).setNameTag(toolboxView.getLevelName()); 210 } 211 212 if (!model.getLevelList().get(toolboxView.getSelectedLevelIndex()).hasEmptyName()) { 213 toolboxView.setLevelName(model.getLevelList().get(toolboxView.getSelectedLevelIndex()).getName()); 214 } else { 215 toolboxView.setLevelName(""); 216 } 217 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); 218 219 lastLevelIndex = toolboxView.getSelectedLevelIndex(); 220 } 221 } 222 } 223 224 225 226 /** 227 * The listener which is called when a new item in the object list is selected. 228 * 229 * @author egru 230 * 231 */ 232 class ToolObjectItemListener implements ItemListener { 233 234 @Override 235 public void itemStateChanged(ItemEvent e) { 236 if (toolboxView.getSelectedObject().equals(IndoorObject.ROOM)) { 237 toolboxView.setTagUiElementsEnabled(true); 238 } else { 239 toolboxView.setTagUiElementsEnabled(false); 240 } 241 } 242 } 243 244 /** 245 * Listener for preset button 1. 246 * @author egru 247 * 248 */ 249 class Preset1Listener implements ActionListener { 250 251 @Override 252 public void actionPerformed(ActionEvent e) { 253 model.addTagsToOSM(toolboxView.getPreset1()); 254 255 } 256 } 257 258 /** 259 * Listener for preset button 2. 260 * @author egru 261 * 262 */ 263 class Preset2Listener implements ActionListener { 264 265 @Override 266 public void actionPerformed(ActionEvent e) { 267 model.addTagsToOSM(toolboxView.getPreset2()); 268 269 } 270 271 } 272 273 /** 274 * Listener for preset button 3. 275 * @author egru 276 * 277 */ 278 class Preset3Listener implements ActionListener { 279 280 @Override 281 public void actionPerformed(ActionEvent e) { 282 model.addTagsToOSM(toolboxView.getPreset3()); 283 284 } 285 286 } 287 288 /** 289 * Listener for preset button 4. 290 * @author egru 291 * 292 */ 293 class Preset4Listener implements ActionListener { 294 295 @Override 296 public void actionPerformed(ActionEvent e) { 297 model.addTagsToOSM(toolboxView.getPreset4()); 298 299 } 300 301 } 302 303 /** 304 * Updates the preset button from the current ranking. 305 */ 306 private void refreshPresets() { 307 toolboxView.setPresetButtons(model.getPresetRanking()); 308 } 309 310 311 //******************* 312 // SELECTOR LISTENERS 313 //******************* 314 315 /** 316 * <pre> 317 * The listener which handles the click on the OK-button of the {@link LevelSelectorView}. 318 * It sends the data of the view to the model and displays an error message, 319 * if the level-list couldn't be created. 320 * </pre> 321 * @author egru 322 * 323 */ 324 class LevelOkButtonListener implements ActionListener { 325 326 @Override 327 public void actionPerformed(ActionEvent e) { 328 boolean levelSuccess = model.setBuildingLevels(selectorView.getMin(), selectorView.getMax()); 329 330 if (levelSuccess) { 331 toolboxView.setLevelList(model.getLevelList()); //set the levels to the ComboBox and 332 model.setWorkingLevel(toolboxView.getSelectedLevelIndex()); //sets the working level in the model 333 334 selectorView.dispose(); 335 336 fittingView = new FittingView(); 337 addFittingListeners(); 338 fittingView.setVisible(true); 339 } else { 340 341 JOptionPane.showMessageDialog(null, "Lowest Level has to be lower than the highest level", 342 "Error", JOptionPane.ERROR_MESSAGE); 343 } 344 } 345 } 346 347 /** 348 * Closes the level selection view if the user hits the cancel button. 349 * 350 * @author egru 351 * 352 */ 353 class LevelCancelButtonListener implements ActionListener { 354 355 @Override 356 public void actionPerformed(ActionEvent e) { 357 selectorView.dispose(); 358 toolboxView.setPowerButtonDisabled(); 359 setPluginPreferences(false); 360 } 361 362 } 363 364 365 366 //******************* 367 // FITTING LISTENERS 368 //******************* 369 /** 370 * Closes the {@link FittingView} if the OK-Button is clicked. 371 * Enables the UI elements of the toolbox 372 * 373 * @author egru 374 * 375 */ 376 class FittingOkButtonListener implements ActionListener { 377 378 @Override 379 public void actionPerformed(ActionEvent e) { 380 fittingView.dispose(); 381 toolboxView.setAllUiElementsEnabled(true); 382 toolboxView.setTagUiElementsEnabled(false); 383 } 384 385 } 386 387 /* 388 HELPER METHODS 389 */ 390 391 /** 392 * Enables or disables the preferences for the mapcss-style and the validator. 393 * 394 * @param enabled Activates or disables the settings. 395 */ 396 private void setPluginPreferences(boolean enabled) { 397 Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 398 399 MapListSetting validatorMapListSetting = (MapListSetting) settings. 400 get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 401 List<Map<String, String>> validatorMaps = new ArrayList<>(); 402 if (validatorMapListSetting != null) { 403 validatorMaps = validatorMapListSetting.getValue(); 404 } 405 406 MapListSetting styleMapListSetting = (MapListSetting) settings. 407 get("mappaint.style.entries"); 408 List<Map<String, String>> styleMaps = new ArrayList<>(); 409 if (styleMapListSetting != null) { 410 styleMaps = styleMapListSetting.getValue(); 411 } 412 413 if (enabled) { 414 //set the validator active 415 416 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 417 if (!validatorMaps.isEmpty()) { 418 validatorMapsNew.addAll(validatorMaps); 419 } 420 421 for (Map<String, String> map : validatorMapsNew) { 422 if (map.containsValue("Indoor")) { 423 validatorMapsNew.remove(map); 424 break; 425 } 426 } 427 428 Map<String, String> indoorValidator = new HashMap<>(); 429 indoorValidator.put("title", "Indoor"); 430 indoorValidator.put("active", "true"); 431 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 432 sep + "indoorhelper.validator.mapcss"); 433 434 validatorMapsNew.add(indoorValidator); 435 Main.pref.putListOfStructs("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 436 validatorMapsNew); 437 438 //set mappaint active 439 440 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 441 if (!styleMaps.isEmpty()) { 442 styleMapsNew.addAll(styleMaps); 443 } 444 445 for (Map<String, String> map : styleMapsNew) { 446 if (map.containsValue("Indoor")) { 447 styleMapsNew.remove(map); 448 break; 449 } 450 } 451 Map<String, String> indoorMapPaint = new HashMap<>(); 452 indoorMapPaint.put("title", "Indoor"); 453 indoorMapPaint.put("active", "true"); 454 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 455 + sep + "indoor.mapcss"); 456 styleMapsNew.add(indoorMapPaint); 457 Main.pref.putListOfStructs("mappaint.style.entries", styleMapsNew); 458 459 updateSettings(); 460 } else { 461 //set the validator inactive 462 463 464 List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 465 if (!validatorMaps.isEmpty()) { 466 validatorMapsNew.addAll(validatorMaps); 467 } 468 469 for (Map<String, String> map : validatorMapsNew) { 470 if (map.containsValue("Indoor")) { 471 validatorMapsNew.remove(map); 472 break; 473 } 474 } 475 Map<String, String> indoorValidator = new HashMap<>(); 476 indoorValidator.put("title", "Indoor"); 477 indoorValidator.put("active", "false"); 478 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 479 sep + "indoorhelper.validator.mapcss"); 480 481 validatorMapsNew.add(indoorValidator); 482 Main.pref.putListOfStructs("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 483 validatorMapsNew); 484 485 486 //set mappaint inactive 487 488 489 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 490 if (!styleMaps.isEmpty()) { 491 styleMapsNew.addAll(styleMaps); 492 } 493 for (Map<String, String> map : styleMapsNew) { 494 if (map.containsValue("Indoor")) { 495 styleMapsNew.remove(map); 496 break; 497 } 498 } 499 Map<String, String> indoorMapPaint = new HashMap<>(); 500 indoorMapPaint.put("title", "Indoor"); 501 indoorMapPaint.put("active", "false"); 502 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 503 + sep + "indoor.mapcss"); 504 styleMapsNew.add(indoorMapPaint); 505 Main.pref.putListOfStructs("mappaint.style.entries", styleMapsNew); 506 507 updateSettings(); 508 } 509 } 510 511 /** 512 * Forces JOSM to load the validator and mappaint settings. 513 */ 514 private void updateSettings() { 515 Main.pref.init(false); 516 MapCSSTagChecker tagChecker = OsmValidator.getTest(MapCSSTagChecker.class); 531 517 if (tagChecker != null) { 532 518 OsmValidator.initializeTests(Collections.singleton(tagChecker)); 533 519 } 534 520 535 521 MapPaintStyles.readFromPreferences(); 536 522 } 537 523 } 538 524
Note:
See TracChangeset
for help on using the changeset viewer.