Changeset 12695 in josm for trunk/src/org
- Timestamp:
- 2017-08-29T00:16:25+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12691 r12695 38 38 import java.util.concurrent.Callable; 39 39 import java.util.concurrent.ExecutorService; 40 import java.util.concurrent.Executors; 40 41 import java.util.concurrent.Future; 41 42 import java.util.logging.Level; … … 60 61 import org.openstreetmap.josm.actions.JosmAction; 61 62 import org.openstreetmap.josm.actions.OpenFileAction; 63 import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask; 62 64 import org.openstreetmap.josm.actions.PreferencesAction; 63 65 import org.openstreetmap.josm.actions.RestartAction; … … 103 105 import org.openstreetmap.josm.io.OsmApiInitializationException; 104 106 import org.openstreetmap.josm.io.OsmTransferCanceledException; 107 import org.openstreetmap.josm.io.OsmTransferException; 105 108 import org.openstreetmap.josm.io.auth.CredentialsManager; 106 109 import org.openstreetmap.josm.io.auth.DefaultAuthenticator; … … 117 120 import org.openstreetmap.josm.tools.OsmUrlToBounds; 118 121 import org.openstreetmap.josm.tools.OverpassTurboQueryWizard; 122 import org.openstreetmap.josm.tools.PlatformHook.NativeOsCallback; 119 123 import org.openstreetmap.josm.tools.PlatformHookWindows; 120 124 import org.openstreetmap.josm.tools.RightAndLefthandTraffic; … … 124 128 import org.openstreetmap.josm.tools.bugreport.BugReport; 125 129 import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler; 130 import org.xml.sax.SAXException; 126 131 127 132 /** … … 725 730 // initialize the platform hook, and 726 731 Main.determinePlatformHook(); 732 Main.platform.setNativeOsCallback(new DefaultNativeOsCallback()); 727 733 // call the really early hook before we do anything else 728 734 Main.platform.preStartupHook(); … … 1188 1194 } 1189 1195 } 1196 1197 private static class DefaultNativeOsCallback implements NativeOsCallback { 1198 @Override 1199 public void openFiles(List<File> files) { 1200 Executors.newSingleThreadExecutor(Utils.newThreadFactory("openFiles-%d", Thread.NORM_PRIORITY)).submit( 1201 new OpenFileTask(files, null) { 1202 @Override 1203 protected void realRun() throws SAXException, IOException, OsmTransferException { 1204 // Wait for JOSM startup is advanced enough to load a file 1205 while (Main.parent == null || !Main.parent.isVisible()) { 1206 try { 1207 Thread.sleep(25); 1208 } catch (InterruptedException e) { 1209 Logging.warn(e); 1210 Thread.currentThread().interrupt(); 1211 } 1212 } 1213 super.realRun(); 1214 } 1215 }); 1216 } 1217 1218 @Override 1219 public boolean handleQuitRequest() { 1220 return MainApplication.exitJosm(false, 0, null); 1221 } 1222 1223 @Override 1224 public void handleAbout() { 1225 MainApplication.getMenu().about.actionPerformed(null); 1226 } 1227 1228 @Override 1229 public void handlePreferences() { 1230 MainApplication.getMenu().preferences.actionPerformed(null); 1231 } 1232 } 1190 1233 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r12676 r12695 272 272 } 273 273 } 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 } 274 313 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r12670 r12695 17 17 import java.util.Collections; 18 18 import java.util.List; 19 import java.util. concurrent.Executors;19 import java.util.Objects; 20 20 21 21 import javax.swing.UIManager; 22 22 23 23 import 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;28 24 29 25 /** … … 36 32 37 33 private String oSBuildNumber; 34 35 private NativeOsCallback osCallback; 38 36 39 37 @Override … … 138 136 } 139 137 138 @Override 139 public void setNativeOsCallback(NativeOsCallback callback) { 140 osCallback = Objects.requireNonNull(callback); 141 } 142 140 143 @SuppressWarnings("unchecked") 141 144 @Override … … 150 153 Object oFiles = args[0].getClass().getMethod("getFiles").invoke(args[0]); 151 154 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); 168 156 } 169 157 } catch (ReflectiveOperationException | SecurityException | IllegalArgumentException ex) { … … 173 161 break; 174 162 case "handleQuitRequestWith": 175 boolean closed = MainApplication.exitJosm(false, 0, null);163 boolean closed = osCallback.handleQuitRequest(); 176 164 if (args[1] != null) { 177 165 try { … … 185 173 break; 186 174 case "handleAbout": 187 MainApplication.getMenu().about.actionPerformed(null);175 osCallback.handleAbout(); 188 176 break; 189 177 case "handlePreferences": 190 MainApplication.getMenu().preferences.actionPerformed(null);178 osCallback.handlePreferences(); 191 179 break; 192 180 default:
Note:
See TracChangeset
for help on using the changeset viewer.