Changeset 30532 in osm for applications/editors/josm/plugins/addrinterpolation/src
- Timestamp:
- 2014-07-14T04:18:06+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/addrinterpolation/src/org/openstreetmap/josm/plugins/AddrInterpolation/AddrInterpolationDialog.java
r30067 r30532 93 93 private boolean interpolationMethodSet = false; 94 94 95 96 95 // NOTE: The following 2 arrays must match in number of elements and position 97 96 // Tag values for map (Except that 'Numeric' is replaced by actual # on map) … … 99 98 String[] addrInterpolationStrings = { tr("Odd"), tr("Even"), tr("All"), tr("Alphabetic"), tr("Numeric") }; // Translatable names for display 100 99 private final int NumericIndex = 4; 101 private JComboBox addrInterpolationList = null;100 private JComboBox<String> addrInterpolationList = null; 102 101 103 102 // NOTE: The following 2 arrays must match in number of elements and position 104 103 String[] addrInclusionTags = { "actual", "estimate", "potential" }; // Tag values for map 105 104 String[] addrInclusionStrings = { tr("Actual"), tr("Estimate"), tr("Potential") }; // Translatable names for display 106 private JComboBox addrInclusionList = null; 107 108 105 private JComboBox<String> addrInclusionList = null; 109 106 110 107 // For tracking edit changes as group for undo … … 121 118 122 119 ShowDialog(editControlsPane, name); 123 124 } 125 126 120 } 127 121 128 122 private void ShowDialog(JPanel editControlsPane, String name) { … … 160 154 } 161 155 162 163 164 156 // Create edit control items and return JPanel on which they reside 165 157 private JPanel CreateEditControls() { … … 172 164 173 165 editControlsPane.setBorder(BorderFactory.createEmptyBorder(15,15,15,15)); 174 175 166 176 167 String streetName = selectedStreet.get("name"); … … 204 195 205 196 JLabel numberingLabel = new JLabel(tr("Numbering Scheme:")); 206 addrInterpolationList = new JComboBox (addrInterpolationStrings);197 addrInterpolationList = new JComboBox<>(addrInterpolationStrings); 207 198 208 199 JLabel incrementLabel = new JLabel(tr("Increment:")); … … 217 208 218 209 JLabel inclusionLabel = new JLabel(tr("Accuracy:")); 219 addrInclusionList = new JComboBox (addrInclusionStrings);210 addrInclusionList = new JComboBox<>(addrInclusionStrings); 220 211 addrInclusionList.setSelectedIndex(lastAccuracyIndex); 221 212 … … 239 230 } 240 231 241 242 243 232 JPanel optionPanel = CreateOptionalFields(); 244 233 c.gridx = 0; … … 248 237 249 238 editControlsPane.add(optionPanel, c); 250 251 239 252 240 KeyAdapter enterProcessor = new KeyAdapter() { … … 257 245 dialog.dispose(); 258 246 } 259 260 247 } 261 248 } … … 267 254 addrInterpolationList.addKeyListener(enterProcessor); 268 255 incrementTextField.addKeyListener(enterProcessor); 269 270 256 271 257 // Watch when Interpolation Method combo box is selected so that … … 282 268 }); 283 269 284 285 270 // Watch when Interpolation Method combo box is changed so that 286 271 // Numeric increment box can be enabled or disabled. … … 292 277 }); 293 278 294 295 279 editControlsPane.add(cbConvertToHouseNumbers, c); 296 297 298 280 299 281 if (houseNumberNodes.size() > 0) { … … 305 287 editControlsPane.add(new UrlLabel("http://wiki.openstreetmap.org/wiki/JOSM/Plugins/AddrInterpolation", 306 288 tr("More information about this feature"),2), c); 307 308 289 309 290 c.gridx = 0; … … 332 313 } 333 314 334 335 336 315 // Call after both starting and ending housenumbers have been entered - usually when 337 316 // combo box gets focus. … … 368 347 } 369 348 } 370 371 372 349 } else { 373 350 // Test for possible alpha … … 392 369 // Did not detect alpha 393 370 return false; 394 395 } 396 371 } 397 372 return true; 398 399 } 400 401 373 } 402 374 403 375 // Set Interpolation Method combo box to method specified by 'currentMethod' (an OSM key value) … … 423 395 } 424 396 425 426 397 // Set Inclusion Method combo box to method specified by 'currentMethod' (an OSM key value) 427 398 private void SelectInclusion(String currentMethod) { … … 435 406 } 436 407 addrInclusionList.setSelectedIndex(currentIndex); 437 438 } 439 440 408 } 441 409 442 410 // Create optional control fields in a group box … … 485 453 AddEditControlRows(optionalTextLabels, optionalEditFields, editControlsPane); 486 454 487 488 489 455 JPanel optionPanel = new JPanel(new BorderLayout()); 490 456 Border groupBox = BorderFactory.createEtchedBorder(); … … 498 464 } 499 465 500 501 502 466 // Populate dialog for any possible existing settings if editing an existing Address interpolation way 503 467 private void GetExistingMapKeys() { 504 505 468 506 469 // Check all nodes for optional addressing data … … 538 501 CheckNodeForAddressTags(firstNode); 539 502 CheckNodeForAddressTags(lastNode); 540 541 } 542 543 544 545 } 546 503 } 504 } 547 505 548 506 // Check for any existing address data. If found, … … 571 529 lastFullAddress = value; 572 530 } 573 574 } 575 576 531 } 577 532 578 533 // Look for a possible 'associatedStreet' type of relation for selected street … … 609 564 } 610 565 } 611 612 } 613 } 614 566 } 567 } 615 568 } 616 569 617 570 return ""; 618 571 } 619 620 572 621 573 // We can proceed only if there is both a named way (the 'street') and … … 668 620 } 669 621 } 670 671 622 } 672 623 … … 697 648 } 698 649 699 700 650 return isValid; 701 651 } 702 703 652 704 653 /** … … 728 677 } 729 678 730 731 732 679 public void actionPerformed(ActionEvent e) { 733 680 if ("ok".equals(e.getActionCommand())) { … … 735 682 dialog.dispose(); 736 683 } 737 738 684 } else if ("cancel".equals(e.getActionCommand())) { 739 685 dialog.dispose(); 740 741 } 742 } 743 744 686 } 687 } 745 688 746 689 // For Alpha interpolation, return base string … … 757 700 } 758 701 759 760 702 private char LastChar(String strValue) { 761 703 if (strValue.length() > 0) { … … 767 709 } 768 710 769 770 711 // Test for valid positive long int 771 private boolean isLong( String input ) 772 { 712 private boolean isLong( String input ) { 773 713 try 774 714 { … … 791 731 return p.matcher(s).matches(); 792 732 } 793 794 733 795 734 private void InterpolateAlphaSection(int startNodeIndex, int endNodeIndex, String endValueString, … … 828 767 LatLon newHouseNumberPosition = lastHouseNode.getCoor().interpolate(toNode.getCoor(), proportion); 829 768 830 831 832 769 Node newHouseNumberNode = new Node(newHouseNumberPosition); 833 770 currentChar++; … … 850 787 } 851 788 } 852 853 854 } 855 789 } 856 790 857 791 private void CreateAlphaInterpolation(String startValueString, String endValueString) { … … 889 823 // End nodes do not actually contain housenumber value yet (command has not executed), so use user-entered value 890 824 InterpolateAlphaSection(startIndex, addrInterpolationWay.getNodesCount()-1, endValueString, startingChar, endingChar); 891 892 } 893 825 } 894 826 895 827 private double CalculateSegmentLengths(int startNodeIndex, int endNodeIndex, double segmentLengths[]) { … … 905 837 } 906 838 return totalLength; 907 908 } 909 839 } 910 840 911 841 private void InterpolateNumericSection(int startNodeIndex, int endNodeIndex, … … 913 843 long increment) { 914 844 915 916 845 int nSegments =endNodeIndex - startNodeIndex; 917 846 … … 920 849 // Total length of address interpolation way section 921 850 double totalLength= CalculateSegmentLengths(startNodeIndex, endNodeIndex, segmentLengths); 922 923 851 924 852 int nHouses = (int)((endingAddr - startingAddr) / increment) -1; … … 956 884 lastHouseNode = newHouseNumberNode; 957 885 958 959 886 segmentLengths[currentSegment] -= distanceNeeded; // Track amount used 960 887 nHouses -- ; 961 888 } 962 889 } 963 964 965 } 966 890 } 967 891 968 892 private void CreateNumericInterpolation(String startValueString, String endValueString, long increment) { … … 970 894 long startingAddr = Long.parseLong( startValueString ); 971 895 long endingAddr = Long.parseLong( endValueString ); 972 973 896 974 897 // Search for possible anchors from the 2nd node to 2nd from last, interpolating between each anchor … … 1000 923 } 1001 924 1002 1003 925 // Called if user has checked "Convert to House Numbers" checkbox. 1004 926 private void ConvertWayToHousenumbers(String selectedMethod, String startValueString, String endValueString, … … 1011 933 1012 934 CreateAlphaInterpolation(startValueString, endValueString); 1013 1014 935 1015 936 } else { … … 1021 942 } 1022 943 CreateNumericInterpolation(startValueString, endValueString, increment); 1023 1024 } 1025 944 } 1026 945 1027 946 RemoveAddressInterpolationWay(); 1028 947 1029 948 } 1030 1031 949 1032 950 private void RemoveAddressInterpolationWay() { … … 1044 962 1045 963 addrInterpolationWay = null; 1046 1047 } 1048 1049 964 } 1050 965 1051 966 private boolean ValidateAndSave() { … … 1084 999 } else if (selectedMethod.equals("all")) { 1085 1000 1086 } else if (selectedMethod.equals("alphabetic")) {1001 } else if (selectedMethod.equals("alphabetic")) { 1087 1002 errorMessage = ValidateAlphaAddress(startValueString, endValueString); 1088 1003 1089 } else if (selectedMethod.equals("Numeric")) {1004 } else if (selectedMethod.equals("Numeric")) { 1090 1005 1091 1006 if (!ValidNumericIncrementString(incrementString, startAddr, endAddr)) { 1092 1007 errorMessage = tr("Expected valid number for increment"); 1093 1008 } 1094 1095 1009 } 1096 1010 if (!errorMessage.equals("")) { … … 1125 1039 currentDataSet.clearSelection(lastNode); // Workaround for JOSM Bug #3838 1126 1040 } 1127 1128 1041 1129 1042 String interpolationTagValue = selectedMethod; … … 1151 1064 } 1152 1065 1153 1154 1155 1066 if (streetRelationButton.isSelected()) { 1156 1067 … … 1167 1078 } 1168 1079 } 1169 1170 1080 1171 1081 // For all nodes, add to relation and … … 1199 1109 } 1200 1110 1201 1202 1111 private boolean ValidNumericIncrementString(String incrementString, long startingAddr, long endingAddr) { 1203 1112 … … 1215 1124 return true; 1216 1125 } 1217 1218 1219 1126 1220 1127 // Create Associated Street relation, add street, and add to list of commands to perform … … 1228 1135 } 1229 1136 1230 1231 1232 1137 // Read from dialog text box, removing leading and trailing spaces 1233 1138 // Return the string, or null for a zero length string … … 1243 1148 } 1244 1149 1245 1246 1150 // Test if relation contains specified member 1247 1151 // If not already present, it is added … … 1263 1167 } 1264 1168 } 1265 1266 1267 1169 1268 1170 // Check alphabetic style address … … 1316 1218 errorMessage = tr("Starting address letter must be less than ending address letter"); 1317 1219 } 1318 1319 1220 } 1320 1221 1321 1222 return errorMessage; 1322 1223 } 1323 1324 1325 1224 1326 1225 // Convert string addresses to numeric, with error check … … 1353 1252 } 1354 1253 1355 1356 1357 1254 private String GetInterpolationMethod() { 1358 1255 int selectedIndex = addrInterpolationList.getSelectedIndex(); 1359 1256 return addrInterpolationTags[selectedIndex]; 1360 1257 } 1361 1362 1258 1363 1259 private String GetInclusionMethod() { … … 1366 1262 return addrInclusionTags[selectedIndex]; 1367 1263 } 1368 1369 1370 1371 1372 1373 1374 1375 1264 } 1376 1377
Note:
See TracChangeset
for help on using the changeset viewer.