Ignore:
Timestamp:
2017-09-08T22:02:38+02:00 (7 years ago)
Author:
bastiK
Message:

closes #15273, see #15229, see #15182 - add command line interface module for projections

  • run josm project --help to see the options
  • extracts parser from LatLon and CustomProjection into LatLonParser
Location:
trunk/src/org/openstreetmap/josm/gui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12790 r12792  
    3434import java.util.Locale;
    3535import java.util.Map;
     36import java.util.Objects;
    3637import java.util.Optional;
    3738import java.util.Set;
     
    6162import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
    6263import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
     64import org.openstreetmap.josm.CLIModule;
    6365import org.openstreetmap.josm.Main;
    6466import org.openstreetmap.josm.actions.DeleteAction;
     
    8587import org.openstreetmap.josm.data.osm.UserInfo;
    8688import org.openstreetmap.josm.data.osm.search.SearchMode;
     89import org.openstreetmap.josm.data.projection.ProjectionCLI;
    8790import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileSource;
    8891import org.openstreetmap.josm.data.projection.datum.NTV2GridShiftFileWrapper;
     
    163166     * Command-line arguments used to run the application.
    164167     */
    165     private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();
     168    private static List<String> commandLineArgs;
    166169
    167170    /**
     
    230233        public void layerAdded(LayerAddEvent e) {
    231234            // 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);
    232263        }
    233264    };
     
    256287        }
    257288    };
     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    }
    258303
    259304    /**
     
    488533     */
    489534    public static List<String> getCommandLineArgs() {
    490         return Collections.unmodifiableList(COMMAND_LINE_ARGS);
     535        return Collections.unmodifiableList(commandLineArgs);
    491536    }
    492537
     
    766811    public static void main(final String[] argArray) {
    767812        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) {
    778834
    779835        if (!GraphicsEnvironment.isHeadless()) {
     
    821877            return;
    822878        }
    823 
    824         COMMAND_LINE_ARGS.addAll(Arrays.asList(argArray));
    825879
    826880        boolean skipLoadingPlugins = args.hasOption(Option.SKIP_PLUGINS);
  • trunk/src/org/openstreetmap/josm/gui/ProgramArguments.java

    r12633 r12792  
    113113     */
    114114    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);
    116116
    117117        Getopt g = new Getopt("JOSM", args, "hv", los);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/LatLonDialog.java

    r12735 r12792  
    2727import org.openstreetmap.josm.data.coor.LatLon;
    2828import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;
     29import org.openstreetmap.josm.data.coor.conversion.LatLonParser;
    2930import org.openstreetmap.josm.gui.ExtendedDialog;
    3031import org.openstreetmap.josm.gui.util.WindowGeometry;
     
    245246        LatLon latLon;
    246247        try {
    247             latLon = LatLon.parse(tfLatLon.getText());
     248            latLon = LatLonParser.parse(tfLatLon.getText());
    248249            if (!LatLon.isValidLat(latLon.lat()) || !LatLon.isValidLon(latLon.lon())) {
    249250                latLon = null;
Note: See TracChangeset for help on using the changeset viewer.