Changeset 5279 in josm
- Timestamp:
- 2012-06-16T15:55:24+02:00 (12 years ago)
- Location:
- trunk/src
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r5278 r5279 58 58 import org.openstreetmap.josm.data.validation.OsmValidator; 59 59 import org.openstreetmap.josm.gui.GettingStarted; 60 import org.openstreetmap.josm.gui.MainApplication.Option; 60 61 import org.openstreetmap.josm.gui.MainMenu; 61 62 import org.openstreetmap.josm.gui.MapFrame; … … 474 475 * @param args The parsed argument list. 475 476 */ 476 public static void preConstructorInit(Map< String, Collection<String>> args) {477 public static void preConstructorInit(Map<Option, Collection<String>> args) { 477 478 ProjectionPreference.setProjection(); 478 479 … … 514 515 515 516 geometry = WindowGeometry.mainWindow("gui.geometry", 516 (args.containsKey( "geometry") ? args.get("geometry").iterator().next() : null),517 !args.containsKey( "no-maximize") && Main.pref.getBoolean("gui.maximized", false));518 } 519 520 public void postConstructorProcessCmdLine(Map< String, Collection<String>> args) {521 if (args.containsKey( "download")) {517 (args.containsKey(Option.GEOMETRY) ? args.get(Option.GEOMETRY).iterator().next() : null), 518 !args.containsKey(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false)); 519 } 520 521 public void postConstructorProcessCmdLine(Map<Option, Collection<String>> args) { 522 if (args.containsKey(Option.DOWNLOAD)) { 522 523 List<File> fileList = new ArrayList<File>(); 523 for (String s : args.get( "download")) {524 for (String s : args.get(Option.DOWNLOAD)) { 524 525 File f = null; 525 526 switch(paramType(s)) { … … 556 557 } 557 558 } 558 if (args.containsKey( "downloadgps")) {559 for (String s : args.get( "downloadgps")) {559 if (args.containsKey(Option.DOWNLOADGPS)) { 560 for (String s : args.get(Option.DOWNLOADGPS)) { 560 561 switch(paramType(s)) { 561 562 case httpUrl: … … 576 577 } 577 578 } 578 if (args.containsKey( "selection")) {579 for (String s : args.get( "selection")) {579 if (args.containsKey(Option.SELECTION)) { 580 for (String s : args.get(Option.SELECTION)) { 580 581 SearchAction.search(s, SearchAction.SearchMode.add); 581 582 } -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r5239 r5279 5 5 6 6 import java.util.ArrayList; 7 import java.util.Arrays;8 7 import java.util.HashMap; 9 import java.util.HashSet;10 8 import java.util.List; 11 9 import java.util.Map; 12 import java.util.Set;13 10 import java.util.regex.Matcher; 14 11 import java.util.regex.Pattern; … … 340 337 } 341 338 342 public Bounds parseBounds(String boundsStr) throws ProjectionConfigurationException {339 public static Bounds parseBounds(String boundsStr) throws ProjectionConfigurationException { 343 340 String[] numStr = boundsStr.split(","); 344 341 if (numStr.length != 4) … … 350 347 } 351 348 352 public double parseDouble(Map<String, String> parameters, String parameterName) throws ProjectionConfigurationException {349 public static double parseDouble(Map<String, String> parameters, String parameterName) throws ProjectionConfigurationException { 353 350 String doubleStr = parameters.get(parameterName); 354 351 if (doubleStr == null && parameters.containsKey(parameterName)) … … 358 355 } 359 356 360 public double parseDouble(String doubleStr, String parameterName) throws ProjectionConfigurationException {357 public static double parseDouble(String doubleStr, String parameterName) throws ProjectionConfigurationException { 361 358 try { 362 359 return Double.parseDouble(doubleStr); … … 367 364 } 368 365 369 public double parseAngle(String angleStr, String parameterName) throws ProjectionConfigurationException {366 public static double parseAngle(String angleStr, String parameterName) throws ProjectionConfigurationException { 370 367 String s = angleStr; 371 368 double value = 0; -
trunk/src/org/openstreetmap/josm/gui/MainApplet.java
r4982 r5279 28 28 import org.openstreetmap.josm.actions.JosmAction; 29 29 import org.openstreetmap.josm.data.ServerSidePreferences; 30 import org.openstreetmap.josm.gui.MainApplication.Option; 30 31 import org.openstreetmap.josm.tools.GBC; 31 32 import org.openstreetmap.josm.tools.I18n; … … 127 128 } 128 129 129 Main.preConstructorInit( args);130 Main.preConstructorInit(Option.fromStringMap(args)); 130 131 Main.parent = frame; 131 132 Main.addListener(); 132 133 133 new MainCaller().postConstructorProcessCmdLine( args);134 new MainCaller().postConstructorProcessCmdLine(Option.fromStringMap(args)); 134 135 135 136 MainMenu m = Main.main.menu; // shortcut -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r5201 r5279 7 7 import java.awt.Image; 8 8 import java.awt.Toolkit; 9 import java.awt.event.ActionEvent;10 9 import java.awt.event.WindowAdapter; 11 10 import java.awt.event.WindowEvent; … … 19 18 import java.security.Permissions; 20 19 import java.security.Policy; 20 import java.util.ArrayList; 21 21 import java.util.Collection; 22 22 import java.util.HashMap; … … 28 28 import javax.swing.RepaintManager; 29 29 import javax.swing.SwingUtilities; 30 31 import gnu.getopt.Getopt; 32 import gnu.getopt.LongOpt; 30 33 31 34 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; … … 95 98 "\tjava -jar josm.jar <options>...\n\n"+ 96 99 tr("options")+":\n"+ 97 "\t--help|- ?|-h"+tr("Show this help")+"\n"+100 "\t--help|-h "+tr("Show this help")+"\n"+ 98 101 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+ 99 102 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+ … … 125 128 } 126 129 127 private static Map<String, Collection<String>> buildCommandLineArgumentMap(String[] args) { 128 Map<String, Collection<String>> argMap = new HashMap<String, Collection<String>>(); 129 for (String arg : args) { 130 if ("-h".equals(arg) || "-?".equals(arg)) { 131 arg = "--help"; 132 } else if ("-v".equals(arg)) { 133 arg = "--version"; 134 } 135 // handle simple arguments like file names, URLs, bounds 136 if (!arg.startsWith("--")) { 137 arg = "--download="+arg; 138 } 139 int i = arg.indexOf('='); 140 String key = i == -1 ? arg.substring(2) : arg.substring(2,i); 141 String value = i == -1 ? "" : arg.substring(i+1); 142 Collection<String> v = argMap.get(key); 143 if (v == null) { 144 v = new LinkedList<String>(); 145 } 146 v.add(value); 147 argMap.put(key, v); 148 } 130 public enum Option { 131 HELP(false), 132 VERSION(false), 133 LANGUAGE(true), 134 RESET_PREFERENCES(false), 135 LOAD_PREFERENCES(true), 136 SET(true), 137 GEOMETRY(true), 138 NO_MAXIMIZE(false), 139 MAXIMIZE(false), 140 DOWNLOAD(true), 141 DOWNLOADGPS(true), 142 SELECTION(true); 143 144 private String name; 145 private boolean requiresArgument; 146 147 private Option(boolean requiresArgument) { 148 this.name = name().toLowerCase().replace("_", "-"); 149 this.requiresArgument = requiresArgument; 150 } 151 152 public String getName() { 153 return name; 154 } 155 156 public boolean requiresArgument() { 157 return requiresArgument; 158 } 159 160 public static Map<Option, Collection<String>> fromStringMap(Map<String, Collection<String>> opts) { 161 Map<Option, Collection<String>> res = new HashMap<Option, Collection<String>>(); 162 for (Map.Entry<String, Collection<String>> e : opts.entrySet()) { 163 Option o = Option.valueOf(e.getKey().toUpperCase().replace("-", "_")); 164 if (o != null) { 165 res.put(o, e.getValue()); 166 } 167 } 168 return res; 169 } 170 } 171 172 private static Map<Option, Collection<String>> buildCommandLineArgumentMap(String[] args) { 173 174 List<LongOpt> los = new ArrayList<LongOpt>(); 175 for (Option o : Option.values()) { 176 los.add(new LongOpt(o.getName(), o.requiresArgument() ? LongOpt.REQUIRED_ARGUMENT : LongOpt.NO_ARGUMENT, null, 0)); 177 } 178 179 Getopt g = new Getopt("JOSM", args, "hv", los.toArray(new LongOpt[0])); 180 181 Map<Option, Collection<String>> argMap = new HashMap<Option, Collection<String>>(); 182 183 int c; 184 while ((c = g.getopt()) != -1 ) { 185 Option opt = null; 186 switch (c) { 187 case 'h': 188 opt = Option.HELP; 189 break; 190 case 'v': 191 opt = Option.VERSION; 192 break; 193 case 0: 194 opt = Option.values()[g.getLongind()]; 195 break; 196 } 197 if (opt != null) { 198 Collection<String> values = argMap.get(opt); 199 if (values == null) { 200 values = new ArrayList<String>(); 201 argMap.put(opt, values); 202 } 203 values.add(g.getOptarg()); 204 } else 205 throw new IllegalArgumentException(); 206 } 207 // positional arguments are a shortcut for the --download ... option 208 for (int i = g.getOptind(); i < args.length; ++i) { 209 Collection<String> values = argMap.get(Option.DOWNLOAD); 210 if (values == null) { 211 values = new ArrayList<String>(); 212 argMap.put(Option.DOWNLOAD, values); 213 } 214 values.add(args[i]); 215 } 216 149 217 return argMap; 150 218 } … … 186 254 187 255 // construct argument table 188 final Map<String, Collection<String>> args = buildCommandLineArgumentMap(argArray); 189 190 if (args.containsKey("version")) { 256 Map<Option, Collection<String>> args = null; 257 try { 258 args = buildCommandLineArgumentMap(argArray); 259 } catch (IllegalArgumentException e) { 260 System.exit(1); 261 } 262 263 if (args.containsKey(Option.VERSION)) { 191 264 System.out.println(Version.getInstance().getAgentString()); 192 265 System.exit(0); … … 195 268 } 196 269 197 Main.pref.init(args.containsKey( "reset-preferences"));270 Main.pref.init(args.containsKey(Option.RESET_PREFERENCES)); 198 271 199 272 // Check if passed as parameter 200 if (args.containsKey( "language")) {201 I18n.set(args.get( "language").iterator().next());273 if (args.containsKey(Option.LANGUAGE)) { 274 I18n.set(args.get(Option.LANGUAGE).iterator().next()); 202 275 } else { 203 276 I18n.set(Main.pref.get("language", null)); … … 208 281 Main.parent = mainFrame; 209 282 210 if (args.containsKey( "load-preferences")) {283 if (args.containsKey(Option.LOAD_PREFERENCES)) { 211 284 CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref); 212 for (String i : args.get( "load-preferences")) {285 for (String i : args.get(Option.LOAD_PREFERENCES)) { 213 286 System.out.println("Reading preferences from " + i); 214 287 try { … … 221 294 } 222 295 223 if (args.containsKey( "set")) {224 for (String i : args.get( "set")) {296 if (args.containsKey(Option.SET)) { 297 for (String i : args.get(Option.SET)) { 225 298 String[] kv = i.split("=", 2); 226 299 Main.pref.put(kv[0], "null".equals(kv[1]) ? null : kv[1]); … … 234 307 235 308 // asking for help? show help and exit 236 if (args.containsKey( "help")) {309 if (args.containsKey(Option.HELP)) { 237 310 showHelp(); 238 311 System.exit(0); … … 278 351 279 352 boolean maximized = Boolean.parseBoolean(Main.pref.get("gui.maximized")); 280 if ((!args.containsKey( "no-maximize") && maximized) || args.containsKey("maximize")) {353 if ((!args.containsKey(Option.NO_MAXIMIZE) && maximized) || args.containsKey(Option.MAXIMIZE)) { 281 354 if (Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH)) { 282 355 // Main.debug("Main window maximized"); … … 292 365 main.menu.fullscreenToggleAction.initial(); 293 366 } 367 368 final Map<Option, Collection<String>> args_final = args; 294 369 295 370 SwingUtilities.invokeLater(new Runnable() { … … 319 394 } 320 395 321 main.postConstructorProcessCmdLine(args );396 main.postConstructorProcessCmdLine(args_final); 322 397 323 398 DownloadDialog.autostartIfNeeded();
Note:
See TracChangeset
for help on using the changeset viewer.