Changeset 35312 in osm for applications/editors/josm/plugins/indoorhelper
- Timestamp:
- 2020-01-28T22:27:30+01:00 (5 years ago)
- Location:
- applications/editors/josm/plugins/indoorhelper/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/controller/IndoorHelperController.java
r35200 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package controller; 21 3 … … 27 9 import java.awt.event.ItemListener; 28 10 import java.awt.event.KeyEvent; 11 import java.awt.event.WindowAdapter; 29 12 import java.awt.event.WindowEvent; 30 import java.awt.event.WindowListener;31 13 import java.util.ArrayList; 32 14 import java.util.Collection; … … 34 16 import java.util.List; 35 17 import java.util.Map; 36 import java.util.Optional;37 18 38 19 import javax.swing.AbstractAction; … … 40 21 41 22 import org.openstreetmap.josm.actions.ValidateAction; 42 import org.openstreetmap.josm.actions.mapmode.DrawAction;43 import org.openstreetmap.josm.actions.mapmode.SelectAction;44 23 import org.openstreetmap.josm.data.Preferences; 45 24 import org.openstreetmap.josm.data.osm.DataSet; … … 48 27 import org.openstreetmap.josm.data.osm.Tag; 49 28 import org.openstreetmap.josm.gui.MainApplication; 50 import org.openstreetmap.josm.gui.MapFrame;51 29 import org.openstreetmap.josm.gui.help.HelpBrowser; 52 30 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 63 41 64 42 /** 65 * 66 * Class for the Controller which provides the communication between 67 * the IndoorHelperModel and the different views. 68 * 69 * @author egru 70 * @author rebsc 71 * 72 */ 43 * 44 * Class for the Controller which provides the communication between the 45 * IndoorHelperModel and the different views. 46 * 47 * @author egru 48 * @author rebsc 49 */ 73 50 public class IndoorHelperController { 74 51 75 private IndoorHelperModel model; 76 private ToolBoxView toolboxView; 77 private String sep; 78 private String levelValue, levelNum; 79 private MapFrame map; 80 private DrawAction drawAction; 81 private SelectAction selectAction; 82 private SpaceAction spaceAction; 83 private transient Shortcut spaceShortcut; 84 private EnterAction enterAction; 85 private transient Shortcut enterShortcut; 86 private boolean outerHelp, innerHelp, levelHelp; 87 private Collection<OsmPrimitive> innerRelation; 88 private LevelSelectorView selectorView; 89 90 /** 91 * Constructor for the {@link IndoorHelperController} which initiates model and views. 92 * 93 */ 94 public IndoorHelperController() { 95 96 this.model = new IndoorHelperModel(); 97 this.toolboxView = new ToolBoxView(); 98 99 this.sep = System.getProperty("file.separator"); 100 setPluginPreferences(true); 101 102 // Multipolygon actions 103 this.drawAction = new DrawAction(); 104 this.map = MainApplication.getMap(); 105 this.selectAction = new SelectAction(map); 106 107 // Ui elements 108 toolboxView.setAllUiElementsEnabled(true); 109 toolboxView.setROUiElementsEnabled(false); 110 111 addToolboxListeners(); 112 MainApplication.getMap().addToggleDialog(toolboxView); 113 114 // Shortcuts 115 spaceShortcut = Shortcut.registerShortcut("mapmode:space", 116 "ConfirmObjectDrawing", KeyEvent.VK_SPACE, Shortcut.DIRECT); 117 this.spaceAction = new SpaceAction(); 118 MainApplication.registerActionShortcut(spaceAction, spaceShortcut); 119 120 enterShortcut = Shortcut.registerShortcut("mapmode:enter", 121 "ConfirmMultipolygonSelection", KeyEvent.VK_ENTER, Shortcut.DIRECT); 122 this.enterAction = new EnterAction(); 123 MainApplication.registerActionShortcut(enterAction, enterShortcut); 124 125 // Helper 126 outerHelp = false; 127 innerHelp = false; 128 levelHelp = false; 129 innerRelation = null; 130 levelValue = new String(); 131 levelNum = new String(); 132 133 } 134 52 private final IndoorHelperModel model = new IndoorHelperModel(); 53 private ToolBoxView toolboxView; 54 private String levelValue, levelNum; 55 private final SpaceAction spaceAction = new SpaceAction(); 56 private Shortcut spaceShortcut; 57 private final EnterAction enterAction = new EnterAction(); 58 private Shortcut enterShortcut; 59 private boolean outerHelp, innerHelp, levelHelp; 60 private Collection<OsmPrimitive> innerRelation; 61 private LevelSelectorView selectorView; 62 63 /** 64 * The listener which provides the handling of the applyButton. 65 * Gets the texts which were written by the user and writes them to the OSM-data. 66 * After that it checks the tagged data. 67 * 68 * @author egru 69 * @author rebsc 70 */ 71 private final ActionListener toolApplyButtonListener = e -> { 72 73 IndoorObject indoorObject = toolboxView.getSelectedObject(); 74 75 // collecting all tags 76 List<Tag> tags = new ArrayList<>(); 77 if (!toolboxView.getLevelCheckBoxStatus() && !levelValue.equals("")) { 78 tags.add(new Tag("level", levelValue)); 79 } 80 if (!toolboxView.getLevelNameText().isEmpty() && !toolboxView.getLevelCheckBoxStatus()) { 81 tags.add(new Tag("level_name", toolboxView.getLevelNameText())); 82 } 83 if (!toolboxView.getNameText().isEmpty()) { 84 tags.add(new Tag("name", toolboxView.getNameText())); 85 } 86 if (!toolboxView.getRefText().isEmpty()) { 87 tags.add(new Tag("ref", toolboxView.getRefText())); 88 } 89 if (!toolboxView.getRepeatOnText().isEmpty()) { 90 tags.add(new Tag("repeat_on", toolboxView.getRepeatOnText())); 91 } 92 if (!toolboxView.getLevelNameText().isEmpty() && !toolboxView.getLevelCheckBoxStatus()) { 93 tags.add(new Tag("level_name", toolboxView.getLevelNameText())); 94 } 95 96 // Tagging to OSM Data 97 model.addTagsToOSM(indoorObject, tags); 98 99 // Reset UI elements 100 toolboxView.resetUiElements(); 101 102 // Do the validation process 103 new ValidateAction().doValidate(true); 104 105 refreshPresets(); 106 }; 107 108 /** 109 * The listener which is called when a new item in the object list is selected. 110 * 111 * @author egru 112 * @author rebsc 113 */ 114 private final ItemListener toolObjectItemListener = e -> { 115 if (toolboxView.getSelectedObject().equals(IndoorObject.ROOM)) { 116 toolboxView.setNRUiElementsEnabled(true); 117 toolboxView.setROUiElementsEnabled(false); 118 } else if (toolboxView.getSelectedObject().equals(IndoorObject.STEPS) 119 || toolboxView.getSelectedObject().equals(IndoorObject.ELEVATOR)) { 120 toolboxView.setROUiElementsEnabled(true); 121 toolboxView.setNRUiElementsEnabled(true); 122 } else { 123 toolboxView.setROUiElementsEnabled(false); 124 } 125 }; 126 127 /** 128 * The listener which is called when the LevelCheckBox is selected. 129 * 130 * @author rebsc 131 */ 132 private final ItemListener toolLevelCheckBoxListener = e -> toolboxView 133 .setLVLUiElementsEnabled(e.getStateChange() != ItemEvent.SELECTED); 134 135 /** 136 * The listener which is called when the helpButton got pushed. 137 * 138 * @author rebsc 139 */ 140 private final ActionListener toolHelpButtonListener = e -> HelpBrowser.setUrlForHelpTopic("Plugin/IndoorHelper"); 141 142 /** 143 * The listener which is called when the addLevelButton got pushed. 144 * 145 * @author rebsc 146 */ 147 private final ActionListener toolAddLevelButtonListener = e -> { 148 if (selectorView == null) { 149 selectorView = new LevelSelectorView(); 150 addLevelSelectorListeners(); 151 152 // Show LevelSelectorView 153 selectorView.setVisible(true); 154 } else { 155 // Put focus back on LevelSelectorView 156 selectorView.toFront(); 157 } 158 }; 159 160 /** 161 * The listener which is called when the MultiCheckBox is selected. 162 * 163 * @author rebsc 164 */ 165 private final ItemListener toolMultiCheckBoxListener = e -> toolboxView 166 .setMultiUiElementsEnabled(e.getStateChange() != ItemEvent.SELECTED); 167 168 /** 169 * The listener which is called when the OUTER Button got pushed. 170 * 171 * @author rebsc 172 */ 173 private final ActionListener toolOuterButtonListener = e -> { 174 // Select drawing action 175 MainApplication.getMap().selectDrawTool(false); 176 177 // For space shortcut to add the relation after spacebar got pushed {@link SpaceAction} 178 outerHelp = true; 179 innerHelp = false; 180 }; 181 182 /** 183 * The listener which is called when the INNER Button got pushed. 184 * 185 * @author rebsc 186 */ 187 private final ActionListener toolInnerButtonListener = e -> { 188 // Select drawing action 189 MainApplication.getMap().selectDrawTool(false); 190 191 // For space shortcut to edit the relation after enter got pushed {@link SpaceAction}{@link EnterAction} 192 innerHelp = true; 193 outerHelp = false; 194 }; 195 196 /** 197 * Listener for preset button 1. 198 * 199 * @author egru 200 */ 201 private final ActionListener preset1Listener = e -> model.addTagsToOSM(toolboxView.getPreset1()); 202 203 /** 204 * Listener for preset button 2. 205 * 206 * @author egru 207 */ 208 private final ActionListener preset2Listener = e -> model.addTagsToOSM(toolboxView.getPreset2()); 209 210 /** 211 * Listener for preset button 3. 212 * 213 * @author egru 214 */ 215 private final ActionListener preset3Listener = e -> model.addTagsToOSM(toolboxView.getPreset3()); 216 217 /** 218 * Listener for preset button 4. 219 * 220 * @author egru 221 */ 222 private final ActionListener preset4Listener = e -> model.addTagsToOSM(toolboxView.getPreset4()); 223 224 /** 225 * Updates the preset button from the current ranking. 226 */ 227 private void refreshPresets() { 228 toolboxView.setPresetButtons(model.getPresetRanking()); 229 } 230 231 /** 232 * Specific listener for the applyButton 233 * 234 * @author rebsc 235 */ 236 private final ActionListener toolLevelOkButtonListener = e -> { 237 levelHelp = true; 238 239 // Get insert level number out of SelectorView 240 if (!selectorView.getLevelNumber().equals("")) { 241 levelNum = selectorView.getLevelNumber(); 242 243 // Unset visibility 244 selectorView.dispose(); 245 // Select draw-action 246 MainApplication.getMap().selectDrawTool(false); 247 248 } else { 249 JOptionPane.showMessageDialog(null, tr("Please insert a value."), tr("Error"), JOptionPane.ERROR_MESSAGE); 250 } 251 252 selectorView = null; 253 }; 254 255 /** 256 * Specific listener for the cancelButton 257 * 258 * @author rebsc 259 */ 260 private final ActionListener toolLevelCancelButtonListener = e -> { 261 selectorView.dispose(); 262 selectorView = null; 263 }; 264 265 /** 266 * General listener for LevelSelectorView window 267 * 268 * @author rebsc 269 */ 270 class ToolSelectorWindowSListener extends WindowAdapter { 271 272 @Override 273 public void windowClosed(WindowEvent e) { 274 selectorView = null; 275 } 276 277 @Override 278 public void windowClosing(WindowEvent e) { 279 selectorView = null; 280 } 281 } 282 283 /** 284 * Constructor for the {@link IndoorHelperController} which initiates model and views. 285 */ 286 public IndoorHelperController() { 287 288 toolboxView = new ToolBoxView(); 289 290 setPluginPreferences(true); 291 292 // Ui elements 293 toolboxView.setAllUiElementsEnabled(true); 294 toolboxView.setROUiElementsEnabled(false); 295 296 addToolboxListeners(); 297 MainApplication.getMap().addToggleDialog(toolboxView); 298 299 // Shortcuts 300 spaceShortcut = Shortcut.registerShortcut("mapmode:space", "ConfirmObjectDrawing", KeyEvent.VK_SPACE, Shortcut.DIRECT); 301 MainApplication.registerActionShortcut(spaceAction, spaceShortcut); 302 303 enterShortcut = Shortcut.registerShortcut("mapmode:enter", "ConfirmMultipolygonSelection", KeyEvent.VK_ENTER, Shortcut.DIRECT); 304 MainApplication.registerActionShortcut(enterAction, enterShortcut); 305 306 // Helper 307 outerHelp = false; 308 innerHelp = false; 309 levelHelp = false; 310 innerRelation = null; 311 levelValue = ""; 312 levelNum = ""; 313 } 135 314 136 315 /** … … 138 317 */ 139 318 private void addToolboxListeners() { 140 141 if (this.toolboxView != null) { 142 this.toolboxView.setApplyButtonListener(new ToolApplyButtonListener()); 143 this.toolboxView.setLevelCheckBoxListener(new ToolLevelCheckBoxListener()); 144 this.toolboxView.setHelpButtonListener(new ToolHelpButtonListener()); 145 this.toolboxView.setAddLevelButtonListener(new ToolAddLevelButtonListener()); 146 this.toolboxView.setObjectItemListener(new ToolObjectItemListener()); 147 this.toolboxView.setOuterButtonListener(new ToolOuterButtonListener()); 148 this.toolboxView.setInnerButtonListener(new ToolInnerButtonListener()); 149 this.toolboxView.setMultiCheckBoxListener(new ToolMultiCheckBoxListener()); 150 this.toolboxView.setPreset1Listener(new Preset1Listener()); 151 this.toolboxView.setPreset2Listener(new Preset2Listener()); 152 this.toolboxView.setPreset3Listener(new Preset3Listener()); 153 this.toolboxView.setPreset4Listener(new Preset4Listener()); 319 if (toolboxView != null) { 320 toolboxView.setApplyButtonListener(toolApplyButtonListener); 321 toolboxView.setLevelCheckBoxListener(toolLevelCheckBoxListener); 322 toolboxView.setHelpButtonListener(toolHelpButtonListener); 323 toolboxView.setAddLevelButtonListener(toolAddLevelButtonListener); 324 toolboxView.setObjectItemListener(toolObjectItemListener); 325 toolboxView.setOuterButtonListener(toolOuterButtonListener); 326 toolboxView.setInnerButtonListener(toolInnerButtonListener); 327 toolboxView.setMultiCheckBoxListener(toolMultiCheckBoxListener); 328 toolboxView.setPreset1Listener(preset1Listener); 329 toolboxView.setPreset2Listener(preset2Listener); 330 toolboxView.setPreset3Listener(preset3Listener); 331 toolboxView.setPreset4Listener(preset4Listener); 154 332 } 155 333 } … … 159 337 */ 160 338 private void addLevelSelectorListeners() { 161 if (this.selectorView != null) { 162 this.selectorView.setOkButtonListener(new ToolLevelOkButtonListener()); 163 this.selectorView.setCancelButtonListener(new ToolLevelCancelButtonListener()); 164 this.selectorView.setSelectorWindowListener(new ToolSelectorWindowSListener()); 165 } 166 167 } 168 169 /** 170 * The listener which provides the handling of the applyButton. 171 * Gets the texts which were written by the user and writes them to the OSM-data. 172 * After that it checks the tagged data. 173 * 174 * @author egru 175 * @author rebsc 176 */ 177 class ToolApplyButtonListener implements ActionListener { 178 179 @Override 180 public void actionPerformed(ActionEvent e) { 181 182 IndoorObject indoorObject = toolboxView.getSelectedObject(); 183 184 // collecting all tags 185 List<Tag> tags = new ArrayList<>(); 186 if (!toolboxView.getLevelCheckBoxStatus() && !levelValue.equals("")) { 187 tags.add(new Tag("level", levelValue)); 188 } 189 if (!toolboxView.getLevelNameText().isEmpty() && !toolboxView.getLevelCheckBoxStatus()) { 190 tags.add(new Tag("level_name", toolboxView.getLevelNameText())); 191 } 192 if (!toolboxView.getNameText().isEmpty()) { 193 tags.add(new Tag("name", toolboxView.getNameText())); 194 } 195 if (!toolboxView.getRefText().isEmpty()) { 196 tags.add(new Tag("ref", toolboxView.getRefText())); 197 } 198 if (!toolboxView.getRepeatOnText().isEmpty()) { 199 tags.add(new Tag("repeat_on", toolboxView.getRepeatOnText())); 200 } 201 if (!toolboxView.getLevelNameText().isEmpty() && !toolboxView.getLevelCheckBoxStatus()) { 202 tags.add(new Tag("level_name", toolboxView.getLevelNameText())); 203 } 204 205 // Tagging to OSM Data 206 model.addTagsToOSM(indoorObject, tags); 207 208 // Reset UI elements 209 toolboxView.resetUiElements(); 210 211 //Do the validation process 212 ValidateAction validateAction = new ValidateAction(); 213 validateAction.doValidate(true); 214 215 refreshPresets(); 216 217 } 218 } 219 220 /** 221 * The listener which is called when a new item in the object list is selected. 222 * 223 * @author egru 224 * @author rebsc 225 * 226 */ 227 class ToolObjectItemListener implements ItemListener { 228 229 @Override 230 public void itemStateChanged(ItemEvent e) { 231 if (toolboxView.getSelectedObject().equals(IndoorObject.ROOM)) { 232 toolboxView.setNRUiElementsEnabled(true); 233 toolboxView.setROUiElementsEnabled(false); 234 } else if (toolboxView.getSelectedObject().equals(IndoorObject.STEPS) || 235 toolboxView.getSelectedObject().equals(IndoorObject.ELEVATOR)) { 236 toolboxView.setROUiElementsEnabled(true); 237 toolboxView.setNRUiElementsEnabled(true); 238 } else { 239 toolboxView.setROUiElementsEnabled(false); 240 } 241 } 242 } 243 244 /** 245 * The listener which is called when the LevelCheckBox is selected. 246 * 247 * @author rebsc 248 */ 249 class ToolLevelCheckBoxListener implements ItemListener { 250 @Override 251 public void itemStateChanged(ItemEvent e) { 252 if (e.getStateChange() == ItemEvent.SELECTED) { 253 toolboxView.setLVLUiElementsEnabled(false); 254 } else { 255 toolboxView.setLVLUiElementsEnabled(true); 256 } 257 } 258 } 259 260 /** 261 * The listener which is called when the helpButton got pushed. 262 * 263 * @author rebsc 264 */ 265 static class ToolHelpButtonListener implements ActionListener { 266 267 @Override 268 public void actionPerformed(ActionEvent e) { 269 String topic = "Plugin/IndoorHelper"; 270 //Open HelpBrowser for short description about the plugin 271 HelpBrowser.setUrlForHelpTopic(Optional.ofNullable(topic).orElse("/")); 272 } 273 } 274 275 /** 276 * The listener which is called when the addLevelButton got pushed. 277 * 278 * @author rebsc 279 */ 280 class ToolAddLevelButtonListener implements ActionListener { 281 282 @Override 283 public void actionPerformed(ActionEvent e) { 284 285 if (selectorView == null) { 286 selectorView = new LevelSelectorView(); 287 addLevelSelectorListeners(); 288 289 //Show LevelSelectorView 290 selectorView.setVisible(true); 291 } else { 292 //Put focus back on LevelSelectorView 293 selectorView.toFront(); 294 } 295 296 } 297 } 298 299 /** 300 * The listener which is called when the MultiCheckBox is selected. 301 * 302 * @author rebsc 303 */ 304 class ToolMultiCheckBoxListener implements ItemListener { 305 @Override 306 public void itemStateChanged(ItemEvent e) { 307 if (e.getStateChange() == ItemEvent.SELECTED) { 308 toolboxView.setMultiUiElementsEnabled(false); 309 } else { 310 toolboxView.setMultiUiElementsEnabled(true); 311 } 312 } 313 } 314 315 /** 316 * The listener which is called when the OUTER Button got pushed. 317 * 318 * @author rebsc 319 */ 320 class ToolOuterButtonListener implements ActionListener { 321 322 @Override 323 public void actionPerformed(ActionEvent e) { 324 // Select drawing action 325 map.selectMapMode(drawAction); 326 327 // For space shortcut to add the relation after spacebar got pushed {@link SpaceAction} 328 outerHelp = true; 329 innerHelp = false; 330 } 331 } 332 333 /** 334 * The listener which is called when the INNER Button got pushed. 335 * 336 * @author rebsc 337 */ 338 class ToolInnerButtonListener implements ActionListener { 339 @Override 340 public void actionPerformed(ActionEvent e) { 341 // Select drawing action 342 map.selectMapMode(drawAction); 343 344 // For space shortcut to edit the relation after enter got pushed {@link SpaceAction}{@link EnterAction} 345 innerHelp = true; 346 outerHelp = false; 347 348 } 349 } 350 351 /** 352 * Listener for preset button 1. 353 * @author egru 354 * 355 */ 356 class Preset1Listener implements ActionListener { 357 358 @Override 359 public void actionPerformed(ActionEvent e) { 360 model.addTagsToOSM(toolboxView.getPreset1()); 361 } 362 } 363 364 /** 365 * Listener for preset button 2. 366 * @author egru 367 * 368 */ 369 class Preset2Listener implements ActionListener { 370 371 @Override 372 public void actionPerformed(ActionEvent e) { 373 model.addTagsToOSM(toolboxView.getPreset2()); 374 } 375 } 376 377 /** 378 * Listener for preset button 3. 379 * @author egru 380 * 381 */ 382 class Preset3Listener implements ActionListener { 383 384 @Override 385 public void actionPerformed(ActionEvent e) { 386 model.addTagsToOSM(toolboxView.getPreset3()); 387 } 388 } 389 390 /** 391 * Listener for preset button 4. 392 * @author egru 393 * 394 */ 395 class Preset4Listener implements ActionListener { 396 397 @Override 398 public void actionPerformed(ActionEvent e) { 399 model.addTagsToOSM(toolboxView.getPreset4()); 400 } 401 } 402 403 /** 404 * Updates the preset button from the current ranking. 405 */ 406 private void refreshPresets() { 407 toolboxView.setPresetButtons(model.getPresetRanking()); 408 } 409 410 /** 411 * Specific listener for the applyButton 412 * @author rebsc 413 * 414 */ 415 class ToolLevelOkButtonListener implements ActionListener { 416 417 @Override 418 public void actionPerformed(ActionEvent e) { 419 levelHelp = true; 420 421 // Get insert level number out of SelectorView 422 if (!selectorView.getLevelNumber().equals("")) { 423 levelNum = selectorView.getLevelNumber(); 424 425 //Unset visibility 426 selectorView.dispose(); 427 //Select draw-action 428 map.selectMapMode(drawAction); 429 430 } else { 431 JOptionPane.showMessageDialog(null, tr("Please insert a value."), tr("Error"), JOptionPane.ERROR_MESSAGE); 432 } 433 434 selectorView = null; 435 } 436 } 437 438 /** 439 * Specific listener for the cancelButton 440 * @author rebsc 441 * 442 */ 443 class ToolLevelCancelButtonListener implements ActionListener { 444 445 @Override 446 public void actionPerformed(ActionEvent e) { 447 selectorView.dispose(); 448 selectorView = null; 449 } 450 } 451 452 /** 453 * General listener for LevelSelectorView window 454 * @author rebsc 455 * 456 */ 457 class ToolSelectorWindowSListener implements WindowListener { 458 459 @Override 460 public void windowClosed(WindowEvent e) { 461 selectorView = null; 462 } 463 464 @Override 465 public void windowClosing(WindowEvent e) { 466 selectorView = null; 467 } 468 469 @Override 470 public void windowActivated(WindowEvent arg0) { 471 // TODO Auto-generated method stub 472 473 } 474 475 @Override 476 public void windowDeactivated(WindowEvent arg0) { 477 // TODO Auto-generated method stub 478 479 } 480 481 @Override 482 public void windowDeiconified(WindowEvent arg0) { 483 // TODO Auto-generated method stub 484 485 } 486 487 @Override 488 public void windowIconified(WindowEvent arg0) { 489 // TODO Auto-generated method stub 490 491 } 492 493 @Override 494 public void windowOpened(WindowEvent arg0) { 495 // TODO Auto-generated method stub 496 497 } 498 } 499 500 /** 501 * Shortcut for spacebar 502 * @author rebsc 503 */ 504 private class SpaceAction extends AbstractAction { 505 506 private static final long serialVersionUID = 1L; 507 508 @Override 509 public void actionPerformed(ActionEvent e) { 510 if (outerHelp) { 511 512 //Create new relation and add the currently drawn object to it 513 model.addRelation("outer"); 514 map.selectMapMode(selectAction); 515 outerHelp = false; 516 517 //Clear currently selection 518 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 519 } else if (innerHelp) { 520 521 //Save new drawn relation for adding 522 innerRelation = MainApplication.getLayerManager().getEditDataSet().getAllSelected(); 523 map.selectMapMode(selectAction); 524 525 //Clear currently selection 526 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 527 } else if (levelHelp) { 528 529 List<Tag> tags = new ArrayList<>(); 530 tags.add(new Tag("level", levelNum)); 531 532 //Add level tag 533 model.addTagsToOSM(tags); 534 535 //Change action 536 map.selectMapMode(selectAction); 537 levelHelp = false; 538 } 539 } 540 } 541 542 /** 543 * Shortcut for enter 544 * @author rebsc 545 */ 546 private class EnterAction extends AbstractAction { 547 548 private static final long serialVersionUID = 1L; 549 550 @Override 551 public void actionPerformed(ActionEvent e) { 552 if (innerHelp && !outerHelp) { 553 // Edit the new drawn relation member to selected relation 554 model.editRelation("inner", innerRelation); 555 innerHelp = false; 556 } else if ((innerHelp && outerHelp) || (outerHelp && !innerHelp)) { 557 JOptionPane.showMessageDialog(null, 558 tr("Please press spacebar first to add \"outer\" object to relation."), tr("Relation-Error"), JOptionPane.ERROR_MESSAGE); 559 resetHelper(); 560 } 561 } 562 } 563 564 /** 565 * Function which unsets the disabled state of currently hidden and/or disabled objects which have a 566 * specific tag (key). Just unsets the disabled state if object has a tag-value which is part of the 567 * current working level. 568 * 569 * @author rebsc 570 * @param key sepcific key to unset hidden objects which contains it 571 */ 572 public void unsetSpecificKeyFilter(String key) { 573 574 DataSet editDataSet = OsmDataManager.getInstance().getEditDataSet(); 575 if (editDataSet != null) { 576 Collection<OsmPrimitive> p = editDataSet.allPrimitives(); 577 int level = Integer.parseInt(levelValue); 578 579 //Find all primitives with the specific tag and check if value is part of the current 580 //workinglevel. After that unset the disabled status. 581 for (OsmPrimitive osm: p) { 582 if ((osm.isDisabledAndHidden() || osm.isDisabled()) && osm.hasKey(key)) { 583 for (Map.Entry<String, String> e: osm.getInterestingTags().entrySet()) { 584 if (e.getKey().equals(key)) { 585 //Compare values to current working level 586 if (IndoorLevel.isPartOfWorkingLevel(e.getValue(), level)) { 587 osm.unsetDisabledState(); 588 } else { 589 osm.setDisabledState(true); 339 if (selectorView != null) { 340 selectorView.setOkButtonListener(toolLevelOkButtonListener); 341 selectorView.setCancelButtonListener(toolLevelCancelButtonListener); 342 selectorView.setSelectorWindowListener(new ToolSelectorWindowSListener()); 343 } 344 } 345 346 /** 347 * Shortcut for spacebar 348 * 349 * @author rebsc 350 */ 351 private class SpaceAction extends AbstractAction { 352 353 private static final long serialVersionUID = 1L; 354 355 @Override 356 public void actionPerformed(ActionEvent e) { 357 if (outerHelp) { 358 359 // Create new relation and add the currently drawn object to it 360 model.addRelation("outer"); 361 MainApplication.getMap().selectSelectTool(false); 362 outerHelp = false; 363 364 // Clear currently selection 365 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 366 } else if (innerHelp) { 367 368 // Save new drawn relation for adding 369 innerRelation = MainApplication.getLayerManager().getEditDataSet().getAllSelected(); 370 MainApplication.getMap().selectSelectTool(false); 371 372 // Clear currently selection 373 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 374 } else if (levelHelp) { 375 376 List<Tag> tags = new ArrayList<>(); 377 tags.add(new Tag("level", levelNum)); 378 379 // Add level tag 380 model.addTagsToOSM(tags); 381 382 // Change action 383 MainApplication.getMap().selectSelectTool(false); 384 levelHelp = false; 385 } 386 } 387 } 388 389 /** 390 * Shortcut for enter 391 * 392 * @author rebsc 393 */ 394 private class EnterAction extends AbstractAction { 395 396 private static final long serialVersionUID = 1L; 397 398 @Override 399 public void actionPerformed(ActionEvent e) { 400 if (innerHelp && !outerHelp) { 401 // Edit the new drawn relation member to selected relation 402 model.editRelation("inner", innerRelation); 403 innerHelp = false; 404 } else if ((innerHelp && outerHelp) || (outerHelp && !innerHelp)) { 405 JOptionPane.showMessageDialog(null, 406 tr("Please press spacebar first to add \"outer\" object to relation."), tr("Relation-Error"), 407 JOptionPane.ERROR_MESSAGE); 408 innerHelp = false; 409 outerHelp = false; 410 } 411 } 412 } 413 414 /** 415 * Function which unsets the disabled state of currently hidden and/or disabled objects which have a 416 * specific tag (key). Just unsets the disabled state if object has a tag-value which is part of the 417 * current working level. 418 * 419 * @author rebsc 420 * @param key specific key to unset hidden objects which contains it 421 */ 422 public void unsetSpecificKeyFilter(String key) { 423 424 DataSet editDataSet = OsmDataManager.getInstance().getEditDataSet(); 425 if (editDataSet != null) { 426 Collection<OsmPrimitive> p = editDataSet.allPrimitives(); 427 int level = Integer.parseInt(levelValue); 428 429 // Find all primitives with the specific tag and check if value is part of the current 430 // workinglevel. After that unset the disabled status. 431 for (OsmPrimitive osm : p) { 432 if ((osm.isDisabledAndHidden() || osm.isDisabled()) && osm.hasKey(key)) { 433 for (Map.Entry<String, String> e : osm.getInterestingTags().entrySet()) { 434 if (e.getKey().equals(key)) { 435 // Compare values to current working level 436 if (IndoorLevel.isPartOfWorkingLevel(e.getValue(), level)) { 437 osm.unsetDisabledState(); 438 } else { 439 osm.setDisabledState(true); 440 } 590 441 } 591 442 } 592 } 593 } 594 } 595 } 596 } 443 } 444 } 445 } 446 } 597 447 598 448 /** … … 602 452 */ 603 453 public void setIndoorLevel(String indoorLevel) { 604 this.toolboxView.setLevelLabel(indoorLevel);454 this.toolboxView.setLevelLabel(indoorLevel); 605 455 } 606 456 … … 615 465 616 466 /** 617 * Function which resets the helper for relation adding618 */619 private void resetHelper() {620 innerHelp = false;621 outerHelp = false;622 }623 624 /**625 467 * Forces JOSM to load the mappaint settings. 626 468 */ 627 private void updateSettings() {469 private static void updateSettings() { 628 470 Preferences.main().init(false); 629 471 MapPaintStyles.readFromPreferences(); … … 635 477 * @param enabled Activates or disables the settings. 636 478 */ 637 private void setPluginPreferences(boolean enabled) { 638 Map<String, Setting<?>> settings = Preferences.main().getAllSettings(); 639 640 MapListSetting styleMapListSetting = (MapListSetting) settings. 641 get("mappaint.style.entries"); 642 List<Map<String, String>> styleMaps = new ArrayList<>(); 643 if (styleMapListSetting != null) { 644 styleMaps = styleMapListSetting.getValue(); 645 } 646 647 if (enabled) { 648 //set mappaint active 649 650 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 651 if (!styleMaps.isEmpty()) { 652 styleMapsNew.addAll(styleMaps); 653 } 654 655 for (Map<String, String> map : styleMapsNew) { 656 if (map.containsValue(tr("Indoor"))) { 657 styleMapsNew.remove(map); 658 break; 659 } 660 } 661 Map<String, String> indoorMapPaint = new HashMap<>(); 662 indoorMapPaint.put("title", tr("Indoor")); 663 indoorMapPaint.put("active", "true"); 664 indoorMapPaint.put("url", Config.getDirs().getUserDataDirectory(true) + sep + "styles" 665 + sep + "sit.mapcss"); 666 styleMapsNew.add(indoorMapPaint); 667 Config.getPref().putListOfMaps("mappaint.style.entries", styleMapsNew); 668 669 updateSettings(); 670 } else { 671 //set mappaint inactive 672 673 List<Map<String, String>> styleMapsNew = new ArrayList<>(); 674 if (!styleMaps.isEmpty()) { 675 styleMapsNew.addAll(styleMaps); 676 } 677 for (Map<String, String> map : styleMapsNew) { 678 if (map.containsValue(tr("Indoor"))) { 679 styleMapsNew.remove(map); 680 break; 681 } 682 } 683 Map<String, String> indoorMapPaint = new HashMap<>(); 684 indoorMapPaint.put("title", tr("Indoor")); 685 indoorMapPaint.put("active", "false"); 686 indoorMapPaint.put("url", Config.getDirs().getUserDataDirectory(true) + sep + "styles" 687 + sep + "sit.mapcss"); 688 styleMapsNew.add(indoorMapPaint); 689 Config.getPref().putListOfMaps("mappaint.style.entries", styleMapsNew); 690 691 updateSettings(); 692 } 693 } 479 private static void setPluginPreferences(boolean enabled) { 480 Map<String, Setting<?>> settings = Preferences.main().getAllSettings(); 481 String sep = System.getProperty("file.separator"); 482 483 MapListSetting styleMapListSetting = (MapListSetting) settings.get("mappaint.style.entries"); 484 List<Map<String, String>> styleMaps = new ArrayList<>(); 485 if (styleMapListSetting != null) { 486 styleMaps = styleMapListSetting.getValue(); 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(tr("Indoor"))) { 495 styleMapsNew.remove(map); 496 break; 497 } 498 } 499 Map<String, String> indoorMapPaint = new HashMap<>(); 500 indoorMapPaint.put("title", tr("Indoor")); 501 indoorMapPaint.put("active", Boolean.toString(enabled)); 502 indoorMapPaint.put("url", Config.getDirs().getUserDataDirectory(true) + sep + "styles" + sep + "sit.mapcss"); 503 styleMapsNew.add(indoorMapPaint); 504 Config.getPref().putListOfMaps("mappaint.style.entries", styleMapsNew); 505 updateSettings(); 506 } 694 507 } -
applications/editors/josm/plugins/indoorhelper/src/model/IndoorHelperModel.java
r35228 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package model; 21 3 … … 206 188 newMember = new RelationMember(role == null ? "" : role, osm); 207 189 relation.addMember(newMember); 208 } ;190 } 209 191 210 192 //Check if dataset is not empty or if {@link innerRelation} has no value -
applications/editors/josm/plugins/indoorhelper/src/model/IndoorLevel.java
r35240 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package model; 20 3 -
applications/editors/josm/plugins/indoorhelper/src/model/PresetCounter.java
r34179 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package model; 21 3 … … 36 18 37 19 private List<IndoorObject> rankingList; 38 private List<ObjectCounter> counterList;20 private final List<ObjectCounter> counterList = new ArrayList<>(); 39 21 40 22 /** … … 43 25 44 26 public PresetCounter() { 45 this.init();46 }47 48 private void init() {49 counterList = new ArrayList<>();50 51 27 counterList.add(new ObjectCounter(IndoorObject.CONCRETE_WALL, 0)); 52 28 counterList.add(new ObjectCounter(IndoorObject.DOOR_PRIVATE, 0)); … … 138 114 } 139 115 } 140 141 142 116 } -
applications/editors/josm/plugins/indoorhelper/src/model/TagCatalog.java
r35076 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package model; 21 3 … … 100 82 return tagList; 101 83 } 102 103 84 } 104 85 … … 110 91 */ 111 92 public enum IndoorObject { 112 113 93 CONCRETE_WALL, GLASS_WALL, ROOM, TOILET_MALE, TOILET_FEMALE, ELEVATOR, DOOR_PRIVATE, DOOR_PUBLIC, ENTRANCE, 94 ENTRANCE_EXIT_ONLY, ACCESS_PRIVATE, ACCESS_PUBLIC, STEPS, CORRIDOR, BENCH, AREA, NONE; 114 95 } 115 96 } -
applications/editors/josm/plugins/indoorhelper/src/org/openstreetmap/josm/plugins/indoorhelper/IndoorHelperPlugin.java
r34743 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package org.openstreetmap.josm.plugins.indoorhelper; 21 3 … … 87 69 try (InputStream stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName)) { 88 70 if (stream == null) { 89 System.out.println("MapPaint: stream is null");90 71 throw new IOException("Cannot get resource \"" + resourceName + "\" from Jar file."); 91 72 } … … 133 114 } 134 115 } 135 136 /**137 * Writes the indoor validator file in the user preferences if it isn't there138 * and activates it.139 */140 // private void setIndoorValidator() {141 // //get the current validator settings142 // Map<String, Setting<?>> settings = Config.getPref().getAllSettings();143 // MapListSetting mapListSetting = (MapListSetting) settings.144 // get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries");145 // List<Map<String, String>> validatorMaps;146 // if (mapListSetting != null) {147 // validatorMaps = mapListSetting.getValue();148 // } else {149 // validatorMaps = new ArrayList<>();150 // }151 // boolean validatorExists = false;152 //153 // //check if indoor validator is already set154 // for (Map<String, String> map : validatorMaps) {155 // if (map.containsValue("Indoor")) {156 // validatorExists = true;157 // }158 // }159 //160 // //put it in the settings if not161 // if (!validatorExists) {162 // List<Map<String, String>> validatorMapsNew = new ArrayList<>();163 // if (!validatorMaps.isEmpty()) {164 // validatorMapsNew.addAll(validatorMaps);165 // }166 // Map<String, String> indoorValidator = new HashMap<>();167 // indoorValidator.put("title", "Indoor");168 // indoorValidator.put("active", "true");169 // indoorValidator.put("url", Config.getPref().getUserDataDirectory()+ sep +"validator" +170 // sep + "indoorhelper.validator.mapcss");171 //172 // validatorMapsNew.add(indoorValidator);173 // Config.getPref().putListOfStructs174 // ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries",175 // validatorMapsNew);176 // }177 // }178 116 } -
applications/editors/josm/plugins/indoorhelper/src/views/DialogPanel.java
r34005 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 1 // License: GPL. For details, see LICENSE file. 19 2 package views; 20 3 -
applications/editors/josm/plugins/indoorhelper/src/views/LevelSelectorView.java
r34135 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package views; 20 3 -
applications/editors/josm/plugins/indoorhelper/src/views/PresetButton.java
r34005 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 1 // License: GPL. For details, see LICENSE file. 20 2 package views; 21 3 -
applications/editors/josm/plugins/indoorhelper/src/views/ToolBoxView.java
r34734 r35312 1 /* 2 * Indoorhelper is a JOSM plug-in to support users when creating their own indoor maps. 3 * Copyright (C) 2016 Erik Gruschka 4 * Copyright (C) 2018 Rebecca Schmidt 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 1 // License: GPL. For details, see LICENSE file. 19 2 package views; 20 3
Note:
See TracChangeset
for help on using the changeset viewer.