Changeset 1104 in josm for trunk/src/org
- Timestamp:
- 2008-12-05T23:48:41+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r1098 r1104 66 66 67 67 abstract public class Main { 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 68 /** 69 * Global parent component for all dialogs and message boxes 70 */ 71 public static Component parent; 72 /** 73 * Global application. 74 */ 75 public static Main main; 76 /** 77 * The worker thread slave. This is for executing all long and intensive 78 * calculations. The executed runnables are guaranteed to be executed separately 79 * and sequential. 80 */ 81 public final static Executor worker = Executors.newSingleThreadExecutor(); 82 /** 83 * Global application preferences 84 */ 85 public static Preferences pref = new Preferences(); 86 /** 87 * The global dataset. 88 */ 89 public static DataSet ds = new DataSet(); 90 /** 91 * The global paste buffer. 92 */ 93 public static DataSet pasteBuffer = new DataSet(); 94 /** 95 * The projection method used. 96 */ 97 public static Projection proj; 98 /** 99 * The MapFrame. Use setMapFrame to set or clear it. 100 */ 101 public static MapFrame map; 102 /** 103 * All installed and loaded plugins (resp. their main classes) 104 */ 105 public final static Collection<PluginProxy> plugins = new LinkedList<PluginProxy>(); 106 /** 107 * The dialog that gets displayed during background task execution. 108 */ 109 public static PleaseWaitDialog pleaseWaitDlg; 110 111 /** 112 * True, when in applet mode 113 */ 114 public static boolean applet = false; 115 116 /** 117 * The toolbar preference control to register new actions. 118 */ 119 public static ToolbarPreferences toolbar; 120 121 122 public UndoRedoHandler undoRedo = new UndoRedoHandler(); 123 124 /** 125 * The main menu bar at top of screen. 126 */ 127 public final MainMenu menu; 128 129 /** 130 * Print a debug message if debugging is on. 131 */ 132 static public int debug_level = 1; 133 static public final void debug(String msg) { 134 if (debug_level <= 0) 135 return; 136 System.out.println(msg); 137 } 138 139 /** 140 * Platform specific code goes in here. 141 * Plugins may replace it, however, some hooks will be called before any plugins have been loeaded. 142 * So if you need to hook into those early ones, split your class and send the one with the early hooks 143 * to the JOSM team for inclusion. 144 */ 145 public static PlatformHook platform; 146 147 /** 148 * Set or clear (if passed <code>null</code>) the map. 149 */ 150 public final void setMapFrame(final MapFrame map) { 151 MapFrame old = Main.map; 152 Main.map = map; 153 panel.setVisible(false); 154 panel.removeAll(); 155 if (map != null) 156 map.fillPanel(panel); 157 else { 158 old.destroy(); 159 panel.add(new GettingStarted(), BorderLayout.CENTER); 160 } 161 panel.setVisible(true); 162 redoUndoListener.commandChanged(0,0); 163 164 for (PluginProxy plugin : plugins) 165 plugin.mapFrameInitialized(old, map); 166 } 167 168 /** 169 * Set the layer menu (changed when active layer changes). 170 */ 171 public final void setLayerMenu(Component[] entries) { 172 //if (entries == null || entries.length == 0) 173 //menu.layerMenu.setVisible(false); 174 //else { 175 //menu.layerMenu.removeAll(); 176 //for (Component c : entries) 177 //menu.layerMenu.add(c); 178 //menu.layerMenu.setVisible(true); 179 //} 180 } 181 182 /** 183 * Remove the specified layer from the map. If it is the last layer, 184 184 * remove the map as well. 185 186 187 188 189 190 191 192 193 194 195 196 // 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 185 */ 186 public final void removeLayer(final Layer layer) { 187 map.mapView.removeLayer(layer); 188 if (layer instanceof OsmDataLayer) 189 ds = new DataSet(); 190 if (map.mapView.getAllLayers().isEmpty()) 191 setMapFrame(null); 192 } 193 194 public Main() { 195 main = this; 196 // platform = determinePlatformHook(); 197 platform.startupHook(); 198 contentPane.add(panel, BorderLayout.CENTER); 199 panel.add(new GettingStarted(), BorderLayout.CENTER); 200 menu = new MainMenu(); 201 202 undoRedo.listenerCommands.add(redoUndoListener); 203 204 // creating toolbar 205 contentPane.add(toolbar.control, BorderLayout.NORTH); 206 207 contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke(), "Help"); 208 contentPane.getActionMap().put("Help", menu.help); 209 210 TaggingPresetPreference.initialize(); 211 MapPaintPreference.initialize(); 212 213 toolbar.refreshToolbarControl(); 214 215 toolbar.control.updateUI(); 216 contentPane.updateUI(); 217 } 218 219 /** 220 * Load all plugins specified in preferences. If the parameter is 221 221 * <code>true</code>, all early plugins are loaded (before constructor). 222 */ 223 public static void loadPlugins(boolean early) { 224 List<String> plugins = new LinkedList<String>(); 225 Collection<String> cp = Main.pref.getCollection("plugins", null); 226 if (cp != null) 227 plugins.addAll(cp); 228 if (System.getProperty("josm.plugins") != null) 229 plugins.addAll(Arrays.asList(System.getProperty("josm.plugins").split(","))); 230 231 String [] oldplugins = new String[] {"mappaint", "unglueplugin", "lang-de","lang-en_GB","lang-fr","lang-it","lang-pl","lang-ro","lang-ru"}; 232 for (String p : oldplugins) { 233 if (plugins.contains(p)) { 234 plugins.remove(p); 235 Main.pref.removeFromCollection("plugins", p); 236 System.out.println(tr("Warning - loading of {0} plugin was requested. This plugin is no longer required.", p)); 237 } 238 } 239 240 if (plugins.isEmpty()) 241 return; 242 243 SortedMap<Integer, Collection<PluginInformation>> p = new TreeMap<Integer, Collection<PluginInformation>>(); 244 for (String pluginName : plugins) { 245 PluginInformation info = PluginInformation.findPlugin(pluginName); 246 if (info != null) { 247 if (info.early != early) 248 continue; 249 if (info.mainversion != null && info.mainversion.compareTo(AboutAction.version) > 0) { 250 JOptionPane.showMessageDialog(Main.parent, tr("Plugin requires JOSM update: {0}.", pluginName)); 251 continue; 252 } 253 if (!p.containsKey(info.stage)) 254 p.put(info.stage, new LinkedList<PluginInformation>()); 255 p.get(info.stage).add(info); 256 } else { 257 if (early) 258 System.out.println("Plugin not found: "+pluginName); // do not translate 259 else 260 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName)); 261 } 262 } 263 264 if (!early) { 265 long tim = System.currentTimeMillis(); 266 long last = Main.pref.getLong("pluginmanager.lastupdate", 0); 267 Integer maxTime = Main.pref.getInteger("pluginmanager.warntime", 30); 268 if (last <= 0) { 269 Main.pref.put("pluginmanager.lastupdate",Long.toString(tim)); 270 } else if (tim - last >= maxTime*1000l*24*60*60) { 271 long d = (tim - last)/(24*60*60*1000l); 272 JOptionPane.showMessageDialog(Main.parent, 273 tr("Last plugin update more than {0} days ago.", d)); 274 } 275 } 276 277 // iterate all plugins and collect all libraries of all plugins: 278 List<URL> allPluginLibraries = new ArrayList<URL>(); 279 for (Collection<PluginInformation> c : p.values()) 280 for (PluginInformation info : c) 281 allPluginLibraries.addAll(info.libraries); 282 // create a classloader for all plugins: 283 URL[] jarUrls = new URL[allPluginLibraries.size()]; 284 jarUrls = allPluginLibraries.toArray(jarUrls); 285 URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader()); 286 ImageProvider.sources.add(0, pluginClassLoader); 287 288 for (Collection<PluginInformation> c : p.values()) { 289 for (PluginInformation info : c) { 290 try { 291 Class<?> klass = info.loadClass(pluginClassLoader); 292 if (klass != null) { 293 System.out.println("loading "+info.name); 294 Main.plugins.add(info.load(klass)); 295 } 296 } catch (Throwable e) { 297 e.printStackTrace(); 298 boolean remove = true; 299 if (early) 300 System.out.println("Could not load plugin: "+info.name+" - deleted from preferences"); // do not translate 301 else { 302 int answer = JOptionPane.showConfirmDialog(Main.parent, 303 tr("Could not load plugin {0}. Delete from preferences?", info.name, 304 JOptionPane.YES_NO_OPTION)); 305 if (answer != JOptionPane.OK_OPTION) { 306 remove = false; 307 } 308 } 309 if (remove) { 310 plugins.remove(info.name); 311 String plist = null; 312 for (String pn : plugins) { 313 if (plist==null) plist=""; else plist=plist+","; 314 plist=plist+pn; 315 } 316 Main.pref.put("plugins", plist); 317 } 318 } 319 } 320 } 321 } 322 323 /** 324 * Add a new layer to the map. If no map exists, create one. 325 */ 326 public final void addLayer(final Layer layer) { 327 if (map == null) { 328 final MapFrame mapFrame = new MapFrame(); 329 setMapFrame(mapFrame); 330 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction()); 331 mapFrame.setVisible(true); 332 mapFrame.setVisibleDialogs(); 333 } 334 map.mapView.addLayer(layer); 335 } 336 /** 337 * @return The edit osm layer. If none exists, it will be created. 338 */ 339 public final OsmDataLayer editLayer() { 340 if (map == null || map.mapView.editLayer == null) 341 menu.newAction.actionPerformed(null); 342 return map.mapView.editLayer; 343 } 344 345 /** 346 * Use this to register shortcuts to 347 */ 348 public static final JPanel contentPane = new JPanel(new BorderLayout()); 349 350 351 /////////////////////////////////////////////////////////////////////////// 352 // Implementation part 353 /////////////////////////////////////////////////////////////////////////// 354 355 public static JPanel panel = new JPanel(new BorderLayout()); 356 357 protected static Rectangle bounds; 358 359 private final CommandQueueListener redoUndoListener = new CommandQueueListener(){ 360 public void commandChanged(final int queueSize, final int redoSize) { 361 menu.undo.setEnabled(queueSize > 0); 362 menu.redo.setEnabled(redoSize > 0); 363 } 364 }; 365 /** 366 * Should be called before the main constructor to setup some parameter stuff 367 * @param args The parsed argument list. 368 */ 369 public static void preConstructorInit(Map<String, Collection<String>> args) { 370 try { 371 Main.proj = (Projection)Class.forName(Main.pref.get("projection")).newInstance(); 372 } catch (final Exception e) { 373 e.printStackTrace(); 374 JOptionPane.showMessageDialog(null, tr("The projection could not be read from preferences. Using EPSG:4263.")); 375 Main.proj = new Epsg4326(); 376 } 377 378 try { 379 UIManager.setLookAndFeel(Main.pref.get("laf")); 380 toolbar = new ToolbarPreferences(); 381 contentPane.updateUI(); 382 panel.updateUI(); 383 } catch (final Exception e) { 384 e.printStackTrace(); 385 } 386 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); 387 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); 388 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); 389 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 390 391 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); 392 if (args.containsKey("geometry")) { 393 String geometry = args.get("geometry").iterator().next(); 394 final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(geometry); 395 if (m.matches()) { 396 int w = Integer.valueOf(m.group(1)); 397 int h = Integer.valueOf(m.group(2)); 398 int x = 0, y = 0; 399 if (m.group(3) != null) { 400 x = Integer.valueOf(m.group(5)); 401 y = Integer.valueOf(m.group(7)); 402 if (m.group(4).equals("-")) 403 x = screenDimension.width - x - w; 404 if (m.group(6).equals("-")) 405 y = screenDimension.height - y - h; 406 } 407 bounds = new Rectangle(x,y,w,h); 408 } else 409 System.out.println("Ignoring malformed geometry: "+geometry); 410 } 411 if (bounds == null) 412 bounds = !args.containsKey("no-fullscreen") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 413 414 // preinitialize a wait dialog for all early downloads (e.g. via command line) 415 pleaseWaitDlg = new PleaseWaitDialog(null); 416 } 417 418 public void postConstructorProcessCmdLine(Map<String, Collection<String>> args) { 419 // initialize the pleaseWaitDialog with the application as parent to handle focus stuff 420 pleaseWaitDlg = new PleaseWaitDialog(parent); 421 422 if (args.containsKey("download")) 423 for (String s : args.get("download")) 424 downloadFromParamString(false, s); 425 if (args.containsKey("downloadgps")) 426 for (String s : args.get("downloadgps")) 427 downloadFromParamString(true, s); 428 if (args.containsKey("selection")) 429 for (String s : args.get("selection")) 430 SearchAction.search(s, SearchAction.SearchMode.add, false); 431 } 432 433 public static boolean breakBecauseUnsavedChanges() { 434 Shortcut.savePrefs(); 435 if (map != null) { 436 boolean modified = false; 437 boolean uploadedModified = false; 438 for (final Layer l : map.mapView.getAllLayers()) { 439 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 440 modified = true; 441 uploadedModified = ((OsmDataLayer)l).uploadedModified; 442 break; 443 } 444 } 445 if (modified) { 446 final String msg = uploadedModified ? "\n"+tr("Hint: Some changes came from uploading new data to the server.") : ""; 447 final int answer = JOptionPane.showConfirmDialog( 448 parent, tr("There are unsaved changes. Discard the changes and continue?")+msg, 449 tr("Unsaved Changes"), JOptionPane.YES_NO_OPTION); 450 if (answer != JOptionPane.YES_OPTION) 451 return true; 452 } 453 } 454 return false; 455 } 456 457 private static void downloadFromParamString(final boolean rawGps, String s) { 458 if (s.startsWith("http:")) { 459 final Bounds b = BoundingBoxSelection.osmurl2bounds(s); 460 if (b == null) 461 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed url: \"{0}\"", s)); 462 else { 463 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 464 DownloadTask osmTask = new DownloadOsmTask(); 465 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon()); 466 } 467 return; 468 } 469 470 if (s.startsWith("file:")) { 471 try { 472 main.menu.open.openFile(new File(new URI(s))); 473 } catch (URISyntaxException e) { 474 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file url: \"{0}\"", s)); 475 } 476 return; 477 } 478 479 final StringTokenizer st = new StringTokenizer(s, ","); 480 if (st.countTokens() == 4) { 481 try { 482 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 483 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())); 484 return; 485 } catch (final NumberFormatException e) { 486 } 487 } 488 489 main.menu.open.openFile(new File(s)); 490 } 491 492 protected static void determinePlatformHook() { 493 String os = System.getProperty("os.name"); 494 if (os == null) { 495 System.err.println("Your operating system has no name, so I'm guessing its some kind of *nix."); 496 platform = new PlatformHookUnixoid(); 497 } else if (os.toLowerCase().startsWith("windows")) { 498 platform = new PlatformHookWindows(); 499 } else if (os.equals("Linux") || os.equals("Solaris") || 500 os.equals("SunOS") || os.equals("AIX") || 501 os.equals("FreeBSD") || os.equals("NetBSD") || os.equals("OpenBSD")) { 502 platform = new PlatformHookUnixoid(); 503 } else if (os.toLowerCase().startsWith("mac os x")) { 504 platform = new PlatformHookOsx(); 505 } else { 506 System.err.println("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix."); 507 platform = new PlatformHookUnixoid(); 508 } 509 } 222 */ 223 public static void loadPlugins(boolean early) { 224 List<String> plugins = new LinkedList<String>(); 225 Collection<String> cp = Main.pref.getCollection("plugins", null); 226 if (cp != null) 227 plugins.addAll(cp); 228 if (System.getProperty("josm.plugins") != null) 229 plugins.addAll(Arrays.asList(System.getProperty("josm.plugins").split(","))); 230 231 String [] oldplugins = new String[] {"mappaint", "unglueplugin", "lang-de","lang-en_GB","lang-fr","lang-it","lang-pl","lang-ro","lang-ru"}; 232 for (String p : oldplugins) { 233 if (plugins.contains(p)) { 234 plugins.remove(p); 235 Main.pref.removeFromCollection("plugins", p); 236 System.out.println(tr("Warning - loading of {0} plugin was requested. This plugin is no longer required.", p)); 237 } 238 } 239 240 if (plugins.isEmpty()) 241 return; 242 243 SortedMap<Integer, Collection<PluginInformation>> p = new TreeMap<Integer, Collection<PluginInformation>>(); 244 for (String pluginName : plugins) { 245 PluginInformation info = PluginInformation.findPlugin(pluginName); 246 if (info != null) { 247 if (info.early != early) 248 continue; 249 if (info.mainversion != null && info.mainversion.compareTo(AboutAction.version) > 0) { 250 JOptionPane.showMessageDialog(Main.parent, tr("Plugin requires JOSM update: {0}.", pluginName)); 251 continue; 252 } 253 if (!p.containsKey(info.stage)) 254 p.put(info.stage, new LinkedList<PluginInformation>()); 255 p.get(info.stage).add(info); 256 } else { 257 if (early) 258 System.out.println("Plugin not found: "+pluginName); // do not translate 259 else 260 JOptionPane.showMessageDialog(Main.parent, tr("Plugin not found: {0}.", pluginName)); 261 } 262 } 263 264 if (!early) { 265 long tim = System.currentTimeMillis(); 266 long last = Main.pref.getLong("pluginmanager.lastupdate", 0); 267 Integer maxTime = Main.pref.getInteger("pluginmanager.warntime", 30); 268 long d = (tim - last)/(24*60*60*1000l); 269 if ((last <= 0) || (maxTime <= 0)) { 270 Main.pref.put("pluginmanager.lastupdate",Long.toString(tim)); 271 } else if (d > maxTime) { 272 JOptionPane.showMessageDialog(Main.parent, 273 "<html>" + 274 tr("Last plugin update more than {0} days ago.", d) + 275 "<br><em>" + 276 tr("(You can change the number of days after which this warning appears<br>by setting the config option 'pluginmanager.warntime'.)") + 277 "</html>"); 278 } 279 } 280 281 // iterate all plugins and collect all libraries of all plugins: 282 List<URL> allPluginLibraries = new ArrayList<URL>(); 283 for (Collection<PluginInformation> c : p.values()) 284 for (PluginInformation info : c) 285 allPluginLibraries.addAll(info.libraries); 286 // create a classloader for all plugins: 287 URL[] jarUrls = new URL[allPluginLibraries.size()]; 288 jarUrls = allPluginLibraries.toArray(jarUrls); 289 URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader()); 290 ImageProvider.sources.add(0, pluginClassLoader); 291 292 for (Collection<PluginInformation> c : p.values()) { 293 for (PluginInformation info : c) { 294 try { 295 Class<?> klass = info.loadClass(pluginClassLoader); 296 if (klass != null) { 297 System.out.println("loading "+info.name); 298 Main.plugins.add(info.load(klass)); 299 } 300 } catch (Throwable e) { 301 e.printStackTrace(); 302 boolean remove = true; 303 if (early) 304 System.out.println("Could not load plugin: "+info.name+" - deleted from preferences"); // do not translate 305 else { 306 int answer = JOptionPane.showConfirmDialog(Main.parent, 307 tr("Could not load plugin {0}. Delete from preferences?", info.name, 308 JOptionPane.YES_NO_OPTION)); 309 if (answer != JOptionPane.OK_OPTION) { 310 remove = false; 311 } 312 } 313 if (remove) { 314 plugins.remove(info.name); 315 String plist = null; 316 for (String pn : plugins) { 317 if (plist==null) plist=""; else plist=plist+","; 318 plist=plist+pn; 319 } 320 Main.pref.put("plugins", plist); 321 } 322 } 323 } 324 } 325 } 326 327 /** 328 * Add a new layer to the map. If no map exists, create one. 329 */ 330 public final void addLayer(final Layer layer) { 331 if (map == null) { 332 final MapFrame mapFrame = new MapFrame(); 333 setMapFrame(mapFrame); 334 mapFrame.selectMapMode((MapMode)mapFrame.getDefaultButtonAction()); 335 mapFrame.setVisible(true); 336 mapFrame.setVisibleDialogs(); 337 } 338 map.mapView.addLayer(layer); 339 } 340 /** 341 * @return The edit osm layer. If none exists, it will be created. 342 */ 343 public final OsmDataLayer editLayer() { 344 if (map == null || map.mapView.editLayer == null) 345 menu.newAction.actionPerformed(null); 346 return map.mapView.editLayer; 347 } 348 349 /** 350 * Use this to register shortcuts to 351 */ 352 public static final JPanel contentPane = new JPanel(new BorderLayout()); 353 354 355 /////////////////////////////////////////////////////////////////////////// 356 // Implementation part 357 /////////////////////////////////////////////////////////////////////////// 358 359 public static JPanel panel = new JPanel(new BorderLayout()); 360 361 protected static Rectangle bounds; 362 363 private final CommandQueueListener redoUndoListener = new CommandQueueListener(){ 364 public void commandChanged(final int queueSize, final int redoSize) { 365 menu.undo.setEnabled(queueSize > 0); 366 menu.redo.setEnabled(redoSize > 0); 367 } 368 }; 369 /** 370 * Should be called before the main constructor to setup some parameter stuff 371 * @param args The parsed argument list. 372 */ 373 public static void preConstructorInit(Map<String, Collection<String>> args) { 374 try { 375 Main.proj = (Projection)Class.forName(Main.pref.get("projection")).newInstance(); 376 } catch (final Exception e) { 377 e.printStackTrace(); 378 JOptionPane.showMessageDialog(null, tr("The projection could not be read from preferences. Using EPSG:4263.")); 379 Main.proj = new Epsg4326(); 380 } 381 382 try { 383 UIManager.setLookAndFeel(Main.pref.get("laf")); 384 toolbar = new ToolbarPreferences(); 385 contentPane.updateUI(); 386 panel.updateUI(); 387 } catch (final Exception e) { 388 e.printStackTrace(); 389 } 390 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok")); 391 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon")); 392 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel")); 393 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon")); 394 395 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize(); 396 if (args.containsKey("geometry")) { 397 String geometry = args.get("geometry").iterator().next(); 398 final Matcher m = Pattern.compile("(\\d+)x(\\d+)(([+-])(\\d+)([+-])(\\d+))?").matcher(geometry); 399 if (m.matches()) { 400 int w = Integer.valueOf(m.group(1)); 401 int h = Integer.valueOf(m.group(2)); 402 int x = 0, y = 0; 403 if (m.group(3) != null) { 404 x = Integer.valueOf(m.group(5)); 405 y = Integer.valueOf(m.group(7)); 406 if (m.group(4).equals("-")) 407 x = screenDimension.width - x - w; 408 if (m.group(6).equals("-")) 409 y = screenDimension.height - y - h; 410 } 411 bounds = new Rectangle(x,y,w,h); 412 } else 413 System.out.println("Ignoring malformed geometry: "+geometry); 414 } 415 if (bounds == null) 416 bounds = !args.containsKey("no-fullscreen") ? new Rectangle(0,0,screenDimension.width,screenDimension.height) : new Rectangle(1000,740); 417 418 // preinitialize a wait dialog for all early downloads (e.g. via command line) 419 pleaseWaitDlg = new PleaseWaitDialog(null); 420 } 421 422 public void postConstructorProcessCmdLine(Map<String, Collection<String>> args) { 423 // initialize the pleaseWaitDialog with the application as parent to handle focus stuff 424 pleaseWaitDlg = new PleaseWaitDialog(parent); 425 426 if (args.containsKey("download")) 427 for (String s : args.get("download")) 428 downloadFromParamString(false, s); 429 if (args.containsKey("downloadgps")) 430 for (String s : args.get("downloadgps")) 431 downloadFromParamString(true, s); 432 if (args.containsKey("selection")) 433 for (String s : args.get("selection")) 434 SearchAction.search(s, SearchAction.SearchMode.add, false); 435 } 436 437 public static boolean breakBecauseUnsavedChanges() { 438 Shortcut.savePrefs(); 439 if (map != null) { 440 boolean modified = false; 441 boolean uploadedModified = false; 442 for (final Layer l : map.mapView.getAllLayers()) { 443 if (l instanceof OsmDataLayer && ((OsmDataLayer)l).isModified()) { 444 modified = true; 445 uploadedModified = ((OsmDataLayer)l).uploadedModified; 446 break; 447 } 448 } 449 if (modified) { 450 final String msg = uploadedModified ? "\n"+tr("Hint: Some changes came from uploading new data to the server.") : ""; 451 final int answer = JOptionPane.showConfirmDialog( 452 parent, tr("There are unsaved changes. Discard the changes and continue?")+msg, 453 tr("Unsaved Changes"), JOptionPane.YES_NO_OPTION); 454 if (answer != JOptionPane.YES_OPTION) 455 return true; 456 } 457 } 458 return false; 459 } 460 461 private static void downloadFromParamString(final boolean rawGps, String s) { 462 if (s.startsWith("http:")) { 463 final Bounds b = BoundingBoxSelection.osmurl2bounds(s); 464 if (b == null) 465 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed url: \"{0}\"", s)); 466 else { 467 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); 468 DownloadTask osmTask = new DownloadOsmTask(); 469 osmTask.download(main.menu.download, b.min.lat(), b.min.lon(), b.max.lat(), b.max.lon()); 470 } 471 return; 472 } 473 474 if (s.startsWith("file:")) { 475 try { 476 main.menu.open.openFile(new File(new URI(s))); 477 } catch (URISyntaxException e) { 478 JOptionPane.showMessageDialog(Main.parent, tr("Ignoring malformed file url: \"{0}\"", s)); 479 } 480 return; 481 } 482 483 final StringTokenizer st = new StringTokenizer(s, ","); 484 if (st.countTokens() == 4) { 485 try { 486 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 487 task.download(main.menu.download, Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())); 488 return; 489 } catch (final NumberFormatException e) { 490 } 491 } 492 493 main.menu.open.openFile(new File(s)); 494 } 495 496 protected static void determinePlatformHook() { 497 String os = System.getProperty("os.name"); 498 if (os == null) { 499 System.err.println("Your operating system has no name, so I'm guessing its some kind of *nix."); 500 platform = new PlatformHookUnixoid(); 501 } else if (os.toLowerCase().startsWith("windows")) { 502 platform = new PlatformHookWindows(); 503 } else if (os.equals("Linux") || os.equals("Solaris") || 504 os.equals("SunOS") || os.equals("AIX") || 505 os.equals("FreeBSD") || os.equals("NetBSD") || os.equals("OpenBSD")) { 506 platform = new PlatformHookUnixoid(); 507 } else if (os.toLowerCase().startsWith("mac os x")) { 508 platform = new PlatformHookOsx(); 509 } else { 510 System.err.println("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix."); 511 platform = new PlatformHookUnixoid(); 512 } 513 } 510 514 511 515 }
Note:
See TracChangeset
for help on using the changeset viewer.