Changeset 12629 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-08-23T21:00:42+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r12620 r12629 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.BorderLayout;7 6 import java.awt.Component; 8 7 import java.awt.GraphicsEnvironment; 9 import java.awt.event.KeyEvent;10 8 import java.io.File; 11 9 import java.io.IOException; … … 43 41 import javax.swing.UnsupportedLookAndFeelException; 44 42 45 import org.openstreetmap.gui.jmapviewer.FeatureAdapter;46 43 import org.openstreetmap.josm.actions.JosmAction; 47 44 import org.openstreetmap.josm.actions.OpenFileAction; … … 63 60 import org.openstreetmap.josm.data.projection.Projection; 64 61 import org.openstreetmap.josm.data.projection.ProjectionChangeListener; 65 import org.openstreetmap.josm.data.validation.OsmValidator;66 62 import org.openstreetmap.josm.gui.MainMenu; 67 63 import org.openstreetmap.josm.gui.MainPanel; … … 73 69 import org.openstreetmap.josm.gui.layer.MainLayerManager; 74 70 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener; 75 import org.openstreetmap.josm.gui.layer.TMSLayer;76 71 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 77 72 import org.openstreetmap.josm.gui.preferences.display.LafPreference; 78 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;79 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;80 73 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 81 74 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 82 75 import org.openstreetmap.josm.gui.progress.ProgressMonitorExecutor; 83 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;84 76 import org.openstreetmap.josm.gui.util.GuiHelper; 85 77 import org.openstreetmap.josm.gui.util.RedirectInputMap; … … 87 79 import org.openstreetmap.josm.io.OnlineResource; 88 80 import org.openstreetmap.josm.io.OsmApi; 89 import org.openstreetmap.josm.io.OsmApiInitializationException;90 import org.openstreetmap.josm.io.OsmTransferCanceledException;91 81 import org.openstreetmap.josm.plugins.PluginHandler; 92 82 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 95 85 import org.openstreetmap.josm.tools.JosmRuntimeException; 96 86 import org.openstreetmap.josm.tools.Logging; 97 import org.openstreetmap.josm.tools.OpenBrowser;98 87 import org.openstreetmap.josm.tools.OsmUrlToBounds; 99 import org.openstreetmap.josm.tools.OverpassTurboQueryWizard;100 88 import org.openstreetmap.josm.tools.PlatformHook; 101 89 import org.openstreetmap.josm.tools.PlatformHookOsx; 102 90 import org.openstreetmap.josm.tools.PlatformHookUnixoid; 103 91 import org.openstreetmap.josm.tools.PlatformHookWindows; 104 import org.openstreetmap.josm.tools.RightAndLefthandTraffic;105 92 import org.openstreetmap.josm.tools.Shortcut; 106 import org.openstreetmap.josm.tools.Territories;107 93 import org.openstreetmap.josm.tools.Utils; 108 94 import org.openstreetmap.josm.tools.bugreport.BugReport; … … 558 544 */ 559 545 public void initialize() { 560 fileWatcher.start(); 561 562 new InitializationTask(tr("Executing platform startup hook"), platform::startupHook).call(); 563 564 new InitializationTask(tr("Building main menu"), this::initializeMainWindow).call(); 565 566 undoRedo.addCommandQueueListener(redoUndoListener); 567 568 // creating toolbar 569 GuiHelper.runInEDTAndWait(() -> contentPanePrivate.add(toolbar.control, BorderLayout.NORTH)); 570 571 registerActionShortcut(menu.help, Shortcut.registerShortcut("system:help", tr("Help"), 572 KeyEvent.VK_F1, Shortcut.DIRECT)); 573 574 // This needs to be done before RightAndLefthandTraffic::initialize is called 575 try { 576 new InitializationTask(tr("Initializing internal boundaries data"), Territories::initialize).call(); 577 } catch (JosmRuntimeException e) { 578 // Can happen if the current projection needs NTV2 grid which is not available 579 // In this case we want the user be able to change his projection 580 BugReport.intercept(e).warn(); 581 } 582 583 // contains several initialization tasks to be executed (in parallel) by a ExecutorService 584 List<Callable<Void>> tasks = new ArrayList<>(); 585 586 tasks.add(new InitializationTask(tr("Initializing OSM API"), () -> { 587 // We try to establish an API connection early, so that any API 588 // capabilities are already known to the editor instance. However 589 // if it goes wrong that's not critical at this stage. 590 try { 591 OsmApi.getOsmApi().initialize(null, true); 592 } catch (OsmTransferCanceledException | OsmApiInitializationException e) { 593 Logging.warn(getErrorMessage(Utils.getRootCause(e))); 594 } 595 })); 596 597 tasks.add(new InitializationTask(tr("Initializing internal traffic data"), RightAndLefthandTraffic::initialize)); 598 599 tasks.add(new InitializationTask(tr("Initializing validator"), OsmValidator::initialize)); 600 601 tasks.add(new InitializationTask(tr("Initializing presets"), TaggingPresets::initialize)); 602 603 tasks.add(new InitializationTask(tr("Initializing map styles"), MapPaintPreference::initialize)); 604 605 tasks.add(new InitializationTask(tr("Loading imagery preferences"), ImageryPreference::initialize)); 606 546 // Initializes tasks that must be run before parallel tasks 547 runInitializationTasks(beforeInitializationTasks()); 548 549 // Initializes tasks to be executed (in parallel) by a ExecutorService 607 550 try { 608 551 ExecutorService service = Executors.newFixedThreadPool( 609 552 Runtime.getRuntime().availableProcessors(), Utils.newThreadFactory("main-init-%d", Thread.NORM_PRIORITY)); 610 for (Future<Void> i : service.invokeAll( tasks)) {553 for (Future<Void> i : service.invokeAll(parallelInitializationTasks())) { 611 554 i.get(); 612 555 } 613 556 // asynchronous initializations to be completed eventually 614 service.submit((Runnable) TMSLayer::getCache); 615 service.submit((Runnable) OsmValidator::initializeTests); 616 service.submit(OverpassTurboQueryWizard::getInstance); 557 asynchronousRunnableTasks().forEach(service::submit); 558 asynchronousCallableTasks().forEach(service::submit); 617 559 service.shutdown(); 618 560 } catch (InterruptedException | ExecutionException ex) { … … 620 562 } 621 563 622 // hooks for the jmapviewer component 623 FeatureAdapter.registerBrowserAdapter(OpenBrowser::displayUrl); 624 FeatureAdapter.registerTranslationAdapter(I18n.getTranslationAdapter()); 625 FeatureAdapter.registerLoggingAdapter(name -> Logging.getLogger()); 626 627 new InitializationTask(tr("Updating user interface"), () -> GuiHelper.runInEDTAndWait(() -> { 628 toolbar.refreshToolbarControl(); 629 toolbar.control.updateUI(); 630 contentPanePrivate.updateUI(); 631 })).call(); 564 // Initializes tasks that must be run after parallel tasks 565 runInitializationTasks(afterInitializationTasks()); 566 } 567 568 private static void runInitializationTasks(List<InitializationTask> tasks) { 569 for (InitializationTask task : tasks) { 570 try { 571 task.call(); 572 } catch (JosmRuntimeException e) { 573 // Can happen if the current projection needs NTV2 grid which is not available 574 // In this case we want the user be able to change his projection 575 BugReport.intercept(e).warn(); 576 } 577 } 578 } 579 580 /** 581 * Returns tasks that must be run before parallel tasks. 582 * @return tasks that must be run before parallel tasks 583 * @see #afterInitializationTasks 584 * @see #parallelInitializationTasks 585 */ 586 protected List<InitializationTask> beforeInitializationTasks() { 587 return Collections.emptyList(); 588 } 589 590 /** 591 * Returns tasks to be executed (in parallel) by a ExecutorService. 592 * @return tasks to be executed (in parallel) by a ExecutorService 593 */ 594 protected Collection<InitializationTask> parallelInitializationTasks() { 595 return Collections.emptyList(); 596 } 597 598 /** 599 * Returns asynchronous callable initializations to be completed eventually 600 * @return asynchronous callable initializations to be completed eventually 601 */ 602 protected List<Callable<?>> asynchronousCallableTasks() { 603 return Collections.emptyList(); 604 } 605 606 /** 607 * Returns asynchronous runnable initializations to be completed eventually 608 * @return asynchronous runnable initializations to be completed eventually 609 */ 610 protected List<Runnable> asynchronousRunnableTasks() { 611 return Collections.emptyList(); 612 } 613 614 /** 615 * Returns tasks that must be run after parallel tasks. 616 * @return tasks that must be run after parallel tasks 617 * @see #beforeInitializationTasks 618 * @see #parallelInitializationTasks 619 */ 620 protected List<InitializationTask> afterInitializationTasks() { 621 return Collections.emptyList(); 632 622 } 633 623 … … 638 628 protected abstract void initializeMainWindow(); 639 629 640 static final class InitializationTask implements Callable<Void> {630 protected static final class InitializationTask implements Callable<Void> { 641 631 642 632 private final String name; 643 633 private final Runnable task; 644 634 645 protected InitializationTask(String name, Runnable task) { 635 /** 636 * Constructs a new {@code InitializationTask}. 637 * @param name translated name to be displayed to user 638 * @param task runnable initialization task 639 */ 640 public InitializationTask(String name, Runnable task) { 646 641 this.name = name; 647 642 this.task = task; -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12620 r12629 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 6 7 import java.awt.BorderLayout; 7 8 import java.awt.Dimension; 9 import java.awt.event.KeyEvent; 8 10 import java.io.File; 9 11 import java.io.IOException; … … 33 35 import java.util.Set; 34 36 import java.util.TreeSet; 37 import java.util.concurrent.Callable; 35 38 import java.util.logging.Level; 36 39 import java.util.stream.Collectors; … … 44 47 45 48 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; 49 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 46 50 import org.openstreetmap.josm.Main; 47 51 import org.openstreetmap.josm.actions.PreferencesAction; … … 50 54 import org.openstreetmap.josm.data.CustomConfigurator; 51 55 import org.openstreetmap.josm.data.Version; 56 import org.openstreetmap.josm.data.validation.OsmValidator; 52 57 import org.openstreetmap.josm.gui.ProgramArguments.Option; 53 58 import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor; 54 59 import org.openstreetmap.josm.gui.download.DownloadDialog; 60 import org.openstreetmap.josm.gui.layer.TMSLayer; 61 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; 62 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; 55 63 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 56 64 import org.openstreetmap.josm.gui.preferences.server.ProxyPreference; 65 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 57 66 import org.openstreetmap.josm.gui.util.GuiHelper; 58 67 import org.openstreetmap.josm.io.CertificateAmendment; … … 60 69 import org.openstreetmap.josm.io.MessageNotifier; 61 70 import org.openstreetmap.josm.io.OnlineResource; 71 import org.openstreetmap.josm.io.OsmApi; 72 import org.openstreetmap.josm.io.OsmApiInitializationException; 73 import org.openstreetmap.josm.io.OsmTransferCanceledException; 62 74 import org.openstreetmap.josm.io.auth.CredentialsManager; 63 75 import org.openstreetmap.josm.io.auth.DefaultAuthenticator; … … 70 82 import org.openstreetmap.josm.tools.I18n; 71 83 import org.openstreetmap.josm.tools.Logging; 84 import org.openstreetmap.josm.tools.OpenBrowser; 72 85 import org.openstreetmap.josm.tools.OsmUrlToBounds; 86 import org.openstreetmap.josm.tools.OverpassTurboQueryWizard; 73 87 import org.openstreetmap.josm.tools.PlatformHookWindows; 88 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; 89 import org.openstreetmap.josm.tools.Shortcut; 90 import org.openstreetmap.josm.tools.Territories; 74 91 import org.openstreetmap.josm.tools.Utils; 75 92 import org.openstreetmap.josm.tools.WindowGeometry; … … 95 112 */ 96 113 public MainApplication() { 97 // Allow subclassing (see JOSM.java)98 114 this(null); 99 115 } … … 106 122 public MainApplication(MainFrame mainFrame) { 107 123 this.mainFrame = mainFrame; 124 } 125 126 @Override 127 protected List<InitializationTask> beforeInitializationTasks() { 128 return Arrays.asList( 129 new InitializationTask(tr("Starting file watcher"), fileWatcher::start), 130 new InitializationTask(tr("Executing platform startup hook"), platform::startupHook), 131 new InitializationTask(tr("Building main menu"), this::initializeMainWindow), 132 new InitializationTask(tr("Updating user interface"), () -> { 133 undoRedo.addCommandQueueListener(redoUndoListener); 134 // creating toolbar 135 GuiHelper.runInEDTAndWait(() -> contentPanePrivate.add(toolbar.control, BorderLayout.NORTH)); 136 // help shortcut 137 registerActionShortcut(menu.help, Shortcut.registerShortcut("system:help", tr("Help"), 138 KeyEvent.VK_F1, Shortcut.DIRECT)); 139 }), 140 // This needs to be done before RightAndLefthandTraffic::initialize is called 141 new InitializationTask(tr("Initializing internal boundaries data"), Territories::initialize) 142 ); 143 } 144 145 @Override 146 protected Collection<InitializationTask> parallelInitializationTasks() { 147 return Arrays.asList( 148 new InitializationTask(tr("Initializing OSM API"), () -> { 149 // We try to establish an API connection early, so that any API 150 // capabilities are already known to the editor instance. However 151 // if it goes wrong that's not critical at this stage. 152 try { 153 OsmApi.getOsmApi().initialize(null, true); 154 } catch (OsmTransferCanceledException | OsmApiInitializationException e) { 155 Logging.warn(Logging.getErrorMessage(Utils.getRootCause(e))); 156 } 157 }), 158 new InitializationTask(tr("Initializing internal traffic data"), RightAndLefthandTraffic::initialize), 159 new InitializationTask(tr("Initializing validator"), OsmValidator::initialize), 160 new InitializationTask(tr("Initializing presets"), TaggingPresets::initialize), 161 new InitializationTask(tr("Initializing map styles"), MapPaintPreference::initialize), 162 new InitializationTask(tr("Loading imagery preferences"), ImageryPreference::initialize) 163 ); 164 } 165 166 @Override 167 protected List<Callable<?>> asynchronousCallableTasks() { 168 return Arrays.asList( 169 OverpassTurboQueryWizard::getInstance 170 ); 171 } 172 173 @Override 174 protected List<Runnable> asynchronousRunnableTasks() { 175 return Arrays.asList( 176 TMSLayer::getCache, 177 OsmValidator::initializeTests 178 ); 179 } 180 181 @Override 182 protected List<InitializationTask> afterInitializationTasks() { 183 return Arrays.asList( 184 new InitializationTask(tr("Updating user interface"), () -> GuiHelper.runInEDTAndWait(() -> { 185 // hooks for the jmapviewer component 186 FeatureAdapter.registerBrowserAdapter(OpenBrowser::displayUrl); 187 FeatureAdapter.registerTranslationAdapter(I18n.getTranslationAdapter()); 188 FeatureAdapter.registerLoggingAdapter(name -> Logging.getLogger()); 189 // UI update 190 toolbar.refreshToolbarControl(); 191 toolbar.control.updateUI(); 192 contentPanePrivate.updateUI(); 193 })) 194 ); 108 195 } 109 196
Note:
See TracChangeset
for help on using the changeset viewer.