Changeset 12892 in josm


Ignore:
Timestamp:
2017-09-24T09:25:26+02:00 (7 years ago)
Author:
bastiK
Message:

see #15229 - remove dependency of getopt library on JOSM classes

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gnu/getopt/Getopt.java

    r10209 r12892  
    2121package gnu.getopt;
    2222
    23 import static org.openstreetmap.josm.tools.I18n.tr;
    24 
    2523import java.text.MessageFormat;
    2624import java.util.HashMap;
    2725import java.util.Map;
     26import java.util.function.Function;
    2827
    2928/**************************************************************************/
     
    582581/**************************************************************************/
    583582
     583private static Function<String, String> tr = Function.identity();
     584
     585/**
     586 * Set the global translation handler for Getopt.
     587 *
     588 * This needs to be done before any call to {@link Getopt} or {@link LongOpt}
     589 * constructor.
     590 * @param tr function that takes messages in English and returns the localized message
     591 */
     592public static void setI18nHandler(Function<String, String> tr) {
     593    Getopt.tr = tr;
     594}
     595
    584596static class OptI18n {
     597
     598    private final Map<String, String> trns = new HashMap<>();
     599
    585600    public  OptI18n() {
    586601        add("getopt.ambigious", tr("{0}: option ''{1}'' is ambiguous"));
     
    596611    }
    597612
    598     Map<String, String> trns = new HashMap<String, String>();
     613    private String tr(String s) {
     614        return Getopt.tr.apply(s);
     615    }
    599616
    600617    private void add(String key, String value) {
  • trunk/src/org/openstreetmap/josm/data/projection/ProjectionCLI.java

    r12846 r12892  
    1919import org.openstreetmap.josm.data.coor.LatLon;
    2020import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
     21import org.openstreetmap.josm.tools.I18n;
    2122import org.openstreetmap.josm.tools.Utils;
    2223
     
    4344    @Override
    4445    public void processArguments(String[] argArray) {
     46        Getopt.setI18nHandler(I18n::tr);
    4547        Getopt getopt = new Getopt("JOSM projection", argArray, "Irh", new LongOpt[] {
    4648                new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h')});
  • trunk/src/org/openstreetmap/josm/gui/ProgramArguments.java

    r12792 r12892  
    1414import java.util.stream.Stream;
    1515
     16import org.openstreetmap.josm.tools.I18n;
    1617import org.openstreetmap.josm.tools.Logging;
    1718
     
    115116        LongOpt[] los = Stream.of(Option.values()).map(Option::toLongOpt).toArray(LongOpt[]::new);
    116117
     118        Getopt.setI18nHandler(I18n::tr);
    117119        Getopt g = new Getopt("JOSM", args, "hv", los);
    118120
Note: See TracChangeset for help on using the changeset viewer.