Ignore:
Timestamp:
2017-08-29T00:16:25+02:00 (2 years ago)
Author:
Don-vip
Message:

see #15182 - refactor PlatformHookOsx so that all GUI actions are performed in MainApplication and only macOS-specific stuff remains in platform hook

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
2 edited

Legend:

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

    r12676 r12695  
    272272        }
    273273    }
     274
     275    /**
     276     * Called when interfacing with native OS functions. Currently only used with macOS.
     277     * The callback must perform all GUI-related tasks associated to an OS request.
     278     * The non-GUI, platform-specific tasks, are usually performed by the {@code PlatformHook}.
     279     * @since 12695
     280     */
     281    interface NativeOsCallback {
     282        /**
     283         * macOS: Called when JOSM is asked to open a list of files.
     284         * @param files list of files to open
     285         */
     286        void openFiles(List<File> files);
     287
     288        /**
     289         * macOS: Invoked when JOSM is asked to quit.
     290         * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation.
     291         */
     292        boolean handleQuitRequest();
     293
     294        /**
     295         * macOS: Called when JOSM is asked to show it's about dialog.
     296         */
     297        void handleAbout();
     298
     299        /**
     300         * macOS: Called when JOSM is asked to show it's preferences UI.
     301         */
     302        void handlePreferences();
     303    }
     304
     305    /**
     306     * Registers the native OS callback. Currently only needed for macOS.
     307     * @param callback the native OS callback
     308     * @since 12695
     309     */
     310    default void setNativeOsCallback(NativeOsCallback callback) {
     311        // To be implemented if needed
     312    }
    274313}
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r12670 r12695  
    1717import java.util.Collections;
    1818import java.util.List;
    19 import java.util.concurrent.Executors;
     19import java.util.Objects;
    2020
    2121import javax.swing.UIManager;
    2222
    2323import org.openstreetmap.josm.Main;
    24 import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask;
    25 import org.openstreetmap.josm.gui.MainApplication;
    26 import org.openstreetmap.josm.io.OsmTransferException;
    27 import org.xml.sax.SAXException;
    2824
    2925/**
     
    3632
    3733    private String oSBuildNumber;
     34
     35    private NativeOsCallback osCallback;
    3836
    3937    @Override
     
    138136    }
    139137
     138    @Override
     139    public void setNativeOsCallback(NativeOsCallback callback) {
     140        osCallback = Objects.requireNonNull(callback);
     141    }
     142
    140143    @SuppressWarnings("unchecked")
    141144    @Override
     
    150153                    Object oFiles = args[0].getClass().getMethod("getFiles").invoke(args[0]);
    151154                    if (oFiles instanceof List) {
    152                         Executors.newSingleThreadExecutor(Utils.newThreadFactory("openFiles-%d", Thread.NORM_PRIORITY)).submit(
    153                                 new OpenFileTask((List<File>) oFiles, null) {
    154                             @Override
    155                             protected void realRun() throws SAXException, IOException, OsmTransferException {
    156                                 // Wait for JOSM startup is advanced enough to load a file
    157                                 while (Main.parent == null || !Main.parent.isVisible()) {
    158                                     try {
    159                                         Thread.sleep(25);
    160                                     } catch (InterruptedException e) {
    161                                         Logging.warn(e);
    162                                         Thread.currentThread().interrupt();
    163                                     }
    164                                 }
    165                                 super.realRun();
    166                             }
    167                         });
     155                        osCallback.openFiles((List<File>) oFiles);
    168156                    }
    169157                } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) {
     
    173161            break;
    174162        case "handleQuitRequestWith":
    175             boolean closed = MainApplication.exitJosm(false, 0, null);
     163            boolean closed = osCallback.handleQuitRequest();
    176164            if (args[1] != null) {
    177165                try {
     
    185173            break;
    186174        case "handleAbout":
    187             MainApplication.getMenu().about.actionPerformed(null);
     175            osCallback.handleAbout();
    188176            break;
    189177        case "handlePreferences":
    190             MainApplication.getMenu().preferences.actionPerformed(null);
     178            osCallback.handlePreferences();
    191179            break;
    192180        default:
Note: See TracChangeset for help on using the changeset viewer.