Changeset 12792 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-09-08T22:02:38+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/JumpToAction.java
r12639 r12792 20 20 import org.openstreetmap.josm.data.Bounds; 21 21 import org.openstreetmap.josm.data.coor.LatLon; 22 import org.openstreetmap.josm.data.coor.conversion.LatLonParser; 22 23 import org.openstreetmap.josm.gui.ExtendedDialog; 23 24 import org.openstreetmap.josm.gui.MainApplication; … … 161 162 } catch (NumberFormatException ex) { 162 163 try { 163 ll = LatLon .parse(lat.getText() + "; " + lon.getText());164 ll = LatLonParser.parse(lat.getText() + "; " + lon.getText()); 164 165 } catch (IllegalArgumentException ex2) { 165 166 JOptionPane.showMessageDialog(Main.parent, -
trunk/src/org/openstreetmap/josm/data/coor/LatLon.java
r12745 r12792 15 15 import java.text.DecimalFormat; 16 16 import java.text.NumberFormat; 17 import java.util.ArrayList;18 17 import java.util.Arrays; 19 import java.util.List;20 18 import java.util.Locale; 21 19 import java.util.Objects; 22 import java.util.regex.Matcher;23 import java.util.regex.Pattern;24 20 25 21 import org.openstreetmap.josm.Main; … … 27 23 import org.openstreetmap.josm.data.coor.conversion.DMSCoordinateFormat; 28 24 import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat; 25 import org.openstreetmap.josm.data.coor.conversion.LatLonParser; 29 26 import org.openstreetmap.josm.data.coor.conversion.NauticalCoordinateFormat; 30 27 import org.openstreetmap.josm.tools.Logging; … … 89 86 } 90 87 91 /** Character denoting South, as string */ 88 /** 89 * Character denoting South, as string. 90 * @deprecated use {@link LatLonParser#SOUTH} 91 */ 92 @Deprecated 92 93 public static final String SOUTH = trc("compass", "S"); 93 /** Character denoting North, as string */ 94 /** 95 * Character denoting North, as string. 96 * @deprecated use {@link LatLonParser#NORTH} 97 */ 98 @Deprecated 94 99 public static final String NORTH = trc("compass", "N"); 95 /** Character denoting West, as string */ 100 /** 101 * Character denoting West, as string. 102 * @deprecated use {@link LatLonParser#WEST} 103 */ 104 @Deprecated 96 105 public static final String WEST = trc("compass", "W"); 97 /** Character denoting East, as string */ 106 /** 107 * Character denoting East, as string. 108 * @deprecated use {@link LatLonParser#EAST} 109 */ 110 @Deprecated 98 111 public static final String EAST = trc("compass", "E"); 99 100 private static final char N_TR = NORTH.charAt(0);101 private static final char S_TR = SOUTH.charAt(0);102 private static final char E_TR = EAST.charAt(0);103 private static final char W_TR = WEST.charAt(0);104 105 private static final String DEG = "\u00B0";106 private static final String MIN = "\u2032";107 private static final String SEC = "\u2033";108 109 private static final Pattern P = Pattern.compile(110 "([+|-]?\\d+[.,]\\d+)|" // (1)111 + "([+|-]?\\d+)|" // (2)112 + "("+DEG+"|o|deg)|" // (3)113 + "('|"+MIN+"|min)|" // (4)114 + "(\"|"+SEC+"|sec)|" // (5)115 + "(,|;)|" // (6)116 + "([NSEW"+N_TR+S_TR+E_TR+W_TR+"])|"// (7)117 + "\\s+|"118 + "(.+)", Pattern.CASE_INSENSITIVE);119 120 private static final Pattern P_XML = Pattern.compile(121 "lat=[\"']([+|-]?\\d+[.,]\\d+)[\"']\\s+lon=[\"']([+|-]?\\d+[.,]\\d+)[\"']");122 112 123 113 /** … … 517 507 } 518 508 519 private static class LatLonHolder {520 private double lat = Double.NaN;521 private double lon = Double.NaN;522 }523 524 private static void setLatLonObj(final LatLonHolder latLon,525 final Object coord1deg, final Object coord1min, final Object coord1sec, final Object card1,526 final Object coord2deg, final Object coord2min, final Object coord2sec, final Object card2) {527 528 setLatLon(latLon,529 (Double) coord1deg, (Double) coord1min, (Double) coord1sec, (String) card1,530 (Double) coord2deg, (Double) coord2min, (Double) coord2sec, (String) card2);531 }532 533 private static void setLatLon(final LatLonHolder latLon,534 final double coord1deg, final double coord1min, final double coord1sec, final String card1,535 final double coord2deg, final double coord2min, final double coord2sec, final String card2) {536 537 setLatLon(latLon, coord1deg, coord1min, coord1sec, card1);538 setLatLon(latLon, coord2deg, coord2min, coord2sec, card2);539 if (Double.isNaN(latLon.lat) || Double.isNaN(latLon.lon)) {540 throw new IllegalArgumentException("invalid lat/lon parameters");541 }542 }543 544 private static void setLatLon(final LatLonHolder latLon, final double coordDeg, final double coordMin, final double coordSec,545 final String card) {546 if (coordDeg < -180 || coordDeg > 180 || coordMin < 0 || coordMin >= 60 || coordSec < 0 || coordSec > 60) {547 throw new IllegalArgumentException("out of range");548 }549 550 double coord = (coordDeg < 0 ? -1 : 1) * (Math.abs(coordDeg) + coordMin / 60 + coordSec / 3600);551 coord = "N".equals(card) || "E".equals(card) ? coord : -coord;552 if ("N".equals(card) || "S".equals(card)) {553 latLon.lat = coord;554 } else {555 latLon.lon = coord;556 }557 }558 559 509 /** 560 510 * Parses the given string as lat/lon. … … 562 512 * @return parsed lat/lon 563 513 * @since 11045 564 */ 514 * @deprecated use {@link LatLonParser#parse(java.lang.String)} 515 */ 516 @Deprecated 565 517 public static LatLon parse(String coord) { 566 final LatLonHolder latLon = new LatLonHolder(); 567 final Matcher mXml = P_XML.matcher(coord); 568 if (mXml.matches()) { 569 setLatLonObj(latLon, 570 Double.valueOf(mXml.group(1).replace(',', '.')), 0.0, 0.0, "N", 571 Double.valueOf(mXml.group(2).replace(',', '.')), 0.0, 0.0, "E"); 572 } else { 573 final Matcher m = P.matcher(coord); 574 575 final StringBuilder sb = new StringBuilder(); 576 final List<Object> list = new ArrayList<>(); 577 578 while (m.find()) { 579 if (m.group(1) != null) { 580 sb.append('R'); // floating point number 581 list.add(Double.valueOf(m.group(1).replace(',', '.'))); 582 } else if (m.group(2) != null) { 583 sb.append('Z'); // integer number 584 list.add(Double.valueOf(m.group(2))); 585 } else if (m.group(3) != null) { 586 sb.append('o'); // degree sign 587 } else if (m.group(4) != null) { 588 sb.append('\''); // seconds sign 589 } else if (m.group(5) != null) { 590 sb.append('"'); // minutes sign 591 } else if (m.group(6) != null) { 592 sb.append(','); // separator 593 } else if (m.group(7) != null) { 594 sb.append('x'); // cardinal direction 595 String c = m.group(7).toUpperCase(Locale.ENGLISH); 596 if ("N".equalsIgnoreCase(c) || "S".equalsIgnoreCase(c) || "E".equalsIgnoreCase(c) || "W".equalsIgnoreCase(c)) { 597 list.add(c); 598 } else { 599 list.add(c.replace(N_TR, 'N').replace(S_TR, 'S') 600 .replace(E_TR, 'E').replace(W_TR, 'W')); 601 } 602 } else if (m.group(8) != null) { 603 throw new IllegalArgumentException("invalid token: " + m.group(8)); 604 } 605 } 606 607 final String pattern = sb.toString(); 608 609 final Object[] params = list.toArray(); 610 611 if (pattern.matches("Ro?,?Ro?")) { 612 setLatLonObj(latLon, 613 params[0], 0.0, 0.0, "N", 614 params[1], 0.0, 0.0, "E"); 615 } else if (pattern.matches("xRo?,?xRo?")) { 616 setLatLonObj(latLon, 617 params[1], 0.0, 0.0, params[0], 618 params[3], 0.0, 0.0, params[2]); 619 } else if (pattern.matches("Ro?x,?Ro?x")) { 620 setLatLonObj(latLon, 621 params[0], 0.0, 0.0, params[1], 622 params[2], 0.0, 0.0, params[3]); 623 } else if (pattern.matches("Zo[RZ]'?,?Zo[RZ]'?|Z[RZ],?Z[RZ]")) { 624 setLatLonObj(latLon, 625 params[0], params[1], 0.0, "N", 626 params[2], params[3], 0.0, "E"); 627 } else if (pattern.matches("xZo[RZ]'?,?xZo[RZ]'?|xZo?[RZ],?xZo?[RZ]")) { 628 setLatLonObj(latLon, 629 params[1], params[2], 0.0, params[0], 630 params[4], params[5], 0.0, params[3]); 631 } else if (pattern.matches("Zo[RZ]'?x,?Zo[RZ]'?x|Zo?[RZ]x,?Zo?[RZ]x")) { 632 setLatLonObj(latLon, 633 params[0], params[1], 0.0, params[2], 634 params[3], params[4], 0.0, params[5]); 635 } else if (pattern.matches("ZoZ'[RZ]\"?x,?ZoZ'[RZ]\"?x|ZZ[RZ]x,?ZZ[RZ]x")) { 636 setLatLonObj(latLon, 637 params[0], params[1], params[2], params[3], 638 params[4], params[5], params[6], params[7]); 639 } else if (pattern.matches("xZoZ'[RZ]\"?,?xZoZ'[RZ]\"?|xZZ[RZ],?xZZ[RZ]")) { 640 setLatLonObj(latLon, 641 params[1], params[2], params[3], params[0], 642 params[5], params[6], params[7], params[4]); 643 } else if (pattern.matches("ZZ[RZ],?ZZ[RZ]")) { 644 setLatLonObj(latLon, 645 params[0], params[1], params[2], "N", 646 params[3], params[4], params[5], "E"); 647 } else { 648 throw new IllegalArgumentException("invalid format: " + pattern); 649 } 650 } 651 652 return new LatLon(latLon.lat, latLon.lon); 518 return LatLonParser.parse(coord); 653 519 } 654 520 } -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r12620 r12792 19 19 import org.openstreetmap.josm.data.coor.EastNorth; 20 20 import org.openstreetmap.josm.data.coor.LatLon; 21 import org.openstreetmap.josm.data.coor.conversion.LatLonParser; 21 22 import org.openstreetmap.josm.data.projection.datum.CentricDatum; 22 23 import org.openstreetmap.josm.data.projection.datum.Datum; … … 655 656 /** 656 657 * Convert an angle string to a double value 657 * @param angleStr The string. e.g. -1.1 or 50d 10'3"658 * @param angleStr The string. e.g. -1.1 or 50d10'3" 658 659 * @param parameterName Only for error message. 659 660 * @return The angle value, in degrees. … … 661 662 */ 662 663 public static double parseAngle(String angleStr, String parameterName) throws ProjectionConfigurationException { 663 final String floatPattern = "(\\d+(\\.\\d*)?)"; 664 // pattern does all error handling. 665 Matcher in = Pattern.compile("^(?<neg1>-)?" 666 + "(?=\\d)(?:(?<single>" + floatPattern + ")|" 667 + "((?<degree>" + floatPattern + ")d)?" 668 + "((?<minutes>" + floatPattern + ")\')?" 669 + "((?<seconds>" + floatPattern + ")\")?)" 670 + "(?:[NE]|(?<neg2>[SW]))?$").matcher(angleStr); 671 672 if (!in.find()) { 664 try { 665 return LatLonParser.parseCoordinate(angleStr); 666 } catch (IllegalArgumentException e) { 673 667 throw new ProjectionConfigurationException( 674 668 tr("Unable to parse value ''{1}'' of parameter ''{0}'' as coordinate value.", parameterName, angleStr)); 675 669 } 676 677 double value = 0;678 if (in.group("single") != null) {679 value += Double.parseDouble(in.group("single"));680 }681 if (in.group("degree") != null) {682 value += Double.parseDouble(in.group("degree"));683 }684 if (in.group("minutes") != null) {685 value += Double.parseDouble(in.group("minutes")) / 60;686 }687 if (in.group("seconds") != null) {688 value += Double.parseDouble(in.group("seconds")) / 3600;689 }690 691 if (in.group("neg1") != null ^ in.group("neg2") != null) {692 value = -value;693 }694 return value;695 670 } 696 671 … … 915 890 return result; 916 891 } 892 893 /** 894 * Return true, if a geographic coordinate reference system is represented. 895 * 896 * I.e. if it returns latitude/longitude values rather than Cartesian 897 * east/north coordinates on a flat surface. 898 * @return true, if it is geographic 899 * @since 12792 900 */ 901 public boolean isGeographic() { 902 return proj.isGeographic(); 903 } 904 917 905 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12790 r12792 34 34 import java.util.Locale; 35 35 import java.util.Map; 36 import java.util.Objects; 36 37 import java.util.Optional; 37 38 import java.util.Set; … … 61 62 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; 62 63 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 64 import org.openstreetmap.josm.CLIModule; 63 65 import org.openstreetmap.josm.Main; 64 66 import org.openstreetmap.josm.actions.DeleteAction; … … 85 87 import org.openstreetmap.josm.data.osm.UserInfo; 86 88 import org.openstreetmap.josm.data.osm.search.SearchMode; 89 import org.openstreetmap.josm.data.projection.ProjectionCLI; 87 90 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileSource; 88 91 import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper; … … 163 166 * Command-line arguments used to run the application. 164 167 */ 165 private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();168 private static List<String> commandLineArgs; 166 169 167 170 /** … … 230 233 public void layerAdded(LayerAddEvent e) { 231 234 // Do nothing 235 } 236 }; 237 238 private static final List<CLIModule> cliModules = new ArrayList<>(); 239 240 /** 241 * Default JOSM command line interface. 242 * <p> 243 * Runs JOSM and performs some action, depending on the options and positional 244 * arguments. 245 */ 246 public static final CLIModule JOSM_CLI_MODULE = new CLIModule() { 247 @Override 248 public String getActionKeyword() { 249 return "runjosm"; 250 } 251 252 @Override 253 public void processArguments(String[] argArray) { 254 ProgramArguments args = null; 255 // construct argument table 256 try { 257 args = new ProgramArguments(argArray); 258 } catch (IllegalArgumentException e) { 259 System.err.println(e.getMessage()); 260 System.exit(1); 261 } 262 mainJOSM(args); 232 263 } 233 264 }; … … 256 287 } 257 288 }; 289 290 static { 291 registerCLIModue(JOSM_CLI_MODULE); 292 registerCLIModue(ProjectionCLI.INSTANCE); 293 } 294 295 /** 296 * Register a command line interface module. 297 * @param module the module 298 * @since 12792 299 */ 300 public static void registerCLIModue(CLIModule module) { 301 cliModules.add(module); 302 } 258 303 259 304 /** … … 488 533 */ 489 534 public static List<String> getCommandLineArgs() { 490 return Collections.unmodifiableList( COMMAND_LINE_ARGS);535 return Collections.unmodifiableList(commandLineArgs); 491 536 } 492 537 … … 766 811 public static void main(final String[] argArray) { 767 812 I18n.init(); 768 769 ProgramArguments args = null; 770 // construct argument table 771 try { 772 args = new ProgramArguments(argArray); 773 } catch (IllegalArgumentException e) { 774 System.err.println(e.getMessage()); 775 System.exit(1); 776 return; 777 } 813 commandLineArgs = Arrays.asList(Arrays.copyOf(argArray, argArray.length)); 814 815 if (argArray.length > 0) { 816 String moduleStr = argArray[0]; 817 for (CLIModule module : cliModules) { 818 if (Objects.equals(moduleStr, module.getActionKeyword())) { 819 String[] argArrayCdr = Arrays.copyOfRange(argArray, 1, argArray.length); 820 module.processArguments(argArrayCdr); 821 return; 822 } 823 } 824 } 825 // no module specified, use default (josm) 826 JOSM_CLI_MODULE.processArguments(argArray); 827 } 828 829 /** 830 * Main method to run the JOSM GUI. 831 * @param args program arguments 832 */ 833 public static void mainJOSM(ProgramArguments args) { 778 834 779 835 if (!GraphicsEnvironment.isHeadless()) { … … 821 877 return; 822 878 } 823 824 COMMAND_LINE_ARGS.addAll(Arrays.asList(argArray));825 879 826 880 boolean skipLoadingPlugins = args.hasOption(Option.SKIP_PLUGINS); -
trunk/src/org/openstreetmap/josm/gui/ProgramArguments.java
r12633 r12792 113 113 */ 114 114 private void buildCommandLineArgumentMap(String... args) { 115 LongOpt[] los = Stream.of(Option.values()).map(Option::toLongOpt).toArray( i -> new LongOpt[i]);115 LongOpt[] los = Stream.of(Option.values()).map(Option::toLongOpt).toArray(LongOpt[]::new); 116 116 117 117 Getopt g = new Getopt("JOSM", args, "hv", los); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LatLonDialog.java
r12735 r12792 27 27 import org.openstreetmap.josm.data.coor.LatLon; 28 28 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 29 import org.openstreetmap.josm.data.coor.conversion.LatLonParser; 29 30 import org.openstreetmap.josm.gui.ExtendedDialog; 30 31 import org.openstreetmap.josm.gui.util.WindowGeometry; … … 245 246 LatLon latLon; 246 247 try { 247 latLon = LatLon .parse(tfLatLon.getText());248 latLon = LatLonParser.parse(tfLatLon.getText()); 248 249 if (!LatLon.isValidLat(latLon.lat()) || !LatLon.isValidLon(latLon.lon())) { 249 250 latLon = null;
Note:
See TracChangeset
for help on using the changeset viewer.