// License: GPL. Copyright 2007 by Immanuel Scholz and others //Licence: GPL package org.openstreetmap.josm.gui; import static org.openstreetmap.josm.tools.I18n.tr; import java.awt.EventQueue; import java.awt.Toolkit; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.swing.JFrame; import javax.swing.JOptionPane; import org.openstreetmap.josm.Main; import org.openstreetmap.josm.plugins.PluginDownloader; import org.openstreetmap.josm.tools.BugReportExceptionHandler; /** * Main window class application. * * @author imi */ public class MainApplication extends Main { /** * Construct an main frame, ready sized and operating. Does not * display the frame. */ public MainApplication(JFrame mainFrame) { super(); mainFrame.setContentPane(contentPane); mainFrame.setJMenuBar(menu); mainFrame.setBounds(bounds); mainFrame.addWindowListener(new WindowAdapter(){ @Override public void windowClosing(final WindowEvent arg0) { if (Main.breakBecauseUnsavedChanges()) return; System.exit(0); } }); mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); } /** * Main application Startup */ @SuppressWarnings("deprecation") public static void main(final String[] argArray) { ///////////////////////////////////////////////////////////////////////// // TO ALL TRANSLATORS ///////////////////////////////////////////////////////////////////////// // Do not translate the early strings below until the locale is set up. // (By the eager loaded plugins) // // These strings cannot be translated. That's life. Really. Sorry. // // Imi. ///////////////////////////////////////////////////////////////////////// Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler()); // construct argument table List argList = Arrays.asList(argArray); final Map> args = new HashMap>(); for (String arg : argArray) { if (!arg.startsWith("--")) arg = "--download="+arg; int i = arg.indexOf('='); String key = i == -1 ? arg.substring(2) : arg.substring(2,i); String value = i == -1 ? "" : arg.substring(i+1); Collection v = args.get(key); if (v == null) v = new LinkedList(); v.add(value); args.put(key, v); } // Only show the splash screen if we don't print the help and exit SplashScreen splash; if (!argList.contains("--help") && !argList.contains("-?") && !argList.contains("-h")) { splash = new SplashScreen(); } else { splash = null; } splash.setStatus(tr("Reading preferences")); // get the preferences. final File prefDir = new File(Main.pref.getPreferencesDir()); // check if preferences directory has moved (TODO: Update code. Remove this after some time) File oldPrefDir = new File(System.getProperty("user.home"), ".josm"); if (!prefDir.isDirectory() && oldPrefDir.isDirectory()) { if (oldPrefDir.renameTo(prefDir)) { // do not translate this JOptionPane.showMessageDialog(null, "The preference directory has been moved to "+prefDir); } else { JOptionPane.showMessageDialog(null, "The preference directory location has changed. Please move "+oldPrefDir+" to "+prefDir); } } if (prefDir.exists() && !prefDir.isDirectory()) { JOptionPane.showMessageDialog(null, "Cannot open preferences directory: "+Main.pref.getPreferencesDir()); return; } if (!prefDir.exists()) prefDir.mkdirs(); if (!new File(Main.pref.getPreferencesDir()+"preferences").exists()) { Main.pref.resetToDefault(); } try { if (args.containsKey("reset-preferences")) { Main.pref.resetToDefault(); } else { Main.pref.load(); } } catch (final IOException e1) { e1.printStackTrace(); String backup = Main.pref.getPreferencesDir() + "preferences.bak"; JOptionPane.showMessageDialog(null, "Preferences file had errors. Making backup of old one to " + backup); new File(Main.pref.getPreferencesDir() + "preferences").renameTo(new File(backup)); Main.pref.save(); } String language = null; if(args.containsKey("language")) language = (String)(args.get("language").toArray()[0]); splash.setStatus(tr("Activating updated plugins")); if (!PluginDownloader.moveUpdatedPlugins()) { JOptionPane.showMessageDialog(null, tr("Activating the updated plugins failed. Check if JOSM has the permission to overwrite the existing ones."), tr("Plugins"), JOptionPane.ERROR_MESSAGE); } // load the early plugins splash.setStatus(tr("Loading early plugins")); Main.loadPlugins(true, language); if (argList.contains("--help") || argList.contains("-?") || argList.contains("-h")) { System.out.println(tr("Java OpenStreetMap Editor")+"\n\n"+ tr("usage")+":\n"+ "\tjava -jar josm.jar