Ignore:
Timestamp:
2017-08-23T21:00:42+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - move GUI initialization stuff from Main (abstract) to gui.MainApplication

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12620 r12629  
    55import static org.openstreetmap.josm.tools.I18n.trn;
    66
     7import java.awt.BorderLayout;
    78import java.awt.Dimension;
     9import java.awt.event.KeyEvent;
    810import java.io.File;
    911import java.io.IOException;
     
    3335import java.util.Set;
    3436import java.util.TreeSet;
     37import java.util.concurrent.Callable;
    3538import java.util.logging.Level;
    3639import java.util.stream.Collectors;
     
    4447
    4548import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
     49import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    4650import org.openstreetmap.josm.Main;
    4751import org.openstreetmap.josm.actions.PreferencesAction;
     
    5054import org.openstreetmap.josm.data.CustomConfigurator;
    5155import org.openstreetmap.josm.data.Version;
     56import org.openstreetmap.josm.data.validation.OsmValidator;
    5257import org.openstreetmap.josm.gui.ProgramArguments.Option;
    5358import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
    5459import org.openstreetmap.josm.gui.download.DownloadDialog;
     60import org.openstreetmap.josm.gui.layer.TMSLayer;
     61import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
     62import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;
    5563import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
    5664import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
     65import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    5766import org.openstreetmap.josm.gui.util.GuiHelper;
    5867import org.openstreetmap.josm.io.CertificateAmendment;
     
    6069import org.openstreetmap.josm.io.MessageNotifier;
    6170import org.openstreetmap.josm.io.OnlineResource;
     71import org.openstreetmap.josm.io.OsmApi;
     72import org.openstreetmap.josm.io.OsmApiInitializationException;
     73import org.openstreetmap.josm.io.OsmTransferCanceledException;
    6274import org.openstreetmap.josm.io.auth.CredentialsManager;
    6375import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
     
    7082import org.openstreetmap.josm.tools.I18n;
    7183import org.openstreetmap.josm.tools.Logging;
     84import org.openstreetmap.josm.tools.OpenBrowser;
    7285import org.openstreetmap.josm.tools.OsmUrlToBounds;
     86import org.openstreetmap.josm.tools.OverpassTurboQueryWizard;
    7387import org.openstreetmap.josm.tools.PlatformHookWindows;
     88import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
     89import org.openstreetmap.josm.tools.Shortcut;
     90import org.openstreetmap.josm.tools.Territories;
    7491import org.openstreetmap.josm.tools.Utils;
    7592import org.openstreetmap.josm.tools.WindowGeometry;
     
    95112     */
    96113    public MainApplication() {
    97         // Allow subclassing (see JOSM.java)
    98114        this(null);
    99115    }
     
    106122    public MainApplication(MainFrame mainFrame) {
    107123        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        );
    108195    }
    109196
Note: See TracChangeset for help on using the changeset viewer.