[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;
|
---|
[283] | 6 |
|
---|
[6523] | 7 | import java.awt.Dimension;
|
---|
[3435] | 8 | import java.io.File;
|
---|
[7335] | 9 | import java.io.IOException;
|
---|
[7033] | 10 | import java.io.InputStream;
|
---|
[2641] | 11 | import java.net.Authenticator;
|
---|
[8356] | 12 | import java.net.Inet6Address;
|
---|
[8296] | 13 | import java.net.InetAddress;
|
---|
[2641] | 14 | import java.net.ProxySelector;
|
---|
[5201] | 15 | import java.net.URL;
|
---|
[3232] | 16 | import java.security.AllPermission;
|
---|
| 17 | import java.security.CodeSource;
|
---|
[10235] | 18 | import java.security.GeneralSecurityException;
|
---|
[7335] | 19 | import java.security.KeyStoreException;
|
---|
| 20 | import java.security.NoSuchAlgorithmException;
|
---|
[3232] | 21 | import java.security.PermissionCollection;
|
---|
| 22 | import java.security.Permissions;
|
---|
| 23 | import java.security.Policy;
|
---|
[7335] | 24 | import java.security.cert.CertificateException;
|
---|
[11650] | 25 | import java.util.ArrayList;
|
---|
[7434] | 26 | import java.util.Arrays;
|
---|
[283] | 27 | import java.util.Collection;
|
---|
[11650] | 28 | import java.util.Collections;
|
---|
[283] | 29 | import java.util.List;
|
---|
[8404] | 30 | import java.util.Locale;
|
---|
[11650] | 31 | import java.util.Map;
|
---|
[10899] | 32 | import java.util.Optional;
|
---|
[6642] | 33 | import java.util.Set;
|
---|
| 34 | import java.util.TreeSet;
|
---|
[10899] | 35 | import java.util.logging.Level;
|
---|
[11255] | 36 | import java.util.stream.Collectors;
|
---|
| 37 | import java.util.stream.Stream;
|
---|
[283] | 38 |
|
---|
[11455] | 39 | import javax.net.ssl.SSLSocketFactory;
|
---|
[6523] | 40 | import javax.swing.JOptionPane;
|
---|
[4720] | 41 | import javax.swing.RepaintManager;
|
---|
[3679] | 42 | import javax.swing.SwingUtilities;
|
---|
[283] | 43 |
|
---|
[4720] | 44 | import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
|
---|
[283] | 45 | import org.openstreetmap.josm.Main;
|
---|
[6523] | 46 | import org.openstreetmap.josm.actions.PreferencesAction;
|
---|
[9238] | 47 | import org.openstreetmap.josm.actions.RestartAction;
|
---|
[3378] | 48 | import org.openstreetmap.josm.data.AutosaveTask;
|
---|
[5201] | 49 | import org.openstreetmap.josm.data.CustomConfigurator;
|
---|
[4259] | 50 | import org.openstreetmap.josm.data.Version;
|
---|
[10899] | 51 | import org.openstreetmap.josm.gui.ProgramArguments.Option;
|
---|
[10093] | 52 | import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
|
---|
[4906] | 53 | import org.openstreetmap.josm.gui.download.DownloadDialog;
|
---|
[2748] | 54 | import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
|
---|
[6523] | 55 | import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
|
---|
[5796] | 56 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[9995] | 57 | import org.openstreetmap.josm.io.CertificateAmendment;
|
---|
[2641] | 58 | import org.openstreetmap.josm.io.DefaultProxySelector;
|
---|
[6349] | 59 | import org.openstreetmap.josm.io.MessageNotifier;
|
---|
[7434] | 60 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
[4245] | 61 | import org.openstreetmap.josm.io.auth.CredentialsManager;
|
---|
[2641] | 62 | import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
|
---|
[10931] | 63 | import org.openstreetmap.josm.io.protocols.data.Handler;
|
---|
[3707] | 64 | import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
|
---|
[1326] | 65 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
[2817] | 66 | import org.openstreetmap.josm.plugins.PluginInformation;
|
---|
[7383] | 67 | import org.openstreetmap.josm.tools.FontsManager;
|
---|
[9171] | 68 | import org.openstreetmap.josm.tools.HttpClient;
|
---|
[2017] | 69 | import org.openstreetmap.josm.tools.I18n;
|
---|
[10899] | 70 | import org.openstreetmap.josm.tools.Logging;
|
---|
[6453] | 71 | import org.openstreetmap.josm.tools.OsmUrlToBounds;
|
---|
[7335] | 72 | import org.openstreetmap.josm.tools.PlatformHookWindows;
|
---|
[5868] | 73 | import org.openstreetmap.josm.tools.Utils;
|
---|
[10340] | 74 | import org.openstreetmap.josm.tools.WindowGeometry;
|
---|
[10899] | 75 | import org.openstreetmap.josm.tools.bugreport.BugReport;
|
---|
[10055] | 76 | import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
|
---|
[1058] | 77 |
|
---|
[283] | 78 | /**
|
---|
| 79 | * Main window class application.
|
---|
| 80 | *
|
---|
| 81 | * @author imi
|
---|
| 82 | */
|
---|
| 83 | public class MainApplication extends Main {
|
---|
[8415] | 84 |
|
---|
[11650] | 85 | /**
|
---|
| 86 | * Command-line arguments used to run the application.
|
---|
| 87 | */
|
---|
| 88 | private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();
|
---|
| 89 |
|
---|
[10340] | 90 | private MainFrame mainFrame;
|
---|
| 91 |
|
---|
[1169] | 92 | /**
|
---|
[10340] | 93 | * Constructs a new {@code MainApplication} without a window.
|
---|
[1169] | 94 | */
|
---|
[8415] | 95 | public MainApplication() {
|
---|
[10340] | 96 | // Allow subclassing (see JOSM.java)
|
---|
| 97 | this(null);
|
---|
[8415] | 98 | }
|
---|
[1023] | 99 |
|
---|
[1169] | 100 | /**
|
---|
[5829] | 101 | * Constructs a main frame, ready sized and operating. Does not display the frame.
|
---|
| 102 | * @param mainFrame The main JFrame of the application
|
---|
[10340] | 103 | * @since 10340
|
---|
[1169] | 104 | */
|
---|
[10340] | 105 | public MainApplication(MainFrame mainFrame) {
|
---|
| 106 | this.mainFrame = mainFrame;
|
---|
[1169] | 107 | }
|
---|
[283] | 108 |
|
---|
[10340] | 109 | @Override
|
---|
| 110 | protected void initializeMainWindow() {
|
---|
[10467] | 111 | mainPanel.reAddListeners();
|
---|
[10340] | 112 | if (mainFrame != null) {
|
---|
| 113 | mainFrame.initialize();
|
---|
| 114 |
|
---|
| 115 | menu = mainFrame.getMenu();
|
---|
| 116 | } else {
|
---|
| 117 | // required for running some tests.
|
---|
| 118 | menu = new MainMenu();
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | @Override
|
---|
| 123 | protected void shutdown() {
|
---|
[11103] | 124 | if (mainFrame != null) {
|
---|
| 125 | mainFrame.storeState();
|
---|
| 126 | }
|
---|
[10340] | 127 | super.shutdown();
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[1169] | 130 | /**
|
---|
[11650] | 131 | * Returns the command-line arguments used to run the application.
|
---|
| 132 | * @return the command-line arguments used to run the application
|
---|
| 133 | * @since 11650
|
---|
| 134 | */
|
---|
| 135 | public static List<String> getCommandLineArgs() {
|
---|
| 136 | return Collections.unmodifiableList(COMMAND_LINE_ARGS);
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | /**
|
---|
[2748] | 140 | * Displays help on the console
|
---|
[6143] | 141 | * @since 2748
|
---|
[2748] | 142 | */
|
---|
| 143 | public static void showHelp() {
|
---|
| 144 | // TODO: put in a platformHook for system that have no console by default
|
---|
[10983] | 145 | System.out.println(getHelp());
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | static String getHelp() {
|
---|
| 149 | return tr("Java OpenStreetMap Editor")+" ["
|
---|
[5363] | 150 | +Version.getInstance().getAgentString()+"]\n\n"+
|
---|
[2748] | 151 | tr("usage")+":\n"+
|
---|
| 152 | "\tjava -jar josm.jar <options>...\n\n"+
|
---|
| 153 | tr("options")+":\n"+
|
---|
[8846] | 154 | "\t--help|-h "+tr("Show this help")+'\n'+
|
---|
| 155 | "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+'\n'+
|
---|
| 156 | "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+'\n'+
|
---|
| 157 | "\t[--download=]<URL> "+tr("Download the location at the URL (with lat=x&lon=y&zoom=z)")+'\n'+
|
---|
| 158 | "\t[--download=]<filename> "+tr("Open a file (any file type that can be opened with File/Open)")+'\n'+
|
---|
| 159 | "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw GPS")+'\n'+
|
---|
| 160 | "\t--downloadgps=<URL> "+tr("Download the location at the URL (with lat=x&lon=y&zoom=z) as raw GPS")+'\n'+
|
---|
| 161 | "\t--selection=<searchstring> "+tr("Select with the given search")+'\n'+
|
---|
| 162 | "\t--[no-]maximize "+tr("Launch in maximized mode")+'\n'+
|
---|
[2748] | 163 | "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
|
---|
[5201] | 164 | "\t--load-preferences=<url-to-xml> "+tr("Changes preferences according to the XML file")+"\n\n"+
|
---|
[4789] | 165 | "\t--set=<key>=<value> "+tr("Set preference key to value")+"\n\n"+
|
---|
[2800] | 166 | "\t--language=<language> "+tr("Set the language")+"\n\n"+
|
---|
[5365] | 167 | "\t--version "+tr("Displays the JOSM version and exits")+"\n\n"+
|
---|
[6730] | 168 | "\t--debug "+tr("Print debugging messages to console")+"\n\n"+
|
---|
[8169] | 169 | "\t--skip-plugins "+tr("Skip loading plugins")+"\n\n"+
|
---|
[7434] | 170 | "\t--offline=<osm_api|josm_website|all> "+tr("Disable access to the given resource(s), separated by comma")+"\n\n"+
|
---|
[2748] | 171 | tr("options provided as Java system properties")+":\n"+
|
---|
[11255] | 172 | align("\t-Djosm.dir.name=JOSM") + tr("Change the JOSM directory name") + "\n\n" +
|
---|
| 173 | align("\t-Djosm.pref=" + tr("/PATH/TO/JOSM/PREF ")) + tr("Set the preferences directory") + "\n" +
|
---|
| 174 | align("\t") + tr("Default: {0}", platform.getDefaultPrefDirectory()) + "\n\n" +
|
---|
| 175 | align("\t-Djosm.userdata=" + tr("/PATH/TO/JOSM/USERDATA")) + tr("Set the user data directory") + "\n" +
|
---|
| 176 | align("\t") + tr("Default: {0}", platform.getDefaultUserDataDirectory()) + "\n\n" +
|
---|
| 177 | align("\t-Djosm.cache=" + tr("/PATH/TO/JOSM/CACHE ")) + tr("Set the cache directory") + "\n" +
|
---|
| 178 | align("\t") + tr("Default: {0}", platform.getDefaultCacheDirectory()) + "\n\n" +
|
---|
| 179 | align("\t-Djosm.home=" + tr("/PATH/TO/JOSM/HOMEDIR ")) +
|
---|
| 180 | tr("Set the preferences+data+cache directory (cache directory will be josm.home/cache)")+"\n\n"+
|
---|
[7843] | 181 | tr("-Djosm.home has lower precedence, i.e. the specific setting overrides the general one")+"\n\n"+
|
---|
[2748] | 182 | tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" +
|
---|
[4720] | 183 | " Java option to specify the maximum size of allocated memory in megabytes")+":\n"+
|
---|
| 184 | "\t-Xmx...m\n\n"+
|
---|
[10983] | 185 | tr("examples")+":\n"+
|
---|
| 186 | "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
|
---|
| 187 | "\tjava -jar josm.jar "+OsmUrlToBounds.getURL(43.2, 11.1, 13)+'\n'+
|
---|
| 188 | "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
|
---|
| 189 | "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n"+
|
---|
| 190 | "\tjava -Djosm.pref=$XDG_CONFIG_HOME -Djosm.userdata=$XDG_DATA_HOME -Djosm.cache=$XDG_CACHE_HOME -jar josm.jar\n"+
|
---|
[11255] | 191 | "\tjava -Djosm.dir.name=josm_dev -jar josm.jar\n"+
|
---|
[10983] | 192 | "\tjava -Djosm.home=/home/user/.josm_dev -jar josm.jar\n"+
|
---|
| 193 | "\tjava -Xmx1024m -jar josm.jar\n\n"+
|
---|
| 194 | tr("Parameters --download, --downloadgps, and --selection are processed in this order.")+'\n'+
|
---|
| 195 | tr("Make sure you load some data if you use --selection.")+'\n';
|
---|
[2748] | 196 | }
|
---|
| 197 |
|
---|
[11255] | 198 | private static String align(String str) {
|
---|
| 199 | return str + Stream.generate(() -> " ").limit(Math.max(0, 43 - str.length())).collect(Collectors.joining(""));
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[6143] | 202 | /**
|
---|
[2856] | 203 | * Main application Startup
|
---|
[5829] | 204 | * @param argArray Command-line arguments
|
---|
[2856] | 205 | */
|
---|
| 206 | public static void main(final String[] argArray) {
|
---|
| 207 | I18n.init();
|
---|
[6108] | 208 |
|
---|
| 209 | // construct argument table
|
---|
[10899] | 210 | ProgramArguments args = null;
|
---|
[6108] | 211 | try {
|
---|
[10899] | 212 | args = new ProgramArguments(argArray);
|
---|
[6108] | 213 | } catch (IllegalArgumentException e) {
|
---|
[10983] | 214 | System.err.println(e.getMessage());
|
---|
[6108] | 215 | System.exit(1);
|
---|
[7434] | 216 | return;
|
---|
[6108] | 217 | }
|
---|
[6830] | 218 |
|
---|
[10899] | 219 | Level logLevel = args.getLogLevel();
|
---|
| 220 | Logging.setLogLevel(logLevel);
|
---|
[10983] | 221 | if (!args.showVersion() && !args.showHelp()) {
|
---|
| 222 | Main.info(tr("Log level is at {0} ({1}, {2})", logLevel.getLocalizedName(), logLevel.getName(), logLevel.intValue()));
|
---|
| 223 | }
|
---|
[6108] | 224 |
|
---|
[10899] | 225 | Optional<String> language = args.getSingle(Option.LANGUAGE);
|
---|
| 226 | I18n.set(language.orElse(null));
|
---|
[6108] | 227 |
|
---|
[3232] | 228 | Policy.setPolicy(new Policy() {
|
---|
| 229 | // Permissions for plug-ins loaded when josm is started via webstart
|
---|
| 230 | private PermissionCollection pc;
|
---|
| 231 |
|
---|
| 232 | {
|
---|
| 233 | pc = new Permissions();
|
---|
| 234 | pc.add(new AllPermission());
|
---|
| 235 | }
|
---|
| 236 |
|
---|
| 237 | @Override
|
---|
| 238 | public PermissionCollection getPermissions(CodeSource codesource) {
|
---|
| 239 | return pc;
|
---|
| 240 | }
|
---|
| 241 | });
|
---|
| 242 |
|
---|
[2856] | 243 | Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
|
---|
| 244 |
|
---|
[3815] | 245 | // initialize the platform hook, and
|
---|
[2856] | 246 | Main.determinePlatformHook();
|
---|
[4259] | 247 | // call the really early hook before we do anything else
|
---|
[2856] | 248 | Main.platform.preStartupHook();
|
---|
| 249 |
|
---|
[10899] | 250 | if (args.showVersion()) {
|
---|
[4259] | 251 | System.out.println(Version.getInstance().getAgentString());
|
---|
[10983] | 252 | return;
|
---|
[10899] | 253 | } else if (args.showHelp()) {
|
---|
| 254 | showHelp();
|
---|
[10983] | 255 | return;
|
---|
[6108] | 256 | }
|
---|
[4259] | 257 |
|
---|
[11650] | 258 | COMMAND_LINE_ARGS.addAll(Arrays.asList(argArray));
|
---|
[10983] | 259 |
|
---|
[10899] | 260 | boolean skipLoadingPlugins = args.hasOption(Option.SKIP_PLUGINS);
|
---|
| 261 | if (skipLoadingPlugins) {
|
---|
[8175] | 262 | Main.info(tr("Plugin loading skipped"));
|
---|
[8169] | 263 | }
|
---|
| 264 |
|
---|
[10899] | 265 | if (Logging.isLoggingEnabled(Logging.LEVEL_TRACE)) {
|
---|
| 266 | // Enable debug in OAuth signpost via system preference, but only at trace level
|
---|
| 267 | Utils.updateSystemProperty("debug", "true");
|
---|
| 268 | Main.info(tr("Enabled detailed debug level (trace)"));
|
---|
[8296] | 269 | }
|
---|
| 270 |
|
---|
[10899] | 271 | Main.pref.init(args.hasOption(Option.RESET_PREFERENCES));
|
---|
| 272 |
|
---|
| 273 | args.getPreferencesToSet().forEach(Main.pref::put);
|
---|
| 274 |
|
---|
| 275 | if (!language.isPresent()) {
|
---|
[1802] | 276 | I18n.set(Main.pref.get("language", null));
|
---|
[2025] | 277 | }
|
---|
[2358] | 278 | Main.pref.updateSystemProperties();
|
---|
[1326] | 279 |
|
---|
[8296] | 280 | checkIPv6();
|
---|
| 281 |
|
---|
[7434] | 282 | processOffline(args);
|
---|
| 283 |
|
---|
[8015] | 284 | Main.platform.afterPrefStartupHook();
|
---|
| 285 |
|
---|
[7383] | 286 | FontsManager.initialize();
|
---|
[7434] | 287 |
|
---|
[8282] | 288 | I18n.setupLanguageFonts();
|
---|
[7896] | 289 |
|
---|
[10931] | 290 | Handler.install();
|
---|
| 291 |
|
---|
[10340] | 292 | WindowGeometry geometry = WindowGeometry.mainWindow("gui.geometry",
|
---|
[10899] | 293 | args.getSingle(Option.GEOMETRY).orElse(null),
|
---|
| 294 | !args.hasOption(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false));
|
---|
[11713] | 295 | final MainFrame mainFrame = new MainFrame(contentPanePrivate, geometry);
|
---|
[5201] | 296 | Main.parent = mainFrame;
|
---|
| 297 |
|
---|
[10899] | 298 | if (args.hasOption(Option.LOAD_PREFERENCES)) {
|
---|
[5201] | 299 | CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
|
---|
[5279] | 300 | for (String i : args.get(Option.LOAD_PREFERENCES)) {
|
---|
[6248] | 301 | info("Reading preferences from " + i);
|
---|
[11509] | 302 | try (InputStream is = openStream(new URL(i))) {
|
---|
[7033] | 303 | config.openAndReadXML(is);
|
---|
[10212] | 304 | } catch (IOException ex) {
|
---|
[10899] | 305 | throw BugReport.intercept(ex).put("file", i);
|
---|
[5201] | 306 | }
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[9995] | 310 | try {
|
---|
| 311 | CertificateAmendment.addMissingCertificates();
|
---|
[10235] | 312 | } catch (IOException | GeneralSecurityException ex) {
|
---|
[10296] | 313 | Main.warn(ex);
|
---|
[9995] | 314 | Main.warn(getErrorMessage(Utils.getRootCause(ex)));
|
---|
| 315 | }
|
---|
[2748] | 316 | Authenticator.setDefault(DefaultAuthenticator.getInstance());
|
---|
[6523] | 317 | DefaultProxySelector proxySelector = new DefaultProxySelector(ProxySelector.getDefault());
|
---|
| 318 | ProxySelector.setDefault(proxySelector);
|
---|
[4245] | 319 | OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance());
|
---|
[2641] | 320 |
|
---|
[10611] | 321 | final SplashScreen splash = GuiHelper.runInEDTAndWaitAndReturn(SplashScreen::new);
|
---|
[8497] | 322 | final SplashScreen.SplashProgressMonitor monitor = splash.getProgressMonitor();
|
---|
[2817] | 323 | monitor.beginTask(tr("Initializing"));
|
---|
[10611] | 324 | GuiHelper.runInEDT(() -> splash.setVisible(Main.pref.getBoolean("draw.splashscreen", true)));
|
---|
[4681] | 325 | Main.setInitStatusListener(new InitStatusListener() {
|
---|
[1023] | 326 |
|
---|
[4681] | 327 | @Override
|
---|
[8497] | 328 | public Object updateStatus(String event) {
|
---|
| 329 | monitor.beginTask(event);
|
---|
| 330 | return event;
|
---|
[4681] | 331 | }
|
---|
[8497] | 332 |
|
---|
| 333 | @Override
|
---|
| 334 | public void finish(Object status) {
|
---|
| 335 | if (status instanceof String) {
|
---|
| 336 | monitor.finishTask((String) status);
|
---|
| 337 | }
|
---|
| 338 | }
|
---|
[4681] | 339 | });
|
---|
| 340 |
|
---|
[8169] | 341 | Collection<PluginInformation> pluginsToLoad = null;
|
---|
[283] | 342 |
|
---|
[8169] | 343 | if (!skipLoadingPlugins) {
|
---|
[10093] | 344 | pluginsToLoad = updateAndLoadEarlyPlugins(splash, monitor);
|
---|
[8169] | 345 | }
|
---|
| 346 |
|
---|
[4681] | 347 | monitor.indeterminateSubTask(tr("Setting defaults"));
|
---|
[10962] | 348 | preConstructorInit();
|
---|
[2817] | 349 |
|
---|
| 350 | monitor.indeterminateSubTask(tr("Creating main GUI"));
|
---|
| 351 | final Main main = new MainApplication(mainFrame);
|
---|
[10340] | 352 | main.initialize();
|
---|
[2817] | 353 |
|
---|
[8169] | 354 | if (!skipLoadingPlugins) {
|
---|
[10093] | 355 | loadLatePlugins(splash, monitor, pluginsToLoad);
|
---|
[8169] | 356 | }
|
---|
[5796] | 357 |
|
---|
[6866] | 358 | // Wait for splash disappearance (fix #9714)
|
---|
[10611] | 359 | GuiHelper.runInEDTAndWait(() -> {
|
---|
| 360 | splash.setVisible(false);
|
---|
| 361 | splash.dispose();
|
---|
| 362 | mainFrame.setVisible(true);
|
---|
[5796] | 363 | });
|
---|
| 364 |
|
---|
[6578] | 365 | boolean maximized = Main.pref.getBoolean("gui.maximized", false);
|
---|
[10899] | 366 | if ((!args.hasOption(Option.NO_MAXIMIZE) && maximized) || args.hasOption(Option.MAXIMIZE)) {
|
---|
[10340] | 367 | mainFrame.setMaximized(true);
|
---|
[2025] | 368 | }
|
---|
[6246] | 369 | if (main.menu.fullscreenToggleAction != null) {
|
---|
[4139] | 370 | main.menu.fullscreenToggleAction.initial();
|
---|
[4720] | 371 | }
|
---|
[1023] | 372 |
|
---|
[6523] | 373 | SwingUtilities.invokeLater(new GuiFinalizationWorker(args, proxySelector));
|
---|
[5279] | 374 |
|
---|
[7335] | 375 | if (Main.isPlatformWindows()) {
|
---|
| 376 | try {
|
---|
| 377 | // Check for insecure certificates to remove.
|
---|
[8509] | 378 | // This is Windows-dependant code but it can't go to preStartupHook (need i18n)
|
---|
| 379 | // neither startupHook (need to be called before remote control)
|
---|
[7343] | 380 | PlatformHookWindows.removeInsecureCertificates();
|
---|
[7335] | 381 | } catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException e) {
|
---|
| 382 | error(e);
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 |
|
---|
[3959] | 386 | if (RemoteControl.PROP_REMOTECONTROL_ENABLED.get()) {
|
---|
| 387 | RemoteControl.start();
|
---|
| 388 | }
|
---|
[6830] | 389 |
|
---|
[6349] | 390 | if (MessageNotifier.PROP_NOTIFIER_ENABLED.get()) {
|
---|
| 391 | MessageNotifier.start();
|
---|
| 392 | }
|
---|
[3959] | 393 |
|
---|
[4720] | 394 | if (Main.pref.getBoolean("debug.edt-checker.enable", Version.getInstance().isLocalBuild())) {
|
---|
[8509] | 395 | // Repaint manager is registered so late for a reason - there is lots of violation during startup process
|
---|
| 396 | // but they don't seem to break anything and are difficult to fix
|
---|
[6248] | 397 | info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console");
|
---|
[4720] | 398 | RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
|
---|
| 399 | }
|
---|
[1169] | 400 | }
|
---|
[6523] | 401 |
|
---|
[11509] | 402 | private static InputStream openStream(URL url) throws IOException {
|
---|
| 403 | if ("file".equals(url.getProtocol())) {
|
---|
| 404 | return url.openStream();
|
---|
| 405 | } else {
|
---|
| 406 | return HttpClient.create(url).connect().getContent();
|
---|
| 407 | }
|
---|
| 408 | }
|
---|
| 409 |
|
---|
[10093] | 410 | static Collection<PluginInformation> updateAndLoadEarlyPlugins(SplashScreen splash, SplashProgressMonitor monitor) {
|
---|
| 411 | Collection<PluginInformation> pluginsToLoad;
|
---|
| 412 | pluginsToLoad = PluginHandler.buildListOfPluginsToLoad(splash, monitor.createSubTaskMonitor(1, false));
|
---|
| 413 | if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) {
|
---|
| 414 | monitor.subTask(tr("Updating plugins"));
|
---|
| 415 | pluginsToLoad = PluginHandler.updatePlugins(splash, null, monitor.createSubTaskMonitor(1, false), false);
|
---|
| 416 | }
|
---|
| 417 |
|
---|
| 418 | monitor.indeterminateSubTask(tr("Installing updated plugins"));
|
---|
| 419 | PluginHandler.installDownloadedPlugins(true);
|
---|
| 420 |
|
---|
| 421 | monitor.indeterminateSubTask(tr("Loading early plugins"));
|
---|
| 422 | PluginHandler.loadEarlyPlugins(splash, pluginsToLoad, monitor.createSubTaskMonitor(1, false));
|
---|
| 423 | return pluginsToLoad;
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | static void loadLatePlugins(SplashScreen splash, SplashProgressMonitor monitor, Collection<PluginInformation> pluginsToLoad) {
|
---|
| 427 | monitor.indeterminateSubTask(tr("Loading plugins"));
|
---|
| 428 | PluginHandler.loadLatePlugins(splash, pluginsToLoad, monitor.createSubTaskMonitor(1, false));
|
---|
| 429 | toolbar.refreshToolbarControl();
|
---|
| 430 | }
|
---|
| 431 |
|
---|
[10899] | 432 | private static void processOffline(ProgramArguments args) {
|
---|
| 433 | for (String offlineNames : args.get(Option.OFFLINE)) {
|
---|
| 434 | for (String s : offlineNames.split(",")) {
|
---|
[7434] | 435 | try {
|
---|
[8404] | 436 | Main.setOffline(OnlineResource.valueOf(s.toUpperCase(Locale.ENGLISH)));
|
---|
[7434] | 437 | } catch (IllegalArgumentException e) {
|
---|
[10627] | 438 | Main.error(e, tr("''{0}'' is not a valid value for argument ''{1}''. Possible values are {2}, possibly delimited by commas.",
|
---|
[8404] | 439 | s.toUpperCase(Locale.ENGLISH), Option.OFFLINE.getName(), Arrays.toString(OnlineResource.values())));
|
---|
[7434] | 440 | System.exit(1);
|
---|
| 441 | return;
|
---|
| 442 | }
|
---|
| 443 | }
|
---|
| 444 | }
|
---|
[10899] | 445 | Set<OnlineResource> offline = Main.getOfflineResources();
|
---|
| 446 | if (!offline.isEmpty()) {
|
---|
| 447 | Main.warn(trn("JOSM is running in offline mode. This resource will not be available: {0}",
|
---|
| 448 | "JOSM is running in offline mode. These resources will not be available: {0}",
|
---|
| 449 | offline.size(), offline.size() == 1 ? offline.iterator().next() : Arrays.toString(offline.toArray())));
|
---|
| 450 | }
|
---|
[7434] | 451 | }
|
---|
| 452 |
|
---|
[8296] | 453 | /**
|
---|
| 454 | * Check if IPv6 can be safely enabled and do so. Because this cannot be done after network activation,
|
---|
| 455 | * disabling or enabling IPV6 may only be done with next start.
|
---|
| 456 | */
|
---|
| 457 | private static void checkIPv6() {
|
---|
[8510] | 458 | if ("auto".equals(Main.pref.get("prefer.ipv6", "auto"))) {
|
---|
[10611] | 459 | new Thread((Runnable) () -> { /* this may take some time (DNS, Connect) */
|
---|
| 460 | boolean hasv6 = false;
|
---|
| 461 | boolean wasv6 = Main.pref.getBoolean("validated.ipv6", false);
|
---|
| 462 | try {
|
---|
| 463 | /* Use the check result from last run of the software, as after the test, value
|
---|
| 464 | changes have no effect anymore */
|
---|
| 465 | if (wasv6) {
|
---|
| 466 | Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
|
---|
| 467 | }
|
---|
| 468 | for (InetAddress a : InetAddress.getAllByName("josm.openstreetmap.de")) {
|
---|
| 469 | if (a instanceof Inet6Address) {
|
---|
| 470 | if (a.isReachable(1000)) {
|
---|
| 471 | /* be sure it REALLY works */
|
---|
[11455] | 472 | SSLSocketFactory.getDefault().createSocket(a, 443).close();
|
---|
[10611] | 473 | Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
|
---|
| 474 | if (!wasv6) {
|
---|
| 475 | Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4 after next restart."));
|
---|
| 476 | } else {
|
---|
| 477 | Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4."));
|
---|
[8296] | 478 | }
|
---|
[10611] | 479 | hasv6 = true;
|
---|
[8296] | 480 | }
|
---|
[10611] | 481 | break; /* we're done */
|
---|
[8296] | 482 | }
|
---|
| 483 | }
|
---|
[10611] | 484 | } catch (IOException | SecurityException e) {
|
---|
| 485 | if (Main.isDebugEnabled()) {
|
---|
| 486 | Main.debug("Exception while checking IPv6 connectivity: "+e);
|
---|
[8296] | 487 | }
|
---|
[10645] | 488 | Main.trace(e);
|
---|
[8296] | 489 | }
|
---|
[10611] | 490 | if (wasv6 && !hasv6) {
|
---|
| 491 | Main.info(tr("Detected no useable IPv6 network, prefering IPv4 over IPv6 after next restart."));
|
---|
| 492 | Main.pref.put("validated.ipv6", hasv6); // be sure it is stored before the restart!
|
---|
| 493 | new RestartAction().actionPerformed(null);
|
---|
| 494 | }
|
---|
| 495 | Main.pref.put("validated.ipv6", hasv6);
|
---|
[8736] | 496 | }, "IPv6-checker").start();
|
---|
[8296] | 497 | }
|
---|
| 498 | }
|
---|
[8356] | 499 |
|
---|
[6523] | 500 | private static class GuiFinalizationWorker implements Runnable {
|
---|
| 501 |
|
---|
[10899] | 502 | private final ProgramArguments args;
|
---|
[6523] | 503 | private final DefaultProxySelector proxySelector;
|
---|
| 504 |
|
---|
[10899] | 505 | GuiFinalizationWorker(ProgramArguments args, DefaultProxySelector proxySelector) {
|
---|
[6523] | 506 | this.args = args;
|
---|
| 507 | this.proxySelector = proxySelector;
|
---|
| 508 | }
|
---|
| 509 |
|
---|
| 510 | @Override
|
---|
| 511 | public void run() {
|
---|
| 512 |
|
---|
[6642] | 513 | // Handle proxy/network errors early to inform user he should change settings to be able to use JOSM correctly
|
---|
| 514 | if (!handleProxyErrors()) {
|
---|
| 515 | handleNetworkErrors();
|
---|
| 516 | }
|
---|
[6523] | 517 |
|
---|
| 518 | // Restore autosave layers after crash and start autosave thread
|
---|
| 519 | handleAutosave();
|
---|
| 520 |
|
---|
| 521 | // Handle command line instructions
|
---|
| 522 | postConstructorProcessCmdLine(args);
|
---|
| 523 |
|
---|
| 524 | // Show download dialog if autostart is enabled
|
---|
| 525 | DownloadDialog.autostartIfNeeded();
|
---|
| 526 | }
|
---|
| 527 |
|
---|
[8870] | 528 | private static void handleAutosave() {
|
---|
[6523] | 529 | if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) {
|
---|
| 530 | AutosaveTask autosaveTask = new AutosaveTask();
|
---|
| 531 | List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles();
|
---|
| 532 | if (!unsavedLayerFiles.isEmpty()) {
|
---|
| 533 | ExtendedDialog dialog = new ExtendedDialog(
|
---|
| 534 | Main.parent,
|
---|
| 535 | tr("Unsaved osm data"),
|
---|
| 536 | new String[] {tr("Restore"), tr("Cancel"), tr("Discard")}
|
---|
| 537 | );
|
---|
| 538 | dialog.setContent(
|
---|
| 539 | trn("JOSM found {0} unsaved osm data layer. ",
|
---|
| 540 | "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) +
|
---|
| 541 | tr("It looks like JOSM crashed last time. Would you like to restore the data?"));
|
---|
| 542 | dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/delete"});
|
---|
| 543 | int selection = dialog.showDialog().getValue();
|
---|
| 544 | if (selection == 1) {
|
---|
| 545 | autosaveTask.recoverUnsavedLayers();
|
---|
| 546 | } else if (selection == 3) {
|
---|
[6995] | 547 | autosaveTask.discardUnsavedLayers();
|
---|
[6523] | 548 | }
|
---|
| 549 | }
|
---|
| 550 | autosaveTask.schedule();
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
| 553 |
|
---|
[10043] | 554 | private static boolean handleNetworkOrProxyErrors(boolean hasErrors, String title, String message) {
|
---|
[6642] | 555 | if (hasErrors) {
|
---|
[6523] | 556 | ExtendedDialog ed = new ExtendedDialog(
|
---|
[6642] | 557 | Main.parent, title,
|
---|
[6523] | 558 | new String[]{tr("Change proxy settings"), tr("Cancel")});
|
---|
[8061] | 559 | ed.setButtonIcons(new String[]{"dialogs/settings", "cancel"}).setCancelButton(2);
|
---|
[6523] | 560 | ed.setMinimumSize(new Dimension(460, 260));
|
---|
| 561 | ed.setIcon(JOptionPane.WARNING_MESSAGE);
|
---|
[6642] | 562 | ed.setContent(message);
|
---|
[6523] | 563 |
|
---|
| 564 | if (ed.showDialog().getValue() == 1) {
|
---|
| 565 | PreferencesAction.forPreferenceSubTab(null, null, ProxyPreference.class).run();
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
[6642] | 568 | return hasErrors;
|
---|
[6523] | 569 | }
|
---|
[6642] | 570 |
|
---|
| 571 | private boolean handleProxyErrors() {
|
---|
| 572 | return handleNetworkOrProxyErrors(proxySelector.hasErrors(), tr("Proxy errors occurred"),
|
---|
| 573 | tr("JOSM tried to access the following resources:<br>" +
|
---|
| 574 | "{0}" +
|
---|
| 575 | "but <b>failed</b> to do so, because of the following proxy errors:<br>" +
|
---|
| 576 | "{1}" +
|
---|
| 577 | "Would you like to change your proxy settings now?",
|
---|
| 578 | Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()),
|
---|
| 579 | Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages())
|
---|
| 580 | ));
|
---|
| 581 | }
|
---|
| 582 |
|
---|
[10755] | 583 | private static boolean handleNetworkErrors() {
|
---|
[11650] | 584 | Map<String, Throwable> networkErrors = Main.getNetworkErrors();
|
---|
| 585 | boolean condition = !networkErrors.isEmpty();
|
---|
[6642] | 586 | if (condition) {
|
---|
[7005] | 587 | Set<String> errors = new TreeSet<>();
|
---|
[11650] | 588 | for (Throwable t : networkErrors.values()) {
|
---|
[6642] | 589 | errors.add(t.toString());
|
---|
| 590 | }
|
---|
| 591 | return handleNetworkOrProxyErrors(condition, tr("Network errors occurred"),
|
---|
| 592 | tr("JOSM tried to access the following resources:<br>" +
|
---|
| 593 | "{0}" +
|
---|
| 594 | "but <b>failed</b> to do so, because of the following network errors:<br>" +
|
---|
| 595 | "{1}" +
|
---|
[7187] | 596 | "It may be due to a missing proxy configuration.<br>" +
|
---|
[6642] | 597 | "Would you like to change your proxy settings now?",
|
---|
[11650] | 598 | Utils.joinAsHtmlUnorderedList(networkErrors.keySet()),
|
---|
[6642] | 599 | Utils.joinAsHtmlUnorderedList(errors)
|
---|
| 600 | ));
|
---|
| 601 | }
|
---|
| 602 | return false;
|
---|
| 603 | }
|
---|
[6523] | 604 | }
|
---|
[1677] | 605 | }
|
---|