Changeset 33579 in osm for applications/editors
- Timestamp:
- 2017-08-27T22:22:31+02:00 (7 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 60 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/OSMRecPlugin/.settings/org.eclipse.jdt.ui.prefs
r32358 r33579 16 16 sp_cleanup.convert_functional_interfaces=false 17 17 sp_cleanup.convert_to_enhanced_for_loop=false 18 sp_cleanup.correct_indentation= true18 sp_cleanup.correct_indentation=false 19 19 sp_cleanup.format_source_code=false 20 20 sp_cleanup.format_source_code_changes_only=false -
applications/editors/josm/plugins/OSMRecPlugin/build.xml
r33524 r33579 3 3 4 4 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 5 <property name="plugin.main.version" value="126 63"/>5 <property name="plugin.main.version" value="12678"/> 6 6 <property name="plugin.version" value="2.1"/> 7 7 -
applications/editors/josm/plugins/OSMRecPlugin/src/org/openstreetmap/josm/plugins/osmrec/OSMRecPluginHelper.java
r33525 r33579 107 107 //import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 108 108 import org.openstreetmap.josm.gui.util.GuiHelper; 109 import org.openstreetmap.josm.gui.util.WindowGeometry; 109 110 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 110 111 import org.openstreetmap.josm.io.XmlWriter; … … 125 126 import org.openstreetmap.josm.tools.Logging; 126 127 import org.openstreetmap.josm.tools.Shortcut; 127 import org.openstreetmap.josm.tools.WindowGeometry;128 128 129 129 import com.vividsolutions.jts.geom.Coordinate; … … 146 146 class OSMRecPluginHelper { 147 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 148 private final DefaultTableModel tagData; 149 private static Collection<String> fileHistory; 150 private Map<File, Double> filesAndWeights = new HashMap<>(); 151 private boolean useCombinedModel; 152 153 //the most recent file from history. 154 //all necessary files will reside in a directory of this file 155 private static String MAIN_PATH; 156 private static String MODEL_PATH; 157 private static String TEXTUAL_LIST_PATH; 158 private static Map<String, List<String>> indirectClasses; 159 private static Map<String, Integer> indirectClassesWithIDs; 160 private static LanguageDetector languageDetector; 161 private static String bestModelPath; 162 private boolean modelWithClasses; 163 private final String modelWithClassesPath; 164 private boolean useCustomSVMModel = false; 165 private String customSVMModelPath; 166 private final String combinedModelClasses; 167 private final String combinedModel; 168 169 // Selection that we are editing by using both dialogs 170 Collection<OsmPrimitive> sel; 171 172 private String changedKey; 173 174 Comparator<AutoCompletionListItem> defaultACItemComparator = new Comparator<AutoCompletionListItem>() { 175 @Override 176 public int compare(AutoCompletionListItem o1, AutoCompletionListItem o2) { 177 return String.CASE_INSENSITIVE_ORDER.compare(o1.getValue(), o2.getValue()); 178 } 179 }; 180 181 private String lastAddKey = null; 182 private String lastAddValue = null; 183 184 public static final int DEFAULT_LRU_TAGS_NUMBER = 5; 185 public static final int MAX_LRU_TAGS_NUMBER = 30; 186 187 // LRU cache for recently added tags (http://java-planet.blogspot.com/2005/08/how-to-set-up-simple-lru-cache-using.html) 188 private final Map<Tag, Void> recentTags = new LinkedHashMap<Tag, Void>(MAX_LRU_TAGS_NUMBER+1, 1.1f, true) { 189 @Override 190 protected boolean removeEldestEntry(Map.Entry<Tag, Void> eldest) { 191 return size() > MAX_LRU_TAGS_NUMBER; 192 } 193 }; 194 195 OSMRecPluginHelper(DefaultTableModel propertyData, Map<String, Map<String, Integer>> valueCount) { 196 this.tagData = propertyData; 197 fileHistory = Main.pref.getCollection("file-open.history"); 198 if (!fileHistory.isEmpty()) { 199 MAIN_PATH = (String) fileHistory.toArray()[0]; 200 } else { 201 MAIN_PATH = System.getProperty("user.home"); 202 } 203 MODEL_PATH = new File(MAIN_PATH).getParentFile() + "/OSMRec_models"; 204 TEXTUAL_LIST_PATH = MODEL_PATH + "/textualList.txt"; 205 combinedModelClasses = MODEL_PATH + "/combinedModel.1"; 206 combinedModel = MODEL_PATH + "/combinedModel.0"; 207 bestModelPath = MODEL_PATH + "/best_model"; 208 customSVMModelPath = bestModelPath; 209 modelWithClassesPath = MODEL_PATH + "/model_with_classes"; 210 languageDetector = LanguageDetector.getInstance(MODEL_PATH + "/profiles"); 211 212 SampleModelsExtractor sampleModelsExtractor = new SampleModelsExtractor(); 213 214 sampleModelsExtractor.extractSampleSVMmodel("best_model", bestModelPath); 215 sampleModelsExtractor.extractSampleSVMmodel("model_with_classes", modelWithClassesPath); 216 } 217 218 /** 219 * Open the add selection dialog and add a new key/value to the table (and to the dataset, of course). 220 */ 221 public void addTag() { 222 changedKey = null; 223 sel = Main.main.getInProgressSelection(); 224 if (sel == null || sel.isEmpty()) return; 225 226 final AddTagsDialog addDialog = new AddTagsDialog(); 227 228 addDialog.showDialog(); 229 230 addDialog.destroyActions(); 231 if (addDialog.getValue() == 1) 232 addDialog.performTagAdding(); 233 else 234 addDialog.undoAllTagsAdding(); 235 } 236 237 /** 238 * Edit the value in the tags table row. 239 * @param row The row of the table from which the value is edited. 240 * @param focusOnKey Determines if the initial focus should be set on key instead of value 241 * @since 5653 242 */ 243 public void editTag(final int row, boolean focusOnKey) { 244 changedKey = null; 245 sel = Main.main.getInProgressSelection(); 246 String key = ""; 247 248 @SuppressWarnings("unchecked") 249 Map<String, Integer> dumPar = new HashMap<>(); 250 dumPar.put(" ", -1); 251 final TrainingDialog editDialog = new TrainingDialog(key, row, 252 dumPar, focusOnKey); 253 editDialog.showDialog(); 254 } 255 256 /** 257 * If during last editProperty call user changed the key name, this key will be returned 258 * Elsewhere, returns null. 259 * @return The modified key, or {@code null} 260 */ 261 public String getChangedKey() { 262 return changedKey; 263 } 264 265 /** 266 * For a given key k, return a list of keys which are used as keys for 267 * auto-completing values to increase the search space. 268 * @param key the key k 269 * @return a list of keys 270 */ 271 private static List<String> getAutocompletionKeys(String key) { 272 if ("name".equals(key) || "addr:street".equals(key)) 273 return Arrays.asList("addr:street", "name"); 274 else 275 return Arrays.asList(key); 276 } 277 278 /** 279 * Load recently used tags from preferences if needed. 280 */ 281 public void loadTagsIfNeeded() { 282 if (PROPERTY_REMEMBER_TAGS.get() && recentTags.isEmpty()) { 283 recentTags.clear(); 284 Collection<String> c = Main.pref.getCollection("properties.recent-tags"); 285 Iterator<String> it = c.iterator(); 286 String key, value; 287 while (it.hasNext()) { 288 key = it.next(); 289 value = it.next(); 290 recentTags.put(new Tag(key, value), null); 291 } 292 } 293 } 294 295 /** 296 * Store recently used tags in preferences if needed. 297 */ 298 public void saveTagsIfNeeded() { 299 if (PROPERTY_REMEMBER_TAGS.get() && !recentTags.isEmpty()) { 300 List<String> c = new ArrayList<>(recentTags.size()*2); 301 for (Tag t: recentTags.keySet()) { 302 c.add(t.getKey()); 303 c.add(t.getValue()); 304 } 305 Main.pref.putCollection("properties.recent-tags", c); 306 } 307 } 308 309 /** 310 * Warns user about a key being overwritten. 311 * @param action The action done by the user. Must state what key is changed 312 * @param togglePref The preference to save the checkbox state to 313 * @return {@code true} if the user accepts to overwrite key, {@code false} otherwise 314 */ 315 private boolean warnOverwriteKey(String action, String togglePref) { 316 ExtendedDialog ed = new ExtendedDialog( 317 Main.parent, 318 tr("Overwrite key"), 319 new String[]{tr("Replace"), tr("Cancel")}); 320 ed.setButtonIcons(new String[]{"purge", "cancel"}); 321 ed.setContent(action+"\n"+ tr("The new key is already used, overwrite values?")); 322 ed.setCancelButton(2); 323 ed.toggleEnable(togglePref); 324 ed.showDialog(); 325 326 return ed.getValue() == 1; 327 } 328 329 public final class TrainingDialog extends AbstractTagsDialog { 330 331 private static final int FIELD_COLUMNS = 4; 332 private final JTextField inputFileField; 333 private final JLabel inputFileLabel; 334 private final JTextField topKField; 335 private final JTextField cParameterField; 336 private final JTextField frequencyField; 337 338 private final JButton fileBrowseButton; 339 private final JButton acceptConfigButton; 340 private JRadioButton frequencyButton; 341 private JRadioButton topKButton; 342 private JCheckBox cParameterCheckBox; 343 private final JButton resetConfigButton; 344 private String inputFileValue; 345 private Double cParameterValue = 0.0; 346 private Integer topKvalue = 0; 347 private Integer frequencyValue = 0; 348 private boolean crossValidateFlag; 349 private final JButton startTrainingButton; 350 private final JLabel cErrorMessageLabel; 351 private final JLabel topKErrorMessageLabel; 352 private final JLabel inputFileErrorMessageLabel; 353 private final JLabel frequencyErrorMessageLabel; 354 private final JProgressBar trainingProgressBar; 355 private final JRadioButton byAreaRadioButton; 356 private final JRadioButton byTimeRadioButton; 357 private final JLabel userNameLabel; 358 private final JTextField userNameField; 359 private final JTextField daysField; 360 private final JLabel daysLabel; 361 private final JCheckBox trainFromUserCheckBox; 362 private final JPanel userHistoryPanel; 363 private Integer daysValue; 364 private String usernameValue; 365 private TrainWorker trainWorker; 366 private UserDataExtractAndTrainWorker userDataExtractAndTrainWorker; 367 368 private TrainingDialog(String key, int row, Map<String, Integer> map, final boolean initialFocusOnKey) { 369 super(Main.parent, tr("Training process configuration"), new String[] {tr("Cancel")}); 370 371 setButtonIcons(new String[] {"ok", "cancel"}); 372 setCancelButton(2); 373 374 JPanel mainPanel = new JPanel(new BorderLayout(10, 10)); //6,6 375 JPanel configPanel = new JPanel(new BorderLayout(10, 10)); //6,6 //at NORTH of mainPanel 376 JPanel inputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); //NORTH at config panel 377 JPanel paramPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); //WEST at config panel //config panel has EAST free 378 379 JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); //SOUTH at config panel 380 userHistoryPanel = new JPanel(); //CENTER of config 381 382 trainingProgressBar = new JProgressBar(0, 100); 383 384 ButtonGroup paramGroup = new ButtonGroup(); 385 ButtonGroup userGroup = new ButtonGroup(); 386 inputFileLabel = new JLabel(); 387 inputFileField = new JTextField(); 388 cParameterField = new JTextField(); 389 topKField = new JTextField(); 390 frequencyField = new JTextField(); 391 392 cParameterCheckBox = new JCheckBox("Define C parameter"); 393 topKButton = new JRadioButton("Top-K terms"); 394 frequencyButton = new JRadioButton("Max-Frequency"); 395 fileBrowseButton = new JButton(); 396 acceptConfigButton = new JButton("Accept Configuration"); 397 resetConfigButton = new JButton("Reset Configuration/Cancel training"); 398 startTrainingButton = new JButton("Train Model"); 399 400 inputFileErrorMessageLabel = new JLabel(""); 401 cErrorMessageLabel = new JLabel(""); 402 topKErrorMessageLabel = new JLabel(""); 403 frequencyErrorMessageLabel = new JLabel(""); 404 405 trainFromUserCheckBox = new JCheckBox("Train Model From User"); 406 byAreaRadioButton = new JRadioButton("By Area"); 407 byTimeRadioButton = new JRadioButton("By Time"); 408 userNameLabel = new JLabel("Username:"); 409 userNameField = new JTextField(); 410 411 daysLabel = new JLabel("Days: "); 412 daysField = new JTextField(); 413 414 cParameterCheckBox.setSelected(true); 415 userHistoryPanel.setEnabled(false); 416 byAreaRadioButton.setEnabled(false); 417 byAreaRadioButton.setSelected(true); 418 byTimeRadioButton.setEnabled(false); 419 userNameLabel.setEnabled(false); 420 userNameField.setEnabled(false); 421 daysLabel.setEnabled(false); 422 daysField.setEnabled(false); 423 userNameField.setColumns(FIELD_COLUMNS); 424 daysField.setColumns(FIELD_COLUMNS); 425 426 Collection<String> fileHistory = Main.pref.getCollection("file-open.history"); 427 if (!fileHistory.isEmpty()) { 428 inputFileField.setText(MAIN_PATH); 429 } 430 431 fileBrowseButton.setText("..."); 432 inputFileLabel.setText("OSM filepath: "); 433 inputFileErrorMessageLabel.setForeground(Color.RED); 434 inputFileErrorMessageLabel.setText(""); 435 topKField.setText("50"); 436 frequencyField.setText("200"); 437 cParameterField.setText("0.01"); 438 439 cParameterField.setColumns(FIELD_COLUMNS); 440 cParameterField.setEditable(false); 441 cParameterField.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 442 cErrorMessageLabel.setForeground(Color.RED); 443 cErrorMessageLabel.setMinimumSize(new Dimension(150, 10)); 444 445 topKButton.setSelected(true); 446 topKField.setColumns(FIELD_COLUMNS); 447 topKField.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 448 topKErrorMessageLabel.setForeground(Color.RED); 449 450 frequencyField.setEditable(false); 451 frequencyField.setColumns(FIELD_COLUMNS); 452 frequencyField.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 453 frequencyErrorMessageLabel.setForeground(Color.RED); 454 455 fileBrowseButton.addActionListener(new java.awt.event.ActionListener() { 456 @Override 457 public void actionPerformed(java.awt.event.ActionEvent evt) { 458 inputFileChooserButtonActionPerformed(evt); 459 } 460 }); 461 topKButton.addActionListener(new java.awt.event.ActionListener() { 462 @Override 463 public void actionPerformed(java.awt.event.ActionEvent evt) { 464 if (topKButton.isSelected()) { 465 frequencyField.setEditable(false); 466 topKField.setEditable(true); 467 } else { 468 frequencyField.setEditable(true); 469 topKField.setEditable(false); 470 } 471 } 472 }); 473 frequencyButton.addActionListener(new java.awt.event.ActionListener() { 474 @Override 475 public void actionPerformed(java.awt.event.ActionEvent evt) { 476 if (frequencyButton.isSelected()) { 477 topKField.setEditable(false); 478 frequencyField.setEditable(true); 479 } else { 480 topKField.setEditable(true); 481 frequencyField.setEditable(false); 482 } 483 } 484 }); 485 cParameterCheckBox.addActionListener(new java.awt.event.ActionListener() { 486 @Override 487 public void actionPerformed(java.awt.event.ActionEvent evt) { 488 if (cParameterCheckBox.isSelected()) { 489 cParameterField.setEditable(true); 490 } else { 491 cParameterField.setEditable(false); 492 } 493 } 494 }); 495 acceptConfigButton.addActionListener(new java.awt.event.ActionListener() { 496 @Override 497 public void actionPerformed(java.awt.event.ActionEvent evt) { 498 acceptConfigButtonActionPerformed(evt); 499 } 500 }); 501 resetConfigButton.addActionListener(new java.awt.event.ActionListener() { 502 @Override 503 public void actionPerformed(java.awt.event.ActionEvent evt) { 504 resetConfigButtonActionPerformed(); 505 } 506 }); 507 508 startTrainingButton.addActionListener(new java.awt.event.ActionListener() { 509 @Override 510 public void actionPerformed(java.awt.event.ActionEvent evt) { 511 if (!acceptConfigButton.isEnabled()) { 512 startTraining(); 513 } else { 514 System.out.println("Set values first!"); 515 } 516 } 517 }); 518 519 trainFromUserCheckBox.addActionListener(new java.awt.event.ActionListener() { 520 @Override 521 public void actionPerformed(java.awt.event.ActionEvent evt) { 522 if (trainFromUserCheckBox.isSelected()) { 523 userHistoryPanel.setEnabled(true); 524 byAreaRadioButton.setEnabled(true); 525 byTimeRadioButton.setEnabled(true); 526 userNameLabel.setEnabled(true); 527 userNameField.setEnabled(true); 528 daysLabel.setEnabled(true); 529 daysField.setEnabled(true); 530 } else { 531 userHistoryPanel.setEnabled(false); 532 byAreaRadioButton.setEnabled(false); 533 byTimeRadioButton.setEnabled(false); 534 userNameLabel.setEnabled(false); 535 userNameField.setEnabled(false); 536 daysLabel.setEnabled(false); 537 daysField.setEnabled(false); 538 } 539 } 540 }); 541 542 byAreaRadioButton.addActionListener(new java.awt.event.ActionListener() { 543 @Override 544 public void actionPerformed(java.awt.event.ActionEvent evt) { 545 if (byAreaRadioButton.isSelected()) { 546 daysField.setEditable(false); 547 } else { 548 daysField.setEditable(true); 549 } 550 } 551 }); 552 553 byTimeRadioButton.addActionListener(new java.awt.event.ActionListener() { 554 @Override 555 public void actionPerformed(java.awt.event.ActionEvent evt) { 556 if (byTimeRadioButton.isSelected()) { 557 daysField.setEditable(true); 558 } else { 559 daysField.setEditable(false); 560 } 561 } 562 }); 563 564 //grouplayout for input panel 565 buildInputPanelGroupLayout(inputPanel); 566 567 //grouplayout for param panel 568 buildParamPanelGroupLayout(paramPanel); 569 570 inputPanel.add(inputFileLabel); 571 inputPanel.add(inputFileField); 572 inputPanel.add(fileBrowseButton); 573 inputPanel.add(inputFileErrorMessageLabel); 574 575 paramGroup.add(topKButton); 576 paramGroup.add(frequencyButton); 577 578 paramPanel.add(cParameterCheckBox); 579 paramPanel.add(cParameterField); 580 paramPanel.add(cErrorMessageLabel); 581 paramPanel.add(topKButton); 582 paramPanel.add(topKField); 583 paramPanel.add(topKErrorMessageLabel); 584 paramPanel.add(frequencyButton); 585 paramPanel.add(frequencyField); 586 paramPanel.add(frequencyErrorMessageLabel); 587 588 southPanel.add(acceptConfigButton); 589 southPanel.add(resetConfigButton); 590 southPanel.add(trainFromUserCheckBox); 591 592 userGroup.add(byAreaRadioButton); 593 userGroup.add(byTimeRadioButton); 594 userHistoryPanel.add(byAreaRadioButton); 595 userHistoryPanel.add(byTimeRadioButton); 596 userHistoryPanel.add(daysLabel); 597 userHistoryPanel.add(daysField); 598 userHistoryPanel.add(userNameLabel); 599 userHistoryPanel.add(userNameField); 600 601 //grouplayout for user history panel 602 /* 603 603 userNameLabel userField 604 604 arearadiobutton 605 605 timeradiobutton daysLabel daysField 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 606 */ 607 buildUserHistoryPanelGroupLayout(); 608 609 configPanel.add(inputPanel, BorderLayout.NORTH); 610 configPanel.add(userHistoryPanel, BorderLayout.EAST); 611 configPanel.add(paramPanel, BorderLayout.WEST); 612 configPanel.add(southPanel, BorderLayout.SOUTH); 613 614 userHistoryPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory 615 .createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE), "Train by user History")); 616 paramPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory 617 .createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE), "SVM Configuration")); 618 inputPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 619 configPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 620 621 mainPanel.add(configPanel, BorderLayout.NORTH); 622 mainPanel.add(startTrainingButton, BorderLayout.CENTER); 623 mainPanel.add(trainingProgressBar, BorderLayout.SOUTH); 624 625 AutoCompletionManager autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager(); 626 List<AutoCompletionListItem> keyList = autocomplete.getKeys(); 627 Collections.sort(keyList, defaultACItemComparator); 628 629 setContent(mainPanel, false); 630 } 631 632 private void buildInputPanelGroupLayout(JPanel inputPanel) { 633 GroupLayout inputGroupLayout = new GroupLayout(inputPanel); 634 inputPanel.setLayout(inputGroupLayout); 635 inputGroupLayout.setAutoCreateGaps(true); 636 inputGroupLayout.setAutoCreateContainerGaps(true); 637 638 GroupLayout.SequentialGroup inputHorGroup = inputGroupLayout.createSequentialGroup(); 639 inputHorGroup.addGroup(inputGroupLayout.createParallelGroup().addComponent(inputFileLabel). 640 addComponent(inputFileErrorMessageLabel)); 641 inputHorGroup.addGroup(inputGroupLayout.createParallelGroup().addComponent(inputFileField)); 642 inputHorGroup.addGroup(inputGroupLayout.createParallelGroup().addComponent(fileBrowseButton)); 643 inputGroupLayout.setHorizontalGroup(inputHorGroup); 644 645 GroupLayout.SequentialGroup inputVerGroup = inputGroupLayout.createSequentialGroup(); 646 inputVerGroup.addGroup(inputGroupLayout.createParallelGroup(Alignment.LEADING).addComponent(inputFileLabel). 647 addComponent(inputFileField).addComponent(fileBrowseButton)); 648 inputVerGroup.addGroup(inputGroupLayout.createParallelGroup(Alignment.LEADING). 649 addComponent(inputFileErrorMessageLabel)); 650 inputGroupLayout.setVerticalGroup(inputVerGroup); 651 } 652 653 private void buildParamPanelGroupLayout(JPanel paramPanel) { 654 GroupLayout paramGroupLayout = new GroupLayout(paramPanel); 655 paramPanel.setLayout(paramGroupLayout); 656 paramGroupLayout.setAutoCreateGaps(true); 657 paramGroupLayout.setAutoCreateContainerGaps(true); 658 659 GroupLayout.SequentialGroup paramHorGroup = paramGroupLayout.createSequentialGroup(); 660 paramHorGroup.addGroup(paramGroupLayout.createParallelGroup().addComponent(topKButton). 661 addComponent(frequencyButton).addComponent(cParameterCheckBox)); 662 paramHorGroup.addGroup(paramGroupLayout.createParallelGroup().addComponent(cParameterField). 663 addComponent(topKField).addComponent(frequencyField)); 664 paramHorGroup.addGroup(paramGroupLayout.createParallelGroup().addComponent(cErrorMessageLabel). 665 addComponent(topKErrorMessageLabel).addComponent(frequencyErrorMessageLabel)); 666 paramGroupLayout.setHorizontalGroup(paramHorGroup); 667 668 GroupLayout.SequentialGroup paramVerGroup = paramGroupLayout.createSequentialGroup(); 669 paramVerGroup.addGroup(paramGroupLayout.createParallelGroup(Alignment.BASELINE). 670 addComponent(cParameterCheckBox).addComponent(cParameterField).addComponent(cErrorMessageLabel)); 671 paramVerGroup.addGroup(paramGroupLayout.createParallelGroup(Alignment.BASELINE).addComponent(topKButton). 672 addComponent(topKField).addComponent(topKErrorMessageLabel)); 673 paramVerGroup.addGroup(paramGroupLayout.createParallelGroup(Alignment.BASELINE). 674 addComponent(frequencyButton).addComponent(frequencyField).addComponent(frequencyErrorMessageLabel)); 675 paramGroupLayout.setVerticalGroup(paramVerGroup); 676 } 677 678 private void buildUserHistoryPanelGroupLayout() { 679 GroupLayout userHistoryGroupLayout = new GroupLayout(userHistoryPanel); 680 userHistoryPanel.setLayout(userHistoryGroupLayout); 681 userHistoryGroupLayout.setAutoCreateGaps(true); 682 userHistoryGroupLayout.setAutoCreateContainerGaps(true); 683 userHistoryGroupLayout.linkSize(SwingConstants.HORIZONTAL, userNameField, daysLabel, daysField); 684 685 GroupLayout.SequentialGroup userHistoryHorGroup = userHistoryGroupLayout.createSequentialGroup(); 686 687 userHistoryHorGroup.addGroup(userHistoryGroupLayout.createParallelGroup().addComponent(userNameLabel) 688 .addComponent(byAreaRadioButton).addComponent(byTimeRadioButton)); 689 userHistoryHorGroup.addGroup(userHistoryGroupLayout.createParallelGroup().addComponent(userNameField) 690 .addComponent(daysLabel)); 691 userHistoryHorGroup.addGroup(userHistoryGroupLayout.createParallelGroup().addComponent(daysField)); 692 userHistoryGroupLayout.setHorizontalGroup(userHistoryHorGroup); 693 694 GroupLayout.SequentialGroup userHistoryVerGroup = userHistoryGroupLayout.createSequentialGroup(); 695 userHistoryVerGroup.addGroup(userHistoryGroupLayout.createParallelGroup(Alignment.BASELINE). 696 addComponent(userNameLabel).addComponent(userNameField)); 697 userHistoryVerGroup.addGroup(userHistoryGroupLayout.createParallelGroup(Alignment.BASELINE). 698 addComponent(byAreaRadioButton)); 699 userHistoryVerGroup.addGroup(userHistoryGroupLayout.createParallelGroup(Alignment.BASELINE). 700 addComponent(byTimeRadioButton).addComponent(daysLabel).addComponent(daysField)); 701 userHistoryGroupLayout.setVerticalGroup(userHistoryVerGroup); 702 } 703 704 private void inputFileChooserButtonActionPerformed(ActionEvent evt) { 705 try { 706 final File file = new File(inputFileField.getText()); 707 final JFileChooser fileChooser = new JFileChooser(file); 708 709 final int returnVal = fileChooser.showOpenDialog(this); 710 if (returnVal == JFileChooser.APPROVE_OPTION) { 711 inputFileField.setText(fileChooser.getSelectedFile().getAbsolutePath()); 712 } 713 } catch (RuntimeException ex) { 714 Logging.warn(ex); 715 } 716 } 717 718 private void acceptConfigButtonActionPerformed(ActionEvent evt) { 719 //parse values 720 inputFileValue = inputFileField.getText(); 721 722 if (!new File(inputFileValue).exists()) { 723 inputFileErrorMessageLabel.setText("OSM file does not exist"); 724 resetConfigButtonActionPerformed(); 725 return; 726 } 727 728 if (cParameterCheckBox.isSelected()) { 729 String c = cParameterField.getText(); 730 try { 731 cParameterValue = Double.parseDouble(c.replace(",", ".")); 732 cErrorMessageLabel.setText(""); 733 } catch (NumberFormatException ex) { 734 cErrorMessageLabel.setText("Must be a number!"); 735 System.out.println("c must be a number!" + ex); //make empty textLabel beside c param to notify errors 736 resetConfigButtonActionPerformed(); 737 return; 738 } 739 crossValidateFlag = false; 740 } else { 741 crossValidateFlag = true; 742 } 743 744 if (topKButton.isSelected()) { 745 String k = topKField.getText(); 746 try { 747 topKvalue = Integer.parseInt(k); 748 topKErrorMessageLabel.setText(""); 749 } catch (NumberFormatException ex) { 750 topKErrorMessageLabel.setText("Must be an Integer!"); 751 resetConfigButtonActionPerformed(); 752 return; 753 } 754 } else { 755 String f = frequencyField.getText(); 756 try { 757 frequencyValue = Integer.parseInt(f); 758 frequencyErrorMessageLabel.setText(""); 759 } catch (NumberFormatException ex) { 760 frequencyErrorMessageLabel.setText("Must be an Integer!"); 761 resetConfigButtonActionPerformed(); 762 return; 763 } 764 } 765 766 if (trainFromUserCheckBox.isSelected()) { 767 usernameValue = userNameField.getText(); 768 if (byTimeRadioButton.isSelected()) { 769 try { 770 daysValue = Integer.parseInt(daysField.getText()); 771 } catch (NumberFormatException ex) { 772 daysField.setText("Integer!"); 773 Logging.warn(ex); 774 } 775 } 776 777 userHistoryPanel.setEnabled(false); 778 byAreaRadioButton.setEnabled(false); 779 byTimeRadioButton.setEnabled(false); 780 userNameLabel.setEnabled(false); 781 userNameField.setEnabled(false); 782 daysLabel.setEnabled(false); 783 daysField.setEnabled(false); 784 } 785 786 System.out.println("Running configuration:" + "\nC parameter: " + cParameterValue +" \ntopK: " + topKvalue 787 + "\nMax Frequency: " + frequencyValue + "\nCross Validate?: " + crossValidateFlag); 788 789 trainFromUserCheckBox.setEnabled(false); 790 inputFileField.setEditable(false); 791 cParameterField.setEditable(false); 792 topKField.setEditable(false); 793 frequencyField.setEditable(false); 794 cParameterCheckBox.setEnabled(false); 795 topKButton.setEnabled(false); 796 frequencyButton.setEnabled(false); 797 acceptConfigButton.setEnabled(false); 798 fileBrowseButton.setEnabled(false); 799 } 800 801 private void resetConfigButtonActionPerformed() { 802 if (trainWorker != null) { 803 try { 804 trainWorker.cancel(true); 805 } catch (CancellationException ex) { 806 startTrainingButton.setEnabled(true); 807 System.out.println(ex); 808 } 809 } 810 if (userDataExtractAndTrainWorker != null) { 811 try { 812 userDataExtractAndTrainWorker.cancel(true); 813 } catch (CancellationException ex) { 814 startTrainingButton.setEnabled(true); 815 System.out.println(ex); 816 } 817 } 818 inputFileField.setEditable(true); 819 cParameterField.setEditable(true); 820 topKField.setEditable(true); 821 frequencyField.setEditable(true); 822 cParameterCheckBox.setEnabled(true); 823 topKButton.setEnabled(true); 824 frequencyButton.setEnabled(true); 825 acceptConfigButton.setEnabled(true); 826 fileBrowseButton.setEnabled(true); 827 trainFromUserCheckBox.setEnabled(true); 828 829 if (trainFromUserCheckBox.isSelected()) { 830 userHistoryPanel.setEnabled(true); 831 byAreaRadioButton.setEnabled(true); 832 byTimeRadioButton.setEnabled(true); 833 userNameLabel.setEnabled(true); 834 userNameField.setEnabled(true); 835 daysLabel.setEnabled(true); 836 daysField.setEnabled(true); 837 } 838 } 839 840 private void startTraining() { 841 startTrainingButton.setEnabled(false); 842 843 if (trainFromUserCheckBox.isSelected()) { //if user training. train by area or days 844 EventQueue.invokeLater(new Runnable() { 845 @Override 846 public void run() { 847 848 userDataExtractAndTrainWorker = new UserDataExtractAndTrainWorker(inputFileValue, usernameValue, daysValue, 849 byAreaRadioButton.isSelected(), crossValidateFlag, cParameterValue, topKvalue, frequencyValue, 850 topKButton.isSelected(), languageDetector); 851 852 userDataExtractAndTrainWorker.addPropertyChangeListener(new PropertyChangeListener() { 853 @Override 854 public void propertyChange(PropertyChangeEvent evt) { 855 if ("progress".equals(evt.getPropertyName())) { 856 int progress = (Integer) evt.getNewValue(); 857 trainingProgressBar.setValue(progress); 858 if (progress == 100) { 859 startTrainingButton.setEnabled(true); 860 } 861 } 862 } 863 }); 864 865 try { 866 System.out.println("executing userDataExtractAndTrainWorker Thread.."); 867 userDataExtractAndTrainWorker.execute(); 868 } catch (Exception ex) { 869 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 870 } 871 } 872 }); 873 } else { 874 EventQueue.invokeLater(new Runnable() { 875 @Override 876 public void run() { 877 trainWorker = new TrainWorker(inputFileValue, crossValidateFlag, cParameterValue, topKvalue, frequencyValue, 878 topKButton.isSelected(), languageDetector); 879 880 trainWorker.addPropertyChangeListener(new PropertyChangeListener() { 881 @Override 882 public void propertyChange(PropertyChangeEvent evt) { 883 if ("progress".equals(evt.getPropertyName())) { 884 int progress = (Integer) evt.getNewValue(); 885 trainingProgressBar.setValue(progress); 886 if (progress == 100) { 887 startTrainingButton.setEnabled(true); 888 } 889 } 890 } 891 }); 892 893 try { 894 trainWorker.execute(); 895 } catch (Exception ex) { 896 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 897 } 898 } 899 }); 900 } 901 } 902 } 903 904 public static final BooleanProperty PROPERTY_FIX_TAG_LOCALE = 905 new BooleanProperty("properties.fix-tag-combobox-locale", false); 906 public static final BooleanProperty PROPERTY_REMEMBER_TAGS = 907 new BooleanProperty("properties.remember-recently-added-tags", true); 908 public static final IntegerProperty PROPERTY_RECENT_TAGS_NUMBER = 909 new IntegerProperty("properties.recently-added-tags", DEFAULT_LRU_TAGS_NUMBER); 910 911 abstract static class AbstractTagsDialog extends ExtendedDialog { 912 AutoCompletingComboBox keys; 913 AutoCompletingComboBox values; 914 915 AbstractTagsDialog(Component parent, String title, String[] buttonTexts) { 916 super(parent, title, buttonTexts); 917 addMouseListener(new PopupMenuLauncher(popupMenu)); 918 } 919 920 @Override 921 public void setupDialog() { 922 super.setupDialog(); 923 final Dimension size = getSize(); 924 // Set resizable only in width 925 setMinimumSize(size); 926 setPreferredSize(size); 927 // setMaximumSize does not work, and never worked, but still it seems not to bother Oracle to fix this 10-year-old bug 928 // https://bugs.openjdk.java.net/browse/JDK-6200438 929 // https://bugs.openjdk.java.net/browse/JDK-6464548 930 931 setRememberWindowGeometry(getClass().getName() + ".geometry", 932 WindowGeometry.centerInWindow(Main.parent, size)); 933 } 934 935 @Override 936 public void setVisible(boolean visible) { 937 // Do not want dialog to be resizable in height, as its size may increase each time because of the recently added tags 938 // So need to modify the stored geometry (size part only) in order to use the automatic positioning mechanism 939 if (visible) { 940 WindowGeometry geometry = initWindowGeometry(); 941 Dimension storedSize = geometry.getSize(); 942 Dimension size = getSize(); 943 if (!storedSize.equals(size)) { 944 if (storedSize.width < size.width) { 945 storedSize.width = size.width; 946 } 947 if (storedSize.height != size.height) { 948 storedSize.height = size.height; 949 } 950 rememberWindowGeometry(geometry); 951 } 952 if (keys != null) { 953 keys.setFixedLocale(PROPERTY_FIX_TAG_LOCALE.get()); 954 } 955 } 956 super.setVisible(visible); 957 } 958 959 /** 960 * Create a focus handling adapter and apply in to the editor component of value 961 * autocompletion box. 962 * @param autocomplete Manager handling the autocompletion 963 * @param comparator Class to decide what values are offered on autocompletion 964 * @return The created adapter 965 */ 966 protected FocusAdapter addFocusAdapter(final AutoCompletionManager autocomplete, final Comparator<AutoCompletionListItem> comparator) { 967 // get the combo box' editor component 968 JTextComponent editor = (JTextComponent) values.getEditor().getEditorComponent(); 969 // Refresh the values model when focus is gained 970 FocusAdapter focus = new FocusAdapter() { 971 @Override 972 public void focusGained(FocusEvent e) { 973 String key = keys.getEditor().getItem().toString(); 974 975 List<AutoCompletionListItem> valueList = autocomplete.getValues(getAutocompletionKeys(key)); 976 Collections.sort(valueList, comparator); 977 978 values.setPossibleACItems(valueList); 979 values.getEditor().selectAll(); 980 } 981 }; 982 editor.addFocusListener(focus); 983 return focus; 984 } 985 986 protected JPopupMenu popupMenu = new JPopupMenu() { 987 JCheckBoxMenuItem fixTagLanguageCb = new JCheckBoxMenuItem( 988 new AbstractAction(tr("Use English language for tag by default")) { 989 @Override 990 public void actionPerformed(ActionEvent e) { 991 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 992 PROPERTY_FIX_TAG_LOCALE.put(sel); 993 } 994 }); 995 { 996 add(fixTagLanguageCb); 997 fixTagLanguageCb.setState(PROPERTY_FIX_TAG_LOCALE.get()); 998 } 999 }; 1000 } 1001 1002 class ModelSettingsDialog extends JPanel { 1003 1004 private final JLabel chooseModelLabel; 1005 private final JButton chooseModelButton; 1006 private final JTextField chooseModelTextField; 1007 1008 private final DefaultListModel<String> combinationDefaultListModel = new DefaultListModel<>(); 1009 private final JList<String> modelCombinationList = new JList<>(combinationDefaultListModel); 1010 private final JPanel modelCombinationPanel; 1011 private final JPanel weightsPanel; 1012 private final JCheckBox useModelCombinationCheckbox; 1013 private final JButton acceptWeightsButton; 1014 private final JButton resetWeightsButton; 1015 private final JButton removeSelectedModelButton; 1016 private Map<JTextField, String> weightFieldsAndPaths = new HashMap<>(); 1017 private final Map<String, Double> normalizedPathsAndWeights = new HashMap<>(); 1018 private final JOptionPane pane; 1019 private final JDialog dlg; 1020 private final JPanel mainPanel; 1021 private final JPanel singleSelectionPanel; 1022 private final JPanel setResetWeightsPanel; 1023 private final JScrollPane combinationScrollPane; 1024 private final JScrollPane singleSelectionScrollPane; 1025 private final TitledBorder modelTitle; 1026 private final TitledBorder weightTitle; 1027 private final TitledBorder combineTitle; 1028 private final Dimension singleSelectionDimension; 1029 private final Dimension modelCombinationDimension; 1030 private final Dimension mainPanelDimension; 1031 1032 ModelSettingsDialog(Collection<OsmPrimitive> sel1, final AddTagsDialog addDialog) { 1033 1034 loadPreviousCombinedSVMModel(); 1035 singleSelectionDimension = new Dimension(470, 70); 1036 modelCombinationDimension = new Dimension(450, 250); 1037 mainPanelDimension = new Dimension(600, 350); 1038 1039 //------- <NORTH of main> ---------// 1040 mainPanel = new JPanel(new BorderLayout(10, 10)); 1041 singleSelectionPanel = new JPanel(new BorderLayout(10, 10)); 1042 setResetWeightsPanel = new JPanel(); 1043 1044 chooseModelLabel = new JLabel("Choose a Model:"); 1045 chooseModelTextField = new JTextField(); 1046 chooseModelButton = new JButton("..."); 1047 chooseModelTextField.setText(MODEL_PATH); 1048 1049 singleSelectionPanel.add(chooseModelLabel, BorderLayout.NORTH); 1050 singleSelectionPanel.add(chooseModelTextField, BorderLayout.WEST); 1051 singleSelectionPanel.add(chooseModelButton, BorderLayout.EAST); 1052 1053 singleSelectionScrollPane = new JScrollPane(singleSelectionPanel); 1054 singleSelectionScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 1055 singleSelectionScrollPane.setPreferredSize(singleSelectionDimension); 1056 1057 //------- </NORTH of main> ---------// 1058 1059 //------- <WEST of main> ---------// 1060 modelCombinationList.setFixedCellHeight(20); 1061 modelCombinationList.setEnabled(false); 1062 modelCombinationPanel = new JPanel(new BorderLayout(10, 10)); 1063 1064 weightsPanel = new JPanel(); 1065 weightsPanel.setLayout(new BoxLayout(weightsPanel, BoxLayout.Y_AXIS)); 1066 weightsPanel.setEnabled(false); 1067 1068 1069 acceptWeightsButton = new JButton("Set Weights/Normalize"); 1070 resetWeightsButton = new JButton("Reset Weights"); 1071 removeSelectedModelButton = new JButton("Remove Selected"); 1072 setResetWeightsPanel.add(acceptWeightsButton); 1073 setResetWeightsPanel.add(resetWeightsButton); 1074 setResetWeightsPanel.add(removeSelectedModelButton); 1075 removeSelectedModelButton.setEnabled(false); 1076 acceptWeightsButton.setEnabled(false); 1077 resetWeightsButton.setEnabled(false); 1078 1079 modelCombinationPanel.add(modelCombinationList, BorderLayout.CENTER); 1080 modelCombinationPanel.add(weightsPanel, BorderLayout.EAST); 1081 modelCombinationPanel.add(setResetWeightsPanel, BorderLayout.SOUTH); 1082 1083 combinationScrollPane = new JScrollPane(modelCombinationPanel); 1084 1085 combinationScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 1086 combinationScrollPane.setPreferredSize(modelCombinationDimension); //new Dimension(450, 250) // w/h 1087 1088 //------- </WEST of main> ---------// 1089 1090 //------- <SOUTH of main> ---------// 1091 useModelCombinationCheckbox = new JCheckBox("Combine different models?"); 1092 1093 //------- </SOUTH of main> ---------// 1094 1095 //------- <Borders> ---------// 1096 modelTitle = BorderFactory.createTitledBorder("Models"); 1097 weightTitle = BorderFactory.createTitledBorder("W"); 1098 combineTitle = BorderFactory.createTitledBorder("Combine Models"); 1099 modelCombinationList.setBorder(modelTitle); 1100 weightsPanel.setBorder(weightTitle); 1101 1102 for (Entry<JTextField, String> entry : weightFieldsAndPaths.entrySet()) { 1103 combinationDefaultListModel.addElement(entry.getValue()); 1104 1105 JTextField weightTextField = new JTextField("0.00"); 1106 weightTextField.setMaximumSize(new Dimension(80, 20)); 1107 weightsPanel.add(entry.getKey()); 1108 } 1109 1110 //modelCombinationPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1111 modelCombinationPanel.setBorder(combineTitle); 1112 singleSelectionPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1113 //------- </Borders> ---------// 1114 1115 chooseModelButton.addActionListener(new java.awt.event.ActionListener() { 1116 @Override 1117 public void actionPerformed(java.awt.event.ActionEvent evt) { 1118 modelChooserButtonActionPerformed(evt); 1119 } 1120 }); 1121 1122 useModelCombinationCheckbox.addActionListener(new java.awt.event.ActionListener() { 1123 @Override 1124 public void actionPerformed(java.awt.event.ActionEvent evt) { 1125 userCombinationCheckboxActionPerformed(evt); 1126 } 1127 }); 1128 1129 acceptWeightsButton.addActionListener(new java.awt.event.ActionListener() { 1130 @Override 1131 public void actionPerformed(java.awt.event.ActionEvent evt) { 1132 acceptWeightsButtonActionPerformed(evt); 1133 } 1134 }); 1135 1136 resetWeightsButton.addActionListener(new java.awt.event.ActionListener() { 1137 @Override 1138 public void actionPerformed(java.awt.event.ActionEvent evt) { 1139 resetWeightsButtonActionPerformed(evt); 1140 } 1141 }); 1142 1143 removeSelectedModelButton.addActionListener(new java.awt.event.ActionListener() { 1144 @Override 1145 public void actionPerformed(java.awt.event.ActionEvent evt) { 1146 removeSelectedModelButtonActionPerformed(evt); 1147 } 1148 }); 1149 mainPanel.add(singleSelectionScrollPane, BorderLayout.NORTH); 1150 mainPanel.add(combinationScrollPane, BorderLayout.CENTER); 1151 mainPanel.add(useModelCombinationCheckbox, BorderLayout.SOUTH); 1152 1153 mainPanel.setPreferredSize(mainPanelDimension); 1154 1155 this.add(mainPanel); 1156 1157 pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION) { 1158 @Override 1159 public void setValue(Object newValue) { 1160 super.setValue(newValue); 1161 if (newValue instanceof Integer && (int) newValue == 0 && useModelCombinationCheckbox.isSelected()) { 1162 System.out.println("model settings button value: " + newValue); 1163 System.out.println("\nUSE COMBINED MODEL\n"); 1164 useCombinedModel = true; 1165 useCustomSVMModel = false; 1166 1167 addDialog.loadSVMmodel(); 1168 addDialog.createOSMObject(sel); 1169 saveCombinedModel(); 1170 dlg.setVisible(false); 1171 } else if (newValue instanceof Integer && (int) newValue == -1 && useModelCombinationCheckbox.isSelected()) { 1172 System.out.println("model settings button value: " + newValue); 1173 useCombinedModel = false; 1174 useCustomSVMModel = false; 1175 System.out.println("Use combined model"); 1176 1177 addDialog.loadSVMmodel(); 1178 addDialog.createOSMObject(sel); 1179 dlg.setVisible(false); 1180 } else if (newValue instanceof Integer && (int) newValue == 0 && !useModelCombinationCheckbox.isSelected()) { 1181 System.out.println("model settings button value: " + newValue); 1182 System.out.println("Don t use combined model, use custom model"); 1183 useCombinedModel = false; 1184 useCustomSVMModel = true; 1185 addDialog.loadSVMmodel(); 1186 addDialog.createOSMObject(sel); 1187 dlg.setVisible(false); 1188 } else if (newValue instanceof Integer && (int) newValue == -1 && !useModelCombinationCheckbox.isSelected()) { 1189 System.out.println("model settings button value: " + newValue); 1190 System.out.println("Don t use combined model, use custom model"); 1191 useCombinedModel = false; 1192 useCustomSVMModel = false; 1193 addDialog.loadSVMmodel(); 1194 addDialog.createOSMObject(sel); 1195 dlg.setVisible(false); 1196 } else if (newValue == null || newValue.equals("uninitializedValue")) { 1197 System.out.println("uninitializedValue, do nothing"); 1198 } 1199 } 1200 }; 1201 1202 dlg = pane.createDialog(Main.parent, tr("Model Settings")); 1203 dlg.setVisible(true); 1204 } 1205 1206 public void makeVisible(boolean visible) { 1207 dlg.setVisible(true); 1208 } 1209 1210 private void modelChooserButtonActionPerformed(ActionEvent evt) { 1211 1212 try { 1213 final File file = new File(chooseModelTextField.getText()); 1214 final JFileChooser fileChooser = new JFileChooser(file); 1215 1216 final int returnVal = fileChooser.showOpenDialog(this); 1217 if (returnVal == JFileChooser.APPROVE_OPTION) { 1218 chooseModelTextField.setText(fileChooser.getSelectedFile().getAbsolutePath()); 1219 useCustomSVMModel = true; 1220 customSVMModelPath = fileChooser.getSelectedFile().getAbsolutePath(); 1221 } 1222 1223 if (useModelCombinationCheckbox.isSelected()) { 1224 String svmModelPath = fileChooser.getSelectedFile().getAbsolutePath(); 1225 String svmModelText; 1226 if (System.getProperty("os.name").contains("ux")) { 1227 if (svmModelPath.contains("/")) { 1228 svmModelText = svmModelPath.substring(svmModelPath.lastIndexOf("/")); 1229 } else { 1230 svmModelText = svmModelPath; 1231 } 1232 } else { 1233 if (svmModelPath.contains("\\")) { 1234 svmModelText = svmModelPath.substring(svmModelPath.lastIndexOf("\\")); 1235 } else { 1236 svmModelText = svmModelPath; 1237 } 1238 } 1239 combinationDefaultListModel.addElement(svmModelText); 1240 JTextField weightTextField = new JTextField("0.00"); 1241 weightFieldsAndPaths.put(weightTextField, svmModelPath); 1242 System.out.println("weights size: " + weightFieldsAndPaths.size()); 1243 1244 weightTextField.setMaximumSize(new Dimension(80, 20)); 1245 weightsPanel.add(weightTextField); 1246 //add additional textbox 1247 } 1248 } catch (RuntimeException ex) { 1249 Logging.warn(ex); 1250 } 1251 } 1252 1253 private void userCombinationCheckboxActionPerformed(java.awt.event.ActionEvent evt) { 1254 1255 if (useModelCombinationCheckbox.isSelected()) { 1256 useCombinedModel = true; 1257 useCustomSVMModel = false; //reseting the selected custom SVM model only here 1258 removeSelectedModelButton.setEnabled(true); 1259 acceptWeightsButton.setEnabled(true); 1260 resetWeightsButton.setEnabled(true); 1261 1262 chooseModelTextField.setEnabled(false); 1263 modelCombinationList.setEnabled(true); 1264 weightsPanel.setEnabled(true); 1265 Component[] weightPanelComponents = weightsPanel.getComponents(); 1266 for (Component weightPanelComponent : weightPanelComponents) { 1267 weightPanelComponent.setEnabled(true); 1268 } 1269 } else { 1270 useCombinedModel = false; 1271 useCustomSVMModel = true; 1272 removeSelectedModelButton.setEnabled(false); 1273 acceptWeightsButton.setEnabled(false); 1274 resetWeightsButton.setEnabled(false); 1275 1276 chooseModelTextField.setEnabled(true); 1277 modelCombinationList.setEnabled(false); 1278 weightsPanel.setEnabled(false); 1279 Component[] weightPanelComponents = weightsPanel.getComponents(); 1280 for (Component weightPanelComponent : weightPanelComponents) { 1281 weightPanelComponent.setEnabled(false); 1282 } 1283 } 1284 } 1285 1286 private void acceptWeightsButtonActionPerformed(ActionEvent evt) { 1287 int weightsCount = 0; 1288 removeSelectedModelButton.setEnabled(false); 1289 double weightSum = 0; 1290 for (JTextField weightField : weightFieldsAndPaths.keySet()) { 1291 if (weightField.getText().equals("")) { 1292 weightField.setText("0.00"); 1293 } 1294 1295 try { 1296 //TODO replace "," with "." to parse doubles with commas 1297 Double weightValue = Double.parseDouble(weightField.getText()); 1298 1299 weightValue = Math.abs(weightValue); 1300 weightSum += weightValue; 1301 } catch (NumberFormatException ex) { 1302 Logging.warn(ex); 1303 } 1304 weightsCount++; 1305 } 1306 1307 if (!filesAndWeights.isEmpty()) { 1308 filesAndWeights.clear(); 1309 } 1310 1311 for (JTextField weightField : weightFieldsAndPaths.keySet()) { 1312 try { 1313 Double weightValue = Double.parseDouble(weightField.getText()); 1314 1315 weightValue = Math.abs(weightValue)/weightSum; //normalize 1316 1317 if (weightSum == 0) { 1318 weightValue = 1.0/weightsCount; 1319 } 1320 1321 weightField.setText(new DecimalFormat("#.##").format(weightValue)); 1322 normalizedPathsAndWeights.put(weightFieldsAndPaths.get(weightField), weightValue); 1323 filesAndWeights.put(new File(weightFieldsAndPaths.get(weightField)), weightValue); 1324 System.out.println("normalized: " + weightFieldsAndPaths.get(weightField) + "->" + weightValue); 1325 weightField.setEnabled(false); 1326 1327 } catch (NumberFormatException ex) { 1328 Logging.warn(ex); 1329 } 1330 } 1331 1332 useCombinedModel = true; 1333 useCustomSVMModel = false; 1334 } 1335 1336 private void resetWeightsButtonActionPerformed(ActionEvent evt) { 1337 removeSelectedModelButton.setEnabled(true); 1338 for (JTextField weightField : weightFieldsAndPaths.keySet()) { 1339 weightField.setEnabled(true); 1340 } 1341 } 1342 1343 private void removeSelectedModelButtonActionPerformed(ActionEvent evt) { 1344 int index = modelCombinationList.getSelectedIndex(); 1345 String modelToBeRemoved = combinationDefaultListModel.get(index); 1346 combinationDefaultListModel.remove(index); 1347 System.out.println("model to be removed: " + modelToBeRemoved); 1348 1349 Iterator<Entry<JTextField, String>> it = weightFieldsAndPaths.entrySet().iterator(); 1350 while (it.hasNext()) { 1351 Entry<JTextField, String> en = it.next(); 1352 if (en.getValue().equals(modelToBeRemoved)) { 1353 it.remove(); 1354 } 1355 } 1356 System.out.println("model to be removed: " + modelToBeRemoved); 1357 1358 weightsPanel.remove(index); 1359 weightsPanel.revalidate(); 1360 weightsPanel.repaint(); 1361 } 1362 1363 @SuppressWarnings("unchecked") 1364 private void loadPreviousCombinedSVMModel() { 1365 File combinedModelClassesFile = new File(combinedModelClasses); 1366 1367 if (combinedModelClassesFile.exists()) { 1368 FileInputStream fileIn = null; 1369 ObjectInputStream in = null; 1370 try { 1371 fileIn = new FileInputStream(combinedModelClassesFile); 1372 in = new ObjectInputStream(fileIn); 1373 weightFieldsAndPaths = (Map<JTextField, String>) in.readObject(); 1374 } catch (FileNotFoundException ex) { 1375 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 1376 } catch (IOException | ClassNotFoundException ex) { 1377 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 1378 } finally { 1379 try { 1380 if (in != null) { 1381 in.close(); 1382 } 1383 if (fileIn != null) { 1384 fileIn.close(); 1385 } 1386 1387 } catch (IOException ex) { 1388 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 1389 } 1390 } 1391 } else { 1392 try { 1393 combinedModelClassesFile.createNewFile(); 1394 } catch (IOException ex) { 1395 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 1396 } 1397 } 1398 } 1399 1400 private void saveCombinedModel() { 1401 try (FileOutputStream fileOut = new FileOutputStream(combinedModelClasses); 1402 ObjectOutputStream out = new ObjectOutputStream(fileOut)) { 1403 out.writeObject(weightFieldsAndPaths); 1404 } catch (IOException e) { 1405 System.out.println("serialize error" + e); 1406 } 1407 } 1408 } 1409 1410 class AddTagsDialog extends AbstractTagsDialog { 1411 List<JosmAction> recentTagsActions = new ArrayList<>(); 1412 1413 // Counter of added commands for possible undo 1414 private int commandCount; 1415 private final JLabel recommendedClassesLabel; 1416 private final JButton modelSettingsButton; 1417 private final JButton addAndContinueButton; 1418 private final DefaultListModel<String> model; 1419 private final JList<String> categoryList; 1420 private Model modelSVM; 1421 private int modelSVMLabelSize; 1422 private int[] modelSVMLabels; 1423 private Map<String, String> mappings; 1424 private Map<String, Integer> mapperWithIDs; 1425 private Map<Integer, String> idsWithMappings; 1426 private List<String> textualList = new ArrayList<>(); 1427 private final JCheckBox useTagsCheckBox; 1428 private ModelSettingsDialog modelSettingsDialog; 1429 private static final int RECOMMENDATIONS_SIZE = 10; 1430 1431 AddTagsDialog() { 1432 super(Main.parent, tr("Add value?"), new String[] {tr("OK"), tr("Cancel")}); 1433 setButtonIcons(new String[] {"ok", "cancel"}); 1434 setCancelButton(2); 1435 configureContextsensitiveHelp("/Dialog/AddValue", true /* show help button */); 1436 final AddTagsDialog addTagsDialog = this; 1437 1438 loadOntology(); 1439 //if the user did not train a model by running the training process 1440 //the list does not exist in a file and so we load the default list from the jar. 1441 1442 System.out.println("path for textual: " + TEXTUAL_LIST_PATH); 1443 File textualListFile = new File(TEXTUAL_LIST_PATH); 1444 if (textualListFile.exists()) { 1445 loadTextualList(textualListFile); 1446 } else { 1447 loadDefaultTextualList(); 1448 } 1449 1450 //if training process has not been performed, we use two sample SVM models, extracted from the jar 1451 1452 JPanel splitPanel = new JPanel(new BorderLayout(10, 10)); 1453 JPanel mainPanel = new JPanel(new GridBagLayout()); //original panel, will be wrapped by the splitPanel 1454 JPanel recommendPanel = new JPanel(new BorderLayout(10, 10)); //will contain listPanel, action panel 1455 JPanel listPanel = new JPanel(new BorderLayout(10, 10)); //class recommend label, recommendation list 1456 JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); //model selection buttons or configuration 1457 1458 addAndContinueButton = new JButton("Add and continue"); 1459 modelSettingsButton = new JButton("Model Settings"); 1460 useTagsCheckBox = new JCheckBox("Predict using tags"); 1461 recommendedClassesLabel = new JLabel("Recommended Classes:"); 1462 1463 addAndContinueButton.addActionListener(new java.awt.event.ActionListener() { 1464 @Override 1465 public void actionPerformed(java.awt.event.ActionEvent evt) { 1466 String selectedClass = categoryList.getSelectedValue(); 1467 addAndContinueButtonActionPerformed(evt, selectedClass); 1468 1469 //reconstruct vector for instance and use the model that was trained with classes here 1470 1471 List<OsmPrimitive> osmPrimitiveSelection = new ArrayList<>(sel); 1472 OsmPrimitive s; 1473 1474 //get a simple selection 1475 if (!osmPrimitiveSelection.isEmpty()) { 1476 s = osmPrimitiveSelection.get(0); 1477 if (s.getInterestingTags().isEmpty()) { 1478 //load original model 1479 modelWithClasses = false; 1480 loadSVMmodel(); 1481 createOSMObject(sel); //create object without class features 1482 } else { 1483 //recommend using tags: set the checkbox selected to avoid confusing the user 1484 useTagsCheckBox.setSelected(true); 1485 1486 if (useTagsCheckBox.isSelected()) { 1487 //load model with classes 1488 modelWithClasses = true; 1489 loadSVMmodel(); 1490 createOSMObject(sel); //create object including class features 1491 } else { 1492 modelWithClasses = false; 1493 loadSVMmodel(); 1494 createOSMObject(sel); //create object including class features 1495 } 1496 } 1497 } 1498 } 1499 }); 1500 1501 modelSettingsButton.addActionListener(new java.awt.event.ActionListener() { 1502 @Override 1503 public void actionPerformed(java.awt.event.ActionEvent evt) { 1504 if (modelSettingsDialog == null) { 1505 System.out.println("new modelSettingsDialog"); 1506 modelSettingsDialog = new ModelSettingsDialog(sel, addTagsDialog); 1507 } else { 1508 System.out.println("set modelSettingsDialog visible"); 1509 modelSettingsDialog.makeVisible(true); 1510 } 1511 } 1512 }); 1513 1514 useTagsCheckBox.addActionListener(new java.awt.event.ActionListener() { 1515 @Override 1516 public void actionPerformed(java.awt.event.ActionEvent evt) { 1517 List<OsmPrimitive> osmPrimitiveSelection = new ArrayList<>(sel); 1518 OsmPrimitive s; 1519 if (!osmPrimitiveSelection.isEmpty()) { 1520 s = osmPrimitiveSelection.get(0); 1521 if (s.getInterestingTags().isEmpty()) { 1522 //load original model 1523 modelWithClasses = false; 1524 loadSVMmodel(); 1525 createOSMObject(sel); //create object without class features 1526 } else { 1527 //useTagsCheckBox 1528 if (useTagsCheckBox.isSelected()) { 1529 //load model with classes 1530 modelWithClasses = true; 1531 loadSVMmodel(); 1532 createOSMObject(sel); //create object including class features 1533 } else { 1534 modelWithClasses = false; 1535 loadSVMmodel(); 1536 createOSMObject(sel); //create object including class features 1537 } 1538 } 1539 } 1540 } 1541 }); 1542 1543 keys = new AutoCompletingComboBox(); 1544 values = new AutoCompletingComboBox(); 1545 1546 mainPanel.add(new JLabel("<html>"+trn("This will change up to {0} object.", 1547 "This will change up to {0} objects.", sel.size(), sel.size()) 1548 +"<br><br>"+tr("Please select a key")), GBC.eol().fill(GBC.HORIZONTAL)); 1549 1550 AutoCompletionManager autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager(); 1551 List<AutoCompletionListItem> keyList = autocomplete.getKeys(); 1552 1553 AutoCompletionListItem itemToSelect = null; 1554 // remove the object's tag keys from the list 1555 Iterator<AutoCompletionListItem> iter = keyList.iterator(); 1556 while (iter.hasNext()) { 1557 AutoCompletionListItem item = iter.next(); 1558 if (item.getValue().equals(lastAddKey)) { 1559 itemToSelect = item; 1560 } 1561 for (int i = 0; i < tagData.getRowCount(); ++i) { 1562 if (item.getValue().equals(tagData.getValueAt(i, 0))) { 1563 if (itemToSelect == item) { 1564 itemToSelect = null; 1565 } 1566 iter.remove(); 1567 break; 1568 } 1569 } 1570 } 1571 1572 Collections.sort(keyList, defaultACItemComparator); 1573 keys.setPossibleACItems(keyList); 1574 keys.setEditable(true); 1575 1576 mainPanel.add(keys, GBC.eop().fill()); 1577 mainPanel.add(new JLabel(tr("Please select a value")), GBC.eol()); 1578 1579 model = new DefaultListModel<>(); 1580 1581 parseTagsMappedToClasses(); 1582 1583 List<OsmPrimitive> osmPrimitiveSelection = new ArrayList<>(sel); 1584 OsmPrimitive s; 1585 //get a simple selection 1586 if (!osmPrimitiveSelection.isEmpty()) { 1587 s = osmPrimitiveSelection.get(0); 1588 File modelDirectory = new File(MODEL_PATH); 1589 String modelWithClassesPath = modelDirectory.getAbsolutePath() + "/model_with_classes"; 1590 File modelWithClassesFile = new File(modelWithClassesPath); 1591 if (s.getInterestingTags().isEmpty() || !modelWithClassesFile.exists()) { 1592 modelWithClasses = false; 1593 loadSVMmodel(); //load original model 1594 createOSMObject(sel); //create object without class features 1595 } else { 1596 //recommend using tags: set the checkbox selected to avoid confusing the user 1597 useTagsCheckBox.setSelected(true); 1598 modelWithClasses = true; 1599 loadSVMmodel(); //load model with classes 1600 createOSMObject(sel); //create object including class features 1601 } 1602 } 1603 1604 categoryList = new JList<>(model); 1605 1606 ListSelectionListener listSelectionListener = new ListSelectionListener() { 1607 @Override 1608 public void valueChanged(ListSelectionEvent listSelectionEvent) { 1609 if (!listSelectionEvent.getValueIsAdjusting()) { //This prevents double events 1610 1611 String selectedClass = categoryList.getSelectedValue(); 1612 1613 if (selectedClass != null) { //null check, because the model is cleared after a new recommendation 1614 //tags become unselected 1615 if ((selectedClass.indexOf(" ")+1) > 0) { 1616 //add both key + value in tags 1617 String keyTag = selectedClass.substring(0, selectedClass.indexOf(" ")); 1618 String valueTag = selectedClass.substring(selectedClass.indexOf(" ")+1, selectedClass.length()); 1619 keys.setSelectedItem(keyTag); //adding selected tags to textBoxes 1620 values.setSelectedItem(valueTag); 1621 } else { 1622 //value does not have a value, add the key tag only 1623 String keyTag = selectedClass; //test it 1624 keys.setSelectedItem(keyTag); 1625 values.setSelectedItem(""); 1626 } 1627 } 1628 } 1629 } 1630 }; 1631 1632 categoryList.addListSelectionListener(listSelectionListener); 1633 categoryList.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1634 categoryList.setModel(model); 1635 1636 values.setEditable(true); 1637 mainPanel.add(values, GBC.eop().fill()); 1638 if (itemToSelect != null) { 1639 keys.setSelectedItem(itemToSelect); 1640 if (lastAddValue != null) { 1641 values.setSelectedItem(lastAddValue); 1642 } 1643 } 1644 1645 FocusAdapter focus = addFocusAdapter(autocomplete, defaultACItemComparator); 1646 // fire focus event in advance or otherwise the popup list will be too small at first 1647 focus.focusGained(null); 1648 1649 int recentTagsToShow = PROPERTY_RECENT_TAGS_NUMBER.get(); 1650 if (recentTagsToShow > MAX_LRU_TAGS_NUMBER) { 1651 recentTagsToShow = MAX_LRU_TAGS_NUMBER; 1652 } 1653 1654 suggestRecentlyAddedTags(mainPanel, recentTagsToShow, focus); 1655 1656 mainPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1657 listPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1658 splitPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED, Color.GRAY, Color.WHITE)); 1659 1660 listPanel.add(recommendedClassesLabel, BorderLayout.NORTH); 1661 listPanel.add(categoryList, BorderLayout.SOUTH); 1662 actionsPanel.add(addAndContinueButton); 1663 actionsPanel.add(modelSettingsButton); 1664 actionsPanel.add(useTagsCheckBox); 1665 1666 recommendPanel.add(actionsPanel, BorderLayout.WEST); 1667 recommendPanel.add(listPanel, BorderLayout.NORTH); 1668 1669 splitPanel.add(mainPanel, BorderLayout.WEST); 1670 splitPanel.add(recommendPanel, BorderLayout.EAST); 1671 1672 setContent(splitPanel, false); 1673 1674 popupMenu.add(new AbstractAction(tr("Set number of recently added tags")) { 1675 @Override 1676 public void actionPerformed(ActionEvent e) { 1677 selectNumberOfTags(); 1678 } 1679 }); 1680 JCheckBoxMenuItem rememberLastTags = new JCheckBoxMenuItem( 1681 new AbstractAction(tr("Remember last used tags after a restart")) { 1682 @Override 1683 public void actionPerformed(ActionEvent e) { 1684 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 1685 PROPERTY_REMEMBER_TAGS.put(sel); 1686 if (sel) saveTagsIfNeeded(); 1687 } 1688 }); 1689 rememberLastTags.setState(PROPERTY_REMEMBER_TAGS.get()); 1690 popupMenu.add(rememberLastTags); 1691 } 1692 1693 private void addAndContinueButtonActionPerformed(ActionEvent evt, String selectedClass) { 1694 performTagAdding(); 1695 } 1696 1697 private void selectNumberOfTags() { 1698 String s = JOptionPane.showInputDialog(this, tr("Please enter the number of recently added tags to display")); 1699 if (s != null) try { 1700 int v = Integer.parseInt(s); 1701 if (v >= 0 && v <= MAX_LRU_TAGS_NUMBER) { 1702 PROPERTY_RECENT_TAGS_NUMBER.put(v); 1703 return; 1704 } 1705 } catch (NumberFormatException ex) { 1706 Logging.warn(ex); 1707 } 1708 JOptionPane.showMessageDialog(this, tr("Please enter integer number between 0 and {0}", MAX_LRU_TAGS_NUMBER)); 1709 } 1710 1711 private void suggestRecentlyAddedTags(JPanel mainPanel, int tagsToShow, final FocusAdapter focus) { 1712 if (!(tagsToShow > 0 && !recentTags.isEmpty())) 1713 return; 1714 1715 mainPanel.add(new JLabel(tr("Recently added tags")), GBC.eol()); 1716 1717 int count = 1; 1718 // We store the maximum number (9) of recent tags to allow dynamic change of number of tags shown in the preferences. 1719 // This implies to iterate in descending order, 1720 // as the oldest elements will only be removed after we reach the maximum numbern and not the number of tags to show. 1721 // However, as Set does not allow to iterate in descending order, 1722 // we need to copy its elements into a List we can access in reverse order. 1723 List<Tag> tags = new LinkedList<>(recentTags.keySet()); 1724 for (int i = tags.size()-1; i >= 0 && count <= tagsToShow; i--, count++) { 1725 final Tag t = tags.get(i); 1726 // Create action for reusing the tag, with keyboard shortcut Ctrl+(1-5) 1727 String scKey = "properties:recent:"+count; 1728 String scsKey = "properties:recent:shift:"+count; 1729 Shortcut sc = Shortcut.registerShortcut(scKey, tr("Choose recent tag {0}", count), KeyEvent.VK_0+count, Shortcut.CTRL); 1730 final JosmAction action = new JosmAction(scKey, null, tr("Use this tag again"), sc, false) { 1731 @Override 1732 public void actionPerformed(ActionEvent e) { 1733 keys.setSelectedItem(t.getKey()); 1734 // fix #7951, #8298 - update list of values before setting value (?) 1735 focus.focusGained(null); 1736 values.setSelectedItem(t.getValue()); 1737 } 1738 }; 1739 Shortcut scs = Shortcut.registerShortcut(scsKey, tr("Apply recent tag {0}", count), KeyEvent.VK_0+count, Shortcut.CTRL_SHIFT); 1740 final JosmAction actionShift = new JosmAction(scsKey, null, tr("Use this tag again"), scs, false) { 1741 @Override 1742 public void actionPerformed(ActionEvent e) { 1743 action.actionPerformed(null); 1744 performTagAdding(); 1745 } 1746 }; 1747 recentTagsActions.add(action); 1748 recentTagsActions.add(actionShift); 1749 disableTagIfNeeded(t, action); 1750 // Find and display icon 1751 ImageIcon icon = MapPaintStyles.getNodeIcon(t, false); // Filters deprecated icon 1752 if (icon == null) { 1753 // If no icon found in map style look at presets 1754 Map<String, String> map = new HashMap<>(); 1755 map.put(t.getKey(), t.getValue()); 1756 // If still nothing display an empty icon 1757 if (icon == null) { 1758 icon = new ImageIcon(new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB)); 1759 } 1760 } 1761 GridBagConstraints gbc = new GridBagConstraints(); 1762 gbc.ipadx = 5; 1763 mainPanel.add(new JLabel(action.isEnabled() ? icon : GuiHelper.getDisabledIcon(icon)), gbc); 1764 // Create tag label 1765 final String color = action.isEnabled() ? "" : "; color:gray"; 1766 final JLabel tagLabel = new JLabel("<html>" 1767 + "<style>td{border:1px solid gray; font-weight:normal"+color+"}</style>" 1768 + "<table><tr><td>" + XmlWriter.encode(t.toString(), true) + "</td></tr></table></html>"); 1769 if (action.isEnabled()) { 1770 // Register action 1771 mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), scKey); 1772 mainPanel.getActionMap().put(scKey, action); 1773 mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(scs.getKeyStroke(), scsKey); 1774 mainPanel.getActionMap().put(scsKey, actionShift); 1775 // Make the tag label clickable and set tooltip to the action description (this displays also the keyboard shortcut) 1776 tagLabel.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION)); 1777 tagLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); 1778 tagLabel.addMouseListener(new MouseAdapter() { 1779 @Override 1780 public void mouseClicked(MouseEvent e) { 1781 action.actionPerformed(null); 1782 // add tags and close window on double-click 1783 1784 if (e.getClickCount() > 1) { 1785 buttonAction(0, null); // emulate OK click and close the dialog 1786 } 1787 // add tags on Shift-Click 1788 if (e.isShiftDown()) { 1789 performTagAdding(); 1790 } 1791 } 1792 }); 1793 } else { 1794 // Disable tag label 1795 tagLabel.setEnabled(false); 1796 // Explain in the tooltip why 1797 tagLabel.setToolTipText(tr("The key ''{0}'' is already used", t.getKey())); 1798 } 1799 // Finally add label to the resulting panel 1800 JPanel tagPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); 1801 tagPanel.add(tagLabel); 1802 mainPanel.add(tagPanel, GBC.eol().fill(GBC.HORIZONTAL)); 1803 } 1804 } 1805 1806 public void destroyActions() { 1807 for (JosmAction action : recentTagsActions) { 1808 action.destroy(); 1809 } 1810 } 1811 1812 /** 1813 * Read tags from comboboxes and add it to all selected objects 1814 */ 1815 public final void performTagAdding() { 1816 String key = Tag.removeWhiteSpaces(keys.getEditor().getItem().toString()); 1817 String value = Tag.removeWhiteSpaces(values.getEditor().getItem().toString()); 1818 if (key.isEmpty() || value.isEmpty()) return; 1819 for (OsmPrimitive osm: sel) { 1820 String val = osm.get(key); 1821 if (val != null && !val.equals(value)) { 1822 if (!warnOverwriteKey(tr("You changed the value of ''{0}'' from ''{1}'' to ''{2}''.", key, val, value), 1823 "overwriteAddKey")) 1824 return; 1825 break; 1826 } 1827 } 1828 lastAddKey = key; 1829 lastAddValue = value; 1830 recentTags.put(new Tag(key, value), null); 1831 AutoCompletionManager.rememberUserInput(key, value, false); 1832 commandCount++; 1833 MainApplication.undoRedo.add(new ChangePropertyCommand(sel, key, value)); 1834 changedKey = key; 1835 } 1836 1837 public void undoAllTagsAdding() { 1838 MainApplication.undoRedo.undo(commandCount); 1839 } 1840 1841 private void disableTagIfNeeded(final Tag t, final JosmAction action) { 1842 // Disable action if its key is already set on the object (the key being absent from the keys list for this reason 1843 // performing this action leads to autocomplete to the next key (see #7671 comments) 1844 for (int j = 0; j < tagData.getRowCount(); ++j) { 1845 if (t.getKey().equals(tagData.getValueAt(j, 0))) { 1846 action.setEnabled(false); 1847 break; 1848 } 1849 } 1850 } 1851 1852 private void loadSVMmodel() { 1853 File modelDirectory = new File(MODEL_PATH); 1854 File modelFile; 1855 if (useCombinedModel) { 1856 if (filesAndWeights.isEmpty()) { 1857 System.out.println("No models selected! Loading defaults.."); 1858 if (modelWithClasses) { 1859 System.out.println("Using default/last model with classes: " + modelDirectory.getAbsolutePath() + "/model_with_classes"); 1860 modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes"); 1861 try { 1862 System.out.println("try to load model: " + modelFile.getAbsolutePath()); 1863 modelSVM = Model.load(modelFile); 1864 System.out.println("model loaded!"); 1865 1866 } catch (IOException ex) { 1867 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 1868 } 1869 modelSVMLabelSize = modelSVM.getLabels().length; 1870 modelSVMLabels = modelSVM.getLabels(); 1871 } else { 1872 System.out.println("Using default/last model without classes: " + modelDirectory.getAbsolutePath() + "/best_model"); 1873 modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model"); 1874 try { 1875 System.out.println("try to load model: " + modelFile.getAbsolutePath()); 1876 modelSVM = Model.load(modelFile); 1877 System.out.println("model loaded!"); 1878 1879 } catch (IOException ex) { 1880 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 1881 } 1882 modelSVMLabelSize = modelSVM.getLabels().length; 1883 modelSVMLabels = modelSVM.getLabels(); 1884 } 1885 } 1886 if (modelWithClasses) { //check filenames to define if model with classes is selected 1887 System.out.println("Using combined model with classes"); 1888 useCombinedSVMmodels(sel, true); 1889 } else { 1890 System.out.println("Using combined model without classes"); 1891 useCombinedSVMmodels(sel, false); 1892 } 1893 } else if (useCustomSVMModel) { 1894 System.out.println("custom path: " + customSVMModelPath); 1895 File checkExistance = new File(customSVMModelPath); 1896 if (checkExistance.exists() && checkExistance.isFile()) { 1897 if (modelWithClasses) { 1898 System.out.println("Using custom model with classes: "); 1899 if (customSVMModelPath.endsWith(".0")) { 1900 String customSVMModelPathWithClasses = customSVMModelPath.substring(0, customSVMModelPath.length() - 2) + ".1"; 1901 1902 modelFile = new File(customSVMModelPathWithClasses); 1903 System.out.println(customSVMModelPathWithClasses); 1904 } else { 1905 modelFile = new File(customSVMModelPath); 1906 } 1907 } else { 1908 System.out.println("Using custom model without classes"); 1909 if (customSVMModelPath.endsWith(".1")) { 1910 String customSVMModelPathWithoutClasses = customSVMModelPath.substring(0, customSVMModelPath.length() - 2) + ".0"; 1911 modelFile = new File(customSVMModelPathWithoutClasses); 1912 System.out.println(customSVMModelPathWithoutClasses); 1913 } else { 1914 modelFile = new File(customSVMModelPath); 1915 } 1916 } 1917 try { 1918 System.out.println("try to load model: " + modelFile.getAbsolutePath()); 1919 modelSVM = Model.load(modelFile); 1920 System.out.println("model loaded!"); 1921 1922 } catch (IOException ex) { 1923 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 1924 } 1925 modelSVMLabelSize = modelSVM.getLabels().length; 1926 modelSVMLabels = modelSVM.getLabels(); 1927 1928 } else { 1929 //user chose to use a custom model, but did not provide a path to a model: 1930 if (modelWithClasses) { 1931 System.out.println("Using default/last model with classes"); 1932 modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes"); 1933 } else { 1934 System.out.println("Using default/last model without classes"); 1935 modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model"); 1936 } 1937 1938 try { 1939 System.out.println("try to load model: " + modelFile.getAbsolutePath()); 1940 modelSVM = Model.load(modelFile); 1941 System.out.println("model loaded!"); 1942 1943 } catch (IOException ex) { 1944 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 1945 } 1946 modelSVMLabelSize = modelSVM.getLabels().length; 1947 modelSVMLabels = modelSVM.getLabels(); 1948 1949 } 1950 } else { 1951 if (modelWithClasses) { 1952 System.out.println("Using default/last model with classes"); 1953 modelFile = new File(modelDirectory.getAbsolutePath() + "/model_with_classes"); 1954 } else { 1955 System.out.println("Using default/last model without classes"); 1956 modelFile = new File(modelDirectory.getAbsolutePath() + "/best_model"); 1957 } 1958 1959 try { 1960 System.out.println("try to load model: " + modelFile.getAbsolutePath()); 1961 modelSVM = Model.load(modelFile); 1962 System.out.println("model loaded!"); 1963 1964 } catch (IOException ex) { 1965 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 1966 } 1967 modelSVMLabelSize = modelSVM.getLabels().length; 1968 modelSVMLabels = modelSVM.getLabels(); 1969 } 1970 } 1971 1972 private void useCombinedSVMmodels(Collection<OsmPrimitive> sel, boolean useClassFeatures) { 1973 System.out.println("The system will combine " + filesAndWeights.size() + " SVM models."); 1974 1975 MathTransform transform = null; 1976 GeometryFactory geometryFactory = new GeometryFactory(); 1977 CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84; 1978 CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN; 1979 try { 1980 transform = CRS.findMathTransform(sourceCRS, targetCRS, true); 1981 1982 } catch (FactoryException ex) { 1983 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 1984 } 1985 1986 OSMWay selectedInstance; 1987 List<OsmPrimitive> osmPrimitiveSelection = new ArrayList<>(sel); 1988 OsmPrimitive s; 1989 1990 //get a simple selection 1991 if (!osmPrimitiveSelection.isEmpty()) { 1992 s = osmPrimitiveSelection.get(0); 1993 } else { 1994 return; 1995 } 1996 1997 selectedInstance = new OSMWay(); 1998 for (Way selectedWay : s.getDataSet().getSelectedWays()) { 1999 List<Node> selectedWayNodes = selectedWay.getNodes(); 2000 for (Node node : selectedWayNodes) { 2001 node.getCoor(); 2002 if (node.isLatLonKnown()) { 2003 double lat = node.getCoor().lat(); 2004 double lon = node.getCoor().lon(); 2005 2006 Coordinate sourceCoordinate = new Coordinate(lon, lat); 2007 Coordinate targetGeometry = null; 2008 try { 2009 targetGeometry = JTS.transform(sourceCoordinate, null, transform); 2010 } catch (MismatchedDimensionException | TransformException ex) { 2011 Logger.getLogger(OSMParser.class.getName()).log(Level.SEVERE, null, ex); 2012 } 2013 2014 Geometry geom = geometryFactory.createPoint(new Coordinate(targetGeometry)); 2015 selectedInstance.addNodeGeometry(geom); 2016 } 2017 } 2018 } 2019 Geometry fullGeom = geometryFactory.buildGeometry(selectedInstance.getNodeGeometries()); 2020 if ((selectedInstance.getNodeGeometries().size() > 3) && 2021 selectedInstance.getNodeGeometries().get(0).equals(selectedInstance.getNodeGeometries() 2022 .get(selectedInstance.getNodeGeometries().size()-1))) { 2023 //checks if the beginning and ending node are the same and the number of nodes are more than 3. 2024 //the nodes must be more than 3, because jts does not allow a construction of a linear ring with less points. 2025 LinearRing linear = geometryFactory.createLinearRing(fullGeom.getCoordinates()); 2026 Polygon poly = new Polygon(linear, null, geometryFactory); 2027 selectedInstance.setGeometry(poly); 2028 2029 System.out.println("\n\npolygon"); 2030 } else if (selectedInstance.getNodeGeometries().size() > 1) { 2031 //it is an open geometry with more than one nodes, make it linestring 2032 System.out.println("\n\nlinestring"); 2033 LineString lineString = geometryFactory.createLineString(fullGeom.getCoordinates()); 2034 selectedInstance.setGeometry(lineString); 2035 } else { //we assume all the rest geometries are points 2036 System.out.println("\n\npoint"); 2037 Point point = geometryFactory.createPoint(fullGeom.getCoordinate()); 2038 selectedInstance.setGeometry(point); 2039 } 2040 2041 Map<String, String> selectedTags = s.getInterestingTags(); 2042 selectedInstance.setAllTags(selectedTags); 2043 2044 //construct vector 2045 if (selectedInstance != null) { 2046 int id; 2047 2048 OSMClassification classifier = new OSMClassification(); 2049 classifier.calculateClasses(selectedInstance, mappings, mapperWithIDs, indirectClasses, indirectClassesWithIDs); 2050 2051 if (useClassFeatures) { 2052 ClassFeatures classFeatures = new ClassFeatures(); 2053 classFeatures.createClassFeatures(selectedInstance, mappings, mapperWithIDs, indirectClasses, indirectClassesWithIDs); 2054 id = 1422; 2055 } else { 2056 id = 1; 2057 } 2058 2059 GeometryFeatures geometryFeatures = new GeometryFeatures(id); 2060 geometryFeatures.createGeometryFeatures(selectedInstance); 2061 id = geometryFeatures.getLastID(); 2062 TextualFeatures textualFeatures = new TextualFeatures(id, textualList, languageDetector); 2063 textualFeatures.createTextualFeatures(selectedInstance); 2064 2065 List<FeatureNode> featureNodeList = selectedInstance.getFeatureNodeList(); 2066 2067 FeatureNode[] featureNodeArray = new FeatureNode[featureNodeList.size()]; 2068 2069 int i = 0; 2070 for (FeatureNode featureNode : featureNodeList) { 2071 featureNodeArray[i] = featureNode; 2072 i++; 2073 } 2074 FeatureNode[] testInstance2 = featureNodeArray; 2075 2076 //compute prediction list for every model 2077 int[] ranks = new int[10]; 2078 2079 for (int l = 0; l < 10; l++) { 2080 ranks[l] = 10-l; //init from 10 to 1 2081 } 2082 2083 Map<String, Double> scoreMap = new HashMap<>(); 2084 2085 Map<File, Double> alignedFilesAndWeights = getAlignedModels(filesAndWeights); 2086 2087 for (File modelFile : alignedFilesAndWeights.keySet()) { 2088 2089 try { 2090 modelSVM = Model.load(modelFile); 2091 } catch (IOException ex) { 2092 Logger.getLogger(TrainWorker.class.getName()).log(Level.SEVERE, null, ex); 2093 } 2094 modelSVMLabelSize = modelSVM.getLabels().length; 2095 modelSVMLabels = modelSVM.getLabels(); 2096 2097 Map<Integer, Integer> mapLabelsToIDs = new HashMap<>(); 2098 for (int h = 0; h < modelSVMLabelSize; h++) { 2099 mapLabelsToIDs.put(modelSVMLabels[h], h); 2100 } 2101 double[] scores = new double[modelSVMLabelSize]; 2102 Linear.predictValues(modelSVM, testInstance2, scores); 2103 2104 Map<Double, Integer> scoresValues = new HashMap<>(); 2105 for (int h = 0; h < scores.length; h++) { 2106 scoresValues.put(scores[h], h); 2107 } 2108 2109 Arrays.sort(scores); 2110 int predicted1 = modelSVMLabels[scoresValues.get(scores[scores.length-1])]; 2111 int predicted2 = modelSVMLabels[scoresValues.get(scores[scores.length-2])]; 2112 int predicted3 = modelSVMLabels[scoresValues.get(scores[scores.length-3])]; 2113 int predicted4 = modelSVMLabels[scoresValues.get(scores[scores.length-4])]; 2114 int predicted5 = modelSVMLabels[scoresValues.get(scores[scores.length-5])]; 2115 int predicted6 = modelSVMLabels[scoresValues.get(scores[scores.length-6])]; 2116 int predicted7 = modelSVMLabels[scoresValues.get(scores[scores.length-7])]; 2117 int predicted8 = modelSVMLabels[scoresValues.get(scores[scores.length-8])]; 2118 int predicted9 = modelSVMLabels[scoresValues.get(scores[scores.length-9])]; 2119 int predicted10 = modelSVMLabels[scoresValues.get(scores[scores.length-10])]; 2120 2121 String[] predictedTags = new String[10]; 2122 for (Map.Entry<String, Integer> entry : mapperWithIDs.entrySet()) { 2123 2124 if (entry.getValue().equals(predicted1)) { 2125 predictedTags[0] = entry.getKey(); 2126 } else if (entry.getValue().equals(predicted2)) { 2127 predictedTags[1] = entry.getKey(); 2128 } else if (entry.getValue().equals(predicted3)) { 2129 predictedTags[2] = entry.getKey(); 2130 } else if (entry.getValue().equals(predicted4)) { 2131 predictedTags[3] = entry.getKey(); 2132 } else if (entry.getValue().equals(predicted5)) { 2133 predictedTags[4] = entry.getKey(); 2134 } else if (entry.getValue().equals(predicted6)) { 2135 predictedTags[5] = entry.getKey(); 2136 } else if (entry.getValue().equals(predicted7)) { 2137 predictedTags[6] = entry.getKey(); 2138 } else if (entry.getValue().equals(predicted8)) { 2139 predictedTags[7] = entry.getKey(); 2140 } else if (entry.getValue().equals(predicted9)) { 2141 predictedTags[8] = entry.getKey(); 2142 } else if (entry.getValue().equals(predicted10)) { 2143 predictedTags[9] = entry.getKey(); 2144 } 2145 } 2146 //clearing model, to add the new computed classes in jlist 2147 model.clear(); 2148 for (Map.Entry<String, String> tag : mappings.entrySet()) { 2149 2150 for (int k = 0; k < 10; k++) { 2151 if (tag.getValue().equals(predictedTags[k])) { 2152 predictedTags[k] = tag.getKey(); 2153 model.addElement(tag.getKey()); 2154 } 2155 } 2156 } 2157 System.out.println("combined, predicted classes: " + Arrays.toString(predictedTags)); 2158 2159 for (int r = 0; r < ranks.length; r++) { 2160 String predictedTag = predictedTags[r]; 2161 Double currentWeight = alignedFilesAndWeights.get(modelFile); 2162 double finalRank = ranks[r]*currentWeight; 2163 2164 if (scoreMap.containsKey(predictedTag)) { 2165 Double scoreToAdd = scoreMap.get(predictedTag); 2166 scoreMap.put(predictedTag, finalRank+scoreToAdd); 2167 } else { 2168 scoreMap.put(predictedTag, finalRank); 2169 } 2170 //add final weight - predicted tag 2171 } 2172 } //files iter 2173 model.clear(); 2174 List<Double> scoresList = new ArrayList<>(scoreMap.values()); 2175 Collections.sort(scoresList, Collections.reverseOrder()); 2176 2177 for (Double sco : scoresList) { 2178 if (model.size() > 9) { 2179 break; 2180 } 2181 for (Map.Entry<String, Double> scoreEntry : scoreMap.entrySet()) { 2182 if (scoreEntry.getValue().equals(sco)) { 2183 model.addElement(scoreEntry.getKey()); 2184 } 2185 } 2186 } 2187 } 2188 } 2189 2190 private void createOSMObject(Collection<OsmPrimitive> sel) { 2191 2192 MathTransform transform = null; 2193 GeometryFactory geometryFactory = new GeometryFactory(); 2194 CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84; 2195 CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN; 2196 try { 2197 transform = CRS.findMathTransform(sourceCRS, targetCRS, true); 2198 2199 } catch (FactoryException ex) { 2200 Logger.getLogger(OSMRecPluginHelper.class.getName()).log(Level.SEVERE, null, ex); 2201 } 2202 2203 //fire an error to the user if he has multiple selection from map 2204 2205 //we consider simple (one instance) selection, so we get the first of the sel list 2206 2207 OSMWay selectedInstance; 2208 List<OsmPrimitive> osmPrimitiveSelection = new ArrayList<>(sel); 2209 OsmPrimitive s; 2210 2211 //get a simple selection 2212 if (!osmPrimitiveSelection.isEmpty()) { 2213 s = osmPrimitiveSelection.get(0); 2214 } else { 2215 return; 2216 } 2217 2218 selectedInstance = new OSMWay(); 2219 for (Way selectedWay : s.getDataSet().getSelectedWays()) { 2220 List<Node> selectedWayNodes = selectedWay.getNodes(); 2221 for (Node node : selectedWayNodes) { 2222 node.getCoor(); 2223 if (node.isLatLonKnown()) { 2224 double lat = node.getCoor().lat(); 2225 double lon = node.getCoor().lon(); 2226 2227 Coordinate sourceCoordinate = new Coordinate(lon, lat); 2228 Coordinate targetGeometry = null; 2229 try { 2230 targetGeometry = JTS.transform(sourceCoordinate, null, transform); 2231 } catch (MismatchedDimensionException | TransformException ex) { 2232 Logger.getLogger(OSMParser.class.getName()).log(Level.SEVERE, null, ex); 2233 } 2234 2235 Geometry geom = geometryFactory.createPoint(new Coordinate(targetGeometry)); 2236 selectedInstance.addNodeGeometry(geom); 2237 } 2238 } 2239 } 2240 Geometry fullGeom = geometryFactory.buildGeometry(selectedInstance.getNodeGeometries()); 2241 2242 System.out.println("number of nodes: " + selectedInstance.getNodeGeometries().size()); 2243 2244 if ((selectedInstance.getNodeGeometries().size() > 3) && 2245 selectedInstance.getNodeGeometries().get(0).equals(selectedInstance.getNodeGeometries() 2246 .get(selectedInstance.getNodeGeometries().size()-1))) { 2247 //checks if the beginning and ending node are the same and the number of nodes are more than 3. 2248 //the nodes must be more than 3, because jts does not allow a construction of a linear ring with less points. 2249 LinearRing linear = geometryFactory.createLinearRing(fullGeom.getCoordinates()); 2250 Polygon poly = new Polygon(linear, null, geometryFactory); 2251 selectedInstance.setGeometry(poly); 2252 2253 System.out.println("\n\npolygon"); 2254 } else if (selectedInstance.getNodeGeometries().size() > 1) { 2255 //it is an open geometry with more than one nodes, make it linestring 2256 System.out.println("\n\nlinestring"); 2257 LineString lineString = geometryFactory.createLineString(fullGeom.getCoordinates()); 2258 selectedInstance.setGeometry(lineString); 2259 } else { //we assume all the rest geometries are points 2260 System.out.println("\n\npoint"); 2261 Point point = geometryFactory.createPoint(fullGeom.getCoordinate()); 2262 selectedInstance.setGeometry(point); 2263 } 2264 2265 Map<String, String> selectedTags = s.getInterestingTags(); 2266 selectedInstance.setAllTags(selectedTags); 2267 2268 //construct vector here 2269 if (selectedInstance != null) { 2270 int id; 2271 if (mappings == null) { 2272 System.out.println("null mappings ERROR"); 2273 } 2274 2275 OSMClassification classifier = new OSMClassification(); 2276 classifier.calculateClasses(selectedInstance, mappings, mapperWithIDs, indirectClasses, indirectClassesWithIDs); 2277 2278 if (modelWithClasses) { 2279 ClassFeatures classFeatures = new ClassFeatures(); 2280 classFeatures.createClassFeatures(selectedInstance, mappings, mapperWithIDs, indirectClasses, indirectClassesWithIDs); 2281 id = 1422; 2282 } else { 2283 id = 1; 2284 } 2285 2286 GeometryFeatures geometryFeatures = new GeometryFeatures(id); 2287 geometryFeatures.createGeometryFeatures(selectedInstance); 2288 id = geometryFeatures.getLastID(); 2289 TextualFeatures textualFeatures = new TextualFeatures(id, textualList, languageDetector); 2290 textualFeatures.createTextualFeatures(selectedInstance); 2291 2292 List<FeatureNode> featureNodeList = selectedInstance.getFeatureNodeList(); 2293 System.out.println(featureNodeList); 2294 2295 FeatureNode[] featureNodeArray = new FeatureNode[featureNodeList.size()]; 2296 2297 int i = 0; 2298 for (FeatureNode featureNode : featureNodeList) { 2299 featureNodeArray[i] = featureNode; 2300 i++; 2301 } 2302 FeatureNode[] testInstance2 = featureNodeArray; 2303 2304 Map<Integer, Integer> mapLabelsToIDs = new HashMap<>(); 2305 for (int h = 0; h < modelSVMLabelSize; h++) { 2306 mapLabelsToIDs.put(modelSVMLabels[h], h); 2307 } 2308 2309 double[] scores = new double[modelSVMLabelSize]; 2310 Linear.predictValues(modelSVM, testInstance2, scores); 2311 2312 Map<Double, Integer> scoresValues = new HashMap<>(); 2313 for (int h = 0; h < scores.length; h++) { 2314 scoresValues.put(scores[h], h); 2315 } 2316 2317 Arrays.sort(scores); 2318 2319 int[] preds = new int[RECOMMENDATIONS_SIZE]; 2320 for (int p = 0; p < RECOMMENDATIONS_SIZE; p++) { 2321 preds[p] = modelSVMLabels[scoresValues.get(scores[scores.length-(p+1)])]; 2322 } 2323 String[] predictedTags2 = new String[RECOMMENDATIONS_SIZE]; 2324 2325 for (int p = 0; p < RECOMMENDATIONS_SIZE; p++) { 2326 if (idsWithMappings.containsKey(preds[p])) { 2327 predictedTags2[p] = idsWithMappings.get(preds[p]); 2328 } 2329 } 2330 2331 //clearing model, to add the new computed classes in jlist 2332 model.clear(); 2333 for (Map.Entry<String, String> tag : mappings.entrySet()) { 2334 for (int k = 0; k < 10; k++) { 2335 if (tag.getValue().equals(predictedTags2[k])) { 2336 predictedTags2[k] = tag.getKey(); 2337 model.addElement(tag.getKey()); 2338 } 2339 } 2340 } 2341 System.out.println("Optimized - create OSMObject, predicted classes: " + Arrays.toString(predictedTags2)); 2342 } 2343 } 2344 2345 private void parseTagsMappedToClasses() { 2346 2347 InputStream tagsToClassesMapping = TrainWorker.class.getResourceAsStream("/resources/files/Map"); 2348 Mapper mapper = new Mapper(); 2349 try { 2350 mapper.parseFile(tagsToClassesMapping); 2351 2352 } catch (FileNotFoundException ex) { 2353 Logger.getLogger(Mapper.class.getName()).log(Level.SEVERE, null, ex); 2354 } 2355 mappings = mapper.getMappings(); 2356 mapperWithIDs = mapper.getMappingsWithIDs(); 2357 idsWithMappings = mapper.getIDsWithMappings(); 2358 } 2359 2360 private void loadTextualList(File textualListFile) { 2361 2362 Scanner input = null; 2363 2364 try { 2365 input = new Scanner(textualListFile); 2366 } catch (FileNotFoundException ex) { 2367 Logging.warn(ex); 2368 } 2369 while (input.hasNext()) { 2370 String nextLine = input.nextLine(); 2371 textualList.add(nextLine); 2372 } 2373 System.out.println("Textual List parsed from file successfully." + textualList); 2374 } 2375 2376 private void loadDefaultTextualList() { 2377 2378 InputStream textualListStream = TrainWorker.class.getResourceAsStream("/resources/files/textualList.txt"); 2379 TextualStatistics textualStatistics = new TextualStatistics(); 2380 textualStatistics.parseTextualList(textualListStream); 2381 textualList = textualStatistics.getTextualList(); 2382 System.out.println("Default Textual List parsed from file successfully." + textualList); 2383 } 2384 2385 private void loadOntology() { 2386 InputStream ontologyStream = TrainWorker.class.getResourceAsStream("/resources/files/owl.xml"); 2387 Ontology ontology = new Ontology(ontologyStream); 2388 indirectClasses = ontology.getIndirectClasses(); 2389 indirectClassesWithIDs = ontology.getIndirectClassesIDs(); 2390 } 2391 2392 private Map<File, Double> getAlignedModels(Map<File, Double> filesAndWeights) { 2393 Map<File, Double> alignedFilesAndWeights = new HashMap<>(); 2394 if (modelWithClasses) { 2395 for (Entry<File, Double> entry : filesAndWeights.entrySet()) { 2396 String absolutePath = entry.getKey().getAbsolutePath(); 2397 if (absolutePath.endsWith(".0")) { 2398 String newPath = absolutePath.substring(0, absolutePath.length()-2) + ".1"; 2399 File alignedFile = new File(newPath); 2400 if (alignedFile.exists()) { 2401 alignedFilesAndWeights.put(alignedFile, entry.getValue()); 2402 } 2403 } else { 2404 alignedFilesAndWeights.put(entry.getKey(), entry.getValue()); 2405 } 2406 } 2407 } else { 2408 for (Entry<File, Double> entry : filesAndWeights.entrySet()) { 2409 String absolutePath = entry.getKey().getAbsolutePath(); 2410 if (absolutePath.endsWith(".1")) { 2411 String newPath = absolutePath.substring(0, absolutePath.length()-2) + ".0"; 2412 File alignedFile = new File(newPath); 2413 if (alignedFile.exists()) { 2414 alignedFilesAndWeights.put(alignedFile, entry.getValue()); 2415 } 2416 } else { 2417 alignedFilesAndWeights.put(entry.getKey(), entry.getValue()); 2418 } 2419 } 2420 } 2421 return alignedFilesAndWeights; 2422 } 2423 } 2424 2424 } -
applications/editors/josm/plugins/native-password-manager/.settings/org.eclipse.jdt.core.prefs
r32699 r33579 3 3 org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore 4 4 org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull 5 org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= 5 6 org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault 7 org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= 6 8 org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable 9 org.eclipse.jdt.core.compiler.annotation.nullable.secondary= 7 10 org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled 8 11 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled … … 45 48 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore 46 49 org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled 47 org.eclipse.jdt.core.compiler.problem.missingSerialVersion= warning50 org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore 48 51 org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore 49 52 org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning … … 51 54 org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore 52 55 org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning 56 org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning 53 57 org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error 54 58 org.eclipse.jdt.core.compiler.problem.nullReference=warning … … 57 61 org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning 58 62 org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore 63 org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning 59 64 org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore 60 65 org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore … … 73 78 org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled 74 79 org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore 80 org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning 75 81 org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning 76 82 org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled … … 79 85 org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore 80 86 org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning 87 org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning 88 org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled 89 org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info 81 90 org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore 82 91 org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore … … 86 95 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 87 96 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 97 org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore 88 98 org.eclipse.jdt.core.compiler.problem.unusedImport=warning 89 99 org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -
applications/editors/josm/plugins/native-password-manager/build.xml
r32680 r33579 5 5 <property name="commit.message" value="Commit message"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="1 0580"/>7 <property name="plugin.main.version" value="12678"/> 8 8 <property name="plugin.author" value="Paul Hartmann"/> 9 9 <property name="plugin.class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/> -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/fallback/FallbackProvider.java
r30822 r33579 100 100 } 101 101 102 @Override 102 103 public char[] read(String key) { 103 104 byte[] ciphertext = prefs.getByteArray(key, null); … … 113 114 } 114 115 116 @Override 115 117 public void save(String key, char[] password, String description) { 116 118 _save(key, password, description); … … 126 128 } 127 129 130 @Override 128 131 public void delete(String key) { 129 132 prefs.remove(key); -
applications/editors/josm/plugins/native-password-manager/src/org/netbeans/modules/keyring/mac/MacProvider.java
r30822 r33579 53 53 private static final Logger LOG = Logger.getLogger(MacProvider.class.getName()); 54 54 55 @Override 55 56 public boolean enabled() { 56 57 return true; // test elsewhere if we are on a mac 57 58 } 58 59 60 @Override 59 61 public char[] read(String key) { 60 62 try { … … 76 78 } 77 79 80 @Override 78 81 public void save(String key, char[] password, String description) { 79 82 try { … … 98 101 } 99 102 103 @Override 100 104 public void delete(String key) { 101 105 try { -
applications/editors/josm/plugins/native-password-manager/src/org/openstreetmap/josm/plugins/npm/InitializationWizard.java
r30822 r33579 44 44 import org.openstreetmap.josm.data.oauth.OAuthToken; 45 45 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel; 46 import org.openstreetmap.josm.gui.util.WindowGeometry; 46 47 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 48 import org.openstreetmap.josm.io.OsmApi; 47 49 import org.openstreetmap.josm.io.auth.CredentialsAgentException; 48 50 import org.openstreetmap.josm.io.auth.CredentialsManager; 49 import org.openstreetmap.josm.io.OsmApi;50 51 import org.openstreetmap.josm.tools.ImageProvider; 51 52 import org.openstreetmap.josm.tools.PlatformHookOsx; 52 53 import org.openstreetmap.josm.tools.PlatformHookUnixoid; 53 54 import org.openstreetmap.josm.tools.PlatformHookWindows; 54 import org.openstreetmap.josm.tools.WindowGeometry;55 55 56 56 public class InitializationWizard extends JDialog { -
applications/editors/josm/plugins/pdfimport/build.xml
r33569 r33579 4 4 <property name="commit.message" value="Initial pdfimport version"/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1267 5"/>6 <property name="plugin.main.version" value="12678"/> 7 7 8 8 <!-- Configure these properties (replace "..." accordingly). -
applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java
r33569 r33579 60 60 import org.openstreetmap.josm.gui.progress.ProgressRenderer; 61 61 import org.openstreetmap.josm.gui.progress.swing.SwingRenderingProgressMonitor; 62 import org.openstreetmap.josm.gui.util.WindowGeometry; 62 63 import org.openstreetmap.josm.tools.ImageProvider; 63 64 import org.openstreetmap.josm.tools.Logging; 64 import org.openstreetmap.josm.tools.WindowGeometry;65 65 66 66 import pdfimport.pdfbox.PdfBoxParser; -
applications/editors/josm/plugins/print/build.xml
r33237 r33579 5 5 <property name="commit.message" value="Added a field to specify the map scale."/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="1 1905"/>7 <property name="plugin.main.version" value="12678"/> 8 8 9 9 <property name="plugin.author" value="Kai Pastor"/> -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java
r33237 r33579 59 59 import org.openstreetmap.gui.jmapviewer.tilesources.AbstractOsmTileSource; 60 60 import org.openstreetmap.josm.Main; 61 import org.openstreetmap.josm.gui.MainApplication; 62 import org.openstreetmap.josm.gui.util.WindowGeometry; 61 63 import org.openstreetmap.josm.tools.GBC; 64 import org.openstreetmap.josm.tools.Logging; 62 65 import org.openstreetmap.josm.tools.Utils; 63 import org.openstreetmap.josm.tools.WindowGeometry;64 66 65 67 /** … … 233 235 printPreview.repaint(); 234 236 } catch (ParseException e) { 235 Main.error(e);237 Logging.error(e); 236 238 } 237 239 } … … 261 263 printPreview.repaint(); 262 264 } catch (ParseException e) { 263 Main.error(e);265 Logging.error(e); 264 266 } 265 267 } … … 343 345 JScrollPane previewPane = new JScrollPane(printPreview, 344 346 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 345 previewPane.setPreferredSize(Main .main != null ? Main.map.mapView.getSize() : new Dimension(210, 297));347 previewPane.setPreferredSize(MainApplication.getMap() != null ? MainApplication.getMap().mapView.getSize() : new Dimension(210, 297)); 346 348 add(previewPane, GBC.std(0, 0).span(1, GBC.RELATIVE).fill().weight(5.0, 5.0)); 347 349 … … 479 481 } else if (!ignoredAttributes.contains(a.getName())) { 480 482 // TODO: Add support for DateTimeSyntax, SetOfIntegerSyntax, ResolutionSyntax if needed 481 Main.warn("Print request attribute not supported: "+a.getName() +": "+a.getCategory()+" - "+a.toString());483 Logging.warn("Print request attribute not supported: "+a.getName() +": "+a.getCategory()+" - "+a.toString()); 482 484 } 483 485 if (setting != null) { … … 531 533 return realClass.getConstructor(int.class).newInstance(Integer.parseInt(value)); 532 534 } else { 533 Main.warn("Attribute syntax not supported: "+syntax);535 Logging.warn("Attribute syntax not supported: "+syntax); 534 536 } 535 537 return null; … … 544 546 } 545 547 } catch (PrinterException | ReflectiveOperationException e) { 546 Main.warn(e.getClass().getSimpleName()+": "+e.getMessage());548 Logging.warn(e.getClass().getSimpleName()+": "+e.getMessage()); 547 549 } 548 550 } … … 551 553 attrs.add(unmarshallPrintSetting(setting)); 552 554 } catch (ReflectiveOperationException e) { 553 Main.warn(e.getClass().getSimpleName()+": "+e.getMessage());555 Logging.warn(e.getClass().getSimpleName()+": "+e.getMessage()); 554 556 } 555 557 } -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java
r33102 r33579 7 7 8 8 import org.openstreetmap.josm.Main; 9 import org.openstreetmap.josm.gui.MainApplication; 9 10 import org.openstreetmap.josm.gui.MapFrame; 10 11 import org.openstreetmap.josm.plugins.Plugin; … … 41 42 super(info); 42 43 43 JMenu fileMenu = Main .main.menu.fileMenu;44 JMenu fileMenu = MainApplication.getMenu().fileMenu; 44 45 int pos = fileMenu.getItemCount(); 45 46 do { -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPreview.java
r33062 r33579 19 19 import javax.swing.RepaintManager; 20 20 21 import org.openstreetmap.josm. Main;21 import org.openstreetmap.josm.tools.Logging; 22 22 23 23 /** … … 281 281 } catch (PrinterException e) { 282 282 // should never happen since we are not printing 283 Main.error(e);283 Logging.error(e); 284 284 } 285 285 } else { -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java
r33237 r33579 7 7 import java.util.List; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.gui.MainApplication; 11 11 import org.openstreetmap.josm.gui.layer.Layer; 12 12 import org.openstreetmap.josm.gui.layer.MainLayerManager; … … 15 15 public class PrintableLayerManager extends MainLayerManager { 16 16 17 private static final MainLayerManager layerManager = Main .getLayerManager();17 private static final MainLayerManager layerManager = MainApplication.getLayerManager(); 18 18 19 19 @Override -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java
r33260 r33579 25 25 import org.openstreetmap.josm.data.Bounds; 26 26 import org.openstreetmap.josm.data.SystemOfMeasurement; 27 import org.openstreetmap.josm.gui.MainApplication; 27 28 import org.openstreetmap.josm.gui.MapView; 28 29 import org.openstreetmap.josm.gui.layer.Layer; … … 122 123 if (dim.width != width || dim.height != height) { 123 124 super.setSize(width, height); 124 zoomTo(Main .map.mapView.getRealBounds());125 zoomTo(MainApplication.getMap().mapView.getRealBounds()); 125 126 rezoomToFixedScale(); 126 127 } … … 135 136 if (dim.width != newSize.width || dim.height != newSize.height) { 136 137 super.setSize(newSize); 137 zoomTo(Main .map.mapView.getRealBounds());138 zoomTo(MainApplication.getMap().mapView.getRealBounds()); 138 139 rezoomToFixedScale(); 139 140 } -
applications/editors/josm/plugins/roadsigns/build.xml
r32680 r33579 4 4 <property name="commit.message" value=""/> 5 5 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 6 <property name="plugin.main.version" value="1 0580"/>6 <property name="plugin.main.version" value="12678"/> 7 7 8 8 <!-- -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignInputDialog.java
r33179 r33579 68 68 import org.openstreetmap.josm.data.osm.OsmPrimitive; 69 69 import org.openstreetmap.josm.gui.ExtendedDialog; 70 import org.openstreetmap.josm.gui.MainApplication; 71 import org.openstreetmap.josm.gui.util.WindowGeometry; 70 72 import org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Divider; 71 73 import org.openstreetmap.josm.gui.widgets.MultiSplitLayout.Leaf; … … 77 79 import org.openstreetmap.josm.plugins.roadsigns.Sign.Tag; 78 80 import org.openstreetmap.josm.tools.GBC; 81 import org.openstreetmap.josm.tools.Logging; 79 82 import org.openstreetmap.josm.tools.OpenBrowser; 80 83 import org.openstreetmap.josm.tools.Pair; 81 import org.openstreetmap.josm.tools.WindowGeometry;82 84 83 85 /** … … 134 136 protected void buttonAction(int i, ActionEvent evt) { 135 137 if (i == 0) { // OK Button 136 Collection<OsmPrimitive> selPrim = Main .getLayerManager().getEditDataSet().getSelected();138 Collection<OsmPrimitive> selPrim = MainApplication.getLayerManager().getEditDataSet().getSelected(); 137 139 if (!selPrim.isEmpty()) { 138 140 Main.pref.put("plugin.roadsigns.addTrafficSignTag", addTrafficSignTag.isSelected()); … … 140 142 Command cmd = createCommand(selPrim); 141 143 if (cmd != null) { 142 Main .main.undoRedo.add(cmd);144 MainApplication.undoRedo.add(cmd); 143 145 } 144 146 } … … 159 161 xmlenc.writeObject(model); 160 162 } catch (FileNotFoundException ex) { 161 Main.warn("unable to write dialog layout: "+ex);163 Logging.warn("unable to write dialog layout: "+ex); 162 164 } 163 165 } -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/javacc/ParseException.java
r23192 r33579 97 97 * gets displayed. 98 98 */ 99 @Override 99 100 public String getMessage() { 100 101 if (!specialConstructor) { -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/javacc/Token.java
r21967 r33579 91 91 * Returns the image. 92 92 */ 93 @Override 93 94 public String toString() 94 95 { -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/javacc/TokenMgrError.java
r23192 r33579 115 115 * from this method for such cases in the release version of your parser. 116 116 */ 117 @Override 117 118 public String getMessage() { 118 119 return super.getMessage(); -
applications/editors/josm/plugins/tageditor/build.xml
r32680 r33579 2 2 <project name="tageditor" default="dist" basedir="."> 3 3 <property name="commit.message" value="Tageditor: help shortcut parser, rebuild"/> 4 <property name="plugin.main.version" value="1 0580"/>4 <property name="plugin.main.version" value="12678"/> 5 5 6 6 <property name="plugin.author" value="Karl Guggisberg"/> -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorDialog.java
r33016 r33579 31 31 import org.openstreetmap.josm.data.osm.OsmPrimitive; 32 32 import org.openstreetmap.josm.data.osm.Tag; 33 import org.openstreetmap.josm.gui.MainApplication; 33 34 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList; 34 35 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 35 36 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 37 import org.openstreetmap.josm.gui.util.WindowGeometry; 36 38 import org.openstreetmap.josm.plugins.tageditor.ac.AutoCompletionListViewer; 37 39 import org.openstreetmap.josm.plugins.tageditor.editor.TagEditor; … … 42 44 import org.openstreetmap.josm.plugins.tageditor.tagspec.ui.TabularTagSelector; 43 45 import org.openstreetmap.josm.tools.ImageProvider; 44 import org.openstreetmap.josm.tools.WindowGeometry;45 46 46 47 /** … … 282 283 tagEditor.getModel().clearAppliedPresets(); 283 284 tagEditor.getModel().initFromJOSMSelection(); 284 autocomplete = Main .getLayerManager().getEditLayer().data.getAutoCompletionManager();285 autocomplete = MainApplication.getLayerManager().getEditLayer().data.getAutoCompletionManager(); 285 286 tagEditor.setAutoCompletionManager(autocomplete); 286 287 getModel().ensureOneTag(); … … 319 320 setVisible(false); 320 321 tagEditor.getModel().updateJOSMSelection(); 321 DataSet ds = Main .getLayerManager().getEditDataSet();322 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 322 323 ds.fireSelectionChanged(); 323 324 Main.parent.repaint(); // repaint all - drawing could have been changed -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/TagEditorPlugin.java
r30488 r33579 2 2 package org.openstreetmap.josm.plugins.tageditor; 3 3 4 import org.openstreetmap.josm. Main;4 import org.openstreetmap.josm.gui.MainApplication; 5 5 import org.openstreetmap.josm.gui.MainMenu; 6 6 import org.openstreetmap.josm.plugins.Plugin; … … 9 9 public class TagEditorPlugin extends Plugin { 10 10 LaunchAction action; 11 11 12 12 /** 13 * constructor 13 * constructor 14 14 */ 15 15 public TagEditorPlugin(PluginInformation info) { 16 16 super(info); 17 17 action = new LaunchAction(); 18 MainMenu.add(Main .main.menu.editMenu, action);18 MainMenu.add(MainApplication.getMenu().editMenu, action); 19 19 } 20 20 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/ac/AutoCompletionContext.java
r32508 r33579 2 2 package org.openstreetmap.josm.plugins.tageditor.ac; 3 3 4 import org.openstreetmap.josm.Main;5 4 import org.openstreetmap.josm.data.osm.DataSet; 5 import org.openstreetmap.josm.gui.MainApplication; 6 6 7 7 public class AutoCompletionContext { … … 16 16 17 17 public void initFromJOSMSelection() { 18 DataSet ds = Main .getLayerManager().getEditDataSet();18 DataSet ds = MainApplication.getLayerManager().getEditDataSet(); 19 19 selectionIncludesNodes = !ds.getSelectedNodes().isEmpty(); 20 20 selectionIncludesWays = !ds.getSelectedWays().isEmpty(); -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/editor/TagEditorModel.java
r33016 r33579 10 10 import javax.swing.DefaultListSelectionModel; 11 11 12 import org.openstreetmap.josm.Main;13 12 import org.openstreetmap.josm.command.Command; 14 13 import org.openstreetmap.josm.command.SequenceCommand; 15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 15 import org.openstreetmap.josm.data.osm.Tag; 16 import org.openstreetmap.josm.gui.MainApplication; 17 17 import org.openstreetmap.josm.gui.tagging.TagModel; 18 18 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; … … 147 147 public void updateJOSMSelection() { 148 148 ArrayList<Command> commands = new ArrayList<>(); 149 Collection<OsmPrimitive> selection = Main .getLayerManager().getEditDataSet().getSelected();149 Collection<OsmPrimitive> selection = MainApplication.getLayerManager().getEditDataSet().getSelected(); 150 150 if (selection == null) 151 151 return; … … 167 167 168 168 // executes the commands and adds them to the undo/redo chains 169 Main .main.undoRedo.add(command);169 MainApplication.undoRedo.add(command); 170 170 } 171 171 … … 174 174 */ 175 175 public void initFromJOSMSelection() { 176 Collection<OsmPrimitive> selection = Main .getLayerManager().getEditDataSet().getSelected();176 Collection<OsmPrimitive> selection = MainApplication.getLayerManager().getEditDataSet().getSelected(); 177 177 clear(); 178 178 for (OsmPrimitive element : selection) { -
applications/editors/josm/plugins/terracer/build.xml
r32680 r33579 2 2 <project name="terracer" default="dist" basedir="."> 3 3 <property name="commit.message" value="applied #j5760 (patch by robome) - Order of housenumbers not correct"/> 4 <property name="plugin.main.version" value="1 0580"/>4 <property name="plugin.main.version" value="12678"/> 5 5 <property name="plugin.author" value="Matt Amos"/> 6 6 <property name="plugin.class" value="terracer.TerracerPlugin"/> -
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputDialog.java
r33077 r33579 28 28 import org.openstreetmap.josm.data.osm.Way; 29 29 import org.openstreetmap.josm.gui.ExtendedDialog; 30 import org.openstreetmap.josm.gui.MainApplication; 30 31 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 31 32 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 33 import org.openstreetmap.josm.gui.util.WindowGeometry; 32 34 import org.openstreetmap.josm.tools.GBC; 33 import org.openstreetmap.josm.tools.WindowGeometry;34 35 35 36 /** … … 310 311 311 312 if (buildingComboBox == null) { 312 final List<AutoCompletionListItem> values = Main.getLayerManager().getEditDataSet().getAutoCompletionManager().getValues("building"); 313 final List<AutoCompletionListItem> values = MainApplication 314 .getLayerManager().getEditDataSet().getAutoCompletionManager().getValues("building"); 313 315 314 316 buildingComboBox = new AutoCompletingComboBox(); … … 362 364 TreeSet<String> createAutoCompletionInfo() { 363 365 final TreeSet<String> names = new TreeSet<>(); 364 for (OsmPrimitive osm : Main .getLayerManager().getEditDataSet()366 for (OsmPrimitive osm : MainApplication.getLayerManager().getEditDataSet() 365 367 .allNonDeletedPrimitives()) { 366 368 if (osm.getKeys() != null && osm.keySet().contains("highway") -
applications/editors/josm/plugins/terracer/src/terracer/HouseNumberInputHandler.java
r33077 r33579 26 26 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox; 27 27 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem; 28 import org.openstreetmap.josm.tools.Logging; 28 29 import org.openstreetmap.josm.tools.UserCancelException; 29 30 … … 300 301 doKeepOutline(), buildingType()); 301 302 } catch (UserCancelException ex) { 302 Main.trace(ex);303 Logging.trace(ex); 303 304 } 304 305 -
applications/editors/josm/plugins/terracer/src/terracer/ReverseTerraceAction.java
r33077 r33579 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 22 import org.openstreetmap.josm.data.osm.Way; 23 import org.openstreetmap.josm.gui.MainApplication; 23 24 import org.openstreetmap.josm.tools.Shortcut; 24 25 … … 48 49 /** 49 50 * Breadth-first searches based on the selection while the selection is a way 50 * with a building=* tag and then applies the addr:housenumber tag in reverse 51 * order. 51 * with a building=* tag and then applies the addr:housenumber tag in reverse order. 52 52 */ 53 @Override 53 54 public void actionPerformed(ActionEvent e) { 54 Collection<Way> selectedWays = Main .getLayerManager().getEditDataSet().getSelectedWays();55 Collection<Way> selectedWays = MainApplication.getLayerManager().getEditDataSet().getSelectedWays(); 55 56 56 57 // Set to keep track of all the nodes that have been visited - that is: if … … 123 124 } 124 125 125 Main .main.undoRedo.add(new SequenceCommand(tr("Reverse Terrace"), commands));126 Main .getLayerManager().getEditDataSet().setSelected(orderedWays);126 MainApplication.undoRedo.add(new SequenceCommand(tr("Reverse Terrace"), commands)); 127 MainApplication.getLayerManager().getEditDataSet().setSelected(orderedWays); 127 128 } 128 129 -
applications/editors/josm/plugins/terracer/src/terracer/TerracerAction.java
r33077 r33579 38 38 import org.openstreetmap.josm.data.osm.Way; 39 39 import org.openstreetmap.josm.gui.ExtendedDialog; 40 import org.openstreetmap.josm.gui.MainApplication; 40 41 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 42 import org.openstreetmap.josm.tools.Logging; 41 43 import org.openstreetmap.josm.tools.Pair; 42 44 import org.openstreetmap.josm.tools.Shortcut; … … 178 180 179 181 } catch (InvalidUserInputException ex) { 180 Main.warn("Terracer: "+ex.getMessage());182 Logging.warn("Terracer: "+ex.getMessage()); 181 183 new ExtendedDialog(Main.parent, tr("Invalid selection"), new String[] {"OK"}) 182 184 .setButtonIcons(new String[] {"ok"}).setIcon(JOptionPane.INFORMATION_MESSAGE) … … 191 193 192 194 // Try to find an associatedStreet relation that could be reused from housenumbers, outline and street. 193 Set<OsmPrimitive> candidates = new HashSet< OsmPrimitive>(housenumbers);195 Set<OsmPrimitive> candidates = new HashSet<>(housenumbers); 194 196 candidates.add(outline); 195 197 if (street != null) { … … 203 205 if (associatedStreets.size() > 1) { 204 206 // TODO: Deal with multiple associated Streets 205 Main.warn("Terracer: Found "+associatedStreets.size()+" associatedStreet relations. Considering the first one only.");207 Logging.warn("Terracer: Found "+associatedStreets.size()+" associatedStreet relations. Considering the first one only."); 206 208 } 207 209 } … … 218 220 housenumbers, streetname, associatedStreet != null, false, "yes"); 219 221 } catch (UserCancelException ex) { 220 Main.trace(ex);222 Logging.trace(ex); 221 223 } finally { 222 224 this.commands.clear(); … … 245 247 * number nodes 246 248 */ 247 class HousenumberNodeComparator implements Comparator<Node> {249 static class HousenumberNodeComparator implements Comparator<Node> { 248 250 private final Pattern pat = Pattern.compile("^(\\d+)\\s*(.*)"); 249 251 … … 402 404 } 403 405 if (!nodesToDelete.isEmpty()) 404 this.commands.add(DeleteCommand.delete(Main .getLayerManager().getEditLayer(), nodesToDelete));406 this.commands.add(DeleteCommand.delete(MainApplication.getLayerManager().getEditLayer(), nodesToDelete)); 405 407 } 406 408 } else { … … 413 415 // Or should removing them also be an option? 414 416 if (!housenumbers.isEmpty()) { 415 commands.add(DeleteCommand.delete(Main .getLayerManager().getEditLayer(),417 commands.add(DeleteCommand.delete(MainApplication.getLayerManager().getEditLayer(), 416 418 housenumbers, true, true)); 417 419 } … … 425 427 } 426 428 427 Main .main.undoRedo.add(createTerracingCommand(outline));429 MainApplication.undoRedo.add(createTerracingCommand(outline)); 428 430 if (nb <= 1 && street != null) { 429 431 // Select the way (for quick selection of a new house (with the same way)) 430 Main .getLayerManager().getEditDataSet().setSelected(street);432 MainApplication.getLayerManager().getEditDataSet().setSelected(street); 431 433 } else { 432 434 // Select the new building outlines (for quick reversing) 433 Main .getLayerManager().getEditDataSet().setSelected(ways);435 MainApplication.getLayerManager().getEditDataSet().setSelected(ways); 434 436 } 435 437 } … … 488 490 } 489 491 } catch (UserCancelException e) { 490 Main.trace(e);492 Logging.trace(e); 491 493 } 492 494 } -
applications/editors/josm/plugins/terracer/src/terracer/TerracerPlugin.java
r33077 r33579 2 2 package terracer; 3 3 4 import org.openstreetmap.josm. Main;4 import org.openstreetmap.josm.gui.MainApplication; 5 5 import org.openstreetmap.josm.gui.MainMenu; 6 6 import org.openstreetmap.josm.plugins.Plugin; … … 16 16 super(info); 17 17 18 MainMenu.add(Main .main.menu.moreToolsMenu, new TerracerAction());19 MainMenu.add(Main .main.menu.moreToolsMenu, new ReverseTerraceAction());18 MainMenu.add(MainApplication.getMenu().moreToolsMenu, new TerracerAction()); 19 MainMenu.add(MainApplication.getMenu().moreToolsMenu, new ReverseTerraceAction()); 20 20 } 21 21 } -
applications/editors/josm/plugins/utilsplugin2/build.xml
r33543 r33579 5 5 <property name="commit.message" value="[josm_utilsplugin2]: select boundary by double-click; multitagger table highlights"/> 6 6 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 7 <property name="plugin.main.version" value="126 66"/>7 <property name="plugin.main.version" value="12678"/> 8 8 9 9 <property name="plugin.author" value="Kalle Lampila, Upliner, Zverik, akks, joshdoe and others"/> -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/UtilsPlugin2.java
r33522 r33579 5 5 import javax.swing.JMenuItem; 6 6 7 import org.openstreetmap.josm.Main;8 7 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 8 import org.openstreetmap.josm.gui.MainApplication; 9 9 import org.openstreetmap.josm.gui.MainMenu; 10 10 import org.openstreetmap.josm.gui.MapFrame; … … 93 93 instance = this; 94 94 95 JMenu editMenu = Main .main.menu.editMenu;96 JMenu toolsMenu = Main .main.menu.moreToolsMenu;97 JMenu dataMenu = Main .main.menu.dataMenu;98 JMenu selectionMenu = Main .main.menu.selectionMenu;95 JMenu editMenu = MainApplication.getMenu().editMenu; 96 JMenu toolsMenu = MainApplication.getMenu().moreToolsMenu; 97 JMenu dataMenu = MainApplication.getMenu().dataMenu; 98 JMenu selectionMenu = MainApplication.getMenu().selectionMenu; 99 99 100 copyTags = MainMenu.addAfter(editMenu, new CopyTagsAction(), false, Main .main.menu.copy);100 copyTags = MainMenu.addAfter(editMenu, new CopyTagsAction(), false, MainApplication.getMenu().copy); 101 101 102 102 addIntersections = MainMenu.add(toolsMenu, new AddIntersectionsAction()); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AddIntersectionsAction.java
r32410 r33579 15 15 import javax.swing.JOptionPane; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.actions.JosmAction; 19 18 import org.openstreetmap.josm.command.AddCommand; … … 23 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.MainApplication; 25 25 import org.openstreetmap.josm.gui.Notification; 26 26 import org.openstreetmap.josm.tools.Geometry; … … 56 56 Geometry.addIntersections(ways, false, cmds); 57 57 if (!cmds.isEmpty()) { 58 Main .main.undoRedo.add(new SequenceCommand(tr("Add nodes at intersections"), cmds));58 MainApplication.undoRedo.add(new SequenceCommand(tr("Add nodes at intersections"), cmds)); 59 59 Set<Node> nodes = new HashSet<>(10); 60 60 // find and select newly added nodes -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/AlignWayNodesAction.java
r33328 r33579 15 15 import javax.swing.JOptionPane; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.actions.JosmAction; 19 18 import org.openstreetmap.josm.command.Command; … … 23 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.MainApplication; 25 25 import org.openstreetmap.josm.gui.Notification; 26 26 import org.openstreetmap.josm.tools.Shortcut; … … 128 128 129 129 if (!commands.isEmpty()) 130 Main .main.undoRedo.add(new SequenceCommand(TITLE, commands));130 MainApplication.undoRedo.add(new SequenceCommand(TITLE, commands)); 131 131 } 132 132 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/ExtractPointAction.java
r32410 r33579 24 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 25 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.gui.MainApplication; 26 27 import org.openstreetmap.josm.gui.Notification; 27 28 import org.openstreetmap.josm.tools.Shortcut; … … 56 57 List<Command> cmds = new LinkedList<>(); 57 58 58 Point p = Main .map.mapView.getMousePosition();59 Point p = MainApplication.getMap().mapView.getMousePosition(); 59 60 if (p != null) 60 cmds.add(new MoveCommand(nd, Main .map.mapView.getLatLon(p.x, p.y)));61 cmds.add(new MoveCommand(nd, MainApplication.getMap().mapView.getLatLon(p.x, p.y))); 61 62 List<OsmPrimitive> refs = nd.getReferrers(); 62 63 cmds.add(new AddCommand(ndCopy)); … … 71 72 } 72 73 } 73 if (cmds.size() > 1) Main .main.undoRedo.add(new SequenceCommand(tr("Extract node from line"), cmds));74 if (cmds.size() > 1) MainApplication.undoRedo.add(new SequenceCommand(tr("Extract node from line"), cmds)); 74 75 } 75 76 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/PasteRelationsAction.java
r33123 r33579 24 24 import org.openstreetmap.josm.data.osm.Relation; 25 25 import org.openstreetmap.josm.data.osm.RelationMember; 26 import org.openstreetmap.josm.gui.MainApplication; 26 27 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 27 28 import org.openstreetmap.josm.gui.datatransfer.data.PrimitiveTransferData; 29 import org.openstreetmap.josm.tools.Logging; 28 30 import org.openstreetmap.josm.tools.Shortcut; 29 31 … … 53 55 data = ((PrimitiveTransferData) ClipboardUtils.getClipboard().getData(PrimitiveTransferData.DATA_FLAVOR)).getDirectlyAdded(); 54 56 } catch (UnsupportedFlavorException | IOException ex) { 55 Main.warn(ex);57 Logging.warn(ex); 56 58 } 57 59 for (PrimitiveData pdata : data) { … … 99 101 100 102 if (!commands.isEmpty()) 101 Main .main.undoRedo.add(new SequenceCommand(TITLE, commands));103 MainApplication.undoRedo.add(new SequenceCommand(TITLE, commands)); 102 104 } 103 105 … … 113 115 && ClipboardUtils.getClipboard().isDataFlavorAvailable(PrimitiveTransferData.DATA_FLAVOR)); 114 116 } catch (IllegalStateException e) { 115 Main.warn(e);117 Logging.warn(e); 116 118 } catch (NullPointerException e) { 117 119 // JDK-6322854: On Linux/X11, NPE can happen for unknown reasons, on all versions of Java 118 Main.error(e);120 Logging.error(e); 119 121 } 120 122 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitObjectAction.java
r32410 r33579 18 18 import javax.swing.JOptionPane; 19 19 20 import org.openstreetmap.josm.Main;21 20 import org.openstreetmap.josm.actions.JosmAction; 22 21 import org.openstreetmap.josm.actions.SplitWayAction; … … 25 24 import org.openstreetmap.josm.data.osm.OsmPrimitive; 26 25 import org.openstreetmap.josm.data.osm.Way; 26 import org.openstreetmap.josm.gui.MainApplication; 27 27 import org.openstreetmap.josm.gui.Notification; 28 28 import org.openstreetmap.josm.tools.Shortcut; … … 210 210 SplitWayAction.SplitWayResult result = SplitWayAction.splitWay( 211 211 getLayerManager().getEditLayer(), selectedWay, wayChunks, Collections.<OsmPrimitive>emptyList()); 212 Main .main.undoRedo.add(result.getCommand());212 MainApplication.undoRedo.add(result.getCommand()); 213 213 if (splitWay != null) 214 Main .main.undoRedo.add(new DeleteCommand(splitWay));214 MainApplication.undoRedo.add(new DeleteCommand(splitWay)); 215 215 getLayerManager().getEditDataSet().setSelected(result.getNewSelection()); 216 216 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SplitOnIntersectionsAction.java
r32410 r33579 15 15 import javax.swing.JOptionPane; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.actions.JosmAction; 19 18 import org.openstreetmap.josm.actions.SplitWayAction; … … 23 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.MainApplication; 25 25 import org.openstreetmap.josm.gui.Notification; 26 26 import org.openstreetmap.josm.tools.Shortcut; … … 95 95 96 96 if (!list.isEmpty()) { 97 Main .main.undoRedo.add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list));97 MainApplication.undoRedo.add(list.size() == 1 ? list.get(0) : new SequenceCommand(TITLE, list)); 98 98 getLayerManager().getEditDataSet().clearSelection(); 99 99 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/SymmetryAction.java
r32410 r33579 22 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 23 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.MainApplication; 24 25 import org.openstreetmap.josm.gui.Notification; 25 26 import org.openstreetmap.josm.tools.Shortcut; … … 87 88 } 88 89 89 Main .main.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds));90 Main .map.repaint();90 MainApplication.undoRedo.add(new SequenceCommand(tr("Symmetry"), cmds)); 91 MainApplication.getMap().repaint(); 91 92 } 92 93 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagBufferAction.java
r32725 r33579 15 15 import java.util.function.Predicate; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.actions.JosmAction; 19 18 import org.openstreetmap.josm.command.ChangePropertyCommand; … … 21 20 import org.openstreetmap.josm.command.SequenceCommand; 22 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.gui.MainApplication; 23 23 import org.openstreetmap.josm.tools.Shortcut; 24 24 import org.openstreetmap.josm.tools.SubclassFilteredCollection; … … 69 69 70 70 if (!commands.isEmpty()) 71 Main .main.undoRedo.add(new SequenceCommand(TITLE, commands));71 MainApplication.undoRedo.add(new SequenceCommand(TITLE, commands)); 72 72 } 73 73 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/TagSourceAction.java
r32410 r33579 14 14 import org.openstreetmap.josm.command.ChangePropertyCommand; 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.gui.MainApplication; 16 17 import org.openstreetmap.josm.tools.Shortcut; 17 18 … … 42 43 return; 43 44 44 Main .main.undoRedo.add(new ChangePropertyCommand(selection, "source", source));45 MainApplication.undoRedo.add(new ChangePropertyCommand(selection, "source", source)); 45 46 } 46 47 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/actions/UnGlueRelationAction.java
r32410 r33579 20 20 import org.openstreetmap.josm.data.osm.Relation; 21 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.gui.MainApplication; 22 23 import org.openstreetmap.josm.plugins.utilsplugin2.command.ChangeRelationMemberCommand; 23 24 import org.openstreetmap.josm.tools.Shortcut; … … 79 80 // error message nothing to do 80 81 } else { 81 Main .main.undoRedo.add(new SequenceCommand(tr("Unglued Relations"), cmds));82 MainApplication.undoRedo.add(new SequenceCommand(tr("Unglued Relations"), cmds)); 82 83 //Set selection all primiteves (new and old) 83 84 newPrimitives.addAll(selection); 84 85 getLayerManager().getEditDataSet().setSelected(newPrimitives); 85 Main .map.mapView.repaint();86 MainApplication.getMap().mapView.repaint(); 86 87 } 87 88 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/curves/CurveAction.java
r32410 r33579 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.osm.Way; 20 import org.openstreetmap.josm.gui.MainApplication; 20 21 import org.openstreetmap.josm.tools.Shortcut; 21 22 … … 58 59 Collection<Command> cmds = CircleArcMaker.doCircleArc(selectedNodes, selectedWays, angleSeparation); 59 60 if (cmds != null) 60 Main .main.undoRedo.add(new SequenceCommand("Create a curve", cmds));61 MainApplication.undoRedo.add(new SequenceCommand("Create a curve", cmds)); 61 62 } 62 63 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/OpenPageAction.java
r32410 r33579 18 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 20 import org.openstreetmap.josm.gui.MainApplication; 21 import org.openstreetmap.josm.gui.MapView; 22 import org.openstreetmap.josm.tools.Logging; 20 23 import org.openstreetmap.josm.tools.OpenBrowser; 21 24 import org.openstreetmap.josm.tools.OsmUrlToBounds; … … 50 53 ChooseURLAction.showConfigDialog(true); 51 54 52 LatLon center = Main.map.mapView.getLatLon(Main.map.mapView.getWidth()/2, Main.map.mapView.getHeight()/2); 55 MapView mv = MainApplication.getMap().mapView; 56 LatLon center = mv.getLatLon(mv.getWidth()/2, mv.getHeight()/2); 53 57 54 58 String addr = URLList.getSelectedURL(); … … 70 74 val = Double.toString(center.lon()); 71 75 } else if (key.equals("#zoom")) { 72 val = Integer.toString(OsmUrlToBounds.getZoom(Main .map.mapView.getRealBounds()));76 val = Integer.toString(OsmUrlToBounds.getZoom(MainApplication.getMap().mapView.getRealBounds())); 73 77 } else { 74 78 if (p != null) { … … 83 87 } 84 88 } catch (UnsupportedEncodingException ex) { 85 Main.error(ex, "Encoding error");89 Logging.log(Logging.LEVEL_ERROR, "Encoding error", ex); 86 90 return; 87 91 } … … 92 96 OpenBrowser.displayUrl(addr); 93 97 } catch (Exception ex) { 94 Main.error(ex, "Can not open URL " + addr);98 Logging.log(Logging.LEVEL_ERROR, "Can not open URL " + addr, ex); 95 99 } 96 100 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/customurl/URLList.java
r33124 r33579 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.plugins.utilsplugin2.UtilsPlugin2; 17 import org.openstreetmap.josm.tools.Logging; 17 18 18 19 public final class URLList { … … 78 79 } 79 80 } catch (IOException e) { 80 Main.error(e);81 Logging.error(e); 81 82 } 82 83 return items; … … 93 94 } 94 95 } catch (IOException e) { 95 Main.error(e);96 Logging.error(e); 96 97 } finally { 97 98 try { … … 99 100 fw.close(); 100 101 } catch (Exception e) { 101 Main.warn(e);102 Logging.warn(e); 102 103 } 103 104 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonAction.java
r32725 r33579 18 18 import org.openstreetmap.josm.data.osm.Node; 19 19 import org.openstreetmap.josm.data.osm.Way; 20 import org.openstreetmap.josm.gui.MainApplication; 20 21 import org.openstreetmap.josm.tools.Shortcut; 21 22 … … 80 81 cmds.add(new AddCommand(wnew)); 81 82 } 82 Main .main.undoRedo.add(new SequenceCommand(tr("Lat Lon tool"), cmds));83 Main .map.mapView.repaint();83 MainApplication.undoRedo.add(new SequenceCommand(tr("Lat Lon tool"), cmds)); 84 MainApplication.getMap().mapView.repaint(); 84 85 } 85 86 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/latlon/LatLonDialog.java
r32410 r33579 36 36 import org.openstreetmap.josm.data.coor.LatLon; 37 37 import org.openstreetmap.josm.gui.ExtendedDialog; 38 import org.openstreetmap.josm.gui.util.WindowGeometry; 38 39 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 39 40 import org.openstreetmap.josm.tools.GBC; 40 import org.openstreetmap.josm.tools.WindowGeometry;41 41 42 42 public class LatLonDialog extends ExtendedDialog { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTagDialog.java
r33522 r33579 49 49 import org.openstreetmap.josm.data.preferences.ColorProperty; 50 50 import org.openstreetmap.josm.gui.ExtendedDialog; 51 import org.openstreetmap.josm.gui.MainApplication; 51 52 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 52 53 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; … … 55 56 import org.openstreetmap.josm.gui.util.HighlightHelper; 56 57 import org.openstreetmap.josm.gui.util.TableHelper; 58 import org.openstreetmap.josm.gui.util.WindowGeometry; 57 59 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 58 60 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 59 61 import org.openstreetmap.josm.tools.GBC; 60 62 import org.openstreetmap.josm.tools.ImageProvider; 61 import org.openstreetmap.josm.tools. WindowGeometry;63 import org.openstreetmap.josm.tools.Logging; 62 64 63 65 /** … … 138 140 public void actionPerformed(ActionEvent e) { 139 141 if (jt.isSelected()) tableModel.shownTypes.add(type); else tableModel.shownTypes.remove(type); 140 tableModel.updateData(Main .getLayerManager().getEditDataSet().getSelected());142 tableModel.updateData(MainApplication.getLayerManager().getEditDataSet().getSelected()); 141 143 } 142 144 }); … … 181 183 @Override 182 184 public void mouseClicked(MouseEvent e) { 183 if (e.getClickCount() > 1 && Main .isDisplayingMapView()) {185 if (e.getClickCount() > 1 && MainApplication.isDisplayingMapView()) { 184 186 AutoScaleAction.zoomTo(currentSelection); 185 187 } … … 191 193 public void valueChanged(ListSelectionEvent e) { 192 194 currentSelection = getSelectedPrimitives(); 193 if (currentSelection != null && Main .isDisplayingMapView()) {195 if (currentSelection != null && MainApplication.isDisplayingMapView()) { 194 196 if (highlightHelper.highlightOnly(currentSelection)) { 195 Main .map.mapView.repaint();197 MainApplication.getMap().mapView.repaint(); 196 198 } 197 199 } … … 210 212 211 213 private void initAutocompletion() { 212 OsmDataLayer l = Main .getLayerManager().getEditLayer();214 OsmDataLayer l = MainApplication.getLayerManager().getEditLayer(); 213 215 AutoCompletionManager autocomplete = l.data.getAutoCompletionManager(); 214 216 for (int i = 0; i < tableModel.mainTags.length; i++) { … … 227 229 @Override 228 230 public void actionPerformed(ActionEvent e) { 229 if (Main .isDisplayingMapView()) {231 if (MainApplication.isDisplayingMapView()) { 230 232 AutoScaleAction.zoomTo(currentSelection); 231 233 } … … 235 237 @Override 236 238 public void actionPerformed(ActionEvent e) { 237 Main .getLayerManager().getEditDataSet().setSelected(getSelectedPrimitives());239 MainApplication.getLayerManager().getEditDataSet().setSelected(getSelectedPrimitives()); 238 240 } 239 241 }); … … 340 342 341 343 private void specifyTagSet(String s) { 342 Main.info("Multitagger tags="+s);344 Logging.info("Multitagger tags="+s); 343 345 tableModel.setupColumnsFromText(s); 344 346 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/multitagger/MultiTaggerTableModel.java
r32410 r33579 12 12 import javax.swing.table.AbstractTableModel; 13 13 14 import org.openstreetmap.josm.Main;15 14 import org.openstreetmap.josm.command.ChangePropertyCommand; 16 15 import org.openstreetmap.josm.command.Command; … … 20 19 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 21 20 import org.openstreetmap.josm.data.osm.Way; 21 import org.openstreetmap.josm.gui.MainApplication; 22 22 import org.openstreetmap.josm.tools.Geometry; 23 23 … … 49 49 public void setWatchSelection(boolean watchSelection) { 50 50 this.watchSelection = watchSelection; 51 if (watchSelection && Main .getLayerManager().getEditLayer() != null)52 selectionChanged(Main .getLayerManager().getEditDataSet().getSelected());51 if (watchSelection && MainApplication.getLayerManager().getEditLayer() != null) 52 selectionChanged(MainApplication.getLayerManager().getEditDataSet().getSelected()); 53 53 } 54 54 … … 115 115 Command cmd = new ChangePropertyCommand(sel, key, (String) value); 116 116 if (autoCommit) { 117 Main .main.undoRedo.add(cmd);117 MainApplication.undoRedo.add(cmd); 118 118 } else { 119 119 cmds.add(cmd); … … 185 185 186 186 void commit(String commandTitle) { 187 Main .main.undoRedo.add(new SequenceCommand(commandTitle, cmds));187 MainApplication.undoRedo.add(new SequenceCommand(commandTitle, cmds)); 188 188 cmds.clear(); 189 189 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryAction.java
r32410 r33579 12 12 import javax.swing.JOptionPane; 13 13 14 import org.openstreetmap.josm.Main;15 14 import org.openstreetmap.josm.actions.JosmAction; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.gui.MainApplication; 17 17 import org.openstreetmap.josm.gui.Notification; 18 18 import org.openstreetmap.josm.tools.Shortcut; … … 58 58 return; 59 59 60 Main .main.undoRedo.add(replaceCommand);60 MainApplication.undoRedo.add(replaceCommand); 61 61 } catch (IllegalArgumentException ex) { 62 62 new Notification( -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r33522 r33579 33 33 import org.openstreetmap.josm.data.osm.TagCollection; 34 34 import org.openstreetmap.josm.data.osm.Way; 35 import org.openstreetmap.josm.gui.MainApplication; 35 36 import org.openstreetmap.josm.gui.Notification; 36 37 import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog; 38 import org.openstreetmap.josm.tools.Logging; 37 39 import org.openstreetmap.josm.tools.UserCancelException; 38 40 … … 110 112 // FIXME: handle different layers 111 113 List<Command> commands = new ArrayList<>(); 112 Command c = MergeNodesAction.mergeNodes(Main.getLayerManager().getEditLayer(), Arrays.asList(subjectNode, referenceNode), referenceNode); 114 Command c = MergeNodesAction.mergeNodes(MainApplication.getLayerManager().getEditLayer(), 115 Arrays.asList(subjectNode, referenceNode), referenceNode); 113 116 if (c == null) { 114 117 // User canceled … … 197 200 } 198 201 199 Main .getLayerManager().getEditDataSet().setSelected(referenceObject);202 MainApplication.getLayerManager().getEditDataSet().setSelected(referenceObject); 200 203 201 204 return new ReplaceGeometryCommand( … … 236 239 public static ReplaceGeometryCommand buildReplaceWayCommand(Way subjectWay, Way referenceWay) { 237 240 238 Area a = Main .getLayerManager().getEditDataSet().getDataSourceArea();241 Area a = MainApplication.getLayerManager().getEditDataSet().getDataSourceArea(); 239 242 if (!isInArea(subjectWay, a) || !isInArea(referenceWay, a)) { 240 243 throw new ReplaceGeometryException(tr("The ways must be entirely within the downloaded area.")); … … 253 256 } catch (UserCancelException e) { 254 257 // user canceled tag merge dialog 255 Main.trace(e);258 Logging.trace(e); 256 259 return null; 257 260 } … … 354 357 355 358 // Remove geometry way from selection 356 Main .getLayerManager().getEditDataSet().clearSelection(referenceWay);359 MainApplication.getLayerManager().getEditDataSet().clearSelection(referenceWay); 357 360 358 361 // And delete old geometry way -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceMembershipAction.java
r33522 r33579 15 15 import javax.swing.JOptionPane; 16 16 17 import org.openstreetmap.josm.Main;18 17 import org.openstreetmap.josm.actions.JosmAction; 19 18 import org.openstreetmap.josm.command.ChangeCommand; … … 24 23 import org.openstreetmap.josm.data.osm.RelationMember; 25 24 import org.openstreetmap.josm.data.osm.RelationToChildReference; 25 import org.openstreetmap.josm.gui.MainApplication; 26 26 import org.openstreetmap.josm.gui.Notification; 27 27 import org.openstreetmap.josm.tools.MultiMap; … … 45 45 final int affectedRelations = command.getChildren().size(); 46 46 if (affectedRelations > 0) { 47 Main .main.undoRedo.add(command);47 MainApplication.undoRedo.add(command); 48 48 new Notification(trn("Replaced ''{0}'' by ''{1}'' in {2} relation", "Replaced ''{0}'' by ''{1}'' in {2} relations", 49 49 affectedRelations, -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/ConnectedMatch.java
r33522 r33579 6 6 import java.util.Set; 7 7 8 import org.openstreetmap.josm.Main;9 8 import org.openstreetmap.josm.data.osm.Node; 10 9 import org.openstreetmap.josm.data.osm.OsmPrimitive; 11 10 import org.openstreetmap.josm.data.osm.Way; 12 11 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 12 import org.openstreetmap.josm.gui.MainApplication; 13 13 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils; 14 14 … … 32 32 Set<Node> matchedNodes = new HashSet<>(); 33 33 // find all ways that match the expression 34 Collection<Way> allWays = Main .getLayerManager().getEditDataSet().getWays();34 Collection<Way> allWays = MainApplication.getLayerManager().getEditDataSet().getWays(); 35 35 for (Way way : allWays) { 36 36 if (match.match(way)) { … … 39 39 } 40 40 // find all nodes that match the expression 41 Collection<Node> allNodes = Main .getLayerManager().getEditDataSet().getNodes();41 Collection<Node> allNodes = MainApplication.getLayerManager().getEditDataSet().getNodes(); 42 42 for (Node node : allNodes) { 43 43 if (match.match(node)) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/InsideMatch.java
r33522 r33579 5 5 import java.util.HashSet; 6 6 7 import org.openstreetmap.josm.Main;8 7 import org.openstreetmap.josm.data.osm.OsmPrimitive; 9 8 import org.openstreetmap.josm.data.osm.Relation; 10 9 import org.openstreetmap.josm.data.osm.Way; 11 10 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 11 import org.openstreetmap.josm.gui.MainApplication; 12 12 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils; 13 13 … … 28 28 Collection<OsmPrimitive> matchedAreas = new HashSet<>(); 29 29 // find all ways that match the expression 30 Collection<Way> ways = Main .getLayerManager().getEditDataSet().getWays();30 Collection<Way> ways = MainApplication.getLayerManager().getEditDataSet().getWays(); 31 31 for (Way way : ways) { 32 32 if (match.match(way)) { … … 35 35 } 36 36 // find all relations that match the expression 37 Collection<Relation> rels = Main .getLayerManager().getEditDataSet().getRelations();37 Collection<Relation> rels = MainApplication.getLayerManager().getEditDataSet().getRelations(); 38 38 for (Relation rel : rels) { 39 39 if (match.match(rel)) { … … 41 41 } 42 42 } 43 inside = NodeWayUtils.selectAllInside(matchedAreas, Main .getLayerManager().getEditDataSet(), false);43 inside = NodeWayUtils.selectAllInside(matchedAreas, MainApplication.getLayerManager().getEditDataSet(), false); 44 44 } 45 45 -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/search/IntersectingMatch.java
r33522 r33579 6 6 import java.util.Set; 7 7 8 import org.openstreetmap.josm.Main;9 8 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 9 import org.openstreetmap.josm.data.osm.Way; 11 10 import org.openstreetmap.josm.data.osm.search.SearchCompiler; 11 import org.openstreetmap.josm.gui.MainApplication; 12 12 import org.openstreetmap.josm.plugins.utilsplugin2.selection.NodeWayUtils; 13 13 … … 31 31 Collection<Way> matchedWays = new HashSet<>(); 32 32 // find all ways that match the expression 33 Collection<Way> allWays = Main .getLayerManager().getEditDataSet().getWays();33 Collection<Way> allWays = MainApplication.getLayerManager().getEditDataSet().getWays(); 34 34 for (Way way : allWays) { 35 35 if (match.match(way)) { -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectBoundaryAction.java
r33297 r33579 14 14 import javax.swing.JOptionPane; 15 15 16 import org.openstreetmap.josm.Main;17 16 import org.openstreetmap.josm.actions.JosmAction; 18 17 import org.openstreetmap.josm.actions.SelectByInternalPointAction; … … 21 20 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.gui.MainApplication; 23 23 import org.openstreetmap.josm.gui.Notification; 24 24 import org.openstreetmap.josm.tools.Shortcut; … … 58 58 } 59 59 } else { 60 Point p = Main .map.mapView.getMousePosition();61 SelectByInternalPointAction.performSelection(Main .map.mapView.getEastNorth(p.x, p.y), false, false);60 Point p = MainApplication.getMap().mapView.getMousePosition(); 61 SelectByInternalPointAction.performSelection(MainApplication.getMap().mapView.getEastNorth(p.x, p.y), false, false); 62 62 return; 63 63 } -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModNodesAction.java
r33297 r33579 11 11 import java.util.Set; 12 12 13 import org.openstreetmap.josm.Main;14 13 import org.openstreetmap.josm.actions.JosmAction; 15 14 import org.openstreetmap.josm.command.Command; … … 17 16 import org.openstreetmap.josm.data.osm.Node; 18 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.gui.MainApplication; 19 19 import org.openstreetmap.josm.tools.Shortcut; 20 20 … … 42 42 Command cmd = null; 43 43 44 if (Main .main.undoRedo.commands == null) return;45 int num = Main .main.undoRedo.commands.size();44 if (MainApplication.undoRedo.commands == null) return; 45 int num = MainApplication.undoRedo.commands.size(); 46 46 if (num == 0) return; 47 47 int k = 0, idx; 48 48 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 49 49 // we are selecting next command in history if nothing is selected 50 idx = Main .main.undoRedo.commands.indexOf(lastCmd);50 idx = MainApplication.undoRedo.commands.indexOf(lastCmd); 51 51 } else { 52 52 idx = num; … … 56 56 do { // select next history element 57 57 if (idx > 0) idx--; else idx = num-1; 58 cmd = Main .main.undoRedo.commands.get(idx);58 cmd = MainApplication.undoRedo.commands.get(idx); 59 59 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 60 60 nodes.clear(); -
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/selection/SelectModWaysAction.java
r33297 r33579 11 11 import java.util.Set; 12 12 13 import org.openstreetmap.josm.Main;14 13 import org.openstreetmap.josm.actions.JosmAction; 15 14 import org.openstreetmap.josm.command.Command; … … 18 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 19 18 import org.openstreetmap.josm.data.osm.Way; 19 import org.openstreetmap.josm.gui.MainApplication; 20 20 import org.openstreetmap.josm.tools.Shortcut; 21 21 … … 43 43 Command cmd; 44 44 45 if (Main .main.undoRedo.commands == null) return;46 int num = Main .main.undoRedo.commands.size();45 if (MainApplication.undoRedo.commands == null) return; 46 int num = MainApplication.undoRedo.commands.size(); 47 47 if (num == 0) return; 48 48 int k = 0, idx; 49 49 if (selection != null && !selection.isEmpty() && selection.hashCode() == lastHash) { 50 50 // we are selecting next command in history if nothing is selected 51 idx = Main .main.undoRedo.commands.indexOf(lastCmd);51 idx = MainApplication.undoRedo.commands.indexOf(lastCmd); 52 52 } else { 53 53 idx = num; … … 57 57 do { // select next history element 58 58 if (idx > 0) idx--; else idx = num-1; 59 cmd = Main .main.undoRedo.commands.get(idx);59 cmd = MainApplication.undoRedo.commands.get(idx); 60 60 Collection<? extends OsmPrimitive> pp = cmd.getParticipatingPrimitives(); 61 61 ways.clear();
Note:
See TracChangeset
for help on using the changeset viewer.