[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[283] | 2 | package org.openstreetmap.josm.gui;
|
---|
| 3 |
|
---|
| 4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
[3461] | 5 | import static org.openstreetmap.josm.tools.I18n.trn;
|
---|
[6221] | 6 | import gnu.getopt.Getopt;
|
---|
| 7 | import gnu.getopt.LongOpt;
|
---|
[283] | 8 |
|
---|
[6523] | 9 | import java.awt.Dimension;
|
---|
[4061] | 10 | import java.awt.Image;
|
---|
[283] | 11 | import java.awt.Toolkit;
|
---|
| 12 | import java.awt.event.WindowAdapter;
|
---|
| 13 | import java.awt.event.WindowEvent;
|
---|
[3435] | 14 | import java.io.File;
|
---|
[7033] | 15 | import java.io.InputStream;
|
---|
[2641] | 16 | import java.net.Authenticator;
|
---|
| 17 | import java.net.ProxySelector;
|
---|
[5201] | 18 | import java.net.URL;
|
---|
[3232] | 19 | import java.security.AllPermission;
|
---|
| 20 | import java.security.CodeSource;
|
---|
| 21 | import java.security.PermissionCollection;
|
---|
| 22 | import java.security.Permissions;
|
---|
| 23 | import java.security.Policy;
|
---|
[5279] | 24 | import java.util.ArrayList;
|
---|
[283] | 25 | import java.util.Collection;
|
---|
| 26 | import java.util.HashMap;
|
---|
| 27 | import java.util.LinkedList;
|
---|
| 28 | import java.util.List;
|
---|
| 29 | import java.util.Map;
|
---|
[6642] | 30 | import java.util.Set;
|
---|
| 31 | import java.util.TreeSet;
|
---|
[283] | 32 |
|
---|
| 33 | import javax.swing.JFrame;
|
---|
[6523] | 34 | import javax.swing.JOptionPane;
|
---|
[4720] | 35 | import javax.swing.RepaintManager;
|
---|
[3679] | 36 | import javax.swing.SwingUtilities;
|
---|
[283] | 37 |
|
---|
[4720] | 38 | import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
|
---|
[283] | 39 | import org.openstreetmap.josm.Main;
|
---|
[6523] | 40 | import org.openstreetmap.josm.actions.PreferencesAction;
|
---|
[3378] | 41 | import org.openstreetmap.josm.data.AutosaveTask;
|
---|
[5201] | 42 | import org.openstreetmap.josm.data.CustomConfigurator;
|
---|
[6851] | 43 | import org.openstreetmap.josm.data.Preferences;
|
---|
[4259] | 44 | import org.openstreetmap.josm.data.Version;
|
---|
[4906] | 45 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
[2748] | 46 | import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
|
---|
[6523] | 47 | import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
|
---|
[2817] | 48 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
[5796] | 49 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[2641] | 50 | import org.openstreetmap.josm.io.DefaultProxySelector;
|
---|
[6349] | 51 | import org.openstreetmap.josm.io.MessageNotifier;
|
---|
[4245] | 52 | import org.openstreetmap.josm.io.auth.CredentialsManager;
|
---|
[2641] | 53 | import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
|
---|
[3707] | 54 | import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
|
---|
[1326] | 55 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
[2817] | 56 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
[283] | 57 | import org.openstreetmap.josm.tools.BugReportExceptionHandler;
|
---|
[2017] | 58 | import org.openstreetmap.josm.tools.I18n;
|
---|
[1033] | 59 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
[6453] | 60 | import org.openstreetmap.josm.tools.OsmUrlToBounds;
|
---|
[5868] | 61 | import org.openstreetmap.josm.tools.Utils;
|
---|
[1058] | 62 |
|
---|
[283] | 63 | /**
|
---|
| 64 | * Main window class application.
|
---|
| 65 | *
|
---|
| 66 | * @author imi
|
---|
| 67 | */
|
---|
| 68 | public class MainApplication extends Main {
|
---|
[1169] | 69 | /**
|
---|
| 70 | * Allow subclassing (see JOSM.java)
|
---|
| 71 | */
|
---|
| 72 | public MainApplication() {}
|
---|
[1023] | 73 |
|
---|
[1169] | 74 | /**
|
---|
[5829] | 75 | * Constructs a main frame, ready sized and operating. Does not display the frame.
|
---|
| 76 | * @param mainFrame The main JFrame of the application
|
---|
[1169] | 77 | */
|
---|
[2817] | 78 | public MainApplication(JFrame mainFrame) {
|
---|
[5829] | 79 | addListener();
|
---|
[3252] | 80 | mainFrame.setContentPane(contentPanePrivate);
|
---|
[1169] | 81 | mainFrame.setJMenuBar(menu);
|
---|
[4932] | 82 | geometry.applySafe(mainFrame);
|
---|
[7005] | 83 | LinkedList<Image> l = new LinkedList<>();
|
---|
[4061] | 84 | l.add(ImageProvider.get("logo_16x16x32").getImage());
|
---|
| 85 | l.add(ImageProvider.get("logo_16x16x8").getImage());
|
---|
| 86 | l.add(ImageProvider.get("logo_32x32x32").getImage());
|
---|
| 87 | l.add(ImageProvider.get("logo_32x32x8").getImage());
|
---|
| 88 | l.add(ImageProvider.get("logo_48x48x32").getImage());
|
---|
| 89 | l.add(ImageProvider.get("logo_48x48x8").getImage());
|
---|
| 90 | l.add(ImageProvider.get("logo").getImage());
|
---|
| 91 | mainFrame.setIconImages(l);
|
---|
[1169] | 92 | mainFrame.addWindowListener(new WindowAdapter(){
|
---|
[6642] | 93 | @Override
|
---|
| 94 | public void windowClosing(final WindowEvent arg0) {
|
---|
[6125] | 95 | Main.exitJosm(true, 0);
|
---|
[1169] | 96 | }
|
---|
| 97 | });
|
---|
| 98 | mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
---|
| 99 | }
|
---|
[283] | 100 |
|
---|
[1169] | 101 | /**
|
---|
[2748] | 102 | * Displays help on the console
|
---|
[6143] | 103 | * @since 2748
|
---|
[2748] | 104 | */
|
---|
| 105 | public static void showHelp() {
|
---|
| 106 | // TODO: put in a platformHook for system that have no console by default
|
---|
[5363] | 107 | System.out.println(tr("Java OpenStreetMap Editor")+" ["
|
---|
| 108 | +Version.getInstance().getAgentString()+"]\n\n"+
|
---|
[2748] | 109 | tr("usage")+":\n"+
|
---|
| 110 | "\tjava -jar josm.jar <options>...\n\n"+
|
---|
| 111 | tr("options")+":\n"+
|
---|
[5279] | 112 | "\t--help|-h "+tr("Show this help")+"\n"+
|
---|
[2748] | 113 | "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+"\n"+
|
---|
| 114 | "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+"\n"+
|
---|
[5365] | 115 | "\t[--download=]<URL> "+tr("Download the location at the URL (with lat=x&lon=y&zoom=z)")+"\n"+
|
---|
[2800] | 116 | "\t[--download=]<filename> "+tr("Open a file (any file type that can be opened with File/Open)")+"\n"+
|
---|
[5365] | 117 | "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw GPS")+"\n"+
|
---|
| 118 | "\t--downloadgps=<URL> "+tr("Download the location at the URL (with lat=x&lon=y&zoom=z) as raw GPS")+"\n"+
|
---|
[2748] | 119 | "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+
|
---|
| 120 | "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+
|
---|
| 121 | "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
|
---|
[5201] | 122 | "\t--load-preferences=<url-to-xml> "+tr("Changes preferences according to the XML file")+"\n\n"+
|
---|
[4789] | 123 | "\t--set=<key>=<value> "+tr("Set preference key to value")+"\n\n"+
|
---|
[2800] | 124 | "\t--language=<language> "+tr("Set the language")+"\n\n"+
|
---|
[5365] | 125 | "\t--version "+tr("Displays the JOSM version and exits")+"\n\n"+
|
---|
[6730] | 126 | "\t--debug "+tr("Print debugging messages to console")+"\n\n"+
|
---|
[2748] | 127 | tr("options provided as Java system properties")+":\n"+
|
---|
| 128 | "\t-Djosm.home="+tr("/PATH/TO/JOSM/FOLDER/ ")+tr("Change the folder for all user settings")+"\n\n"+
|
---|
| 129 | tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" +
|
---|
[4720] | 130 | " Java option to specify the maximum size of allocated memory in megabytes")+":\n"+
|
---|
| 131 | "\t-Xmx...m\n\n"+
|
---|
| 132 | tr("examples")+":\n"+
|
---|
| 133 | "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
|
---|
[6453] | 134 | "\tjava -jar josm.jar "+OsmUrlToBounds.getURL(43.2, 11.1, 13)+"\n"+
|
---|
[4720] | 135 | "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
|
---|
| 136 | "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n"+
|
---|
| 137 | "\tjava -Djosm.home=/home/user/.josm_dev -jar josm.jar\n"+
|
---|
[6453] | 138 | "\tjava -Xmx1024m -jar josm.jar\n\n"+
|
---|
[4720] | 139 | tr("Parameters --download, --downloadgps, and --selection are processed in this order.")+"\n"+
|
---|
| 140 | tr("Make sure you load some data if you use --selection.")+"\n"
|
---|
| 141 | );
|
---|
[2748] | 142 | }
|
---|
| 143 |
|
---|
[6143] | 144 | /**
|
---|
| 145 | * JOSM command line options.
|
---|
[6920] | 146 | * @see <a href="https://josm.openstreetmap.de/wiki/Help/CommandLineOptions">Help/CommandLineOptions</a>
|
---|
[6143] | 147 | * @since 5279
|
---|
| 148 | */
|
---|
[5279] | 149 | public enum Option {
|
---|
[6143] | 150 | /** --help|-h Show this help */
|
---|
[5279] | 151 | HELP(false),
|
---|
[6143] | 152 | /** --version Displays the JOSM version and exits */
|
---|
[5279] | 153 | VERSION(false),
|
---|
[6730] | 154 | /** --debug Print debugging messages to console */
|
---|
| 155 | DEBUG(false),
|
---|
[6830] | 156 | /** --language=<language> Set the language */
|
---|
[5279] | 157 | LANGUAGE(true),
|
---|
[6143] | 158 | /** --reset-preferences Reset the preferences to default */
|
---|
[5279] | 159 | RESET_PREFERENCES(false),
|
---|
[6830] | 160 | /** --load-preferences=<url-to-xml> Changes preferences according to the XML file */
|
---|
[5279] | 161 | LOAD_PREFERENCES(true),
|
---|
[6830] | 162 | /** --set=<key>=<value> Set preference key to value */
|
---|
[5279] | 163 | SET(true),
|
---|
[6143] | 164 | /** --geometry=widthxheight(+|-)x(+|-)y Standard unix geometry argument */
|
---|
[5279] | 165 | GEOMETRY(true),
|
---|
[6143] | 166 | /** --no-maximize Do not launch in maximized mode */
|
---|
[5279] | 167 | NO_MAXIMIZE(false),
|
---|
[6143] | 168 | /** --maximize Launch in maximized mode */
|
---|
[5279] | 169 | MAXIMIZE(false),
|
---|
[6143] | 170 | /** --download=minlat,minlon,maxlat,maxlon Download the bounding box <br>
|
---|
[6830] | 171 | * --download=<URL> Download the location at the URL (with lat=x&lon=y&zoom=z) <br>
|
---|
| 172 | * --download=<filename> Open a file (any file type that can be opened with File/Open) */
|
---|
[5279] | 173 | DOWNLOAD(true),
|
---|
[6143] | 174 | /** --downloadgps=minlat,minlon,maxlat,maxlon Download the bounding box as raw GPS <br>
|
---|
[6830] | 175 | * --downloadgps=<URL> Download the location at the URL (with lat=x&lon=y&zoom=z) as raw GPS */
|
---|
[5279] | 176 | DOWNLOADGPS(true),
|
---|
[6830] | 177 | /** --selection=<searchstring> Select with the given search */
|
---|
[5279] | 178 | SELECTION(true);
|
---|
| 179 |
|
---|
| 180 | private String name;
|
---|
| 181 | private boolean requiresArgument;
|
---|
| 182 |
|
---|
| 183 | private Option(boolean requiresArgument) {
|
---|
| 184 | this.name = name().toLowerCase().replace("_", "-");
|
---|
| 185 | this.requiresArgument = requiresArgument;
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[6143] | 188 | /**
|
---|
| 189 | * Replies the option name
|
---|
| 190 | * @return The option name, in lowercase
|
---|
| 191 | */
|
---|
[5279] | 192 | public String getName() {
|
---|
| 193 | return name;
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[6143] | 196 | /**
|
---|
| 197 | * Determines if this option requires an argument.
|
---|
| 198 | * @return {@code true} if this option requires an argument, {@code false} otherwise
|
---|
| 199 | */
|
---|
[5279] | 200 | public boolean requiresArgument() {
|
---|
| 201 | return requiresArgument;
|
---|
| 202 | }
|
---|
| 203 |
|
---|
| 204 | public static Map<Option, Collection<String>> fromStringMap(Map<String, Collection<String>> opts) {
|
---|
[7005] | 205 | Map<Option, Collection<String>> res = new HashMap<>();
|
---|
[5279] | 206 | for (Map.Entry<String, Collection<String>> e : opts.entrySet()) {
|
---|
| 207 | Option o = Option.valueOf(e.getKey().toUpperCase().replace("-", "_"));
|
---|
| 208 | if (o != null) {
|
---|
| 209 | res.put(o, e.getValue());
|
---|
| 210 | }
|
---|
[2821] | 211 | }
|
---|
[5279] | 212 | return res;
|
---|
| 213 | }
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | private static Map<Option, Collection<String>> buildCommandLineArgumentMap(String[] args) {
|
---|
| 217 |
|
---|
[7005] | 218 | List<LongOpt> los = new ArrayList<>();
|
---|
[5279] | 219 | for (Option o : Option.values()) {
|
---|
| 220 | los.add(new LongOpt(o.getName(), o.requiresArgument() ? LongOpt.REQUIRED_ARGUMENT : LongOpt.NO_ARGUMENT, null, 0));
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[6083] | 223 | Getopt g = new Getopt("JOSM", args, "hv", los.toArray(new LongOpt[los.size()]));
|
---|
[5279] | 224 |
|
---|
[7005] | 225 | Map<Option, Collection<String>> argMap = new HashMap<>();
|
---|
[5279] | 226 |
|
---|
| 227 | int c;
|
---|
| 228 | while ((c = g.getopt()) != -1 ) {
|
---|
| 229 | Option opt = null;
|
---|
| 230 | switch (c) {
|
---|
| 231 | case 'h':
|
---|
| 232 | opt = Option.HELP;
|
---|
| 233 | break;
|
---|
| 234 | case 'v':
|
---|
| 235 | opt = Option.VERSION;
|
---|
| 236 | break;
|
---|
| 237 | case 0:
|
---|
| 238 | opt = Option.values()[g.getLongind()];
|
---|
| 239 | break;
|
---|
[2025] | 240 | }
|
---|
[5279] | 241 | if (opt != null) {
|
---|
| 242 | Collection<String> values = argMap.get(opt);
|
---|
| 243 | if (values == null) {
|
---|
[7005] | 244 | values = new ArrayList<>();
|
---|
[5279] | 245 | argMap.put(opt, values);
|
---|
| 246 | }
|
---|
| 247 | values.add(g.getOptarg());
|
---|
| 248 | } else
|
---|
| 249 | throw new IllegalArgumentException();
|
---|
| 250 | }
|
---|
| 251 | // positional arguments are a shortcut for the --download ... option
|
---|
| 252 | for (int i = g.getOptind(); i < args.length; ++i) {
|
---|
| 253 | Collection<String> values = argMap.get(Option.DOWNLOAD);
|
---|
| 254 | if (values == null) {
|
---|
[7005] | 255 | values = new ArrayList<>();
|
---|
[5279] | 256 | argMap.put(Option.DOWNLOAD, values);
|
---|
[2025] | 257 | }
|
---|
[5279] | 258 | values.add(args[i]);
|
---|
[1169] | 259 | }
|
---|
[5279] | 260 |
|
---|
[2856] | 261 | return argMap;
|
---|
| 262 | }
|
---|
[283] | 263 |
|
---|
[2856] | 264 | /**
|
---|
| 265 | * Main application Startup
|
---|
[5829] | 266 | * @param argArray Command-line arguments
|
---|
[2856] | 267 | */
|
---|
| 268 | public static void main(final String[] argArray) {
|
---|
| 269 | I18n.init();
|
---|
[7001] | 270 | Main.checkJavaVersion();
|
---|
[6108] | 271 |
|
---|
| 272 | // construct argument table
|
---|
| 273 | Map<Option, Collection<String>> args = null;
|
---|
| 274 | try {
|
---|
| 275 | args = buildCommandLineArgumentMap(argArray);
|
---|
| 276 | } catch (IllegalArgumentException e) {
|
---|
| 277 | System.exit(1);
|
---|
| 278 | }
|
---|
[6830] | 279 |
|
---|
[6108] | 280 | final boolean languageGiven = args.containsKey(Option.LANGUAGE);
|
---|
| 281 |
|
---|
| 282 | if (languageGiven) {
|
---|
| 283 | I18n.set(args.get(Option.LANGUAGE).iterator().next());
|
---|
| 284 | }
|
---|
| 285 |
|
---|
[6471] | 286 | initApplicationPreferences();
|
---|
[2856] | 287 |
|
---|
[3232] | 288 | Policy.setPolicy(new Policy() {
|
---|
| 289 | // Permissions for plug-ins loaded when josm is started via webstart
|
---|
| 290 | private PermissionCollection pc;
|
---|
| 291 |
|
---|
| 292 | {
|
---|
| 293 | pc = new Permissions();
|
---|
| 294 | pc.add(new AllPermission());
|
---|
| 295 | }
|
---|
| 296 |
|
---|
| 297 | @Override
|
---|
| 298 | public void refresh() { }
|
---|
| 299 |
|
---|
| 300 | @Override
|
---|
| 301 | public PermissionCollection getPermissions(CodeSource codesource) {
|
---|
| 302 | return pc;
|
---|
| 303 | }
|
---|
| 304 | });
|
---|
| 305 |
|
---|
[2856] | 306 | Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
|
---|
| 307 |
|
---|
[3815] | 308 | // initialize the platform hook, and
|
---|
[2856] | 309 | Main.determinePlatformHook();
|
---|
[4259] | 310 | // call the really early hook before we do anything else
|
---|
[2856] | 311 | Main.platform.preStartupHook();
|
---|
| 312 |
|
---|
[6221] | 313 | Main.commandLineArgs = Utils.copyArray(argArray);
|
---|
[6830] | 314 |
|
---|
[5279] | 315 | if (args.containsKey(Option.VERSION)) {
|
---|
[4259] | 316 | System.out.println(Version.getInstance().getAgentString());
|
---|
| 317 | System.exit(0);
|
---|
[6108] | 318 | }
|
---|
[4259] | 319 |
|
---|
[6730] | 320 | if (args.containsKey(Option.DEBUG)) {
|
---|
[6851] | 321 | // Enable JOSM debug level
|
---|
[6730] | 322 | logLevel = 4;
|
---|
[6851] | 323 | // Enable debug in OAuth signpost
|
---|
| 324 | Preferences.updateSystemProperty("debug", "true");
|
---|
[6730] | 325 | Main.debug(tr("Print debugging messages to console"));
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[5279] | 328 | Main.pref.init(args.containsKey(Option.RESET_PREFERENCES));
|
---|
[2085] | 329 |
|
---|
[6108] | 330 | if (!languageGiven) {
|
---|
[1802] | 331 | I18n.set(Main.pref.get("language", null));
|
---|
[2025] | 332 | }
|
---|
[2358] | 333 | Main.pref.updateSystemProperties();
|
---|
[1326] | 334 |
|
---|
[5796] | 335 | final JFrame mainFrame = new JFrame(tr("Java OpenStreetMap Editor"));
|
---|
[5201] | 336 | Main.parent = mainFrame;
|
---|
| 337 |
|
---|
[5279] | 338 | if (args.containsKey(Option.LOAD_PREFERENCES)) {
|
---|
[5201] | 339 | CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
|
---|
[5279] | 340 | for (String i : args.get(Option.LOAD_PREFERENCES)) {
|
---|
[6248] | 341 | info("Reading preferences from " + i);
|
---|
[7033] | 342 | try (InputStream is = Utils.openURL(new URL(i))) {
|
---|
| 343 | config.openAndReadXML(is);
|
---|
[5201] | 344 | } catch (Exception ex) {
|
---|
| 345 | throw new RuntimeException(ex);
|
---|
| 346 | }
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
[5279] | 350 | if (args.containsKey(Option.SET)) {
|
---|
| 351 | for (String i : args.get(Option.SET)) {
|
---|
[4789] | 352 | String[] kv = i.split("=", 2);
|
---|
| 353 | Main.pref.put(kv[0], "null".equals(kv[1]) ? null : kv[1]);
|
---|
| 354 | }
|
---|
| 355 | }
|
---|
| 356 |
|
---|
[4249] | 357 | DefaultAuthenticator.createInstance();
|
---|
[2748] | 358 | Authenticator.setDefault(DefaultAuthenticator.getInstance());
|
---|
[6523] | 359 | DefaultProxySelector proxySelector = new DefaultProxySelector(ProxySelector.getDefault());
|
---|
| 360 | ProxySelector.setDefault(proxySelector);
|
---|
[4245] | 361 | OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance());
|
---|
[2641] | 362 |
|
---|
[2748] | 363 | // asking for help? show help and exit
|
---|
[5279] | 364 | if (args.containsKey(Option.HELP)) {
|
---|
[2748] | 365 | showHelp();
|
---|
[1169] | 366 | System.exit(0);
|
---|
| 367 | }
|
---|
[976] | 368 |
|
---|
[5796] | 369 | final SplashScreen splash = new SplashScreen();
|
---|
[4681] | 370 | final ProgressMonitor monitor = splash.getProgressMonitor();
|
---|
[2817] | 371 | monitor.beginTask(tr("Initializing"));
|
---|
| 372 | splash.setVisible(Main.pref.getBoolean("draw.splashscreen", true));
|
---|
[4681] | 373 | Main.setInitStatusListener(new InitStatusListener() {
|
---|
[1023] | 374 |
|
---|
[4681] | 375 | @Override
|
---|
| 376 | public void updateStatus(String event) {
|
---|
| 377 | monitor.indeterminateSubTask(event);
|
---|
| 378 | }
|
---|
| 379 | });
|
---|
| 380 |
|
---|
[6797] | 381 | Collection<PluginInformation> pluginsToLoad = PluginHandler.buildListOfPluginsToLoad(splash,monitor.createSubTaskMonitor(1, false));
|
---|
[2856] | 382 | if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) {
|
---|
[4681] | 383 | monitor.subTask(tr("Updating plugins"));
|
---|
[6839] | 384 | pluginsToLoad = PluginHandler.updatePlugins(splash, null, monitor.createSubTaskMonitor(1, false), false);
|
---|
[2817] | 385 | }
|
---|
[283] | 386 |
|
---|
[4681] | 387 | monitor.indeterminateSubTask(tr("Installing updated plugins"));
|
---|
[3054] | 388 | PluginHandler.installDownloadedPlugins(true);
|
---|
[283] | 389 |
|
---|
[4681] | 390 | monitor.indeterminateSubTask(tr("Loading early plugins"));
|
---|
[2856] | 391 | PluginHandler.loadEarlyPlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false));
|
---|
[2817] | 392 |
|
---|
[4681] | 393 | monitor.indeterminateSubTask(tr("Setting defaults"));
|
---|
[1169] | 394 | preConstructorInit(args);
|
---|
[2817] | 395 |
|
---|
| 396 | monitor.indeterminateSubTask(tr("Creating main GUI"));
|
---|
| 397 | final Main main = new MainApplication(mainFrame);
|
---|
| 398 |
|
---|
[4681] | 399 | monitor.indeterminateSubTask(tr("Loading plugins"));
|
---|
[2856] | 400 | PluginHandler.loadLatePlugins(splash,pluginsToLoad, monitor.createSubTaskMonitor(1, false));
|
---|
[1169] | 401 | toolbar.refreshToolbarControl();
|
---|
[5796] | 402 |
|
---|
[6866] | 403 | // Wait for splash disappearance (fix #9714)
|
---|
| 404 | GuiHelper.runInEDTAndWait(new Runnable() {
|
---|
[6084] | 405 | @Override
|
---|
[5796] | 406 | public void run() {
|
---|
| 407 | splash.setVisible(false);
|
---|
| 408 | splash.dispose();
|
---|
| 409 | mainFrame.setVisible(true);
|
---|
| 410 | }
|
---|
| 411 | });
|
---|
| 412 |
|
---|
[5538] | 413 | Main.MasterWindowListener.setup();
|
---|
[283] | 414 |
|
---|
[6578] | 415 | boolean maximized = Main.pref.getBoolean("gui.maximized", false);
|
---|
[5279] | 416 | if ((!args.containsKey(Option.NO_MAXIMIZE) && maximized) || args.containsKey(Option.MAXIMIZE)) {
|
---|
[2876] | 417 | if (Toolkit.getDefaultToolkit().isFrameStateSupported(JFrame.MAXIMIZED_BOTH)) {
|
---|
| 418 | Main.windowState = JFrame.MAXIMIZED_BOTH;
|
---|
| 419 | mainFrame.setExtendedState(Main.windowState);
|
---|
| 420 | } else {
|
---|
| 421 | Main.debug("Main window: maximizing not supported");
|
---|
| 422 | }
|
---|
[2025] | 423 | }
|
---|
[6246] | 424 | if (main.menu.fullscreenToggleAction != null) {
|
---|
[4139] | 425 | main.menu.fullscreenToggleAction.initial();
|
---|
[4720] | 426 | }
|
---|
[1023] | 427 |
|
---|
[6523] | 428 | SwingUtilities.invokeLater(new GuiFinalizationWorker(args, proxySelector));
|
---|
[5279] | 429 |
|
---|
[3959] | 430 | if (RemoteControl.PROP_REMOTECONTROL_ENABLED.get()) {
|
---|
| 431 | RemoteControl.start();
|
---|
| 432 | }
|
---|
[6830] | 433 |
|
---|
[6349] | 434 | if (MessageNotifier.PROP_NOTIFIER_ENABLED.get()) {
|
---|
| 435 | MessageNotifier.start();
|
---|
| 436 | }
|
---|
[3959] | 437 |
|
---|
[4720] | 438 | if (Main.pref.getBoolean("debug.edt-checker.enable", Version.getInstance().isLocalBuild())) {
|
---|
| 439 | // Repaint manager is registered so late for a reason - there is lots of violation during startup process but they don't seem to break anything and are difficult to fix
|
---|
[6248] | 440 | info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console");
|
---|
[4720] | 441 | RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
|
---|
| 442 | }
|
---|
[1169] | 443 | }
|
---|
[6523] | 444 |
|
---|
| 445 | private static class GuiFinalizationWorker implements Runnable {
|
---|
| 446 |
|
---|
| 447 | private final Map<Option, Collection<String>> args;
|
---|
| 448 | private final DefaultProxySelector proxySelector;
|
---|
| 449 |
|
---|
| 450 | public GuiFinalizationWorker(Map<Option, Collection<String>> args, DefaultProxySelector proxySelector) {
|
---|
| 451 | this.args = args;
|
---|
| 452 | this.proxySelector = proxySelector;
|
---|
| 453 | }
|
---|
| 454 |
|
---|
| 455 | @Override
|
---|
| 456 | public void run() {
|
---|
| 457 |
|
---|
[6642] | 458 | // Handle proxy/network errors early to inform user he should change settings to be able to use JOSM correctly
|
---|
| 459 | if (!handleProxyErrors()) {
|
---|
| 460 | handleNetworkErrors();
|
---|
| 461 | }
|
---|
[6523] | 462 |
|
---|
| 463 | // Restore autosave layers after crash and start autosave thread
|
---|
| 464 | handleAutosave();
|
---|
| 465 |
|
---|
| 466 | // Handle command line instructions
|
---|
| 467 | postConstructorProcessCmdLine(args);
|
---|
| 468 |
|
---|
| 469 | // Show download dialog if autostart is enabled
|
---|
| 470 | DownloadDialog.autostartIfNeeded();
|
---|
| 471 | }
|
---|
| 472 |
|
---|
| 473 | private void handleAutosave() {
|
---|
| 474 | if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) {
|
---|
| 475 | AutosaveTask autosaveTask = new AutosaveTask();
|
---|
| 476 | List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles();
|
---|
| 477 | if (!unsavedLayerFiles.isEmpty()) {
|
---|
| 478 | ExtendedDialog dialog = new ExtendedDialog(
|
---|
| 479 | Main.parent,
|
---|
| 480 | tr("Unsaved osm data"),
|
---|
| 481 | new String[] {tr("Restore"), tr("Cancel"), tr("Discard")}
|
---|
| 482 | );
|
---|
| 483 | dialog.setContent(
|
---|
| 484 | trn("JOSM found {0} unsaved osm data layer. ",
|
---|
| 485 | "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) +
|
---|
| 486 | tr("It looks like JOSM crashed last time. Would you like to restore the data?"));
|
---|
| 487 | dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/delete"});
|
---|
| 488 | int selection = dialog.showDialog().getValue();
|
---|
| 489 | if (selection == 1) {
|
---|
| 490 | autosaveTask.recoverUnsavedLayers();
|
---|
| 491 | } else if (selection == 3) {
|
---|
[6995] | 492 | autosaveTask.discardUnsavedLayers();
|
---|
[6523] | 493 | }
|
---|
| 494 | }
|
---|
| 495 | autosaveTask.schedule();
|
---|
| 496 | }
|
---|
| 497 | }
|
---|
| 498 |
|
---|
[6642] | 499 | private boolean handleNetworkOrProxyErrors(boolean hasErrors, String title, String message) {
|
---|
| 500 | if (hasErrors) {
|
---|
[6523] | 501 | ExtendedDialog ed = new ExtendedDialog(
|
---|
[6642] | 502 | Main.parent, title,
|
---|
[6523] | 503 | new String[]{tr("Change proxy settings"), tr("Cancel")});
|
---|
| 504 | ed.setButtonIcons(new String[]{"dialogs/settings.png", "cancel.png"}).setCancelButton(2);
|
---|
| 505 | ed.setMinimumSize(new Dimension(460, 260));
|
---|
| 506 | ed.setIcon(JOptionPane.WARNING_MESSAGE);
|
---|
[6642] | 507 | ed.setContent(message);
|
---|
[6523] | 508 |
|
---|
| 509 | if (ed.showDialog().getValue() == 1) {
|
---|
| 510 | PreferencesAction.forPreferenceSubTab(null, null, ProxyPreference.class).run();
|
---|
| 511 | }
|
---|
| 512 | }
|
---|
[6642] | 513 | return hasErrors;
|
---|
[6523] | 514 | }
|
---|
[6642] | 515 |
|
---|
| 516 | private boolean handleProxyErrors() {
|
---|
| 517 | return handleNetworkOrProxyErrors(proxySelector.hasErrors(), tr("Proxy errors occurred"),
|
---|
| 518 | tr("JOSM tried to access the following resources:<br>" +
|
---|
| 519 | "{0}" +
|
---|
| 520 | "but <b>failed</b> to do so, because of the following proxy errors:<br>" +
|
---|
| 521 | "{1}" +
|
---|
| 522 | "Would you like to change your proxy settings now?",
|
---|
| 523 | Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()),
|
---|
| 524 | Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages())
|
---|
| 525 | ));
|
---|
| 526 | }
|
---|
| 527 |
|
---|
| 528 | private boolean handleNetworkErrors() {
|
---|
[6806] | 529 | boolean condition = !NETWORK_ERRORS.isEmpty();
|
---|
[6642] | 530 | if (condition) {
|
---|
[7005] | 531 | Set<String> errors = new TreeSet<>();
|
---|
[6806] | 532 | for (Throwable t : NETWORK_ERRORS.values()) {
|
---|
[6642] | 533 | errors.add(t.toString());
|
---|
| 534 | }
|
---|
| 535 | return handleNetworkOrProxyErrors(condition, tr("Network errors occurred"),
|
---|
| 536 | tr("JOSM tried to access the following resources:<br>" +
|
---|
| 537 | "{0}" +
|
---|
| 538 | "but <b>failed</b> to do so, because of the following network errors:<br>" +
|
---|
| 539 | "{1}" +
|
---|
| 540 | "It may result of a missing proxy configuration.<br>" +
|
---|
| 541 | "Would you like to change your proxy settings now?",
|
---|
[6806] | 542 | Utils.joinAsHtmlUnorderedList(NETWORK_ERRORS.keySet()),
|
---|
[6642] | 543 | Utils.joinAsHtmlUnorderedList(errors)
|
---|
| 544 | ));
|
---|
| 545 | }
|
---|
| 546 | return false;
|
---|
| 547 | }
|
---|
[6523] | 548 | }
|
---|
[1677] | 549 | }
|
---|