Changeset 34005 in osm for applications/editors/josm/plugins/indoorhelper/src/controller/IndoorHelperController.java
- Timestamp:
- 2018-01-13T18:19:22+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/controller/IndoorHelperController.java
r33997 r34005 83 83 private EnterAction EnterAction; 84 84 private transient Shortcut EnterShortcut; 85 private boolean OuterHelp,InnerHelp,LevelHelp; 85 private boolean OuterHelp, InnerHelp, LevelHelp; 86 86 private Collection<OsmPrimitive> innerRelation; 87 87 private LevelSelectorView selectorView; … … 93 93 public IndoorHelperController() { 94 94 95 95 this.model = new IndoorHelperModel(); 96 96 this.toolboxView = new ToolBoxView(); 97 97 … … 115 115 "", KeyEvent.VK_SPACE, Shortcut.DIRECT); 116 116 this.SpaceAction = new SpaceAction(); 117 MainApplication.registerActionShortcut(SpaceAction,SpaceShortcut); 117 MainApplication.registerActionShortcut(SpaceAction, SpaceShortcut); 118 118 119 119 EnterShortcut = Shortcut.registerShortcut("mapmode:ALT", 120 120 "", KeyEvent.VK_ENTER, Shortcut.DIRECT); 121 121 this.EnterAction = new EnterAction(); 122 MainApplication.registerActionShortcut(EnterAction,EnterShortcut); 122 MainApplication.registerActionShortcut(EnterAction, EnterShortcut); 123 123 124 124 // Helper … … 126 126 InnerHelp = false; 127 127 LevelHelp = false; 128 129 130 128 innerRelation = null; 129 levelValue = new String(); 130 levelNum = new String(); 131 131 132 132 } … … 166 166 } 167 167 168 /*************************************************169 * TOOLBOX LISTENER170 *171 */172 173 168 /** 174 169 * The listener which provides the handling of the apply button. … … 186 181 IndoorObject indoorObject = toolboxView.getSelectedObject(); 187 182 188 183 // collecting all tags 189 184 List<Tag> tags = new ArrayList<>(); 190 185 if (toolboxView.getLevelCheckBoxStatus() == false && !levelValue.equals("")) { 191 186 tags.add(new Tag("level", levelValue)); 192 187 } 193 194 195 188 if (!toolboxView.getLevelNameText().isEmpty() && !toolboxView.getLevelCheckBoxStatus()) { 189 tags.add(new Tag("level_name", toolboxView.getLevelNameText())); 190 } 196 191 if (!toolboxView.getNameText().isEmpty()) { 197 192 tags.add(new Tag("name", toolboxView.getNameText())); … … 200 195 tags.add(new Tag("ref", toolboxView.getRefText())); 201 196 } 202 if (!toolboxView.getRepeatOnText().isEmpty()){ 203 204 205 206 207 197 if (!toolboxView.getRepeatOnText().isEmpty()) { 198 tags.add(new Tag("repeat_on", toolboxView.getRepeatOnText())); 199 } 200 if (!toolboxView.getLevelNameText().isEmpty() && !toolboxView.getLevelCheckBoxStatus()) { 201 tags.add(new Tag("level_name", toolboxView.getLevelNameText())); 202 } 208 203 209 204 // Tagging to OSM Data … … 236 231 toolboxView.setNRUiElementsEnabled(true); 237 232 toolboxView.setROUiElementsEnabled(false); 238 } 239 else if (toolboxView.getSelectedObject().equals(IndoorObject.STEPS) || 240 toolboxView.getSelectedObject().equals(IndoorObject.ELEVATOR)) { 241 toolboxView.setROUiElementsEnabled(true); 242 toolboxView.setNRUiElementsEnabled(true); 243 } 244 else { 233 } else if (toolboxView.getSelectedObject().equals(IndoorObject.STEPS) || 234 toolboxView.getSelectedObject().equals(IndoorObject.ELEVATOR)) { 235 toolboxView.setROUiElementsEnabled(true); 236 toolboxView.setNRUiElementsEnabled(true); 237 } else { 245 238 toolboxView.setROUiElementsEnabled(false); 246 239 } … … 253 246 * @author rebsc 254 247 */ 255 class ToolLevelCheckBoxListener implements ItemListener{ 248 class ToolLevelCheckBoxListener implements ItemListener { 256 249 @Override 257 250 public void itemStateChanged(ItemEvent e) { 258 if(e.getStateChange() == ItemEvent.SELECTED) { 259 toolboxView.setLVLUiElementsEnabled(false); 260 } 261 else { 262 toolboxView.setLVLUiElementsEnabled(true); 263 } 251 if (e.getStateChange() == ItemEvent.SELECTED) { 252 toolboxView.setLVLUiElementsEnabled(false); 253 } else { 254 toolboxView.setLVLUiElementsEnabled(true); 255 } 264 256 } 265 257 } … … 270 262 * @author rebsc 271 263 */ 272 static class ToolHelpButtonListener implements ActionListener{ 273 274 275 276 277 278 279 264 static class ToolHelpButtonListener implements ActionListener { 265 266 @Override 267 public void actionPerformed(ActionEvent e) { 268 String topic = "indoorHelper"; 269 //Open HelpBrowser for short description about the plugin 270 HelpBrowser.setUrlForHelpTopic(Optional.ofNullable(topic).orElse("/")); 271 } 280 272 } 281 273 … … 285 277 * @author rebsc 286 278 */ 287 class ToolAddLevelButtonListener implements ActionListener{ 288 289 290 291 292 if(selectorView == null) {293 294 295 296 297 298 299 300 301 302 303 279 class ToolAddLevelButtonListener implements ActionListener { 280 281 @Override 282 public void actionPerformed(ActionEvent e) { 283 284 if (selectorView == null) { 285 selectorView = new LevelSelectorView(); 286 addLevelSelectorListeners(); 287 288 //Show LevelSelectorView 289 selectorView.setVisible(true); 290 } else { 291 //Put focus back on LevelSelectorView 292 selectorView.toFront(); 293 } 294 295 } 304 296 } 305 297 … … 309 301 * @author rebsc 310 302 */ 311 class ToolMultiCheckBoxListener implements ItemListener{ 303 class ToolMultiCheckBoxListener implements ItemListener { 312 304 @Override 313 305 public void itemStateChanged(ItemEvent e) { 314 if(e.getStateChange() == ItemEvent.SELECTED) { 315 toolboxView.setMultiUiElementsEnabled(false); 316 } 317 else { 318 toolboxView.setMultiUiElementsEnabled(true); 319 } 306 if (e.getStateChange() == ItemEvent.SELECTED) { 307 toolboxView.setMultiUiElementsEnabled(false); 308 } else { 309 toolboxView.setMultiUiElementsEnabled(true); 310 } 320 311 } 321 312 } … … 326 317 * @author rebsc 327 318 */ 328 class ToolOuterButtonListener implements ActionListener{ 329 330 331 332 333 334 335 336 337 338 319 class ToolOuterButtonListener implements ActionListener { 320 321 @Override 322 public void actionPerformed(ActionEvent e) { 323 // Select drawing action 324 map.selectMapMode(drawAction); 325 326 // For space shortcut to add the relation after spacebar got pushed {@link SpaceAction} 327 OuterHelp = true; 328 InnerHelp = false; 329 } 339 330 } 340 331 … … 345 336 */ 346 337 class ToolInnerButtonListener implements ActionListener { 347 348 349 350 351 352 353 354 355 356 338 @Override 339 public void actionPerformed(ActionEvent e) { 340 // Select drawing action 341 map.selectMapMode(drawAction); 342 343 // For space shortcut to edit the relation after enter got pushed {@link SpaceAction}{@link EnterAction} 344 InnerHelp = true; 345 OuterHelp = false; 346 347 } 357 348 } 358 349 … … 416 407 } 417 408 418 /*************************************************419 * LEVEL SELCTOR VIEW LISTENER420 *421 */422 409 /** 423 410 * Specific listener for the applyButton … … 429 416 @Override 430 417 public void actionPerformed(ActionEvent e) { 431 432 433 //Get insert level number out of SelectorView434 if(!selectorView.getLevelNumber().equals("")) {435 436 437 438 439 440 441 442 }else {443 444 445 446 418 LevelHelp = true; 419 420 // Get insert level number out of SelectorView 421 if (!selectorView.getLevelNumber().equals("")) { 422 levelNum = selectorView.getLevelNumber(); 423 424 //Unset visibility 425 selectorView.dispose(); 426 //Select draw-action 427 map.selectMapMode(drawAction); 428 429 } else { 430 JOptionPane.showMessageDialog(null, tr("Please insert a value."), tr("Error"), JOptionPane.ERROR_MESSAGE); 431 } 432 433 selectorView = null; 447 434 } 448 435 } … … 467 454 * 468 455 */ 469 class ToolSelectorWindowSListener implements WindowListener{ 470 471 @Override 472 public void windowClosed(WindowEvent e) { 473 selectorView = null; 474 } 475 476 @Override 477 public void windowClosing(WindowEvent e) { 478 selectorView = null; 479 } 480 481 @Override 482 public void windowActivated(WindowEvent arg0) { 483 // TODO Auto-generated method stub 484 485 } 486 487 @Override 488 public void windowDeactivated(WindowEvent arg0) { 489 // TODO Auto-generated method stub 490 491 } 492 493 @Override 494 public void windowDeiconified(WindowEvent arg0) { 495 // TODO Auto-generated method stub 496 497 } 498 499 @Override 500 public void windowIconified(WindowEvent arg0) { 501 // TODO Auto-generated method stub 502 503 } 504 505 @Override 506 public void windowOpened(WindowEvent arg0) { 507 // TODO Auto-generated method stub 508 509 } 510 } 511 512 513 /************************************************* 514 * SHORTCUT METHODS 515 * 516 */ 456 class ToolSelectorWindowSListener implements WindowListener { 457 458 @Override 459 public void windowClosed(WindowEvent e) { 460 selectorView = null; 461 } 462 463 @Override 464 public void windowClosing(WindowEvent e) { 465 selectorView = null; 466 } 467 468 @Override 469 public void windowActivated(WindowEvent arg0) { 470 // TODO Auto-generated method stub 471 472 } 473 474 @Override 475 public void windowDeactivated(WindowEvent arg0) { 476 // TODO Auto-generated method stub 477 478 } 479 480 @Override 481 public void windowDeiconified(WindowEvent arg0) { 482 // TODO Auto-generated method stub 483 484 } 485 486 @Override 487 public void windowIconified(WindowEvent arg0) { 488 // TODO Auto-generated method stub 489 490 } 491 492 @Override 493 public void windowOpened(WindowEvent arg0) { 494 // TODO Auto-generated method stub 495 496 } 497 } 498 517 499 /** 518 500 * Shortcut for Spacebar … … 521 503 private class SpaceAction extends AbstractAction { 522 504 523 private static final long serialVersionUID = 1L; 524 525 @Override 526 public void actionPerformed(ActionEvent e) { 527 if(OuterHelp) { 528 529 //Create new relation and add the currently drawn object to it 530 model.addRelation("outer"); 531 map.selectMapMode(selectAction); 532 OuterHelp = false; 533 534 //Clear currently selection 535 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 536 } 537 else if(InnerHelp) { 538 539 //Save new drawn relation for adding 540 innerRelation = MainApplication.getLayerManager().getEditDataSet().getAllSelected(); 541 map.selectMapMode(selectAction); 542 543 //Clear currently selection 544 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 545 } 546 else if(LevelHelp) { 505 private static final long serialVersionUID = 1L; 506 507 @Override 508 public void actionPerformed(ActionEvent e) { 509 if (OuterHelp) { 510 511 //Create new relation and add the currently drawn object to it 512 model.addRelation("outer"); 513 map.selectMapMode(selectAction); 514 OuterHelp = false; 515 516 //Clear currently selection 517 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 518 } else if (InnerHelp) { 519 520 //Save new drawn relation for adding 521 innerRelation = MainApplication.getLayerManager().getEditDataSet().getAllSelected(); 522 map.selectMapMode(selectAction); 523 524 //Clear currently selection 525 MainApplication.getLayerManager().getEditDataSet().clearSelection(); 526 } else if (LevelHelp) { 547 527 548 528 List<Tag> tags = new ArrayList<>(); 549 550 551 552 553 554 555 556 529 tags.add(new Tag("level", levelNum)); 530 531 //Add level tag 532 model.addTagsToOSM(tags); 533 534 //Change action 535 map.selectMapMode(selectAction); 536 LevelHelp = false; 557 537 } 558 538 } … … 565 545 private class EnterAction extends AbstractAction { 566 546 567 private static final long serialVersionUID = 1L; 568 569 @Override 570 public void actionPerformed(ActionEvent e) { 571 572 if(InnerHelp && !OuterHelp) { 573 574 // Edit the new drawn relation member to selected relation 575 model.editRelation("inner", innerRelation); 576 InnerHelp = false; 577 578 }else if((InnerHelp && OuterHelp) || (OuterHelp && !InnerHelp)){ 579 JOptionPane.showMessageDialog(null, tr("Please press spacebar first to add \"outer\" object to relation."), tr("Relation-Error"), JOptionPane.ERROR_MESSAGE); 580 resetHelper(); 581 } 582 } 583 } 584 585 /************************************************* 586 * FILTER METHODS 587 * 588 */ 547 private static final long serialVersionUID = 1L; 548 549 @Override 550 public void actionPerformed(ActionEvent e) { 551 if (InnerHelp && !OuterHelp) { 552 // Edit the new drawn relation member to selected relation 553 model.editRelation("inner", innerRelation); 554 InnerHelp = false; 555 } else if ((InnerHelp && OuterHelp) || (OuterHelp && !InnerHelp)) { 556 JOptionPane.showMessageDialog(null, 557 tr("Please press spacebar first to add \"outer\" object to relation."), tr("Relation-Error"), JOptionPane.ERROR_MESSAGE); 558 resetHelper(); 559 } 560 } 561 } 562 589 563 /** 590 564 * Function which unset the disabled state of currently hidden and/or disabled objects which have a … … 592 566 * current working level. 593 567 * Specific example: key: repeat_on ; value: 1-4; 594 * If current selected workinglevel is "3" all objects with the leveltag "level=3" are hidden but the 595 * objects with the key "repeat_on" and the value which includes "3" or is (minValue+1) - maxValue (4-...), 596 * because repeat_on tag starts on the current workinglevel+1. 568 * If current selected workinglevel is "3" all objects with the leveltag "level=3" are hidden but the 569 * objects with the key "repeat_on" and the value which includes "3" or is (minValue+1) - maxValue (4-...), 570 * because repeat_on tag starts on the current workinglevel+1. 571 * @author rebsc 597 572 * @param key sepcific key to unset hidden objects which contains it 598 * @author rebsc599 573 */ 600 574 public void unsetSpecificKeyFilter(String key) { 601 575 602 Collection<OsmPrimitive> p = Main.main.getEditDataSet().allPrimitives(); 603 Map<String, String> tags = new HashMap<>(); 604 Integer level = Integer.parseInt(levelValue); 605 Integer firstVal, secVal; 606 607 //Find all primitives with the specific tag and check if value is part of the current 608 //workinglevel. After that unset the disabled status. 609 for(OsmPrimitive osm: p) { 610 if((osm.isDisabledAndHidden() || osm.isDisabled()) && osm.hasKey(key)) { 611 612 tags = osm.getInterestingTags(); 613 614 for(Map.Entry<String, String> e: tags.entrySet()) { 615 if(e.getKey().equals(key)) { 616 String val = e.getValue(); 617 618 //Extract values 619 if(val.indexOf("-") == 0) { 620 firstVal = (Integer.parseInt(val.split("-",2)[1].split("-",2)[0]))*-1; 621 secVal = Integer.parseInt(val.split("-",2)[1].split("-",2)[1]); 622 }else { 623 firstVal = Integer.parseInt(val.split("-")[0]); 624 secVal = Integer.parseInt(val.split("-")[1]); 625 } 626 627 //Compare values to current working level 628 if(level >= ((firstVal)-1) && level <= secVal) { 629 osm.unsetDisabledState(); 630 }else { 631 osm.setDisabledState(true); 632 } 633 } 634 635 } 636 637 } 638 } 639 640 } 641 642 /** 643 * Function which updates the current working level tag 644 * 645 * @param indoorLevel: current working level 646 */ 647 public void setIndoorLevel(String indoorLevel) { 648 this.toolboxView.setLevelLabel(indoorLevel); 649 } 650 651 /** 652 * Function which gets the current working level tag 653 * 654 * @param indoorLevel: current working level 655 */ 576 Collection<OsmPrimitive> p = Main.main.getEditDataSet().allPrimitives(); 577 Map<String, String> tags = new HashMap<>(); 578 Integer level = Integer.parseInt(levelValue); 579 Integer firstVal, secVal; 580 581 //Find all primitives with the specific tag and check if value is part of the current 582 //workinglevel. After that unset the disabled status. 583 for (OsmPrimitive osm: p) { 584 if ((osm.isDisabledAndHidden() || osm.isDisabled()) && osm.hasKey(key)) { 585 586 tags = osm.getInterestingTags(); 587 588 for (Map.Entry<String, String> e: tags.entrySet()) { 589 if (e.getKey().equals(key)) { 590 String val = e.getValue(); 591 592 //Extract values 593 if (val.indexOf("-") == 0) { 594 firstVal = (Integer.parseInt(val.split("-", 2)[1].split("-", 2)[0]))*-1; 595 secVal = Integer.parseInt(val.split("-", 2)[1].split("-", 2)[1]); 596 } else { 597 firstVal = Integer.parseInt(val.split("-")[0]); 598 secVal = Integer.parseInt(val.split("-")[1]); 599 } 600 601 //Compare values to current working level 602 if (level >= ((firstVal)-1) && level <= secVal) { 603 osm.unsetDisabledState(); 604 } else { 605 osm.setDisabledState(true); 606 } 607 } 608 } 609 } 610 } 611 } 612 613 /** 614 * Function which updates the current working level tag 615 * 616 * @param indoorLevel current working level 617 */ 618 public void setIndoorLevel(String indoorLevel) { 619 this.toolboxView.setLevelLabel(indoorLevel); 620 } 621 622 /** 623 * Function which gets the current working level tag 624 * 625 * @param indoorLevel current working level 626 */ 656 627 public void getIndoorLevel(String indoorLevel) { 657 levelValue = indoorLevel; 658 659 } 660 661 662 /************************************************* 663 * HELPER METHODS 664 * 665 */ 666 667 /** 668 * Function which resets the helper for relation adding 669 */ 670 private void resetHelper() { 671 InnerHelp = false; 672 OuterHelp = false; 673 } 628 levelValue = indoorLevel; 629 } 630 631 /** 632 * Function which resets the helper for relation adding 633 */ 634 private void resetHelper() { 635 InnerHelp = false; 636 OuterHelp = false; 637 } 674 638 675 639 /** … … 686 650 } 687 651 688 /** 689 * Enables or disables the preferences for the mapcss-style and the validator. 690 * 691 * @param enabled Activates or disables the settings. 692 */ 693 @SuppressWarnings("deprecation") 694 private void setPluginPreferences(boolean enabled) { 652 /** 653 * Enables or disables the preferences for the mapcss-style and the validator. 654 * 655 * @param enabled Activates or disables the settings. 656 */ 657 private void setPluginPreferences(boolean enabled) { 695 658 Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 696 659 … … 727 690 indoorValidator.put("title", "Indoor"); 728 691 indoorValidator.put("active", "true"); 729 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 692 indoorValidator.put("url", Main.pref.getDirs().getUserDataDirectory(true)+ sep +"validator" + 730 693 sep + "indoorhelper.validator.mapcss"); 731 694 … … 750 713 indoorMapPaint.put("title", tr("Indoor")); 751 714 indoorMapPaint.put("active", "true"); 752 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 715 indoorMapPaint.put("url", Main.pref.getDirs().getUserDataDirectory(true) + sep + "styles" 753 716 + sep + "sit.mapcss"); 754 717 styleMapsNew.add(indoorMapPaint); … … 774 737 indoorValidator.put("title", tr("Indoor")); 775 738 indoorValidator.put("active", "false"); 776 indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 739 indoorValidator.put("url", Main.pref.getDirs().getUserDataDirectory(true)+ sep +"validator" + 777 740 sep + "indoorhelper.validator.mapcss"); 778 741 … … 798 761 indoorMapPaint.put("title", tr("Indoor")); 799 762 indoorMapPaint.put("active", "false"); 800 indoorMapPaint.put("url", Main.pref.getUserDataDirectory() + sep + "styles" 763 indoorMapPaint.put("url", Main.pref.getDirs().getUserDataDirectory(true) + sep + "styles" 801 764 + sep + "sit.mapcss"); 802 765 styleMapsNew.add(indoorMapPaint); … … 806 769 } 807 770 } 808 809 810 811 812 813 /**814 *815 *816 *817 *818 *819 *820 *821 *822 *823 */824 771 }
Note:
See TracChangeset
for help on using the changeset viewer.