Changeset 14125 in josm for trunk/src/org


Ignore:
Timestamp:
2018-08-11T19:01:26+02:00 (6 years ago)
Author:
Don-vip
Message:

see #15229 - extract lifecycle Main classes to a new lifecycle SPI

Location:
trunk/src/org/openstreetmap/josm
Files:
4 added
2 edited

Legend:

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

    r14121 r14125  
    3636import org.openstreetmap.josm.io.NetworkManager;
    3737import org.openstreetmap.josm.io.OnlineResource;
     38import org.openstreetmap.josm.spi.lifecycle.InitializationTask;
    3839import org.openstreetmap.josm.spi.preferences.Config;
    3940import org.openstreetmap.josm.spi.preferences.IUrls;
    40 import org.openstreetmap.josm.tools.CheckParameterUtil;
    4141import org.openstreetmap.josm.tools.ImageProvider;
    4242import org.openstreetmap.josm.tools.JosmRuntimeException;
     
    8787     */
    8888    public static volatile PlatformHook platform;
    89 
    90     private static volatile InitStatusListener initListener;
    91 
    92     /**
    93      * Initialization task listener.
    94      */
    95     public interface InitStatusListener {
    96 
    97         /**
    98          * Called when an initialization task updates its status.
    99          * @param event task name
    100          * @return new status
    101          */
    102         Object updateStatus(String event);
    103 
    104         /**
    105          * Called when an initialization task completes.
    106          * @param status final status
    107          */
    108         void finish(Object status);
    109     }
    110 
    111     /**
    112      * Sets initialization task listener.
    113      * @param listener initialization task listener
    114      */
    115     public static void setInitStatusListener(InitStatusListener listener) {
    116         CheckParameterUtil.ensureParameterNotNull(listener);
    117         initListener = listener;
    118     }
    11989
    12090    /**
     
    217187    }
    218188
    219     protected static final class InitializationTask implements Callable<Void> {
    220 
    221         private final String name;
    222         private final Runnable task;
    223 
    224         /**
    225          * Constructs a new {@code InitializationTask}.
    226          * @param name translated name to be displayed to user
    227          * @param task runnable initialization task
    228          */
    229         public InitializationTask(String name, Runnable task) {
    230             this.name = name;
    231             this.task = task;
    232         }
    233 
    234         @Override
    235         public Void call() {
    236             Object status = null;
    237             if (initListener != null) {
    238                 status = initListener.updateStatus(name);
    239             }
    240             task.run();
    241             if (initListener != null) {
    242                 initListener.finish(status);
    243             }
    244             return null;
    245         }
    246     }
    247 
    248189    /**
    249190     * Replies the current selected OSM primitives, from a end-user point of view.
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r14121 r14125  
    161161import org.openstreetmap.josm.plugins.PluginHandler;
    162162import org.openstreetmap.josm.plugins.PluginInformation;
     163import org.openstreetmap.josm.spi.lifecycle.InitStatusListener;
     164import org.openstreetmap.josm.spi.lifecycle.InitializationTask;
     165import org.openstreetmap.josm.spi.lifecycle.Lifecycle;
    163166import org.openstreetmap.josm.spi.preferences.Config;
    164167import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     
    318321        String location = Config.getUrls().getJOSMWebsite() + "/proj/" + gridFileName;
    319322        // Try to load grid file
     323        @SuppressWarnings("resource")
    320324        CachedFile cf = new CachedFile(location);
    321325        try {
     
    667671    }
    668672
     673    /**
     674     * Redirects the key inputs from {@code source} to main content pane.
     675     * @param source source component from which key inputs are redirected
     676     */
    669677    public static void redirectToMainContentPane(JComponent source) {
    670678        RedirectInputMap.redirect(source, contentPanePrivate);
     
    10451053            GuiHelper.runInEDT(() -> splash.setVisible(Config.getPref().getBoolean("draw.splashscreen", true)));
    10461054        }
    1047         Main.setInitStatusListener(new InitStatusListener() {
     1055        Lifecycle.setInitStatusListener(new InitStatusListener() {
    10481056
    10491057            @Override
Note: See TracChangeset for help on using the changeset viewer.